kspread

kspread_factory.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 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 as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <kdebug.h>
00021 #include <kstandarddirs.h>
00022 
00023 #include "kspread_aboutdata.h"
00024 #include "kspread_doc.h"
00025 #include "KSpreadAppIface.h"
00026 
00027 #include "kspread_factory.h"
00028 
00029 using namespace KSpread;
00030 
00031 KInstance* Factory::s_global = 0;
00032 DCOPObject* Factory::s_dcopObject = 0;
00033 KAboutData* Factory::s_aboutData = 0;
00034 
00035 Factory::Factory( QObject* parent, const char* name )
00036     : KoFactory( parent, name )
00037 {
00038   //kdDebug(36001) << "Factory::Factory()" << endl;
00039   // Create our instance, so that it becomes KGlobal::instance if the
00040   // main app is KSpread.
00041   (void)global();
00042   (void)dcopObject();
00043 }
00044 
00045 Factory::~Factory()
00046 {
00047   //kdDebug(36001) << "Factory::~Factory()" << endl;
00048   delete s_aboutData;
00049   s_aboutData=0;
00050   delete s_global;
00051   s_global = 0L;
00052   delete s_dcopObject;
00053   s_dcopObject = 0L;
00054 }
00055 
00056 KParts::Part* Factory::createPartObject( QWidget *parentWidget, const char *widgetName, QObject* parent, const char* name, const char* classname, const QStringList & )
00057 {
00058   bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 );
00059 
00060   Doc *doc = new Doc( parentWidget, widgetName, parent, name, !bWantKoDocument );
00061 
00062   if ( !bWantKoDocument )
00063     doc->setReadWrite( false );
00064 
00065   return doc;
00066 }
00067 
00068 KAboutData* Factory::aboutData()
00069 {
00070   if( !s_aboutData )
00071       s_aboutData = newAboutData();
00072   return s_aboutData;
00073 }
00074 
00075 KInstance* Factory::global()
00076 {
00077     if ( !s_global )
00078     {
00079       s_global = new KInstance(aboutData());
00080 
00081       s_global->dirs()->addResourceType( "kspread_template",
00082                                           KStandardDirs::kde_default("data") + "kspread/templates/");
00083 
00084       s_global->dirs()->addResourceType( "toolbar",
00085                          KStandardDirs::kde_default("data") + "koffice/toolbar/");
00086       s_global->dirs()->addResourceType( "extensions", KStandardDirs::kde_default("data") + "kspread/extensions/");
00087       s_global->dirs()->addResourceType( "sheet-styles", KStandardDirs::kde_default("data") + "kspread/sheetstyles/");
00088       // Tell the iconloader about share/apps/koffice/icons
00089       s_global->iconLoader()->addAppDir("koffice");
00090     }
00091     return s_global;
00092 }
00093 
00094 DCOPObject* Factory::dcopObject()
00095 {
00096     if ( !s_dcopObject )
00097         s_dcopObject = new AppIface;
00098     return s_dcopObject;
00099 }
00100 
00101 #include "kspread_factory.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys