Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit cf639b7

Browse files
committed
[nemo-systemsettings] Make AboutSettings easily stubbable. Contributes to JB#47601
1 parent 9bcdd68 commit cf639b7

File tree

4 files changed

+131
-42
lines changed

4 files changed

+131
-42
lines changed

src/aboutsettings.cpp

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
*/
3131

3232
#include "aboutsettings.h"
33+
#include "aboutsettings_p.h"
3334

3435
#include <QDebug>
3536
#include <QStringList>
37+
3638
#include <QNetworkInfo>
39+
3740
#include <QDeviceInfo>
3841
#include <QFile>
3942
#include <QByteArray>
@@ -151,19 +154,33 @@ void parseLocalizationFile(const QString &filename, QMap<QString, QString> *resu
151154

152155
}
153156

157+
158+
AboutSettingsPrivate::AboutSettingsPrivate(QObject *parent)
159+
: QObject(parent)
160+
{
161+
162+
}
163+
164+
AboutSettingsPrivate::~AboutSettingsPrivate()
165+
{
166+
167+
}
168+
169+
154170
AboutSettings::AboutSettings(QObject *parent)
155-
: QObject(parent), m_netinfo(new QNetworkInfo(this)),
156-
m_devinfo(new QDeviceInfo(this))
171+
: QObject(parent)
172+
, d_ptr(new AboutSettingsPrivate(this))
157173
{
174+
Q_D(AboutSettings);
158175
QSettings settings(QStringLiteral("/mnt/vendor_data/vendor-data.ini"), QSettings::IniFormat);
159-
m_vendorName = settings.value(QStringLiteral("Name")).toString();
160-
m_vendorVersion = settings.value(QStringLiteral("Version")).toString();
176+
d->vendorName = settings.value(QStringLiteral("Name")).toString();
177+
d->vendorVersion = settings.value(QStringLiteral("Version")).toString();
161178

162179
refreshStorageModels();
163180

164-
connect(&m_partitionManager, &PartitionManager::partitionAdded,
181+
connect(&d->partitionManager, &PartitionManager::partitionAdded,
165182
this, &AboutSettings::partitionCountChanged);
166-
connect(&m_partitionManager, &PartitionManager::partitionRemoved,
183+
connect(&d->partitionManager, &PartitionManager::partitionRemoved,
167184
this, &AboutSettings::partitionCountChanged);
168185
}
169186

@@ -173,27 +190,32 @@ AboutSettings::~AboutSettings()
173190

174191
qlonglong AboutSettings::totalDiskSpace() const
175192
{
176-
return m_partitionManager.root().bytesTotal();
193+
Q_D(const AboutSettings);
194+
return d->partitionManager.root().bytesTotal();
177195
}
178196

179197
qlonglong AboutSettings::availableDiskSpace() const
180198
{
181-
return m_partitionManager.root().bytesAvailable();
199+
Q_D(const AboutSettings);
200+
return d->partitionManager.root().bytesAvailable();
182201
}
183202

184203
QVariant AboutSettings::diskUsageModel() const
185204
{
186-
return m_internalStorage;
205+
Q_D(const AboutSettings);
206+
return d->internalStorage;
187207
}
188208

189209
QString AboutSettings::wlanMacAddress() const
190210
{
191-
return m_netinfo->macAddress(QNetworkInfo::WlanMode, 0);
211+
Q_D(const AboutSettings);
212+
return d->networkInfo.macAddress(QNetworkInfo::WlanMode, 0);
192213
}
193214

194215
QString AboutSettings::imei() const
195216
{
196-
return m_devinfo->imei(0);
217+
Q_D(const AboutSettings);
218+
return d->deviceInfo.imei(0);
197219
}
198220

199221
QString AboutSettings::serial() const
@@ -224,9 +246,10 @@ QString AboutSettings::serial() const
224246

225247
QString AboutSettings::localizedOperatingSystemName() const
226248
{
227-
parseLocalizationFile(QStringLiteral("/etc/os-release-l10n"), &m_osReleaseLocalization);
249+
Q_D(const AboutSettings);
250+
parseLocalizationFile(QStringLiteral("/etc/os-release-l10n"), &d->osReleaseLocalization);
228251

229-
return m_osReleaseLocalization.value("NAME", operatingSystemName());
252+
return d->osReleaseLocalization.value("NAME", operatingSystemName());
230253
}
231254

232255
QString AboutSettings::baseOperatingSystemName() const
@@ -240,45 +263,52 @@ QString AboutSettings::baseOperatingSystemName() const
240263

241264
QString AboutSettings::operatingSystemName() const
242265
{
243-
parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease);
266+
Q_D(const AboutSettings);
267+
parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease);
244268

245-
return m_osRelease["NAME"];
269+
return d->osRelease["NAME"];
246270
}
247271

248272
QString AboutSettings::softwareVersion() const
249273
{
250-
parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease);
274+
Q_D(const AboutSettings);
275+
parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease);
251276

252-
return m_osRelease["VERSION"];
277+
return d->osRelease["VERSION"];
253278
}
254279

255280
QString AboutSettings::softwareVersionId() const
256281
{
257-
parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease);
282+
Q_D(const AboutSettings);
283+
parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease);
258284

