From 1cf2023bc496a4abe5a98138401295b45a0b899a Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 15 Apr 2010 22:16:37 +0100 Subject: Normalise muc joining, allow it from bookmark list. Resolves: #320 diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index e3d3e64..a490a3f 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -14,6 +14,7 @@ #include "Swift/Controllers/EventController.h" #include "Swift/Controllers/Chat/MUCController.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" +#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" #include "Swift/Controllers/UIInterfaces/ChatListWindowFactory.h" #include "Swiften/Presence/PresenceSender.h" #include "Swiften/Elements/ChatState.h" @@ -58,8 +59,7 @@ void ChatsManager::handleMUCBookmarkAdded(boost::shared_ptr bookmar std::map::iterator it = mucControllers_.find(bookmark->getRoom()); if (it == mucControllers_.end() && bookmark->getAutojoin()) { //FIXME: need vcard stuff here to get a nick - String nick = bookmark->getNick() ? bookmark->getNick().get() : "Swift user"; - handleJoinMUCRequest(bookmark->getRoom(), nick); + handleJoinMUCRequest(bookmark->getRoom(), bookmark->getNick()); } chatListWindow_->addMUCBookmark(bookmark); } @@ -84,6 +84,10 @@ void ChatsManager::handleUIEvent(boost::shared_ptr event) { if (chatEvent) { handleChatRequest(chatEvent->getContact()); } + boost::shared_ptr joinMUCEvent = boost::dynamic_pointer_cast(event); + if (joinMUCEvent) { + handleJoinMUCRequest(joinMUCEvent->getJID(), joinMUCEvent->getNick()); + } } /** @@ -115,7 +119,7 @@ void ChatsManager::setAvatarManager(AvatarManager* avatarManager) { // { // boost::shared_ptr event = boost::dynamic_pointer_cast(rawEvent); // if (event != NULL) { -// handleJoinMUCRequest(event->getRoom(), event->getNick()); +// handleJoinMUCRequest(); // } // } // } @@ -191,11 +195,12 @@ void ChatsManager::rebindControllerJID(const JID& from, const JID& to) { chatControllers_[to]->setToJID(to); } -void ChatsManager::handleJoinMUCRequest(const JID &muc, const String &nick) { +void ChatsManager::handleJoinMUCRequest(const JID &muc, const boost::optional& nickMaybe) { std::map::iterator it = mucControllers_.find(muc); if (it != mucControllers_.end()) { //FIXME: What's correct behaviour here? } else { + String nick = nickMaybe ? nickMaybe.get() : "Swift user"; MUCController* controller = new MUCController(jid_, muc, nick, stanzaChannel_, presenceSender_, iqRouter_, chatWindowFactory_, treeWidgetFactory_, presenceOracle_, avatarManager_, uiEventStream_); mucControllers_[muc] = controller; controller->setAvailableServerFeatures(serverDiscoInfo_); diff --git a/Swift/Controllers/Chat/ChatsManager.h b/Swift/Controllers/Chat/ChatsManager.h index 6dc598e..df49b0a 100644 --- a/Swift/Controllers/Chat/ChatsManager.h +++ b/Swift/Controllers/Chat/ChatsManager.h @@ -44,8 +44,8 @@ namespace Swift { void setServerDiscoInfo(boost::shared_ptr info); void handleIncomingMessage(boost::shared_ptr message); void handleChatRequest(const String& contact); - void handleJoinMUCRequest(const JID& muc, const String& nick); private: + void handleJoinMUCRequest(const JID& muc, const boost::optional& nick); void rebindControllerJID(const JID& from, const JID& to); void handlePresenceChange(boost::shared_ptr newPresence, boost::shared_ptr lastPresence); void handleUIEvent(boost::shared_ptr event); diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index e8c6c94..341fc09 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -21,8 +21,8 @@ #include "Swift/Controllers/UIInterfaces/LoginWindow.h" #include "Swift/Controllers/UIInterfaces/LoginWindowFactory.h" #include "Swift/Controllers/UIInterfaces/EventWindowFactory.h" -#include "Swift/Controllers/MainWindow.h" -#include "Swift/Controllers/MainWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/MainWindow.h" +#include "Swift/Controllers/UIInterfaces/MainWindowFactory.h" #include "Swift/Controllers/Chat/MUCController.h" #include "Swift/Controllers/NickResolver.h" #include "Swift/Controllers/ProfileSettingsProvider.h" @@ -185,7 +185,6 @@ void MainController::handleConnected() { client_->onMessageReceived.connect(boost::bind(&ChatsManager::handleIncomingMessage, chatsManager_, _1)); chatsManager_->setAvatarManager(avatarManager_); rosterController_->onStartChatRequest.connect(boost::bind(&ChatsManager::handleChatRequest, chatsManager_, _1)); - rosterController_->onJoinMUCRequest.connect(boost::bind(&ChatsManager::handleJoinMUCRequest, chatsManager_, _1, _2)); avatarManager_->setMUCRegistry(chatsManager_); diff --git a/Swift/Controllers/MainWindow.h b/Swift/Controllers/MainWindow.h deleted file mode 100644 index 0f68af5..0000000 --- a/Swift/Controllers/MainWindow.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_MainWindow_H -#define SWIFTEN_MainWindow_H - -#include "Swiften/Base/String.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Elements/StatusShow.h" - -#include -#include - -namespace Swift { - class TreeWidget; - - class MainWindow { - public: - virtual ~MainWindow() {}; - virtual TreeWidget* getTreeWidget() = 0; - virtual void setMyName(const String& name) = 0; - virtual void setMyAvatarPath(const String& path) = 0; - virtual void setMyStatusText(const String& status) = 0; - virtual void setMyStatusType(StatusShow::Type type) = 0; - - boost::signal onStartChatRequest; - boost::signal onJoinMUCRequest; - boost::signal onChangeStatusRequest; - boost::signal onShowOfflineToggled; - boost::signal onSignOutRequest; - }; -} -#endif - diff --git a/Swift/Controllers/MainWindowFactory.h b/Swift/Controllers/MainWindowFactory.h deleted file mode 100644 index c5cdfef..0000000 --- a/Swift/Controllers/MainWindowFactory.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2010 Kevin Smith - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. - */ - -#ifndef SWIFTEN_MainWindowFactory_H -#define SWIFTEN_MainWindowFactory_H - -#include "Swiften/JID/JID.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" - -namespace Swift { - class MainWindow; - - class MainWindowFactory { - public: - virtual ~MainWindowFactory() {}; - /** - * Transfers ownership of result. - */ - virtual MainWindow* createMainWindow(UIEventStream* eventStream) = 0; - - }; -} -#endif - diff --git a/Swift/Controllers/RosterController.cpp b/Swift/Controllers/RosterController.cpp index 17fd2e9..3bbc9f8 100644 --- a/Swift/Controllers/RosterController.cpp +++ b/Swift/Controllers/RosterController.cpp @@ -9,8 +9,8 @@ #include #include "Swiften/Base/foreach.h" -#include "Swift/Controllers/MainWindow.h" -#include "Swift/Controllers/MainWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/MainWindow.h" +#include "Swift/Controllers/UIInterfaces/MainWindowFactory.h" #include "Swift/Controllers/NickResolver.h" #include "Swiften/Queries/Requests/GetRosterRequest.h" #include "Swiften/Queries/Requests/SetRosterRequest.h" @@ -44,7 +44,6 @@ RosterController::RosterController(const JID& jid, boost::shared_ptr eventController_ = eventController; roster_->addFilter(offlineFilter_); - joinMUCConnection_ = mainWindow_->onJoinMUCRequest.connect(boost::bind(&RosterController::handleJoinMUCRequest, this, _1, _2)); changeStatusConnection_ = mainWindow_->onChangeStatusRequest.connect(boost::bind(&RosterController::handleChangeStatusRequest, this, _1, _2)); showOfflineConnection_ = mainWindow_->onShowOfflineToggled.connect(boost::bind(&RosterController::handleShowOfflineToggled, this, _1)); signOutConnection_ = mainWindow_->onSignOutRequest.connect(boost::bind(boost::ref(onSignOutRequest))); @@ -233,8 +232,4 @@ void RosterController::handleAvatarChanged(const JID& jid, const String&) { } } -void RosterController::handleJoinMUCRequest(const JID &muc, const String &nick) { - onJoinMUCRequest(JID(muc), nick); -} - } diff --git a/Swift/Controllers/RosterController.h b/Swift/Controllers/RosterController.h index d5a97a9..e9561bb 100644 --- a/Swift/Controllers/RosterController.h +++ b/Swift/Controllers/RosterController.h @@ -42,7 +42,6 @@ namespace Swift { void setAvatarManager(AvatarManager* avatarManager); void setNickResolver(NickResolver* nickResolver); boost::signal onStartChatRequest; - boost::signal onJoinMUCRequest; boost::signal onChangeStatusRequest; boost::signal onSignOutRequest; void handleAvatarChanged(const JID& jid, const String& hash); @@ -52,7 +51,6 @@ namespace Swift { void handleOnJIDRemoved(const JID &jid); void handleOnJIDUpdated(const JID &jid, const String& oldName, const std::vector oldGroups); void handleStartChatRequest(const JID& contact); - void handleJoinMUCRequest(const JID &muc, const String &nick); void handleUserAction(boost::shared_ptr action); void handleChangeStatusRequest(StatusShow::Type show, const String &statusText); void handleShowOfflineToggled(bool state); @@ -74,7 +72,6 @@ namespace Swift { PresenceOracle* presenceOracle_; EventController* eventController_; IQRouter* iqRouter_; - boost::bsignals::scoped_connection joinMUCConnection_; boost::bsignals::scoped_connection changeStatusConnection_; boost::bsignals::scoped_connection showOfflineConnection_; boost::bsignals::scoped_connection signOutConnection_; diff --git a/Swift/Controllers/UIEvents/JoinMUCUIEvent.h b/Swift/Controllers/UIEvents/JoinMUCUIEvent.h index 0bdfef1..4ebf1f1 100644 --- a/Swift/Controllers/UIEvents/JoinMUCUIEvent.h +++ b/Swift/Controllers/UIEvents/JoinMUCUIEvent.h @@ -4,10 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -//Not used yet. - #pragma once +#include #include "Swiften/Base/String.h" #include "Swift/Controllers/UIEvents/UIEvent.h" @@ -15,11 +14,11 @@ namespace Swift { class JoinMUCUIEvent : public UIEvent { public: - JoinMUCUIEvent(const JID& jid, const String& contact) : jid_(jid), contact_(contact) {}; - String getContact() {return contact_;}; + JoinMUCUIEvent(const JID& jid, const boost::optional& nick) : jid_(jid), nick_(nick) {}; + boost::optional getNick() {return nick_;}; JID getJID() {return jid_;}; private: - String contact_; JID jid_; + boost::optional nick_; }; } diff --git a/Swift/Controllers/UIInterfaces/MainWindow.h b/Swift/Controllers/UIInterfaces/MainWindow.h new file mode 100644 index 0000000..ce8b877 --- /dev/null +++ b/Swift/Controllers/UIInterfaces/MainWindow.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#ifndef SWIFTEN_MainWindow_H +#define SWIFTEN_MainWindow_H + +#include "Swiften/Base/String.h" +#include "Swiften/JID/JID.h" +#include "Swiften/Elements/StatusShow.h" + +#include +#include + +namespace Swift { + class TreeWidget; + + class MainWindow { + public: + virtual ~MainWindow() {}; + virtual TreeWidget* getTreeWidget() = 0; + virtual void setMyName(const String& name) = 0; + virtual void setMyAvatarPath(const String& path) = 0; + virtual void setMyStatusText(const String& status) = 0; + virtual void setMyStatusType(StatusShow::Type type) = 0; + + boost::signal onStartChatRequest; + boost::signal onChangeStatusRequest; + boost::signal onShowOfflineToggled; + boost::signal onSignOutRequest; + }; +} +#endif + diff --git a/Swift/Controllers/UIInterfaces/MainWindowFactory.h b/Swift/Controllers/UIInterfaces/MainWindowFactory.h new file mode 100644 index 0000000..c5cdfef --- /dev/null +++ b/Swift/Controllers/UIInterfaces/MainWindowFactory.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#ifndef SWIFTEN_MainWindowFactory_H +#define SWIFTEN_MainWindowFactory_H + +#include "Swiften/JID/JID.h" +#include "Swift/Controllers/UIEvents/UIEventStream.h" + +namespace Swift { + class MainWindow; + + class MainWindowFactory { + public: + virtual ~MainWindowFactory() {}; + /** + * Transfers ownership of result. + */ + virtual MainWindow* createMainWindow(UIEventStream* eventStream) = 0; + + }; +} +#endif + diff --git a/Swift/Controllers/UnitTest/MockMainWindow.h b/Swift/Controllers/UnitTest/MockMainWindow.h index f20c088..f6134da 100644 --- a/Swift/Controllers/UnitTest/MockMainWindow.h +++ b/Swift/Controllers/UnitTest/MockMainWindow.h @@ -6,7 +6,7 @@ #pragma once -#include "Swift/Controllers/MainWindow.h" +#include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "Swiften/Roster/TreeWidget.h" namespace Swift { diff --git a/Swift/Controllers/UnitTest/MockMainWindowFactory.h b/Swift/Controllers/UnitTest/MockMainWindowFactory.h index 3cee5ca..2f0559b 100644 --- a/Swift/Controllers/UnitTest/MockMainWindowFactory.h +++ b/Swift/Controllers/UnitTest/MockMainWindowFactory.h @@ -6,7 +6,7 @@ #pragma once -#include "Swift/Controllers/MainWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/MainWindowFactory.h" #include "Swiften/Roster/TreeWidgetFactory.h" #include "Swift/Controllers/UnitTest/MockMainWindow.h" diff --git a/Swift/Controllers/XMPPRosterController.cpp b/Swift/Controllers/XMPPRosterController.cpp index e5cf0a3..a7e634a 100644 --- a/Swift/Controllers/XMPPRosterController.cpp +++ b/Swift/Controllers/XMPPRosterController.cpp @@ -9,8 +9,6 @@ #include #include "Swiften/Base/foreach.h" -#include "Swift/Controllers/MainWindow.h" -#include "Swift/Controllers/MainWindowFactory.h" #include "Swiften/Elements/RosterItemPayload.h" #include "Swiften/Queries/IQRouter.h" #include "Swiften/Queries/Requests/GetRosterRequest.h" diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp index 1b01c64..40ed1b7 100644 --- a/Swift/QtUI/ChatList/ChatListModel.cpp +++ b/Swift/QtUI/ChatList/ChatListModel.cpp @@ -41,8 +41,13 @@ int ChatListModel::columnCount(const QModelIndex& /*parent*/) const { return 1; } +ChatListItem* ChatListModel::getItemForIndex(const QModelIndex& index) const { + return index.isValid() ? static_cast(index.internalPointer()) : NULL; +} + QVariant ChatListModel::data(const QModelIndex& index, int role) const { - return index.isValid() ? static_cast(index.internalPointer())->data(role) : QVariant(); + ChatListItem* item = getItemForIndex(index); + return item ? item->data(role) : QVariant(); } QModelIndex ChatListModel::index(int row, int column, const QModelIndex & parent) const { diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h index f7cd137..71849cc 100644 --- a/Swift/QtUI/ChatList/ChatListModel.h +++ b/Swift/QtUI/ChatList/ChatListModel.h @@ -27,6 +27,7 @@ namespace Swift { QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; QModelIndex parent(const QModelIndex& index) const; int rowCount(const QModelIndex& parent = QModelIndex()) const; + ChatListItem* getItemForIndex(const QModelIndex& index) const; private: ChatListGroupItem* mucBookmarks_; ChatListGroupItem* root_; diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp index c6c8e64..793d89a 100644 --- a/Swift/QtUI/ChatList/QtChatListWindow.cpp +++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp @@ -5,6 +5,8 @@ */ #include "Swift/QtUI/ChatList/QtChatListWindow.h" +#include "Swift/QtUI/ChatList/ChatListMUCItem.h" +#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" namespace Swift { @@ -29,8 +31,13 @@ QtChatListWindow::~QtChatListWindow() { delete delegate_; } -void QtChatListWindow::handleItemActivated(const QModelIndex& item) { - +void QtChatListWindow::handleItemActivated(const QModelIndex& index) { + ChatListItem* item = model_->getItemForIndex(index); + ChatListMUCItem* mucItem = dynamic_cast(item); + if (mucItem) { + boost::shared_ptr event(new JoinMUCUIEvent(mucItem->getBookmark()->getRoom(), mucItem->getBookmark()->getNick())); + eventStream_->send(event); + } } void QtChatListWindow::addMUCBookmark(boost::shared_ptr bookmark) { diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h index 654498d..c7b35c7 100644 --- a/Swift/QtUI/QtLoginWindow.h +++ b/Swift/QtUI/QtLoginWindow.h @@ -17,7 +17,7 @@ #include "Swift/Controllers/UIInterfaces/LoginWindow.h" #include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/MainWindow.h" +#include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "QtAboutWidget.h" class QLabel; diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index 116f52e..c947ae7 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -6,6 +6,8 @@ #include "QtMainWindow.h" +#include + #include #include #include @@ -24,6 +26,7 @@ #include "Roster/QtTreeWidgetFactory.h" #include "Roster/QtTreeWidget.h" #include "Swift/Controllers/UIEvents/AddContactUIEvent.h" +#include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" namespace Swift { @@ -137,7 +140,9 @@ void QtMainWindow::handleJoinMUCAction() { } void QtMainWindow::handleJoinMUCDialogComplete(const JID& muc, const QString& nick) { - onJoinMUCRequest(muc, Q2PSTRING(nick)); + boost::optional maybeNick(Q2PSTRING(nick)); + boost::shared_ptr event(new JoinMUCUIEvent(muc, maybeNick)); + uiEventStream_->send(event); } void QtMainWindow::handleStatusChanged(StatusShow::Type showType, const QString &statusMessage) { diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h index f846e27..45dbda6 100644 --- a/Swift/QtUI/QtMainWindow.h +++ b/Swift/QtUI/QtMainWindow.h @@ -9,7 +9,7 @@ #include #include -#include "Swift/Controllers/MainWindow.h" +#include "Swift/Controllers/UIInterfaces/MainWindow.h" #include "Swift/QtUI/QtRosterHeader.h" #include "Swift/QtUI/EventViewer/QtEventWindow.h" #include "Swift/QtUI/ChatList/QtChatListWindow.h" diff --git a/Swift/QtUI/QtMainWindowFactory.h b/Swift/QtUI/QtMainWindowFactory.h index 11414bb..c16d229 100644 --- a/Swift/QtUI/QtMainWindowFactory.h +++ b/Swift/QtUI/QtMainWindowFactory.h @@ -7,7 +7,7 @@ #ifndef SWIFT_QtMainWindowFactory_H #define SWIFT_QtMainWindowFactory_H -#include "Swift/Controllers/MainWindowFactory.h" +#include "Swift/Controllers/UIInterfaces/MainWindowFactory.h" namespace Swift { class QtTreeWidgetFactory; -- cgit v0.10.2-6-g49f6