• 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 #include "tdehardwaredevices.h"
28 #include "tdenetworkconnections.h"
29 #include "tdeaboutdata.h"
30 #include "kstandarddirs.h"
31 #include "kdebug.h"
32 #include "tdeglobal.h"
33 #include "kmimesourcefactory.h"
34 
35 #include <tqfont.h>
36 
37 #include "config.h"
38 #ifndef NDEBUG
39  #include <assert.h>
40  #include <tqptrdict.h>
41  static TQPtrList<TDEInstance> *allInstances = 0;
42  static TQPtrDict<TQCString> *allOldInstances = 0;
43  #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);
44  #define DEBUG_REMOVE do { allInstances->removeRef(this); } while (false);
45  #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);
46 #else
47  #define DEBUG_ADD
48  #define DEBUG_REMOVE
49  #define DEBUG_CHECK_ALIVE
50 #endif
51 
52 class TDEInstancePrivate
53 {
54 public:
55  TDEInstancePrivate ()
56  {
57  mimeSourceFactory = 0L;
58  }
59 
60  ~TDEInstancePrivate ()
61  {
62  delete mimeSourceFactory;
63  }
64 
65  KMimeSourceFactory* mimeSourceFactory;
66  TQString configName;
67  bool ownAboutdata;
68  TDESharedConfig::Ptr sharedConfig;
69 };
70 
71 TDEInstance::TDEInstance( const TQCString& name)
72  : _dirs (0L),
73  _config (0L),
74  _iconLoader (0L),
75  _hardwaredevices (0L),
76  _networkmanager (0L),
77  _name( name ), _aboutData( new TDEAboutData( name, "", 0 ) ), m_configReadOnly(false)
78 {
79  DEBUG_ADD
80  Q_ASSERT(!name.isEmpty());
81  if (!TDEGlobal::_instance)
82  {
83  TDEGlobal::_instance = this;
84  TDEGlobal::setActiveInstance(this);
85  }
86 
87  d = new TDEInstancePrivate ();
88  d->ownAboutdata = true;
89 }
90 
91 TDEInstance::TDEInstance( const TDEAboutData * aboutData )
92  : _dirs (0L),
93  _config (0L),
94  _iconLoader (0L),
95  _hardwaredevices (0L),
96  _networkmanager (0L),
97  _name( aboutData->appName() ), _aboutData( aboutData ), m_configReadOnly(false)
98 {
99  DEBUG_ADD
100  Q_ASSERT(!_name.isEmpty());
101 
102  if (!TDEGlobal::_instance)
103  {
104  TDEGlobal::_instance = this;
105  TDEGlobal::setActiveInstance(this);
106  }
107 
108  d = new TDEInstancePrivate ();
109  d->ownAboutdata = false;
110 }
111 
112 TDEInstance::TDEInstance( TDEInstance* src )
113  : _dirs ( src->_dirs ),
114  _config ( src->_config ),
115  _iconLoader ( src->_iconLoader ),
116  _hardwaredevices ( src->_hardwaredevices ),
117  _networkmanager ( src->_networkmanager ),
118  _name( src->_name ), _aboutData( src->_aboutData ), m_configReadOnly(false)
119 {
120  DEBUG_ADD
121  Q_ASSERT(!_name.isEmpty());
122 
123  if (!TDEGlobal::_instance || TDEGlobal::_instance == src )
124  {
125  TDEGlobal::_instance = this;
126  TDEGlobal::setActiveInstance(this);
127  }
128 
129  d = new TDEInstancePrivate ();
130  d->ownAboutdata = src->d->ownAboutdata;
131  d->sharedConfig = src->d->sharedConfig;
132 
133  src->_dirs = 0L;
134  src->_config = 0L;
135  src->_iconLoader = 0L;
136  src->_hardwaredevices = 0L;
137  src->_networkmanager = 0L;
138  src->_aboutData = 0L;
139  delete src;
140 }
141 
142 TDEInstance::~TDEInstance()
143 {
144  DEBUG_CHECK_ALIVE
145 
146  if (d->ownAboutdata)
147  delete _aboutData;
148  _aboutData = 0;
149 
150  delete d;
151  d = 0;
152 
153  delete _iconLoader;
154  _iconLoader = 0;
155 
156  delete _hardwaredevices;
157  _hardwaredevices = 0;
158 
159  delete _networkmanager;
160  _networkmanager = 0;
161 
162  // delete _config; // Do not delete, stored in d->sharedConfig
163  _config = 0;
164  delete _dirs;
165  _dirs = 0;
166 
167  if (TDEGlobal::_instance == this)
168  TDEGlobal::_instance = 0;
169  if (TDEGlobal::activeInstance() == this)
170  TDEGlobal::setActiveInstance(0);
171  DEBUG_REMOVE
172 }
173 
174 
175 TDEStandardDirs *TDEInstance::dirs() const
176 {
177  DEBUG_CHECK_ALIVE
178  if( _dirs == 0 ) {
179  _dirs = new TDEStandardDirs( );
180  if (_config) {
181  if (_dirs->addCustomized(_config))
182  _config->reparseConfiguration();
183  } else
184  config(); // trigger adding of possible customized dirs
185  }
186 
187  return _dirs;
188 }
189 
190 extern bool kde_kiosk_exception;
191 extern bool kde_kiosk_admin;
192 
193 void TDEInstance::setConfigReadOnly(bool ro)
194 {
195  m_configReadOnly = ro;
196 }
197 
198 TDEConfig *TDEInstance::config() const
199 {
200  DEBUG_CHECK_ALIVE
201  if( _config == 0 ) {
202  if ( !d->configName.isEmpty() )
203  {
204  d->sharedConfig = TDESharedConfig::openConfig( d->configName );
205 
206  // Check whether custom config files are allowed.
207  d->sharedConfig->setGroup( "KDE Action Restrictions" );
208  TQString kioskException = d->sharedConfig->readEntry("kiosk_exception");
209  if (d->sharedConfig->readBoolEntry( "custom_config", true))
210  {
211  d->sharedConfig->setGroup(TQString::null);
212  }
213  else
214  {
215  d->sharedConfig = 0;
216  }
217 
218  }
219 
220  if ( d->sharedConfig == 0 )
221  {
222  if ( !_name.isEmpty() ) {
223  d->sharedConfig = TDESharedConfig::openConfig( _name + "rc", m_configReadOnly );
224  }
225  else {
226  d->sharedConfig = TDESharedConfig::openConfig( TQString::null );
227  }
228  }
229 
230  // Check if we are excempt from kiosk restrictions
231  if (kde_kiosk_admin && !kde_kiosk_exception && !TQCString(getenv("TDE_KIOSK_NO_RESTRICTIONS")).isEmpty())
232  {
233  kde_kiosk_exception = true;
234  d->sharedConfig = 0;
235  return config(); // Reread...
236  }
237 
238  _config = d->sharedConfig;
239  if (_dirs)
240  if (_dirs->addCustomized(_config))
241  _config->reparseConfiguration();
242  }
243 
244  return _config;
245 }
246 
247 TDESharedConfig *TDEInstance::sharedConfig() const
248 {
249  DEBUG_CHECK_ALIVE
250  if (_config == 0)
251  (void) config(); // Initialize config
252 
253  return d->sharedConfig;
254 }
255 
256 void TDEInstance::setConfigName(const TQString &configName)
257 {
258  DEBUG_CHECK_ALIVE
259  d->configName = configName;
260 }
261 
262 TDEIconLoader *TDEInstance::iconLoader() const
263 {
264  DEBUG_CHECK_ALIVE
265  if( _iconLoader == 0 ) {
266  _iconLoader = new TDEIconLoader( _name, dirs() );
267  _iconLoader->enableDelayedIconSetLoading( true );
268  }
269 
270  return _iconLoader;
271 }
272 
273 TDEHardwareDevices *TDEInstance::hardwareDevices() const
274 {
275  DEBUG_CHECK_ALIVE
276  if( _hardwaredevices == 0 ) {
277  _hardwaredevices = new TDEHardwareDevices( );
278  }
279 
280  return _hardwaredevices;
281 }
282 
283 TDEGlobalNetworkManager *TDEInstance::networkManager() const
284 {
285  DEBUG_CHECK_ALIVE
286  if( _networkmanager == 0 ) {
287  _networkmanager = new TDEGlobalNetworkManager( );
288  }
289 
290  return _networkmanager;
291 }
292 
293 void TDEInstance::newIconLoader() const
294 {
295  DEBUG_CHECK_ALIVE
296  TDEIconTheme::reconfigure();
297  _iconLoader->reconfigure( _name, dirs() );
298 }
299 
300 const TDEAboutData * TDEInstance::aboutData() const
301 {
302  DEBUG_CHECK_ALIVE
303  return _aboutData;
304 }
305 
306 TQCString TDEInstance::instanceName() const
307 {
308  DEBUG_CHECK_ALIVE
309  return _name;
310 }
311 
312 KMimeSourceFactory* TDEInstance::mimeSourceFactory () const
313 {
314  DEBUG_CHECK_ALIVE
315  if (!d->mimeSourceFactory)
316  {
317  d->mimeSourceFactory = new KMimeSourceFactory(_iconLoader);
318  d->mimeSourceFactory->setInstance(const_cast<TDEInstance *>(this));
319  }
320 
321  return d->mimeSourceFactory;
322 }
323 
324 void TDEInstance::virtual_hook( int, void* )
325 { /*BASE::virtual_hook( id, data );*/ }
326 

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
  • knewstuff
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.