summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@qt.io>2020-02-13 14:50:03 +0100
committerRobert Griebl <robert.griebl@qt.io>2020-02-17 17:02:20 +0100
commit9f518a90f5549a770f16c3c9cd72e72403f7231b (patch)
tree6ff8db9dc8c7e9d949a42955e3782a1b0b76d07a
parentf3209dd2b71f7c6f78b70dd1035206d66c51a789 (diff)
downloadqtapplicationmanager-9f518a90f5549a770f16c3c9cd72e72403f7231b.tar.gz
Add properties to allow cross-referencing between Package and Application
Change-Id: Ia4b3688b2eb270905c37c726aa80474c4336de4b Fixes: AUTOSUITE-1470 Reviewed-by: Dominik Holland <dominik.holland@qt.io>
-rw-r--r--qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes1
-rw-r--r--src/manager-lib/application.h1
-rw-r--r--src/manager-lib/applicationmanager.cpp5
-rw-r--r--src/manager-lib/package.cpp25
-rw-r--r--src/manager-lib/package.h9
-rw-r--r--tests/qml/simple/tst_applicationmanager.qml9
6 files changed, 50 insertions, 0 deletions
diff --git a/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes b/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes
index e928f053..3ba0deef 100644
--- a/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes
+++ b/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes
@@ -510,6 +510,7 @@ Module {
Property { name: "lastExitStatus"; type: "ExitStatus"; isReadonly: true }
Property { name: "codeDir"; type: "string"; isReadonly: true }
Property { name: "runState"; type: "RunState"; isReadonly: true }
+ Property { name: "package"; type: "Package"; isPointer: true; isReadonly: true }
Property { name: "icon"; type: "QUrl"; isReadonly: true }
Property { name: "builtIn"; type: "bool"; isReadonly: true }
Property { name: "alias"; type: "bool"; isReadonly: true }
diff --git a/src/manager-lib/application.h b/src/manager-lib/application.h
index 6edb33cf..aa686c4a 100644
--- a/src/manager-lib/application.h
+++ b/src/manager-lib/application.h
@@ -85,6 +85,7 @@ class Application : public QObject
Q_PROPERTY(QT_PREPEND_NAMESPACE_AM(Am::ExitStatus) lastExitStatus READ lastExitStatus NOTIFY lastExitStatusChanged)
Q_PROPERTY(QString codeDir READ codeDir NOTIFY bulkChange)
Q_PROPERTY(QT_PREPEND_NAMESPACE_AM(Am::RunState) runState READ runState NOTIFY runStateChanged)
+ Q_PROPERTY(Package *package READ package CONSTANT)
// legacy, forwarded to Package
Q_PROPERTY(QUrl icon READ icon NOTIFY bulkChange)
diff --git a/src/manager-lib/applicationmanager.cpp b/src/manager-lib/applicationmanager.cpp
index 5a391185..0911126f 100644
--- a/src/manager-lib/applicationmanager.cpp
+++ b/src/manager-lib/applicationmanager.cpp
@@ -76,6 +76,7 @@
#include "qtyaml.h"
#include "debugwrapper.h"
#include "amnamespace.h"
+#include "package.h"
/*!
\qmltype ApplicationManager
@@ -1417,6 +1418,8 @@ void ApplicationManager::addApplication(ApplicationInfo *appInfo, Package *packa
endInsertRows();
registerMimeTypes();
+
+ package->addApplication(app);
emit applicationAdded(appInfo->id());
}
@@ -1437,6 +1440,8 @@ void ApplicationManager::removeApplication(ApplicationInfo *appInfo, Package *pa
emit applicationAboutToBeRemoved(appInfo->id());
+ package->removeApplication(d->apps.at(index));
+
beginRemoveRows(QModelIndex(), index, index);
auto app = d->apps.takeAt(index);
diff --git a/src/manager-lib/package.cpp b/src/manager-lib/package.cpp
index 4835e378..2ca2a690 100644
--- a/src/manager-lib/package.cpp
+++ b/src/manager-lib/package.cpp
@@ -46,6 +46,7 @@
#include "package.h"
#include "packageinfo.h"
#include "applicationinfo.h"
+#include "application.h"
/*!
\qmltype PackageObject
@@ -245,6 +246,18 @@ QStringList Package::categories() const
return info()->categories();
}
+QList<QObject *> Package::applications() const
+{
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+ QList<QObject *> result;
+ for (auto app : m_applications)
+ result << app;
+ return result;
+#else
+ return QList<QObject *>(m_applications.cbegin(), m_applications.cend());
+#endif
+}
+
QUrl Package::icon() const
{
if (info()->icon().isEmpty())
@@ -362,4 +375,16 @@ bool Package::areAllApplicationsStoppedDueToBlock() const
return isBlocked() && !m_blockedAppsCount;
}
+void Package::addApplication(Application *application)
+{
+ m_applications.append(application);
+ emit applicationsChanged();
+}
+
+void Package::removeApplication(Application *application)
+{
+ m_applications.removeAll(application);
+ emit applicationsChanged();
+}
+
QT_END_NAMESPACE_AM
diff --git a/src/manager-lib/package.h b/src/manager-lib/package.h
index d8513bb1..2890383a 100644
--- a/src/manager-lib/package.h
+++ b/src/manager-lib/package.h
@@ -52,6 +52,7 @@
QT_BEGIN_NAMESPACE_AM
+class Application;
class Package : public QObject
{
@@ -69,6 +70,7 @@ class Package : public QObject
Q_PROPERTY(QStringList categories READ categories NOTIFY bulkChange)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(bool blocked READ isBlocked NOTIFY blockedChanged)
+ Q_PROPERTY(QList<QObject *> applications READ applications NOTIFY applicationsChanged)
public:
enum State {
@@ -92,6 +94,7 @@ public:
QString description() const;
QVariantMap descriptions() const;
QStringList categories() const;
+ QList<QObject *> applications() const;
State state() const { return m_state; }
qreal progress() const { return m_progress; }
@@ -130,10 +133,15 @@ public:
// query function for the installer to verify that it is safe to manipulate binaries
bool areAllApplicationsStoppedDueToBlock() const;
+ // for the ApplicationManager to update the package -> application mapping
+ void addApplication(Application *application);
+ void removeApplication(Application *application);
+
signals:
void bulkChange();
void stateChanged(State state);
void blockedChanged(bool blocked);
+ void applicationsChanged();
private:
PackageInfo *m_info = nullptr;
@@ -144,6 +152,7 @@ private:
QAtomicInt m_blocked;
QAtomicInt m_blockedAppsCount;
QVector<ApplicationInfo *> m_blockedApps;
+ QVector<Application *> m_applications;
};
QT_END_NAMESPACE_AM
diff --git a/tests/qml/simple/tst_applicationmanager.qml b/tests/qml/simple/tst_applicationmanager.qml
index 53f999a2..f7c45435 100644
--- a/tests/qml/simple/tst_applicationmanager.qml
+++ b/tests/qml/simple/tst_applicationmanager.qml
@@ -123,6 +123,15 @@ TestCase {
compare(ApplicationManager.systemProperties.nullTest, null)
}
+ function test_package() {
+ compare(PackageManager.count, 2)
+ verify(simpleApplication.package !== capsApplication.package)
+ compare(simpleApplication.package, PackageManager.package("tld.test.simple1"))
+ compare(simpleApplication.package.id, "tld.test.simple1")
+ compare(simpleApplication.package.applications.length, 1)
+ compare(simpleApplication.package.applications[0], simpleApplication)
+ }
+
function test_application() {
var id = simpleApplication.id;
compare(simpleApplication.id, "tld.test.simple1")