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 currentCommand = commands.begin();
205 // If this macro is empty, just return:
206 if (currentCommand == commands.end())
208 emit macroCompleted();
212 // Start running the list of commands:
215 // Take note of the current keyset id:
216 preMacroKeysetID = mainWindow->getCurrentKeyset();
220 SIGNAL(commandCompleted()),
222 SLOT(startNextCommand()));
224 (*currentCommand)->executeCommand();
230 void PIRMacro::startNextCommand()
234 SIGNAL(commandCompleted()),
241 if (currentCommand == commands.end())
244 macroRunning = false;
245 mainWindow->updateKeysetSelection(preMacroKeysetID);
246 emit macroCompleted();
250 // We are not done; run the next command.
253 SIGNAL(commandCompleted()),
255 SLOT(startNextCommand()));
257 (*currentCommand)->executeCommand();
261 void PIRMacro::storeSettings(
264 settings.setValue("macroName", text(0));
265 settings.setValue("macroKey", key);
266 settings.setValue("macroButtonID", buttonID);
268 CommandSequence::const_iterator i = commands.begin();
271 while (i != commands.end())
273 (*i)->storeSettings(settings, index);
280 QString PIRMacro::getCommandType(
283 CommandSequence::iterator i = commands.begin();
285 // Advance 'index' steps into the sequence:
286 while (i != commands.end() && index)
292 if (i != commands.end())
294 return (*i)->getTypeString();
301 QString PIRMacro::getCommandName(
304 CommandSequence::iterator i = commands.begin();
306 while (i != commands.end() && index)
312 if (i != commands.end())
314 return (*i)->getName();