summaryrefslogtreecommitdiffstats
path: root/languages/cpp/app_templates/kofficepart/kopart_factory.cpp
blob: db6655001ee31e1d529554ee0a6ca985749a65f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

/* This template is based off of the KOffice example written by Torben Weis <weis@kde.org
   It was converted to a KDevelop template by Ian Reinhart Geiser <geiseri@yahoo.com>
*/
#include <%{APPNAMELC}_factory.h>
#include <%{APPNAMELC}_part.h>
#include <%{APPNAMELC}_aboutdata.h>
#include <kinstance.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <kdebug.h>
#include <tdeglobal.h>

extern "C"
{
    void* init_lib%{APPNAMELC}part()
    {
        TDEGlobal::locale()->insertCatalogue("%{APPNAMELC}");
        return new %{APPNAME}Factory;
    }
};

TDEInstance* %{APPNAME}Factory::s_global = 0L;
TDEAboutData* %{APPNAME}Factory::s_aboutData = 0L;

%{APPNAME}Factory::%{APPNAME}Factory( TQObject* parent, const char* name )
    : KoFactory( parent, name )
{
    global();
}

%{APPNAME}Factory::~%{APPNAME}Factory()
{
    delete s_aboutData;
    s_aboutData = 0L;
    delete s_global;
    s_global = 0L;
}

KParts::Part* %{APPNAME}Factory::createPartObject( TQWidget *parentWidget, const char *widgetName, TQObject* parent, const char* name, const char* classname, const TQStringList & )
{
    // If classname is "KoDocument", our host is a koffice application
    // otherwise, the host wants us as a simple part, so switch to readonly and single view.
    bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 );

    // parentWidget and widgetName are used by KoDocument for the "readonly+singleView" case.
    %{APPNAME}Part *part = new %{APPNAME}Part( parentWidget, widgetName, parent, name, !bWantKoDocument );

    if ( !bWantKoDocument )
      part->setReadWrite( false );

    return part;
}

TDEAboutData* %{APPNAME}Factory::aboutData()
{
    if ( !s_aboutData )
        // Change this, of course
        s_aboutData = new%{APPNAME}AboutData();
    return s_aboutData;
}

TDEInstance* %{APPNAME}Factory::global()
{
    if ( !s_global )
    {
        s_global = new TDEInstance( aboutData() );
        // Add any application-specific resource directories here

        // Tell the iconloader about share/apps/koffice/icons
        s_global->iconLoader()->addAppDir("koffice");
    }
    return s_global;
}

#include <%{APPNAMELC}_factory.moc>