| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kinstance.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 1999 Torben Weis <weis@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018 #include "kinstance.h"
    00019
    00020 #include <stdlib.h>
    00021 #include <unistd.h>
    00022
    00023 #include "kconfig.h"
    00024 #include "klocale.h"
    00025 #include "kcharsets.h"
    00026 #include "kiconloader.h"
    00027 #include "kaboutdata.h"
    00028 #include "kstandarddirs.h"
    00029 #include "kdebug.h"
    00030 #include "kglobal.h"
    00031 #include "kmimesourcefactory.h"
    00032
    00033 #include <qfont.h>
    00034
    00035 #include "config.h"
    00036 #ifndef NDEBUG
    00037   #include <assert.h>
    00038   #include <qptrdict.h>
    00039   static QPtrList<KInstance> *allInstances = 0;
    00040   static QPtrDict<QCString> *allOldInstances = 0;
    00041   #define DEBUG_ADD do { if (!allInstances) { allInstances = new QPtrList<KInstance>(); allOldInstances = new QPtrDict<QCString>(); } allInstances->append(this); allOldInstances->insert( this, new QCString( _name)); } while (false);
    00042   #define DEBUG_REMOVE do { allInstances->removeRef(this); } while (false);
    00043   #define DEBUG_CHECK_ALIVE do { if (!allInstances->contains((KInstance*)this)) { QCString *old = allOldInstances->find((KInstance*)this); qWarning("ACCESSING DELETED KINSTANCE! (%s)", old ? old->data() : "<unknown>"); assert(false); } } while (false);
    00044 #else
    00045   #define DEBUG_ADD
    00046   #define DEBUG_REMOVE
    00047   #define DEBUG_CHECK_ALIVE
    00048 #endif
    00049
    00050 class KInstancePrivate
    00051 {
    00052 public:
    00053     KInstancePrivate ()
    00054     {
    00055         mimeSourceFactory = 0L;
    00056     }
    00057
    00058     ~KInstancePrivate ()
    00059     {
    00060         delete mimeSourceFactory;
    00061     }
    00062
    00063     KMimeSourceFactory* mimeSourceFactory;
    00064     QString configName;
    00065     bool ownAboutdata;
    00066     KSharedConfig::Ptr sharedConfig;
    00067 };
    00068
    00069 KInstance::KInstance( const QCString& name)
    00070   : _dirs (0L),
    00071     _config (0L),
    00072     _iconLoader (0L),
    00073     _name( name ), _aboutData( new KAboutData( name, "", 0 ) )
    00074 {
    00075     DEBUG_ADD
    00076     Q_ASSERT(!name.isEmpty());
    00077     if (!KGlobal::_instance)
    00078     {
    00079       KGlobal::_instance = this;
    00080       KGlobal::setActiveInstance(this);
    00081     }
    00082
    00083     d = new KInstancePrivate ();
    00084     d->ownAboutdata = true;
    00085 }
    00086
    00087 KInstance::KInstance( const KAboutData * aboutData )
    00088   : _dirs (0L),
    00089     _config (0L),
    00090     _iconLoader (0L),
    00091     _name( aboutData->appName() ), _aboutData( aboutData )
    00092 {
    00093     DEBUG_ADD
    00094     Q_ASSERT(!_name.isEmpty());
    00095
    00096     if (!KGlobal::_instance)
    00097     {
    00098       KGlobal::_instance = this;
    00099       KGlobal::setActiveInstance(this);
    00100     }
    00101
    00102     d = new KInstancePrivate ();
    00103     d->ownAboutdata = false;
    00104 }
    00105
    00106 KInstance::KInstance( KInstance* src )
    00107   : _dirs ( src->_dirs ),
    00108     _config ( src->_config ),
    00109     _iconLoader ( src->_iconLoader ),
    00110     _name( src->_name ), _aboutData( src->_aboutData )
    00111 {
    00112     DEBUG_ADD
    00113     Q_ASSERT(!_name.isEmpty());
    00114
    00115     if (!KGlobal::_instance || KGlobal::_instance == src )
    00116     {
    00117       KGlobal::_instance = this;
    00118       KGlobal::setActiveInstance(this);
    00119     }
    00120
    00121     d = new KInstancePrivate ();
    00122     d->ownAboutdata = src->d->ownAboutdata;
    00123     d->sharedConfig = src->d->sharedConfig;
    00124
    00125     src->_dirs = 0L;
    00126     src->_config = 0L;
    00127     src->_iconLoader = 0L;
    00128     src->_aboutData = 0L;
    00129     delete src;
    00130 }
    00131
    00132 KInstance::~KInstance()
    00133 {
    00134     DEBUG_CHECK_ALIVE
    00135
    00136     if (d->ownAboutdata)
    00137         delete _aboutData;
    00138     _aboutData = 0;
    00139
    00140     delete d;
    00141     d = 0;
    00142
    00143     delete _iconLoader;
    00144     _iconLoader = 0;
    00145
    00146     // delete _config; // Do not delete, stored in d->sharedConfig
    00147     _config = 0;
    00148     delete _dirs;
    00149     _dirs = 0;
    00150
    00151     if (KGlobal::_instance == this)
    00152         KGlobal::_instance = 0;
    00153     if (KGlobal::activeInstance() == this)
    00154         KGlobal::setActiveInstance(0);
    00155     DEBUG_REMOVE
    00156 }
    00157
    00158
    00159 KStandardDirs *KInstance::dirs() const
    00160 {
    00161     DEBUG_CHECK_ALIVE
    00162     if( _dirs == 0 ) {
    00163     _dirs = new KStandardDirs( );
    00164         if (_config)
    00165             if (_dirs->addCustomized(_config))
    00166                 _config->reparseConfiguration();
    00167     }
    00168
    00169     return _dirs;
    00170 }
    00171
    00172 extern bool kde_kiosk_exception;
    00173 extern bool kde_kiosk_admin;
    00174
    00175 KConfig *KInstance::config() const
    00176 {
    00177     DEBUG_CHECK_ALIVE
    00178     if( _config == 0 ) {
    00179         if ( !d->configName.isEmpty() )
    00180         {
    00181             d->sharedConfig = KSharedConfig::openConfig( d->configName );
    00182
    00183             // Check whether custom config files are allowed.
    00184             d->sharedConfig->setGroup( "KDE Action Restrictions" );
    00185             QString kioskException = d->sharedConfig->readEntry("kiosk_exception");
    00186             if (d->sharedConfig->readBoolEntry( "custom_config", true))
    00187             {
    00188                d->sharedConfig->setGroup(QString::null);
    00189             }
    00190             else
    00191             {
    00192                d->sharedConfig = 0;
    00193             }
    00194
    00195         }
    00196
    00197         if ( d->sharedConfig == 0 )
    00198         {
    00199         if ( !_name.isEmpty() )
    00200             d->sharedConfig = KSharedConfig::openConfig( _name + "rc");
    00201         else
    00202             d->sharedConfig = KSharedConfig::openConfig( QString::null );
    00203     }
    00204
    00205     // Check if we are excempt from kiosk restrictions
    00206     if (kde_kiosk_admin && !kde_kiosk_exception && !QCString(getenv("KDE_KIOSK_NO_RESTRICTIONS")).isEmpty())
    00207     {
    00208             kde_kiosk_exception = true;
    00209             d->sharedConfig = 0;
    00210             return config(); // Reread...
    00211         }
    00212
    00213     _config = d->sharedConfig;
    00214         if (_dirs)
    00215             if (_dirs->addCustomized(_config))
    00216                 _config->reparseConfiguration();
    00217     }
    00218
    00219     return _config;
    00220 }
    00221
    00222 KSharedConfig *KInstance::sharedConfig() const
    00223 {
    00224     DEBUG_CHECK_ALIVE
    00225     if (_config == 0)
    00226        (void) config(); // Initialize config
    00227
    00228     return d->sharedConfig;
    00229 }
    00230
    00231 void KInstance::setConfigName(const QString &configName)
    00232 {
    00233     DEBUG_CHECK_ALIVE
    00234     d->configName = configName;
    00235 }
    00236
    00237 KIconLoader *KInstance::iconLoader() const
    00238 {
    00239     DEBUG_CHECK_ALIVE
    00240     if( _iconLoader == 0 ) {
    00241     _iconLoader = new KIconLoader( _name, dirs() );
    00242     _iconLoader->enableDelayedIconSetLoading( true );
    00243     }
    00244
    00245     return _iconLoader;
    00246 }
    00247
    00248 void KInstance::newIconLoader() const
    00249 {
    00250     DEBUG_CHECK_ALIVE
    00251     KIconTheme::reconfigure();
    00252     _iconLoader->reconfigure( _name, dirs() );
    00253 }
    00254
    00255 const KAboutData * KInstance::aboutData() const
    00256 {
    00257     DEBUG_CHECK_ALIVE
    00258     return _aboutData;
    00259 }
    00260
    00261 QCString KInstance::instanceName() const
    00262 {
    00263     DEBUG_CHECK_ALIVE
    00264     return _name;
    00265 }
    00266
    00267 KMimeSourceFactory* KInstance::mimeSourceFactory () const
    00268 {
    00269   DEBUG_CHECK_ALIVE
    00270   if (!d->mimeSourceFactory)
    00271   {
    00272     d->mimeSourceFactory = new KMimeSourceFactory(iconLoader());
    00273   }
    00274
    00275   return d->mimeSourceFactory;
    00276 }
    00277
    00278 void KInstance::virtual_hook( int, void* )
    00279 { /*BASE::virtual_hook( id, data );*/ }
    00280

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:06 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003