diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/BlockListController.cpp | 34 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/BlockListEditorWidget.h | 8 |
2 files changed, 37 insertions, 5 deletions
diff --git a/Swift/Controllers/BlockListController.cpp b/Swift/Controllers/BlockListController.cpp index d778883..9cd42f0 100644 --- a/Swift/Controllers/BlockListController.cpp +++ b/Swift/Controllers/BlockListController.cpp @@ -1,12 +1,18 @@ /* * Copyright (c) 2013 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + #include <Swift/Controllers/BlockListController.h> #include <boost/bind.hpp> #include <Swiften/Client/ClientBlockListManager.h> @@ -54,12 +60,13 @@ void BlockListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) { if (blockListEditorWidget_ == NULL) { blockListEditorWidget_ = blockListEditorWidgetFactory_->createBlockListEditorWidget(); blockListEditorWidget_->onSetNewBlockList.connect(boost::bind(&BlockListController::handleSetNewBlockList, this, _1)); } blockListBeforeEdit = blockListManager_->getBlockList()->getItems(); blockListEditorWidget_->setCurrentBlockList(blockListBeforeEdit); + blockListEditorWidget_->setError(""); blockListEditorWidget_->show(); return; } // handle block state change boost::shared_ptr<RequestChangeBlockStateUIEvent> changeStateEvent = boost::dynamic_pointer_cast<RequestChangeBlockStateUIEvent>(rawEvent); @@ -82,36 +89,50 @@ void BlockListController::handleBlockResponse(GenericRequest<BlockPayload>::ref std::string errorMessage; // FIXME: Handle reporting of list of JIDs in a translatable way. errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to block %1%.")) % jids.at(0).toString()); if (!error->getText().empty()) { errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText()); } - eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage)); + if (blockListEditorWidget_ && originEditor) { + blockListEditorWidget_->setError(errorMessage); + blockListEditorWidget_->setBusy(false); + } + else { + eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage)); + } } if (originEditor) { remainingRequests_--; - if (blockListEditorWidget_ && (remainingRequests_ == 0)) { + if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) { blockListEditorWidget_->setBusy(false); + blockListEditorWidget_->hide(); } } } void BlockListController::handleUnblockResponse(GenericRequest<UnblockPayload>::ref request, boost::shared_ptr<UnblockPayload>, ErrorPayload::ref error, const std::vector<JID>& jids, bool originEditor) { if (error) { std::string errorMessage; // FIXME: Handle reporting of list of JIDs in a translatable way. errorMessage = str(format(QT_TRANSLATE_NOOP("", "Failed to unblock %1%.")) % jids.at(0).toString()); if (!error->getText().empty()) { errorMessage = str(format(QT_TRANSLATE_NOOP("", "%1%: %2%.")) % errorMessage % error->getText()); } - eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage)); + if (blockListEditorWidget_ && originEditor) { + blockListEditorWidget_->setError(errorMessage); + blockListEditorWidget_->setBusy(false); + } + else { + eventController_->handleIncomingEvent(boost::make_shared<ErrorEvent>(request->getReceiver(), errorMessage)); + } } if (originEditor) { remainingRequests_--; - if (blockListEditorWidget_ && (remainingRequests_ == 0)) { + if (blockListEditorWidget_ && (remainingRequests_ == 0) && !error) { blockListEditorWidget_->setBusy(false); + blockListEditorWidget_->hide(); } } } void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlockList) { std::vector<JID> jidsToBlock; @@ -128,15 +149,18 @@ void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlock if (!jidsToUnblock.empty()) { remainingRequests_++; GenericRequest<UnblockPayload>::ref unblockRequest = blockListManager_->createUnblockJIDsRequest(jidsToUnblock); unblockRequest->onResponse.connect(boost::bind(&BlockListController::handleUnblockResponse, this, unblockRequest, _1, _2, jidsToUnblock, true)); unblockRequest->send(); } - if (!jidsToBlock.empty() || jidsToUnblock.empty()) { + if (!jidsToBlock.empty() || !jidsToUnblock.empty()) { assert(blockListEditorWidget_); blockListEditorWidget_->setBusy(true); + blockListEditorWidget_->setError(""); + } else { + blockListEditorWidget_->hide(); } } void BlockListController::handleBlockListChanged() { if (blockListEditorWidget_) { std::vector<JID> jidsToBlock; diff --git a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h index 60a1c11..f8a4c59 100644 --- a/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h +++ b/Swift/Controllers/UIInterfaces/BlockListEditorWidget.h @@ -1,12 +1,18 @@ /* * Copyright (c) 2013 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + #pragma once #include <vector> #include <Swiften/JID/JID.h> #include <Swiften/Base/boost_bsignals.h> @@ -17,15 +23,17 @@ namespace Swift { class BlockListEditorWidget { public: virtual ~BlockListEditorWidget() {} virtual void show() = 0; + virtual void hide() = 0; virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs) = 0; virtual void setBusy(bool isBusy) = 0; + virtual void setError(const std::string&) = 0; virtual std::vector<JID> getCurrentBlockList() const = 0; boost::signal<void (const std::vector<JID>& /* blockedJID */)> onSetNewBlockList; }; |