Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:lafenghu
kdelibs4-apidocs
desktop-translations.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File desktop-translations.diff of Package kdelibs4-apidocs
Subject: Read .desktop file translations from .mo files if not present From: Lubos Lunak Fate: #300461 Patch-upstream: no Relates: kdelibs3/desktop-translations.diff Index: kdecore/services/kservicegroup.cpp =================================================================== --- kdecore/services/kservicegroup.cpp.orig +++ kdecore/services/kservicegroup.cpp @@ -56,9 +56,9 @@ void KServiceGroupPrivate::load(const QS const KConfigGroup config = desktopFile.desktopGroup(); - m_strCaption = config.readEntry( "Name" ); - m_strIcon = config.readEntry( "Icon" ); - m_strComment = config.readEntry( "Comment" ); + m_strCaption = desktopFile.readName(); + m_strIcon = desktopFile.readIcon(); + m_strComment = desktopFile.readComment(); deleted = config.readEntry("Hidden", false ); m_bNoDisplay = desktopFile.noDisplay(); if (directoryEntryPath.startsWith(QDir::homePath())) Index: kdecore/config/kconfigdata.h =================================================================== --- kdecore/config/kconfigdata.h.orig +++ kdecore/config/kconfigdata.h @@ -175,6 +175,19 @@ class KEntryMap : public QMap<KEntryKey, return find(theKey); } + ConstIterator findExactEntry(const QByteArray& group, const QByteArray& key = QByteArray(), + SearchFlags flags = SearchFlags()) const + { + KEntryKey theKey(group, key, false, bool(flags&SearchDefaults)); + + // try the localized key first + if (flags&SearchLocalized) { + theKey.bLocal = true; + return find(theKey); + } + return find(theKey); + } + Iterator findEntry(const QByteArray& group, const QByteArray& key = QByteArray(), SearchFlags flags = SearchFlags()) { Index: kdecore/config/kdesktopfile.cpp =================================================================== --- kdecore/config/kdesktopfile.cpp.orig +++ kdecore/config/kdesktopfile.cpp @@ -35,6 +35,8 @@ #include "kstandarddirs.h" #include "kconfigini_p.h" #include "kde_file.h" +#include "kcatalog_p.h" +#include "klocale.h" class KDesktopFilePrivate : public KConfigPrivate { @@ -174,6 +176,29 @@ bool KDesktopFile::isAuthorizedDesktopFi return false; } +QString KDesktopFile::translatedEntry(const char* key) const +{ + Q_D(const KDesktopFile); + if (d->desktopGroup.hasTranslatedKey(key)) + return d->desktopGroup.readEntry(key); + + if (d->desktopGroup.hasKey(key)) { + QString value = d->desktopGroup.readEntryUntranslated(key); + QString fName = fileName(); + fName = fName.mid(fName.lastIndexOf(QLatin1Char('/'))+1); + QString po_lookup_key = QString::fromLatin1(key) + QString::fromLatin1("(") + fName + QString::fromLatin1("): ") + value; + QString po_value; + KGlobal::locale()->translateRaw(po_lookup_key.toUtf8().data(), NULL, &po_value); + + if (po_value == po_lookup_key) + return value; + + return po_value; + } + + return QString::null; +} + QString KDesktopFile::readType() const { Q_D(const KDesktopFile); @@ -188,20 +213,17 @@ QString KDesktopFile::readIcon() const QString KDesktopFile::readName() const { - Q_D(const KDesktopFile); - return d->desktopGroup.readEntry("Name", QString()); + return translatedEntry("Name"); } QString KDesktopFile::readComment() const { - Q_D(const KDesktopFile); - return d->desktopGroup.readEntry("Comment", QString()); + return translatedEntry("Comment"); } QString KDesktopFile::readGenericName() const { - Q_D(const KDesktopFile); - return d->desktopGroup.readEntry("GenericName", QString()); + return translatedEntry("GenericName"); } QString KDesktopFile::readPath() const Index: kdecore/config/kdesktopfile.h =================================================================== --- kdecore/config/kdesktopfile.h.orig +++ kdecore/config/kdesktopfile.h @@ -250,6 +250,8 @@ protected: // virtual void virtual_hook( int id, void* data ); private: + QString translatedEntry(const char*) const; + Q_DISABLE_COPY(KDesktopFile) Q_DECLARE_PRIVATE(KDesktopFile) Index: kdecore/config/kconfiggroup.h =================================================================== --- kdecore/config/kconfiggroup.h.orig +++ kdecore/config/kconfiggroup.h @@ -621,6 +621,11 @@ public: */ QMap<QString, QString> entryMap() const; + /** + * @internal + */ + bool hasTranslatedKey( const char *pKey ) const; + protected: bool hasGroupImpl(const QByteArray &group) const; KConfigGroup groupImpl(const QByteArray &b); Index: kdecore/config/kconfig.cpp =================================================================== --- kdecore/config/kconfig.cpp.orig +++ kdecore/config/kconfig.cpp @@ -881,6 +881,17 @@ QString KConfigPrivate::lookupData(const return entryMap.getEntry(group, key, QString(), flags, expand); } +QByteArray KConfigPrivate::lookupExactData(const QByteArray& group, const char* key, + KEntryMap::SearchFlags flags) const +{ + if (bReadDefaults) + flags |= KEntryMap::SearchDefaults; + const KEntryMapConstIterator it = entryMap.findExactEntry(group, key, flags); + if (it == entryMap.constEnd()) + return QByteArray(); + return it->mValue; +} + void KConfig::virtual_hook(int /*id*/, void* /*data*/) { /* nothing */ Index: kdecore/config/kconfig_p.h =================================================================== --- kdecore/config/kconfig_p.h.orig +++ kdecore/config/kconfig_p.h @@ -53,6 +53,7 @@ public: QString lookupData(const QByteArray& group, const char* key, KEntryMap::SearchFlags flags, bool* expand) const; QByteArray lookupData(const QByteArray& group, const char* key, KEntryMap::SearchFlags flags) const; + QByteArray lookupExactData(const QByteArray& group, const char* key, KEntryMap::SearchFlags flags) const; void putData(const QByteArray& group, const char* key, const QByteArray& value, KConfigBase::WriteConfigFlags flags, bool expand=false); Index: kdecore/config/kconfiggroup.cpp =================================================================== --- kdecore/config/kconfiggroup.cpp.orig +++ kdecore/config/kconfiggroup.cpp @@ -1159,6 +1159,16 @@ bool KConfigGroup::hasKey(const char *ke return !config()->d_func()->lookupData(d->fullName(), key, flags).isNull(); } +bool KConfigGroup::hasTranslatedKey(const char* key) const +{ + Q_ASSERT_X(isValid(), "KConfigGroup::hasTranslatedKey", "accessing an invalid group"); + + KEntryMap::SearchFlags flags = KEntryMap::SearchLocalized; + if ( config()->readDefaults() ) + flags |= KEntryMap::SearchDefaults; + return !config()->d_func()->lookupExactData(d->fullName(), key, flags).isNull(); +} + bool KConfigGroup::hasKey(const QString &key) const { return hasKey(key.toUtf8().constData());
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor