diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 30 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.h | 1 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatsManager.cpp | 7 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 5 | ||||
-rw-r--r-- | Swift/Controllers/Chat/MUCController.h | 1 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/ChatWindow.h | 3 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/MockChatWindow.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 34 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 1 |
9 files changed, 70 insertions, 13 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index df59c2f..4bcb4c7 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -16,16 +16,17 @@ #include <Swift/Controllers/Intl.h> #include <Swiften/Base/format.h> -#include "Swiften/Base/String.h" -#include "Swiften/Client/StanzaChannel.h" -#include "Swiften/Elements/Delay.h" -#include "Swiften/Base/foreach.h" -#include "Swift/Controllers/XMPPEvents/EventController.h" -#include "Swiften/Disco/EntityCapsProvider.h" -#include "Swift/Controllers/UIInterfaces/ChatWindow.h" -#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h" -#include "Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h" -#include "Swiften/Avatars/AvatarManager.h" +#include <Swiften/Base/String.h> +#include <Swiften/Client/StanzaChannel.h> +#include <Swiften/Elements/Delay.h> +#include <Swiften/Elements/MUCInvitationPayload.h> +#include <Swiften/Base/foreach.h> +#include <Swift/Controllers/XMPPEvents/EventController.h> +#include <Swiften/Disco/EntityCapsProvider.h> +#include <Swift/Controllers/UIInterfaces/ChatWindow.h> +#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h> +#include <Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h> +#include <Swiften/Avatars/AvatarManager.h> namespace Swift { @@ -176,6 +177,10 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m std::string errorMessage = str(format(QT_TRANSLATE_NOOP("", "Couldn't send message: %1%")) % getErrorMessage(message->getPayload<ErrorPayload>())); chatWindow_->addErrorMessage(errorMessage); } + else if (messageEvent->getStanza()->getPayload<MUCInvitationPayload>()) { + handleMUCInvitation(messageEvent->getStanza()); + return; + } else { if (!messageEvent->isReadable()) { return; @@ -256,4 +261,9 @@ std::string ChatControllerBase::getErrorMessage(boost::shared_ptr<ErrorPayload> return defaultMessage; } +void ChatControllerBase::handleMUCInvitation(Message::ref message) { + MUCInvitationPayload::ref invite = message->getPayload<MUCInvitationPayload>(); + chatWindow_->addMUCInvitation(invite->getJID(), invite->getReason(), invite->getPassword()); +} + } diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h index 67bd74f..a857f3d 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.h +++ b/Swift/Controllers/Chat/ChatControllerBase.h @@ -80,6 +80,7 @@ namespace Swift { void handleAllMessagesRead(); void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error); void handleDayChangeTick(); + void handleMUCInvitation(Message::ref message); protected: JID selfJID_; diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp index 47a65a8..c0b2a7d 100644 --- a/Swift/Controllers/Chat/ChatsManager.cpp +++ b/Swift/Controllers/Chat/ChatsManager.cpp @@ -33,6 +33,7 @@ #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> #include <Swift/Controllers/ProfileSettingsProvider.h> #include <Swiften/Avatars/AvatarManager.h> +#include <Swiften/Elements/MUCInvitationPayload.h> namespace Swift { @@ -516,12 +517,13 @@ void ChatsManager::handleSearchMUCRequest() { void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) { JID jid = message->getFrom(); boost::shared_ptr<MessageEvent> event(new MessageEvent(message)); - if (!event->isReadable() && !message->getPayload<ChatState>() && !message->hasSubject()) { + bool isInvite = message->getPayload<MUCInvitationPayload>(); + if (!event->isReadable() && !message->getPayload<ChatState>() && !isInvite && !message->hasSubject()) { return; } // Try to deliver it to a MUC - if (message->getType() == Message::Groupchat || message->getType() == Message::Error) { + if (message->getType() == Message::Groupchat || message->getType() == Message::Error || (isInvite && message->getType() == Message::Normal)) { std::map<JID, MUCController*>::iterator i = mucControllers_.find(jid.toBare()); if (i != mucControllers_.end()) { i->second->handleIncomingMessage(event); @@ -562,5 +564,4 @@ void ChatsManager::handleRecentActivated(const ChatListWindow::Chat& chat) { } } - } diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index e1d02ae..87d5a16 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -74,6 +74,7 @@ MUCController::MUCController ( chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1)); chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1)); chatWindow_->onDestroyRequest.connect(boost::bind(&MUCController::handleDestroyRoomRequest, this)); + chatWindow_->onInvitePersonToThisMUCRequest.connect(boost::bind(&MUCController::handleInvitePersonToThisMUCRequest, this, _1, _2)); muc_->onJoinComplete.connect(boost::bind(&MUCController::handleJoinComplete, this, _1)); muc_->onJoinFailed.connect(boost::bind(&MUCController::handleJoinFailed, this, _1)); muc_->onOccupantJoined.connect(boost::bind(&MUCController::handleOccupantJoined, this, _1)); @@ -603,4 +604,8 @@ void MUCController::handleDestroyRoomRequest() { muc_->destroyRoom(); } +void MUCController::handleInvitePersonToThisMUCRequest(const JID& jid, const std::string& reason) { + muc_->invitePerson(jid, reason); +} + } diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h index 7a7461b..f83e2af 100644 --- a/Swift/Controllers/Chat/MUCController.h +++ b/Swift/Controllers/Chat/MUCController.h @@ -92,6 +92,7 @@ namespace Swift { void handleConfigurationFailed(ErrorPayload::ref); void handleConfigurationFormReceived(Form::ref); void handleDestroyRoomRequest(); + void handleInvitePersonToThisMUCRequest(const JID& jid, const std::string& reason); private: MUC::ref muc_; diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index df57d80..7977940 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -54,6 +54,7 @@ namespace Swift { virtual std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) = 0; virtual void setFileTransferProgress(std::string, const int percentageDone) = 0; virtual void setFileTransferStatus(std::string, const FileTransferState state, const std::string& msg = "") = 0; + virtual void addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password) = 0; virtual void setContactChatState(ChatState::ChatStateType state) = 0; virtual void setName(const std::string& name) = 0; @@ -74,6 +75,7 @@ namespace Swift { virtual void setAckState(const std::string& id, AckState state) = 0; virtual void flash() = 0; virtual void setSubject(const std::string& subject) = 0; + /** * Set an alert on the window. * @param alertText Description of alert (required). @@ -103,6 +105,7 @@ namespace Swift { boost::signal<void (const std::string&)> onChangeSubjectRequest; boost::signal<void (Form::ref)> onConfigureRequest; boost::signal<void ()> onDestroyRequest; + boost::signal<void (const JID&, const std::string& /*reason*/)> onInvitePersonToThisMUCRequest; // File transfer related boost::signal<void (std::string /* id */)> onFileTransferCancel; diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h index ad8856b..58e8698 100644 --- a/Swift/Controllers/UnitTest/MockChatWindow.h +++ b/Swift/Controllers/UnitTest/MockChatWindow.h @@ -48,6 +48,7 @@ namespace Swift { void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {} void setSubject(const std::string& /*subject*/) {} virtual void showRoomConfigurationForm(Form::ref) {} + virtual void addMUCInvitation(const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/) {}; boost::signal<void ()> onClosed; boost::signal<void ()> onAllMessagesRead; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 50fe984..df78767 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -21,6 +21,7 @@ #include "SwifTools/TabComplete.h" #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/SendFileUIEvent.h> +#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h> #include "QtFileTransferJSBridge.h" #include <boost/cstdint.hpp> @@ -28,6 +29,7 @@ #include <boost/lexical_cast.hpp> #include <QLabel> +#include <QMessageBox> #include <QInputDialog> #include <QApplication> #include <QBoxLayout> @@ -702,6 +704,7 @@ void QtChatWindow::handleActionButtonClicked() { QAction* changeSubject = contextMenu.addAction(tr("Change subject")); QAction* configure = contextMenu.addAction(tr("Configure room")); QAction* destroy = contextMenu.addAction(tr("Destroy room")); + QAction* invite = contextMenu.addAction(tr("Invite person to this room")); QAction* result = contextMenu.exec(QCursor::pos()); if (result == changeSubject) { bool ok; @@ -716,6 +719,13 @@ void QtChatWindow::handleActionButtonClicked() { else if (result == destroy) { onDestroyRequest(); } + else if (result == invite) { + bool ok; + QString jid = QInputDialog::getText(this, tr("Enter person's address"), tr("Address:"), QLineEdit::Normal, "", &ok); + if (ok) { + onInvitePersonToThisMUCRequest(JID(Q2PSTRING(jid)), ""); + } + } } void QtChatWindow::showRoomConfigurationForm(Form::ref form) { @@ -726,4 +736,28 @@ void QtChatWindow::showRoomConfigurationForm(Form::ref form) { mucConfigurationWindow->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1)); } +void QtChatWindow::addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password) { + bool accepted = false; + QMessageBox msgBox; + msgBox.setText(QString("You have been invited to the room %1 by %2.").arg(P2QSTRING(jid.toString())).arg(contact_)); + QString reasonString; + if (!reason.empty()) { + reasonString = QString("\"%1\"").arg(P2QSTRING(reason)); + } + msgBox.setInformativeText(QString("Accept invitation from %1 to enter %2?\n%3").arg(contact_).arg(P2QSTRING(jid.toString())).arg(reasonString)); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + int ret = msgBox.exec(); + switch (ret) { + case QMessageBox::Yes: + accepted = true; + break; + default: + break; + } + if (accepted) { + eventStream_->send(boost::make_shared<JoinMUCUIEvent>(jid)); + } +} + } diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index b011427..8dfe767 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -72,6 +72,7 @@ namespace Swift { virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions); void setSubject(const std::string& subject); void showRoomConfigurationForm(Form::ref); + void addMUCInvitation(const JID& jid, const std::string& reason, const std::string& password); public slots: void handleChangeSplitterState(QByteArray state); |