From cf639b7050641760c68c4bf0ca64bac633823e87 Mon Sep 17 00:00:00 2001 From: Raine Makelainen Date: Mon, 14 Oct 2019 13:53:21 +0000 Subject: [PATCH] [nemo-systemsettings] Make AboutSettings easily stubbable. Contributes to JB#47601 --- src/aboutsettings.cpp | 85 +++++++++++++++++++++++++++++-------------- src/aboutsettings.h | 22 ++++------- src/aboutsettings_p.h | 65 +++++++++++++++++++++++++++++++++ src/src.pro | 1 + 4 files changed, 131 insertions(+), 42 deletions(-) create mode 100644 src/aboutsettings_p.h diff --git a/src/aboutsettings.cpp b/src/aboutsettings.cpp index 4caeb7b..05684f6 100644 --- a/src/aboutsettings.cpp +++ b/src/aboutsettings.cpp @@ -30,10 +30,13 @@ */ #include "aboutsettings.h" +#include "aboutsettings_p.h" #include #include + #include + #include #include #include @@ -151,19 +154,33 @@ void parseLocalizationFile(const QString &filename, QMap *resu } + +AboutSettingsPrivate::AboutSettingsPrivate(QObject *parent) + : QObject(parent) +{ + +} + +AboutSettingsPrivate::~AboutSettingsPrivate() +{ + +} + + AboutSettings::AboutSettings(QObject *parent) -: QObject(parent), m_netinfo(new QNetworkInfo(this)), - m_devinfo(new QDeviceInfo(this)) + : QObject(parent) + , d_ptr(new AboutSettingsPrivate(this)) { + Q_D(AboutSettings); QSettings settings(QStringLiteral("/mnt/vendor_data/vendor-data.ini"), QSettings::IniFormat); - m_vendorName = settings.value(QStringLiteral("Name")).toString(); - m_vendorVersion = settings.value(QStringLiteral("Version")).toString(); + d->vendorName = settings.value(QStringLiteral("Name")).toString(); + d->vendorVersion = settings.value(QStringLiteral("Version")).toString(); refreshStorageModels(); - connect(&m_partitionManager, &PartitionManager::partitionAdded, + connect(&d->partitionManager, &PartitionManager::partitionAdded, this, &AboutSettings::partitionCountChanged); - connect(&m_partitionManager, &PartitionManager::partitionRemoved, + connect(&d->partitionManager, &PartitionManager::partitionRemoved, this, &AboutSettings::partitionCountChanged); } @@ -173,27 +190,32 @@ AboutSettings::~AboutSettings() qlonglong AboutSettings::totalDiskSpace() const { - return m_partitionManager.root().bytesTotal(); + Q_D(const AboutSettings); + return d->partitionManager.root().bytesTotal(); } qlonglong AboutSettings::availableDiskSpace() const { - return m_partitionManager.root().bytesAvailable(); + Q_D(const AboutSettings); + return d->partitionManager.root().bytesAvailable(); } QVariant AboutSettings::diskUsageModel() const { - return m_internalStorage; + Q_D(const AboutSettings); + return d->internalStorage; } QString AboutSettings::wlanMacAddress() const { - return m_netinfo->macAddress(QNetworkInfo::WlanMode, 0); + Q_D(const AboutSettings); + return d->networkInfo.macAddress(QNetworkInfo::WlanMode, 0); } QString AboutSettings::imei() const { - return m_devinfo->imei(0); + Q_D(const AboutSettings); + return d->deviceInfo.imei(0); } QString AboutSettings::serial() const @@ -224,9 +246,10 @@ QString AboutSettings::serial() const QString AboutSettings::localizedOperatingSystemName() const { - parseLocalizationFile(QStringLiteral("/etc/os-release-l10n"), &m_osReleaseLocalization); + Q_D(const AboutSettings); + parseLocalizationFile(QStringLiteral("/etc/os-release-l10n"), &d->osReleaseLocalization); - return m_osReleaseLocalization.value("NAME", operatingSystemName()); + return d->osReleaseLocalization.value("NAME", operatingSystemName()); } QString AboutSettings::baseOperatingSystemName() const @@ -240,45 +263,52 @@ QString AboutSettings::baseOperatingSystemName() const QString AboutSettings::operatingSystemName() const { - parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease); + Q_D(const AboutSettings); + parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease); - return m_osRelease["NAME"]; + return d->osRelease["NAME"]; } QString AboutSettings::softwareVersion() const { - parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease); + Q_D(const AboutSettings); + parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease); - return m_osRelease["VERSION"]; + return d->osRelease["VERSION"]; } QString AboutSettings::softwareVersionId() const { - parseReleaseFile(QStringLiteral("/etc/os-release"), &m_osRelease); + Q_D(const AboutSettings); + parseReleaseFile(QStringLiteral("/etc/os-release"), &d->osRelease); - return m_osRelease["VERSION_ID"]; + return d->osRelease["VERSION_ID"]; } QString AboutSettings::adaptationVersion() const { - parseReleaseFile(QStringLiteral("/etc/hw-release"), &m_hardwareRelease); + Q_D(const AboutSettings); + parseReleaseFile(QStringLiteral("/etc/hw-release"), &d->hardwareRelease); - return m_hardwareRelease["VERSION_ID"]; + return d->hardwareRelease["VERSION_ID"]; } QString AboutSettings::vendorName() const { - return m_vendorName; + Q_D(const AboutSettings); + return d->vendorName; } QString AboutSettings::vendorVersion() const { - return m_vendorVersion; + Q_D(const AboutSettings); + return d->vendorVersion; } void AboutSettings::refreshStorageModels() { - m_partitionManager.refresh(); + Q_D(AboutSettings); + d->partitionManager.refresh(); partitionCountChanged(); } @@ -292,9 +322,10 @@ void AboutSettings::partitionCountChanged() void AboutSettings::reloadStorageLists() { - m_internalStorage.clear(); + Q_D(AboutSettings); + d->internalStorage.clear(); - for (auto partition : m_partitionManager.partitions()) { + for (auto partition : d->partitionManager.partitions()) { QVariantMap row; row[QStringLiteral("mounted")] = partition.status() == Partition::Mounted; row[QStringLiteral("path")] = partition.mountPath(); @@ -318,7 +349,7 @@ void AboutSettings::reloadStorageLists() }(); if (partition.storageType() != Partition::External) { - m_internalStorage << QVariant(row); + d->internalStorage << QVariant(row); } } diff --git a/src/aboutsettings.h b/src/aboutsettings.h index 6752135..2b60d78 100644 --- a/src/aboutsettings.h +++ b/src/aboutsettings.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2013 Jolla Ltd. + * Copyright (C) 2013 - 2019 Jolla Ltd. + * Copyright (c) 2019 Open Mobile Platform LLC. * * You may use this file under the terms of the BSD license as follows: * @@ -36,10 +37,9 @@ #include #include -#include -class QNetworkInfo; -class QDeviceInfo; +class AboutSettingsPrivate; + class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject { Q_OBJECT @@ -95,18 +95,10 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject void partitionCountChanged(); void reloadStorageLists(); - QNetworkInfo *m_netinfo; - QDeviceInfo *m_devinfo; - - QVariantList m_internalStorage; - PartitionManager m_partitionManager; - - mutable QMap m_osRelease; - mutable QMap m_osReleaseLocalization; - mutable QMap m_hardwareRelease; + Q_DECLARE_PRIVATE(AboutSettings) + Q_DISABLE_COPY(AboutSettings) - QString m_vendorName; - QString m_vendorVersion; + AboutSettingsPrivate *d_ptr; }; #endif diff --git a/src/aboutsettings_p.h b/src/aboutsettings_p.h new file mode 100644 index 0000000..a692c83 --- /dev/null +++ b/src/aboutsettings_p.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2019 Open Mobile Platform LLC. + * + * You may use this file under the terms of the BSD license as follows: + * + * "Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Nemo Mobile nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + */ + +#ifndef ABOUTSETTINGS_P_H +#define ABOUTSETTINGS_P_H + +#include +#include +#include +#include + +#include "partitionmanager.h" + +class AboutSettingsPrivate : public QObject +{ + Q_OBJECT + +public: + AboutSettingsPrivate(QObject *parent = nullptr); + virtual ~AboutSettingsPrivate(); + + QNetworkInfo networkInfo; + QDeviceInfo deviceInfo; + + QVariantList internalStorage; + + PartitionManager partitionManager; + + mutable QMap osRelease; + mutable QMap osReleaseLocalization; + mutable QMap hardwareRelease; + + QString vendorName; + QString vendorVersion; +}; + +#endif diff --git a/src/src.pro b/src/src.pro index 6dc96d1..386f2a2 100644 --- a/src/src.pro +++ b/src/src.pro @@ -63,6 +63,7 @@ PUBLIC_HEADERS = \ HEADERS += \ $$PUBLIC_HEADERS \ + aboutsettings_p.h \ localeconfig.h \ batterystatus_p.h \ logging_p.h \