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

tdecore

  • tdecore
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 "tdeconfig.h"
24 #include "tdelocale.h"
25 #include "kcharsets.h"
26 #include "kiconloader.h"
27 #ifdef __TDE_HAVE_TDEHWLIB
28 #include "tdehardwaredevices.h"
29 #include "tdenetworkconnections.h"
30 #endif
31 #include "tdeaboutdata.h"
32 #include "kstandarddirs.h"
33 #include "kdebug.h"
34 #include "tdeglobal.h"
35 #include "kmimesourcefactory.h"
36 
37 #include <tqfont.h>
38 
39 #include "config.h"
40 #ifndef NDEBUG
41  #include <assert.h>
42  #include <tqptrdict.h>
43  static TQPtrList<TDEInstance> *allInstances = 0;
44  static TQPtrDict<TQCString> *allOldInstances = 0;
45  #define DEBUG_ADD do { if (!allInstances) { allInstances = new TQPtrList<TDEInstance>(); allOldInstances = new TQPtrDict<TQCString>(); } allInstances->append(this); allOldInstances->insert( this, new TQCString( _name)); } while (false);
46  #define DEBUG_REMOVE do { allInstances->removeRef(this); } while (false);
47  #define DEBUG_CHECK_ALIVE do { if (!allInstances->contains((TDEInstance*)this)) { TQCString *old = allOldInstances->find((TDEInstance*)this); tqWarning("ACCESSING DELETED KINSTANCE! (%s)", old ? old->data() : "<unknown>"); assert(false); } } while (false);
48 #else
49  #define DEBUG_ADD
50  #define DEBUG_REMOVE
51  #define DEBUG_CHECK_ALIVE
52 #endif
53 
54 class TDEInstancePrivate
55 {
56 public:
57  TDEInstancePrivate ()
58  {
59  mimeSourceFactory = 0L;
60  }
61 
62  ~TDEInstancePrivate ()
63  {
64  delete mimeSourceFactory;
65  }
66 
67  KMimeSourceFactory* mimeSourceFactory;
68  TQString configName;
69  bool ownAboutdata;
70  TDESharedConfig::Ptr sharedConfig;
71 };
72 
73 TDEInstance::TDEInstance( const TQCString& name)
74  : _dirs (0L),
75  _config (0L),
76  _iconLoader (0L),
77 #ifdef __TDE_HAVE_TDEHWLIB
78  _hardwaredevices (0L),
79  _networkmanager (0L),
80 #endif
81  _name( name ), _aboutData( new TDEAboutData( name, "", 0 ) ), m_configReadOnly(false)
82 {
83  DEBUG_ADD
84  Q_ASSERT(!name.isEmpty());
85  if (!TDEGlobal::_instance)
86  {
87  TDEGlobal::_instance = this;
88  TDEGlobal::setActiveInstance(this);
89  }
90 
91  d = new TDEInstancePrivate ();
92  d->ownAboutdata = true;
93 }
94 
95 TDEInstance::TDEInstance( const TDEAboutData * aboutData )
96  : _dirs (0L),
97  _config (0L),
98  _iconLoader (0L),
99 #ifdef __TDE_HAVE_TDEHWLIB
100  _hardwaredevices (0L),
101  _networkmanager (0L),
102 #endif
103  _name( aboutData->appName() ), _aboutData( aboutData ), m_configReadOnly(false)
104 {
105  DEBUG_ADD
106  Q_ASSERT(!_name.isEmpty());
107 
108  if (!TDEGlobal::_instance)
109  {
110  TDEGlobal::_instance = this;
111  TDEGlobal::setActiveInstance(this);
112  }
113 
114  d = new TDEInstancePrivate ();
115  d->ownAboutdata = false;
116 }
117 
118 TDEInstance::TDEInstance( TDEInstance* src )
119  : _dirs ( src->_dirs ),
120  _config ( src->_config ),
121  _iconLoader ( src->_iconLoader ),
122 #ifdef __TDE_HAVE_TDEHWLIB
123  _hardwaredevices ( src->_hardwaredevices ),
124  _networkmanager ( src->_networkmanager ),
125 #endif
126  _name( src->_name ), _aboutData( src->_aboutData ), m_configReadOnly(false)
127 {
128  DEBUG_ADD
129  Q_ASSERT(!_name.isEmpty());
130 
131  if (!TDEGlobal::_instance || TDEGlobal::_instance == src )
132  {
133  TDEGlobal::_instance = this;
134  TDEGlobal::setActiveInstance(this);
135  }
136 
137  d = new TDEInstancePrivate ();
138  d->ownAboutdata = src->d->ownAboutdata;
139  d->sharedConfig = src->d->sharedConfig;
140 
141  src->_dirs = 0L;
142  src->_config = 0L;
143  src->_iconLoader = 0L;
144 #ifdef __TDE_HAVE_TDEHWLIB
145  src->_hardwaredevices = 0L;
146  src->_networkmanager = 0L;
147 #endif
148  src->_aboutData = 0L;
149  delete src;
150 }
151 
152 TDEInstance::~TDEInstance()
153 {
154  DEBUG_CHECK_ALIVE
155 
156  if (d->ownAboutdata)
157  delete _aboutData;
158  _aboutData = 0;
159 
160  delete d;
161  d = 0;
162 
163  delete _iconLoader;
164  _iconLoader = 0;
165 
166 #ifdef __TDE_HAVE_TDEHWLIB
167  delete _hardwaredevices;
168  _hardwaredevices = 0;
169 
170  delete _networkmanager;
171  _networkmanager = 0;
172 #endif
173 
174  // delete _config; // Do not delete, stored in d->sharedConfig
175  _config = 0;
176  delete _dirs;
177  _dirs = 0;
178 
179  if (TDEGlobal::_instance == this)
180  TDEGlobal::_instance = 0;
181  if (TDEGlobal::activeInstance() == this)
182  TDEGlobal::setActiveInstance(0);
183  DEBUG_REMOVE
184 }
185 
186 
187 TDEStandardDirs *TDEInstance::dirs() const
188 {
189  DEBUG_CHECK_ALIVE
190  if( _dirs == 0 ) {
191  _dirs = new TDEStandardDirs( );
192  if (_config) {
193  if (_dirs->addCustomized(_config))
194  _config->reparseConfiguration();
195  } else
196  config(); // trigger adding of possible customized dirs
197  }
198 
199  return _dirs;
200 }
201 
202 extern bool kde_kiosk_exception;
203 extern bool kde_kiosk_admin;
204 
205 void TDEInstance::setConfigReadOnly(bool ro)
206 {
207  m_configReadOnly = ro;
208 }
209 
210 TDEConfig *TDEInstance::config() const
211 {
212  DEBUG_CHECK_ALIVE
213  if( _config == 0 ) {
214  if ( !d->configName.isEmpty() )
215  {
216  d->sharedConfig = TDESharedConfig::openConfig( d->configName );
217 
218  // Check whether custom config files are allowed.
219  d->sharedConfig->setGroup( "KDE Action Restrictions" );
220  TQString kioskException = d->sharedConfig->readEntry("kiosk_exception");
221  if (d->sharedConfig->readBoolEntry( "custom_config", true))
222  {
223  d->sharedConfig->setGroup(TQString::null);
224  }
225  else
226  {
227  d->sharedConfig = 0;
228  }
229 
230  }
231 
232  if ( d->sharedConfig == 0 )
233  {
234  if ( !_name.isEmpty() ) {
235  d->sharedConfig = TDESharedConfig::openConfig( _name + "rc", m_configReadOnly );
236  }
237  else {
238  d->sharedConfig = TDESharedConfig::openConfig( TQString::null );
239  }
240  }
241 
242  // Check if we are excempt from kiosk restrictions
243  if (kde_kiosk_admin && !kde_kiosk_exception && !TQCString(getenv("TDE_KIOSK_NO_RESTRICTIONS")).isEmpty())
244  {
245  kde_kiosk_exception = true;
246  d->sharedConfig = 0;
247  return config(); // Reread...
248  }
249 
250  _config = d->sharedConfig;
251  if (_dirs)
252  if (_dirs->addCustomized(_config))
253  _config->reparseConfiguration();
254  }
255 
256  return _config;
257 }
258 
259 TDESharedConfig *TDEInstance::sharedConfig() const
260 {
261  DEBUG_CHECK_ALIVE
262  if (_config == 0)
263  (void) config(); // Initialize config
264 
265  return d->sharedConfig;
266 }
267 
268 void TDEInstance::setConfigName(const TQString &configName)
269 {
270  DEBUG_CHECK_ALIVE
271  d->configName = configName;
272 }
273 
274 TDEIconLoader *TDEInstance::iconLoader() const
275 {
276  DEBUG_CHECK_ALIVE
277  if( _iconLoader == 0 ) {
278  _iconLoader = new TDEIconLoader( _name, dirs() );
279  _iconLoader->enableDelayedIconSetLoading( true );
280  }
281 
282  return _iconLoader;
283 }
284 
285 #ifdef __TDE_HAVE_TDEHWLIB
286 TDEHardwareDevices *TDEInstance::hardwareDevices() const
287 {
288  DEBUG_CHECK_ALIVE
289  if( _hardwaredevices == 0 ) {
290  _hardwaredevices = new TDEHardwareDevices( );
291  }
292 
293  return _hardwaredevices;
294 }
295 
296 TDEGlobalNetworkManager *TDEInstance::networkManager() const
297 {
298  DEBUG_CHECK_ALIVE
299  if( _networkmanager == 0 ) {
300  _networkmanager = new TDEGlobalNetworkManager( );
301  }
302 
303  return _networkmanager;
304 }
305 #endif
306 
307 void TDEInstance::newIconLoader() const
308 {
309  DEBUG_CHECK_ALIVE
310  TDEIconTheme::reconfigure();
311  _iconLoader->reconfigure( _name, dirs() );
312 }
313 
314 const TDEAboutData * TDEInstance::aboutData() const
315 {
316  DEBUG_CHECK_ALIVE
317  return _aboutData;
318 }
319 
320 TQCString TDEInstance::instanceName() const
321 {
322  DEBUG_CHECK_ALIVE
323  return _name;
324 }
325 
326 KMimeSourceFactory* TDEInstance::mimeSourceFactory () const
327 {
328  DEBUG_CHECK_ALIVE
329  if (!d->mimeSourceFactory)
330  {
331  d->mimeSourceFactory = new KMimeSourceFactory(_iconLoader);
332  d->mimeSourceFactory->setInstance(const_cast<TDEInstance *>(this));
333  }
334 
335  return d->mimeSourceFactory;
336 }
337 
338 void TDEInstance::virtual_hook( int, void* )
339 { /*BASE::virtual_hook( id, data );*/ }
340 
TDEConfig::reparseConfiguration
virtual void reparseConfiguration()
Clears all internal data structures and then reread configuration information from disk...
Definition: tdeconfig.cpp:161
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:43
TDEIconLoader::enableDelayedIconSetLoading
void enableDelayedIconSetLoading(bool enable)
Enables on-demand icon loading for QIconSets using TQIconFactory.
Definition: kiconloader.cpp:289
TDESharedConfig::openConfig
static TDESharedConfig::Ptr openConfig(const TQString &fileName, bool readOnly=false, bool bUseKDEGlobals=true)
Returns a ref-counted pointer to a shared read-write config object.
Definition: tdeconfig.cpp:334
TDEInstance::iconLoader
TDEIconLoader * iconLoader() const
Returns an iconloader object.
Definition: kinstance.cpp:274
TDEInstance::dirs
TDEStandardDirs * dirs() const
Returns the application standard dirs object.
Definition: kinstance.cpp:187
TDEAboutData
This class is used to store information about a program.
Definition: tdeaboutdata.h:182
TDEInstance::aboutData
const TDEAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
Definition: kinstance.cpp:314
TDEStandardDirs
Site-independent access to standard KDE directories.
Definition: kstandarddirs.h:125
TDEIconLoader::reconfigure
void reconfigure(const TQString &_appname, TDEStandardDirs *_dirs)
Called by TDEInstance::newIconLoader to reconfigure the icon loader.
Definition: kiconloader.cpp:166
TDEInstance::newIconLoader
void newIconLoader() const
Re-allocate the global iconloader.
Definition: kinstance.cpp:307
tdelocale.h
TDEInstance::mimeSourceFactory
KMimeSourceFactory * mimeSourceFactory() const
Returns the KMimeSourceFactory of the instance.
Definition: kinstance.cpp:326
TDEIconTheme::reconfigure
static void reconfigure()
Reconfigure the theme.
Definition: kicontheme.cpp:503
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:320
TDEIconLoader
Iconloader for KDE.
Definition: kiconloader.h:77
TDEInstance::setConfigReadOnly
void setConfigReadOnly(bool ro)
Set a read-only flag on the configuration files This must be called before config() or dirs() to have...
Definition: kinstance.cpp:205
TDEInstance::config
TDEConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:210
TDEStandardDirs::addCustomized
bool addCustomized(TDEConfig *config)
Reads customized entries out of the given config object and add them via addResourceDirs().
Definition: kstandarddirs.cpp:1537
TDESharedConfig
TDEConfig variant using shared memory.
Definition: tdeconfig.h:273
TDEInstance::setConfigName
void setConfigName(const TQString &name)
Set name of default config file.
Definition: kinstance.cpp:268
TDEInstance::sharedConfig
TDESharedConfig * sharedConfig() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:259
KMimeSourceFactory
An extension to TQMimeSourceFactory that uses TDEIconLoader to find images.
Definition: kmimesourcefactory.h:40
TDESharedPtr
Can be used to control the lifetime of an object that has derived TDEShared.
Definition: ksharedptr.h:100
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:47
TDEGlobal::setActiveInstance
static void setActiveInstance(TDEInstance *d)
The instance currently active (useful in a multi-instance application, such as a KParts application)...
Definition: tdeglobal.cpp:134
TDEInstance::~TDEInstance
virtual ~TDEInstance()
Destructor.
Definition: kinstance.cpp:152
TDEInstance::TDEInstance
TDEInstance(const TQCString &instanceName)
Constructor.
Definition: kinstance.cpp:73

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.