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 // the first KComponentData sets the KDE Qt plugin paths 00147 if (dirs && kdeLibraryPathsAdded != KdeLibraryPathsAddedDone) { 00148 kdeLibraryPathsAdded = KdeLibraryPathsAddedDone; 00149 const QStringList &plugins = dirs->resourceDirs("qtplugins"); 00150 QStringList::ConstIterator it = plugins.begin(); 00151 while (it != plugins.end()) { 00152 QCoreApplication::addLibraryPath(*it); 00153 ++it; 00154 } 00155 } 00156 } 00157 00158 bool kde_kiosk_exception = false; // flag to disable kiosk restrictions 00159 bool kde_kiosk_admin = false; 00160 00161 void KComponentDataPrivate::configInit(const KComponentData &component) 00162 { 00163 Q_ASSERT(!sharedConfig); 00164 00165 if (!configName.isEmpty()) { 00166 sharedConfig = KSharedConfig::openConfig(component, configName); 00167 00168 //FIXME: this is broken and I don't know how to repair it 00169 // Check whether custom config files are allowed. 00170 KConfigGroup cg(sharedConfig, "KDE Action Restrictions"); 00171 QString kioskException = cg.readEntry("kiosk_exception"); 00172 if (!cg.readEntry("custom_config", true)) { 00173 sharedConfig = 0; 00174 } 00175 } 00176 00177 if (!sharedConfig) { 00178 sharedConfig = KSharedConfig::openConfig(component); 00179 } 00180 00181 // Check if we are excempt from kiosk restrictions 00182 if (kde_kiosk_admin && !kde_kiosk_exception && !qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty()) { 00183 kde_kiosk_exception = true; 00184 sharedConfig = 0; 00185 configInit(component); // Reread... 00186 } 00187 } 00188 00189 KStandardDirs *KComponentData::dirs() const 00190 { 00191 Q_ASSERT(d); 00192 d->lazyInit(*this); 00193 00194 return d->dirs; 00195 } 00196 00197 const KSharedConfig::Ptr &KComponentData::config() const 00198 { 00199 Q_ASSERT(d); 00200 d->lazyInit(*this); 00201 00202 return d->sharedConfig; 00203 } 00204 00205 void KComponentData::setConfigName(const QString &configName) 00206 { 00207 Q_ASSERT(d); 00208 d->configName = configName; 00209 } 00210 00211 const KAboutData *KComponentData::aboutData() const 00212 { 00213 Q_ASSERT(d); 00214 return &d->aboutData; 00215 } 00216 00217 void KComponentData::setAboutData(const KAboutData &aboutData) 00218 { 00219 d->aboutData = aboutData; 00220 } 00221 00222 QString KComponentData::componentName() const 00223 { 00224 Q_ASSERT(d); 00225 return d->aboutData.appName(); 00226 } 00227 00228 QString KComponentData::catalogName() const 00229 { 00230 Q_ASSERT(d); 00231 return d->aboutData.catalogName(); 00232 } 00233 00234 void KComponentData::virtual_hook(int, void*) 00235 { /*BASE::virtual_hook(id, data);*/ }
KDE 4.6 API Reference