summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-05-02 09:19:23 (GMT)
committerSwift Review <review@swift.im>2014-07-09 09:03:34 (GMT)
commitacac7962ba04c083377f62f4265ecc754176f74e (patch)
treefa2db718854d10c76e81fc54b0b1f2b33a12963f /Swift/Controllers
parent8ab7ca17fdde8f8fb62a0c574478aa2c4c01a9bc (diff)
downloadswift-contrib-acac7962ba04c083377f62f4265ecc754176f74e.zip
swift-contrib-acac7962ba04c083377f62f4265ecc754176f74e.tar.bz2
Refactor AdHoc forms.
Test-Information: Check that forms still open properly and can be submitted and canceled. Check that error message is displayed if disconnected when a form is open. Change-Id: I23e35730b0decdfb5cf0592fc7234bf4643b6127
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/AdHocController.cpp31
-rw-r--r--Swift/Controllers/AdHocController.h28
-rw-r--r--Swift/Controllers/AdHocManager.cpp20
-rw-r--r--Swift/Controllers/AdHocManager.h14
-rw-r--r--Swift/Controllers/MainController.cpp5
-rw-r--r--Swift/Controllers/SConscript1
-rw-r--r--Swift/Controllers/UIInterfaces/AdHocCommandWindow.h6
-rw-r--r--Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h9
8 files changed, 99 insertions, 15 deletions
diff --git a/Swift/Controllers/AdHocController.cpp b/Swift/Controllers/AdHocController.cpp
new file mode 100644
index 0000000..c017120
--- /dev/null
+++ b/Swift/Controllers/AdHocController.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2010-2014 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/bind.hpp>
+#include <Swift/Controllers/AdHocController.h>
+#include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h>
+
+namespace Swift {
+
+AdHocController::AdHocController(AdHocCommandWindowFactory* factory, boost::shared_ptr<OutgoingAdHocCommandSession> command) {
+ window_ = factory->createAdHocCommandWindow(command);
+ window_->onClosing.connect(boost::bind(&AdHocController::handleWindowClosed, this));
+}
+
+AdHocController::~AdHocController() {
+ window_->onClosing.disconnect(boost::bind(&AdHocController::handleWindowClosed, this));
+ delete window_;
+}
+
+void AdHocController::setOnline(bool online) {
+ window_->setOnline(online);
+}
+
+void AdHocController::handleWindowClosed() {
+ onDeleting();
+}
+
+}
diff --git a/Swift/Controllers/AdHocController.h b/Swift/Controllers/AdHocController.h
new file mode 100644
index 0000000..910756f
--- /dev/null
+++ b/Swift/Controllers/AdHocController.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2010-2014 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h>
+
+namespace Swift {
+
+class AdHocCommandWindowFactory;
+class AdHocCommandWindow;
+
+class AdHocController {
+public:
+ AdHocController(AdHocCommandWindowFactory* factory, boost::shared_ptr<OutgoingAdHocCommandSession> command);
+ ~AdHocController();
+ boost::signal<void ()> onDeleting;
+ void setOnline(bool online);
+private:
+ void handleWindowClosed();
+ AdHocCommandWindow* window_;
+};
+
+}
diff --git a/Swift/Controllers/AdHocManager.cpp b/Swift/Controllers/AdHocManager.cpp
index e926138..59e139b 100644
--- a/Swift/Controllers/AdHocManager.cpp
+++ b/Swift/Controllers/AdHocManager.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -32,4 +32,12 @@ AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, I
AdHocManager::~AdHocManager() {
uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1));
+ for (size_t i = 0; i < controllers_.size(); ++i) {
+ controllers_[i]->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controllers_[i]));
+ }
+}
+
+void AdHocManager::removeController(boost::shared_ptr<AdHocController> controller) {
+ controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));
+ controllers_.erase(std::find(controllers_.begin(), controllers_.end(), controller));
}
@@ -46,5 +54,10 @@ void AdHocManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) {
mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
}
+}
+void AdHocManager::setOnline(bool online) {
+ foreach (boost::shared_ptr<AdHocController> controller, controllers_) {
+ controller->setOnline(online);
+ }
}
@@ -64,5 +77,8 @@ void AdHocManager::handleUIEvent(boost::shared_ptr<UIEvent> event) {
boost::shared_ptr<RequestAdHocUIEvent> adHocEvent = boost::dynamic_pointer_cast<RequestAdHocUIEvent>(event);
if (adHocEvent) {
- factory_->createAdHocCommandWindow(boost::make_shared<OutgoingAdHocCommandSession>(adHocEvent->getCommand().getJID(), adHocEvent->getCommand().getNode(), iqRouter_));
+ boost::shared_ptr<OutgoingAdHocCommandSession> command = boost::make_shared<OutgoingAdHocCommandSession>(adHocEvent->getCommand().getJID(), adHocEvent->getCommand().getNode(), iqRouter_);
+ boost::shared_ptr<AdHocController> controller = boost::make_shared<AdHocController>(factory_, command);
+ controller->onDeleting.connect(boost::bind(&AdHocManager::removeController, this, controller));
+ controllers_.push_back(controller);
}
}
diff --git a/Swift/Controllers/AdHocManager.h b/Swift/Controllers/AdHocManager.h
index 47b03cd..b2c34c5 100644
--- a/Swift/Controllers/AdHocManager.h
+++ b/Swift/Controllers/AdHocManager.h
@@ -1,11 +1,8 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#pragma once
-
-#include <boost/shared_ptr.hpp>
#include <vector>
@@ -16,5 +13,7 @@
#include <Swiften/Elements/ErrorPayload.h>
#include <Swiften/Disco/GetDiscoItemsRequest.h>
+#include <Swiften/Client/Client.h>
#include <Swift/Controllers/UIEvents/UIEvent.h>
+#include <Swift/Controllers/AdHocController.h>
namespace Swift {
@@ -27,8 +26,11 @@ namespace Swift {
AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow);
~AdHocManager();
+ void removeController(boost::shared_ptr<AdHocController> contoller);
void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info);
+ void setOnline(bool online);
private:
- void handleUIEvent(boost::shared_ptr<UIEvent> event);
void handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems>, ErrorPayload::ref error);
+ void handleUIEvent(boost::shared_ptr<UIEvent> event);
+ boost::signal<void (const AdHocController&)> onControllerComplete;
JID jid_;
IQRouter* iqRouter_;
@@ -37,4 +39,6 @@ namespace Swift {
AdHocCommandWindowFactory* factory_;
GetDiscoItemsRequest::ref discoItemsRequest_;
+ std::vector<boost::shared_ptr<AdHocController> > controllers_;
};
+
}
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index f16f8ad..79b7502 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -423,5 +423,5 @@ void MainController::handleConnected() {
assert(chatsManager_);
chatsManager_->setOnline(true);
-
+ adHocManager_->setOnline(true);
}
@@ -603,4 +603,7 @@ void MainController::handleDisconnected(const boost::optional<ClientError>& erro
rosterController_->getWindow()->setStreamEncryptionStatus(false);
}
+ if (adHocManager_) {
+ adHocManager_->setOnline(false);
+ }
if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) {
purgeCachedCredentials();
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index e911a3a..4c71268 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -58,4 +58,5 @@ if env["SCONS_STAGE"] == "build" :
"EventNotifier.cpp",
"AdHocManager.cpp",
+ "AdHocController.cpp",
"XMPPEvents/EventController.cpp",
"UIEvents/UIEvent.cpp",
diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
index 835defe..07319c2 100644
--- a/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
+++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,8 +7,12 @@
#pragma once
+#include <Swiften/Base/boost_bsignals.h>
+
namespace Swift {
class AdHocCommandWindow {
public:
virtual ~AdHocCommandWindow() {}
+ virtual void setOnline(bool /*online*/) {}
+ boost::signal<void ()> onClosing;
};
}
diff --git a/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
index ae77180..eeefa2d 100644
--- a/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
+++ b/Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -11,12 +11,9 @@
namespace Swift {
+class AdHocCommandWindow;
class AdHocCommandWindowFactory {
public:
virtual ~AdHocCommandWindowFactory() {}
- /**
- * The UI should deal with the lifetime of this window (i.e. DeleteOnClose),
- * so the result isn't returned.
- */
- virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) = 0;
+ virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) = 0;
};
}