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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • 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 
36 KComponentData::KComponentData()
37  : d(0)
38 {
39 }
40 
41 KComponentData::KComponentData(const KComponentData &rhs)
42  : d(rhs.d)
43 {
44  if (d) {
45  d->ref();
46  }
47 }
48 
49 KComponentData &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 
63 bool KComponentData::operator==(const KComponentData &rhs) const
64 {
65  return d == rhs.d;
66 }
67 
68 enum KdeLibraryPathsAdded {
69  NeedLazyInit,
70  LazyInitDone,
71  KdeLibraryPathsAddedDone
72 };
73 static KdeLibraryPathsAdded kdeLibraryPathsAdded = NeedLazyInit;
74 
75 KComponentData::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 
90 KComponentData::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 
105 KComponentData::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 
120 KComponentData::~KComponentData()
121 {
122  if (d) {
123  d->deref();
124  d = 0;
125  }
126 }
127 
128 bool KComponentData::isValid() const
129 {
130  return (d != 0);
131 }
132 
133 void 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 
162 bool kde_kiosk_exception = false; // flag to disable kiosk restrictions
163 bool kde_kiosk_admin = false;
164 
165 void 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 
193 KStandardDirs *KComponentData::dirs() const
194 {
195  Q_ASSERT(d);
196  d->lazyInit(*this);
197 
198  return d->dirs;
199 }
200 
201 const KSharedConfig::Ptr &KComponentData::config() const
202 {
203  Q_ASSERT(d);
204  d->lazyInit(*this);
205 
206  return d->sharedConfig;
207 }
208 
209 void KComponentData::setConfigName(const QString &configName)
210 {
211  Q_ASSERT(d);
212  d->configName = configName;
213 }
214 
215 const KAboutData *KComponentData::aboutData() const
216 {
217  Q_ASSERT(d);
218  return &d->aboutData;
219 }
220 
221 void KComponentData::setAboutData(const KAboutData &aboutData)
222 {
223  d->aboutData = aboutData;
224 }
225 
226 QString KComponentData::componentName() const
227 {
228  Q_ASSERT(d);
229  return d->aboutData.appName();
230 }
231 
232 QString KComponentData::catalogName() const
233 {
234  Q_ASSERT(d);
235  return d->aboutData.catalogName();
236 }
237 
238 void KComponentData::virtual_hook(int, void*)
239 { /*BASE::virtual_hook(id, data);*/ }
KComponentData::operator=
KComponentData & operator=(const KComponentData &)
Assignment operator.
Definition: kcomponentdata.cpp:49
KSharedPtr< KSharedConfig >
KdeLibraryPathsAddedDone
Definition: kcomponentdata.cpp:71
KComponentDataPrivate::configInit
void configInit(const KComponentData &component)
Definition: kcomponentdata.cpp:165
KSharedPtr::data
T * data()
Definition: ksharedptr.h:111
KAboutData::appName
QString appName() const
Returns the application's internal name.
Definition: kaboutdata.cpp:678
KStandardDirs::addResourceType
bool addResourceType(const char *type, const QString &relativename, bool priority=true)
Adds suffixes for types.
Definition: kstandarddirs.cpp:393
QByteArray
kconfig.h
kdeLibraryPathsAdded
static KdeLibraryPathsAdded kdeLibraryPathsAdded
Definition: kcomponentdata.cpp:73
KComponentData::operator==
bool operator==(const KComponentData &) const
Returns whether two KComponentData objects reference the same data.
Definition: kcomponentdata.cpp:63
NeedLazyInit
Definition: kcomponentdata.cpp:69
QByteArray::isEmpty
bool isEmpty() const
KComponentData::virtual_hook
virtual void virtual_hook(int id, void *data)
Standard trick to add virtuals later.
Definition: kcomponentdata.cpp:238
KGlobal::newComponentData
void newComponentData(const KComponentData &c)
Definition: kglobal.cpp:246
kde_kiosk_admin
bool kde_kiosk_admin
Definition: kcomponentdata.cpp:163
KComponentData::aboutData
const KAboutData * aboutData() const
Returns the about data of this component.
Definition: kcomponentdata.cpp:215
KComponentDataPrivate::configName
QString configName
Definition: kcomponentdata_p.h:87
klocale.h
KComponentDataPrivate::deref
void deref()
Definition: kcomponentdata_p.h:66
QCoreApplication::addLibraryPath
void addLibraryPath(const QString &path)
KComponentData::catalogName
QString catalogName() const
Returns the name of the translation catalog.
Definition: kcomponentdata.cpp:232
KComponentDataPrivate::sharedConfig
KSharedConfig::Ptr sharedConfig
Definition: kcomponentdata_p.h:88
kglobal.h
KComponentData::config
const KSharedConfig::Ptr & config() const
Returns the general config object ("appnamerc").
Definition: kcomponentdata.cpp:201
KComponentData::setConfigName
void setConfigName(const QString &name)
Set name of default config file.
Definition: kcomponentdata.cpp:209
KComponentDataPrivate
Definition: kcomponentdata_p.h:33
KComponentDataPrivate::ref
void ref()
Definition: kcomponentdata_p.h:60
KStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:171
kcmdlineargs.h
QString::isEmpty
bool isEmpty() const
KComponentData::KComponentData
KComponentData()
Creates an invalid KComponentData object.
Definition: kcomponentdata.cpp:36
KComponentData::RegisterAsMainComponent
Definition: kcomponentdata.h:85
kglobal_p.h
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:192
KComponentDataPrivate::lazyInit
void lazyInit(const KComponentData &component)
Definition: kcomponentdata.cpp:133
QCoreApplication::instance
QCoreApplication * instance()
KComponentData::componentName
QString componentName() const
Returns the name of the component.
Definition: kcomponentdata.cpp:226
QString
KdeLibraryPathsAdded
KdeLibraryPathsAdded
Definition: kcomponentdata.cpp:68
QStringList
KComponentDataPrivate::aboutData
KAboutData aboutData
Definition: kcomponentdata_p.h:86
QList::end
iterator end()
KComponentData::~KComponentData
virtual ~KComponentData()
Destructor.
Definition: kcomponentdata.cpp:120
QLatin1Char
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
LazyInitDone
Definition: kcomponentdata.cpp:70
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:53
kcomponentdata_p.h
kstandarddirs.h
KConfig::reparseConfiguration
void reparseConfiguration()
Updates the state of this object to match the persistent storage.
Definition: kconfig.cpp:557
QList::ConstIterator
typedef ConstIterator
KComponentData::isValid
bool isValid() const
Returns whether this is a valid object.
Definition: kcomponentdata.cpp:128
kde_kiosk_exception
bool kde_kiosk_exception
Definition: kcomponentdata.cpp:162
KComponentData::setAboutData
void setAboutData(const KAboutData &aboutData)
Sets the about data of this component.
Definition: kcomponentdata.cpp:221
KComponentData::MainComponentRegistration
MainComponentRegistration
Definition: kcomponentdata.h:84
KStandardDirs::addCustomized
bool addCustomized(KConfig *config)
Reads customized entries out of the given config object and add them via addResourceDirs().
Definition: kstandarddirs.cpp:1939
kaboutdata.h
KComponentDataPrivate::dirs
KStandardDirs * dirs
Definition: kcomponentdata_p.h:85
kcomponentdata.h
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
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
KLocalizedString
Class for producing and handling localized messages.
Definition: klocalizedstring.h:299
QList::begin
iterator begin()
KComponentData
Per component data.
Definition: kcomponentdata.h:46
kconfiggroup.h
KComponentData::dirs
KStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kcomponentdata.cpp:193
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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