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
337
338
339
340
341
342
343
344
345
|
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2019 Luxoft Sweden AB
// Copyright (C) 2018 Pelagicore AG
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QLocale>
#include "package.h"
#include "packageinfo.h"
#include "applicationinfo.h"
#include "application.h"
#include "utilities.h"
/*!
\qmltype PackageObject
\inqmlmodule QtApplicationManager.SystemUI
\ingroup system-ui-non-instantiable
\brief The handle for a package known to the application manager.
Each instance of this class represents a single package known to the application manager.
Most of the read-only properties map directly to values read from the package's
\c info.yaml file - these are documented in the \l{Manifest Definition}.
Items of this type are not creatable from QML code. Only functions and properties of
PackageManager will return pointers to this class.
Make sure to \b not save references to a PackageObject across function calls: packages can
be deinstalled at any time, invalidating your reference. In case you do need a persistent
handle, use the id string.
*/
/*!
\qmlproperty string PackageObject::id
\readonly
This property returns the unique id of the package.
*/
/*!
\qmlproperty bool PackageObject::builtIn
\readonly
This property describes, if this package is part of the built-in set of packages of the
current System UI.
*/
/*!
\qmlproperty bool PackageObject::builtInHasRemovableUpdate
\readonly
This property describes, if this package is part of the built-in set of packages of the
current System UI \b and if there is currently an update installed that shadows the original
built-in package contents.
\sa builtIn
*/
/*!
\qmlproperty url PackageObject::icon
\readonly
The URL of the package's icon - can be used as the source property of an \l Image.
*/
/*!
\qmlproperty string PackageObject::version
\readonly
Holds the version of the package as a string.
*/
/*!
\qmlproperty string PackageObject::name
\readonly
Returns the localized name of the package - as provided in the info.yaml file - in the currently
active locale.
This is a convenience property, that takes the mapping returned by the \l names property,
and then tries to return the value for these keys if available: first the current locale's id,
then \c en_US, then \c en and lastly the first available key.
If no mapping is available, this will return the \l id.
*/
/*!
\qmlproperty var PackageObject::names
\readonly
Returns an object with all the language code to localized name mappings as provided in the
package's info.yaml file.
*/
/*!
\qmlproperty string PackageObject::description
\readonly
Returns the localized description of the package - as provided in the info.yaml file - in the
currently active locale.
This property uses the same algorithm as the \l name property, but for the description.
*/
/*!
\qmlproperty var PackageObject::descriptions
\readonly
Returns an object with all the language code to localized description mappings as provided in
the package's info.yaml file.
*/
/*!
\qmlproperty list<string> PackageObject::categories
\readonly
A list of category names the package should be associated with. This is mainly for the
automated app-store uploads as well as displaying the package within a fixed set of
categories in the System UI.
*/
/*!
\qmlproperty enumeration PackageObject::state
\readonly
This property holds the current installation state of the package. It can be one of:
\list
\li PackageObject.Installed - The package is completely installed and ready to be used.
\li PackageObject.BeingInstalled - The package is currently in the process of being installed.
\li PackageObject.BeingUpdated - The package is currently in the process of being updated.
\li PackageObject.BeingDowngraded - The package is currently in the process of being downgraded.
That can only happen for a built-in package that was previously
upgraded. It will then be brought back to its original, built-in,
version and its state will go back to PackageObject.Installed.
\li PackageObject.BeingRemoved - The package is currently in the process of being removed.
\endlist
*/
/*!
\qmlproperty bool PackageObject::blocked
\readonly
Describes if this package is currently blocked: being blocked means that all applications in
the package are stopped and are prevented from being started while in this state.
This is normally only the case while an update is being applied.
*/
/*!
\qmlproperty list<ApplicationObject> PackageObject::applications
\readonly
Returns a list of ApplicationObjects that are part of this package.
*/
QT_BEGIN_NAMESPACE_AM
Package::Package(PackageInfo *packageInfo, State initialState)
: m_info(packageInfo)
, m_state(initialState)
{
// calling block() would lead to the AM waiting for the not-yet installed apps to quit
if (initialState == BeingInstalled)
m_blocked = 1;
}
QString Package::id() const
{
return info()->id();
}
bool Package::isBuiltIn() const
{
return m_info->isBuiltIn();
}
bool Package::builtInHasRemovableUpdate() const
{
return isBuiltIn() && m_updatedInfo;
}
QString Package::version() const
{
return info()->version();
}
QString Package::name() const
{
return translateFromMap(info()->names(), id());
}
QVariantMap Package::names() const
{
QVariantMap names;
const auto nmap = info()->names();
for (auto it = nmap.cbegin(); it != nmap.cend(); ++it)
names.insert(it.key(), it.value());
return names;
}
QString Package::description() const
{
return translateFromMap(info()->descriptions());
}
QVariantMap Package::descriptions() const
{
QVariantMap descriptions;
const auto dmap = info()->descriptions();
for (auto it = dmap.cbegin(); it != dmap.cend(); ++it)
descriptions.insert(it.key(), it.value());
return descriptions;
}
QStringList Package::categories() const
{
return info()->categories();
}
QVector<Application *> Package::applications() const
{
return m_applications;
}
QUrl Package::icon() const
{
if (info()->icon().isEmpty())
return QUrl();
QDir dir;
switch (state()) {
default:
case Installed:
dir = info()->baseDir(); // clazy:exclude=qt6-deprecated-api-fixes
break;
case BeingInstalled:
case BeingUpdated:
case BeingDowngraded:
dir.setPath(info()->baseDir().absolutePath() + u'+');
break;
case BeingRemoved:
dir.setPath(info()->baseDir().absolutePath() + u'-');
break;
}
return QUrl::fromLocalFile(dir.absoluteFilePath(info()->icon()));
}
void Package::setState(State state)
{
if (m_state != state) {
m_state = state;
emit stateChanged(m_state);
}
}
void Package::setProgress(qreal progress)
{
m_progress = progress;
}
PackageInfo *Package::info() const
{
return m_updatedInfo ? m_updatedInfo : m_info;
}
PackageInfo *Package::baseInfo() const
{
return m_info;
}
PackageInfo *Package::updatedInfo() const
{
return m_updatedInfo;
}
PackageInfo *Package::setUpdatedInfo(PackageInfo *info)
{
Q_ASSERT(!info || (m_info && info->id() == m_info->id()));
Q_ASSERT(info != m_updatedInfo);
auto old = m_updatedInfo;
m_updatedInfo = info;
emit bulkChange();
return old;
}
PackageInfo *Package::setBaseInfo(PackageInfo *info)
{
Q_ASSERT(info != m_info);
auto old = m_info;
m_info = info;
emit bulkChange();
return old;
}
bool Package::isBlocked() const
{
return m_blocked > 0;
}
bool Package::block()
{
bool blockedNow = (m_blocked.fetchAndAddOrdered(1) == 0);
if (blockedNow) {
m_blockedApps = info()->applications();
m_blockedAppsCount = int(m_blockedApps.count());
emit blockedChanged(true);
}
return blockedNow;
}
bool Package::unblock()
{
bool unblockedNow = (m_blocked.fetchAndSubOrdered(1) == 1);
if (unblockedNow) {
m_blockedApps.clear();
m_blockedAppsCount = 0;
emit blockedChanged(false);
}
return unblockedNow;
}
void Package::applicationStoppedDueToBlock(const QString &appId)
{
if (!isBlocked())
return;
auto it = std::find_if(m_blockedApps.cbegin(), m_blockedApps.cend(), [appId](const ApplicationInfo *appInfo) {
return appInfo->id() == appId;
});
if (it != m_blockedApps.cend())
m_blockedApps.removeOne(*it);
m_blockedAppsCount = int(m_blockedApps.count());
}
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
#include "moc_package.cpp"
|