Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.1
kdelibs4
desktop-translations.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File desktop-translations.diff of Package kdelibs4
Subject: Read .desktop file translations from .mo files if not present From: Lubos Lunak Fate: #300461 Patch-upstream: no Relates: kdelibs3/desktop-translations.diff --- kdecore/services/kservicegroup.cpp.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/services/kservicegroup.cpp 2008-09-15 15:03:12.000000000 +0200 @@ -57,9 +57,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(); m_strBaseGroupName = config.readEntry( "X-KDE-BaseGroup" ); --- kdecore/config/kconfigdata.h.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kconfigdata.h 2008-09-15 15:03:12.000000000 +0200 @@ -174,6 +174,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()) { --- kdecore/config/kdesktopfile.cpp.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kdesktopfile.cpp 2008-09-15 15:03:12.000000000 +0200 @@ -34,6 +34,8 @@ #include "kstandarddirs.h" #include "kconfigini_p.h" #include "kde_file.h" +#include "kcatalog_p.h" +#include "klocale.h" class KDesktopFilePrivate : public KConfigPrivate { @@ -162,6 +164,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('/')+1); + QString po_lookup_key = QString::fromLatin1(key) + "(" + fName + "): " + 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); @@ -176,20 +201,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 --- kdecore/config/kdesktopfile.h.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kdesktopfile.h 2008-09-15 15:03:12.000000000 +0200 @@ -243,6 +243,8 @@ protected: // virtual void virtual_hook( int id, void* data ); private: + QString translatedEntry(const char*) const; + Q_DISABLE_COPY(KDesktopFile) Q_DECLARE_PRIVATE(KDesktopFile) --- kdecore/config/kconfiggroup.h.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kconfiggroup.h 2008-09-15 15:05:54.000000000 +0200 @@ -558,6 +558,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); --- kdecore/config/kconfig.cpp.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kconfig.cpp 2008-09-15 15:03:12.000000000 +0200 @@ -732,6 +732,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 */ --- kdecore/config/kconfig_p.h.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kconfig_p.h 2008-09-15 15:03:12.000000000 +0200 @@ -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); --- kdecore/config/kconfiggroup.cpp.sav 2008-09-15 14:43:32.000000000 +0200 +++ kdecore/config/kconfiggroup.cpp 2008-09-15 15:03:12.000000000 +0200 @@ -1236,6 +1236,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