diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-05-02 09:19:23 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-07-09 09:03:34 (GMT) |
| commit | acac7962ba04c083377f62f4265ecc754176f74e (patch) | |
| tree | fa2db718854d10c76e81fc54b0b1f2b33a12963f /Swift | |
| parent | 8ab7ca17fdde8f8fb62a0c574478aa2c4c01a9bc (diff) | |
| download | swift-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')
| -rw-r--r-- | Swift/Controllers/AdHocController.cpp | 31 | ||||
| -rw-r--r-- | Swift/Controllers/AdHocController.h | 28 | ||||
| -rw-r--r-- | Swift/Controllers/AdHocManager.cpp | 20 | ||||
| -rw-r--r-- | Swift/Controllers/AdHocManager.h | 50 | ||||
| -rw-r--r-- | Swift/Controllers/MainController.cpp | 5 | ||||
| -rw-r--r-- | Swift/Controllers/SConscript | 1 | ||||
| -rw-r--r-- | Swift/Controllers/UIInterfaces/AdHocCommandWindow.h | 6 | ||||
| -rw-r--r-- | Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h | 9 | ||||
| -rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.cpp | 28 | ||||
| -rw-r--r-- | Swift/QtUI/QtAdHocCommandWindow.h | 3 | ||||
| -rw-r--r-- | Swift/QtUI/QtUIFactory.cpp | 6 | ||||
| -rw-r--r-- | Swift/QtUI/QtUIFactory.h | 4 |
12 files changed, 149 insertions, 42 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,70 +1,86 @@ /* - * 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. */ #include <Swift/Controllers/AdHocManager.h> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/foreach.h> #include <Swiften/Queries/IQRouter.h> #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> #include <Swift/Controllers/UIInterfaces/MainWindow.h> #include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h> namespace Swift { AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow) : jid_(jid) { iqRouter_ = iqRouter; uiEventStream_ = uiEventStream; mainWindow_ = mainWindow; factory_ = factory; uiEventStream_->onUIEvent.connect(boost::bind(&AdHocManager::handleUIEvent, this, _1)); } 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)); } void AdHocManager::setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info) { if (iqRouter_->isAvailable() && info->hasFeature(DiscoInfo::CommandsFeature)) { if (discoItemsRequest_) { discoItemsRequest_->onResponse.disconnect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2)); discoItemsRequest_.reset(); } discoItemsRequest_ = GetDiscoItemsRequest::create(JID(jid_.getDomain()), DiscoInfo::CommandsFeature, iqRouter_); discoItemsRequest_->onResponse.connect(boost::bind(&AdHocManager::handleServerDiscoItemsResponse, this, _1, _2)); discoItemsRequest_->send(); } else { mainWindow_->setAvailableAdHocCommands(std::vector<DiscoItems::Item>()); } +} +void AdHocManager::setOnline(bool online) { + foreach (boost::shared_ptr<AdHocController> controller, controllers_) { + controller->setOnline(online); + } } void AdHocManager::handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems> items, ErrorPayload::ref error) { std::vector<DiscoItems::Item> commands; if (!error) { foreach (DiscoItems::Item item, items->getItems()) { if (item.getNode() != "http://isode.com/xmpp/commands#test") { commands.push_back(item); } } } mainWindow_->setAvailableAdHocCommands(commands); } 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,40 +1,44 @@ /* - * 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> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/JID/JID.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Elements/DiscoItems.h> #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 { - class IQRouter; - class MainWindow; - class UIEventStream; - class AdHocCommandWindowFactory; - class AdHocManager { - public: - AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, IQRouter* iqRouter, UIEventStream* uiEventStream, MainWindow* mainWindow); - ~AdHocManager(); - void setServerDiscoInfo(boost::shared_ptr<DiscoInfo> info); - private: - void handleUIEvent(boost::shared_ptr<UIEvent> event); - void handleServerDiscoItemsResponse(boost::shared_ptr<DiscoItems>, ErrorPayload::ref error); - JID jid_; - IQRouter* iqRouter_; - UIEventStream* uiEventStream_; - MainWindow* mainWindow_; - AdHocCommandWindowFactory* factory_; - GetDiscoItemsRequest::ref discoItemsRequest_; - }; +class IQRouter; +class MainWindow; +class UIEventStream; +class AdHocCommandWindowFactory; +class AdHocManager { +public: + 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 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_; + UIEventStream* uiEventStream_; + MainWindow* mainWindow_; + 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 @@ -1,892 +1,895 @@ /* * Copyright (c) 2010-2013 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ /* * Copyright (c) 2013 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swift/Controllers/MainController.h> #include <cstdlib> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> #include <boost/shared_ptr.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/format.h> #include <Swiften/Base/Algorithm.h> #include <Swiften/Base/String.h> #include <Swiften/StringCodecs/Base64.h> #include <Swiften/Network/TimerFactory.h> #include <Swiften/Client/Storages.h> #include <Swiften/VCards/VCardManager.h> #include <Swiften/Client/NickResolver.h> #include <Swiften/Base/foreach.h> #include <Swiften/Client/Client.h> #include <Swiften/Presence/PresenceSender.h> #include <Swiften/Elements/ChatState.h> #include <Swiften/Elements/Presence.h> #include <Swiften/Elements/VCardUpdate.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Disco/CapsInfoGenerator.h> #include <Swiften/Disco/GetDiscoInfoRequest.h> #include <Swiften/Disco/ClientDiscoManager.h> #include <Swiften/VCards/GetVCardRequest.h> #include <Swiften/StringCodecs/Hexify.h> #include <Swiften/Network/NetworkFactories.h> #include <Swiften/FileTransfer/FileTransferManager.h> #include <Swiften/Client/ClientXMLTracer.h> #include <Swiften/Client/StanzaChannel.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swiften/Crypto/CryptoProvider.h> #include <SwifTools/Dock/Dock.h> #include <SwifTools/Notifier/TogglableNotifier.h> #include <SwifTools/Idle/IdleDetector.h> #include <Swift/Controllers/Intl.h> #include <Swift/Controllers/UIInterfaces/UIFactory.h> #include <Swift/Controllers/BuildVersion.h> #include <Swift/Controllers/Chat/UserSearchController.h> #include <Swift/Controllers/Chat/ChatsManager.h> #include <Swift/Controllers/XMPPEvents/EventController.h> #include <Swift/Controllers/EventWindowController.h> #include <Swift/Controllers/UIInterfaces/LoginWindow.h> #include <Swift/Controllers/UIInterfaces/LoginWindowFactory.h> #include <Swift/Controllers/UIInterfaces/MainWindow.h> #include <Swift/Controllers/Chat/MUCController.h> #include <Swift/Controllers/Roster/RosterController.h> #include <Swift/Controllers/SoundEventController.h> #include <Swift/Controllers/SoundPlayer.h> #include <Swift/Controllers/StatusTracker.h> #include <Swift/Controllers/SystemTray.h> #include <Swift/Controllers/SystemTrayController.h> #include <Swift/Controllers/XMLConsoleController.h> #include <Swift/Controllers/HistoryController.h> #include <Swift/Controllers/HistoryViewController.h> #include <Swift/Controllers/FileTransferListController.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/PresenceNotifier.h> #include <Swift/Controllers/EventNotifier.h> #include <Swift/Controllers/Storages/StoragesFactory.h> #include <Swift/Controllers/WhiteboardManager.h> #include <Swift/Controllers/Settings/SettingsProvider.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> #include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include <Swift/Controllers/Storages/CertificateStorageFactory.h> #include <Swift/Controllers/Storages/CertificateStorageTrustChecker.h> #include <Swift/Controllers/ProfileController.h> #include <Swift/Controllers/ShowProfileController.h> #include <Swift/Controllers/ContactEditController.h> #include <Swift/Controllers/XMPPURIController.h> #include <Swift/Controllers/AdHocManager.h> #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> #include <Swift/Controllers/SettingConstants.h> #include <Swift/Controllers/HighlightManager.h> #include <Swift/Controllers/HighlightEditorController.h> #include <Swift/Controllers/BlockListController.h> #include <Swift/Controllers/ContactSuggester.h> #include <Swift/Controllers/ContactsFromXMPPRoster.h> namespace Swift { static const std::string CLIENT_NAME = "Swift"; static const std::string CLIENT_NODE = "http://swift.im"; MainController::MainController( EventLoop* eventLoop, NetworkFactories* networkFactories, UIFactory* uiFactories, SettingsProvider* settings, SystemTray* systemTray, SoundPlayer* soundPlayer, StoragesFactory* storagesFactory, CertificateStorageFactory* certificateStorageFactory, Dock* dock, Notifier* notifier, URIHandler* uriHandler, IdleDetector* idleDetector, const std::map<std::string, std::string>& emoticons, bool useDelayForLatency) : eventLoop_(eventLoop), networkFactories_(networkFactories), uiFactory_(uiFactories), storagesFactory_(storagesFactory), certificateStorageFactory_(certificateStorageFactory), settings_(settings), uriHandler_(uriHandler), idleDetector_(idleDetector), loginWindow_(NULL) , useDelayForLatency_(useDelayForLatency), ftOverview_(NULL), emoticons_(emoticons) { storages_ = NULL; certificateStorage_ = NULL; statusTracker_ = NULL; presenceNotifier_ = NULL; eventNotifier_ = NULL; rosterController_ = NULL; chatsManager_ = NULL; historyController_ = NULL; historyViewController_ = NULL; eventWindowController_ = NULL; profileController_ = NULL; blockListController_ = NULL; showProfileController_ = NULL; contactEditController_ = NULL; userSearchControllerChat_ = NULL; userSearchControllerAdd_ = NULL; userSearchControllerInvite_ = NULL; contactsFromRosterProvider_ = NULL; contactSuggesterWithoutRoster_ = NULL; contactSuggesterWithRoster_ = NULL; whiteboardManager_ = NULL; adHocManager_ = NULL; quitRequested_ = false; clientInitialized_ = false; offlineRequested_ = false; timeBeforeNextReconnect_ = -1; dock_ = dock; uiEventStream_ = new UIEventStream(); notifier_ = new TogglableNotifier(notifier); notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS)); eventController_ = new EventController(); eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1)); systemTrayController_ = new SystemTrayController(eventController_, systemTray); loginWindow_ = uiFactory_->createLoginWindow(uiEventStream_); loginWindow_->setShowNotificationToggle(!notifier->isExternallyConfigured()); highlightManager_ = new HighlightManager(settings_); highlightEditorController_ = new HighlightEditorController(uiEventStream_, uiFactory_, highlightManager_); soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings, highlightManager_); xmppURIController_ = new XMPPURIController(uriHandler_, uiEventStream_); std::string selectedLoginJID = settings_->getSetting(SettingConstants::LAST_LOGIN_JID); bool loginAutomatically = settings_->getSetting(SettingConstants::LOGIN_AUTOMATICALLY); std::string cachedPassword; std::string cachedCertificate; ClientOptions cachedOptions; bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS); if (!eagle) { foreach (std::string profile, settings->getAvailableProfiles()) { ProfileSettingsProvider profileSettings(profile, settings); std::string password = profileSettings.getStringSetting("pass"); std::string certificate = profileSettings.getStringSetting("certificate"); std::string jid = profileSettings.getStringSetting("jid"); ClientOptions clientOptions = parseClientOptions(profileSettings.getStringSetting("options")); loginWindow_->addAvailableAccount(jid, password, certificate, clientOptions); if (jid == selectedLoginJID) { cachedPassword = password; cachedCertificate = certificate; cachedOptions = clientOptions; } } loginWindow_->selectUser(selectedLoginJID); loginWindow_->setLoginAutomatically(loginAutomatically); } loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4, _5, _6, _7)); loginWindow_->onPurgeSavedLoginRequest.connect(boost::bind(&MainController::handlePurgeSavedLoginRequest, this, _1)); loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this)); loginWindow_->onQuitRequest.connect(boost::bind(&MainController::handleQuitRequest, this)); idleDetector_->setIdleTimeSeconds(settings->getSetting(SettingConstants::IDLE_TIMEOUT)); idleDetector_->onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1)); xmlConsoleController_ = new XMLConsoleController(uiEventStream_, uiFactory_); fileTransferListController_ = new FileTransferListController(uiEventStream_, uiFactory_); settings_->onSettingChanged.connect(boost::bind(&MainController::handleSettingChanged, this, _1)); if (loginAutomatically) { profileSettings_ = new ProfileSettingsProvider(selectedLoginJID, settings_); /* FIXME: deal with autologin with a cert*/ handleLoginRequest(selectedLoginJID, cachedPassword, cachedCertificate, CertificateWithKey::ref(), cachedOptions, true, true); } else { profileSettings_ = NULL; } } MainController::~MainController() { idleDetector_->onIdleChanged.disconnect(boost::bind(&MainController::handleInputIdleChanged, this, _1)); purgeCachedCredentials(); //setManagersOffline(); eventController_->disconnectAll(); resetClient(); delete highlightEditorController_; delete highlightManager_; delete fileTransferListController_; delete xmlConsoleController_; delete xmppURIController_; delete soundEventController_; delete systemTrayController_; delete eventController_; delete notifier_; delete uiEventStream_; } void MainController::purgeCachedCredentials() { safeClear(password_); } void MainController::resetClient() { purgeCachedCredentials(); resetCurrentError(); resetPendingReconnects(); vCardPhotoHash_.clear(); delete contactEditController_; contactEditController_ = NULL; delete profileController_; profileController_ = NULL; delete showProfileController_; showProfileController_ = NULL; delete eventWindowController_; eventWindowController_ = NULL; delete chatsManager_; chatsManager_ = NULL; #ifdef SWIFT_EXPERIMENTAL_HISTORY delete historyViewController_; historyViewController_ = NULL; delete historyController_; historyController_ = NULL; #endif delete ftOverview_; ftOverview_ = NULL; delete rosterController_; rosterController_ = NULL; delete eventNotifier_; eventNotifier_ = NULL; delete presenceNotifier_; presenceNotifier_ = NULL; delete certificateStorage_; certificateStorage_ = NULL; delete storages_; storages_ = NULL; delete statusTracker_; statusTracker_ = NULL; delete profileSettings_; profileSettings_ = NULL; delete userSearchControllerChat_; userSearchControllerChat_ = NULL; delete userSearchControllerAdd_; userSearchControllerAdd_ = NULL; delete userSearchControllerInvite_; userSearchControllerInvite_ = NULL; delete contactSuggesterWithoutRoster_; contactSuggesterWithoutRoster_ = NULL; delete contactSuggesterWithRoster_; contactSuggesterWithRoster_ = NULL; delete contactsFromRosterProvider_; contactsFromRosterProvider_ = NULL; delete adHocManager_; adHocManager_ = NULL; delete whiteboardManager_; whiteboardManager_ = NULL; clientInitialized_ = false; } void MainController::handleSettingChanged(const std::string& settingPath) { if (settingPath == SettingConstants::SHOW_NOTIFICATIONS.getKey()) { notifier_->setPersistentEnabled(settings_->getSetting(SettingConstants::SHOW_NOTIFICATIONS)); } } void MainController::resetPendingReconnects() { timeBeforeNextReconnect_ = -1; if (reconnectTimer_) { reconnectTimer_->stop(); reconnectTimer_.reset(); } resetCurrentError(); } void MainController::resetCurrentError() { if (lastDisconnectError_) { lastDisconnectError_->conclude(); lastDisconnectError_ = boost::shared_ptr<ErrorEvent>(); } } void MainController::handleConnected() { boundJID_ = client_->getJID(); resetCurrentError(); resetPendingReconnects(); if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } bool freshLogin = rosterController_ == NULL; myStatusLooksOnline_ = true; if (freshLogin) { profileController_ = new ProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_); showProfileController_ = new ShowProfileController(client_->getVCardManager(), uiFactory_, uiEventStream_); ftOverview_ = new FileTransferOverview(client_->getFileTransferManager()); fileTransferListController_->setFileTransferOverview(ftOverview_); rosterController_ = new RosterController(boundJID_, client_->getRoster(), client_->getAvatarManager(), uiFactory_, client_->getNickManager(), client_->getNickResolver(), client_->getPresenceOracle(), client_->getSubscriptionManager(), eventController_, uiEventStream_, client_->getIQRouter(), settings_, client_->getEntityCapsProvider(), ftOverview_, client_->getClientBlockListManager(), client_->getVCardManager()); rosterController_->onChangeStatusRequest.connect(boost::bind(&MainController::handleChangeStatusRequest, this, _1, _2)); rosterController_->onSignOutRequest.connect(boost::bind(&MainController::signOut, this)); rosterController_->getWindow()->onShowCertificateRequest.connect(boost::bind(&MainController::handleShowCertificateRequest, this)); blockListController_ = new BlockListController(client_->getClientBlockListManager(), uiEventStream_, uiFactory_, eventController_); contactEditController_ = new ContactEditController(rosterController_, client_->getVCardManager(), uiFactory_, uiEventStream_); whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getNickResolver(), client_->getWhiteboardSessionManager()); /* Doing this early as an ordering fix. Various things later will * want to have the user's nick available and this means it will * be before they receive stanzas that need it (e.g. bookmarks).*/ client_->getVCardManager()->requestOwnVCard(); contactSuggesterWithoutRoster_ = new ContactSuggester(); contactSuggesterWithRoster_ = new ContactSuggester(); userSearchControllerInvite_ = new UserSearchController(UserSearchController::InviteToChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle()); #ifdef SWIFT_EXPERIMENTAL_HISTORY historyController_ = new HistoryController(storages_->getHistoryStorage()); historyViewController_ = new HistoryViewController(jid_, uiEventStream_, historyController_, client_->getNickResolver(), client_->getAvatarManager(), client_->getPresenceOracle(), uiFactory_); chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, historyController_, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, userSearchControllerInvite_, client_->getVCardManager()); #else chatsManager_ = new ChatsManager(jid_, client_->getStanzaChannel(), client_->getIQRouter(), eventController_, uiFactory_, uiFactory_, client_->getNickResolver(), client_->getPresenceOracle(), client_->getPresenceSender(), uiEventStream_, uiFactory_, useDelayForLatency_, networkFactories_->getTimerFactory(), client_->getMUCRegistry(), client_->getEntityCapsProvider(), client_->getMUCManager(), uiFactory_, profileSettings_, ftOverview_, client_->getRoster(), !settings_->getSetting(SettingConstants::REMEMBER_RECENT_CHATS), settings_, NULL, whiteboardManager_, highlightManager_, client_->getClientBlockListManager(), emoticons_, userSearchControllerInvite_, client_->getVCardManager()); #endif contactsFromRosterProvider_ = new ContactsFromXMPPRoster(client_->getRoster(), client_->getAvatarManager(), client_->getPresenceOracle()); contactSuggesterWithoutRoster_->addContactProvider(chatsManager_); contactSuggesterWithRoster_->addContactProvider(chatsManager_); contactSuggesterWithRoster_->addContactProvider(contactsFromRosterProvider_); client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(client_->getAvatarManager()); eventWindowController_ = new EventWindowController(eventController_, uiFactory_); loginWindow_->morphInto(rosterController_->getWindow()); DiscoInfo discoInfo; discoInfo.addIdentity(DiscoInfo::Identity(CLIENT_NAME, "client", "pc")); discoInfo.addFeature(DiscoInfo::ChatStatesFeature); discoInfo.addFeature(DiscoInfo::SecurityLabelsFeature); discoInfo.addFeature(DiscoInfo::MessageCorrectionFeature); #ifdef SWIFT_EXPERIMENTAL_FT discoInfo.addFeature(DiscoInfo::JingleFeature); discoInfo.addFeature(DiscoInfo::JingleFTFeature); discoInfo.addFeature(DiscoInfo::JingleTransportsIBBFeature); discoInfo.addFeature(DiscoInfo::JingleTransportsS5BFeature); #endif #ifdef SWIFT_EXPERIMENTAL_WB discoInfo.addFeature(DiscoInfo::WhiteboardFeature); #endif discoInfo.addFeature(DiscoInfo::MessageDeliveryReceiptsFeature); client_->getDiscoManager()->setCapsNode(CLIENT_NODE); client_->getDiscoManager()->setDiscoInfo(discoInfo); userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithRoster_, client_->getAvatarManager(), client_->getPresenceOracle()); userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_, contactSuggesterWithoutRoster_, client_->getAvatarManager(), client_->getPresenceOracle()); adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow()); chatsManager_->onImpromptuMUCServiceDiscovered.connect(boost::bind(&UserSearchController::setCanInitiateImpromptuMUC, userSearchControllerChat_, _1)); } loginWindow_->setIsLoggingIn(false); client_->requestRoster(); GetDiscoInfoRequest::ref discoInfoRequest = GetDiscoInfoRequest::create(JID(boundJID_.getDomain()), client_->getIQRouter()); discoInfoRequest->onResponse.connect(boost::bind(&MainController::handleServerDiscoInfoResponse, this, _1, _2)); discoInfoRequest->send(); client_->getVCardManager()->requestOwnVCard(); rosterController_->setJID(boundJID_); rosterController_->setEnabled(true); rosterController_->getWindow()->setStreamEncryptionStatus(client_->isStreamEncrypted()); profileController_->setAvailable(true); contactEditController_->setAvailable(true); /* Send presence later to catch all the incoming presences. */ sendPresence(statusTracker_->getNextPresence()); /* Enable chats last of all, so rejoining MUCs has the right sent presence */ assert(chatsManager_); chatsManager_->setOnline(true); - + adHocManager_->setOnline(true); } void MainController::handleEventQueueLengthChange(int count) { dock_->setNumberOfPendingMessages(count); } void MainController::reconnectAfterError() { if (reconnectTimer_) { reconnectTimer_->stop(); } performLoginFromCachedCredentials(); } void MainController::handleChangeStatusRequest(StatusShow::Type show, const std::string &statusText) { boost::shared_ptr<Presence> presence(new Presence()); if (show == StatusShow::None) { // Note: this is misleading, None doesn't mean unavailable on the wire. presence->setType(Presence::Unavailable); resetPendingReconnects(); myStatusLooksOnline_ = false; offlineRequested_ = true; } else { offlineRequested_ = false; presence->setShow(show); } presence->setStatus(statusText); statusTracker_->setRequestedPresence(presence); if (presence->getType() != Presence::Unavailable) { profileSettings_->storeInt("lastShow", presence->getShow()); profileSettings_->storeString("lastStatus", presence->getStatus()); } if (presence->getType() != Presence::Unavailable && !client_->isAvailable()) { performLoginFromCachedCredentials(); } else { sendPresence(presence); } } void MainController::sendPresence(boost::shared_ptr<Presence> presence) { rosterController_->getWindow()->setMyStatusType(presence->getShow()); rosterController_->getWindow()->setMyStatusText(presence->getStatus()); systemTrayController_->setMyStatusType(presence->getShow()); notifier_->setTemporarilyDisabled(presence->getShow() == StatusShow::DND); // Add information and send presence->updatePayload(boost::make_shared<VCardUpdate>(vCardPhotoHash_)); client_->getPresenceSender()->sendPresence(presence); if (presence->getType() == Presence::Unavailable) { logout(); } } void MainController::handleInputIdleChanged(bool idle) { if (!statusTracker_) { //Haven't logged in yet. return; } if (settings_->getSetting(SettingConstants::IDLE_GOES_OFFLINE)) { if (idle) { logout(); } } else { if (idle) { if (statusTracker_->goAutoAway(idleDetector_->getIdleTimeSeconds())) { if (client_ && client_->isAvailable()) { sendPresence(statusTracker_->getNextPresence()); } } } else { if (statusTracker_->goAutoUnAway()) { if (client_ && client_->isAvailable()) { sendPresence(statusTracker_->getNextPresence()); } } } } } void MainController::handleShowCertificateRequest() { std::vector<Certificate::ref> chain = client_->getStanzaChannel()->getPeerCertificateChain(); rosterController_->getWindow()->openCertificateDialog(chain); } void MainController::handleLoginRequest(const std::string &username, const std::string &password, const std::string& certificatePath, CertificateWithKey::ref certificate, const ClientOptions& options, bool remember, bool loginAutomatically) { jid_ = JID(username); if (!jid_.isValid() || jid_.getNode().empty()) { loginWindow_->setMessage(QT_TRANSLATE_NOOP("", "User address invalid. User address should be of the form 'alice@wonderland.lit'")); loginWindow_->setIsLoggingIn(false); } else { loginWindow_->setMessage(""); loginWindow_->setIsLoggingIn(true); profileSettings_ = new ProfileSettingsProvider(username, settings_); if (!settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { profileSettings_->storeString("jid", username); profileSettings_->storeString("certificate", certificatePath); profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : ""); std::string optionString = serializeClientOptions(options); profileSettings_->storeString("options", optionString); settings_->storeSetting(SettingConstants::LAST_LOGIN_JID, username); settings_->storeSetting(SettingConstants::LOGIN_AUTOMATICALLY, loginAutomatically); loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate"), options); } password_ = password; certificate_ = certificate; clientOptions_ = options; performLoginFromCachedCredentials(); } } void MainController::handlePurgeSavedLoginRequest(const std::string& username) { settings_->removeProfile(username); loginWindow_->removeAvailableAccount(username); } void MainController::performLoginFromCachedCredentials() { if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS) && password_.empty()) { /* Then we can't try to login again. */ return; } /* If we logged in with a bare JID, and we have a full bound JID, re-login with the * bound JID to try and keep dynamically assigned resources */ JID clientJID = jid_; if (boundJID_.isValid() && jid_.isBare() && boundJID_.toBare() == jid_) { clientJID = boundJID_; } if (!statusTracker_) { statusTracker_ = new StatusTracker(); } if (!clientInitialized_) { storages_ = storagesFactory_->createStorages(jid_.toBare()); certificateStorage_ = certificateStorageFactory_->createCertificateStorage(jid_.toBare()); certificateTrustChecker_ = new CertificateStorageTrustChecker(certificateStorage_); client_ = boost::make_shared<Swift::Client>(clientJID, createSafeByteArray(password_.c_str()), networkFactories_, storages_); clientInitialized_ = true; client_->setCertificateTrustChecker(certificateTrustChecker_); client_->onDataRead.connect(boost::bind(&XMLConsoleController::handleDataRead, xmlConsoleController_, _1)); client_->onDataWritten.connect(boost::bind(&XMLConsoleController::handleDataWritten, xmlConsoleController_, _1)); client_->onDisconnected.connect(boost::bind(&MainController::handleDisconnected, this, _1)); client_->onConnected.connect(boost::bind(&MainController::handleConnected, this)); client_->setSoftwareVersion(CLIENT_NAME, buildVersion); client_->getVCardManager()->onVCardChanged.connect(boost::bind(&MainController::handleVCardReceived, this, _1, _2)); presenceNotifier_ = new PresenceNotifier(client_->getStanzaChannel(), notifier_, client_->getMUCRegistry(), client_->getAvatarManager(), client_->getNickResolver(), client_->getPresenceOracle(), networkFactories_->getTimerFactory()); presenceNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); eventNotifier_ = new EventNotifier(eventController_, notifier_, client_->getAvatarManager(), client_->getNickResolver()); eventNotifier_->onNotificationActivated.connect(boost::bind(&MainController::handleNotificationClicked, this, _1)); if (certificate_ && !certificate_->isNull()) { client_->setCertificate(certificate_); } boost::shared_ptr<Presence> presence(new Presence()); presence->setShow(static_cast<StatusShow::Type>(profileSettings_->getIntSetting("lastShow", StatusShow::Online))); presence->setStatus(profileSettings_->getStringSetting("lastStatus")); statusTracker_->setRequestedPresence(presence); } else { /* In case we're in the middle of another login, make sure they don't overlap */ client_->disconnect(); } systemTrayController_->setConnecting(); if (rosterController_) { rosterController_->getWindow()->setConnecting(); } ClientOptions clientOptions = clientOptions_; bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS); clientOptions.forgetPassword = eagle; clientOptions.useTLS = eagle ? ClientOptions::RequireTLS : clientOptions_.useTLS; client_->connect(clientOptions); } void MainController::handleDisconnected(const boost::optional<ClientError>& error) { if (rosterController_) { rosterController_->getWindow()->setStreamEncryptionStatus(false); } + if (adHocManager_) { + adHocManager_->setOnline(false); + } if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } if (quitRequested_) { resetClient(); loginWindow_->quit(); } else if (error) { std::string message; std::string certificateErrorMessage; bool forceSignout = false; switch(error->getType()) { case ClientError::UnknownError: message = QT_TRANSLATE_NOOP("", "Unknown Error"); break; case ClientError::DomainNameResolveError: message = QT_TRANSLATE_NOOP("", "Unable to find server"); break; case ClientError::ConnectionError: message = QT_TRANSLATE_NOOP("", "Error connecting to server"); break; case ClientError::ConnectionReadError: message = QT_TRANSLATE_NOOP("", "Error while receiving server data"); break; case ClientError::ConnectionWriteError: message = QT_TRANSLATE_NOOP("", "Error while sending data to the server"); break; case ClientError::XMLError: message = QT_TRANSLATE_NOOP("", "Error parsing server data"); break; case ClientError::AuthenticationFailedError: message = QT_TRANSLATE_NOOP("", "Login/password invalid"); break; case ClientError::CompressionFailedError: message = QT_TRANSLATE_NOOP("", "Error while compressing stream"); break; case ClientError::ServerVerificationFailedError: message = QT_TRANSLATE_NOOP("", "Server verification failed"); break; case ClientError::NoSupportedAuthMechanismsError: message = QT_TRANSLATE_NOOP("", "Authentication mechanisms not supported"); break; case ClientError::UnexpectedElementError: message = QT_TRANSLATE_NOOP("", "Unexpected response"); break; case ClientError::ResourceBindError: message = QT_TRANSLATE_NOOP("", "Error binding resource"); break; case ClientError::SessionStartError: message = QT_TRANSLATE_NOOP("", "Error starting session"); break; case ClientError::StreamError: message = QT_TRANSLATE_NOOP("", "Stream error"); break; case ClientError::TLSError: message = QT_TRANSLATE_NOOP("", "Encryption error"); break; case ClientError::ClientCertificateLoadError: message = QT_TRANSLATE_NOOP("", "Error loading certificate (Invalid password?)"); break; case ClientError::ClientCertificateError: message = QT_TRANSLATE_NOOP("", "Certificate not authorized"); break; case ClientError::CertificateCardRemoved: message = QT_TRANSLATE_NOOP("", "Certificate card removed"); forceSignout = true; break; case ClientError::UnknownCertificateError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unknown certificate"); break; case ClientError::CertificateExpiredError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has expired"); break; case ClientError::CertificateNotYetValidError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not yet valid"); break; case ClientError::CertificateSelfSignedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is self-signed"); break; case ClientError::CertificateRejectedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been rejected"); break; case ClientError::CertificateUntrustedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate is not trusted"); break; case ClientError::InvalidCertificatePurposeError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate cannot be used for encrypting your connection"); break; case ClientError::CertificatePathLengthExceededError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate path length constraint exceeded"); break; case ClientError::InvalidCertificateSignatureError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid certificate signature"); break; case ClientError::InvalidCAError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Invalid Certificate Authority"); break; case ClientError::InvalidServerIdentityError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate does not match the host identity"); break; case ClientError::RevokedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Certificate has been revoked"); break; case ClientError::RevocationCheckFailedError: certificateErrorMessage = QT_TRANSLATE_NOOP("", "Unable to determine certificate revocation state"); break; } bool forceReconnectAfterCertificateTrust = false; if (!certificateErrorMessage.empty()) { std::vector<Certificate::ref> certificates = certificateTrustChecker_->getLastCertificateChain(); if (!certificates.empty() && loginWindow_->askUserToTrustCertificatePermanently(certificateErrorMessage, certificates)) { certificateStorage_->addCertificate(certificates[0]); forceReconnectAfterCertificateTrust = true; } else { message = QT_TRANSLATE_NOOP("", "Certificate error"); } } if (forceReconnectAfterCertificateTrust && settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { forceReconnectAfterCertificateTrust = false; forceSignout = true; message = QT_TRANSLATE_NOOP("", "Re-enter credentials and retry"); } if (forceReconnectAfterCertificateTrust) { performLoginFromCachedCredentials(); } else if (forceSignout || !rosterController_) { //hasn't been logged in yet or permanent error signOut(); loginWindow_->setMessage(message); loginWindow_->setIsLoggingIn(false); } else { logout(); if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%. To reconnect, Sign Out and provide your password again.")) % jid_.getDomain() % message); } else { if (!offlineRequested_) { setReconnectTimer(); } if (lastDisconnectError_) { message = str(format(QT_TRANSLATE_NOOP("", "Reconnect to %1% failed: %2%. Will retry in %3% seconds.")) % jid_.getDomain() % message % boost::lexical_cast<std::string>(timeBeforeNextReconnect_)); lastDisconnectError_->conclude(); } else { message = str(format(QT_TRANSLATE_NOOP("", "Disconnected from %1%: %2%.")) % jid_.getDomain() % message); } lastDisconnectError_ = boost::make_shared<ErrorEvent>(JID(jid_.getDomain()), message); eventController_->handleIncomingEvent(lastDisconnectError_); } } } else if (!rosterController_) { //hasn't been logged in yet loginWindow_->setIsLoggingIn(false); } } void MainController::setReconnectTimer() { if (timeBeforeNextReconnect_ < 0) { timeBeforeNextReconnect_ = 1; } else { timeBeforeNextReconnect_ = timeBeforeNextReconnect_ >= 150 ? 300 : timeBeforeNextReconnect_ * 2; // Randomly selected by roll of a die, as required by 3920bis } if (reconnectTimer_) { reconnectTimer_->stop(); } reconnectTimer_ = networkFactories_->getTimerFactory()->createTimer(timeBeforeNextReconnect_ * 1000); reconnectTimer_->onTick.connect(boost::bind(&MainController::reconnectAfterError, this)); reconnectTimer_->start(); } void MainController::handleCancelLoginRequest() { signOut(); } void MainController::signOut() { if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } eventController_->clear(); logout(); loginWindow_->loggedOut(); resetClient(); } void MainController::logout() { if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { purgeCachedCredentials(); } systemTrayController_->setMyStatusType(StatusShow::None); if (clientInitialized_ /*&& client_->isAvailable()*/) { client_->disconnect(); } if (rosterController_ && myStatusLooksOnline_) { rosterController_->getWindow()->setMyStatusType(StatusShow::None); rosterController_->getWindow()->setMyStatusText(""); myStatusLooksOnline_ = false; } setManagersOffline(); } void MainController::setManagersOffline() { if (chatsManager_) { chatsManager_->setOnline(false); } if (rosterController_) { rosterController_->setEnabled(false); } if (profileController_) { profileController_->setAvailable(false); } if (contactEditController_) { contactEditController_->setAvailable(false); } } void MainController::handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo> info, ErrorPayload::ref error) { if (!error) { chatsManager_->setServerDiscoInfo(info); adHocManager_->setServerDiscoInfo(info); if (info->hasFeature(DiscoInfo::BlockingCommandFeature)) { rosterController_->getWindow()->setBlockingCommandAvailable(true); rosterController_->initBlockingCommand(); } } } void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) { if (!jid.equals(jid_, JID::WithoutResource) || !vCard) { return; } std::string hash; if (!vCard->getPhoto().empty()) { hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto())); } if (hash != vCardPhotoHash_) { vCardPhotoHash_ = hash; if (client_ && client_->isAvailable()) { sendPresence(statusTracker_->getNextPresence()); } } } void MainController::handleNotificationClicked(const JID& jid) { assert(chatsManager_); if (clientInitialized_) { if (client_->getMUCRegistry()->isMUC(jid)) { uiEventStream_->send(boost::make_shared<JoinMUCUIEvent>(jid)); } else { uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(jid))); } } } void MainController::handleQuitRequest() { if (client_ && client_->isActive()) { quitRequested_ = true; client_->disconnect(); } else { resetClient(); loginWindow_->quit(); } } #define SERIALIZE_BOOL(option) result += options.option ? "1" : "0"; result += ","; #define SERIALIZE_INT(option) result += boost::lexical_cast<std::string>(options.option); result += ","; #define SERIALIZE_STRING(option) result += Base64::encode(createByteArray(options.option)); result += ","; #define SERIALIZE_SAFE_STRING(option) result += safeByteArrayToString(Base64::encode(options.option)); result += ","; #define SERIALIZE_URL(option) SERIALIZE_STRING(option.toString()) std::string MainController::serializeClientOptions(const ClientOptions& options) { std::string result; SERIALIZE_BOOL(useStreamCompression); switch (options.useTLS) { case ClientOptions::NeverUseTLS: result += "1";break; case ClientOptions::UseTLSWhenAvailable: result += "2";break; case ClientOptions::RequireTLS: result += "3";break; } result += ","; SERIALIZE_BOOL(allowPLAINWithoutTLS); SERIALIZE_BOOL(useStreamResumption); SERIALIZE_BOOL(useAcks); SERIALIZE_STRING(manualHostname); SERIALIZE_INT(manualPort); switch (options.proxyType) { case ClientOptions::NoProxy: result += "1";break; case ClientOptions::SystemConfiguredProxy: result += "2";break; case ClientOptions::SOCKS5Proxy: result += "3";break; case ClientOptions::HTTPConnectProxy: result += "4";break; } result += ","; SERIALIZE_STRING(manualProxyHostname); SERIALIZE_INT(manualProxyPort); SERIALIZE_URL(boshURL); SERIALIZE_URL(boshHTTPConnectProxyURL); SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthID); SERIALIZE_SAFE_STRING(boshHTTPConnectProxyAuthPassword); return result; } #define CHECK_PARSE_LENGTH if (i >= segments.size()) {return result;} #define PARSE_INT_RAW(defaultValue) CHECK_PARSE_LENGTH intVal = defaultValue; try {intVal = boost::lexical_cast<int>(segments[i]);} catch(const boost::bad_lexical_cast&) {};i++; #define PARSE_STRING_RAW CHECK_PARSE_LENGTH stringVal = byteArrayToString(Base64::decode(segments[i]));i++; #define PARSE_BOOL(option, defaultValue) PARSE_INT_RAW(defaultValue); result.option = (intVal == 1); #define PARSE_INT(option, defaultValue) PARSE_INT_RAW(defaultValue); result.option = intVal; #define PARSE_STRING(option) PARSE_STRING_RAW; result.option = stringVal; #define PARSE_SAFE_STRING(option) PARSE_STRING_RAW; result.option = SafeString(createSafeByteArray(stringVal)); #define PARSE_URL(option) {PARSE_STRING_RAW; result.option = URL::fromString(stringVal);} ClientOptions MainController::parseClientOptions(const std::string& optionString) { ClientOptions result; size_t i = 0; int intVal = 0; std::string stringVal; std::vector<std::string> segments = String::split(optionString, ','); PARSE_BOOL(useStreamCompression, 1); PARSE_INT_RAW(-1); switch (intVal) { case 1: result.useTLS = ClientOptions::NeverUseTLS;break; case 2: result.useTLS = ClientOptions::UseTLSWhenAvailable;break; case 3: result.useTLS = ClientOptions::RequireTLS;break; default:; } PARSE_BOOL(allowPLAINWithoutTLS, 0); PARSE_BOOL(useStreamResumption, 0); PARSE_BOOL(useAcks, 1); PARSE_STRING(manualHostname); PARSE_INT(manualPort, -1); PARSE_INT_RAW(-1); switch (intVal) { case 1: result.proxyType = ClientOptions::NoProxy;break; case 2: result.proxyType = ClientOptions::SystemConfiguredProxy;break; case 3: result.proxyType = ClientOptions::SOCKS5Proxy;break; case 4: result.proxyType = ClientOptions::HTTPConnectProxy;break; } PARSE_STRING(manualProxyHostname); PARSE_INT(manualProxyPort, -1); PARSE_URL(boshURL); PARSE_URL(boshHTTPConnectProxyURL); PARSE_SAFE_STRING(boshHTTPConnectProxyAuthID); PARSE_SAFE_STRING(boshHTTPConnectProxyAuthPassword); return result; } } diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript index e911a3a..4c71268 100644 --- a/Swift/Controllers/SConscript +++ b/Swift/Controllers/SConscript @@ -1,109 +1,110 @@ Import("env") import Version ################################################################################ # Flags ################################################################################ if env["SCONS_STAGE"] == "flags" : env["SWIFT_CONTROLLERS_FLAGS"] = { "LIBPATH": [Dir(".")], "LIBS": ["SwiftControllers"] } ################################################################################ # Build ################################################################################ if env["SCONS_STAGE"] == "build" : myenv = env.Clone() myenv.BuildVersion("BuildVersion.h", project = "swift") myenv.UseFlags(env["SWIFTEN_FLAGS"]) myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"]) myenv.StaticLibrary("SwiftControllers", [ "Chat/ChatController.cpp", "Chat/ChatControllerBase.cpp", "Chat/ChatsManager.cpp", "Chat/MUCController.cpp", "Chat/MUCSearchController.cpp", "Chat/UserSearchController.cpp", "Chat/ChatMessageParser.cpp", "ContactSuggester.cpp", "MainController.cpp", "ProfileController.cpp", "ShowProfileController.cpp", "ContactEditController.cpp", "FileTransfer/FileTransferController.cpp", "FileTransfer/FileTransferOverview.cpp", "FileTransfer/FileTransferProgressInfo.cpp", "Roster/RosterController.cpp", "Roster/RosterGroupExpandinessPersister.cpp", "Roster/ContactRosterItem.cpp", "Roster/GroupRosterItem.cpp", "Roster/RosterItem.cpp", "Roster/Roster.cpp", "Roster/RosterVCardProvider.cpp", "Roster/TableRoster.cpp", "EventWindowController.cpp", "SoundEventController.cpp", "SystemTrayController.cpp", "XMLConsoleController.cpp", "HistoryViewController.cpp", "HistoryController.cpp", "FileTransferListController.cpp", "BlockListController.cpp", "StatusTracker.cpp", "PresenceNotifier.cpp", "EventNotifier.cpp", "AdHocManager.cpp", + "AdHocController.cpp", "XMPPEvents/EventController.cpp", "UIEvents/UIEvent.cpp", "UIInterfaces/XMLConsoleWidget.cpp", "UIInterfaces/ChatListWindow.cpp", "PreviousStatusStore.cpp", "ProfileSettingsProvider.cpp", "Settings/SettingsProviderHierachy.cpp", "Settings/XMLSettingsProvider.cpp", "Storages/CertificateStorageFactory.cpp", "Storages/CertificateStorage.cpp", "Storages/CertificateFileStorage.cpp", "Storages/CertificateMemoryStorage.cpp", "Storages/AvatarFileStorage.cpp", "Storages/FileStorages.cpp", "Storages/RosterFileStorage.cpp", "Storages/CapsFileStorage.cpp", "Storages/VCardFileStorage.cpp", "StatusUtil.cpp", "Translator.cpp", "XMPPURIController.cpp", "ChatMessageSummarizer.cpp", "SettingConstants.cpp", "WhiteboardManager.cpp", "StatusCache.cpp", "HighlightAction.cpp", "HighlightEditorController.cpp", "HighlightManager.cpp", "HighlightRule.cpp", "Highlighter.cpp", "ContactsFromXMPPRoster.cpp", "ContactProvider.cpp", "Contact.cpp" ]) env.Append(UNITTEST_SOURCES = [ File("Roster/UnitTest/RosterControllerTest.cpp"), File("Roster/UnitTest/RosterTest.cpp"), File("Roster/UnitTest/LeastCommonSubsequenceTest.cpp"), File("Roster/UnitTest/TableRosterTest.cpp"), File("UnitTest/PreviousStatusStoreTest.cpp"), File("UnitTest/PresenceNotifierTest.cpp"), File("Chat/UnitTest/ChatsManagerTest.cpp"), File("Chat/UnitTest/MUCControllerTest.cpp"), File("Chat/UnitTest/ChatMessageParserTest.cpp"), File("UnitTest/MockChatWindow.cpp"), File("UnitTest/ChatMessageSummarizerTest.cpp"), File("Settings/UnitTest/SettingsProviderHierachyTest.cpp"), File("UnitTest/HighlightRuleTest.cpp"), File("UnitTest/ContactSuggesterTest.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,14 +1,18 @@ /* - * 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. */ #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,22 +1,19 @@ /* - * 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 <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> 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; }; } diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp index 5d87031..5f99dba 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.cpp +++ b/Swift/QtUI/QtAdHocCommandWindow.cpp @@ -1,143 +1,163 @@ /* - * Copyright (c) 2010-2012 Kevin Smith + * Copyright (c) 2010-2014 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include <Swift/QtUI/QtAdHocCommandWindow.h> - #include <boost/bind.hpp> #include <QBoxLayout> +#include <Swift/QtUI/QtAdHocCommandWindow.h> #include <Swift/QtUI/QtFormWidget.h> -#include <Swiften/Elements/Command.h> #include <Swift/QtUI/QtSwiftUtil.h> +#include <Swiften/Base/format.h> +#include <Swiften/Elements/Command.h> const int FormLayoutIndex = 1; namespace Swift { QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) { formWidget_ = NULL; setAttribute(Qt::WA_DeleteOnClose); command->onNextStageReceived.connect(boost::bind(&QtAdHocCommandWindow::handleNextStageReceived, this, _1)); command->onError.connect(boost::bind(&QtAdHocCommandWindow::handleError, this, _1)); command->start(); layout_ = new QBoxLayout(QBoxLayout::TopToBottom, this); layout_->setContentsMargins(0,0,0,0); layout_->setSpacing(2); label_ = new QLabel(this); label_->setTextFormat(Qt::PlainText); layout_->addWidget(label_); + + errorLabel_ = new QLabel(this); + errorLabel_->setText(QString("<b>%1</b>").arg(tr("Unable to complete the command because you have been disconnected"))); + errorLabel_->setVisible(false); + errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken); + layout_->addWidget(errorLabel_); + QWidget* buttonsWidget = new QWidget(this); layout_->addWidget(buttonsWidget); QBoxLayout* buttonsLayout = new QBoxLayout(QBoxLayout::LeftToRight, buttonsWidget); cancelButton_ = new QPushButton(tr("Cancel"), buttonsWidget); buttonsLayout->addWidget(cancelButton_); connect(cancelButton_, SIGNAL(clicked()), this, SLOT(handleCancelClicked())); backButton_ = new QPushButton(tr("Back"), buttonsWidget); buttonsLayout->addWidget(backButton_); connect(backButton_, SIGNAL(clicked()), this, SLOT(handlePrevClicked())); nextButton_ = new QPushButton(tr("Next"), buttonsWidget); buttonsLayout->addWidget(nextButton_); connect(nextButton_, SIGNAL(clicked()), this, SLOT(handleNextClicked())); completeButton_ = new QPushButton(tr("Complete"), buttonsWidget); buttonsLayout->addWidget(completeButton_); connect(completeButton_, SIGNAL(clicked()), this, SLOT(handleCompleteClicked())); nextButton_->setEnabled(false); backButton_->setEnabled(false); completeButton_->setEnabled(false); + actions_[Command::Next] = nextButton_; actions_[Command::Prev] = backButton_; actions_[Command::Complete] = completeButton_; actions_[Command::Cancel] = cancelButton_; } QtAdHocCommandWindow::~QtAdHocCommandWindow() { +} + +void QtAdHocCommandWindow::setOnline(bool online) { + if (!online) { + nextButton_->setEnabled(false); + backButton_->setEnabled(false); + completeButton_->setEnabled(false); + errorLabel_->setVisible(true); + } +} +void QtAdHocCommandWindow::closeEvent(QCloseEvent*) { + onClosing(); } void QtAdHocCommandWindow::handleCancelClicked() { command_->cancel(); close(); } void QtAdHocCommandWindow::handlePrevClicked() { command_->goBack(); } void QtAdHocCommandWindow::handleNextClicked() { command_->goNext(formWidget_ ? formWidget_->getCompletedForm() : Form::ref()); } void QtAdHocCommandWindow::handleCompleteClicked() { command_->complete(formWidget_ ? formWidget_->getCompletedForm() : Form::ref()); } void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) { QString notes; foreach (Command::Note note, command->getNotes()) { if (!notes.isEmpty()) { notes += "\n"; } QString qNote(P2QSTRING(note.note)); switch (note.type) { case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break; case Command::Note::Warn: notes += tr("Warning: %1").arg(qNote); break; case Command::Note::Info: notes += qNote; break; } } label_->setText(notes); if (command->getForm()) { setForm(command->getForm()); } else { setNoForm(notes.isEmpty()); } setAvailableActions(command); } void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) { nextButton_->setEnabled(false); backButton_->setEnabled(false); completeButton_->setEnabled(false); label_->setText(tr("Error executing command")); } void QtAdHocCommandWindow::setForm(Form::ref form) { form_ = form; delete formWidget_; formWidget_ = new QtFormWidget(form, this); layout_->insertWidget(FormLayoutIndex, formWidget_); show(); } void QtAdHocCommandWindow::setNoForm(bool andHide) { form_.reset(); delete formWidget_; formWidget_ = NULL; resize(minimumSize()); setVisible(!andHide); } typedef std::pair<Command::Action, QPushButton*> ActionButton; void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) { foreach (ActionButton pair, actions_) { OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first); if (state & OutgoingAdHocCommandSession::Present) { pair.second->show(); } else { pair.second->hide(); } if (state & OutgoingAdHocCommandSession::Enabled) { pair.second->setEnabled(true); } else { pair.second->setEnabled(false); } } } } diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h index d42a77d..0e398af 100644 --- a/Swift/QtUI/QtAdHocCommandWindow.h +++ b/Swift/QtUI/QtAdHocCommandWindow.h @@ -1,48 +1,51 @@ /* * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <QWidget> #include <QPushButton> #include <QLabel> #include <Swift/Controllers/UIInterfaces/AdHocCommandWindow.h> #include <Swiften/AdHoc/OutgoingAdHocCommandSession.h> class QBoxLayout; namespace Swift { class QtFormWidget; class QtAdHocCommandWindow : public QWidget, public AdHocCommandWindow { Q_OBJECT public: QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); virtual ~QtAdHocCommandWindow(); + virtual void setOnline(bool online); private: + void closeEvent(QCloseEvent* event); void handleNextStageReceived(Command::ref command); void handleError(ErrorPayload::ref error); void setForm(Form::ref); void setNoForm(bool andHide); void setAvailableActions(Command::ref commandResult); private slots: void handleCancelClicked(); void handlePrevClicked(); void handleNextClicked(); void handleCompleteClicked(); private: boost::shared_ptr<OutgoingAdHocCommandSession> command_; QtFormWidget* formWidget_; Form::ref form_; QLabel* label_; + QLabel* errorLabel_; QPushButton* backButton_; QPushButton* nextButton_; QPushButton* completeButton_; QPushButton* cancelButton_; std::map<Command::Action, QPushButton*> actions_; QBoxLayout* layout_; }; } diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index e5db22d..afd2a9e 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -1,179 +1,179 @@ /* - * Copyright (c) 2010-2012 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include <Swift/QtUI/QtUIFactory.h> #include <QSplitter> #include <Swift/QtUI/QtXMLConsoleWidget.h> #include <Swift/QtUI/QtChatTabs.h> #include <Swift/QtUI/QtMainWindow.h> #include <Swift/QtUI/QtLoginWindow.h> #include <Swift/QtUI/QtSystemTray.h> #include <Swift/QtUI/QtSettingsProvider.h> #include <Swift/QtUI/QtMainWindow.h> #include <Swift/QtUI/QtChatWindow.h> #include <Swift/QtUI/QtJoinMUCWindow.h> #include <Swift/QtUI/QtChatWindowFactory.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/MUCSearch/QtMUCSearchWindow.h> #include <Swift/QtUI/UserSearch/QtUserSearchWindow.h> #include <Swift/QtUI/QtProfileWindow.h> #include <Swift/QtUI/QtContactEditWindow.h> #include <Swift/QtUI/QtAdHocCommandWindow.h> #include <Swift/QtUI/QtFileTransferListWidget.h> #include <Swift/QtUI/QtHighlightEditorWidget.h> #include <Swift/QtUI/Whiteboard/QtWhiteboardWindow.h> #include <Swift/Controllers/Settings/SettingsProviderHierachy.h> #include <Swift/QtUI/QtUISettingConstants.h> #include <Swift/QtUI/QtHistoryWindow.h> #include <Swiften/Whiteboard/WhiteboardSession.h> #include <Swift/QtUI/QtSingleWindow.h> #include <Swift/QtUI/QtBlockListEditorWindow.h> namespace Swift { QtUIFactory::QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist) : settings(settings), qtOnlySettings(qtOnlySettings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), timerFactory_(timerFactory), lastMainWindow(NULL), loginWindow(NULL), statusCache(statusCache), startMinimized(startMinimized), emoticonsExist_(emoticonsExist) { chatFontSize = settings->getSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE); historyFontSize_ = settings->getSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE); } XMLConsoleWidget* QtUIFactory::createXMLConsoleWidget() { QtXMLConsoleWidget* widget = new QtXMLConsoleWidget(); tabs->addTab(widget); if (!tabs->isVisible()) { tabs->show(); } widget->show(); return widget; } HistoryWindow* QtUIFactory::createHistoryWindow(UIEventStream* uiEventStream) { QtHistoryWindow* window = new QtHistoryWindow(settings, uiEventStream); tabs->addTab(window); if (!tabs->isVisible()) { tabs->show(); } connect(window, SIGNAL(fontResized(int)), this, SLOT(handleHistoryWindowFontResized(int))); window->handleFontResized(historyFontSize_); window->show(); return window; } void QtUIFactory::handleHistoryWindowFontResized(int size) { historyFontSize_ = size; settings->storeSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE, size); } FileTransferListWidget* QtUIFactory::createFileTransferListWidget() { QtFileTransferListWidget* widget = new QtFileTransferListWidget(); tabs->addTab(widget); if (!tabs->isVisible()) { tabs->show(); } widget->show(); return widget; } MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) { lastMainWindow = new QtMainWindow(settings, eventStream, loginWindow->getMenus(), statusCache, emoticonsExist_); return lastMainWindow; } LoginWindow* QtUIFactory::createLoginWindow(UIEventStream* eventStream) { loginWindow = new QtLoginWindow(eventStream, settings, timerFactory_); if (netbookSplitter) { netbookSplitter->insertAtFront(loginWindow); } connect(systemTray, SIGNAL(clicked()), loginWindow, SLOT(toggleBringToFront())); #ifndef SWIFT_MOBILE QVariant loginWindowGeometryVariant = qtOnlySettings->getQSettings()->value("loginWindowGeometry"); if (loginWindowGeometryVariant.isValid()) { loginWindow->restoreGeometry(loginWindowGeometryVariant.toByteArray()); } connect(loginWindow, SIGNAL(geometryChanged()), this, SLOT(handleLoginWindowGeometryChanged())); if (startMinimized) loginWindow->hide(); #endif return loginWindow; } void QtUIFactory::handleLoginWindowGeometryChanged() { qtOnlySettings->getQSettings()->setValue("loginWindowGeometry", loginWindow->saveGeometry()); } EventWindow* QtUIFactory::createEventWindow() { return lastMainWindow->getEventWindow(); } ChatListWindow* QtUIFactory::createChatListWindow(UIEventStream*) { return lastMainWindow->getChatListWindow(); } MUCSearchWindow* QtUIFactory::createMUCSearchWindow() { return new QtMUCSearchWindow(); } ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eventStream) { QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream)); chatWindows.push_back(window); std::vector<QPointer<QtChatWindow> > deletions; foreach (QPointer<QtChatWindow> existingWindow, chatWindows) { if (existingWindow.isNull()) { deletions.push_back(existingWindow); } else { connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int))); connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int))); } } foreach (QPointer<QtChatWindow> deletedWindow, deletions) { chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), deletedWindow), chatWindows.end()); } connect(window, SIGNAL(fontResized(int)), this, SLOT(handleChatWindowFontResized(int))); window->handleFontResized(chatFontSize); return window; } void QtUIFactory::handleChatWindowFontResized(int size) { chatFontSize = size; settings->storeSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE, size); } UserSearchWindow* QtUIFactory::createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) { return new QtUserSearchWindow(eventStream, type, groups, qtOnlySettings); } JoinMUCWindow* QtUIFactory::createJoinMUCWindow(UIEventStream* uiEventStream) { return new QtJoinMUCWindow(uiEventStream); } ProfileWindow* QtUIFactory::createProfileWindow() { return new QtProfileWindow(); } ContactEditWindow* QtUIFactory::createContactEditWindow() { return new QtContactEditWindow(); } WhiteboardWindow* QtUIFactory::createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) { return new QtWhiteboardWindow(whiteboardSession); } HighlightEditorWidget* QtUIFactory::createHighlightEditorWidget() { return new QtHighlightEditorWidget(); } BlockListEditorWidget *QtUIFactory::createBlockListEditorWidget() { return new QtBlockListEditorWindow(); } -void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) { - new QtAdHocCommandWindow(command); +AdHocCommandWindow* QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) { + return new QtAdHocCommandWindow(command); } } diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h index 662c78e..721aa76 100644 --- a/Swift/QtUI/QtUIFactory.h +++ b/Swift/QtUI/QtUIFactory.h @@ -1,77 +1,77 @@ /* - * Copyright (c) 2010-2012 Remko Tronçon + * Copyright (c) 2010-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <QObject> #include <QPointer> #include <Swift/Controllers/UIInterfaces/UIFactory.h> class QSplitter; namespace Swift { class QtSettingsProvider; class SettingsProviderHierachy; class QtChatTabs; class QtSystemTray; class QtLoginWindow; class QtMainWindow; class QtChatTheme; class QtChatWindowFactory; class QtChatWindow; class TimerFactory; class historyWindow_; class WhiteboardSession; class StatusCache; class QtSingleWindow; class QtUIFactory : public QObject, public UIFactory { Q_OBJECT public: QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist); virtual XMLConsoleWidget* createXMLConsoleWidget(); virtual HistoryWindow* createHistoryWindow(UIEventStream*); virtual MainWindow* createMainWindow(UIEventStream* eventStream); virtual LoginWindow* createLoginWindow(UIEventStream* eventStream); virtual EventWindow* createEventWindow(); virtual ChatListWindow* createChatListWindow(UIEventStream*); virtual MUCSearchWindow* createMUCSearchWindow(); virtual ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream); virtual UserSearchWindow* createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups); virtual JoinMUCWindow* createJoinMUCWindow(UIEventStream* uiEventStream); virtual ProfileWindow* createProfileWindow(); virtual ContactEditWindow* createContactEditWindow(); virtual FileTransferListWidget* createFileTransferListWidget(); virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession); virtual HighlightEditorWidget* createHighlightEditorWidget(); virtual BlockListEditorWidget* createBlockListEditorWidget(); - virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); + virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command); private slots: void handleLoginWindowGeometryChanged(); void handleChatWindowFontResized(int); void handleHistoryWindowFontResized(int); private: SettingsProviderHierachy* settings; QtSettingsProvider* qtOnlySettings; QtChatTabs* tabs; QtSingleWindow* netbookSplitter; QtSystemTray* systemTray; QtChatWindowFactory* chatWindowFactory; TimerFactory* timerFactory_; QtMainWindow* lastMainWindow; QtLoginWindow* loginWindow; StatusCache* statusCache; std::vector<QPointer<QtChatWindow> > chatWindows; bool startMinimized; int chatFontSize; int historyFontSize_; bool emoticonsExist_; }; } |
Swift