macro.cpp
1/***************************************************************************
2 * This file is part of the KDE project
3 * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
4 * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 ***************************************************************************/
19
20#include "macro.h"
21#include "macroitem.h"
22#include "manager.h"
23#include "context.h"
24#include "variable.h"
25
26#include <tqdom.h>
27#include <kdebug.h>
28
29using namespace KoMacro;
30
31namespace KoMacro {
32
37 class Macro::Private
38 {
39 public:
40
44 TQValueList<TDESharedPtr<MacroItem > > itemlist;
45
49 TQString name;
50
51 };
52
53}
54
55//constructor, initalize internal (d-pointer) name
56Macro::Macro(const TQString& name)
57 : TQObject()
58 , TDEShared()
59 , XMLHandler(this)
60 , d( new Private() ) // create the private d-pointer instance.
61{
62 d->name = name;
63}
64
65//destructor
67{
68 // destroy the private d-pointer instance.
69 delete d;
70}
71
72//get internal (d-pointer) name
73const TQString Macro::name() const
74{
75 return d->name;
76}
77
78//set internal (d-pointer) name
79void Macro::setName(const TQString& name)
80{
81 d->name = name;
82}
83
84//get an "extended" name
85const TQString Macro::toString() const
86{
87 return TQString("Macro:%1").arg(name());
88}
89
90//get (d-pointer) itemlist
91TQValueList<TDESharedPtr<MacroItem > >& Macro::items() const
92{
93 return d->itemlist;
94}
95
96//add a macroitem to internal (d-pointer) itemlist
97void Macro::addItem(TDESharedPtr<MacroItem> item)
98{
99 d->itemlist.append(item);
100}
101//clear internal (d-pointer) itemlist
103{
104 d->itemlist.clear();
105}
106
107//run our macro
108TDESharedPtr<Context> Macro::execute(TQObject* sender)
109{
110 kdDebug() << "Macro::execute(TDESharedPtr<Context>)" << endl;
111
112 //create context in which macro can/should run
113 TDESharedPtr<Context> c = TDESharedPtr<Context>( new Context(this) );
114 if(sender) {
115 // set the sender-variable if we got a sender TQObject.
116 c->setVariable("[sender]", TDESharedPtr<Variable>( new Variable(sender) ));
117 }
118 //connect(context, TQ_SIGNAL(activated()), this, TQ_SIGNAL(activated()));
119
120 //call activate in the context of the macro
121 c->activate( c );
122
123 return c;
124}
125
126#include "macro.moc"
The context of an execution.
Definition context.h:44
virtual TDESharedPtr< Context > execute(TQObject *sender)
Connect the TQt signal signal of the TQObject sender with this Macro .
Definition macro.cpp:108
const TQString name() const
Definition macro.cpp:73
TQValueList< TDESharedPtr< MacroItem > > & items() const
Definition macro.cpp:91
void setName(const TQString &name)
Set the name this Macro instance has.
Definition macro.cpp:79
virtual ~Macro()
Destructor.
Definition macro.cpp:66
void addItem(TDESharedPtr< MacroItem > item)
Add the MacroItem item to the list of items this Macro has.
Definition macro.cpp:97
void clearItems()
Removes all MacroItem instances this Macro has.
Definition macro.cpp:102
Macro(const TQString &name)
Constructor.
Definition macro.cpp:56
virtual const TQString toString() const
Definition macro.cpp:85
A variable value used to provide abstract access to variables.
Definition variable.h:39
The XMLHandler class manages the (un-)serialization of a Macro instance to/from XML.
Definition xmlhandler.h:38