Skip to content

Commit

Permalink
Merge branch 'jb47268' into 'master'
Browse files Browse the repository at this point in the history
[aboutsettings] Add property with localized OS name. Contributes to JB#47268

See merge request mer-core/nemo-qml-plugin-systemsettings!118
  • Loading branch information
rainemak committed Sep 19, 2019
2 parents 290b35d + ea49e0a commit 4bbaa50
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/aboutsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,39 @@ void parseReleaseFile(const QString &filename, QMap<QString, QString> *result)
}
}

void parseLocalizationFile(const QString &filename, QMap<QString, QString> *result)
{
if (!result->isEmpty()) {
return;
}

if (!QFile(filename).exists()) {
return;
}

QSettings localizations(filename, QSettings::IniFormat);
localizations.setIniCodec("UTF-8");

QStringList languages = QLocale::system().uiLanguages();
QStringList availableLanguages;

for (auto it = languages.crbegin(); it != languages.crend(); ++it) {
const auto &lang = *it;
if (localizations.childGroups().contains(lang)) {
availableLanguages.append(lang);
}
}

// Gradually load localizations, overridding least preferred with most preferred ones
for (const auto &lang : availableLanguages) {
localizations.beginGroup(lang);
for (const auto &key : localizations.childKeys()) {
result->insert(key, localizations.value(key).toString());
}
localizations.endGroup();
}
}

}

AboutSettings::AboutSettings(QObject *parent)
Expand Down Expand Up @@ -189,6 +222,13 @@ QString AboutSettings::serial() const
return QString();
}

QString AboutSettings::localizedOperatingSystemName() const
{
parseLocalizationFile(QStringLiteral("/etc/os-release-l10n"), &m_osReleaseLocalization);

return m_osReleaseLocalization.value("NAME", operatingSystemName());
}

QString AboutSettings::baseOperatingSystemName() const
{
QString osName = operatingSystemName();
Expand Down
3 changes: 3 additions & 0 deletions src/aboutsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
Q_PROPERTY(QString wlanMacAddress READ wlanMacAddress CONSTANT)
Q_PROPERTY(QString imei READ imei CONSTANT)
Q_PROPERTY(QString serial READ serial CONSTANT)
Q_PROPERTY(QString localizedOperatingSystemName READ localizedOperatingSystemName CONSTANT)
Q_PROPERTY(QString baseOperatingSystemName READ baseOperatingSystemName CONSTANT)
Q_PROPERTY(QString operatingSystemName READ operatingSystemName CONSTANT)
Q_PROPERTY(QString softwareVersion READ softwareVersion CONSTANT)
Expand Down Expand Up @@ -77,6 +78,7 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
QString wlanMacAddress() const;
QString imei() const;
QString serial() const;
QString localizedOperatingSystemName() const;
QString baseOperatingSystemName() const;
QString operatingSystemName() const;
QString softwareVersion() const;
Expand All @@ -100,6 +102,7 @@ class SYSTEMSETTINGS_EXPORT AboutSettings: public QObject
PartitionManager m_partitionManager;

mutable QMap<QString, QString> m_osRelease;
mutable QMap<QString, QString> m_osReleaseLocalization;
mutable QMap<QString, QString> m_hardwareRelease;

QString m_vendorName;
Expand Down
1 change: 1 addition & 0 deletions src/plugin/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Module {
Property { name: "wlanMacAddress"; type: "string"; isReadonly: true }
Property { name: "imei"; type: "string"; isReadonly: true }
Property { name: "serial"; type: "string"; isReadonly: true }
Property { name: "localizedOperatingSystemName"; type: "string"; isReadonly: true }
Property { name: "baseOperatingSystemName"; type: "string"; isReadonly: true }
Property { name: "operatingSystemName"; type: "string"; isReadonly: true }
Property { name: "softwareVersion"; type: "string"; isReadonly: true }
Expand Down

0 comments on commit 4bbaa50

Please sign in to comment.