| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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 "kconfig.h"
    00021 #include "klocale.h"
    00022 #include "kcharsets.h"
    00023 #include "kiconloader.h"
    00024 #include "kaboutdata.h"
    00025 #include "kstandarddirs.h"
    00026 #include "kdebug.h"
    00027 #include "kglobal.h"
    00028 #include "kmimesourcefactory.h"
    00029
    00030 #include <qfont.h>
    00031
    00032 class KInstancePrivate
    00033 {
    00034 public:
    00035     KInstancePrivate ()
    00036     {
    00037         mimeSourceFactory = 0L;
    00038     }
    00039
    00040     ~KInstancePrivate ()
    00041     {
    00042         delete mimeSourceFactory;
    00043     }
    00044
    00045     KMimeSourceFactory* mimeSourceFactory;
    00046     QString configName;
    00047     bool ownAboutdata;
    00048 };
    00049
    00050 KInstance::KInstance( const QCString& name)
    00051   : _dirs (0L),
    00052     _config (0L),
    00053     _iconLoader (0L),
    00054     _name( name ), _aboutData( new KAboutData( name, "", 0 ) )
    00055 {
    00056     Q_ASSERT(!name.isEmpty());
    00057     if (!KGlobal::_instance)
    00058     {
    00059       KGlobal::_instance = this;
    00060       KGlobal::setActiveInstance(this);
    00061     }
    00062
    00063     d = new KInstancePrivate ();
    00064     d->ownAboutdata = true;
    00065 }
    00066
    00067 KInstance::KInstance( const KAboutData * aboutData )
    00068   : _dirs (0L),
    00069     _config (0L),
    00070     _iconLoader (0L),
    00071     _name( aboutData->appName() ), _aboutData( aboutData )
    00072 {
    00073     Q_ASSERT(!_name.isEmpty());
    00074
    00075     if (!KGlobal::_instance)
    00076     {
    00077       KGlobal::_instance = this;
    00078       KGlobal::setActiveInstance(this);
    00079     }
    00080
    00081     d = new KInstancePrivate ();
    00082     d->ownAboutdata = false;
    00083 }
    00084
    00085 KInstance::KInstance( KInstance* src )
    00086   : _dirs ( src->_dirs ),
    00087     _config ( src->_config ),
    00088     _iconLoader ( src->_iconLoader ),
    00089     _name( src->_name ), _aboutData( src->_aboutData )
    00090 {
    00091     Q_ASSERT(!_name.isEmpty());
    00092
    00093     if (!KGlobal::_instance || KGlobal::_instance == src )
    00094     {
    00095       KGlobal::_instance = this;
    00096       KGlobal::setActiveInstance(this);
    00097     }
    00098
    00099     d = new KInstancePrivate ();
    00100     d->ownAboutdata = src->d->ownAboutdata;
    00101
    00102     src->_dirs = 0L;
    00103     src->_config = 0L;
    00104     src->_iconLoader = 0L;
    00105     src->_aboutData = 0L;
    00106     delete src;
    00107 }
    00108
    00109 KInstance::~KInstance()
    00110 {
    00111     if (d->ownAboutdata)
    00112         delete _aboutData;
    00113     _aboutData = 0;
    00114
    00115     delete d;
    00116     d = 0;
    00117
    00118     delete _iconLoader;
    00119     _iconLoader = 0;
    00120     delete _config;
    00121     _config = 0;
    00122     delete _dirs;
    00123     _dirs = 0;
    00124
    00125     if (KGlobal::_instance == this)
    00126         KGlobal::_instance = 0;
    00127     if (KGlobal::activeInstance() == this)
    00128         KGlobal::setActiveInstance(0);
    00129 }
    00130
    00131
    00132 KStandardDirs *KInstance::dirs() const
    00133 {
    00134     if( _dirs == 0 ) {
    00135         _dirs = new KStandardDirs( );
    00136         if (_config)
    00137             if (_dirs->addCustomized(_config))
    00138                 _config->reparseConfiguration();
    00139     }
    00140
    00141     return _dirs;
    00142 }
    00143
    00144 KConfig *KInstance::config() const
    00145 {
    00146     if( _config == 0 ) {
    00147         if ( !d->configName.isEmpty() )
    00148         {
    00149             _config = new KConfig( d->configName );
    00150             // Check whether custom config files are allowed.
    00151             _config->setGroup( "KDE Action Restrictions" );
    00152             if (_config->readBoolEntry( "custom_config", true))
    00153             {
    00154                _config->setGroup(QString::null);
    00155             }
    00156             else
    00157             {
    00158                delete _config;
    00159                _config = 0;
    00160             }
    00161
    00162         }
    00163
    00164         if ( _config == 0 )
    00165         {
    00166             if ( !_name.isEmpty() )
    00167                 _config = new KConfig( _name + "rc");
    00168             else
    00169                 _config = new KConfig();
    00170         }
    00171         if (_dirs)
    00172             if (_dirs->addCustomized(_config))
    00173                 _config->reparseConfiguration();
    00174     }
    00175
    00176     return _config;
    00177 }
    00178
    00179 void KInstance::setConfigName(const QString &configName)
    00180 {
    00181     d->configName = configName;
    00182 }
    00183
    00184 KIconLoader *KInstance::iconLoader() const
    00185 {
    00186     if( _iconLoader == 0 ) {
    00187         _iconLoader = new KIconLoader( _name, dirs() );
    00188     _iconLoader->enableDelayedIconSetLoading( true );
    00189     }
    00190
    00191     return _iconLoader;
    00192 }
    00193
    00194 void KInstance::newIconLoader() const
    00195 {
    00196     KIconTheme::reconfigure();
    00197     _iconLoader->reconfigure( _name, dirs() );
    00198 }
    00199
    00200 const KAboutData * KInstance::aboutData() const
    00201 {
    00202     return _aboutData;
    00203 }
    00204
    00205 QCString KInstance::instanceName() const
    00206 {
    00207     return _name;
    00208 }
    00209
    00210 KMimeSourceFactory* KInstance::mimeSourceFactory () const
    00211 {
    00212   if (!d->mimeSourceFactory)
    00213   {
    00214     d->mimeSourceFactory = new KMimeSourceFactory(iconLoader());
    00215   }
    00216
    00217   return d->mimeSourceFactory;
    00218 }
    00219
    00220 void KInstance::virtual_hook( int, void* )
    00221 { /*BASE::virtual_hook( id, data );*/ }
    00222

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:34 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001