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 /Swiften
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 'Swiften')
-rw-r--r--Swiften/AdHoc/OutgoingAdHocCommandSession.cpp25
-rw-r--r--Swiften/AdHoc/OutgoingAdHocCommandSession.h19
2 files changed, 43 insertions, 1 deletions
diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp
index 40b17e7..edacf94 100644
--- a/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp
+++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.cpp
@@ -19,8 +19,27 @@ void OutgoingAdHocCommandSession::handleResponse(boost::shared_ptr<Command> payl
if (error) {
onError(error);
} else {
- sessionID_ = payload->getSessionID();
const std::vector<Command::Action> actions = payload->getAvailableActions();
+ actionStates_.clear();
+ actionStates_[Command::Cancel] = EnabledAndPresent;
+ actionStates_[Command::Complete] = Present;
+ if (std::find(actions.begin(), actions.end(), Command::Complete) != actions.end()) {
+ actionStates_[Command::Complete] = EnabledAndPresent;
+ }
+
+ if (getIsMultiStage()) {
+ actionStates_[Command::Next] = Present;
+ actionStates_[Command::Prev] = Present;
+ }
+
+ if (std::find(actions.begin(), actions.end(), Command::Next) != actions.end()) {
+ actionStates_[Command::Next] = EnabledAndPresent;
+ }
+ if (std::find(actions.begin(), actions.end(), Command::Prev) != actions.end()) {
+ actionStates_[Command::Prev] = EnabledAndPresent;
+ }
+
+ sessionID_ = payload->getSessionID();
if (std::find(actions.begin(), actions.end(), Command::Next) != actions.end()
|| std::find(actions.begin(), actions.end(), Command::Prev) != actions.end()) {
isMultiStage_ = true;
@@ -74,4 +93,8 @@ void OutgoingAdHocCommandSession::goNext(Form::ref form) {
commandRequest->send();
}
+OutgoingAdHocCommandSession::ActionState OutgoingAdHocCommandSession::getActionState(Command::Action action) {
+ return actionStates_[action];
+}
+
}
diff --git a/Swiften/AdHoc/OutgoingAdHocCommandSession.h b/Swiften/AdHoc/OutgoingAdHocCommandSession.h
index 820dc62..fcc93e7 100644
--- a/Swiften/AdHoc/OutgoingAdHocCommandSession.h
+++ b/Swiften/AdHoc/OutgoingAdHocCommandSession.h
@@ -19,6 +19,16 @@ namespace Swift {
class AdHocCommandWindowFactory;
class OutgoingAdHocCommandSession {
public:
+
+ /**
+ * Availability of action.
+ */
+ enum ActionState {
+ Absent /** Action isn't applicable to this command. */ = 0,
+ Present /** Action is applicable to this command */= 1,
+ Enabled /** Action is applicable and currently available */ = 2,
+ EnabledAndPresent = 3};
+
OutgoingAdHocCommandSession(const DiscoItems::Item& command, AdHocCommandWindowFactory* factory, IQRouter* iqRouter);
/**
* Send initial request to the target.
@@ -57,6 +67,14 @@ namespace Swift {
* Emitted on error.
*/
boost::signal<void (ErrorPayload::ref)> onError;
+
+ /**
+ * Get the state of a given action.
+ * This is useful for a UI to determine which buttons should be visible,
+ * and which enabled.
+ * Use for Next, Prev, Cancel and Complete only.
+ */
+ ActionState getActionState(Command::Action action);
private:
void handleResponse(boost::shared_ptr<Command> payload, ErrorPayload::ref error);
private:
@@ -64,5 +82,6 @@ namespace Swift {
IQRouter* iqRouter_;
bool isMultiStage_;
std::string sessionID_;
+ std::map<Command::Action, ActionState> actionStates_;
};
}