1 #include "pirmacrocommanditem.h"
3 #include "mainwindow.h"
4 #include "pirkeynames.h"
11 PIRKeynameMgr keynameMgr;
14 PIRMacroCommandItem::PIRMacroCommandItem()
20 PIRMacroCommandItem::PIRMacroCommandItem(
27 QString PIRMacroCommandItem::getName() const
33 void PIRMacroCommandItem::setName(
40 PIRKeyCommandItem::PIRKeyCommandItem(
41 PIRKeyName keyToExecute,
43 : PIRMacroCommandItem(keynameMgr.getKeynameString(keyToExecute)),
51 PIRKeyCommandItem::~PIRKeyCommandItem()
53 if (advanceTimer) delete advanceTimer;
58 void PIRKeyCommandItem::executeCommand()
60 // First, make sure no other macro is running:
61 if (advanceTimer) delete advanceTimer;
64 advanceTimer = new QTimer();
65 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(startRunningCommand()));
66 advanceTimer->start(50);
70 void PIRKeyCommandItem::startRunningCommand()
72 // Try to start running the command:
73 if (mainWindow->startRepeating(key))
75 // The command has successfully started, now wait for it to stop:
76 if (advanceTimer) delete advanceTimer;
77 advanceTimer = new QTimer();
78 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(stopRunningCommand()));
79 advanceTimer->start(50);
84 void PIRKeyCommandItem::stopRunningCommand()
86 mainWindow->stopRepeating();
88 if (advanceTimer) delete advanceTimer;
91 emit commandCompleted();
95 void PIRKeyCommandItem::storeSettings(
99 QString commandName = "commandType";
100 commandName.append(QString::number(index));
101 settings.setValue(commandName, KeyCommand_Type);
103 commandName = "commandKeyID";
104 commandName.append(QString::number(index));
105 settings.setValue(commandName, key);
109 QString PIRKeyCommandItem::getTypeString() const
111 return "Execute Keypress: ";
115 PIRKeysetCommandItem::PIRKeysetCommandItem(
117 unsigned int keysetToChoose,
119 : PIRMacroCommandItem(displayName),
126 PIRKeysetCommandItem::PIRKeysetCommandItem(
127 unsigned int keysetToChoose,
129 : PIRMacroCommandItem(),
133 setName(mainWindow->getFullKeysetName(keysetToChoose));
137 void PIRKeysetCommandItem::executeCommand()
139 mainWindow->updateKeysetSelection(id);
140 emit commandCompleted();
144 void PIRKeysetCommandItem::storeSettings(
148 QString commandName = "commandType";
149 commandName.append(QString::number(index));
150 settings.setValue(commandName, KeysetCommand_Type);
152 commandName = "commandKeysetMake";
153 commandName.append(QString::number(index));
154 settings.setValue(commandName, mainWindow->getKeysetMake(id));
156 commandName = "commandKeysetName";
157 commandName.append(QString::number(index));
158 settings.setValue(commandName, mainWindow->getKeysetName(id));
160 commandName = "commandKeysetDisplayName";
161 commandName.append(QString::number(index));
162 settings.setValue(commandName, mainWindow->getFullKeysetName(id));
166 QString PIRKeysetCommandItem::getTypeString() const
168 return "Choose Keyset: ";
172 PIRPauseCommandItem::PIRPauseCommandItem(
173 unsigned int timeToWait)
174 : timeInSeconds(timeToWait),
177 QString pauseName = "Pause for ";
178 pauseName.append(QString::number(timeToWait));
179 pauseName.append(" seconds");
185 PIRPauseCommandItem::~PIRPauseCommandItem()
187 if (advanceTimer) delete advanceTimer;
191 void PIRPauseCommandItem::executeCommand()
193 if (advanceTimer) delete advanceTimer;
195 advanceTimer = new QTimer();
196 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(finishedWaiting()));
197 advanceTimer->start(timeInSeconds * 1000);
201 void PIRPauseCommandItem::finishedWaiting()
209 emit commandCompleted();
213 void PIRPauseCommandItem::storeSettings(
217 QString commandName = "commandType";
218 commandName.append(QString::number(index));
219 settings.setValue(commandName, PauseCommand_Type);
221 commandName = "commandPause";
222 commandName.append(QString::number(index));
223 settings.setValue(commandName, timeInSeconds);
227 QString PIRPauseCommandItem::getTypeString() const
229 return "Pause (in seconds): ";