[Kde-bindings] KDE/kdelibs/kdecore/kernel

Albert Astals Cid tsdgeos at terra.es
Mon Nov 22 19:05:06 UTC 2010


SVN commit 1199791 by aacid:

Add the K_CATALOG_LOADER macro and KGlobal::insertCatalog
Acked by k-c-d
CCMAIL: kde-bindings at kde.org


 M  +14 -0     kglobal.cpp  
 M  +35 -0     kglobal.h  


--- trunk/KDE/kdelibs/kdecore/kernel/kglobal.cpp #1199790:1199791
@@ -100,6 +100,7 @@
         KLocale *locale;
         KCharsets *charsets;
         bool localeIsFromFakeComponent;
+        QStringList catalogsToInsert;
 
         /**
          * This component may be used in applications that doesn't have a
@@ -149,6 +150,16 @@
     return d->mainComponent.isValid();
 }
 
+void KGlobal::insertCatalog(const QString& catalog)
+{
+    PRIVATE_DATA;
+    if (d->locale) {
+        d->locale->insertCatalog(catalog);
+    } else {
+        d->catalogsToInsert.append(catalog);
+    }
+}
+
 KLocale *KGlobal::locale()
 {
     PRIVATE_DATA;
@@ -168,6 +179,9 @@
                 QCoreApplication::installTranslator(new KDETranslator(coreApp));
             }
         }
+        foreach(const QString &catalog, d->catalogsToInsert)
+            d->locale->insertCatalog(catalog);
+        d->catalogsToInsert.clear();
     }
     return d->locale;
 }
--- trunk/KDE/kdelibs/kdecore/kernel/kglobal.h #1199790:1199791
@@ -300,6 +300,33 @@
 } NAME;
 
 /**
+ * This macro is useful in libraries where you want to make sure that
+ * anyone that uses your library will get the correct catalog loaded.
+ *
+ * @param CATALOGNAME The name of your catalog
+ *
+ * @since 4.6
+ *
+ * Example:
+ * @code
+ * K_CATALOG_LOADER(libkdepim)
+ * @endcode
+ * 
+ * @ingroup KDEMacros
+ */
+#define K_CATALOG_LOADER(CATALOGNAME)                               \
+class KCatalogLoader##CATALOGNAME                                   \
+{                                                                   \
+    public:                                                         \
+        KCatalogLoader##CATALOGNAME();                              \
+};                                                                  \
+static KCatalogLoader##CATALOGNAME catalogLoader##CATALOGNAME;      \
+KCatalogLoader##CATALOGNAME::KCatalogLoader##CATALOGNAME()          \
+{                                                                   \
+    KGlobal::insertCatalog(QLatin1String(#CATALOGNAME));            \
+}
+
+/**
  * Access to the KDE global objects.
  * KGlobal provides you with pointers of many central
  * objects that exist only once in the process. It is also
@@ -338,6 +365,14 @@
     KDECORE_EXPORT KSharedConfigPtr config();
 
     /**
+     * Inserts the catalog in the main locale object if it exists.
+     * Otherwise the catalog name is stored and added once the main locale gets created
+     *
+     * @since 4.6
+     */
+    KDECORE_EXPORT void insertCatalog(const QString& catalog);
+
+    /**
      * Returns the global locale object.
      * @return the global locale object
      *



More information about the Kde-bindings mailing list