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 KComponentData::KComponentData(const QByteArray &name, const QByteArray &catalog, MainComponentRegistration registerAsMain)
00069 : d(new KComponentDataPrivate(KAboutData(name, catalog, KLocalizedString(), "", KLocalizedString())))
00070 {
00071 Q_ASSERT(!name.isEmpty());
00072
00073 if (registerAsMain == RegisterAsMainComponent) {
00074 KGlobal::newComponentData(*this);
00075 }
00076 }
00077
00078 KComponentData::KComponentData(const KAboutData *aboutData, MainComponentRegistration registerAsMain)
00079 : d(new KComponentDataPrivate(*aboutData))
00080 {
00081 Q_ASSERT(!aboutData->appName().isEmpty());
00082
00083 if (registerAsMain == RegisterAsMainComponent) {
00084 KGlobal::newComponentData(*this);
00085 }
00086 }
00087
00088 KComponentData::KComponentData(const KAboutData &aboutData, MainComponentRegistration registerAsMain)
00089 : d(new KComponentDataPrivate(aboutData))
00090 {
00091 Q_ASSERT(!aboutData.appName().isEmpty());
00092
00093 if (registerAsMain == RegisterAsMainComponent) {
00094 KGlobal::newComponentData(*this);
00095 }
00096 }
00097
00098 KComponentData::~KComponentData()
00099 {
00100 if (d) {
00101 d->deref();
00102 d = 0;
00103 }
00104 }
00105
00106 bool KComponentData::isValid() const
00107 {
00108 return (d != 0);
00109 }
00110
00111 void KComponentDataPrivate::lazyInit(const KComponentData &component)
00112 {
00113 if (dirs == 0) {
00114 dirs = new KStandardDirs();
00115
00116 dirs->addResourceType("appdata", "data", aboutData.appName() + QLatin1Char('/'), true);
00117
00118 configInit(component);
00119
00120 if (dirs->addCustomized(sharedConfig.data()))
00121 sharedConfig->reparseConfiguration();
00122 }
00123 }
00124
00125 bool kde_kiosk_exception = false;
00126 bool kde_kiosk_admin = false;
00127
00128 void KComponentDataPrivate::configInit(const KComponentData &component)
00129 {
00130 Q_ASSERT(!sharedConfig);
00131
00132 if (!configName.isEmpty()) {
00133 sharedConfig = KSharedConfig::openConfig(component, configName);
00134
00135
00136
00137 KConfigGroup cg(sharedConfig, "KDE Action Restrictions");
00138 QString kioskException = cg.readEntry("kiosk_exception");
00139 if (!cg.readEntry("custom_config", true)) {
00140 sharedConfig = 0;
00141 }
00142 }
00143
00144 if (!sharedConfig) {
00145 sharedConfig = KSharedConfig::openConfig(component);
00146 }
00147
00148
00149 if (kde_kiosk_admin && !kde_kiosk_exception && !qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty()) {
00150 kde_kiosk_exception = true;
00151 sharedConfig = 0;
00152 configInit(component);
00153 }
00154 }
00155
00156 KStandardDirs *KComponentData::dirs() const
00157 {
00158 Q_ASSERT(d);
00159 d->lazyInit(*this);
00160
00161 return d->dirs;
00162 }
00163
00164 const KSharedConfig::Ptr &KComponentData::config() const
00165 {
00166 Q_ASSERT(d);
00167 d->lazyInit(*this);
00168
00169 return d->sharedConfig;
00170 }
00171
00172 void KComponentData::setConfigName(const QString &configName)
00173 {
00174 Q_ASSERT(d);
00175 d->configName = configName;
00176 }
00177
00178 const KAboutData *KComponentData::aboutData() const
00179 {
00180 Q_ASSERT(d);
00181 return &d->aboutData;
00182 }
00183
00184 QString KComponentData::componentName() const
00185 {
00186 Q_ASSERT(d);
00187 return d->aboutData.appName();
00188 }
00189
00190 QString KComponentData::catalogName() const
00191 {
00192 Q_ASSERT(d);
00193 return d->aboutData.catalogName();
00194 }
00195
00196 void KComponentData::virtual_hook(int, void*)
00197 { }