summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/plugin.cpp
blob: d3efb4e70b0dbcfce013dd70d6654eec63842e26 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/***************************************************************************
                          plugin.h
                             -------------------
    begin                : Mon Jan 13 2003
    copyright            : (C) 2003 by Andrew Sutton
    email                : ansutton@kent.edu
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

// own header
#include "plugin.h"

// KDE includes
#include <kdebug.h>
#include <kapplication.h>
#include <kconfig.h>

// app includes
#include "pluginloader.h"

using namespace Umbrello;

Plugin::Plugin(TQObject *parent,
               const char *name,
               const TQStringList & /* args */) :
        TQObject(parent, name),
        Configurable(),
        _ref(0),
        _instanceName(name),
        _config(NULL)
{
}

Plugin::~Plugin()
{
}

void
Plugin::ref()
{
    _ref++;
}

void
Plugin::unload()
{
    _ref--;
    if(_ref == 0) {
        // save the name
        TQString pluginName = _instanceName;

        // shutdown and delete
        shutdown();
        delete this;

        // once the object is destroyed, we can have the plugin loader unload
        // the library.
        PluginLoader::instance()->unloadPlugin(pluginName);
    }
}

bool
Plugin::init()
{
    bool ret = true;

    // initialize this plugin first - then load other plugins
    ret = onInit();
    if(!ret) {
        kdError() << "failed to initialize " << instanceName() << endl;
    }

    // configure on load plugins
    if(ret) {
        ret = configure();
        if(!ret) {
            kdError() << "failed configuration " << instanceName() << endl;
        }
    }

    return true;
}

bool
Plugin::shutdown()
{
    bool ret = true;

    // always unload plugins, even if things are failing
    unloadPlugins();

    // shutdown this plugin
    ret = onShutdown();
    if(!ret) {
        kdError() << "failed to shutdown " << instanceName() << endl;
    }

    return true;
}

TQCString
Plugin::instanceName() const
{
    return _instanceName;
}

TDEConfig *
Plugin::config()
{
    return _config;
}

bool
Plugin::onInit()
{
    return true;
}

bool
Plugin::onShutdown()
{
    return true;
}

bool
Plugin::configure()
{
    bool ret = true;

    // grab the OnStartup map
    TDEConfig *conf = config();
    if(!conf) {
        kdDebug() << "no configuration for " << instanceName() << endl;
        ret = false;
    }

    if(ret) {
        // set the config group to Load Actions
        conf->setGroup("Load Actions");

        // load standard plugins by default
        loadPlugins(conf, "Load");

        // only load GUI plugins if this is not a terminal app
        if(TDEApplication::kApplication()->type() != TQApplication::Tty) {
            loadPlugins(conf, "LoadGUI");
        }
    }

    return ret;
}

TQString
Plugin::category()
{
    return TQString("miscellaneous");
}

#include "plugin.moc"