summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tradeshow/iot-sensortag/mockdataproviderpool.cpp2
-rw-r--r--wayland/democompositor/.gitignore11
-rw-r--r--wayland/democompositor/apps/README20
-rw-r--r--wayland/democompositor/apps/appentry.cpp57
-rw-r--r--wayland/democompositor/apps/appentry.h77
-rw-r--r--wayland/democompositor/apps/applistmodel.cpp159
-rw-r--r--wayland/democompositor/apps/applistmodel.h90
-rw-r--r--wayland/democompositor/apps/applog.h55
-rw-r--r--wayland/democompositor/apps/appparser.cpp156
-rw-r--r--wayland/democompositor/apps/appparser.h62
-rw-r--r--wayland/democompositor/apps/apps.pri11
-rw-r--r--wayland/democompositor/apps/files/clock.app8
-rw-r--r--wayland/democompositor/apps/files/maps.app8
-rw-r--r--wayland/democompositor/apps/files/rss.app8
-rw-r--r--wayland/democompositor/apps/files/stocqt.app8
-rw-r--r--wayland/democompositor/democompositor.pro9
-rw-r--r--wayland/democompositor/democompositor_all.pro5
-rw-r--r--wayland/democompositor/main.cpp34
-rw-r--r--wayland/democompositor/processlauncher.cpp84
-rw-r--r--wayland/democompositor/processlauncher.h34
-rw-r--r--wayland/democompositor/qml/LaunchButton.qml7
-rw-r--r--wayland/democompositor/qml/Screen.qml61
-rw-r--r--wayland/democompositor/qml/main.qml8
-rw-r--r--wayland/democompositor/tests/applist/applist.pro17
-rw-r--r--wayland/democompositor/tests/applist/applist.qrc6
-rw-r--r--wayland/democompositor/tests/applist/tst_applistmodel.cpp108
-rw-r--r--wayland/democompositor/tests/apps/apps.pro15
-rw-r--r--wayland/democompositor/tests/apps/apps.qrc5
-rw-r--r--wayland/democompositor/tests/apps/tst_appparser.cpp133
29 files changed, 1206 insertions, 52 deletions
diff --git a/tradeshow/iot-sensortag/mockdataproviderpool.cpp b/tradeshow/iot-sensortag/mockdataproviderpool.cpp
index 5f37737..6592e1b 100644
--- a/tradeshow/iot-sensortag/mockdataproviderpool.cpp
+++ b/tradeshow/iot-sensortag/mockdataproviderpool.cpp
@@ -69,7 +69,7 @@ void MockDataProviderPool::startScanning()
p->setTagType(SensorTagDataProvider::Humidity | SensorTagDataProvider::Light | SensorTagDataProvider::Accelometer);
m_dataProviders.push_back(p);
p = new MockDataProvider("MOCK_PROVIDER_3", this);
- p->setTagType(SensorTagDataProvider::Magnetometer | SensorTagDataProvider::AirPressure);
+ p->setTagType(SensorTagDataProvider::Magnetometer | SensorTagDataProvider::AirPressure | SensorTagDataProvider::Altitude);
m_dataProviders.push_back(p);
for (int i=0; i < m_dataProviders.length(); i++)
emit providerConnected(p->id());
diff --git a/wayland/democompositor/.gitignore b/wayland/democompositor/.gitignore
new file mode 100644
index 0000000..acd6488
--- /dev/null
+++ b/wayland/democompositor/.gitignore
@@ -0,0 +1,11 @@
+.obj/
+.moc/
+.rcc/
+*.sw?
+Makefile
+target_wrapper.sh
+
+Makefile.democompositor
+democompositor
+tests/applist/tst_applistmodel
+tests/apps/tst_apps
diff --git a/wayland/democompositor/apps/README b/wayland/democompositor/apps/README
new file mode 100644
index 0000000..361b2c1
--- /dev/null
+++ b/wayland/democompositor/apps/README
@@ -0,0 +1,20 @@
+A directory holding a list of applications. There is one JSON file
+per launchable application. The content is inspired by the "Desktop
+Entry Specification" of freedesktop.org.
+
+Application files need to be installed into any of the paths that
+will be listed for QStandardPaths::DataLocation/apps. In the
+case of the democompositor this can be
+/usr/share/democompositor/apps.
+
+The content of the files must follow:
+
+Name Description Required JSON type
+Type Type of entry. Currently only Yes String
+ Application is supported.
+Version The version of the specification
+ addressed. Currently version 1 Yes Number
+Icon The icon to use for display Yes String
+Name A user displayable name Yes String
+Exec Application to execute to launch Yes String
+Path The directory to search for the app No String
diff --git a/wayland/democompositor/apps/appentry.cpp b/wayland/democompositor/apps/appentry.cpp
new file mode 100644
index 0000000..aaae167
--- /dev/null
+++ b/wayland/democompositor/apps/appentry.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "appentry.h"
+
+AppEntry AppEntry::empty()
+{
+ QString empty;
+ return AppEntry{empty, empty, empty, empty, empty};
+}
diff --git a/wayland/democompositor/apps/appentry.h b/wayland/democompositor/apps/appentry.h
new file mode 100644
index 0000000..317b748
--- /dev/null
+++ b/wayland/democompositor/apps/appentry.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QtCore/QObject>
+#include <QtCore/QString>
+
+/**
+ * A const representatation of an application entry. Members include
+ * executable name, path, icon and other information in the future.
+ */
+class AppEntry {
+ Q_GADGET
+ Q_PROPERTY(QString iconName MEMBER iconName CONSTANT)
+ Q_PROPERTY(QString appName MEMBER appName CONSTANT)
+ Q_PROPERTY(QString executableName MEMBER executableName CONSTANT)
+ Q_PROPERTY(QString executablePath MEMBER executablePath CONSTANT)
+public:
+
+ QString iconName;
+ QString appName;
+ QString executableName;
+ QString executablePath;
+ QString sourceFileName;
+
+ static AppEntry empty();
+};
+
+Q_DECLARE_METATYPE(AppEntry)
diff --git a/wayland/democompositor/apps/applistmodel.cpp b/wayland/democompositor/apps/applistmodel.cpp
new file mode 100644
index 0000000..0b4d620
--- /dev/null
+++ b/wayland/democompositor/apps/applistmodel.cpp
@@ -0,0 +1,159 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "applistmodel.h"
+#include "appparser.h"
+#include "applog.h"
+
+#include <QtCore/QDirIterator>
+#include <QtCore/QFileSystemWatcher>
+
+static QHash<int, QByteArray> modelRoles()
+{
+ QHash<int, QByteArray> roles;
+ roles[AppListModel::App] = "appEntry";
+ roles[AppListModel::IconName] = "iconName";
+ roles[AppListModel::ApplicationName] = "applicationName";
+ roles[AppListModel::ExeuctableName] = "executableName";
+ roles[AppListModel::ExecutablePath] = "executablePath";
+ roles[AppListModel::SourceFileName] = "sourceFileName";
+ return roles;
+}
+
+QHash<int, QByteArray> AppListModel::m_roles = modelRoles();
+
+int AppListModel::rowCount(const QModelIndex& index) const
+{
+ if (index.isValid())
+ return 0;
+ return m_rows.count();
+}
+
+QVariant AppListModel::data(const QModelIndex& index, int role) const
+{
+ if (!index.isValid() || index.parent().isValid())
+ return QVariant();
+
+ auto entry = m_rows[index.row()];
+
+ switch (role) {
+ case App:
+ return QVariant::fromValue(entry);
+ case IconName:
+ return entry.iconName;
+ case ApplicationName:
+ return entry.appName;
+ case ExeuctableName:
+ return entry.executableName;
+ case ExecutablePath:
+ return entry.executablePath;
+ case SourceFileName:
+ return entry.sourceFileName;
+ default:
+ qCWarning(apps) << "Unhandled role" << role;
+ return QVariant();
+ }
+}
+
+QHash<int, QByteArray> AppListModel::roleNames() const
+{
+ return m_roles;
+}
+
+/*!
+ * Returns true if the directory can be watched
+ *
+ * Parse all JSON application files from the given directory
+ * and monitor it for changes.
+ */
+bool AppListModel::addAndWatchDir(const QString& dirName)
+{
+ auto watcher = new QFileSystemWatcher(this);
+ connect(watcher, &QFileSystemWatcher::directoryChanged, this, &AppListModel::addDir);
+ auto res = watcher->addPath(dirName);
+ addDir(dirName);
+
+ qCDebug(apps) << "addAndWatchDir" << dirName << "result: " << res;
+ return res;
+}
+
+void AppListModel::addFile(const QString& fileName)
+{
+ beginResetModel();
+ doAddFile(fileName);
+ endResetModel();
+}
+
+void AppListModel::addDir(const QString& dirName)
+{
+ QDirIterator dirIt(dirName, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable);
+
+ beginResetModel();
+ while (dirIt.hasNext())
+ doAddFile(dirIt.next());
+ endResetModel();
+}
+
+void AppListModel::doAddFile(const QString& fileName)
+{
+ bool ok;
+ auto newEntry = AppParser::parseFile(fileName, &ok);
+ if (!ok)
+ return;
+
+ for (int i = 0; i < m_rows.count(); ++i) {
+ if (m_rows[i].sourceFileName == fileName) {
+ m_rows[i] = newEntry;
+ return;
+ }
+ }
+
+ m_rows.push_back(newEntry);
+}
diff --git a/wayland/democompositor/apps/applistmodel.h b/wayland/democompositor/apps/applistmodel.h
new file mode 100644
index 0000000..9147f54
--- /dev/null
+++ b/wayland/democompositor/apps/applistmodel.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include "appentry.h"
+
+#include <QtCore/QAbstractListModel>
+#include <QtCore/QVector>
+
+/**
+ * A model that holds all available applications and
+ * exports them to a QML scene
+ */
+class AppListModel : public QAbstractListModel {
+ Q_OBJECT
+public:
+
+ enum Roles {
+ App = Qt::UserRole,
+ IconName,
+ ApplicationName,
+ ExeuctableName,
+ ExecutablePath,
+ SourceFileName,
+ };
+
+ int rowCount(const QModelIndex& parent) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex& index, int role) const Q_DECL_OVERRIDE;
+ QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+
+public Q_SLOTS:
+ bool addAndWatchDir(const QString& dirName);
+
+ void addFile(const QString& fileName);
+ void addDir(const QString& dirName);
+
+private:
+ void doAddFile(const QString& fileName);
+
+ QVector<AppEntry> m_rows;
+ static QHash<int, QByteArray> m_roles;
+};
diff --git a/wayland/democompositor/apps/applog.h b/wayland/democompositor/apps/applog.h
new file mode 100644
index 0000000..b116530
--- /dev/null
+++ b/wayland/democompositor/apps/applog.h
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QtCore/QLoggingCategory>
+
+Q_DECLARE_LOGGING_CATEGORY(apps)
diff --git a/wayland/democompositor/apps/appparser.cpp b/wayland/democompositor/apps/appparser.cpp
new file mode 100644
index 0000000..2c373cc
--- /dev/null
+++ b/wayland/democompositor/apps/appparser.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "appparser.h"
+#include "applog.h"
+
+#include <QtCore/QFile>
+#include <QtCore/QJsonDocument>
+#include <QtCore/QJsonObject>
+
+Q_LOGGING_CATEGORY(apps, "launcher.apps")
+
+
+static QString doReadString(const QJsonValue& value, bool *ok)
+{
+ if (value.type() != QJsonValue::String) {
+ *ok = false;
+ return QString();
+ }
+ return value.toString();
+}
+
+static int doReadInt(const QJsonValue& value, bool *ok)
+{
+ if (value.type() != QJsonValue::Double) {
+ *ok = false;
+ return 0;
+ }
+ return value.toInt();
+}
+
+static QString readString(const QJsonObject& object, const QString& key, bool *ok)
+{
+ return doReadString(object.value(key), ok);
+}
+
+static QString readStringOptional(const QJsonObject& object, const QString& key, bool *ok)
+{
+ auto item = object.value(key);
+ if (item.type() == QJsonValue::Undefined)
+ return QString();
+ return doReadString(item, ok);
+}
+
+static int readInt(const QJsonObject& object, const QString& key, bool *ok)
+{
+ return doReadInt(object.value(key), ok);
+}
+
+AppEntry AppParser::parseData(const QByteArray& content, const QString& fileName, bool *ok)
+{
+ *ok = true;
+ QJsonParseError error;
+
+ QJsonDocument doc = QJsonDocument::fromJson(content, &error);
+ if (error.error != QJsonParseError::NoError) {
+ qCWarning(apps) << "Failed to parse json: " << error.errorString();
+ *ok = false;
+ return AppEntry::empty();
+ }
+
+ if (!doc.isObject()) {
+ qCWarning(apps) << "Parsed document is not an object";
+ *ok = false;
+ return AppEntry::empty();
+ }
+
+ auto root = doc.object();
+
+ QString type = readString(root, QStringLiteral("Type"), ok);
+ if (type != QStringLiteral("Application")) {
+ qCWarning(apps) << "Unknown type" << type;
+ *ok = false;
+ }
+
+ int version = readInt(root, QStringLiteral("Version"), ok);
+ if (version != 1) {
+ qCWarning(apps) << "Version number should be 1... Consider to fix that" << version;
+ }
+
+ QString iconName = readString(root, QStringLiteral("Icon"), ok);
+ QString appName = readString(root, QStringLiteral("Name"), ok);
+ QString executableName = readString(root, QStringLiteral("Exec"), ok);
+ QString executablePath = readStringOptional(root, QStringLiteral("Path"), ok);
+ if (!*ok)
+ return AppEntry::empty();
+
+ return AppEntry{iconName, appName, executableName, executablePath, fileName};
+}
+
+AppEntry AppParser::parseFile(const QString& fileName, bool *ok)
+{
+ qCDebug(apps) << "Trying to parse" << fileName;
+
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ qCWarning(apps) << "Failed to open" << fileName;
+ *ok = false;
+ return AppEntry::empty();
+ }
+
+ auto entry = parseData(file.readAll(), fileName, ok);
+ file.close();
+ if (!*ok) {
+ qCWarning(apps) << "Failed to parse" << fileName;
+ return AppEntry::empty();
+ }
+ return entry;
+}
diff --git a/wayland/democompositor/apps/appparser.h b/wayland/democompositor/apps/appparser.h
new file mode 100644
index 0000000..a6711b4
--- /dev/null
+++ b/wayland/democompositor/apps/appparser.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include "appentry.h"
+
+/**
+ * Parse a single application entry to an AppEntry.
+ */
+class AppParser {
+public:
+ static AppEntry parseData(const QByteArray& content, const QString& fileName, bool *ok);
+ static AppEntry parseFile(const QString& fileName, bool *ok);
+};
diff --git a/wayland/democompositor/apps/apps.pri b/wayland/democompositor/apps/apps.pri
new file mode 100644
index 0000000..9b19060
--- /dev/null
+++ b/wayland/democompositor/apps/apps.pri
@@ -0,0 +1,11 @@
+
+HEADERS += \
+ apps/appentry.h \
+ apps/applog.h \
+ apps/applistmodel.h \
+ apps/appparser.h
+
+SOURCES += \
+ apps/appentry.cpp \
+ apps/applistmodel.cpp \
+ apps/appparser.cpp
diff --git a/wayland/democompositor/apps/files/clock.app b/wayland/democompositor/apps/files/clock.app
new file mode 100644
index 0000000..d6f5f56
--- /dev/null
+++ b/wayland/democompositor/apps/files/clock.app
@@ -0,0 +1,8 @@
+{
+ "Type": "Application",
+ "Version": 1,
+ "Icon": "qrc:/images/Icon_Clocks.png",
+ "Name": "Clocks",
+ "Exec": "clocks",
+ "Path": "./"
+}
diff --git a/wayland/democompositor/apps/files/maps.app b/wayland/democompositor/apps/files/maps.app
new file mode 100644
index 0000000..e88899a
--- /dev/null
+++ b/wayland/democompositor/apps/files/maps.app
@@ -0,0 +1,8 @@
+{
+ "Type": "Application",
+ "Version": 1,
+ "Icon": "qrc:/images/Icon_Maps.png",
+ "Name": "Maps",
+ "Exec": "qml_location_mapviewer",
+ "Path": "./"
+}
diff --git a/wayland/democompositor/apps/files/rss.app b/wayland/democompositor/apps/files/rss.app
new file mode 100644
index 0000000..13ffbca
--- /dev/null
+++ b/wayland/democompositor/apps/files/rss.app
@@ -0,0 +1,8 @@
+{
+ "Type": "Application",
+ "Version": 1,
+ "Icon": "qrc:/images/Icon_RSS.png",
+ "Name": "RSS News",
+ "Exec": "rssnews",
+ "Path": "./"
+}
diff --git a/wayland/democompositor/apps/files/stocqt.app b/wayland/democompositor/apps/files/stocqt.app
new file mode 100644
index 0000000..9317359
--- /dev/null
+++ b/wayland/democompositor/apps/files/stocqt.app
@@ -0,0 +1,8 @@
+{
+ "Type": "Application",
+ "Version": 1,
+ "Icon": "qrc:/images/Icon_StocQt.png",
+ "Name": "StoQt",
+ "Exec": "stocqt",
+ "Path": "./"
+}
diff --git a/wayland/democompositor/democompositor.pro b/wayland/democompositor/democompositor.pro
index 99b6f93..ff9f2b4 100644
--- a/wayland/democompositor/democompositor.pro
+++ b/wayland/democompositor/democompositor.pro
@@ -17,5 +17,12 @@ RESOURCES += democompositor.qrc
HEADERS += \
processlauncher.h
-INSTALLS += target
+# include modules
+include(apps/apps.pri)
+
+INSTALLS += target apps
target.path = /data/user/$$TARGET
+
+# TODO. How does /data/user/$$TARGET map to QStandardPaths
+apps.path = /data/user/$$TARGET/apps/
+apps.files = apps/files/*.app
diff --git a/wayland/democompositor/democompositor_all.pro b/wayland/democompositor/democompositor_all.pro
new file mode 100644
index 0000000..52ae399
--- /dev/null
+++ b/wayland/democompositor/democompositor_all.pro
@@ -0,0 +1,5 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ democompositor.pro \
+ tests/apps \
+ tests/applist
diff --git a/wayland/democompositor/main.cpp b/wayland/democompositor/main.cpp
index a094a20..2b1279d 100644
--- a/wayland/democompositor/main.cpp
+++ b/wayland/democompositor/main.cpp
@@ -48,6 +48,8 @@
**
****************************************************************************/
+#include <QtCore/QCommandLineOption>
+#include <QtCore/QCommandLineParser>
#include <QtCore/QUrl>
#include <QtCore/QDebug>
@@ -55,11 +57,14 @@
#include <QtGui/QFont>
#include <QtQml/qqml.h>
#include <QtQml/QQmlApplicationEngine>
+
+#include "apps/applistmodel.h"
#include "processlauncher.h"
static void registerTypes()
{
qmlRegisterType<WaylandProcessLauncher>("com.theqtcompany.wlprocesslauncher", 1, 0, "ProcessLauncher");
+ qmlRegisterType<AppListModel>("com.theqtcompany.wlapplistmodel", 1, 0, "AppListModel");
}
@@ -68,13 +73,38 @@ int main(int argc, char *argv[])
{
qputenv("QT_QPA_EGLFS_HIDECURSOR", "1");
QGuiApplication app(argc, argv);
+ QGuiApplication::setApplicationName("democompositor");
+ QGuiApplication::setApplicationVersion("1.0");
+
+ /* Parse options */
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Demo Compositor");
+ parser.addHelpOption();
+ parser.addVersionOption();
+
+ QCommandLineOption fontNameOpt(QStringList() << "f" << "font",
+ QCoreApplication::translate("main", "Default font to use"),
+ QCoreApplication::translate("main", "Name of the font"),
+ "Open Sans");
+ parser.addOption(fontNameOpt);
+ QCommandLineOption fontNameSzeOpt(QStringList() << "s" << "size",
+ QCoreApplication::translate("main", "Default font size to use"),
+ QCoreApplication::translate("main", "Point size of the font"),
+ "12");
+ parser.addOption(fontNameSzeOpt);
+ QCommandLineOption qmlUrlOpt(QStringList() << "o" << "open",
+ QCoreApplication::translate("main", "QML scene to open"),
+ QCoreApplication::translate("main", "URL"),
+ "qrc:///qml/main.qml");
+ parser.addOption(qmlUrlOpt);
+ parser.process(app);
- QFont f("Open Sans", 12.5);
+ QFont f(parser.value(fontNameOpt), parser.value(fontNameSzeOpt).toInt());
app.setFont(f);
qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1");
registerTypes();
- QQmlApplicationEngine appEngine(QUrl("qrc:///qml/main.qml"));
+ QQmlApplicationEngine appEngine(QUrl(parser.value(qmlUrlOpt)));
return app.exec();
}
diff --git a/wayland/democompositor/processlauncher.cpp b/wayland/democompositor/processlauncher.cpp
index a25fbd5..2fb75c7 100644
--- a/wayland/democompositor/processlauncher.cpp
+++ b/wayland/democompositor/processlauncher.cpp
@@ -49,9 +49,22 @@
****************************************************************************/
#include "processlauncher.h"
+#include "apps/appentry.h"
#include <QProcess>
+Q_LOGGING_CATEGORY(procs, "launcher.procs")
+
+/*
+ * Two AppState's are equal if they are managing the same
+ * QProcess. It is assumed that no AppState survives beyond
+ * the QProcess.
+ */
+bool operator==(const AppState& lhs, const AppState& rhs)
+{
+ return lhs.process == rhs.process;
+}
+
WaylandProcessLauncher::WaylandProcessLauncher(QObject *parent)
: QObject(parent)
{
@@ -61,16 +74,75 @@ WaylandProcessLauncher::~WaylandProcessLauncher()
{
}
-void WaylandProcessLauncher::launch(const QString &program)
+QVariant WaylandProcessLauncher::appStateForPid(int pid) const
+{
+ for (auto state : m_appStates) {
+ if (state.process->pid() == pid) {
+ qCDebug(procs) << "Found state for" << pid << state.appEntry.executableName;
+ return QVariant::fromValue(state);
+ }
+ }
+
+ qCDebug(procs) << "Couldn't find entry for" << pid;
+ return QVariant();
+}
+
+bool WaylandProcessLauncher::isRunning(const AppEntry& entry) const
+{
+ for (auto state : m_appStates) {
+ if (state.appEntry.sourceFileName == entry.sourceFileName) {
+ qCDebug(procs) << "AppEntry associated to a state" << entry.executableName;
+ return true;
+ }
+ }
+
+ qCDebug(procs) << "AppEntry not associated to a state " << entry.executableName;
+ return false;
+}
+
+void WaylandProcessLauncher::launch(const AppEntry &entry)
{
+ qCDebug(procs) << "Launching" << entry.executableName;
+
QProcess *process = new QProcess(this);
+ process->setProcessChannelMode(QProcess::ForwardedChannels);
+
+ AppState state{process, entry};
+ m_appStates.push_back(state);
+
+ /* handle potential errors and life cycle */
connect(process, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
- process, &QProcess::deleteLater);
- connect(process, &QProcess::errorOccurred, &QProcess::deleteLater);
+ [state, this](int exitCode, QProcess::ExitStatus status) {
+ qCDebug(procs) << "AppEntry finished" << state.appEntry.executableName << exitCode << status;
+ emit appFinished(state, exitCode, status);
+ m_appStates.removeOne(state);
+ state.process->deleteLater();
+ });
+ connect(process, &QProcess::errorOccurred,
+ [state, this](QProcess::ProcessError err) {
+ qCDebug(procs) << "AppEntry error occurred" << state.appEntry.executableName << err;
+
+ /* Maybe finished was already emitted. Let's not emit an error after that */
+ if (!m_appStates.removeOne(state))
+ return;
+
+ if (err == QProcess::FailedToStart || err == QProcess::UnknownError)
+ emit appNotStarted(state);
+ state.process->deleteLater();
+ });
+ connect(process, &QProcess::started,
+ [state, this]() {
+ qCDebug(procs) << "AppEntry started" << state.appEntry.executableName;
+ emit appStarted(state);
+ });
+
+ if (!entry.executablePath.isNull()) {
+ auto env = QProcessEnvironment::systemEnvironment();
+ env.insert(QStringLiteral("PATH"), entry.executablePath);
+ process->setProcessEnvironment(env);
+ }
QStringList arguments;
arguments << "-platform" << "wayland";
- process->start(program, arguments);
-
+ process->start(entry.executableName, arguments);
}
-
diff --git a/wayland/democompositor/processlauncher.h b/wayland/democompositor/processlauncher.h
index 261da6d..f21be98 100644
--- a/wayland/democompositor/processlauncher.h
+++ b/wayland/democompositor/processlauncher.h
@@ -51,7 +51,26 @@
#ifndef PROCESSLAUNCHER_H
#define PROCESSLAUNCHER_H
+#include "apps/appentry.h"
+
#include <QObject>
+#include <QProcess>
+#include <QLoggingCategory>
+
+Q_DECLARE_LOGGING_CATEGORY(procs)
+
+/**
+ * Transient class. Do not keep AppState beyond the
+ * finished signal.
+ */
+class AppState {
+ Q_GADGET
+ Q_PROPERTY(QProcess *process MEMBER process CONSTANT)
+ Q_PROPERTY(AppEntry appEntry MEMBER appEntry CONSTANT)
+public:
+ QProcess *process;
+ AppEntry appEntry;
+};
class WaylandProcessLauncher : public QObject
{
@@ -60,7 +79,20 @@ class WaylandProcessLauncher : public QObject
public:
explicit WaylandProcessLauncher(QObject *parent = 0);
~WaylandProcessLauncher();
- Q_INVOKABLE void launch(const QString &program);
+ Q_INVOKABLE void launch(const AppEntry &entry);
+
+ Q_INVOKABLE QVariant appStateForPid(int pid) const;
+ Q_INVOKABLE bool isRunning(const AppEntry& entry) const;
+
+Q_SIGNALS:
+ void appStarted(const AppState &appState);
+ void appFinished(const AppState &appState, int exitCode, QProcess::ExitStatus exitStatus);
+ void appNotStarted(const AppState& appState);
+
+private:
+ QVector<AppState> m_appStates;
};
+Q_DECLARE_METATYPE(AppState)
+
#endif // PROCESSLAUNCHER_H
diff --git a/wayland/democompositor/qml/LaunchButton.qml b/wayland/democompositor/qml/LaunchButton.qml
index deb462c..80a057a 100644
--- a/wayland/democompositor/qml/LaunchButton.qml
+++ b/wayland/democompositor/qml/LaunchButton.qml
@@ -51,11 +51,14 @@
import QtQuick 2.6
MyButton {
- property string executable
+ property var appEntry
text.text: "Uninitialized"
text.elide: Text.ElideRight
text.maximumLineCount: 1
iconSize: 32
- onTriggered: launcher.launch(executable)
+ onTriggered: {
+ if (!launcher.isRunning(appEntry))
+ launcher.launch(appEntry)
+ }
}
diff --git a/wayland/democompositor/qml/Screen.qml b/wayland/democompositor/qml/Screen.qml
index 34fd090..ffb8490 100644
--- a/wayland/democompositor/qml/Screen.qml
+++ b/wayland/democompositor/qml/Screen.qml
@@ -53,11 +53,13 @@ import QtQuick.Window 2.2
import QtWayland.Compositor 1.0
import com.theqtcompany.wlprocesslauncher 1.0
+import com.theqtcompany.wlapplistmodel 1.0
WaylandOutput {
id: output
property alias surfaceArea: background
+ property alias appLauncher: launcher
property var windowList: [ ]
property int hiddenWindowCount
@@ -85,6 +87,13 @@ WaylandOutput {
id: launcher
}
+ AppListModel {
+ id: apps
+ }
+
+ Component.onCompleted: {
+ apps.addAndWatchDir("/data/user/democompositor/apps/")
+ }
Rectangle {
id: curtain
@@ -252,46 +261,20 @@ WaylandOutput {
height: 5
width: 1
}
- LaunchButton {
- height: 60
- width: sidebar.width - 10
- buttonColor: backgroundCol
- pressedColor: pressedCol
- textColor: textCol
- text.text: "Clocks"
- executable: "./clocks"
- icon.source: "qrc:/images/Icon_Clocks.png"
- }
- LaunchButton {
- height: 60
- width: sidebar.width - 10
- buttonColor: backgroundCol
- pressedColor: pressedCol
- textColor: textCol
- text.text: "RSS News"
- executable: "./rssnews"
- icon.source: "qrc:/images/Icon_RSS.png"
- }
- LaunchButton {
- height: 60
- width: sidebar.width - 10
- buttonColor: backgroundCol
- pressedColor: pressedCol
- textColor: textCol
- text.text: "StoQt"
- executable: "./stocqt"
- icon.source: "qrc:/images/Icon_StocQt.png"
- }
- LaunchButton {
- height: 60
- width: sidebar.width - 10
- buttonColor: backgroundCol
- pressedColor: pressedCol
- textColor: textCol
- text.text: "Maps"
- executable: "./qml_location_mapviewer"
- icon.source: "qrc:/images/Icon_Maps.png"
+ Repeater {
+ model: apps
+
+ LaunchButton {
+ height: 60
+ width: sidebar.width - 10
+ buttonColor: backgroundCol
+ pressedColor: pressedCol
+ textColor: textCol
+ text.text: model.applicationName
+ appEntry: model.appEntry
+ icon.source: model.iconName
+ }
}
TimedButton {
diff --git a/wayland/democompositor/qml/main.qml b/wayland/democompositor/qml/main.qml
index 8c0c621..75d1adc 100644
--- a/wayland/democompositor/qml/main.qml
+++ b/wayland/democompositor/qml/main.qml
@@ -57,6 +57,7 @@ WaylandCompositor {
property var primarySurfacesArea: null
Screen {
+ id: mainScreen
compositor: comp
}
@@ -69,6 +70,13 @@ WaylandCompositor {
WlShell {
id: defaultShell
onWlShellSurfaceCreated: {
+ const pid = shellSurface.surface.client.processId;
+ const appState = mainScreen.appLauncher.appStateForPid(pid);
+ if (!appState) {
+ console.log("shellSurface of unknown application. Continuing. PID=" + pid);
+ } else {
+ console.log("shellSurface belonging to " + appState.appEntry.executableName);
+ }
chromeComponent.createObject(defaultOutput.surfaceArea, { "shellSurface": shellSurface } );
defaultOutput.relayout();
}
diff --git a/wayland/democompositor/tests/applist/applist.pro b/wayland/democompositor/tests/applist/applist.pro
new file mode 100644
index 0000000..e253b66
--- /dev/null
+++ b/wayland/democompositor/tests/applist/applist.pro
@@ -0,0 +1,17 @@
+TARGET = tst_applistmodel
+QT = testlib
+CONFIG += testcase
+
+INCLUDEPATH += ../../apps
+
+HEADERS += \
+ ../../apps/appentry.h \
+ ../../apps/applistmodel.h
+
+SOURCES += \
+ ../../apps/appentry.cpp \
+ ../../apps/appparser.cpp \
+ ../../apps/applistmodel.cpp
+
+SOURCES += tst_applistmodel.cpp
+RESOURCES += applist.qrc
diff --git a/wayland/democompositor/tests/applist/applist.qrc b/wayland/democompositor/tests/applist/applist.qrc
new file mode 100644
index 0000000..04db642
--- /dev/null
+++ b/wayland/democompositor/tests/applist/applist.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file alias="app1.json">../../apps/files/clock.app</file>
+ <file alias="app2.json">../../apps/files/maps.app</file>
+</qresource>
+</RCC>
diff --git a/wayland/democompositor/tests/applist/tst_applistmodel.cpp b/wayland/democompositor/tests/applist/tst_applistmodel.cpp
new file mode 100644
index 0000000..921defc
--- /dev/null
+++ b/wayland/democompositor/tests/applist/tst_applistmodel.cpp
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "applistmodel.h"
+#include "appentry.h"
+
+#include <QtCore/QVariant>
+
+#include <QtTest>
+
+class tst_AppListModel : public QObject {
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testNoDuplicates();
+ void testRoles();
+};
+
+void tst_AppListModel::testNoDuplicates()
+{
+ AppListModel model;
+ QCOMPARE(model.rowCount(QModelIndex()), 0);
+ model.addFile(":/app1.json");
+ QCOMPARE(model.rowCount(QModelIndex()), 1);
+ model.addFile(":/app2.json");
+ QCOMPARE(model.rowCount(QModelIndex()), 2);
+ model.addFile(":/app1.json");
+ QCOMPARE(model.rowCount(QModelIndex()), 2);
+ model.addFile(":/app2.json");
+}
+
+void tst_AppListModel::testRoles()
+{
+ AppListModel model;
+ model.addFile(":/app1.json");
+
+ auto idx = model.index(1, 0);
+ QVERIFY(!idx.isValid());
+ idx = model.index(0, 0);
+ QVERIFY(idx.isValid());
+
+ /* Check we get a full AppEntry back */
+ auto var = idx.data(AppListModel::App);
+ QVERIFY(var.canConvert<AppEntry>());
+ auto app = var.value<AppEntry>();
+ QCOMPARE(app.sourceFileName, QStringLiteral(":/app1.json"));
+
+ var = idx.data(AppListModel::IconName);
+ QCOMPARE(var.toString(), QStringLiteral("qrc:/images/Icon_Clocks.png"));
+ var = idx.data(AppListModel::ApplicationName);
+ QCOMPARE(var.toString(), QStringLiteral("Clocks"));
+ var = idx.data(AppListModel::ExeuctableName);
+ QCOMPARE(var.toString(), QStringLiteral("clocks"));
+ var = idx.data(AppListModel::ExecutablePath);
+ QCOMPARE(var.toString(), QStringLiteral("./"));
+ var = idx.data(AppListModel::SourceFileName);
+ QCOMPARE(var.toString(), QStringLiteral(":/app1.json"));
+}
+
+QTEST_MAIN(tst_AppListModel)
+#include "tst_applistmodel.moc"
diff --git a/wayland/democompositor/tests/apps/apps.pro b/wayland/democompositor/tests/apps/apps.pro
new file mode 100644
index 0000000..21a6cfe
--- /dev/null
+++ b/wayland/democompositor/tests/apps/apps.pro
@@ -0,0 +1,15 @@
+TARGET = tst_apps
+QT = testlib
+CONFIG += testcase
+
+INCLUDEPATH += ../../apps
+
+HEADERS += \
+ ../../apps/appentry.h
+
+SOURCES += \
+ ../../apps/appentry.cpp \
+ ../../apps/appparser.cpp
+
+SOURCES += tst_appparser.cpp
+RESOURCES += apps.qrc
diff --git a/wayland/democompositor/tests/apps/apps.qrc b/wayland/democompositor/tests/apps/apps.qrc
new file mode 100644
index 0000000..07e0afe
--- /dev/null
+++ b/wayland/democompositor/tests/apps/apps.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file alias="app.json">../../apps/files/clock.app</file>
+</qresource>
+</RCC>
diff --git a/wayland/democompositor/tests/apps/tst_appparser.cpp b/wayland/democompositor/tests/apps/tst_appparser.cpp
new file mode 100644
index 0000000..6d63fd9
--- /dev/null
+++ b/wayland/democompositor/tests/apps/tst_appparser.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of Qt for Device Creation.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest>
+
+#include "appparser.h"
+
+class tst_AppParser : public QObject {
+ Q_OBJECT
+
+private Q_SLOTS:
+ void testValidVersion1_data();
+ void testValidVersion1();
+
+ void testInvalid_data();
+ void testInvalid();
+
+ void testFileOpen();
+};
+
+
+void tst_AppParser::testValidVersion1_data()
+{
+ QTest::addColumn<QByteArray>("input");
+ QTest::addColumn<QString>("icon");
+ QTest::addColumn<QString>("name");
+ QTest::addColumn<QString>("exec");
+ QTest::addColumn<QString>("path");
+
+ QTest::addRow("clock")
+ << QByteArray("{\"Type\":\"Application\", \"Version\":1, \"Icon\":\"icon\", \"Name\":\"Clocks\",\"Exec\":\"clocks\"}")
+ << QStringLiteral("icon") << QStringLiteral("Clocks") << QStringLiteral("clocks") << QString();
+ QTest::addRow("path")
+ << QByteArray("{\"Type\":\"Application\", \"Version\":1, \"Icon\":\"icon\", \"Name\":\"Clocks\",\"Exec\":\"clocks\",\"Path\":\"P\"}")
+ << QStringLiteral("icon") << QStringLiteral("Clocks") << QStringLiteral("clocks") << QStringLiteral("P");
+}
+
+void tst_AppParser::testValidVersion1()
+{
+ QFETCH(QByteArray, input);
+ QFETCH(QString, icon);
+ QFETCH(QString, name);
+ QFETCH(QString, exec);
+ QFETCH(QString, path);
+
+ bool ok = false;
+ auto entry = AppParser::parseData(input, QStringLiteral("dummy"), &ok);
+ QVERIFY(ok);
+}
+
+void tst_AppParser::testInvalid_data()
+{
+ QTest::addColumn<QByteArray>("input");
+ QTest::addRow("no json") << QByteArray("12345");
+ QTest::addRow("array") << QByteArray("[]");
+ QTest::addRow("no content") << QByteArray("{}");
+ QTest::addRow("empty") << QByteArray("");
+}
+
+void tst_AppParser::testInvalid()
+{
+ QFETCH(QByteArray, input);
+
+ bool ok = true;
+ AppParser::parseData(input, QStringLiteral("dummy"), &ok);
+ QVERIFY(!ok);
+}
+
+void tst_AppParser::testFileOpen()
+{
+ bool ok = true;
+
+ AppParser::parseFile(":/can_not_exist_here.json", &ok);
+ QVERIFY(!ok);
+
+ ok = false;
+ auto entry = AppParser::parseFile(":/app.json", &ok);
+ QVERIFY(ok);
+ QCOMPARE(entry.iconName, QStringLiteral("qrc:/images/Icon_Clocks.png"));
+ QCOMPARE(entry.appName, QStringLiteral("Clocks"));
+ QCOMPARE(entry.executableName, QStringLiteral("clocks"));
+ QCOMPARE(entry.executablePath, QStringLiteral("./"));
+}
+
+QTEST_MAIN(tst_AppParser)
+#include "tst_appparser.moc"