summaryrefslogtreecommitdiffstats
path: root/src/main-lib/applicationinstaller.cpp
blob: 0f156f2a2837551bd1667d79deb943ea2987c198 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2019 Luxoft Sweden AB
** Copyright (C) 2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtApplicationManager module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** 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.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QCoreApplication>
#include <qqml.h>
#include <QQmlEngine>

#include "applicationinstaller.h"


/*!
    \qmltype ApplicationInstaller
    \inqmlmodule QtApplicationManager.SystemUI
    \ingroup system-ui-singletons
    \brief (obsolete) The package installation/removal/update part of the application manager.

    \b{This class is obsolete since 5.14. It is provided to keep old source code working. We
    strongly advise against using it in new code. Use the new PackageManager instead.}

    Please be aware that the new PackageManager API expects package-IDs instead of application-IDs
    as is the case with this class. Since the new package format adds support for more than one
    application per package, this legacy API here has its limits in supporting the new features.
    It is strongly advised to only use the PackageManager API when dealing with new-style packages.

    The background tasks handling the (de)installation process are the same between the old and
    new API, so the documentation for the \l{Task States}{task states in PackageManager}
    holds true for this class as well.

    If possible, all function calls and signals are forwarded to and from the PackageManager API.
    Exceptions are documented below in the detailed function and signal descriptions.

    \note The ApplicationInstaller singleton and its corresponding DBus API are only available if
          you specify a base directory for installed application manifests. See \l{Configuration}
          for details.
*/

/*!
    \qmlsignal ApplicationInstaller::taskStateChanged(string taskId, string newState)
    \qmlobsolete

    Use PackageManager::taskStateChanged(\a taskId, \a newState).
*/

/*!
    \qmlsignal ApplicationInstaller::taskStarted(string taskId)
    \qmlobsolete

    Use PackageManager::taskStarted(\a taskId).
*/

/*!
    \qmlsignal ApplicationInstaller::taskFinished(string taskId)
    \qmlobsolete

    Use PackageManager::taskFinished(\a taskId).
*/

/*!
    \qmlsignal ApplicationInstaller::taskFailed(string taskId)
    \qmlobsolete

    Use PackageManager::taskFailed(\a taskId).
*/

/*!
    \qmlsignal ApplicationInstaller::taskRequestingInstallationAcknowledge(string taskId, object application, object packageExtraMetaData, object packageExtraSignedMetaData)
    \qmlobsolete

    Use PackageManager::taskRequestingInstallationAcknowledge(\a taskId, \c package, \a
    packageExtraMetaData, \a packageExtraSignedMetaData).

    A subset of the contents of the package's manifest file is supplied via \a application as a
    JavaScript object. This object is constructed from the replacement function's Package object
    parameter. Since the manifest files changed in 5.14, only the following legacy keys are reported
    through this object: \c id, \c version, \c icon, \c displayIcon, \c name, \c displayName,
    \c baseDir, \c codeDir, \c manifestDir and \c installationLocationId.
*/

/*!
    \qmlsignal ApplicationInstaller::taskBlockingUntilInstallationAcknowledge(string taskId)
    \qmlobsolete

    Use PackageManager::taskBlockingUntilInstallationAcknowledge(\a taskId).
*/

/*!
    \qmlsignal ApplicationInstaller::taskProgressChanged(string taskId, qreal progress)
    \qmlobsolete

    Use PackageManager::taskProgressChanged(\a taskId, \a progress).
*/

QT_BEGIN_NAMESPACE_AM

ApplicationInstaller *ApplicationInstaller::s_instance = nullptr;

ApplicationInstaller::ApplicationInstaller(PackageManager *pm, QObject *parent)
    : QObject(parent)
    , m_pm(pm)
{
#if !defined(AM_DISABLE_INSTALLER)
    // connect the APIs of the PackageManager and ApplicationInstaller
    QObject::connect(pm, &PackageManager::taskProgressChanged,
                     this, &ApplicationInstaller::taskProgressChanged);
    QObject::connect(pm, &PackageManager::taskStarted,
                     this, &ApplicationInstaller::taskStarted);
    QObject::connect(pm, &PackageManager::taskFinished,
                     this, &ApplicationInstaller::taskFinished);
    QObject::connect(pm, &PackageManager::taskFailed,
                     this, &ApplicationInstaller::taskFailed);
    QObject::connect(pm, &PackageManager::taskStateChanged,
                     this, &ApplicationInstaller::taskStateChanged);
    QObject::connect(pm, &PackageManager::taskRequestingInstallationAcknowledge,
                     this, [this](const QString &taskId, Package *package,
                     const QVariantMap &packageExtraMetaData,
                     const QVariantMap &packageExtraSignedMetaData) {
        QVariantMap nameMap;
        auto names = package->names();
        for (auto it = names.constBegin(); it != names.constEnd(); ++it)
            nameMap.insert(it.key(), it.value());

        QString baseDir = package->info()->baseDir().absolutePath();

        QVariantMap applicationData {
            { qSL("id"), package->id() },
            { qSL("version"), package->version() },
            { qSL("icon"), package->icon() },
            { qSL("displayIcon"), package->icon() },             // 1.0 compatibility
            { qSL("name"), nameMap },
            { qSL("displayName"), nameMap },                     // 1.0 compatibility
            { qSL("baseDir"), baseDir },
            { qSL("codeDir"), baseDir },                         // 5.12 compatibility
            { qSL("manifestDir"), baseDir },                     // 5.12 compatibility
            { qSL("installationLocationId"), qSL("internal-0") } // 5.13 compatibility
        };

        emit taskRequestingInstallationAcknowledge(taskId, applicationData, packageExtraMetaData,
                                                   packageExtraSignedMetaData);
    });
    QObject::connect(pm, &PackageManager::taskBlockingUntilInstallationAcknowledge,
                     this, &ApplicationInstaller::taskBlockingUntilInstallationAcknowledge);
#endif
}

