diff options
author | Robert Griebl <robert.griebl@qt.io> | 2022-06-10 18:11:26 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2022-06-13 14:54:25 +0000 |
commit | 6f0b7f34d1f235d7c5d51b43fa51abde2bb1e313 (patch) | |
tree | e08e2d2aaa3ff4765a472937bd6893989d2f02ed | |
parent | 41d22d80ed30d8491bd1b3b86a21c637002a23c4 (diff) | |
download | qtapplicationmanager-6f0b7f34d1f235d7c5d51b43fa51abde2bb1e313.tar.gz |
Add a new 'ready' property to the PackageManager
If a project is using the new applications/installationDirMountPoint
config option which might delay loading the package database, it also
needs a signal to tell it when that database is in a consistent state.
Change-Id: I4b250f08c6dade2c675c3b742fe663afd992c1bd
Reviewed-by: Dominik Holland <dominik.holland@qt.io>
(cherry picked from commit d7a64b2163a00330ddb8d84eb0ab6c4c8261e0e9)
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r-- | qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes | 5 | ||||
-rw-r--r-- | src/manager-lib/packagemanager.cpp | 22 | ||||
-rw-r--r-- | src/manager-lib/packagemanager.h | 4 |
3 files changed, 31 insertions, 0 deletions
diff --git a/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes b/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes index b40c8b33..d9970045 100644 --- a/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes +++ b/qmltypes/QtApplicationManager/SystemUI/plugins.qmltypes @@ -665,11 +665,16 @@ Module { Property { name: "allowInstallationOfUnsignedPackages"; type: "bool"; isReadonly: true } Property { name: "developmentMode"; type: "bool"; isReadonly: true } Property { name: "hardwareId"; type: "string"; isReadonly: true } + Property { name: "ready"; type: "bool"; isReadonly: true } Property { name: "installationLocation"; type: "QVariantMap"; isReadonly: true } Property { name: "documentLocation"; type: "QVariantMap"; isReadonly: true } Property { name: "applicationUserIdSeparation"; type: "bool"; isReadonly: true } Property { name: "commonApplicationGroupId"; type: "uint"; isReadonly: true } Signal { + name: "readyChanged" + Parameter { name: "b"; type: "bool"; } + } + Signal { name: "countChanged" } Signal { diff --git a/src/manager-lib/packagemanager.cpp b/src/manager-lib/packagemanager.cpp index c174665f..7243a035 100644 --- a/src/manager-lib/packagemanager.cpp +++ b/src/manager-lib/packagemanager.cpp @@ -85,6 +85,10 @@ application manager's \l{Configuration} will just lead to package (de-) installations failing instantly. + Please be aware that setting the \c{applications/installationDirMountPoint} configuration + option might delay the initialization of the package database. In this case, make sure to check + that the \l ready property is \c true before interacting with the PackageManager. + The type is derived from \c QAbstractListModel, so it can be used directly as a model from QML. \target PackageManager Roles @@ -379,6 +383,8 @@ void PackageManager::registerPackages() // now that we have a consistent pkg db, we can clean up the installed packages cleanupBrokenInstallations(); + emit readyChanged(d->cleanupBrokenInstallationsDone); + #if !defined(AM_DISABLE_INSTALLER) // something might have been queued already before the cleanup had finished triggerExecuteNextTask(); @@ -674,6 +680,22 @@ int PackageManager::indexOfPackage(const QString &id) const return -1; } +/*! + \qmlproperty bool PackageManager::ready + + Loading the package database might be delayed at startup if the + \c{applications/installationDirMountPoint} configuration option is set. + + If your system is relying on this behavior, you should always check if the \l ready property is + \c true before accessing information about installed packages. + \note Calls to startPackageInstallation() and removePackage() while ready is still \c false + will be queued and executed once the package database is fully loaded. +*/ +bool PackageManager::isReady() const +{ + return d->cleanupBrokenInstallationsDone; +} + bool PackageManager::developmentMode() const { return d->developmentMode; diff --git a/src/manager-lib/packagemanager.h b/src/manager-lib/packagemanager.h index 4be96f5d..befeefbd 100644 --- a/src/manager-lib/packagemanager.h +++ b/src/manager-lib/packagemanager.h @@ -90,6 +90,7 @@ class PackageManager : public QAbstractListModel Q_PROPERTY(bool developmentMode READ developmentMode CONSTANT) Q_PROPERTY(QString hardwareId READ hardwareId CONSTANT) + Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged) Q_PROPERTY(QVariantMap installationLocation READ installationLocation CONSTANT) Q_PROPERTY(QVariantMap documentLocation READ documentLocation CONSTANT) @@ -131,6 +132,8 @@ public: Q_INVOKABLE Package *package(const QString &id) const; Q_INVOKABLE int indexOfPackage(const QString &id) const; + bool isReady() const; + bool developmentMode() const; void setDevelopmentMode(bool enable); bool allowInstallationOfUnsignedPackages() const; @@ -180,6 +183,7 @@ public: PackageManagerInternalSignals internalSignals; signals: + Q_SCRIPTABLE void readyChanged(bool b); Q_SCRIPTABLE void countChanged(); Q_SCRIPTABLE void packageAdded(const QString &id); |