Commit 2e04b05b authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb47601' into 'master'

[nemo-systemsettings] Make AboutSettings easily stubbable. Contributes to JB#47601

See merge request mer-core/nemo-qml-plugin-systemsettings!122
parents 9bcdd68d cf639b70
......@@ -30,10 +30,13 @@
*/
#include "aboutsettings.h"
#include "aboutsettings_p.h"
#include <QDebug>
#include <QStringList>
#include <QNetworkInfo>
#include <QDeviceInfo>
#include <QFile>
#include <QByteArray>
......@@ -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);
}
......@@ -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);
}
}
......
/*
* 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:
*
......@@ -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
......@@ -95,18 +95,10 @@ private:
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
/*
* 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
......@@ -63,6 +63,7 @@ PUBLIC_HEADERS = \
HEADERS += \
$$PUBLIC_HEADERS \
aboutsettings_p.h \
localeconfig.h \
batterystatus_p.h \
logging_p.h \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment