kexi

manager.cpp

00001 /***************************************************************************
00002  * This file is part of the KDE project
00003  * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
00004  * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this program; see the file COPYING.  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 "manager.h"
00021 #include "action.h"
00022 #include "function.h"
00023 #include "macro.h"
00024 #include "exception.h"
00025 
00026 #include <qobject.h>
00027 #include <qwidget.h>
00028 #include <qdom.h>
00029 #include <kxmlguibuilder.h>
00030 #include <kdebug.h>
00031 
00032 using namespace KoMacro;
00033 
00034 namespace KoMacro {
00035 
00040     class Manager::Private
00041     {
00042         public:
00043             KXMLGUIClient* const xmlguiclient;
00044             QMap<QString, KSharedPtr<Macro > > macros;
00045 
00046             QStringList actionnames;
00047             QMap<QString, KSharedPtr<Action> > actions;
00048 
00049             QMap<QString, QGuardedPtr<QObject> > objects;
00050 
00051             Private(KXMLGUIClient* const xmlguiclient)
00052                 : xmlguiclient(xmlguiclient)
00053             {
00054             }
00055     };
00056 
00058     static ::KoMacro::Manager* _self = 0;
00059 
00061     static KStaticDeleter< ::KoMacro::Manager > _manager;
00062 
00063 }
00064 
00065 void Manager::init(KXMLGUIClient* xmlguiclient)
00066 {
00067     if(! _self) {
00068         ::KoMacro::Manager* manager = new ::KoMacro::Manager(xmlguiclient);
00069         _manager.setObject(_self, manager);
00070     }
00071     else {
00072         throw Exception("Already initialized.");
00073     }
00074 }
00075 
00076 Manager* Manager::self()
00077 {
00078     //Q_ASSERT(_self);
00079     return _self;
00080 }
00081 
00082 Manager::Manager(KXMLGUIClient* const xmlguiclient)
00083     : d( new Private(xmlguiclient) ) // create the private d-pointer instance.
00084 {
00085     kdDebug() << "Manager::Manager() Ctor" << endl;
00086     QObject* obj = dynamic_cast<QObject*>(xmlguiclient);
00087     if(obj) {
00088         d->objects.replace(obj->name(), obj);
00089     }
00090 
00091     //TESTCASE
00092     d->objects.replace("TestCase", new QWidget());
00093 }
00094 
00095 Manager::~Manager()
00096 {
00097     // destroy the private d-pointer instance.
00098     delete d;
00099 }
00100 
00101 KXMLGUIClient* Manager::guiClient() const
00102 {
00103     return d->xmlguiclient;
00104 }
00105 
00106 bool Manager::hasMacro(const QString& macroname)
00107 {
00108     return d->macros.contains(macroname);
00109 }
00110 
00111 KSharedPtr<Macro> Manager::getMacro(const QString& macroname)
00112 {
00113     return d->macros[macroname];
00114 }
00115 
00116 void Manager::addMacro(const QString& macroname, KSharedPtr<Macro> macro)
00117 {
00118     d->macros.replace(macroname, macro);
00119 }
00120 
00121 void Manager::removeMacro(const QString& macroname)
00122 {
00123     d->macros.remove(macroname);
00124 }
00125 
00126 KSharedPtr<Macro> Manager::createMacro(const QString& macroname)
00127 {
00128     KSharedPtr<Macro> macro = KSharedPtr<Macro>( new Macro(macroname) );
00129     return macro;
00130 }
00131 
00132 KSharedPtr<Action> Manager::action(const QString& name) const
00133 {
00134     return d->actions[name];
00135 }
00136 
00137 Action::Map Manager::actions() const
00138 {
00139     return d->actions;
00140 }
00141 
00142 QStringList Manager::actionNames() const
00143 {
00144     return d->actionnames;
00145 }
00146 
00147 void Manager::publishAction(KSharedPtr<Action> action)
00148 {
00149     const QString name = action->name();
00150     if(! d->actions.contains(name)) {
00151         d->actionnames.append(name);
00152     }
00153     d->actions.replace(name, action);
00154 }
00155 
00156 void Manager::publishObject(const QString& name, QObject* object)
00157 {
00158     Q_ASSERT(! d->objects.contains(name));
00159     d->objects.replace(name, object);
00160 }
00161 
00162 QGuardedPtr<QObject> Manager::object(const QString& name) const
00163 {
00164     return d->objects[name];
00165 }
00166 
00167 QMap<QString, QGuardedPtr<QObject> > Manager::objects() const
00168 {
00169     return d->objects;
00170 }
KDE Home | KDE Accessibility Home | Description of Access Keys