• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • kernel
kcomponentdata.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Torben Weis <weis@kde.org>
3 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 Copyright (C) 2007 Bernhard Loos <nhuh.put@web.de>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "kcomponentdata.h"
22#include "kcomponentdata_p.h"
23
24#include <QtCore/QCoreApplication>
25
26#include "kaboutdata.h"
27#include "kcmdlineargs.h"
28#include "kconfig.h"
29#include "kglobal.h"
30#include "kglobal_p.h"
31#include "klocale.h"
32#include "kconfiggroup.h"
33#include "kstandarddirs.h"
34#include <QtDebug>
35
36KComponentData::KComponentData()
37 : d(0)
38{
39}
40
41KComponentData::KComponentData(const KComponentData &rhs)
42 : d(rhs.d)
43{
44 if (d) {
45 d->ref();
46 }
47}
48
49KComponentData &KComponentData::operator=(const KComponentData &rhs)
50{
51 if (rhs.d != d) {
52 if (rhs.d) {
53 rhs.d->ref();
54 }
55 if (d) {
56 d->deref();
57 }
58 d = rhs.d;
59 }
60 return *this;
61}
62
63bool KComponentData::operator==(const KComponentData &rhs) const
64{
65 return d == rhs.d;
66}
67
68enum KdeLibraryPathsAdded {
69 NeedLazyInit,
70 LazyInitDone,
71 KdeLibraryPathsAddedDone
72};
73static KdeLibraryPathsAdded kdeLibraryPathsAdded = NeedLazyInit;
74
75KComponentData::KComponentData(const QByteArray &name, const QByteArray &catalog, MainComponentRegistration registerAsMain)
76 : d(new KComponentDataPrivate(KAboutData(name, catalog, KLocalizedString(), "", KLocalizedString())))
77{
78 Q_ASSERT(!name.isEmpty());
79
80 if (kdeLibraryPathsAdded == NeedLazyInit) {
81 kdeLibraryPathsAdded = LazyInitDone;
82 d->lazyInit(*this);
83 }
84
85 if (registerAsMain == RegisterAsMainComponent) {
86 KGlobal::newComponentData(*this);
87 }
88}
89
90KComponentData::KComponentData(const KAboutData *aboutData, MainComponentRegistration registerAsMain)
91 : d(new KComponentDataPrivate(*aboutData))
92{
93 Q_ASSERT(!aboutData->appName().isEmpty());
94
95 if (kdeLibraryPathsAdded == NeedLazyInit) {
96 kdeLibraryPathsAdded = LazyInitDone;
97 d->lazyInit(*this);
98 }
99
100 if (registerAsMain == RegisterAsMainComponent) {
101 KGlobal::newComponentData(*this);
102 }
103}
104
105KComponentData::KComponentData(const KAboutData &aboutData, MainComponentRegistration registerAsMain)
106 : d(new KComponentDataPrivate(aboutData))
107{
108 Q_ASSERT(!aboutData.appName().isEmpty());
109
110 if (kdeLibraryPathsAdded == NeedLazyInit) {
111 kdeLibraryPathsAdded = LazyInitDone;
112 d->lazyInit(*this);
113 }
114
115 if (registerAsMain == RegisterAsMainComponent) {
116 KGlobal::newComponentData(*this);
117 }
118}
119
120KComponentData::~KComponentData()
121{
122 if (d) {
123 d->deref();
124 d = 0;
125 }
126}
127
128bool KComponentData::isValid() const
129{
130 return (d != 0);
131}
132
133void KComponentDataPrivate::lazyInit(const KComponentData &component)
134{
135 if (dirs == 0) {
136 dirs = new KStandardDirs();
137 // install appdata resource type
138 dirs->addResourceType("appdata", "data", aboutData.appName() + QLatin1Char('/'), true);
139
140 configInit(component);
141
142 if (dirs->addCustomized(sharedConfig.data()))
143 sharedConfig->reparseConfiguration();
144 }
145
146#ifdef Q_OS_WIN
147 if (QCoreApplication::instance() && dirs && kdeLibraryPathsAdded != KdeLibraryPathsAddedDone) {
148#else
149 // the first KComponentData sets the KDE Qt plugin paths
150 if (dirs && kdeLibraryPathsAdded != KdeLibraryPathsAddedDone) {
151#endif
152 kdeLibraryPathsAdded = KdeLibraryPathsAddedDone;
153 const QStringList &plugins = dirs->resourceDirs("qtplugins");
154 QStringList::ConstIterator it = plugins.begin();
155 while (it != plugins.end()) {
156 QCoreApplication::addLibraryPath(*it);
157 ++it;
158 }
159 }
160}
161
162bool kde_kiosk_exception = false; // flag to disable kiosk restrictions
163bool kde_kiosk_admin = false;
164
165void KComponentDataPrivate::configInit(const KComponentData &component)
166{
167 Q_ASSERT(!sharedConfig);
168
169 if (!configName.isEmpty()) {
170 sharedConfig = KSharedConfig::openConfig(component, configName);
171
172 //FIXME: this is broken and I don't know how to repair it
173 // Check whether custom config files are allowed.
174 KConfigGroup cg(sharedConfig, "KDE Action Restrictions");
175 QString kioskException = cg.readEntry("kiosk_exception");
176 if (!cg.readEntry("custom_config", true)) {
177 sharedConfig = 0;
178 }
179 }
180
181 if (!sharedConfig) {
182 sharedConfig = KSharedConfig::openConfig(component);
183 }
184
185 // Check if we are excempt from kiosk restrictions
186 if (kde_kiosk_admin && !kde_kiosk_exception && !qgetenv("KDE_KIOSK_NO_RESTRICTIONS").isEmpty()) {
187 kde_kiosk_exception = true;
188 sharedConfig = 0;
189 configInit(component); // Reread...
190 }
191}
192
193KStandardDirs *KComponentData::dirs() const
194{
195 Q_ASSERT(d);
196 d->lazyInit(*this);
197
198 return d->dirs;
199}
200
201const KSharedConfig::Ptr &KComponentData::config() const
202{
203 Q_ASSERT(d);
204 d->lazyInit(*this);
205
206 return d->sharedConfig;
207}
208
209void KComponentData::setConfigName(const QString &configName)
210{
211 Q_ASSERT(d);
212 d->configName = configName;
213}
214
215const KAboutData *KComponentData::aboutData() const
216{
217 Q_ASSERT(d);
218 return &d->aboutData;
219}
220
221void KComponentData::setAboutData(const KAboutData &aboutData)
222{
223 d->aboutData = aboutData;
224}
225
226QString KComponentData::componentName() const
227{
228 Q_ASSERT(d);
229 return d->aboutData.appName();
230}
231
232QString KComponentData::catalogName() const
233{
234 Q_ASSERT(d);
235 return d->aboutData.catalogName();
236}
237
238void KComponentData::virtual_hook(int, void*)
239{ /*BASE::virtual_hook(id, data);*/ }
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:193
KAboutData::appName
QString appName() const
Returns the application's internal name.
Definition: kaboutdata.cpp:678
KComponentDataPrivate
Definition: kcomponentdata_p.h:34
KComponentDataPrivate::configInit
void configInit(const KComponentData &component)
Definition: kcomponentdata.cpp:165
KComponentDataPrivate::configName
QString configName
Definition: kcomponentdata_p.h:87
KComponentDataPrivate::aboutData
KAboutData aboutData
Definition: kcomponentdata_p.h:86
KComponentDataPrivate::dirs
KStandardDirs * dirs
Definition: kcomponentdata_p.h:85
KComponentDataPrivate::ref
void ref()
Definition: kcomponentdata_p.h:60
KComponentDataPrivate::lazyInit
void lazyInit(const KComponentData &component)
Definition: kcomponentdata.cpp:133
KComponentDataPrivate::deref
void deref()
Definition: kcomponentdata_p.h:66
KComponentDataPrivate::sharedConfig
KSharedConfig::Ptr sharedConfig
Definition: kcomponentdata_p.h:88
KComponentData
Per component data.
Definition: kcomponentdata.h:47
KComponentData::operator=
KComponentData & operator=(const KComponentData &)
Assignment operator.
Definition: kcomponentdata.cpp:49
KComponentData::isValid
bool isValid() const
Returns whether this is a valid object.
Definition: kcomponentdata.cpp:128
KComponentData::componentName
QString componentName() const
Returns the name of the component.
Definition: kcomponentdata.cpp:226
KComponentData::config
const KSharedConfig::Ptr & config() const
Returns the general config object ("appnamerc").
Definition: kcomponentdata.cpp:201
KComponentData::MainComponentRegistration
MainComponentRegistration
Definition: kcomponentdata.h:84
KComponentData::RegisterAsMainComponent
@ RegisterAsMainComponent
Definition: kcomponentdata.h:85
KComponentData::setConfigName
void setConfigName(const QString &name)
Set name of default config file.
Definition: kcomponentdata.cpp:209
KComponentData::dirs
KStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kcomponentdata.cpp:193
KComponentData::~KComponentData
virtual ~KComponentData()
Destructor.
Definition: kcomponentdata.cpp:120
KComponentData::operator==
bool operator==(const KComponentData &) const
Returns whether two KComponentData objects reference the same data.
Definition: kcomponentdata.cpp:63
KComponentData::aboutData
const KAboutData * aboutData() const
Returns the about data of this component.
Definition: kcomponentdata.cpp:215
KComponentData::virtual_hook
virtual void virtual_hook(int id, void *data)
Standard trick to add virtuals later.
Definition: kcomponentdata.cpp:238
KComponentData::KComponentData
KComponentData()
Creates an invalid KComponentData object.
Definition: kcomponentdata.cpp:36
KComponentData::catalogName
QString catalogName() const
Returns the name of the translation catalog.
Definition: kcomponentdata.cpp:232
KComponentData::setAboutData
void setAboutData(const KAboutData &aboutData)
Sets the about data of this component.
Definition: kcomponentdata.cpp:221
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:54
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KConfig::reparseConfiguration
void reparseConfiguration()
Updates the state of this object to match the persistent storage.
Definition: kconfig.cpp:557
KLocalizedString
Class for producing and handling localized messages.
Definition: klocalizedstring.h:300
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
Creates a KSharedConfig object to manipulate a configuration file.
Definition: ksharedconfig.cpp:31
KSharedPtr< KSharedConfig >
KSharedPtr::data
T * data()
Definition: ksharedptr.h:111
KStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:172
KStandardDirs::addResourceType
bool addResourceType(const char *type, const QString &relativename, bool priority=true)
Adds suffixes for types.
Definition: kstandarddirs.cpp:393
KStandardDirs::addCustomized
bool addCustomized(KConfig *config)
Reads customized entries out of the given config object and add them via addResourceDirs().
Definition: kstandarddirs.cpp:1945
KStandardDirs::resourceDirs
QStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
Definition: kstandarddirs.cpp:1069
QStringList
QString
kaboutdata.h
kcmdlineargs.h
KdeLibraryPathsAdded
KdeLibraryPathsAdded
Definition: kcomponentdata.cpp:68
NeedLazyInit
@ NeedLazyInit
Definition: kcomponentdata.cpp:69
LazyInitDone
@ LazyInitDone
Definition: kcomponentdata.cpp:70
KdeLibraryPathsAddedDone
@ KdeLibraryPathsAddedDone
Definition: kcomponentdata.cpp:71
kde_kiosk_admin
bool kde_kiosk_admin
Definition: kcomponentdata.cpp:163
kdeLibraryPathsAdded
static KdeLibraryPathsAdded kdeLibraryPathsAdded
Definition: kcomponentdata.cpp:73
kcomponentdata.h
kcomponentdata_p.h
kconfig.h
kconfiggroup.h
kde_kiosk_exception
bool kde_kiosk_exception
Definition: kcomponentdata.cpp:162
kglobal.h
kglobal_p.h
klocale.h
kstandarddirs.h
KGlobal::newComponentData
void newComponentData(const KComponentData &c)
Definition: kglobal.cpp:246
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal