3 #include "pirmacrocommanditem.h"
4 #include "pirmacropack.h"
5 #include "mainwindow.h"
11 bool PIRMacro::macroRunning = false;
19 : QTreeWidgetItem(parent),
28 parent->registerKey(key, this);
33 parent->registerButton(buttonID, this);
40 PIRMacroPack *mp = dynamic_cast<PIRMacroPack*> (QTreeWidgetItem::parent());
44 mp->eraseKey(key, this);
49 mp->eraseButton(buttonID, this);
52 currentCommand = commands.begin();
53 while (currentCommand != commands.end())
55 delete *currentCommand;
57 currentCommand = commands.begin();
62 QString PIRMacro::getName()
68 void PIRMacro::setName(
75 char PIRMacro::getKey()
81 void PIRMacro::setKey(
88 unsigned int PIRMacro::getButtonID()
94 void PIRMacro::setButtonID(
100 void PIRMacro::appendCommand(
101 PIRMacroCommandItem *c)
103 commands.push_back(c);
107 bool PIRMacro::deleteCommand(
110 CommandSequence::iterator i = commands.begin();
113 while (i != commands.end())
129 bool PIRMacro::moveUp(
132 CommandSequence::iterator i = commands.begin();
134 CommandSequence::iterator previ = commands.begin();
136 while (i != commands.end())
140 PIRMacroCommandItem *mci = *i;
142 commands.insert(previ, mci);
155 bool PIRMacro::moveDown(
158 CommandSequence::iterator i = commands.begin();
159 CommandSequence::iterator nexti = commands.begin();
162 while (i != commands.end())
165 if ((index == count) && nexti != commands.end())
167 PIRMacroCommandItem *mci = *i;
170 commands.insert(nexti, mci);
182 void PIRMacro::populateList(
187 CommandSequence::const_iterator i = commands.begin();
189 while (i != commands.end())
191 lw->addItem(new QListWidgetItem((*i)->getName()));
197 // executeMacro() returns false if it was unable to start the macro running:
198 bool PIRMacro::executeMacro()
200 // Don't start a new macro if one is already running:
201 if (macroRunning) return false;
203 // Start running the list of commands:
206 currentCommand = commands.begin();
208 // If this macro is empty, just return:
209 if (currentCommand == commands.end())
211 emit macroCompleted();
212 macroRunning = false;
216 // Take note of the current keyset id:
217 preMacroKeysetID = mainWindow->getCurrentKeyset();
221 SIGNAL(commandCompleted()),
223 SLOT(startNextCommand()));
225 (*currentCommand)->executeCommand();
231 void PIRMacro::startNextCommand()
235 SIGNAL(commandCompleted()),
242 if (currentCommand == commands.end())
245 macroRunning = false;
246 mainWindow->updateKeysetSelection(preMacroKeysetID);
247 emit macroCompleted();
251 // We are not done; run the next command.
254 SIGNAL(commandCompleted()),
256 SLOT(startNextCommand()));
258 (*currentCommand)->executeCommand();
262 void PIRMacro::storeSettings(
265 settings.setValue("macroName", text(0));
266 settings.setValue("macroKey", key);
267 settings.setValue("macroButtonID", buttonID);
269 CommandSequence::const_iterator i = commands.begin();
272 while (i != commands.end())
274 (*i)->storeSettings(settings, index);
281 QString PIRMacro::getCommandType(
284 CommandSequence::iterator i = commands.begin();
286 // Advance 'index' steps into the sequence:
287 while (i != commands.end() && index)
293 if (i != commands.end())
295 return (*i)->getTypeString();
302 QString PIRMacro::getCommandName(
305 CommandSequence::iterator i = commands.begin();
307 while (i != commands.end() && index)
313 if (i != commands.end())
315 return (*i)->getName();