karbon

karbon_factory.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
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 
00021 #include <kaboutdata.h>
00022 #include <kglobal.h>
00023 #include <kiconloader.h>
00024 #include <kinstance.h>
00025 #include <klocale.h>
00026 #include <kstandarddirs.h>
00027 #include <ktrader.h>
00028 #include <kparts/componentfactory.h>
00029 #include <kparts/plugin.h>
00030 
00031 #include "karbon_factory.h"
00032 #include "karbon_part.h"
00033 #include "karbon_resourceserver.h"
00034 #include "karbon_aboutdata.h"
00035 #include "karbon_tool_registry.h"
00036 
00037 #include <kdebug.h>
00038 
00039 KarbonResourceServer* KarbonFactory::s_rserver = 0;
00040 
00041 KInstance* KarbonFactory::s_instance = 0L;
00042 KAboutData* KarbonFactory::s_aboutData = 0L;
00043 
00044 KarbonFactory::KarbonFactory( QObject* parent, const char* name )
00045         : KoFactory( parent, name )
00046 {
00047     instance();
00048 
00049     KarbonToolRegistry::instance();
00050 
00051     // Load plugins
00052     KTrader::OfferList offers = KTrader::self() -> query(QString::fromLatin1("Karbon/CoreModule"),
00053                                     QString::fromLatin1("Type == 'Service'"));
00054 
00055     KTrader::OfferList::ConstIterator iter;
00056 
00057     for(iter = offers.begin(); iter != offers.end(); ++iter)
00058     {
00059         KService::Ptr service = *iter;
00060         int errCode = 0;
00061         KParts::Plugin* plugin =
00062         KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, QStringList(), &errCode);
00063         if ( plugin )
00064             kdDebug() << "found plugin " << service -> property("Name").toString() << "\n";
00065     }
00066 }
00067 
00068 KarbonFactory::~KarbonFactory()
00069 {
00070     delete s_instance;
00071     s_instance = 0L;
00072     delete s_aboutData;
00073     s_aboutData = 0L;
00074     delete s_rserver;
00075     s_rserver = 0L;
00076 }
00077 
00078 KParts::Part*
00079 KarbonFactory::createPartObject( QWidget* parentWidget, const char* widgetName,
00080                                  QObject* parent, const char* name, const char* classname, const QStringList& )
00081 {
00082     // If classname is "KoDocument", our host is a koffice application
00083     // otherwise, the host wants us as a simple part, so switch to readonly and
00084     // single view.
00085     bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 );
00086 
00087     // parentWidget and widgetName are used by KoDocument for the
00088     // "readonly+singleView" case.
00089     KarbonPart* part =
00090         new KarbonPart( parentWidget, widgetName, parent, name, !bWantKoDocument );
00091 
00092     if( !bWantKoDocument )
00093         part->setReadWrite( false );
00094 
00095     return part;
00096 }
00097 
00098 KAboutData*
00099 KarbonFactory::aboutData()
00100 {
00101     if( !s_aboutData )
00102             s_aboutData = newKarbonAboutData();
00103     return s_aboutData;
00104 }
00105 
00106 KInstance*
00107 KarbonFactory::instance()
00108 {
00109     if( !s_instance )
00110     {
00111         s_instance = new KInstance( aboutData() );
00112         // Add any application-specific resource directories here
00113 
00114         s_instance->dirs()->addResourceType( "kis_brushes",
00115                                               KStandardDirs::kde_default( "data" ) + "krita/brushes/" );
00116 
00117         s_instance->dirs()->addResourceType( "kis_pattern",
00118                                               KStandardDirs::kde_default( "data" ) + "krita/patterns/" );
00119 
00120         s_instance->dirs()->addResourceType( "karbon_gradient",
00121                                               KStandardDirs::kde_default( "data" ) + "karbon/gradients/" );
00122 
00123         s_instance->dirs()->addResourceType( "karbon_clipart",
00124                                               KStandardDirs::kde_default( "data" ) + "karbon/cliparts/" );
00125         s_instance->dirs()->addResourceType( "karbon_template", KStandardDirs::kde_default("data") + "karbon/templates/" );
00126         // Tell the iconloader about share/apps/koffice/icons
00127         s_instance->iconLoader()->addAppDir("koffice");
00128     }
00129 
00130     return s_instance;
00131 }
00132 
00133 KarbonResourceServer *KarbonFactory::rServer()
00134 {
00135     if( !s_rserver )
00136         s_rserver = new KarbonResourceServer;
00137 
00138     return s_rserver;
00139 }
00140 
00141 #include "karbon_factory.moc"
00142 
KDE Home | KDE Accessibility Home | Description of Access Keys