kplato

kptfactory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
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#include "kptfactory.h"
21#include "kptpart.h"
22#include "kptaboutdata.h"
23#include <tdeinstance.h>
24#include <kiconloader.h>
25#include <tdelocale.h>
26#include <kdebug.h>
27#include <kstandarddirs.h>
28
29namespace KPlato
30{
31
32K_EXPORT_COMPONENT_FACTORY( libkplatopart, Factory )
33
34TDEInstance* Factory::s_global = 0L;
35TDEAboutData* Factory::s_aboutData = 0L;
36
37Factory::Factory( TQObject* parent, const char* name )
38 : KoFactory( parent, name )
39{
40 global();
41}
42
43Factory::~Factory()
44{
45 delete s_aboutData;
46 s_aboutData = 0L;
47 delete s_global;
48 s_global = 0L;
49}
50
51KParts::Part *Factory::createPartObject(TQWidget *parentWidget,
52 const char *widgetName,
53 TQObject* parent, const char* name,
54 const char* classname,
55 const TQStringList &)
56{
57 // If classname is "KoDocument", our host is a koffice application
58 // otherwise, the host wants us as a simple part, so switch to readonly
59 // and single view.
60 bool bWantKoDocument = (strcmp(classname, "KoDocument") == 0);
61
62 // parentWidget and widgetName are used by KoDocument for the
63 // "readonly+singleView" case.
64 Part *part = new Part(parentWidget, widgetName, parent, name,
65 !bWantKoDocument);
66
67 if (!bWantKoDocument)
68 part->setReadWrite(false);
69
70 return part;
71}
72
73TDEAboutData* Factory::aboutData()
74{
75 if ( !s_aboutData )
76 s_aboutData = newAboutData();
77 return s_aboutData;
78}
79
80TDEInstance* Factory::global()
81{
82 if ( !s_global )
83 {
84 s_global = new TDEInstance( aboutData() );
85
86 // Add any application-specific resource directories here
87 s_global->dirs()->addResourceType("kplato_template",
88 TDEStandardDirs::kde_default("data") + "kplato/templates/");
89 s_global->dirs()->addResourceType( "expression", TDEStandardDirs::kde_default("data") + "kplato/expression/");
90 s_global->dirs()->addResourceType("toolbar",
91 TDEStandardDirs::kde_default("data") + "koffice/toolbar/");
92
93 // Tell the iconloader about share/apps/koffice/icons
94 s_global->iconLoader()->addAppDir("koffice");
95 }
96 return s_global;
97}
98
99} // KPlato namespace
100
101#include "kptfactory.moc"