umbrello API Documentation

plugin.cpp

00001 /***************************************************************************
00002                           plugin.h
00003                              -------------------
00004     begin                : Mon Jan 13 2003
00005     copyright            : (C) 2003 by Andrew Sutton
00006     email                : ansutton@kent.edu
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 // own header
00019 #include "plugin.h"
00020 
00021 // KDE includes
00022 #include <kdebug.h>
00023 #include <kapplication.h>
00024 #include <kconfig.h>
00025 
00026 // app includes
00027 #include "pluginloader.h"
00028 
00029 using namespace Umbrello;
00030 
00031 Plugin::Plugin(QObject *parent,
00032                const char *name,
00033                const QStringList & /* args */) :
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         // save the name
00058         QString pluginName = _instanceName;
00059 
00060         // shutdown and delete
00061         shutdown();
00062         delete this;
00063 
00064         // once the object is destroyed, we can have the plugin loader unload
00065         // the library.
00066         PluginLoader::instance()->unloadPlugin(pluginName);
00067     }
00068 }
00069 
00070 bool
00071 Plugin::init()
00072 {
00073     bool ret = true;
00074 
00075     // initialize this plugin first - then load other plugins
00076     ret = onInit();
00077     if(!ret) {
00078         kdError() << "failed to initialize " << instanceName() << endl;
00079     }
00080 
00081     // configure on load plugins
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     // always unload plugins, even if things are failing
00098     unloadPlugins();
00099 
00100     // shutdown this plugin
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     // grab the OnStartup map
00139     KConfig *conf = config();
00140     if(!conf) {
00141         kdDebug() << "no configuration for " << instanceName() << endl;
00142         ret = false;
00143     }
00144 
00145     if(ret) {
00146         // set the config group to Load Actions
00147         conf->setGroup("Load Actions");
00148 
00149         // load standard plugins by default
00150         loadPlugins(conf, "Load");
00151 
00152         // only load GUI plugins if this is not a terminal app
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"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:59 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003