From ff19df37415ead8d26597d861b4d0311ac971c74 Mon Sep 17 00:00:00 2001 From: Dmitry Mordvinov Date: Thu, 7 May 2015 05:25:07 +0300 Subject: Implemented xml:lang attribute support for DisplayName tag. Components in tree view are often need to be localized. Therefore packages.xml syntax is extended with possibility to specify xml:lang attribute for DisplayName tag (similarly to Description one). Test data extended with root component localization. Added new testcase that changes default locale and checks that loaded component names correspond to hard-coded ones. Docs updated with new feature description. Change-Id: Ic330c3c6684e763eb48a2e99e71784913544e686 Reviewed-by: Leena Miettinen Reviewed-by: Karsten Heimrich --- src/libs/kdtools/kdupdaterupdatesinfo.cpp | 21 ++++++++++++++------- src/libs/kdtools/kdupdaterupdatesinfodata_p.h | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src/libs/kdtools') diff --git a/src/libs/kdtools/kdupdaterupdatesinfo.cpp b/src/libs/kdtools/kdupdaterupdatesinfo.cpp index b46d96943..ffc907923 100644 --- a/src/libs/kdtools/kdupdaterupdatesinfo.cpp +++ b/src/libs/kdtools/kdupdaterupdatesinfo.cpp @@ -140,14 +140,10 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE) info.data.insert(QLatin1String("inheritVersionFrom"), childE.attribute(QLatin1String("inheritVersionFrom"))); info.data[childE.tagName()] = childE.text(); + } else if (childE.tagName() == QLatin1String("DisplayName")) { + processLocalizedTag(childE, info.data); } else if (childE.tagName() == QLatin1String("Description")) { - QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower(); - if (!info.data.contains(QLatin1String("Description")) && (languageAttribute.isEmpty())) - info.data[childE.tagName()] = childE.text(); - - // overwrite default if we have a language specific description - if (languageAttribute == QLocale().name().toLower()) - info.data[childE.tagName()] = childE.text(); + processLocalizedTag(childE, info.data); } else if (childE.tagName() == QLatin1String("UpdateFile")) { info.data[QLatin1String("CompressedSize")] = childE.attribute(QLatin1String("CompressedSize")); info.data[QLatin1String("UncompressedSize")] = childE.attribute(QLatin1String("UncompressedSize")); @@ -173,6 +169,17 @@ bool UpdatesInfoData::parsePackageUpdateElement(const QDomElement &updateE) return true; } +void UpdatesInfoData::processLocalizedTag(const QDomElement &childE, QHash &info) const +{ + QString languageAttribute = childE.attribute(QLatin1String("xml:lang")).toLower(); + if (!info.contains(childE.tagName()) && (languageAttribute.isEmpty())) + info[childE.tagName()] = childE.text(); + + // overwrite default if we have a language specific description + if (QLocale().name().startsWith(languageAttribute, Qt::CaseInsensitive)) + info[childE.tagName()] = childE.text(); +} + // // UpdatesInfo diff --git a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h index 19e44fa10..786c96f1c 100644 --- a/src/libs/kdtools/kdupdaterupdatesinfodata_p.h +++ b/src/libs/kdtools/kdupdaterupdatesinfodata_p.h @@ -62,6 +62,9 @@ public: bool parsePackageUpdateElement(const QDomElement &updateE); void setInvalidContentError(const QString &detail); + +private: + void processLocalizedTag(const QDomElement &childE, QHash &info) const; }; } // namespace KDUpdater -- cgit v1.2.3