• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

  • kdecore
kinstance.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999 Torben Weis <weis@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 #include "kinstance.h"
19 
20 #include <stdlib.h>
21 #include <unistd.h>
22 
23 #include "kconfig.h"
24 #include "klocale.h"
25 #include "kcharsets.h"
26 #include "kiconloader.h"
27 #include "kaboutdata.h"
28 #include "kstandarddirs.h"
29 #include "kdebug.h"
30 #include "kglobal.h"
31 #include "kmimesourcefactory.h"
32 
33 #include <tqfont.h>
34 
35 #include "config.h"
36 #ifndef NDEBUG
37  #include <assert.h>
38  #include <tqptrdict.h>
39  static TQPtrList<KInstance> *allInstances = 0;
40  static TQPtrDict<TQCString> *allOldInstances = 0;
41  #define DEBUG_ADD do { if (!allInstances) { allInstances = new TQPtrList<KInstance>(); allOldInstances = new TQPtrDict<TQCString>(); } allInstances->append(this); allOldInstances->insert( this, new TQCString( _name)); } while (false);
42  #define DEBUG_REMOVE do { allInstances->removeRef(this); } while (false);
43  #define DEBUG_CHECK_ALIVE do { if (!allInstances->contains((KInstance*)this)) { TQCString *old = allOldInstances->find((KInstance*)this); qWarning("ACCESSING DELETED KINSTANCE! (%s)", old ? old->data() : "<unknown>"); assert(false); } } while (false);
44 #else
45  #define DEBUG_ADD
46  #define DEBUG_REMOVE
47  #define DEBUG_CHECK_ALIVE
48 #endif
49 
50 class KInstancePrivate
51 {
52 public:
53  KInstancePrivate ()
54  {
55  mimeSourceFactory = 0L;
56  }
57 
58  ~KInstancePrivate ()
59  {
60  delete mimeSourceFactory;
61  }
62 
63  KMimeSourceFactory* mimeSourceFactory;
64  TQString configName;
65  bool ownAboutdata;
66  KSharedConfig::Ptr sharedConfig;
67 };
68 
69 KInstance::KInstance( const TQCString& name)
70  : _dirs (0L),
71  _config (0L),
72  _iconLoader (0L),
73  _name( name ), _aboutData( new KAboutData( name, "", 0 ) )
74 {
75  DEBUG_ADD
76  Q_ASSERT(!name.isEmpty());
77  if (!KGlobal::_instance)
78  {
79  KGlobal::_instance = this;
80  KGlobal::setActiveInstance(this);
81  }
82 
83  d = new KInstancePrivate ();
84  d->ownAboutdata = true;
85 }
86 
87 KInstance::KInstance( const KAboutData * aboutData )
88  : _dirs (0L),
89  _config (0L),
90  _iconLoader (0L),
91  _name( aboutData->appName() ), _aboutData( aboutData )
92 {
93  DEBUG_ADD
94  Q_ASSERT(!_name.isEmpty());
95 
96  if (!KGlobal::_instance)
97  {
98  KGlobal::_instance = this;
99  KGlobal::setActiveInstance(this);
100  }
101 
102  d = new KInstancePrivate ();
103  d->ownAboutdata = false;
104 }
105 
106 KInstance::KInstance( KInstance* src )
107  : _dirs ( src->_dirs ),
108  _config ( src->_config ),
109  _iconLoader ( src->_iconLoader ),
110  _name( src->_name ), _aboutData( src->_aboutData )
111 {
112  DEBUG_ADD
113  Q_ASSERT(!_name.isEmpty());
114 
115  if (!KGlobal::_instance || KGlobal::_instance == src )
116  {
117  KGlobal::_instance = this;
118  KGlobal::setActiveInstance(this);
119  }
120 
121  d = new KInstancePrivate ();
122  d->ownAboutdata = src->d->ownAboutdata;
123  d->sharedConfig = src->d->sharedConfig;
124 
125  src->_dirs = 0L;
126  src->_config = 0L;
127  src->_iconLoader = 0L;
128  src->_aboutData = 0L;
129  delete src;
130 }
131 
132 KInstance::~KInstance()
133 {
134  DEBUG_CHECK_ALIVE
135 
136  if (d->ownAboutdata)
137  delete _aboutData;
138  _aboutData = 0;
139 
140  delete d;
141  d = 0;
142 
143  delete _iconLoader;
144  _iconLoader = 0;
145 
146  // delete _config; // Do not delete, stored in d->sharedConfig
147  _config = 0;
148  delete _dirs;
149  _dirs = 0;
150 
151  if (KGlobal::_instance == this)
152  KGlobal::_instance = 0;
153  if (KGlobal::activeInstance() == this)
154  KGlobal::setActiveInstance(0);
155  DEBUG_REMOVE
156 }
157 
158 
159 KStandardDirs *KInstance::dirs() const
160 {
161  DEBUG_CHECK_ALIVE
162  if( _dirs == 0 ) {
163  _dirs = new KStandardDirs( );
164  if (_config) {
165  if (_dirs->addCustomized(_config))
166  _config->reparseConfiguration();
167  } else
168  config(); // trigger adding of possible customized dirs
169  }
170 
171  return _dirs;
172 }
173 
174 extern bool kde_kiosk_exception;
175 extern bool kde_kiosk_admin;
176 
177 KConfig *KInstance::config() const
178 {
179  DEBUG_CHECK_ALIVE
180  if( _config == 0 ) {
181  if ( !d->configName.isEmpty() )
182  {
183  d->sharedConfig = KSharedConfig::openConfig( d->configName );
184 
185  // Check whether custom config files are allowed.
186  d->sharedConfig->setGroup( "KDE Action Restrictions" );
187  TQString kioskException = d->sharedConfig->readEntry("kiosk_exception");
188  if (d->sharedConfig->readBoolEntry( "custom_config", true))
189  {
190  d->sharedConfig->setGroup(TQString::null);
191  }
192  else
193  {
194  d->sharedConfig = 0;
195  }
196 
197  }
198 
199  if ( d->sharedConfig == 0 )
200  {
201  if ( !_name.isEmpty() )
202  d->sharedConfig = KSharedConfig::openConfig( _name + "rc");
203  else
204  d->sharedConfig = KSharedConfig::openConfig( TQString::null );
205  }
206 
207  // Check if we are excempt from kiosk restrictions
208  if (kde_kiosk_admin && !kde_kiosk_exception && !TQCString(getenv("KDE_KIOSK_NO_RESTRICTIONS")).isEmpty())
209  {
210  kde_kiosk_exception = true;
211  d->sharedConfig = 0;
212  return config(); // Reread...
213  }
214 
215  _config = d->sharedConfig;
216  if (_dirs)
217  if (_dirs->addCustomized(_config))
218  _config->reparseConfiguration();
219  }
220 
221  return _config;
222 }
223 
224 KSharedConfig *KInstance::sharedConfig() const
225 {
226  DEBUG_CHECK_ALIVE
227  if (_config == 0)
228  (void) config(); // Initialize config
229 
230  return d->sharedConfig;
231 }
232 
233 void KInstance::setConfigName(const TQString &configName)
234 {
235  DEBUG_CHECK_ALIVE
236  d->configName = configName;
237 }
238 
239 KIconLoader *KInstance::iconLoader() const
240 {
241  DEBUG_CHECK_ALIVE
242  if( _iconLoader == 0 ) {
243  _iconLoader = new KIconLoader( _name, dirs() );
244  _iconLoader->enableDelayedIconSetLoading( true );
245  }
246 
247  return _iconLoader;
248 }
249 
250 void KInstance::newIconLoader() const
251 {
252  DEBUG_CHECK_ALIVE
253  KIconTheme::reconfigure();
254  _iconLoader->reconfigure( _name, dirs() );
255 }
256 
257 const KAboutData * KInstance::aboutData() const
258 {
259  DEBUG_CHECK_ALIVE
260  return _aboutData;
261 }
262 
263 TQCString KInstance::instanceName() const
264 {
265  DEBUG_CHECK_ALIVE
266  return _name;
267 }
268 
269 KMimeSourceFactory* KInstance::mimeSourceFactory () const
270 {
271  DEBUG_CHECK_ALIVE
272  if (!d->mimeSourceFactory)
273  {
274  d->mimeSourceFactory = new KMimeSourceFactory(_iconLoader);
275  d->mimeSourceFactory->setInstance(const_cast<KInstance *>(this));
276  }
277 
278  return d->mimeSourceFactory;
279 }
280 
281 void KInstance::virtual_hook( int, void* )
282 { /*BASE::virtual_hook( id, data );*/ }
283 
KIconTheme::reconfigure
static void reconfigure()
Reconfigure the theme.
Definition: kicontheme.cpp:503
KSharedPtr
Can be used to control the lifetime of an object that has derived KShared.
Definition: ksharedptr.h:100
KIconLoader::reconfigure
void reconfigure(const TQString &_appname, KStandardDirs *_dirs)
Called by KInstance::newIconLoader to reconfigure the icon loader.
Definition: kiconloader.cpp:166
KSharedConfig
KConfig variant using shared memory.
Definition: kconfig.h:273
KInstance::newIconLoader
void newIconLoader() const
Re-allocate the global iconloader.
Definition: kinstance.cpp:250
KInstance::~KInstance
virtual ~KInstance()
Destructor.
Definition: kinstance.cpp:132
KGlobal::setActiveInstance
static void setActiveInstance(KInstance *d)
The instance currently active (useful in a multi-instance application, such as a KParts application)...
Definition: kglobal.cpp:114
KInstance::config
KConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:177
KInstance::aboutData
const KAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
Definition: kinstance.cpp:257
KInstance::KInstance
KInstance(const TQCString &instanceName)
Constructor.
Definition: kinstance.cpp:69
klocale.h
KInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:263
KInstance::iconLoader
KIconLoader * iconLoader() const
Returns an iconloader object.
Definition: kinstance.cpp:239
KStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:125
KIconLoader::enableDelayedIconSetLoading
void enableDelayedIconSetLoading(bool enable)
Enables on-demand icon loading for QIconSets using TQIconFactory.
Definition: kiconloader.cpp:289
KInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:43
KAboutData
This class is used to store information about a program.
Definition: kaboutdata.h:182
KInstance::setConfigName
void setConfigName(const TQString &name)
Set name of default config file.
Definition: kinstance.cpp:233
KConfig
Access KDE Configuration entries.
Definition: kconfig.h:43
KConfig::reparseConfiguration
virtual void reparseConfiguration()
Clears all internal data structures and then reread configuration information from disk...
Definition: kconfig.cpp:161
KInstance::dirs
KStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kinstance.cpp:159
KInstance::sharedConfig
KSharedConfig * sharedConfig() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:224
KStandardDirs::addCustomized
bool addCustomized(KConfig *config)
Reads customized entries out of the given config object and add them via addResourceDirs().
Definition: kstandarddirs.cpp:1537
KMimeSourceFactory
An extension to TQMimeSourceFactory that uses KIconLoader to find images.
Definition: kmimesourcefactory.h:40
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const TQString &fileName, bool readOnly=false, bool bUseKDEGlobals=true)
Returns a ref-counted pointer to a shared read-write config object.
Definition: kconfig.cpp:334
KIconLoader
Iconloader for KDE.
Definition: kiconloader.h:77
KInstance::mimeSourceFactory
KMimeSourceFactory * mimeSourceFactory() const
Returns the KMimeSourceFactory of the instance.
Definition: kinstance.cpp:269

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |