Skip to content

Commit 436f05a

Browse files
authored
Merge pull request #25 from spiiroin/jb56948_no_qt5_qtsysteminfo
[systemsettings] Remove qt5-qtsysteminfo usage. Fixes JB#56948
2 parents d043c72 + c463fca commit 436f05a

File tree

9 files changed

+87
-24
lines changed

9 files changed

+87
-24
lines changed

rpm/nemo-qml-plugin-systemsettings.spec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Requires: udisks2 >= 2.8.1+git6
1616
Requires: mlite-qt5 >= 0.3.6
1717
Requires(post): coreutils
1818
BuildRequires: pkgconfig(Qt5Qml)
19-
BuildRequires: pkgconfig(Qt5SystemInfo)
2019
BuildRequires: pkgconfig(Qt5Test)
2120
BuildRequires: pkgconfig(Qt5XmlPatterns)
2221
BuildRequires: pkgconfig(timed-qt5)

src/aboutsettings.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
#include <QDebug>
3636
#include <QStringList>
3737

38-
#include <QNetworkInfo>
39-
40-
#include <QDeviceInfo>
4138
#include <QFile>
4239
#include <QByteArray>
4340
#include <QRegularExpression>
@@ -157,13 +154,14 @@ void parseLocalizationFile(const QString &filename, QMap<QString, QString> *resu
157154

158155
AboutSettingsPrivate::AboutSettingsPrivate(QObject *parent)
159156
: QObject(parent)
157+
, deviceInfo(new DeviceInfo())
160158
{
161-
162159
}
163160

164161
AboutSettingsPrivate::~AboutSettingsPrivate()
165162
{
166-
163+
delete deviceInfo;
164+
deviceInfo = nullptr;
167165
}
168166

169167

@@ -184,19 +182,11 @@ AboutSettings::~AboutSettings()
184182
QString AboutSettings::wlanMacAddress() const
185183
{
186184
Q_D(const AboutSettings);
187-
return d->networkInfo.macAddress(QNetworkInfo::WlanMode, 0);
188-
}
189-
190-
QString AboutSettings::imei() const
191-
{
192-
Q_D(const AboutSettings);
193-
return d->deviceInfo.imei(0);
185+
return d->deviceInfo->wlanMacAddress();
194186
}
195187

196188
QString AboutSettings::serial() const
197189
{
198-
// TODO: eventually we should use QDeviceInfo's uniqueDeviceID()
199-
200190
QStringList serialFiles;
201191

202192
serialFiles

src/aboutsettings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
4545
Q_OBJECT
4646

4747
Q_PROPERTY(QString wlanMacAddress READ wlanMacAddress CONSTANT)
48-
Q_PROPERTY(QString imei READ imei CONSTANT)
4948
Q_PROPERTY(QString serial READ serial CONSTANT)
5049
Q_PROPERTY(QString localizedOperatingSystemName READ localizedOperatingSystemName CONSTANT)
5150
Q_PROPERTY(QString baseOperatingSystemName READ baseOperatingSystemName CONSTANT)
@@ -62,7 +61,6 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
6261
virtual ~AboutSettings();
6362

6463
QString wlanMacAddress() const;
65-
QString imei() const;
6664
QString serial() const;
6765
QString localizedOperatingSystemName() const;
6866
QString baseOperatingSystemName() const;

src/aboutsettings_p.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
#define ABOUTSETTINGS_P_H
3434

3535
#include <QObject>
36-
#include <QNetworkInfo>
37-
#include <QDeviceInfo>
3836
#include <QVariantList>
3937

38+
#include "deviceinfo.h"
39+
4040
class AboutSettingsPrivate : public QObject
4141
{
4242
Q_OBJECT
@@ -45,8 +45,7 @@ class AboutSettingsPrivate : public QObject
4545
AboutSettingsPrivate(QObject *parent = nullptr);
4646
virtual ~AboutSettingsPrivate();
4747

48-
QNetworkInfo networkInfo;
49-
QDeviceInfo deviceInfo;
48+
DeviceInfo *deviceInfo;
5049

5150
mutable QMap<QString, QString> osRelease;
5251
mutable QMap<QString, QString> osReleaseLocalization;

src/deviceinfo.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DeviceInfoPrivate: public QObject
4444
DeviceInfoPrivate(DeviceInfo *deviceInfo, bool synchronousInit);
4545
~DeviceInfoPrivate();
4646
QStringList imeiNumbers();
47+
QString wlanMacAddress();
4748

4849
QSet<DeviceInfo::Feature> m_features;
4950
QSet<Qt::Key> m_keys;
@@ -60,10 +61,20 @@ private slots:
6061
void modemSerialChanged(const QString &serial);
6162
void updateModemProperties();
6263
private:
64+
enum NetworkMode {
65+
/* Subset of QNetworkInfo::NetworkMode enum */
66+
WlanMode = 4,
67+
EthernetMode = 5,
68+
};
69+
6370
void modemAdded(const QString &modem);
6471
void modemRemoved(const QString &modem);
6572
QSharedPointer<QOfonoManager> ofonoManager();
6673
void updateModemPropertiesLater();
74+
int networkInterfaceCount(DeviceInfoPrivate::NetworkMode mode);
75+
QString macAddress(DeviceInfoPrivate::NetworkMode mode, int interface);
76+
const QStringList &networkModeDirectoryList(DeviceInfoPrivate::NetworkMode mode);
77+
static QString readSimpleFile(const QString &path);
6778

6879
DeviceInfo *q_ptr;
6980
bool m_synchronousInit;
@@ -72,6 +83,7 @@ private slots:
7283
QStringList m_modemList;
7384
QStringList m_imeiNumbers;
7485
QTimer *m_updateModemPropertiesTimer;
86+
QHash<DeviceInfoPrivate::NetworkMode, QStringList> m_networkModeDirectoryListHash;
7587
Q_DISABLE_COPY(DeviceInfoPrivate);
7688
Q_DECLARE_PUBLIC(DeviceInfo);
7789
};
@@ -205,6 +217,52 @@ void DeviceInfoPrivate::modemSerialChanged(const QString &serial)
205217
updateModemPropertiesLater();
206218
}
207219

220+
QString DeviceInfoPrivate::wlanMacAddress()
221+
{
222+
return macAddress(DeviceInfoPrivate::WlanMode, 0);
223+
}
224+
225+
int DeviceInfoPrivate::networkInterfaceCount(DeviceInfoPrivate::NetworkMode mode)
226+
{
227+
/* Like QNetworkInfo::networkInterfaceCount() */
228+
return networkModeDirectoryList(mode).size();
229+
}
230+
231+
QString DeviceInfoPrivate::macAddress(DeviceInfoPrivate::NetworkMode mode, int interface)
232+
{
233+
/* Like QNetworkInfo::macAddress() */
234+
if (interface >= 0 && interface < networkInterfaceCount(mode))
235+
return readSimpleFile(QDir(networkModeDirectoryList(mode).at(interface)).filePath("address"));
236+
return QString();
237+
}
238+
239+
const QStringList &DeviceInfoPrivate::networkModeDirectoryList(DeviceInfoPrivate::NetworkMode mode)
240+
{
241+
if (!m_networkModeDirectoryListHash.contains(mode)) {
242+
QStringList &modeDirectoryList(m_networkModeDirectoryListHash[mode]);
243+
QDir baseDir(QStringLiteral("/sys/class/net"));
244+
QStringList stemList;
245+
if (mode == DeviceInfoPrivate::WlanMode)
246+
stemList << QStringLiteral("wlan");
247+
else if (mode == DeviceInfoPrivate::EthernetMode)
248+
stemList << QStringLiteral("eth") << QStringLiteral("usb") << QStringLiteral("rndis");
249+
for (auto stemIter = stemList.cbegin(); stemIter != stemList.cend(); ++stemIter) {
250+
QFileInfoList modeDirList(baseDir.entryInfoList(QStringList() << QStringLiteral("%1*").arg(*stemIter), QDir::Dirs, QDir::Name));
251+
for (auto modeDirIter = modeDirList.cbegin(); modeDirIter != modeDirList.cend(); ++modeDirIter)
252+
modeDirectoryList.append((*modeDirIter).filePath());
253+
}
254+
}
255+
return m_networkModeDirectoryListHash[mode];
256+
}
257+
258+
QString DeviceInfoPrivate::readSimpleFile(const QString &path)
259+
{
260+
QFile file(path);
261+
if (file.open(QIODevice::ReadOnly))
262+
return QString::fromLocal8Bit(file.readAll().simplified().data());
263+
return QString();
264+
}
265+
208266
DeviceInfo::DeviceInfo(bool synchronousInit, QObject *parent)
209267
: QObject(parent)
210268
, d_ptr(new DeviceInfoPrivate(this, synchronousInit))
@@ -291,4 +349,10 @@ QStringList DeviceInfo::imeiNumbers()
291349
return d->imeiNumbers();
292350
}
293351

