kplato

kptfactory.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 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 "kptfactory.h"
00021 #include "kptpart.h"
00022 #include "kptaboutdata.h"
00023 #include <kinstance.h>
00024 #include <kiconloader.h>
00025 #include <klocale.h>
00026 #include <kdebug.h>
00027 #include <kstandarddirs.h>
00028 
00029 namespace KPlato
00030 {
00031 
00032 K_EXPORT_COMPONENT_FACTORY( libkplatopart, Factory )
00033 
00034 KInstance* Factory::s_global = 0L;
00035 KAboutData* Factory::s_aboutData = 0L;
00036 
00037 Factory::Factory( QObject* parent, const char* name )
00038     : KoFactory( parent, name )
00039 {
00040     global();
00041 }
00042 
00043 Factory::~Factory()
00044 {
00045     delete s_aboutData;
00046     s_aboutData = 0L;
00047     delete s_global;
00048     s_global = 0L;
00049 }
00050 
00051 KParts::Part *Factory::createPartObject(QWidget *parentWidget,
00052                        const char *widgetName,
00053                        QObject* parent, const char* name,
00054                        const char* classname,
00055                        const QStringList &)
00056 {
00057     // If classname is "KoDocument", our host is a koffice application
00058     // otherwise, the host wants us as a simple part, so switch to readonly
00059     // and single view.
00060     bool bWantKoDocument = (strcmp(classname, "KoDocument") == 0);
00061 
00062     // parentWidget and widgetName are used by KoDocument for the
00063     // "readonly+singleView" case.
00064     Part *part = new Part(parentWidget, widgetName, parent, name,
00065                 !bWantKoDocument);
00066 
00067     if (!bWantKoDocument)
00068       part->setReadWrite(false);
00069 
00070     return part;
00071 }
00072 
00073 KAboutData* Factory::aboutData()
00074 {
00075     if ( !s_aboutData )
00076         s_aboutData = newAboutData();
00077     return s_aboutData;
00078 }
00079 
00080 KInstance* Factory::global()
00081 {
00082     if ( !s_global )
00083     {
00084         s_global = new KInstance( aboutData() );
00085 
00086         // Add any application-specific resource directories here
00087     s_global->dirs()->addResourceType("kplato_template",
00088                       KStandardDirs::kde_default("data") + "kplato/templates/");
00089     s_global->dirs()->addResourceType( "expression", KStandardDirs::kde_default("data") + "kplato/expression/");
00090     s_global->dirs()->addResourceType("toolbar",
00091                       KStandardDirs::kde_default("data") + "koffice/toolbar/");
00092 
00093         // Tell the iconloader about share/apps/koffice/icons
00094         s_global->iconLoader()->addAppDir("koffice");
00095     }
00096     return s_global;
00097 }
00098 
00099 } // KPlato namespace
00100 
00101 #include "kptfactory.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys