KDECore
kcomponentdata.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
00147 if (QCoreApplication::instance() && 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;
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
00169
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
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);
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 QString KComponentData::componentName() const
00218 {
00219 Q_ASSERT(d);
00220 return d->aboutData.appName();
00221 }
00222
00223 QString KComponentData::catalogName() const
00224 {
00225 Q_ASSERT(d);
00226 return d->aboutData.catalogName();
00227 }
00228
00229 void KComponentData::virtual_hook(int, void*)
00230 { }