karbon

karbon_factory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, 2002, 2003 The Karbon Developers
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 as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20
21#include <tdeaboutdata.h>
22#include <tdeglobal.h>
23#include <kiconloader.h>
24#include <tdeinstance.h>
25#include <tdelocale.h>
26#include <kstandarddirs.h>
27#include <ktrader.h>
28#include <tdeparts/componentfactory.h>
29#include <tdeparts/plugin.h>
30
31#include "karbon_factory.h"
32#include "karbon_part.h"
33#include "karbon_resourceserver.h"
34#include "karbon_aboutdata.h"
35#include "karbon_tool_registry.h"
36
37#include <kdebug.h>
38
39KarbonResourceServer* KarbonFactory::s_rserver = 0;
40
41TDEInstance* KarbonFactory::s_instance = 0L;
42TDEAboutData* KarbonFactory::s_aboutData = 0L;
43
44KarbonFactory::KarbonFactory( TQObject* parent, const char* name )
45 : KoFactory( parent, name )
46{
47 instance();
48
49 KarbonToolRegistry::instance();
50
51 // Load plugins
52 TDETrader::OfferList offers = TDETrader::self() -> query(TQString::fromLatin1("Karbon/CoreModule"),
53 TQString::fromLatin1("Type == 'Service'"));
54
55 TDETrader::OfferList::ConstIterator iter;
56
57 for(iter = offers.begin(); iter != offers.end(); ++iter)
58 {
59 KService::Ptr service = *iter;
60 int errCode = 0;
61 KParts::Plugin* plugin =
62 KParts::ComponentFactory::createInstanceFromService<KParts::Plugin> ( service, this, 0, TQStringList(), &errCode);
63 if ( plugin )
64 kdDebug() << "found plugin " << service -> property("Name").toString() << "\n";
65 }
66}
67
68KarbonFactory::~KarbonFactory()
69{
70 delete s_instance;
71 s_instance = 0L;
72 delete s_aboutData;
73 s_aboutData = 0L;
74 delete s_rserver;
75 s_rserver = 0L;
76}
77
78KParts::Part*
79KarbonFactory::createPartObject( TQWidget* parentWidget, const char* widgetName,
80 TQObject* parent, const char* name, const char* classname, const TQStringList& )
81{
82 // If classname is "KoDocument", our host is a koffice application
83 // otherwise, the host wants us as a simple part, so switch to readonly and
84 // single view.
85 bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 );
86
87 // parentWidget and widgetName are used by KoDocument for the
88 // "readonly+singleView" case.
89 KarbonPart* part =
90 new KarbonPart( parentWidget, widgetName, parent, name, !bWantKoDocument );
91
92 if( !bWantKoDocument )
93 part->setReadWrite( false );
94
95 return part;
96}
97
98TDEAboutData*
99KarbonFactory::aboutData()
100{
101 if( !s_aboutData )
102 s_aboutData = newKarbonAboutData();
103 return s_aboutData;
104}
105
106TDEInstance*
107KarbonFactory::instance()
108{
109 if( !s_instance )
110 {
111 s_instance = new TDEInstance( aboutData() );
112 // Add any application-specific resource directories here
113
114 s_instance->dirs()->addResourceType( "kis_brushes",
115 TDEStandardDirs::kde_default( "data" ) + "chalk/brushes/" );
116
117 s_instance->dirs()->addResourceType( "kis_pattern",
118 TDEStandardDirs::kde_default( "data" ) + "chalk/patterns/" );
119
120 s_instance->dirs()->addResourceType( "karbon_gradient",
121 TDEStandardDirs::kde_default( "data" ) + "karbon/gradients/" );
122
123 s_instance->dirs()->addResourceType( "karbon_clipart",
124 TDEStandardDirs::kde_default( "data" ) + "karbon/cliparts/" );
125 s_instance->dirs()->addResourceType( "karbon_template", TDEStandardDirs::kde_default("data") + "karbon/templates/" );
126 // Tell the iconloader about share/apps/koffice/icons
127 s_instance->iconLoader()->addAppDir("koffice");
128 }
129
130 return s_instance;
131}
132
133KarbonResourceServer *KarbonFactory::rServer()
134{
135 if( !s_rserver )
136 s_rserver = new KarbonResourceServer;
137
138 return s_rserver;
139}
140
141#include "karbon_factory.moc"
142