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;
57 void PIRKeyCommandItem::executeCommand()
59 // First, make sure no other macro is running:
60 if (advanceTimer) delete advanceTimer;
63 advanceTimer = new QTimer();
64 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(startRunningCommand()));
65 advanceTimer->start(50);
69 void PIRKeyCommandItem::startRunningCommand()
71 // Try to start running the command:
72 if (mainWindow->startRepeating(key))
74 // The command has successfully started, now wait for it to stop:
75 if (advanceTimer) delete advanceTimer;
76 advanceTimer = new QTimer();
77 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(stopRunningCommand()));
78 advanceTimer->start(50);
83 void PIRKeyCommandItem::stopRunningCommand()
85 mainWindow->stopRepeating();
87 if (advanceTimer) delete advanceTimer;
90 emit commandCompleted();
94 void PIRKeyCommandItem::storeSettings(
98 QString commandName = "commandType";
99 commandName.append(QString::number(index));
100 settings.setValue(commandName, KeyCommand_Type);
102 commandName = "commandKeyID";
103 commandName.append(QString::number(index));
104 settings.setValue(commandName, key);
108 QString PIRKeyCommandItem::getTypeString() const
110 return "Execute Keypress: ";
114 PIRKeysetCommandItem::PIRKeysetCommandItem(
116 unsigned int keysetToChoose,
118 : PIRMacroCommandItem(displayName),
125 PIRKeysetCommandItem::PIRKeysetCommandItem(
126 unsigned int keysetToChoose,
128 : PIRMacroCommandItem(),
132 setName(mainWindow->getFullKeysetName(keysetToChoose));
136 void PIRKeysetCommandItem::executeCommand()
138 mainWindow->updateKeysetSelection(id);
139 emit commandCompleted();
143 void PIRKeysetCommandItem::storeSettings(
147 QString commandName = "commandType";
148 commandName.append(QString::number(index));
149 settings.setValue(commandName, KeysetCommand_Type);
151 commandName = "commandKeysetMake";
152 commandName.append(QString::number(index));
153 settings.setValue(commandName, mainWindow->getKeysetMake(id));
155 commandName = "commandKeysetName";
156 commandName.append(QString::number(index));
157 settings.setValue(commandName, mainWindow->getKeysetName(id));
159 commandName = "commandKeysetDisplayName";
160 commandName.append(QString::number(index));
161 settings.setValue(commandName, mainWindow->getFullKeysetName(id));
165 QString PIRKeysetCommandItem::getTypeString() const
167 return "Choose Keyset: ";
171 PIRPauseCommandItem::PIRPauseCommandItem(
172 unsigned int timeToWait)
173 : timeInSeconds(timeToWait),
176 QString pauseName = "Pause for ";
177 pauseName.append(QString::number(timeToWait));
178 pauseName.append(" seconds");
184 PIRPauseCommandItem::~PIRPauseCommandItem()
186 if (advanceTimer) delete advanceTimer;
190 void PIRPauseCommandItem::executeCommand()
192 if (advanceTimer) delete advanceTimer;
194 advanceTimer = new QTimer();
195 connect(advanceTimer, SIGNAL(timeout()), this, SLOT(finishedWaiting()));
196 advanceTimer->start(timeInSeconds * 1000);
200 void PIRPauseCommandItem::finishedWaiting()
208 emit commandCompleted();
212 void PIRPauseCommandItem::storeSettings(
216 QString commandName = "commandType";
217 commandName.append(QString::number(index));
218 settings.setValue(commandName, PauseCommand_Type);
220 commandName = "commandPause";
221 commandName.append(QString::number(index));
222 settings.setValue(commandName, timeInSeconds);
226 QString PIRPauseCommandItem::getTypeString() const
228 return "Pause (in seconds): ";