Skip to content

Commit

Permalink
[nemo-systemsettings] Make AboutSettings easily stubbable. Contribute…
Browse files Browse the repository at this point in the history
…s to JB#47601
  • Loading branch information
rainemak committed Oct 14, 2019
1 parent 9bcdd68 commit cf639b7
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 42 deletions.
85 changes: 58 additions & 27 deletions src/aboutsettings.cpp
Expand Up @@ -30,10 +30,13 @@
*/

#include "aboutsettings.h"
#include "aboutsettings_p.h"

#include <QDebug>
#include <QStringList>

#include <QNetworkInfo>

#include <QDeviceInfo>
#include <QFile>
#include <QByteArray>
Expand Down Expand Up @@ -151,19 +154,33 @@ void parseLocalizationFile(const QString &filename, QMap<QString, QString> *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);
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -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();
Expand All @@ -318,7 +349,7 @@ void AboutSettings::reloadStorageLists()
}();

if (partition.storageType() != Partition::External) {
m_internalStorage << QVariant(row);
d->internalStorage << QVariant(row);
}
}

Expand Down
22 changes: 7 additions & 15 deletions src/aboutsettings.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
* 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:
*
Expand Down Expand Up @@ -36,10 +37,9 @@
#include <QVariant>

#include <systemsettingsglobal.h>
#include <partitionmanager.h>

class QNetworkInfo;
class QDeviceInfo;
class AboutSettingsPrivate;

class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -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<QString, QString> m_osRelease;
mutable QMap<QString, QString> m_osReleaseLocalization;
mutable QMap<QString, QString> m_hardwareRelease;
Q_DECLARE_PRIVATE(AboutSettings)
Q_DISABLE_COPY(AboutSettings)

QString m_vendorName;
QString m_vendorVersion;
AboutSettingsPrivate *d_ptr;
};

#endif
65 changes: 65 additions & 0 deletions 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 <QObject>
#include <QNetworkInfo>
#include <QDeviceInfo>
#include <QVariantList>

#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<QString, QString> osRelease;
mutable QMap<QString, QString> osReleaseLocalization;
mutable QMap<QString, QString> hardwareRelease;

QString vendorName;
QString vendorVersion;
};

#endif
1 change: 1 addition & 0 deletions src/src.pro
Expand Up @@ -63,6 +63,7 @@ PUBLIC_HEADERS = \

HEADERS += \
$$PUBLIC_HEADERS \
aboutsettings_p.h \
localeconfig.h \
batterystatus_p.h \
logging_p.h \
Expand Down

0 comments on commit cf639b7

Please sign in to comment.