summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-09-27 16:13:56 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-09-27 16:38:45 (GMT)
commit41854ebf8c3376d6ee430efe3a9fdd25610bb2f5 (patch)
tree81e918793afb16accb29af46ccd99eefa204930c /Swift
parent24e53876500f0f5497a84b239d9350676e95751a (diff)
downloadswift-41854ebf8c3376d6ee430efe3a9fdd25610bb2f5.zip
swift-41854ebf8c3376d6ee430efe3a9fdd25610bb2f5.tar.bz2
Allow room configuration.
Resolves: #989
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/Chat/ChatControllerBase.h2
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp23
-rw-r--r--Swift/Controllers/Chat/MUCController.h4
-rw-r--r--Swift/Controllers/UIInterfaces/ChatWindow.h10
-rw-r--r--Swift/Controllers/UnitTest/MockChatWindow.h1
-rw-r--r--Swift/QtUI/QtChatWindow.cpp23
-rw-r--r--Swift/QtUI/QtChatWindow.h13
-rw-r--r--Swift/QtUI/QtMUCConfigurationWindow.cpp56
-rw-r--r--Swift/QtUI/QtMUCConfigurationWindow.h34
-rw-r--r--Swift/QtUI/SConscript1
10 files changed, 149 insertions, 18 deletions
diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h
index 79d376c..67bd74f 100644
--- a/Swift/Controllers/Chat/ChatControllerBase.h
+++ b/Swift/Controllers/Chat/ChatControllerBase.h
@@ -70,6 +70,7 @@ namespace Swift {
virtual boost::optional<boost::posix_time::ptime> getMessageTimestamp(boost::shared_ptr<Message>) const = 0;
virtual void dayTicked() {};
virtual void handleBareJIDCapsChanged(const JID& jid) = 0;
+ std::string getErrorMessage(boost::shared_ptr<ErrorPayload>);
private:
IDGenerator idGenerator_;
@@ -78,7 +79,6 @@ namespace Swift {
void handleSendMessageRequest(const std::string &body, bool isCorrectionMessage);
void handleAllMessagesRead();
void handleSecurityLabelsCatalogResponse(boost::shared_ptr<SecurityLabelsCatalog>, ErrorPayload::ref error);
- std::string getErrorMessage(boost::shared_ptr<ErrorPayload>);
void handleDayChangeTick();
protected:
diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp
index 178f4b6..56cc639 100644
--- a/Swift/Controllers/Chat/MUCController.cpp
+++ b/Swift/Controllers/Chat/MUCController.cpp
@@ -72,13 +72,15 @@ MUCController::MUCController (
chatWindow_->onOccupantSelectionChanged.connect(boost::bind(&MUCController::handleWindowOccupantSelectionChanged, this, _1));
chatWindow_->onOccupantActionSelected.connect(boost::bind(&MUCController::handleActionRequestedOnOccupant, this, _1, _2));
chatWindow_->onChangeSubjectRequest.connect(boost::bind(&MUCController::handleChangeSubjectRequest, this, _1));
- chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this));
+ chatWindow_->onConfigureRequest.connect(boost::bind(&MUCController::handleConfigureRequest, this, _1));
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));
muc_->onOccupantPresenceChange.connect(boost::bind(&MUCController::handleOccupantPresenceChange, this, _1));
muc_->onOccupantLeft.connect(boost::bind(&MUCController::handleOccupantLeft, this, _1, _2, _3));
muc_->onOccupantRoleChanged.connect(boost::bind(&MUCController::handleOccupantRoleChanged, this, _1, _2, _3));
+ muc_->onConfigurationFailed.connect(boost::bind(&MUCController::handleConfigurationFailed, this, _1));
+ muc_->onConfigurationFormReceived.connect(boost::bind(&MUCController::handleConfigurationFormReceived, this, _1));
if (timerFactory) {
loginCheckTimer_ = boost::shared_ptr<Timer>(timerFactory->createTimer(MUC_JOIN_WARNING_TIMEOUT_MILLISECONDS));
loginCheckTimer_->onTick.connect(boost::bind(&MUCController::handleJoinTimeoutTick, this));
@@ -577,8 +579,23 @@ void MUCController::handleChangeSubjectRequest(const std::string& subject) {
muc_->changeSubject(subject);
}
-void MUCController::handleConfigureRequest() {
- muc_->requestConfigurationForm();
+void MUCController::handleConfigureRequest(Form::ref form) {
+ if (form) {
+ muc_->configureRoom(form);
+ }
+ else {
+ muc_->requestConfigurationForm();
+ }
+}
+
+void MUCController::handleConfigurationFailed(ErrorPayload::ref error) {
+ std::string errorMessage = getErrorMessage(error);
+ errorMessage = str(format(QT_TRANSLATE_NOOP("", "Room configuration failed: %1%.")) % errorMessage);
+ chatWindow_->addErrorMessage(errorMessage);
+}
+
+void MUCController::handleConfigurationFormReceived(Form::ref form) {
+ chatWindow_->showRoomConfigurationForm(form);
}
}
diff --git a/Swift/Controllers/Chat/MUCController.h b/Swift/Controllers/Chat/MUCController.h
index 08a3fc3..4be1488 100644
--- a/Swift/Controllers/Chat/MUCController.h
+++ b/Swift/Controllers/Chat/MUCController.h
@@ -88,7 +88,9 @@ namespace Swift {
void dayTicked() {lastWasPresence_ = false;}
void processUserPart();
void handleBareJIDCapsChanged(const JID& jid);
- void handleConfigureRequest();
+ void handleConfigureRequest(Form::ref);
+ void handleConfigurationFailed(ErrorPayload::ref);
+ void handleConfigurationFormReceived(Form::ref);
private:
MUC::ref muc_;
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h
index 7004324..75c92d3 100644
--- a/Swift/Controllers/UIInterfaces/ChatWindow.h
+++ b/Swift/Controllers/UIInterfaces/ChatWindow.h
@@ -14,8 +14,10 @@
#include <vector>
#include <string>
-#include "Swiften/Elements/SecurityLabelsCatalog.h"
-#include "Swiften/Elements/ChatState.h"
+#include <Swiften/Elements/SecurityLabelsCatalog.h>
+#include <Swiften/Elements/ChatState.h>
+#include <Swiften/Elements/Form.h>
+
namespace Swift {
class AvatarManager;
@@ -87,6 +89,8 @@ namespace Swift {
* Actions that can be performed on the selected occupant.
*/
virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions) = 0;
+
+ virtual void showRoomConfigurationForm(Form::ref) = 0;
boost::signal<void ()> onClosed;
boost::signal<void ()> onAllMessagesRead;
boost::signal<void (const std::string&, bool isCorrection)> onSendMessageRequest;
@@ -97,7 +101,7 @@ namespace Swift {
boost::signal<void (ContactRosterItem*)> onOccupantSelectionChanged;
boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
boost::signal<void (const std::string&)> onChangeSubjectRequest;
- boost::signal<void ()> onConfigureRequest;
+ boost::signal<void (Form::ref)> onConfigureRequest;
// 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 143e281..ad8856b 100644
--- a/Swift/Controllers/UnitTest/MockChatWindow.h
+++ b/Swift/Controllers/UnitTest/MockChatWindow.h
@@ -47,6 +47,7 @@ namespace Swift {
virtual void setCorrectionEnabled(Tristate /*enabled*/) {}
void setAvailableOccupantActions(const std::vector<OccupantAction>&/* actions*/) {}
void setSubject(const std::string& /*subject*/) {}
+ virtual void showRoomConfigurationForm(Form::ref) {}
boost::signal<void ()> onClosed;
boost::signal<void ()> onAllMessagesRead;
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 2e3a225..1576880 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -162,6 +162,9 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
QtChatWindow::~QtChatWindow() {
delete fileTransferJS;
+ if (mucConfigurationWindow) {
+ delete mucConfigurationWindow.data();
+ }
}
@@ -364,7 +367,9 @@ void QtChatWindow::qAppFocusChanged(QWidget* /*old*/, QWidget* /*now*/) {
void QtChatWindow::setInputEnabled(bool enabled) {
inputEnabled_ = enabled;
-// input_->setEnabled(enabled);
+ if (!enabled && mucConfigurationWindow) {
+ delete mucConfigurationWindow.data();
+ }
}
void QtChatWindow::showEvent(QShowEvent* event) {
@@ -694,7 +699,7 @@ void QtChatWindow::setSubject(const std::string& subject) {
void QtChatWindow::handleActionButtonClicked() {
QMenu contextMenu;
QAction* changeSubject = contextMenu.addAction(tr("Change subject"));
- //QAction* configure = contextMenu.addAction(tr("Configure room"));
+ QAction* configure = contextMenu.addAction(tr("Configure room"));
QAction* result = contextMenu.exec(QCursor::pos());
if (result == changeSubject) {
bool ok;
@@ -703,9 +708,17 @@ void QtChatWindow::handleActionButtonClicked() {
onChangeSubjectRequest(Q2PSTRING(subject));
}
}
- //else if (result == configure) {
- // onConfigureRequest();
- //}
+ else if (result == configure) {
+ onConfigureRequest(Form::ref());
+ }
+}
+
+void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
+ if (mucConfigurationWindow) {
+ delete mucConfigurationWindow.data();
+ }
+ mucConfigurationWindow = new QtMUCConfigurationWindow(form);
+ mucConfigurationWindow->onFormComplete.connect(boost::bind(boost::ref(onConfigureRequest), _1));
}
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index b8fa478..b011427 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -6,15 +6,17 @@
#pragma once
-#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+#include <Swift/QtUI/QtMUCConfigurationWindow.h>
-#include "QtTabbable.h"
+#include <QtTabbable.h>
-#include "SwifTools/LastLineTracker.h"
+#include <SwifTools/LastLineTracker.h>
-#include "Swiften/Base/IDGenerator.h"
+#include <Swiften/Base/IDGenerator.h>
#include <map>
+#include <QPointer>
class QTextEdit;
class QLineEdit;
@@ -69,6 +71,7 @@ namespace Swift {
QByteArray getSplitterState();
virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions);
void setSubject(const std::string& subject);
+ void showRoomConfigurationForm(Form::ref);
public slots:
void handleChangeSplitterState(QByteArray state);
@@ -147,8 +150,8 @@ namespace Swift {
QSplitter *logRosterSplitter_;
Tristate correctionEnabled_;
QString alertStyleSheet_;
-
std::map<QString, QString> descriptions;
QtFileTransferJSBridge* fileTransferJS;
+ QPointer<QtMUCConfigurationWindow> mucConfigurationWindow;
};
}
diff --git a/Swift/QtUI/QtMUCConfigurationWindow.cpp b/Swift/QtUI/QtMUCConfigurationWindow.cpp
new file mode 100644
index 0000000..e6be9b7
--- /dev/null
+++ b/Swift/QtUI/QtMUCConfigurationWindow.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtMUCConfigurationWindow.h>
+
+#include <boost/bind.hpp>
+#include <QBoxLayout>
+#include <Swift/QtUI/QtFormWidget.h>
+
+namespace Swift {
+QtMUCConfigurationWindow::QtMUCConfigurationWindow(Form::ref form) {
+
+ setAttribute(Qt::WA_DeleteOnClose);
+
+ QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ layout->setContentsMargins(0,0,0,0);
+ layout->setSpacing(2);
+ QLabel* label = new QLabel(this);
+ label->setText(tr("Room configuration"));
+ layout->addWidget(label);
+
+ formWidget_ = NULL;
+ formWidget_ = new QtFormWidget(form, this);
+ layout->addWidget(formWidget_);
+
+ 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()));
+ okButton_ = new QPushButton(tr("OK"), buttonsWidget);
+ buttonsLayout->addWidget(okButton_);
+ connect(okButton_, SIGNAL(clicked()), this, SLOT(handleOKClicked()));
+ show();
+}
+
+QtMUCConfigurationWindow::~QtMUCConfigurationWindow() {
+
+}
+
+void QtMUCConfigurationWindow::handleCancelClicked() {
+ close();
+}
+
+void QtMUCConfigurationWindow::handleOKClicked() {
+ onFormComplete(formWidget_->getCompletedForm());
+ close();
+}
+
+
+}
diff --git a/Swift/QtUI/QtMUCConfigurationWindow.h b/Swift/QtUI/QtMUCConfigurationWindow.h
new file mode 100644
index 0000000..2be126b
--- /dev/null
+++ b/Swift/QtUI/QtMUCConfigurationWindow.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 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 <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Elements/Form.h>
+
+class QBoxLayout;
+
+namespace Swift {
+ class QtFormWidget;
+ class QtMUCConfigurationWindow : public QWidget {
+ Q_OBJECT
+ public:
+ QtMUCConfigurationWindow(Form::ref form);
+ virtual ~QtMUCConfigurationWindow();
+ boost::signal<void (Form::ref)> onFormComplete;
+ private slots:
+ void handleCancelClicked();
+ void handleOKClicked();
+ private:
+ QtFormWidget* formWidget_;
+ QPushButton* okButton_;
+ QPushButton* cancelButton_;
+ };
+}
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 1d7ab78..82e4490 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -136,6 +136,7 @@ sources = [
"qrc_DefaultTheme.cc",
"qrc_Swift.cc",
"QtFileTransferJSBridge.cpp",
+ "QtMUCConfigurationWindow.cpp",
]
myenv["SWIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift")