diff options
-rw-r--r-- | Swift/QtUI/QtChatView.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/QtLoginWindow.cpp | 10 | ||||
-rw-r--r-- | Swift/QtUI/QtPlainChatView.cpp | 92 | ||||
-rw-r--r-- | Swift/QtUI/QtPlainChatView.h | 69 | ||||
-rw-r--r-- | Swift/QtUI/QtUISettingConstants.cpp | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtUISettingConstants.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/QtWebKitChatView.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtWebKitChatView.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/SConscript | 1 |
10 files changed, 183 insertions, 3 deletions
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index c8519b7..61c6f24 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -48,5 +48,5 @@ namespace Swift { virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) = 0; virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) = 0; - virtual void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) = 0; + virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) = 0; virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 49f57c9..bfa0663 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -46,4 +46,5 @@ #include <Swift/QtUI/Roster/QtOccupantListWidget.h> +#include <Swift/QtUI/QtPlainChatView.h> #include <Swift/QtUI/QtSettingsProvider.h> #include <Swift/QtUI/QtScaledAvatarCache.h> @@ -108,5 +109,10 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt logRosterSplitter_->setAutoFillBackground(true); layout->addWidget(logRosterSplitter_); + if (settings_->getSetting(QtUISettingConstants::USE_PLAIN_CHATS)) { + messageLog_ = new QtPlainChatView(this); + } + else { messageLog_ = new QtWebKitChatView(this, eventStream_, theme, this); // I accept that passing the ChatWindow in so that the view can call the signals is somewhat inelegant, but it saves a lot of boilerplate. This patch is unpleasant enough already. So let's fix this soon (it at least needs fixing by the time history is sorted), but not now. + } logRosterSplitter_->addWidget(messageLog_); diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index 188e55f..eeb4317 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -60,4 +60,6 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set #endif QtUtilities::setX11Resource(this, "Main"); + setAccessibleName(tr("Swift Login Window")); + //setAccessibleDescription(tr("This window is used for providing credentials to log into your XMPP service")); resize(200, 500); @@ -94,4 +96,5 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set layout->addWidget(jidLabel); + username_ = new QComboBox(this); username_->setEditable(true); @@ -99,4 +102,6 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set username_->setToolTip(tr("User address - looks like someuser@someserver.com")); username_->view()->installEventFilter(this); + username_->setAccessibleName(tr("User address (of the form someuser@someserver.com)")); + username_->setAccessibleDescription(tr("This is the user address that you'll be using to log in with")); layout->addWidget(username_); QLabel* jidHintLabel = new QLabel(this); @@ -108,4 +113,6 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set QLabel* passwordLabel = new QLabel(); passwordLabel->setText("<font size='-1'>" + tr("Password:") + "</font>"); + passwordLabel->setAccessibleName(tr("User password")); + passwordLabel->setAccessibleDescription(tr("This is the password you'll use to log in to the XMPP service")); layout->addWidget(passwordLabel); @@ -130,4 +137,6 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set certificateButton_->setToolTip(tr("Click if you have a personal certificate used for login to the service.")); certificateButton_->setWhatsThis(tr("Click if you have a personal certificate used for login to the service.")); + certificateButton_->setAccessibleName(tr("Login with certificate")); + certificateButton_->setAccessibleDescription(tr("Click if you have a personal certificate used for login to the service.")); credentialsLayout->addWidget(certificateButton_); @@ -138,4 +147,5 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set loginButton_->setAutoDefault(true); loginButton_->setDefault(true); + loginButton_->setAccessibleName(tr("Connect now")); layout->addWidget(loginButton_); diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp new file mode 100644 index 0000000..267b13b --- /dev/null +++ b/Swift/QtUI/QtPlainChatView.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2013 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swift/QtUI/QtPlainChatView.h> + +#include <QTextEdit> +#include <QVBoxLayout> + +#include <Swiften/Base/foreach.h> + +#include <Swift/QtUI/ChatSnippet.h> +#include <Swift/QtUI/QtSwiftUtil.h> +#include <Swift/QtUI/QtUtilities.h> + + +namespace Swift { + +QtPlainChatView::QtPlainChatView(QWidget* parent) : QtChatView(parent) { + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->setSpacing(0); + mainLayout->setContentsMargins(0,0,0,0); + log_ = new QTextEdit(this); + log_->setReadOnly(true); + mainLayout->addWidget(log_); +} + +QtPlainChatView::~QtPlainChatView() { + +} + +QString chatMessageToString(const ChatWindow::ChatMessage& message) { + QString result; + foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) { + boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart; + boost::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart; + boost::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart; + boost::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart; + + if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) { + QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text)); + text.replace("\n","<br/>"); + result += text; + continue; + } + if ((uriPart = boost::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) { + QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target)); + result += "<a href='" + uri + "' >" + uri + "</a>"; + continue; + } + if ((emoticonPart = boost::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) { + result += P2QSTRING(emoticonPart->alternativeText); + continue; + } + if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) { + //FIXME: Maybe do something here. Anything, really. + continue; + } + } + return result; +} + +std::string QtPlainChatView::addMessage(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { + QString text = "<p>"; + if (label) { + text += P2QSTRING(label->getLabel()) + "<br/>"; + } + QString name = senderIsSelf ? "you" : P2QSTRING(senderName); + text += QString(tr("At %1 %2 said:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>"; + text += chatMessageToString(message); + text += "</p>"; + log_->append(text); + return ""; +}; + +std::string QtPlainChatView::addAction(const ChatWindow::ChatMessage& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& /*avatarPath*/, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/) { + QString text = "<p>"; + if (label) { + text += P2QSTRING(label->getLabel()) + "<br/>"; + } + QString name = senderIsSelf ? "you" : P2QSTRING(senderName); + text += QString(tr("At %1 %2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name); + text += chatMessageToString(message); + text += "</p>"; + log_->append(text); + return ""; +}; + + +} diff --git a/Swift/QtUI/QtPlainChatView.h b/Swift/QtUI/QtPlainChatView.h new file mode 100644 index 0000000..c475862 --- /dev/null +++ b/Swift/QtUI/QtPlainChatView.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> +#include <boost/shared_ptr.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + +#include <QWidget> + +#include <Swift/Controllers/UIInterfaces/ChatWindow.h> + +#include <Swift/QtUI/QtChatView.h> + +class QTextEdit; + +namespace Swift { + class HighlightAction; + class SecurityLabel; + + class QtPlainChatView : public QtChatView { + Q_OBJECT + public: + QtPlainChatView(QWidget* parent); + virtual ~QtPlainChatView(); + + /** Add message to window. + * @return id of added message (for acks). + */ + virtual std::string addMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/, const HighlightAction& /*highlight*/); + /** Adds action to window. + * @return id of added message (for acks); + */ + virtual std::string addAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*senderName*/, bool /*senderIsSelf*/, boost::shared_ptr<SecurityLabel> /*label*/, const std::string& /*avatarPath*/, const boost::posix_time::ptime& /*time*/, const HighlightAction& /*highlight*/); + + virtual void addSystemMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/) {}; + virtual void addPresenceMessage(const ChatWindow::ChatMessage& /*message*/, ChatWindow::Direction /*direction*/) {}; + + virtual void addErrorMessage(const ChatWindow::ChatMessage& /*message*/) {}; + virtual void replaceMessage(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/, const HighlightAction& /*highlight*/) {}; + virtual void replaceWithAction(const ChatWindow::ChatMessage& /*message*/, const std::string& /*id*/, const boost::posix_time::ptime& /*time*/, const HighlightAction& /*highlight*/) {}; + virtual void replaceLastMessage(const ChatWindow::ChatMessage& /*message*/) {}; + virtual void setAckState(const std::string& /*id*/, ChatWindow::AckState /*state*/) {}; + + virtual std::string addFileTransfer(const std::string& /*senderName*/, bool /*senderIsSelf*/, const std::string& /*filename*/, const boost::uintmax_t /*sizeInBytes*/) {return "";}; + virtual void setFileTransferProgress(std::string, const int /*percentageDone*/) {}; + virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState /*state*/, const std::string& /*msg*/ = "") {}; + virtual void addMUCInvitation(const std::string& /*senderName*/, const JID& /*jid*/, const std::string& /*reason*/, const std::string& /*password*/, bool /*direct*/, bool /*isImpromptu*/, bool /*isContinuation*/) {}; + virtual std::string addWhiteboardRequest(const QString& /*contact*/, bool /*senderIsSelf*/) {return "";}; + virtual void setWhiteboardSessionStatus(const std::string& /*id*/, const ChatWindow::WhiteboardSessionState /*state*/) {}; + virtual void setMessageReceiptState(const std::string& /*id*/, ChatWindow::ReceiptState /*state*/) {}; + + virtual void showEmoticons(bool /*show*/) {}; + virtual void addLastSeenLine() {}; + + public slots: + virtual void resizeFont(int /*fontSizeSteps*/) {}; + virtual void scrollToBottom() {}; + virtual void handleKeyPressEvent(QKeyEvent* /*event*/) {}; + + private: + QTextEdit* log_; + + }; +} diff --git a/Swift/QtUI/QtUISettingConstants.cpp b/Swift/QtUI/QtUISettingConstants.cpp index 68001d7..1ff3beb 100644 --- a/Swift/QtUI/QtUISettingConstants.cpp +++ b/Swift/QtUI/QtUISettingConstants.cpp @@ -16,3 +16,4 @@ const SettingsProvider::Setting<int> QtUISettingConstants::CHATWINDOW_FONT_SIZE( const SettingsProvider::Setting<int> QtUISettingConstants::HISTORYWINDOW_FONT_SIZE("historyWindowFontSize", 0); const SettingsProvider::Setting<bool> QtUISettingConstants::SHOW_EMOTICONS("showEmoticons", true); +const SettingsProvider::Setting<bool> QtUISettingConstants::USE_PLAIN_CHATS("plainChats", false); } diff --git a/Swift/QtUI/QtUISettingConstants.h b/Swift/QtUI/QtUISettingConstants.h index 8ac835f..31085c1 100644 --- a/Swift/QtUI/QtUISettingConstants.h +++ b/Swift/QtUI/QtUISettingConstants.h @@ -19,4 +19,5 @@ namespace Swift { static const SettingsProvider::Setting<int> HISTORYWINDOW_FONT_SIZE; static const SettingsProvider::Setting<bool> SHOW_EMOTICONS; + static const SettingsProvider::Setting<bool> USE_PLAIN_CHATS; }; } diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp index bc57de4..af21609 100644 --- a/Swift/QtUI/QtWebKitChatView.cpp +++ b/Swift/QtUI/QtWebKitChatView.cpp @@ -721,5 +721,5 @@ std::string QtWebKitChatView::addWhiteboardRequest(const QString& contact, bool } -void QtWebKitChatView::setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) { +void QtWebKitChatView::setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) { setWhiteboardSessionStatus(P2QSTRING(id), state); } diff --git a/Swift/QtUI/QtWebKitChatView.h b/Swift/QtUI/QtWebKitChatView.h index 6bdaf96..bdb2a75 100644 --- a/Swift/QtUI/QtWebKitChatView.h +++ b/Swift/QtUI/QtWebKitChatView.h @@ -70,5 +70,5 @@ namespace Swift { virtual void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) SWIFTEN_OVERRIDE; virtual std::string addWhiteboardRequest(const QString& contact, bool senderIsSelf) SWIFTEN_OVERRIDE; - virtual void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) SWIFTEN_OVERRIDE; + virtual void setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) SWIFTEN_OVERRIDE; virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) SWIFTEN_OVERRIDE; diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 6835872..5cfe81f 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -106,4 +106,5 @@ sources = [ "QtChatView.cpp", "QtWebKitChatView.cpp", + "QtPlainChatView.cpp", "QtChatTheme.cpp", "QtChatTabs.cpp", |