X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=macros%2Fpirmacro.cpp;fp=macros%2Fpirmacro.cpp;h=b1a947505012319a8de2862c6e8aa109d0f734cb;hb=afbbd0cd07a3f63c95969633bae56fcdd58c71b8;hp=0d39209ac3dd3aa877d5965e6ea2ffe085a83d8f;hpb=6331b1b21bde2a80e6a0895d9cce865c8b558bc5;p=pierogi diff --git a/macros/pirmacro.cpp b/macros/pirmacro.cpp index 0d39209..b1a9475 100644 --- a/macros/pirmacro.cpp +++ b/macros/pirmacro.cpp @@ -1,17 +1,61 @@ #include "pirmacro.h" -#include "macros/pirmacrocommanditem.h" +#include "pirmacrocommanditem.h" +#include "pirmacropack.h" +#include "mainwindow.h" + +#include + +#include bool PIRMacro::macroRunning = false; PIRMacro::PIRMacro( - QTreeWidgetItem *parent, - QString n, - char k) + PIRMacroPack *parent, + QString name, + char k, + unsigned int b, + MainWindow *mw) : QTreeWidgetItem(parent), - keyMapping(k) + key(k), + buttonID(b), + mainWindow(mw) { - setText(0, n); + setText(0, name); + + if (key) + { + parent->registerKey(key, this); + } + + if (buttonID) + { + parent->registerButton(buttonID, this); + } +} + + +PIRMacro::~PIRMacro() +{ + PIRMacroPack *mp = dynamic_cast (QTreeWidgetItem::parent()); + + if (key) + { + mp->eraseKey(key, this); + } + + if (buttonID) + { + mp->eraseButton(buttonID, this); + } + + currentCommand = commands.begin(); + while (currentCommand != commands.end()) + { + delete *currentCommand; + commands.pop_front(); + currentCommand = commands.begin(); + } } @@ -21,12 +65,38 @@ QString PIRMacro::getName() } -char PIRMacro::getKeyMapping() +void PIRMacro::setName( + QString name) { - return keyMapping; + setText(0, name); } +char PIRMacro::getKey() +{ + return key; +} + + +void PIRMacro::setKey( + char k) +{ + key = k; +} + + +unsigned int PIRMacro::getButtonID() +{ + return buttonID; +} + + +void PIRMacro::setButtonID( + unsigned int id) +{ + buttonID = id; +} + void PIRMacro::appendCommand( PIRMacroCommandItem *c) { @@ -34,6 +104,81 @@ void PIRMacro::appendCommand( } +bool PIRMacro::deleteCommand( + int index) +{ + CommandSequence::iterator i = commands.begin(); + int count = 0; + + while (i != commands.end()) + { + if (index == count) + { + delete (*i); + commands.erase(i); + return true; + } + ++count; + ++i; + } + + return false; +} + + +bool PIRMacro::moveUp( + int index) +{ + CommandSequence::iterator i = commands.begin(); + int count = 0; + CommandSequence::iterator previ = commands.begin(); + + while (i != commands.end()) + { + if (index == count) + { + PIRMacroCommandItem *mci = *i; + commands.erase(i); + commands.insert(previ, mci); + return true; + } + + previ = i; + ++count; + ++i; + } + + return false; +} + + +bool PIRMacro::moveDown( + int index) +{ + CommandSequence::iterator i = commands.begin(); + CommandSequence::iterator nexti = commands.begin(); + int count = 0; + + while (i != commands.end()) + { + ++nexti; + if ((index == count) && nexti != commands.end()) + { + PIRMacroCommandItem *mci = *i; + commands.erase(i); + ++nexti; + commands.insert(nexti, mci); + return true; + } + + ++count; + ++i; + } + + return false; +} + + void PIRMacro::populateList( QListWidget *lw) { @@ -43,7 +188,7 @@ void PIRMacro::populateList( while (i != commands.end()) { - lw->addItem(*i); + lw->addItem(new QListWidgetItem((*i)->getName())); ++i; } } @@ -67,6 +212,9 @@ bool PIRMacro::executeMacro() // Start running the list of commands: macroRunning = true; + // Take note of the current keyset id: + preMacroKeysetID = mainWindow->getCurrentKeyset(); + connect( *currentCommand, SIGNAL(commandCompleted()), @@ -75,19 +223,26 @@ bool PIRMacro::executeMacro() (*currentCommand)->executeCommand(); - ++currentCommand; - return true; } void PIRMacro::startNextCommand() { + disconnect( + *currentCommand, + SIGNAL(commandCompleted()), + 0, + 0); + + ++currentCommand; + // Are we done? if (currentCommand == commands.end()) { // We are done. macroRunning = false; + mainWindow->updateKeysetSelection(preMacroKeysetID); emit macroCompleted(); return; } @@ -100,6 +255,64 @@ void PIRMacro::startNextCommand() SLOT(startNextCommand())); (*currentCommand)->executeCommand(); +} - ++currentCommand; + +void PIRMacro::storeSettings( + QSettings &settings) +{ + settings.setValue("macroName", text(0)); + settings.setValue("macroKey", key); + settings.setValue("macroButtonID", buttonID); + + CommandSequence::const_iterator i = commands.begin(); + + int index = 0; + while (i != commands.end()) + { + (*i)->storeSettings(settings, index); + ++index; + ++i; + } +} + + +QString PIRMacro::getCommandType( + int index) +{ + CommandSequence::iterator i = commands.begin(); + + // Advance 'index' steps into the sequence: + while (i != commands.end() && index) + { + ++i; + --index; + } + + if (i != commands.end()) + { + return (*i)->getTypeString(); + } + + return ""; +} + + +QString PIRMacro::getCommandName( + int index) +{ + CommandSequence::iterator i = commands.begin(); + + while (i != commands.end() && index) + { + ++i; + --index; + } + + if (i != commands.end()) + { + return (*i)->getName(); + } + + return ""; }