[ogoffart at kde.org: KDE/kdelibs/kdecore/kernel]

Andreas Pakulat apaku at gmx.de
Mon Feb 2 17:35:35 UTC 2009


Hi,

just saw this on k-c-d... Could we use kstandarddirs now for the duchain,
as apparently the component data si initialized now and dirs should work as
expected. Except of course appdirs+config are different as soon as the main
component is created and set (as that one uses "kdevelop" as component
name), so maybe its not overly useful?

Andreas

----- Forwarded message from Olivier Goffart <ogoffart at kde.org> -----

From: Olivier Goffart <ogoffart at kde.org>
To: kde-commits at kde.org
Subject: KDE/kdelibs/kdecore/kernel
Reply-To: kde-commits at kde.org

SVN commit 920285 by ogoffart:

Create a default KComponenentData if there is none.
This is usefull for pure Qt applications that loads KDE plugins.

KStyle and Oxygen actually worked around the problem but that can be removed
QtCreator may crash when opening a file dialog because KFileDialog gets hooked by some designer plugin and, KFileDialog request KGlobal::config for many things.

BUG: 182861



 M  +21 -7     kglobal.cpp  


--- trunk/KDE/kdelibs/kdecore/kernel/kglobal.cpp #920284:920285
@@ -1,6 +1,7 @@
 /* This file is part of the KDE libraries
    Copyright (C) 1999 Sirtaj Singh Kanq <taj at kde.org>
    Copyright (C) 2007 Matthias Kretz <kretz at kde.org>
+   Copyright (C) 2009 Olivier Goffart <ogoffart at kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -93,31 +94,44 @@
         KStringDict *stringDict;
         KLocale *locale;
         KCharsets *charsets;
+
+        /**
+         * This componenent may be used instead of the main component for application
+         * That doesn't have a main componennt such as pure Qt application.
+         */
+        static KComponentData initFakeComponent()
+        {
+            QString name = QCoreApplication::applicationName();
+            if(name.isEmpty())
+                name = qAppName();
+            if(name.isEmpty())
+                name = QString::fromLatin1("kde");
+            return KComponentData(name.toLatin1(), name.toLatin1(),
+                                  KComponentData::SkipMainComponentRegistration);
+        }
 };
 
 K_GLOBAL_STATIC(KGlobalPrivate, globalData)
+K_GLOBAL_STATIC_WITH_ARGS(KComponentData, fakeComponent, (KGlobalPrivate::initFakeComponent()))
 
 #define PRIVATE_DATA KGlobalPrivate *d = globalData
 
 KStandardDirs *KGlobal::dirs()
 {
     PRIVATE_DATA;
-    MYASSERT(d->mainComponent.isValid());
-    return d->mainComponent.dirs();
+    return d->mainComponent.isValid() ? d->mainComponent.dirs() : fakeComponent->dirs();
 }
 
 KSharedConfig::Ptr KGlobal::config()
 {
     PRIVATE_DATA;
-    MYASSERT(d->mainComponent.isValid());
-    return d->mainComponent.config();
+    return d->mainComponent.isValid() ? d->mainComponent.config() : fakeComponent->config();
 }
 
 const KComponentData &KGlobal::mainComponent()
 {
     PRIVATE_DATA;
-    MYASSERT(d->mainComponent.isValid());
-    return d->mainComponent;
+    return d->mainComponent.isValid() ? d->mainComponent : *fakeComponent;
 }
 
 bool KGlobal::hasMainComponent()
@@ -240,7 +254,7 @@
         return args->getOption("caption");
     } else {
         // We have some about data ?
-        if (d->mainComponent.aboutData()) {
+        if (d->mainComponent.isValid() && d->mainComponent.aboutData()) {
             return d->mainComponent.aboutData()->programName();
         } else {
             // Last resort : application name


----- End forwarded message -----

-- 
There was a phone call for you.




More information about the KDevelop-devel mailing list