plugin.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "plugin.h"
00020
00021
00022 #include <kdebug.h>
00023 #include <kapplication.h>
00024 #include <kconfig.h>
00025
00026
00027 #include "pluginloader.h"
00028
00029 using namespace Umbrello;
00030
00031 Plugin::Plugin(QObject *parent,
00032 const char *name,
00033 const QStringList & ) :
00034 QObject(parent, name),
00035 Configurable(),
00036 _ref(0),
00037 _instanceName(name),
00038 _config(NULL)
00039 {
00040 }
00041
00042 Plugin::~Plugin()
00043 {
00044 }
00045
00046 void
00047 Plugin::ref()
00048 {
00049 _ref++;
00050 }
00051
00052 void
00053 Plugin::unload()
00054 {
00055 _ref--;
00056 if(_ref == 0) {
00057
00058 QString pluginName = _instanceName;
00059
00060
00061 shutdown();
00062 delete this;
00063
00064
00065
00066 PluginLoader::instance()->unloadPlugin(pluginName);
00067 }
00068 }
00069
00070 bool
00071 Plugin::init()
00072 {
00073 bool ret = true;
00074
00075
00076 ret = onInit();
00077 if(!ret) {
00078 kdError() << "failed to initialize " << instanceName() << endl;
00079 }
00080
00081
00082 if(ret) {
00083 ret = configure();
00084 if(!ret) {
00085 kdError() << "failed configuration " << instanceName() << endl;
00086 }
00087 }
00088
00089 return true;
00090 }
00091
00092 bool
00093 Plugin::shutdown()
00094 {
00095 bool ret = true;
00096
00097
00098 unloadPlugins();
00099
00100
00101 ret = onShutdown();
00102 if(!ret) {
00103 kdError() << "failed to shutdown " << instanceName() << endl;
00104 }
00105
00106 return true;
00107 }
00108
00109 QCString
00110 Plugin::instanceName() const
00111 {
00112 return _instanceName;
00113 }
00114
00115 KConfig *
00116 Plugin::config()
00117 {
00118 return _config;
00119 }
00120
00121 bool
00122 Plugin::onInit()
00123 {
00124 return true;
00125 }
00126
00127 bool
00128 Plugin::onShutdown()
00129 {
00130 return true;
00131 }
00132
00133 bool
00134 Plugin::configure()
00135 {
00136 bool ret = true;
00137
00138
00139 KConfig *conf = config();
00140 if(!conf) {
00141 kdDebug() << "no configuration for " << instanceName() << endl;
00142 ret = false;
00143 }
00144
00145 if(ret) {
00146
00147 conf->setGroup("Load Actions");
00148
00149
00150 loadPlugins(conf, "Load");
00151
00152
00153 if(KApplication::kApplication()->type() != QApplication::Tty) {
00154 loadPlugins(conf, "LoadGUI");
00155 }
00156 }
00157
00158 return ret;
00159 }
00160
00161 QString
00162 Plugin::category()
00163 {
00164 return QString("miscellaneous");
00165 }
00166
00167 #include "plugin.moc"
This file is part of the documentation for umbrello Version 3.1.0.