1 #include "pirmacromanager.h"
3 #include "pirmacropack.h"
4 #include "pirreversemultitap.h"
6 #include "pirmacrocommanditem.h"
7 #include "mainwindow.h"
12 PIRMacroManager::PIRMacroManager(
16 keyboardController(0),
20 userPack = new PIRMacroPack("User Defined Macros");
21 multitapPack = new PIRReverseMultitap(mw);
25 // For testing, set the multitap pack as the keyboard controller:
26 // keyboardController = multitapPack;
28 // And more testing, userpack as button controller:
29 // buttonsController = userPack;
33 PIRMacroManager::~PIRMacroManager()
35 // The UI currently owns the macro packs...
37 // delete multitapPack;
41 PIRMacroPack *PIRMacroManager::getUserPack()
47 PIRMacroPack *PIRMacroManager::getMultitapPack()
53 void PIRMacroManager::setKeyboardController(
56 keyboardController = pack;
60 void PIRMacroManager::setButtonsController(
63 buttonsController = pack;
67 void PIRMacroManager::handleKeypress(
70 if (keyboardController)
72 keyboardController->executeKey(key);
77 bool PIRMacroManager::hasMacroButton(
78 unsigned int buttonID)
80 if (buttonsController)
81 return buttonsController->hasButton(buttonID);
87 QString PIRMacroManager::getMacroButtonText(
88 unsigned int buttonID)
90 if (buttonsController)
91 return buttonsController->buttonText(buttonID);
93 return "No Macro Found";
97 void PIRMacroManager::executeMacroButton(
98 unsigned int buttonID)
100 if (buttonsController)
101 buttonsController->executeButton(buttonID);
105 void PIRMacroManager::storeSettings()
107 if (userPack) userPack->storeSettings();
111 void PIRMacroManager::retrieveSettings()
113 // Pull in any user-defined macros:
114 QSettings settings("pietrzak.org", "Pierogi");
115 int size = settings.beginReadArray("userMacros");
119 unsigned int macroButtonID;
121 PIRMacroCommandItem *macroCommand;
125 unsigned int keysetID;
126 QString commandKeysetName;
127 QString commandKeysetMakeStr;
128 QString commandKeysetDisplayName;
129 PIRKeyName commandKeyID;
130 unsigned int commandPause;
134 settings.setArrayIndex(index);
135 macroName = settings.value("macroName").toString();
136 macroKey = settings.value("macroKey").toInt();
137 macroButtonID = settings.value("macroButtonID").toInt();
139 macro = new PIRMacro(
140 userPack, macroName, macroKey, macroButtonID, mainWindow);
143 commandName = "commandType";
144 commandName.append(QString::number(commandIndex));
145 while (settings.contains(commandName))
147 commandType = settings.value(commandName).toInt();
148 switch(CommandItemType(commandType))
150 case KeysetCommand_Type:
151 commandName = "commandKeysetName";
152 commandName.append(QString::number(commandIndex));
153 commandKeysetName = settings.value(commandName).toString();
155 commandName = "commandKeysetMake";
156 commandName.append(QString::number(commandIndex));
157 commandKeysetMakeStr = settings.value(commandName).toString();
159 commandName = "commandKeysetDisplayName";
160 commandName.append(QString::number(commandIndex));
161 commandKeysetDisplayName = settings.value(commandName).toString();
163 if (mainWindow->findKeysetID(
164 commandKeysetMakeStr,
168 macroCommand = new PIRKeysetCommandItem(
169 commandKeysetDisplayName,
173 macro->appendCommand(macroCommand);
178 case KeyCommand_Type:
179 commandName = "commandKeyID";
180 commandName.append(QString::number(commandIndex));
181 commandKeyID = PIRKeyName(settings.value(commandName).toInt());
183 macroCommand = new PIRKeyCommandItem(commandKeyID, mainWindow);
185 macro->appendCommand(macroCommand);
189 case PauseCommand_Type:
190 commandName = "commandPause";
191 commandName.append(QString::number(commandIndex));
192 commandPause = settings.value(commandName).toInt();
194 macroCommand = new PIRPauseCommandItem(commandPause);
196 macro->appendCommand(macroCommand);
205 commandName = "commandType";
206 commandName.append(QString::number(commandIndex));
216 // This needs to be done differently!!!
217 void PIRMacroManager::setKbdFocus(
222 keyboardController = userPack;
226 keyboardController = multitapPack;
231 void PIRMacroManager::setBtnFocus(
236 buttonsController = userPack;
240 buttonsController = multitapPack;