259-
return m_osRelease["VERSION_ID"];
285+
return d->osRelease["VERSION_ID"];
260286
}
261287

262288
QString AboutSettings::adaptationVersion() const
263289
{
264-
parseReleaseFile(QStringLiteral("/etc/hw-release"), &m_hardwareRelease);
290+
Q_D(const AboutSettings);
291+
parseReleaseFile(QStringLiteral("/etc/hw-release"), &d->hardwareRelease);
265292

266-
return m_hardwareRelease["VERSION_ID"];
293+
return d->hardwareRelease["VERSION_ID"];
267294
}
268295

269296
QString AboutSettings::vendorName() const
270297
{
271-
return m_vendorName;
298+
Q_D(const AboutSettings);
299+
return d->vendorName;
272300
}
273301

274302
QString AboutSettings::vendorVersion() const
275303
{
276-
return m_vendorVersion;
304+
Q_D(const AboutSettings);
305+
return d->vendorVersion;
277306
}
278307

279308
void AboutSettings::refreshStorageModels()
280309
{
281-
m_partitionManager.refresh();
310+
Q_D(AboutSettings);
311+
d->partitionManager.refresh();
282312

283313
partitionCountChanged();
284314
}
@@ -292,9 +322,10 @@ void AboutSettings::partitionCountChanged()
292322

293323
void AboutSettings::reloadStorageLists()
294324
{
295-
m_internalStorage.clear();
325+
Q_D(AboutSettings);
326+
d->internalStorage.clear();
296327

297-
for (auto partition : m_partitionManager.partitions()) {
328+
for (auto partition : d->partitionManager.partitions()) {
298329
QVariantMap row;
299330
row[QStringLiteral("mounted")] = partition.status() == Partition::Mounted;
300331
row[QStringLiteral("path")] = partition.mountPath();
@@ -318,7 +349,7 @@ void AboutSettings::reloadStorageLists()
318349
}();
319350

320351
if (partition.storageType() != Partition::External) {
321-
m_internalStorage << QVariant(row);
352+
d->internalStorage << QVariant(row);
322353
}
323354
}
324355

src/aboutsettings.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
* Copyright (C) 2013 Jolla Ltd. <[email protected]>
2+
* Copyright (C) 2013 - 2019 Jolla Ltd.
3+
* Copyright (c) 2019 Open Mobile Platform LLC.
34
*
45
* You may use this file under the terms of the BSD license as follows:
56
*
@@ -36,10 +37,9 @@
3637
#include <QVariant>
3738

3839
#include <systemsettingsglobal.h>
39-
#include <partitionmanager.h>
4040

41-
class QNetworkInfo;
42-
class QDeviceInfo;
41+
class AboutSettingsPrivate;
42+
4343
class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
4444
{
4545
Q_OBJECT
@@ -95,18 +95,10 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
9595
void partitionCountChanged();
9696
void reloadStorageLists();
9797

98-
QNetworkInfo *m_netinfo;
99-
QDeviceInfo *m_devinfo;
100-
101-
QVariantList m_internalStorage;
102-
PartitionManager m_partitionManager;
103-
104-
mutable QMap<QString, QString> m_osRelease;
105-
mutable QMap<QString, QString> m_osReleaseLocalization;
106-
mutable QMap<QString, QString> m_hardwareRelease;
98+
Q_DECLARE_PRIVATE(AboutSettings)
99+
Q_DISABLE_COPY(AboutSettings)
107100

108-
QString m_vendorName;
109-
QString m_vendorVersion;
101+
AboutSettingsPrivate *d_ptr;
110102
};
111103

112104
#endif

src/aboutsettings_p.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2019 Open Mobile Platform LLC.
3+
*
4+
* You may use this file under the terms of the BSD license as follows:
5+
*
6+
* "Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are
8+
* met:
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
* * Neither the name of Nemo Mobile nor the names of its contributors
16+
* may be used to endorse or promote products derived from this
17+
* software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
30+
*/
31+
32+
#ifndef ABOUTSETTINGS_P_H
33+
#define ABOUTSETTINGS_P_H
34+
35+
#include <QObject>
36+
#include <QNetworkInfo>
37+
#include <QDeviceInfo>
38+
#include <QVariantList>
39+
40+
#include "partitionmanager.h"
41+
42+
class AboutSettingsPrivate : public QObject
43+
{
44+
Q_OBJECT
45+
46+
public:
47+
AboutSettingsPrivate(QObject *parent = nullptr);
48+
virtual ~AboutSettingsPrivate();
49+
50+
QNetworkInfo networkInfo;
51+
QDeviceInfo deviceInfo;
52+
53+
QVariantList internalStorage;
54+
55+
PartitionManager partitionManager;
56+
57+
mutable QMap<QString, QString> osRelease;
58+
mutable QMap<QString, QString> osReleaseLocalization;
59+
mutable QMap<QString, QString> hardwareRelease;
60+
61+
QString vendorName;
62+
QString vendorVersion;
63+
};
64+
65+
#endif

src/src.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PUBLIC_HEADERS = \
6363

6464
HEADERS += \
6565
$$PUBLIC_HEADERS \
66+
aboutsettings_p.h \
6667
localeconfig.h \
6768
batterystatus_p.h \
6869
logging_p.h \

0 commit comments

Comments
 (0)