summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/BlockListController.cpp')
-rw-r--r--Swift/Controllers/BlockListController.cpp34
1 files changed, 29 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,15 +1,21 @@
/*
* 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>
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/format.h>
#include <Swift/Controllers/Intl.h>
@@ -51,18 +57,19 @@ void BlockListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
// handle UI dialog
boost::shared_ptr<RequestBlockListDialogUIEvent> requestDialogEvent = boost::dynamic_pointer_cast<RequestBlockListDialogUIEvent>(rawEvent);
if (requestDialogEvent != NULL) {
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);
if (changeStateEvent != NULL) {
if (changeStateEvent->getBlockState() == RequestChangeBlockStateUIEvent::Blocked) {
GenericRequest<BlockPayload>::ref blockRequest = blockListManager_->createBlockJIDRequest(changeStateEvent->getContact());
@@ -79,42 +86,56 @@ void BlockListController::handleUIEvent(boost::shared_ptr<UIEvent> rawEvent) {
void BlockListController::handleBlockResponse(GenericRequest<BlockPayload>::ref request, boost::shared_ptr<BlockPayload>, 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 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;
std::vector<JID> jidsToUnblock;
blockListDifferences(newBlockList, jidsToUnblock, jidsToBlock);
@@ -125,21 +146,24 @@ void BlockListController::handleSetNewBlockList(const std::vector<JID> &newBlock
blockRequest->onResponse.connect(boost::bind(&BlockListController::handleBlockResponse, this, blockRequest, _1, _2, jidsToBlock, true));
blockRequest->send();
}
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;
std::vector<JID> jidsToUnblock;
blockListDifferences(blockListEditorWidget_->getCurrentBlockList(), jidsToUnblock, jidsToBlock);