LCOV - code coverage report
Current view: top level - manager-lib - packagemanager.h (source / functions) Coverage Total Hit
Test: QtApplicationManager Lines: 100.0 % 1 1
Test Date: 2024-05-11 10:19:06 Functions: - 0 0
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 50.0 % 4 2

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2021 The Qt Company Ltd.
       2                 :             : // Copyright (C) 2019 Luxoft Sweden AB
       3                 :             : // Copyright (C) 2018 Pelagicore AG
       4                 :             : // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
       5                 :             : 
       6                 :             : #ifndef PACKAGEMANAGER_H
       7                 :             : #define PACKAGEMANAGER_H
       8                 :             : 
       9                 :             : #include <QtCore/QObject>
      10                 :             : #include <QtCore/QAbstractListModel>
      11                 :             : #include <QtAppManCommon/global.h>
      12                 :             : #include <QtAppManApplication/packageinfo.h>
      13                 :             : #include <QtAppManManager/asynchronoustask.h>
      14                 :             : 
      15                 :             : 
      16                 :             : QT_FORWARD_DECLARE_CLASS(QQmlEngine)
      17                 :             : QT_FORWARD_DECLARE_CLASS(QJSEngine)
      18                 :             : 
      19                 :             : QT_BEGIN_NAMESPACE_AM
      20                 :             : 
      21                 :             : class PackageDatabase;
      22                 :             : class Package;
      23                 :             : class PackageManagerPrivate;
      24                 :             : class InstallationTask;
      25                 :             : class DeinstallationTask;
      26                 :             : 
      27                 :             : // A place to collect signals used internally by appman without polluting
      28                 :             : // PackageManager's public QML API.
      29   [ +  -  +  - ]:         107 : class PackageManagerInternalSignals : public QObject
      30                 :             : {
      31                 :             :     Q_OBJECT
      32                 :             : Q_SIGNALS:
      33                 :             :     // the slots connected to these signals are allowed to throw Exception objects, if the
      34                 :             :     // connection is direct!
      35                 :             :     void registerApplication(QtAM::ApplicationInfo *applicationInfo,
      36                 :             :                              QtAM::Package *package);
      37                 :             :     void unregisterApplication(QtAM::ApplicationInfo *applicationInfo,
      38                 :             :                                QtAM::Package *package);
      39                 :             : 
      40                 :             :     void registerIntent(QtAM::IntentInfo *intentInfo,
      41                 :             :                         QtAM::Package *package);
      42                 :             :     void unregisterIntent(QtAM::IntentInfo *intentInfo,
      43                 :             :                           QtAM::Package *package);
      44                 :             : };
      45                 :             : 
      46                 :             : class PackageManager : public QAbstractListModel
      47                 :             : {
      48                 :             :     Q_OBJECT
      49                 :             :     Q_CLASSINFO("D-Bus Interface", "io.qt.PackageManager")
      50                 :             :     Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
      51                 :             :     // these are const on purpose - these should never change in a running system
      52                 :             :     Q_PROPERTY(bool allowInstallationOfUnsignedPackages READ allowInstallationOfUnsignedPackages CONSTANT FINAL)
      53                 :             :     Q_PROPERTY(bool developmentMode READ developmentMode CONSTANT FINAL)
      54                 :             :     Q_PROPERTY(QString hardwareId READ hardwareId CONSTANT FINAL)
      55                 :             :     Q_PROPERTY(QString architecture READ architecture CONSTANT FINAL)
      56                 :             : 
      57                 :             :     Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged FINAL)
      58                 :             :     Q_PROPERTY(QVariantMap installationLocation READ installationLocation CONSTANT FINAL)
      59                 :             :     Q_PROPERTY(QVariantMap documentLocation READ documentLocation CONSTANT FINAL)
      60                 :             : 
      61                 :             : public:
      62                 :             :     Q_ENUMS(QtAM::AsynchronousTask::TaskState)
      63                 :             : 
      64                 :             :     enum CacheMode {
      65                 :             :         NoCache,
      66                 :             :         UseCache,
      67                 :             :         RecreateCache
      68                 :             :     };
      69                 :             : 
      70                 :             :     ~PackageManager() override;
      71                 :             :     static PackageManager *createInstance(PackageDatabase *packageDatabase,
      72                 :             :                                           const QString &documentPath);
      73                 :             :     static PackageManager *instance();
      74                 :             : 
      75                 :             :     void enableInstaller();
      76                 :             :     void registerPackages();
      77                 :             : 
      78                 :             :     QVector<Package *> packages() const;
      79                 :             : 
      80                 :             :     Package *fromId(const QString &id) const;
      81                 :             :     QVariantMap get(Package *package) const;
      82                 :             : 
      83                 :             :     // the item model part
      84                 :             :     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
      85                 :             :     QVariant data(const QModelIndex &index, int role) const override;
      86                 :             :     QVariant dataForRole(Package *package, int role) const;
      87                 :             :     QHash<int, QByteArray> roleNames() const override;
      88                 :             : 
      89                 :             :     int count() const;
      90                 :             :     Q_INVOKABLE QVariantMap get(int index) const;
      91                 :             :     Q_INVOKABLE QtAM::Package *package(int index) const;
      92                 :             :     Q_INVOKABLE QtAM::Package *package(const QString &id) const;
      93                 :             :     Q_INVOKABLE int indexOfPackage(const QString &id) const;
      94                 :             : 
      95                 :             :     bool isReady() const;
      96                 :             : 
      97                 :             :     bool developmentMode() const;
      98                 :             :     void setDevelopmentMode(bool enable);
      99                 :             :     bool allowInstallationOfUnsignedPackages() const;
     100                 :             :     void setAllowInstallationOfUnsignedPackages(bool enable);
     101                 :             :     QString hardwareId() const;
     102                 :             :     void setHardwareId(const QString &hwId);
     103                 :             :     QString architecture() const;
     104                 :             :     void setCACertificates(const QByteArrayList &chainOfTrust);
     105                 :             : 
     106                 :             :     void cleanupBrokenInstallations() noexcept(false);
     107                 :             : 
     108                 :             :     QVariantMap installationLocation() const;
     109                 :             :     QVariantMap documentLocation() const;
     110                 :             : 
     111                 :             :     bool isPackageInstallationActive(const QString &packageId) const;
     112                 :             : 
     113                 :             :     // Q_SCRIPTABLEs are available via both QML and D-Bus
     114                 :             :     Q_SCRIPTABLE QStringList packageIds() const;
     115                 :             :     Q_SCRIPTABLE QVariantMap get(const QString &packageId) const;
     116                 :             : 
     117                 :             :     Q_SCRIPTABLE qint64 installedPackageSize(const QString &packageId) const;
     118                 :             :     Q_SCRIPTABLE QVariantMap installedPackageExtraMetaData(const QString &packageId) const;
     119                 :             :     Q_SCRIPTABLE QVariantMap installedPackageExtraSignedMetaData(const QString &packageId) const;
     120                 :             : 
     121                 :             :     // all QString return values are task-ids
     122                 :             :     QString startPackageInstallation(const QUrl &sourceUrl);
     123                 :             :     Q_SCRIPTABLE QString startPackageInstallation(const QString &sourceUrl);
     124                 :             :     Q_SCRIPTABLE void acknowledgePackageInstallation(const QString &taskId);
     125                 :             :     Q_SCRIPTABLE QString removePackage(const QString &id, bool keepDocuments, bool force = false);
     126                 :             : 
     127                 :             :     Q_SCRIPTABLE QtAM::AsynchronousTask::TaskState taskState(const QString &taskId) const;
     128                 :             :     Q_SCRIPTABLE QString taskPackageId(const QString &taskId) const;
     129                 :             :     Q_SCRIPTABLE QStringList activeTaskIds() const;
     130                 :             :     Q_SCRIPTABLE bool cancelTask(const QString &taskId);
     131                 :             : 
     132                 :             :     // convenience function for app-store implementations
     133                 :             :     Q_SCRIPTABLE int compareVersions(const QString &version1, const QString &version2);
     134                 :             :     Q_SCRIPTABLE bool validateDnsName(const QString &name, int minimumParts = 1);
     135                 :             : 
     136                 :             :     PackageManagerInternalSignals internalSignals;
     137                 :             : 
     138                 :             : Q_SIGNALS:
     139                 :             :     Q_SCRIPTABLE void readyChanged(bool b);
     140                 :             :     Q_SCRIPTABLE void countChanged();
     141                 :             : 
     142                 :             :     Q_SCRIPTABLE void packageAdded(const QString &id);
     143                 :             :     Q_SCRIPTABLE void packageAboutToBeRemoved(const QString &id);
     144                 :             :     Q_SCRIPTABLE void packageChanged(const QString &id, const QStringList &changedRoles);
     145                 :             : 
     146                 :             :     Q_SCRIPTABLE void taskStarted(const QString &taskId);
     147                 :             :     Q_SCRIPTABLE void taskProgressChanged(const QString &taskId, qreal progress);
     148                 :             :     Q_SCRIPTABLE void taskFinished(const QString &taskId);
     149                 :             :     Q_SCRIPTABLE void taskFailed(const QString &taskId, int errorCode, const QString &errorString);
     150                 :             :     Q_SCRIPTABLE void taskStateChanged(const QString &taskId,
     151                 :             :                                        QtAM::AsynchronousTask::TaskState newState);
     152                 :             : 
     153                 :             :     // installation only
     154                 :             :     void taskRequestingInstallationAcknowledge(const QString &taskId,
     155                 :             :                                                QtAM::Package *package,
     156                 :             :                                                const QVariantMap &packageExtraMetaData,
     157                 :             :                                                const QVariantMap &packageExtraSignedMetaData);
     158                 :             :     Q_SCRIPTABLE void taskBlockingUntilInstallationAcknowledge(const QString &taskId);
     159                 :             : 
     160                 :             : protected:
     161                 :             :     Package *startingPackageInstallation(PackageInfo *info);
     162                 :             :     bool startingPackageRemoval(const QString &id);
     163                 :             :     bool finishedPackageInstall(const QString &id);
     164                 :             :     bool canceledPackageInstall(const QString &id);
     165                 :             : 
     166                 :             : private:
     167                 :             :     void executeNextTask();
     168                 :             :     void triggerExecuteNextTask();
     169                 :             :     QString enqueueTask(AsynchronousTask *task);
     170                 :             :     void handleFailure(AsynchronousTask *task);
     171                 :             : 
     172                 :             : private:
     173                 :             :     void emitDataChanged(Package *package, const QVector<int> &roles = QVector<int>());
     174                 :             :     Package *registerPackage(PackageInfo *packageInfo, PackageInfo *updatedPackageInfo,
     175                 :             :                              bool currentlyBeingInstalled = false);
     176                 :             :     void registerApplicationsAndIntentsOfPackage(Package *package);
     177                 :             :     void unregisterApplicationsAndIntentsOfPackage(Package *package);
     178                 :             :     static void registerQmlTypes();
     179                 :             :     QByteArrayList caCertificates() const;
     180                 :             : 
     181                 :             : private:
     182                 :             :     explicit PackageManager(PackageDatabase *packageDatabase,
     183                 :             :                             const QString &documentPath);
     184                 :             :     PackageManager(const PackageManager &);
     185                 :             :     PackageManager &operator=(const PackageManager &);
     186                 :             :     static PackageManager *s_instance;
     187                 :             :     static QHash<int, QByteArray> s_roleNames;
     188                 :             : 
     189                 :             :     PackageManagerPrivate *d;
     190                 :             : 
     191                 :             :     friend class InstallationTask;
     192                 :             :     friend class DeinstallationTask;
     193                 :             : };
     194                 :             : 
     195                 :             : QT_END_NAMESPACE_AM
     196                 :             : 
     197                 :             : #endif // PACKAGEMANAGER_H
        

Generated by: LCOV version 2.0-1