Commit 4bbaa500 authored by Raine Makelainen's avatar Raine Makelainen

Merge branch 'jb47268' into 'master'

[aboutsettings] Add property with localized OS name. Contributes to JB#47268

See merge request !118
parents 290b35d4 ea49e0a4
......@@ -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)
......@@ -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();
......
......@@ -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)
......@@ -77,6 +78,7 @@ public:
QString wlanMacAddress() const;
QString imei() const;
QString serial() const;
QString localizedOperatingSystemName() const;
QString baseOperatingSystemName() const;
QString operatingSystemName() const;
QString softwareVersion() const;
......@@ -100,6 +102,7 @@ private:
PartitionManager m_partitionManager;
mutable QMap<QString, QString> m_osRelease;
mutable QMap<QString, QString> m_osReleaseLocalization;
mutable QMap<QString, QString> m_hardwareRelease;
QString m_vendorName;
......
......@@ -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 }
......
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