ApplicationInstaller::~ApplicationInstaller()
{
    s_instance = nullptr;
}

ApplicationInstaller *ApplicationInstaller::createInstance(PackageManager *pm)
{
    if (Q_UNLIKELY(s_instance))
        qFatal("ApplicationInstaller::createInstance() was called a second time.");


    qmlRegisterSingletonType<ApplicationInstaller>("QtApplicationManager.SystemUI", 2, 0, "ApplicationInstaller",
                                                   &ApplicationInstaller::instanceForQml);

    return s_instance = new ApplicationInstaller(pm, QCoreApplication::instance());
}

ApplicationInstaller *ApplicationInstaller::instance()
{
    if (!s_instance)
        qFatal("ApplicationInstaller::instance() was called before createInstance().");
    return s_instance;
}

QObject *ApplicationInstaller::instanceForQml(QQmlEngine *, QJSEngine *)
{
    QQmlEngine::setObjectOwnership(instance(), QQmlEngine::CppOwnership);
    return instance();
}

/*!
    \qmlmethod list<string> ApplicationInstaller::installationLocationIds()
    \qmlobsolete

    This function became obsolete, because the new architecture only supports one single
    installation location: it now always returns \c internal-0.
*/

/*!
    \qmlmethod string ApplicationInstaller::installationLocationIdFromApplication(string id)
    \qmlobsolete

    This function became obsolete, because the new architecture only supports one single
    installation location: it now always returns \c internal-0 if the application identified by
    \a id is installed or an empty string otherwise.
*/

/*!
    \qmlmethod object ApplicationInstaller::getInstallationLocation(string installationLocationId)
    \qmlobsolete

    This function became obsolete, because the new architecture only supports one single
    installation location (\c internal-0).

    Returns an empty object in case the \a installationLocationId is not valid.
*/

/*!
    \qmlmethod int ApplicationInstaller::installedApplicationSize(string id)
    \qmlobsolete

    Use PackageManager::installedPackageSize(), same return value.

    \note The replacement function PackageManager::installedPackageSize expects a
          \b package-ID as parameter, while this function wants an \b application-ID as \a id.
*/

/*!
    \qmlmethod var ApplicationInstaller::installedApplicationExtraMetaData(string id)
    \qmlobsolete

    Use PackageManager::installedPackageExtraMetaData(), same return value.

    \note The replacement function PackageManager::installedPackageExtraMetaData expects a
          \b package-ID as parameter, while this function wants an \b application-ID as \a id.
*/

/*!
    \qmlmethod var ApplicationInstaller::installedApplicationExtraSignedMetaData(string id)
    \qmlobsolete

    Use PackageManager::installedPackageExtraSignedMetaData(), same return value.

    \note The replacement function PackageManager::installedPackageExtraSignedMetaData expects a
          \b package-ID as parameter, while this function wants an \b application-ID as \a id.
*/

/*!
    \qmlmethod string ApplicationInstaller::startPackageInstallation(string installationLocationId, string sourceUrl)
    \qmlobsolete

    Use PackageManager::startPackageInstallation(\a sourceUrl), same return value.

    \note The replacement function PackageManager::startPackageInstallation is missing the first
          parameter (\a installationLocationId). This became obsolete, because the new architecture
          only supports one single installation location.
*/

/*!
    \qmlmethod void ApplicationInstaller::acknowledgePackageInstallation(string taskId)
    \qmlobsolete

    Use PackageManager::acknowledgePackageInstallation(\a taskId).
*/

/*!
    \qmlmethod string ApplicationInstaller::removePackage(string id, bool keepDocuments, bool force)
    \qmlobsolete

    Use PackageManager::removePackage(\c packageId, \a keepDocuments, \a force), same return value.

    \note The replacement function PackageManager::removePackage expects a \b package-ID as
          parameter, while this function wants an \b application-ID as \a id.
*/

/*!
    \qmlmethod enumeration ApplicationInstaller::taskState(string taskId)
    \qmlobsolete

    Use PackageManager::taskState(\a taskId), same return value.
*/

/*!
    \qmlmethod string ApplicationInstaller::taskApplicationId(string taskId)
    \qmlobsolete

    Use PackageManager::taskPackageId(\a taskId).

    \note The replacement function PackageManager::taskPackageId returns an \b package-ID,
          while this function returns an \b application-ID.
*/


/*!
    \qmlmethod list<string> ApplicationInstaller::activeTaskIds()
    \qmlobsolete

    Use PackageManager::activeTaskIds(), same return value.
*/

/*!
    \qmlmethod bool ApplicationInstaller::cancelTask(string taskId)
    \qmlobsolete

    Use PackageManager::cancelTask(\a taskId), same return value.
*/

/*!
    \qmlmethod int ApplicationInstaller::compareVersions(string version1, string version2)
    \qmlobsolete

    Use PackageManager::compareVersions(\a version1, \a version2), same return value.
*/

/*!
    \qmlmethod int ApplicationInstaller::validateDnsName(string name, int minimalPartCount)
    \qmlobsolete

    Use PackageManager::validateDnsName(\a name, \a minimalPartCount), same return value.
*/

QT_END_NAMESPACE_AM

#include "moc_applicationinstaller.cpp"