summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2011-11-11 15:01:32 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-11-28 16:44:22 (GMT)
commit86aad702d1f2e831c8e27bbe4ca1402626e4c542 (patch)
tree3be5a8ed23aef3877c9b313d0ee0f58afb54f57a /Swift/QtUI
parent81a7776d5ab523894a7c4745baee3988ad9f1ef9 (diff)
downloadswift-86aad702d1f2e831c8e27bbe4ca1402626e4c542.zip
swift-86aad702d1f2e831c8e27bbe4ca1402626e4c542.tar.bz2
Message Receipts (XEP-0184) support for 1-to-1 conversations (including 1-to-1 MUC).
Warn icon from already existing theme. Check icon from Wikipedia. See Swift/resources/icons/license_info.txt for details. License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/MessageSnippet.cpp2
-rw-r--r--Swift/QtUI/QtChatView.cpp16
-rw-r--r--Swift/QtUI/QtChatView.h3
-rw-r--r--Swift/QtUI/QtChatWindow.cpp23
-rw-r--r--Swift/QtUI/QtChatWindow.h4
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp4
-rw-r--r--Swift/QtUI/QtLoginWindow.h9
-rw-r--r--Swift/QtUI/QtMainWindow.cpp19
-rw-r--r--Swift/QtUI/QtMainWindow.h6
-rw-r--r--Swift/QtUI/QtUIFactory.cpp2
-rw-r--r--Swift/QtUI/Swift.qrc2
11 files changed, 83 insertions, 7 deletions
diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp
index 47cb1a0..a2e4651 100644
--- a/Swift/QtUI/MessageSnippet.cpp
+++ b/Swift/QtUI/MessageSnippet.cpp
@@ -32,7 +32,7 @@ MessageSnippet::MessageSnippet(const QString& message, const QString& sender, co
}
}
- content_.replace("%message%", "<span class='swift_message'>" + escape(message) + "</span><span class='swift_ack'></span>");
+ content_.replace("%message%", "<span class='swift_message'>" + escape(message) + "</span><span class='swift_ack'></span><span class='swift_receipt'></span>");
content_.replace("%sender%", escape(sender));
content_.replace("%time%", "<span class='swift_time'>" + timeToEscapedString(time) + "</span>");
content_.replace("%userIconPath%", escape(iconURI));
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 1c3dd37..db00ba0 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -196,6 +196,22 @@ void QtChatView::setAckXML(const QString& id, const QString& xml) {
ackElement.setInnerXml(xml);
}
+void QtChatView::setReceiptXML(const QString& id, const QString& xml) {
+ QWebElement message = document_.findFirst("#" + id);
+ if (message.isNull()) return;
+ QWebElement receiptElement = message.findFirst("span.swift_receipt");
+ assert(!receiptElement.isNull());
+ receiptElement.setInnerXml(xml);
+}
+
+void QtChatView::displayReceiptInfo(const QString& id, bool showIt) {
+ QWebElement message = document_.findFirst("#" + id);
+ if (message.isNull()) return;
+ QWebElement receiptElement = message.findFirst("span.swift_receipt");
+ assert(!receiptElement.isNull());
+ receiptElement.setStyleProperty("display", showIt ? "inline" : "none");
+}
+
void QtChatView::rememberScrolledToBottom() {
isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
}
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index cf47029..0cc521a 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -35,6 +35,9 @@ namespace Swift {
void replaceMessage(const QString& newMessage, const QString& id, const QDateTime& time);
void rememberScrolledToBottom();
void setAckXML(const QString& id, const QString& xml);
+ void setReceiptXML(const QString& id, const QString& xml);
+ void displayReceiptInfo(const QString& id, bool showIt);
+
QString getLastSentMessage();
void addToJSEnvironment(const QString&, QObject*);
void setFileTransferProgress(QString id, const int percentageDone);
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index f0f268d..88f326f 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -475,13 +475,32 @@ void QtChatWindow::flash() {
void QtChatWindow::setAckState(std::string const& id, ChatWindow::AckState state) {
QString xml;
switch (state) {
- case ChatWindow::Pending: xml = "<img src='qrc:/icons/throbber.gif' alt='" + tr("This message has not been received by your server yet.") + "'/>"; break;
- case ChatWindow::Received: xml = ""; break;
+ case ChatWindow::Pending:
+ xml = "<img src='qrc:/icons/throbber.gif' alt='" + tr("This message has not been received by your server yet.") + "'/>";
+ messageLog_->displayReceiptInfo(P2QSTRING(id), false);
+ break;
+ case ChatWindow::Received:
+ xml = "";
+ messageLog_->displayReceiptInfo(P2QSTRING(id), true);
+ break;
case ChatWindow::Failed: xml = "<img src='qrc:/icons/error.png' alt='" + tr("This message may not have been transmitted.") + "'/>"; break;
}
messageLog_->setAckXML(P2QSTRING(id), xml);
}
+void QtChatWindow::setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) {
+ QString xml;
+ switch (state) {
+ case ChatWindow::ReceiptReceived:
+ xml = "<img src='qrc:/icons/check.png' alt'" + tr("The receipt for this message has been received.") + "'/>";
+ break;
+ case ChatWindow::ReceiptRequested:
+ xml = "<img src='qrc:/icons/warn.png' alt='" + tr("The receipt for this message has not yet been received. The receipient(s) might not have received this message.") + "'/>";
+ break;
+ }
+ messageLog_->setReceiptXML(P2QSTRING(id), xml);
+}
+
int QtChatWindow::getCount() {
return unreadCount_;
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 233f2bc..55e929d 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -68,6 +68,10 @@ namespace Swift {
int getCount();
void replaceLastMessage(const std::string& message);
void setAckState(const std::string& id, AckState state);
+
+ // message receipts
+ void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state);
+
void flash();
QByteArray getSplitterState();
virtual void setAvailableOccupantActions(const std::vector<OccupantAction>& actions);
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index e339d79..5a8b9ab 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -455,6 +455,10 @@ void QtLoginWindow::hide() {
window()->hide();
}
+QtLoginWindow::QtMenus QtLoginWindow::getMenus() const {
+ return QtMenus(swiftMenu_, generalMenu_);
+}
+
void QtLoginWindow::resizeEvent(QResizeEvent*) {
emit geometryChanged();
}
diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h
index acf327f..a830af5 100644
--- a/Swift/QtUI/QtLoginWindow.h
+++ b/Swift/QtUI/QtLoginWindow.h
@@ -27,6 +27,13 @@ namespace Swift {
class QtLoginWindow : public QMainWindow, public LoginWindow {
Q_OBJECT
public:
+ struct QtMenus {
+ QtMenus(QMenu* swiftMenu, QMenu* generalMenu) : swiftMenu(swiftMenu), generalMenu(generalMenu) {}
+ QMenu* swiftMenu;
+ QMenu* generalMenu;
+ };
+
+ public:
QtLoginWindow(UIEventStream* uiEventStream, bool eagleMode);
void morphInto(MainWindow *mainWindow);
@@ -39,7 +46,7 @@ namespace Swift {
void selectUser(const std::string& user);
bool askUserToTrustCertificatePermanently(const std::string& message, Certificate::ref certificate);
void hide();
-
+ QtMenus getMenus() const;
virtual void quit();
signals:
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index a4ce98e..199e388 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -25,6 +25,7 @@
#include <Swift/QtUI/QtTabWidget.h>
#include <Swift/QtUI/QtSettingsProvider.h>
#include <Swift/QtUI/QtUIPreferences.h>
+#include <Swift/QtUI/QtLoginWindow.h>
#include <Roster/QtRosterWidget.h>
#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
@@ -33,12 +34,13 @@
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/ToggleShowOfflineUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h>
+#include <Swift/Controllers/UIEvents/ToggleRequestDeliveryReceiptsUIEvent.h>
namespace Swift {
#define CURRENT_ROSTER_TAB "current_roster_tab"
-QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream, QtUIPreferences* uiPreferences) : QWidget(), MainWindow(false) {
+QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream, QtUIPreferences* uiPreferences, QtLoginWindow::QtMenus loginMenus) : QWidget(), MainWindow(false), loginMenus_(loginMenus) {
uiEventStream_ = uiEventStream;
uiPreferences_ = uiPreferences;
settings_ = settings;
@@ -123,6 +125,12 @@ QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventS
connect(signOutAction, SIGNAL(triggered()), SLOT(handleSignOutAction()));
actionsMenu->addAction(signOutAction);
+ toggleRequestDeliveryReceipts_ = new QAction(tr("&Request Delivery Receipts"), this);
+ toggleRequestDeliveryReceipts_->setCheckable(true);
+ toggleRequestDeliveryReceipts_->setChecked(false);
+ connect(toggleRequestDeliveryReceipts_, SIGNAL(toggled(bool)), SLOT(handleToggleRequestDeliveryReceipts(bool)));
+ loginMenus_.generalMenu->addAction(toggleRequestDeliveryReceipts_);
+
treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QAction::setEnabled, editUserAction_, _1));
setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
@@ -143,6 +151,10 @@ void QtMainWindow::handleTabChanged(int index) {
settings_->storeInt(CURRENT_ROSTER_TAB, index);
}
+void QtMainWindow::handleToggleRequestDeliveryReceipts(bool enabled) {
+ uiEventStream_->send(boost::make_shared<ToggleRequestDeliveryReceiptsUIEvent>(enabled));
+}
+
QtEventWindow* QtMainWindow::getEventWindow() {
return eventWindow_;
}
@@ -192,6 +204,7 @@ void QtMainWindow::handleChatUserActionTriggered(bool /*checked*/) {
}
void QtMainWindow::handleSignOutAction() {
+ loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_);
onSignOutRequest();
}
@@ -212,6 +225,10 @@ void QtMainWindow::handleUIEvent(boost::shared_ptr<UIEvent> event) {
if (toggleEvent) {
handleShowOfflineToggled(toggleEvent->getShow());
}
+ boost::shared_ptr<ToggleRequestDeliveryReceiptsUIEvent> deliveryReceiptEvent = boost::dynamic_pointer_cast<ToggleRequestDeliveryReceiptsUIEvent>(event);
+ if (deliveryReceiptEvent) {
+ toggleRequestDeliveryReceipts_->setChecked(deliveryReceiptEvent->getEnabled());
+ }
}
void QtMainWindow::handleShowOfflineToggled(bool state) {
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index afcb57c..3c8bdec 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -13,6 +13,7 @@
#include "Swift/QtUI/QtRosterHeader.h"
#include "Swift/QtUI/EventViewer/QtEventWindow.h"
#include "Swift/QtUI/ChatList/QtChatListWindow.h"
+#include "Swift/QtUI/QtLoginWindow.h"
#include <vector>
@@ -35,7 +36,7 @@ namespace Swift {
class QtMainWindow : public QWidget, public MainWindow {
Q_OBJECT
public:
- QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream, QtUIPreferences* uiPreferences);
+ QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream, QtUIPreferences* uiPreferences, QtLoginWindow::QtMenus loginMenus);
virtual ~QtMainWindow();
std::vector<QMenu*> getMenus() {return menus_;}
void setMyNick(const std::string& name);
@@ -62,9 +63,11 @@ namespace Swift {
void handleChatCountUpdated(int count);
void handleEditProfileRequest();
void handleTabChanged(int index);
+ void handleToggleRequestDeliveryReceipts(bool enabled);
private:
QtSettingsProvider* settings_;
+ QtLoginWindow::QtMenus loginMenus_;
std::vector<QMenu*> menus_;
QtRosterWidget* treeWidget_;
QtRosterHeader* meView_;
@@ -72,6 +75,7 @@ namespace Swift {
QAction* editUserAction_;
QAction* chatUserAction_;
QAction* showOfflineAction_;
+ QAction* toggleRequestDeliveryReceipts_;
QMenu* serverAdHocMenu_;
QtTabWidget* tabs_;
QWidget* contactsTabWidget_;
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index 8a026f2..88da781 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -55,7 +55,7 @@ FileTransferListWidget* QtUIFactory::createFileTransferListWidget() {
}
MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) {
- lastMainWindow = new QtMainWindow(settings, eventStream, uiPreferences);
+ lastMainWindow = new QtMainWindow(settings, eventStream, uiPreferences, loginWindow->getMenus());
return lastMainWindow;
}
diff --git a/Swift/QtUI/Swift.qrc b/Swift/QtUI/Swift.qrc
index d2798e4..61d8cc0 100644
--- a/Swift/QtUI/Swift.qrc
+++ b/Swift/QtUI/Swift.qrc
@@ -11,6 +11,8 @@
<file alias="icons/offline.png">../resources/icons/offline.png</file>
<file alias="icons/certificate.png">../resources/icons/certificate.png</file>
<file alias="icons/error.png">../resources/icons/error.png</file>
+ <file alias="icons/warn.png">../resources/icons/warn.png</file>
+ <file alias="icons/check.png">../resources/icons/check.png</file>
<file alias="icons/throbber.gif">../resources/icons/throbber.gif</file>
<file alias="icons/avatar.png">../resources/icons/avatar.png</file>
<file alias="icons/no-avatar.png">../resources/icons/no-avatar.png</file>