kexi

macro.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 "macro.h"
00021 #include "macroitem.h"
00022 #include "manager.h"
00023 #include "context.h"
00024 #include "variable.h"
00025 
00026 #include <qdom.h>
00027 #include <kdebug.h>
00028 
00029 using namespace KoMacro;
00030 
00031 namespace KoMacro {
00032 
00037     class Macro::Private
00038     {
00039         public:
00040 
00044             QValueList<KSharedPtr<MacroItem > > itemlist;
00045 
00049             QString name;
00050 
00051     };
00052 
00053 }
00054 
00055 //constructor, initalize internal (d-pointer) name
00056 Macro::Macro(const QString& name)
00057     : QObject()
00058     , KShared()
00059     , XMLHandler(this)
00060     , d( new Private() ) // create the private d-pointer instance.
00061 {
00062     d->name = name;
00063 }
00064 
00065 //destructor
00066 Macro::~Macro()
00067 {
00068     // destroy the private d-pointer instance.
00069     delete d;
00070 }
00071 
00072 //get internal (d-pointer) name
00073 const QString Macro::name() const
00074 {
00075     return d->name;
00076 }
00077 
00078 //set internal (d-pointer) name
00079 void Macro::setName(const QString& name)
00080 {
00081     d->name = name;
00082 }
00083 
00084 //get an "extended" name
00085 const QString Macro::toString() const
00086 {
00087     return QString("Macro:%1").arg(name());
00088 }
00089 
00090 //get (d-pointer) itemlist
00091 QValueList<KSharedPtr<MacroItem > >& Macro::items() const
00092 {
00093     return d->itemlist;
00094 }
00095 
00096 //add a macroitem to internal (d-pointer) itemlist
00097 void Macro::addItem(KSharedPtr<MacroItem> item)
00098 {
00099     d->itemlist.append(item);
00100 }
00101 //clear internal (d-pointer) itemlist
00102 void Macro::clearItems()
00103 {
00104     d->itemlist.clear();
00105 }
00106 
00107 //run our macro
00108 KSharedPtr<Context> Macro::execute(QObject* sender)
00109 {
00110     kdDebug() << "Macro::execute(KSharedPtr<Context>)" << endl;
00111 
00112     //create context in which macro can/should run
00113     KSharedPtr<Context> c = KSharedPtr<Context>( new Context(this) );
00114     if(sender) {
00115         // set the sender-variable if we got a sender QObject.
00116         c->setVariable("[sender]", KSharedPtr<Variable>( new Variable(sender) ));
00117     }
00118     //connect(context, SIGNAL(activated()), this, SIGNAL(activated()));
00119     
00120     //call activate in the context of the macro
00121     c->activate( c );
00122 
00123     return c;
00124 }
00125 
00126 #include "macro.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys