KDECore
kcomponentdata.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1999 Torben Weis <weis@kde.org> 00003 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 00004 Copyright (C) 2007 Bernhard Loos <nhuh.put@web.de> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "kcomponentdata.h" 00022 #include "kcomponentdata_p.h" 00023 00024 #include <QtCore/QCoreApplication> 00025 00026 #include "kaboutdata.h" 00027 #include "kcmdlineargs.h" 00028 #include "kconfig.h" 00029 #include "kglobal.h" 00030 #include "kglobal_p.h" 00031 #include "klocale.h" 00032 #include "kconfiggroup.h" 00033 #include "kstandarddirs.h" 00034 #include <QtDebug> 00035 00036 KComponentData::KComponentData() 00037 : d(0) 00038 { 00039 } 00040 00041 KComponentData::KComponentData(const KComponentData &rhs) 00042 : d(rhs.d) 00043 { 00044 if (d) { 00045 d->ref(); 00046 } 00047 } 00048 00049 KComponentData &KComponentData::operator=(const KComponentData &rhs) 00050 { 00051 if (rhs.d != d) { 00052 if (rhs.d) { 00053 rhs.d->ref(); 00054 } 00055 if (d) { 00056 d->deref(); 00057 } 00058 d = rhs.d; 00059 } 00060 return *this; 00061 } 00062 00063 bool KComponentData::operator==(const KComponentData &rhs) const 00064 { 00065 return d == rhs.d; 00066 } 00067 00068 enum KdeLibraryPathsAdded { 00069 NeedLazyInit, 00070 LazyInitDone, 00071 KdeLibraryPathsAddedDone 00072 }; 00073 static KdeLibraryPathsAdded kdeLibraryPathsAdded = NeedLazyInit; 00074 00075 KComponentData::KComponentData(const QByteArray &name, const QByteArray &catalog, MainComponentRegistration registerAsMain) 00076 : d(new KComponentDataPrivate(KAboutData(name, catalog, KLocalizedString(), "", KLocalizedString()))) 00077 { 00078 Q_ASSERT(!name.isEmpty()); 00079 00080 if (kdeLibraryPathsAdded == NeedLazyInit) { 00081 kdeLibraryPathsAdded = LazyInitDone; 00082 d->lazyInit(*this); 00083 } 00084 00085 if (registerAsMain == RegisterAsMainComponent) { 00086 KGlobal::newComponentData(*this); 00087 } 00088 } 00089 00090 KComponentData::KComponentData(const KAboutData *aboutData, MainComponentRegistration registerAsMain) 00091 : d(new KComponentDataPrivate(*aboutData)) 00092 { 00093 Q_ASSERT(!aboutData->appName().isEmpty()); 00094 00095 if (kdeLibraryPathsAdded == NeedLazyInit) { 00096 kdeLibraryPathsAdded = LazyInitDone; 00097 d->lazyInit(*this); 00098 } 00099 00100 if (registerAsMain == RegisterAsMainComponent) { 00101 KGlobal::newComponentData(*this); 00102 } 00103 } 00104 00105 KComponentData::KComponentData(const KAboutData &aboutData, MainComponentRegistration registerAsMain) 00106 : d(new KComponentDataPrivate(aboutData)) 00107 { 00108 Q_ASSERT(!aboutData.appName().isEmpty()); 00109 00110 if (kdeLibraryPathsAdded == NeedLazyInit) { 00111 kdeLibraryPathsAdded = LazyInitDone; 00112 d->lazyInit(*this); 00113 } 00114 00115 if (registerAsMain == RegisterAsMainComponent) { 00116 KGlobal::newComponentData(*this); 00117 } 00118 } 00119 00120 KComponentData::~KComponentData() 00121 { 00122 if (d) { 00123 d->deref(); 00124 d = 0; 00125 } 00126 } 00127 00128 bool KComponentData::isValid() const 00129 { 00130 return (d != 0); 00131 } 00132 00133 void KComponentDataPrivate::lazyInit(const KComponentData &component) 00134 { 00135 if (dirs == 0) { 00136 dirs = new KStandardDirs(); 00137 // install appdata resource type 00138 dirs->addResourceType("appdata", "data", aboutData.appName() + QLatin1Char('/'), true); 00139 00140 configInit(component); 00141 00142 if (dirs->addCustomized(sharedConfig.data())) 00143 sharedConfig->reparseConfiguration(); 00144 } 00145 00146 #ifdef Q_OS_WIN 00147 if (QCoreApplication::instance() && dirs && kdeLibraryPathsAdded != KdeLibraryPathsAddedDone) { 00148 #else 00149 // the first KComponentData sets the KDE Qt plugin paths 00150 if (dirs && kdeLibraryPathsAdded != KdeLibraryPathsAddedDone) { 00151 #endif 00152 kdeLibraryPathsAdded = KdeLibraryPathsAddedDone; 00153 const QStringList &plugins = dirs->resourceDirs("qtplugins"); 00154 QStringList::ConstIterator it = plugins.begin(); 00155 while (it != plugins.end()) { 00156 QCoreApplication::addLibraryPath(*it); 00157 ++it; 00158 } 00159 } 00160 } 00161 00162 bool kde_kiosk_exception = false; // flag to disable kiosk restrictions 00163 bool kde_kiosk_admin = false; 00164 00165 void KComponentDataPrivate::configInit(const KComponentData &component) 00166 { 00167 Q_ASSERT(!sharedConfig); 00168 00169 if (!configName.isEmpty()) { 00170 sharedConfig = KSharedConfig::openConfig(component, configName); 00171 00172 //FIXME: this is broken and I don't know how to repair it 00173 // Check whether custom config files are allowed. 00174 KConfigGroup cg(sharedConfig, "KDE Action Restrictions"); 00175 QString kioskException = cg.readEntry("kiosk_exception"); 00176 if (!cg.readEntry("custom_config", true)) { 00177 sharedConfig = 0; 00178 } 00179 } 00180 00181 if (!sharedConfig) { 00182 sharedConfig = KSharedConfig::openConfig(component); 00183 } 00184 00185 // Check if we are excempt from kiosk restrictions 00186 if (kde_kiosk_admin && !kde_kiosk_exception && !qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty()) { 00187 kde_kiosk_exception = true; 00188 sharedConfig = 0; 00189 configInit(component); // Reread... 00190 } 00191 } 00192 00193 KStandardDirs *KComponentData::dirs() const 00194 { 00195 Q_ASSERT(d); 00196 d->lazyInit(*this); 00197 00198 return d->dirs; 00199 } 00200 00201 const KSharedConfig::Ptr &KComponentData::config() const 00202 { 00203 Q_ASSERT(d); 00204 d->lazyInit(*this); 00205 00206 return d->sharedConfig; 00207 } 00208 00209 void KComponentData::setConfigName(const QString &configName) 00210 { 00211 Q_ASSERT(d); 00212 d->configName = configName; 00213 } 00214 00215 const KAboutData *KComponentData::aboutData() const 00216 { 00217 Q_ASSERT(d); 00218 return &d->aboutData; 00219 } 00220 00221 void KComponentData::setAboutData(const KAboutData &aboutData) 00222 { 00223 d->aboutData = aboutData; 00224 } 00225 00226 QString KComponentData::componentName() const 00227 { 00228 Q_ASSERT(d); 00229 return d->aboutData.appName(); 00230 } 00231 00232 QString KComponentData::catalogName() const 00233 { 00234 Q_ASSERT(d); 00235 return d->aboutData.catalogName(); 00236 } 00237 00238 void KComponentData::virtual_hook(int, void*) 00239 { /*BASE::virtual_hook(id, data);*/ }
KDE 4.7 API Reference