352+
QString DeviceInfo::wlanMacAddress()
353+
{
354+
Q_D(DeviceInfo);
355+
return d->wlanMacAddress();
356+
}
357+
294358
#include "deviceinfo.moc"

src/deviceinfo.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class SYSTEMSETTINGS_EXPORT DeviceInfo: public QObject
5252
Q_PROPERTY(QString osVersion READ osVersion CONSTANT)
5353
Q_PROPERTY(QString adaptationVersion READ adaptationVersion CONSTANT)
5454
Q_PROPERTY(QStringList imeiNumbers READ imeiNumbers NOTIFY imeiNumbersChanged)
55+
Q_PROPERTY(QString wlanMacAddress READ wlanMacAddress CONSTANT)
5556

5657
public:
5758
enum Feature {
@@ -250,6 +251,14 @@ class SYSTEMSETTINGS_EXPORT DeviceInfo: public QObject
250251
*/
251252
QStringList imeiNumbers();
252253

254+
/*!
255+
* Get wlan mac address
256+
*
257+
* Note: Interface availability is cached on the first call, but
258+
* mac address itself is re-read from sysfs on every call.
259+
*/
260+
QString wlanMacAddress();
261+
253262
Q_SIGNALS:
254263
void imeiNumbersChanged();
255264

src/plugin/plugins.qmltypes

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Module {
1414
exports: ["org.nemomobile.systemsettings/AboutSettings 1.0"]
1515
exportMetaObjectRevisions: [0]
1616
Property { name: "wlanMacAddress"; type: "string"; isReadonly: true }
17-
Property { name: "imei"; type: "string"; isReadonly: true }
1817
Property { name: "serial"; type: "string"; isReadonly: true }
1918
Property { name: "localizedOperatingSystemName"; type: "string"; isReadonly: true }
2019
Property { name: "baseOperatingSystemName"; type: "string"; isReadonly: true }
@@ -236,6 +235,11 @@ Module {
236235
Property { name: "designation"; type: "string"; isReadonly: true }
237236
Property { name: "manufacturer"; type: "string"; isReadonly: true }
238237
Property { name: "prettyName"; type: "string"; isReadonly: true }
238+
Property { name: "osName"; type: "string"; isReadonly: true }
239+
Property { name: "osVersion"; type: "string"; isReadonly: true }
240+
Property { name: "adaptationVersion"; type: "string"; isReadonly: true }
241+
Property { name: "imeiNumbers"; type: "QStringList"; isReadonly: true }
242+
Property { name: "wlanMacAddress"; type: "string"; isReadonly: true }
239243
Method {
240244
name: "hasFeature"
241245
type: "bool"

src/src.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TEMPLATE = lib
22
TARGET = systemsettings
33

44
CONFIG += qt create_pc create_prl no_install_prl c++11
5-
QT += qml dbus systeminfo xmlpatterns
5+
QT += qml dbus xmlpatterns
66
QT -= gui
77

88
CONFIG += c++11 hide_symbols link_pkgconfig

tests/tests.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PACKAGENAME = nemo-qml-plugin-systemsettings
44

5-
QT += testlib qml dbus systeminfo
5+
QT += testlib qml dbus
66
QT -= gui
77

88
TEMPLATE = app

0 commit comments

Comments
 (0)