summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-04-25 08:56:21 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-04-25 09:46:05 (GMT)
commit3727dd9632007bc97962156bd131f6c8c977a7ba (patch)
tree75b85d1264cc43846765acf1194f3123f6e50c00 /Swift/QtUI
parent1ae62edd9a9bc3a92e546a7e5267f9c943750c23 (diff)
downloadswift-3727dd9632007bc97962156bd131f6c8c977a7ba.zip
swift-3727dd9632007bc97962156bd131f6c8c977a7ba.tar.bz2
Move available actions logic into Swiften class.
Ready for unit testing, and fixing.
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.cpp35
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.h1
2 files changed, 22 insertions, 14 deletions
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index f6b1b5c..a3bb077 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -9,6 +9,7 @@
#include <boost/bind.hpp>
#include <QBoxLayout>
#include <Swift/QtUI/QtFormWidget.h>
+#include <Swiften/Elements/Command.h>
namespace Swift {
QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) {
@@ -47,6 +48,10 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
nextButton_->setEnabled(false);
backButton_->setEnabled(false);
completeButton_->setEnabled(false);
+ actions_[Command::Next] = nextButton_;
+ actions_[Command::Prev] = backButton_;
+ actions_[Command::Complete] = completeButton_;
+ actions_[Command::Cancel] = cancelButton_;
show();
}
@@ -109,21 +114,23 @@ void QtAdHocCommandWindow::setNoForm() {
delete formWidget_;
}
-void QtAdHocCommandWindow::setAvailableActions(Command::ref commandResult) {
- const std::vector<Command::Action> actions = commandResult->getAvailableActions();
- nextButton_->setEnabled(std::find(actions.begin(), actions.end(), Command::Next) != actions.end());
- backButton_->setEnabled(std::find(actions.begin(), actions.end(), Command::Prev) != actions.end());
- completeButton_->setEnabled(std::find(actions.begin(), actions.end(), Command::Complete) != actions.end());
-
-
- if (command_->getIsMultiStage()) {
- backButton_->show();
- nextButton_->show();
- }
- else {
- backButton_->hide();
- nextButton_->hide();
+typedef std::pair<Command::Action, QPushButton*> ActionButton;
+void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
+ foreach (ActionButton pair, actions_) {
+ OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
+ if (state & OutgoingAdHocCommandSession::Present) {
+ pair.second->show();
+ }
+ else {
+ pair.second->hide();
+ }
+ if (state & OutgoingAdHocCommandSession::Enabled) {
+ pair.second->setEnabled(true);
+ }
+ else {
+ pair.second->setEnabled(false);
+ }
}
}
diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h
index f1073bc..adeb3e6 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.h
+++ b/Swift/QtUI/QtAdHocCommandWindow.h
@@ -43,5 +43,6 @@ namespace Swift {
QPushButton* nextButton_;
QPushButton* completeButton_;
QPushButton* cancelButton_;
+ std::map<Command::Action, QPushButton*> actions_;
};
}