diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/ProfileController.cpp | 1 | ||||
-rw-r--r-- | Swift/Controllers/ShowProfileController.cpp | 17 | ||||
-rw-r--r-- | Swift/Controllers/ShowProfileController.h | 4 |
3 files changed, 20 insertions, 2 deletions
diff --git a/Swift/Controllers/ProfileController.cpp b/Swift/Controllers/ProfileController.cpp index d000164..1a92f29 100644 --- a/Swift/Controllers/ProfileController.cpp +++ b/Swift/Controllers/ProfileController.cpp @@ -21,60 +21,61 @@ ProfileController::ProfileController(VCardManager* vcardManager, ProfileWindowFa uiEventStream->onUIEvent.connect(boost::bind(&ProfileController::handleUIEvent, this, _1)); } ProfileController::~ProfileController() { if (profileWindow) { vcardManager->onOwnVCardChanged.disconnect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1)); vcardManager->onVCardRetrievalError.disconnect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2)); profileWindow->onVCardChangeRequest.disconnect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1)); profileWindow->onWindowAboutToBeClosed.disconnect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1)); } uiEventStream->onUIEvent.disconnect(boost::bind(&ProfileController::handleUIEvent, this, _1)); delete profileWindow; } void ProfileController::handleUIEvent(UIEvent::ref event) { if (!std::dynamic_pointer_cast<RequestProfileEditorUIEvent>(event)) { return; } if (!profileWindow) { profileWindow = profileWindowFactory->createProfileWindow(); profileWindow->setEditable(true); profileWindow->onVCardChangeRequest.connect(boost::bind(&ProfileController::handleVCardChangeRequest, this, _1)); profileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ProfileController::handleProfileWindowAboutToBeClosed, this, _1)); vcardManager->onOwnVCardChanged.connect(boost::bind(&ProfileController::handleOwnVCardChanged, this, _1)); vcardManager->onVCardRetrievalError.connect(boost::bind(&ProfileController::handleVCardRetrievalError, this, _1, _2)); } gettingVCard = true; updateDialogStatus(); vcardManager->requestOwnVCard(); + profileWindow->setError(""); profileWindow->show(); } void ProfileController::handleVCardChangeRequest(VCard::ref vcard) { assert(!pendingSetVCardRequest); profileWindow->setError(""); pendingSetVCardRequest = vcardManager->createSetVCardRequest(vcard); pendingSetVCardRequest->onResponse.connect(boost::bind(&ProfileController::handleSetVCardResponse, this, _2)); pendingSetVCardRequest->send(); updateDialogStatus(); } void ProfileController::handleSetVCardResponse(ErrorPayload::ref error) { pendingSetVCardRequest.reset(); updateDialogStatus(); if (error) { profileWindow->setVCard(vcardBeforeEdit); profileWindow->setError(QT_TRANSLATE_NOOP("", "There was an error publishing your profile data")); } else { profileWindow->setError(""); profileWindow->hide(); } } void ProfileController::handleVCardRetrievalError(const JID& jid, ErrorPayload::ref /* error */) { if ((jid == JID()) && profileWindow) { profileWindow->setProcessing(false); profileWindow->setEnabled(false); profileWindow->setVCard(std::make_shared<VCard>()); diff --git a/Swift/Controllers/ShowProfileController.cpp b/Swift/Controllers/ShowProfileController.cpp index b379141..a7d7d04 100644 --- a/Swift/Controllers/ShowProfileController.cpp +++ b/Swift/Controllers/ShowProfileController.cpp @@ -1,79 +1,94 @@ /* * Copyright (c) 2012 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2014-2016 Isode Limited. + * Copyright (c) 2014-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swift/Controllers/ShowProfileController.h> #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <Swiften/VCards/VCardManager.h> +#include <Swift/Controllers/Intl.h> #include <Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIInterfaces/ProfileWindowFactory.h> namespace Swift { ShowProfileController::ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream) : vcardManager(vcardManager), profileWindowFactory(profileWindowFactory), uiEventStream(uiEventStream) { uiEventStream->onUIEvent.connect(boost::bind(&ShowProfileController::handleUIEvent, this, _1)); vcardManager->onVCardChanged.connect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2)); + vcardManager->onVCardRetrievalError.connect(boost::bind(&ShowProfileController::handleVCardRetrievalError, this, _1, _2)); } ShowProfileController::~ShowProfileController() { for (const auto& jidWndPair : openedProfileWindows) { jidWndPair.second->onWindowAboutToBeClosed.disconnect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1)); delete jidWndPair.second; } + vcardManager->onVCardRetrievalError.disconnect(boost::bind(&ShowProfileController::handleVCardRetrievalError, this, _1, _2)); vcardManager->onVCardChanged.disconnect(boost::bind(&ShowProfileController::handleVCardChanged, this, _1, _2)); uiEventStream->onUIEvent.disconnect(boost::bind(&ShowProfileController::handleUIEvent, this, _1)); } void ShowProfileController::handleUIEvent(UIEvent::ref event) { ShowProfileForRosterItemUIEvent::ref showProfileEvent = std::dynamic_pointer_cast<ShowProfileForRosterItemUIEvent>(event); if (!showProfileEvent) { return; } if (openedProfileWindows.find(showProfileEvent->getJID()) == openedProfileWindows.end()) { ProfileWindow* newProfileWindow = profileWindowFactory->createProfileWindow(); newProfileWindow->setJID(showProfileEvent->getJID()); newProfileWindow->onWindowAboutToBeClosed.connect(boost::bind(&ShowProfileController::handleProfileWindowAboutToBeClosed, this, _1)); openedProfileWindows[showProfileEvent->getJID()] = newProfileWindow; VCard::ref vcard = vcardManager->getVCardAndRequestWhenNeeded(showProfileEvent->getJID(), boost::posix_time::minutes(5)); if (vcard) { newProfileWindow->setVCard(vcard); } else { newProfileWindow->setProcessing(true); } + newProfileWindow->setError(""); newProfileWindow->show(); } else { openedProfileWindows[showProfileEvent->getJID()]->show(); } } void ShowProfileController::handleVCardChanged(const JID& jid, VCard::ref vcard) { if (openedProfileWindows.find(jid) == openedProfileWindows.end()) { return; } ProfileWindow* profileWindow = openedProfileWindows[jid]; profileWindow->setVCard(vcard); profileWindow->setProcessing(false); profileWindow->show(); } void ShowProfileController::handleProfileWindowAboutToBeClosed(const JID& profileJid) { openedProfileWindows.erase(profileJid); } +void ShowProfileController::handleVCardRetrievalError(const JID& jid, ErrorPayload::ref /* error */) { + if (openedProfileWindows.find(jid) == openedProfileWindows.end()) { + return; + } + + auto profileWindow = openedProfileWindows[jid]; + profileWindow->setError(QT_TRANSLATE_NOOP("", "Failed to retrieve recent profile for user.")); + profileWindow->setProcessing(false); + profileWindow->show(); +} + } diff --git a/Swift/Controllers/ShowProfileController.h b/Swift/Controllers/ShowProfileController.h index 4f23c19..0d01ba1 100644 --- a/Swift/Controllers/ShowProfileController.h +++ b/Swift/Controllers/ShowProfileController.h @@ -1,42 +1,44 @@ /* * Copyright (c) 2012 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2016 Isode Limited. + * Copyright (c) 2016-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <Swiften/Elements/ErrorPayload.h> #include <Swiften/Elements/VCard.h> #include <Swiften/JID/JID.h> #include <Swift/Controllers/UIEvents/UIEvent.h> namespace Swift { class VCardManager; class ProfileWindow; class ProfileWindowFactory; class UIEventStream; class ShowProfileController { public: ShowProfileController(VCardManager* vcardManager, ProfileWindowFactory* profileWindowFactory, UIEventStream* uiEventStream); ~ShowProfileController(); private: void handleUIEvent(UIEvent::ref event); void handleVCardChanged(const JID&, VCard::ref); void handleProfileWindowAboutToBeClosed(const JID& profileJid); + void handleVCardRetrievalError(const JID& jid, ErrorPayload::ref error); private: VCardManager* vcardManager; ProfileWindowFactory* profileWindowFactory; UIEventStream* uiEventStream; std::map<JID, ProfileWindow*> openedProfileWindows; }; } |