X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=macros%2Fpirmacropack.cpp;fp=macros%2Fpirmacropack.cpp;h=61137c7fd9cae4d1aa1589447dc7582ba7ff6169;hb=afbbd0cd07a3f63c95969633bae56fcdd58c71b8;hp=275e9d055f6be1419dafdce93b0dbabfc0f4fc8d;hpb=6331b1b21bde2a80e6a0895d9cce865c8b558bc5;p=pierogi diff --git a/macros/pirmacropack.cpp b/macros/pirmacropack.cpp index 275e9d0..61137c7 100644 --- a/macros/pirmacropack.cpp +++ b/macros/pirmacropack.cpp @@ -1,10 +1,159 @@ #include "pirmacropack.h" +#include "pirmacro.h" + +#include + +#include + PIRMacroPack::PIRMacroPack( - QTreeWidget *parent, QString name) - : QTreeWidgetItem(parent) { setText(0, name); } + +bool PIRMacroPack::hasButton( + unsigned int buttonID) +{ + ButtonCollection::const_iterator i = buttons.find(buttonID); + + if (i != buttons.end()) + { + return true; + } + else + { + return false; + } +} + + +void PIRMacroPack::registerButton( + unsigned int buttonID, + PIRMacro *macro) +{ + buttons[buttonID] = macro; +} + + +void PIRMacroPack::eraseButton( + unsigned int buttonID, + PIRMacro *macro) +{ + ButtonCollection::iterator i = buttons.find(buttonID); + + if (i != buttons.end() && (*i).second == macro) + { + buttons.erase(i); + } +} + + +QString PIRMacroPack::buttonText( + unsigned int buttonID) +{ + ButtonCollection::const_iterator i = buttons.find(buttonID); + + if (i != buttons.end()) + { + return i->second->getName(); + } + else + { + return "Error: Macro not found"; + } +} + + +void PIRMacroPack::executeButton( + unsigned int buttonID) +{ + ButtonCollection::const_iterator i = buttons.find(buttonID); + + if (i != buttons.end()) + { + i->second->executeMacro(); + } +} + + +bool PIRMacroPack::hasKey( + char key) +{ + KeyboardCollection::const_iterator i = keymaps.find(key); + + if (i != keymaps.end()) + { + return true; + } + else + { + return false; + } +} + + +void PIRMacroPack::registerKey( + char key, + PIRMacro *macro) +{ + keymaps[key] = macro; +} + + +void PIRMacroPack::eraseKey( + char key, + PIRMacro *macro) +{ + KeyboardCollection::iterator i = keymaps.find(key); + + if (i != keymaps.end() && (*i).second == macro) + { + keymaps.erase(i); + } +} + + +void PIRMacroPack::executeKey( + char key) +{ + KeyboardCollection::const_iterator i = keymaps.find(key); + + if (i != keymaps.end()) + { + i->second->executeMacro(); + } +} + + +void PIRMacroPack::storeSettings() +{ + QSettings settings("pietrzak.org", "Pierogi"); + + // Erase any existing macros: + settings.remove("userMacros"); + + // First, do we even have any macros? If not, quit. + int macroCount = childCount(); + if (macroCount == 0) return; + + // (Re-) Construct the macros array: + + int index = 0; + PIRMacro *macro; + + settings.beginWriteArray("userMacros"); + + while (index < macroCount) + { + settings.setArrayIndex(index); + macro = dynamic_cast (child(index)); + + macro->storeSettings(settings); + + ++index; + } + + settings.endArray(); +}