summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.cpp25
-rw-r--r--Swift/QtUI/ChatList/ChatListDelegate.h2
-rw-r--r--Swift/QtUI/ChatList/ChatListGroupItem.h28
-rw-r--r--Swift/QtUI/ChatList/ChatListItem.h4
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.cpp102
-rw-r--r--Swift/QtUI/ChatList/ChatListModel.h15
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.cpp21
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.h3
-rw-r--r--Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp46
-rw-r--r--Swift/QtUI/ChatList/ChatListWhiteboardItem.h35
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.cpp101
-rw-r--r--Swift/QtUI/ChatList/QtChatListWindow.h11
-rw-r--r--Swift/QtUI/ChatSnippet.cpp62
-rw-r--r--Swift/QtUI/ChatSnippet.h21
-rw-r--r--Swift/QtUI/CocoaApplicationActivateHelper.h2
-rw-r--r--Swift/QtUI/CocoaUIHelpers.h20
-rw-r--r--Swift/QtUI/CocoaUIHelpers.mm43
-rw-r--r--Swift/QtUI/EventViewer/EventDelegate.cpp20
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.cpp5
-rw-r--r--Swift/QtUI/EventViewer/QtEvent.h2
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.cpp7
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.h7
-rw-r--r--Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp2
-rw-r--r--Swift/QtUI/MessageSnippet.cpp13
-rw-r--r--Swift/QtUI/MessageSnippet.h6
-rw-r--r--Swift/QtUI/QtAboutWidget.cpp2
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.cpp55
-rw-r--r--Swift/QtUI/QtAdHocCommandWindow.h6
-rw-r--r--Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp61
-rw-r--r--Swift/QtUI/QtAdHocCommandWithJIDWindow.h32
-rw-r--r--Swift/QtUI/QtAddBookmarkWindow.cpp6
-rw-r--r--Swift/QtUI/QtAddBookmarkWindow.h3
-rw-r--r--Swift/QtUI/QtAffiliationEditor.cpp0
-rw-r--r--Swift/QtUI/QtAffiliationEditor.h0
-rw-r--r--Swift/QtUI/QtAffiliationEditor.ui2
-rw-r--r--Swift/QtUI/QtAvatarWidget.cpp12
-rw-r--r--Swift/QtUI/QtAvatarWidget.h10
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.cpp226
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.h55
-rw-r--r--Swift/QtUI/QtBlockListEditorWindow.ui114
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.cpp27
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.h5
-rw-r--r--Swift/QtUI/QtBookmarkDetailWindow.ui31
-rw-r--r--Swift/QtUI/QtCachedImageScaler.cpp14
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.cpp134
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.h44
-rw-r--r--Swift/QtUI/QtCertificateViewerDialog.ui131
-rw-r--r--Swift/QtUI/QtChatTabs.cpp50
-rw-r--r--Swift/QtUI/QtChatTabs.h4
-rw-r--r--Swift/QtUI/QtChatTheme.h28
-rw-r--r--Swift/QtUI/QtChatView.cpp360
-rw-r--r--Swift/QtUI/QtChatView.h102
-rw-r--r--Swift/QtUI/QtChatWindow.cpp783
-rw-r--r--Swift/QtUI/QtChatWindow.h141
-rw-r--r--Swift/QtUI/QtChatWindowFactory.cpp15
-rw-r--r--Swift/QtUI/QtChatWindowFactory.h11
-rw-r--r--Swift/QtUI/QtChatWindowJSBridge.h2
-rw-r--r--Swift/QtUI/QtClosableLineEdit.cpp59
-rw-r--r--Swift/QtUI/QtClosableLineEdit.h43
-rw-r--r--Swift/QtUI/QtColorToolButton.cpp45
-rw-r--r--Swift/QtUI/QtColorToolButton.h32
-rw-r--r--Swift/QtUI/QtConnectionSettings.ui529
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.cpp165
-rw-r--r--Swift/QtUI/QtConnectionSettingsWindow.h37
-rw-r--r--Swift/QtUI/QtContactEditWidget.cpp16
-rw-r--r--Swift/QtUI/QtContactEditWidget.h4
-rw-r--r--Swift/QtUI/QtContactEditWindow.cpp5
-rw-r--r--Swift/QtUI/QtFileTransferListItemModel.cpp15
-rw-r--r--Swift/QtUI/QtFileTransferListItemModel.h2
-rw-r--r--Swift/QtUI/QtFormResultItemModel.cpp19
-rw-r--r--Swift/QtUI/QtFormWidget.cpp199
-rw-r--r--Swift/QtUI/QtFormWidget.h4
-rw-r--r--Swift/QtUI/QtHighlightEditor.cpp542
-rw-r--r--Swift/QtUI/QtHighlightEditor.h70
-rw-r--r--Swift/QtUI/QtHighlightEditor.ui479
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.cpp149
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.h44
-rw-r--r--Swift/QtUI/QtHighlightEditorWidget.ui124
-rw-r--r--Swift/QtUI/QtHighlightRulesItemModel.cpp284
-rw-r--r--Swift/QtUI/QtHighlightRulesItemModel.h64
-rw-r--r--Swift/QtUI/QtHistoryWindow.cpp264
-rw-r--r--Swift/QtUI/QtHistoryWindow.h81
-rw-r--r--Swift/QtUI/QtHistoryWindow.ui101
-rw-r--r--Swift/QtUI/QtJoinMUCWindow.ui16
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp70
-rw-r--r--Swift/QtUI/QtLoginWindow.h9
-rw-r--r--Swift/QtUI/QtMainWindow.cpp175
-rw-r--r--Swift/QtUI/QtMainWindow.h37
-rw-r--r--Swift/QtUI/QtNameWidget.cpp9
-rw-r--r--Swift/QtUI/QtNameWidget.h6
-rw-r--r--Swift/QtUI/QtPlainChatView.cpp413
-rw-r--r--Swift/QtUI/QtPlainChatView.h132
-rw-r--r--Swift/QtUI/QtProfileWindow.cpp191
-rw-r--r--Swift/QtUI/QtProfileWindow.h52
-rw-r--r--Swift/QtUI/QtProfileWindow.ui105
-rw-r--r--Swift/QtUI/QtResourceHelper.cpp25
-rw-r--r--Swift/QtUI/QtResourceHelper.h17
-rw-r--r--Swift/QtUI/QtRosterHeader.cpp61
-rw-r--r--Swift/QtUI/QtRosterHeader.h17
-rw-r--r--Swift/QtUI/QtScaledAvatarCache.cpp8
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp2
-rw-r--r--Swift/QtUI/QtSingleWindow.cpp81
-rw-r--r--Swift/QtUI/QtSingleWindow.h37
-rw-r--r--Swift/QtUI/QtSoundPlayer.cpp16
-rw-r--r--Swift/QtUI/QtSoundPlayer.h2
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.cpp115
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.h34
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.ui105
-rw-r--r--Swift/QtUI/QtStatusWidget.cpp59
-rw-r--r--Swift/QtUI/QtStatusWidget.h7
-rw-r--r--Swift/QtUI/QtSubscriptionRequestWindow.cpp18
-rw-r--r--Swift/QtUI/QtSwift.cpp126
-rw-r--r--Swift/QtUI/QtSwift.h6
-rw-r--r--Swift/QtUI/QtSwiftUtil.h2
-rw-r--r--Swift/QtUI/QtSystemTray.cpp25
-rw-r--r--Swift/QtUI/QtSystemTray.h3
-rw-r--r--Swift/QtUI/QtTabbable.cpp59
-rw-r--r--Swift/QtUI/QtTabbable.h17
-rw-r--r--Swift/QtUI/QtTextEdit.cpp177
-rw-r--r--Swift/QtUI/QtTextEdit.h28
-rw-r--r--Swift/QtUI/QtTranslator.h4
-rw-r--r--Swift/QtUI/QtUIFactory.cpp90
-rw-r--r--Swift/QtUI/QtUIFactory.h21
-rw-r--r--Swift/QtUI/QtUISettingConstants.cpp6
-rw-r--r--Swift/QtUI/QtUISettingConstants.h6
-rw-r--r--Swift/QtUI/QtURLValidator.cpp25
-rw-r--r--Swift/QtUI/QtURLValidator.h17
-rw-r--r--Swift/QtUI/QtUtilities.cpp19
-rw-r--r--Swift/QtUI/QtUtilities.h12
-rw-r--r--Swift/QtUI/QtVCardWidget/QtCloseButton.cpp45
-rw-r--r--Swift/QtUI/QtVCardWidget/QtCloseButton.h24
-rw-r--r--Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp63
-rw-r--r--Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h28
-rw-r--r--Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp58
-rw-r--r--Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h33
-rw-r--r--Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp102
-rw-r--r--Swift/QtUI/QtVCardWidget/QtTagComboBox.h46
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp175
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressField.h60
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp99
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h50
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp61
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h43
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp64
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h42
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h52
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp154
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h91
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp40
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h31
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp82
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h43
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp73
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardJIDField.h42
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp145
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h54
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp144
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h62
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.ui251
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp50
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardRoleField.h41
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp100
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h42
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp51
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardTitleField.h41
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp71
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardURLField.h42
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp407
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.h63
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.ui138
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp945
-rw-r--r--Swift/QtUI/QtWebKitChatView.h188
-rw-r--r--Swift/QtUI/QtWebView.cpp7
-rw-r--r--Swift/QtUI/QtWin32NotifierWindow.h2
-rw-r--r--Swift/QtUI/QtXMLConsoleWidget.cpp23
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.cpp9
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.h5
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.cpp166
-rw-r--r--Swift/QtUI/Roster/QtFilterWidget.h51
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.cpp16
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.h11
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.cpp87
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp91
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h35
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp4
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp116
-rw-r--r--Swift/QtUI/Roster/RosterModel.h24
-rw-r--r--Swift/QtUI/Roster/RosterTooltip.cpp166
-rw-r--r--Swift/QtUI/Roster/RosterTooltip.h27
-rw-r--r--Swift/QtUI/SConscript187
-rw-r--r--Swift/QtUI/Swift.qrc24
-rw-r--r--Swift/QtUI/SystemMessageSnippet.cpp5
-rw-r--r--Swift/QtUI/SystemMessageSnippet.h2
-rw-r--r--Swift/QtUI/UserSearch/ContactListDelegate.cpp52
-rw-r--r--Swift/QtUI/UserSearch/ContactListDelegate.h30
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.cpp139
-rw-r--r--Swift/QtUI/UserSearch/ContactListModel.h64
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.cpp101
-rw-r--r--Swift/QtUI/UserSearch/QtContactListWidget.h63
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp199
-rw-r--r--Swift/QtUI/UserSearch/QtSuggestingJIDInput.h66
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp3
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp101
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h52
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.ui222
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp9
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.h6
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchFirstPage.ui35
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.cpp397
-rw-r--r--Swift/QtUI/UserSearch/QtUserSearchWindow.h36
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.cpp37
-rw-r--r--Swift/QtUI/Whiteboard/ColorWidget.h33
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.cpp97
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.h33
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp499
-rw-r--r--Swift/QtUI/Whiteboard/GView.h75
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp394
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h88
-rw-r--r--Swift/QtUI/Whiteboard/TextDialog.cpp52
-rw-r--r--Swift/QtUI/Whiteboard/TextDialog.h43
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h187
-rw-r--r--Swift/QtUI/WinUIHelpers.cpp61
-rw-r--r--Swift/QtUI/WinUIHelpers.h20
-rw-r--r--Swift/QtUI/main.cpp48
224 files changed, 15884 insertions, 1759 deletions
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.cpp b/Swift/QtUI/ChatList/ChatListDelegate.cpp
index bcd1585..5b03ac5 100644
--- a/Swift/QtUI/ChatList/ChatListDelegate.cpp
+++ b/Swift/QtUI/ChatList/ChatListDelegate.cpp
@@ -13,4 +13,5 @@
#include "Swift/QtUI/ChatList/ChatListMUCItem.h"
#include "Swift/QtUI/ChatList/ChatListRecentItem.h"
+#include "Swift/QtUI/ChatList/ChatListWhiteboardItem.h"
#include "Swift/QtUI/ChatList/ChatListGroupItem.h"
@@ -40,4 +41,7 @@ QSize ChatListDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode
return groupDelegate_->sizeHint(option, index);
}
+ else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ return common_.contactSizeHint(option, index, compact_);
+ }
return QStyledItemDelegate::sizeHint(option, index);
}
@@ -66,4 +70,7 @@ void ChatListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& opti
groupDelegate_->paint(painter, option, group->data(Qt::DisplayRole).toString(), group->rowCount(), option.state & QStyle::State_Open);
}
+ else if (item && dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ paintWhiteboard(painter, option, dynamic_cast<ChatListWhiteboardItem*>(item));
+ }
else {
QStyledItemDelegate::paint(painter, option, index);
@@ -114,5 +121,21 @@ void ChatListDelegate::paintRecent(QPainter* painter, const QStyleOptionViewItem
//qDebug() << "Avatar for " << name << " = " << avatarPath;
QString statusText = item->data(ChatListRecentItem::DetailTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, item->getChat().unreadCount, compact_);
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
+}
+
+void ChatListDelegate::paintWhiteboard(QPainter* painter, const QStyleOptionViewItem& option, ChatListWhiteboardItem* item) const {
+ QColor nameColor = item->data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath;
+ if (item->data(ChatListWhiteboardItem::AvatarRole).isValid() && !item->data(ChatListWhiteboardItem::AvatarRole).value<QString>().isNull()) {
+ avatarPath = item->data(ChatListWhiteboardItem::AvatarRole).value<QString>();
+ }
+ QIcon presenceIcon;/* = item->data(ChatListWhiteboardItem::PresenceIconRole).isValid() && !item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>().isNull()
+ ? item->data(ChatListWhiteboardItem::PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");*/
+ QString name = item->data(Qt::DisplayRole).toString();
+ //qDebug() << "Avatar for " << name << " = " << avatarPath;
+ QString statusText = item->data(ChatListWhiteboardItem::DetailTextRole).toString();
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, item->getChat().unreadCount, compact_);
+
}
diff --git a/Swift/QtUI/ChatList/ChatListDelegate.h b/Swift/QtUI/ChatList/ChatListDelegate.h
index 5ac45ce..9460c28 100644
--- a/Swift/QtUI/ChatList/ChatListDelegate.h
+++ b/Swift/QtUI/ChatList/ChatListDelegate.h
@@ -14,4 +14,5 @@ namespace Swift {
class ChatListMUCItem;
class ChatListRecentItem;
+ class ChatListWhiteboardItem;
class ChatListDelegate : public QStyledItemDelegate {
public:
@@ -25,4 +26,5 @@ namespace Swift {
void paintMUC(QPainter* painter, const QStyleOptionViewItem& option, ChatListMUCItem* item) const;
void paintRecent(QPainter* painter, const QStyleOptionViewItem& option, ChatListRecentItem* item) const;
+ void paintWhiteboard(QPainter* painter, const QStyleOptionViewItem& option, ChatListWhiteboardItem* item) const;
QSize mucSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
QSize recentSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const;
diff --git a/Swift/QtUI/ChatList/ChatListGroupItem.h b/Swift/QtUI/ChatList/ChatListGroupItem.h
index a1e479f..3bb4b8e 100644
--- a/Swift/QtUI/ChatList/ChatListGroupItem.h
+++ b/Swift/QtUI/ChatList/ChatListGroupItem.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -9,4 +9,6 @@
#include <QList>
+#include <Swiften/Base/foreach.h>
+
#include "Swift/QtUI/ChatList/ChatListItem.h"
@@ -14,12 +16,20 @@ namespace Swift {
class ChatListGroupItem : public ChatListItem {
public:
- ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {};
- void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}};
- void remove(int index) {items_.removeAt(index);};
- int rowCount() {return items_.size();};
- ChatListItem* item(int i) {return items_[i];};
- int row(ChatListItem* item) {return items_.indexOf(item);};
- QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();};
- void clear() {items_.clear();};
+ ChatListGroupItem(const QString& name, ChatListGroupItem* parent, bool sorted = true) : ChatListItem(parent), name_(name), sorted_(sorted) {}
+ virtual ~ChatListGroupItem() {clear();}
+ void addItem(ChatListItem* item) {items_.push_back(item); if (sorted_) {qStableSort(items_.begin(), items_.end(), pointerItemLessThan);}}
+ void remove(int index) {items_.removeAt(index);}
+ int rowCount() {return items_.size();}
+ ChatListItem* item(int i) {return items_[i];}
+ int row(ChatListItem* item) {return items_.indexOf(item);}
+ QVariant data(int role) const {return (role == Qt::DisplayRole) ? name_ : QVariant();}
+ void clear() {
+ foreach (ChatListItem* item, items_) {
+ delete item;
+ }
+ items_.clear();
+ }
+
+
private:
static bool pointerItemLessThan(const ChatListItem* first, const ChatListItem* second) {
diff --git a/Swift/QtUI/ChatList/ChatListItem.h b/Swift/QtUI/ChatList/ChatListItem.h
index e7be614..28c0f9c 100644
--- a/Swift/QtUI/ChatList/ChatListItem.h
+++ b/Swift/QtUI/ChatList/ChatListItem.h
@@ -14,8 +14,8 @@ namespace Swift {
class ChatListItem {
public:
- ChatListItem(ChatListGroupItem* parent) {parent_ = parent;};
+ ChatListItem(ChatListGroupItem* parent) {parent_ = parent;}
virtual ~ChatListItem() {}
- ChatListGroupItem* parent() {return parent_;};
+ ChatListGroupItem* parent() {return parent_;}
virtual QVariant data(int role) const = 0;
diff --git a/Swift/QtUI/ChatList/ChatListModel.cpp b/Swift/QtUI/ChatList/ChatListModel.cpp
index 681c1c2..f08478f 100644
--- a/Swift/QtUI/ChatList/ChatListModel.cpp
+++ b/Swift/QtUI/ChatList/ChatListModel.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,30 +7,57 @@
#include <Swift/QtUI/ChatList/ChatListModel.h>
+#include <QMimeData>
+#include <QUrl>
+
#include <Swift/QtUI/ChatList/ChatListMUCItem.h>
#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
+#include <Swift/QtUI/ChatList/ChatListWhiteboardItem.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-ChatListModel::ChatListModel() {
+ChatListModel::ChatListModel() : whiteboards_(NULL) {
root_ = new ChatListGroupItem("", NULL, false);
mucBookmarks_ = new ChatListGroupItem(tr("Bookmarked Rooms"), root_);
recents_ = new ChatListGroupItem(tr("Recent Chats"), root_, false);
+#ifdef SWIFT_EXPERIMENTAL_WB
+ whiteboards_ = new ChatListGroupItem(tr("Opened Whiteboards"), root_, false);
+ root_->addItem(whiteboards_);
+#endif
+
root_->addItem(recents_);
root_->addItem(mucBookmarks_);
+
+ QModelIndex idx = index(0, 0, QModelIndex());
+ while (idx.isValid()) {
+ if (idx.internalPointer() == mucBookmarks_) {
+ mucBookmarksIndex_ = idx;
+ } else if (idx.internalPointer() == recents_) {
+ recentsIndex_ = idx;
+ } else if (idx.internalPointer() == whiteboards_) {
+ whiteboardsIndex_ = idx;
+ }
+ idx = index(idx.row() + 1, 0, QModelIndex());
+ }
+}
+
+Qt::ItemFlags ChatListModel::flags(const QModelIndex& index) const {
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (dynamic_cast<ChatListRecentItem*>(getItemForIndex(index))) {
+ flags |= Qt::ItemIsDragEnabled;
+ }
+ return flags;
}
void ChatListModel::clearBookmarks() {
- emit layoutAboutToBeChanged();
+ beginRemoveRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
mucBookmarks_->clear();
- emit layoutChanged();
+ endRemoveRows();
}
void ChatListModel::addMUCBookmark(const Swift::MUCBookmark& bookmark) {
- emit layoutAboutToBeChanged();
+ beginInsertRows(mucBookmarksIndex_, 0, mucBookmarks_->rowCount());
mucBookmarks_->addItem(new ChatListMUCItem(bookmark, mucBookmarks_));
- emit layoutChanged();
- //QModelIndex index = createIndex(mucBookmarks_->rowCount() - 1, 0, mucBookmarks_);
- //emit dataChanged(index, index);
- //emit dataChanged(parent(index), parent(index));
+ endInsertRows();
}
@@ -39,7 +66,25 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {
ChatListMUCItem* item = dynamic_cast<ChatListMUCItem*>(mucBookmarks_->item(i));
if (item->getBookmark() == bookmark) {
- emit layoutAboutToBeChanged();
+ beginRemoveRows(mucBookmarksIndex_, i, i+1);
mucBookmarks_->remove(i);
- emit layoutChanged();
+ endRemoveRows();
+ break;
+ }
+ }
+}
+
+void ChatListModel::addWhiteboardSession(const ChatListWindow::Chat& chat) {
+ beginInsertRows(whiteboardsIndex_, 0, whiteboards_->rowCount());
+ whiteboards_->addItem(new ChatListWhiteboardItem(chat, whiteboards_));
+ endInsertRows();
+}
+
+void ChatListModel::removeWhiteboardSession(const JID& jid) {
+ for (int i = 0; i < whiteboards_->rowCount(); i++) {
+ ChatListWhiteboardItem* item = dynamic_cast<ChatListWhiteboardItem*>(whiteboards_->item(i));
+ if (item->getChat().jid == jid) {
+ beginRemoveRows(whiteboardsIndex_, i, i+1);
+ whiteboards_->remove(i);
+ endRemoveRows();
break;
}
@@ -48,10 +93,41 @@ void ChatListModel::removeMUCBookmark(const Swift::MUCBookmark& bookmark) {
void ChatListModel::setRecents(const std::list<ChatListWindow::Chat>& recents) {
- emit layoutAboutToBeChanged();
+ beginRemoveRows(recentsIndex_, 0, recents_->rowCount());
recents_->clear();
+ endRemoveRows();
+ beginInsertRows(recentsIndex_, 0, recents.size());
foreach (const ChatListWindow::Chat chat, recents) {
recents_->addItem(new ChatListRecentItem(chat, recents_));
+//whiteboards_->addItem(new ChatListRecentItem(chat, whiteboards_));
+ }
+ endInsertRows();
+}
+
+QMimeData* ChatListModel::mimeData(const QModelIndexList& indexes) const {
+ QMimeData* data = QAbstractItemModel::mimeData(indexes);
+ ChatListRecentItem *item = dynamic_cast<ChatListRecentItem*>(getItemForIndex(indexes.first()));
+ if (item == NULL) {
+ return data;
+ }
+
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ const ChatListWindow::Chat& chat = item->getChat();
+
+ QString mimeType = "application/vnd.swift.contact-jid-list";
+ if (!chat.impromptuJIDs.size()) {
+ if (chat.isMUC) {
+ mimeType = "application/vnd.swift.contact-jid-muc";
+ }
+ dataStream << P2QSTRING(chat.jid.toString());
+ } else {
+ typedef std::map<std::string, JID> JIDMap;
+ foreach (const JIDMap::value_type& jid, chat.impromptuJIDs) {
+ dataStream << P2QSTRING(jid.second.toString());
+ }
}
- emit layoutChanged();
+
+ data->setData(mimeType, itemData);
+ return data;
}
diff --git a/Swift/QtUI/ChatList/ChatListModel.h b/Swift/QtUI/ChatList/ChatListModel.h
index 8e7828c..00bd5eb 100644
--- a/Swift/QtUI/ChatList/ChatListModel.h
+++ b/Swift/QtUI/ChatList/ChatListModel.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,8 +7,6 @@
#pragma once
-#include <boost/shared_ptr.hpp>
-
#include <QAbstractItemModel>
-#include <QList>
+#include <QPersistentModelIndex>
#include <Swiften/MUC/MUCBookmark.h>
@@ -22,6 +20,9 @@ namespace Swift {
public:
ChatListModel();
+ Qt::ItemFlags flags(const QModelIndex& index) const;
void addMUCBookmark(const MUCBookmark& bookmark);
void removeMUCBookmark(const MUCBookmark& bookmark);
+ void addWhiteboardSession(const ChatListWindow::Chat& chat);
+ void removeWhiteboardSession(const JID& jid);
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
@@ -32,8 +33,14 @@ namespace Swift {
void clearBookmarks();
void setRecents(const std::list<ChatListWindow::Chat>& recents);
+ QMimeData* mimeData(const QModelIndexList& indexes) const;
private:
ChatListGroupItem* mucBookmarks_;
ChatListGroupItem* recents_;
+ ChatListGroupItem* whiteboards_;
ChatListGroupItem* root_;
+
+ QPersistentModelIndex mucBookmarksIndex_;
+ QPersistentModelIndex recentsIndex_;
+ QPersistentModelIndex whiteboardsIndex_;
};
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
index 6c9807f..5497fdd 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
@@ -1,10 +1,12 @@
/*
- * Copyright (c) 2011 Kevin Smith
+ * Copyright (c) 2011-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
+#include <Swiften/Base/Path.h>
+#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
+#include <Swift/QtUI/QtResourceHelper.h>
#include <Swift/QtUI/QtSwiftUtil.h>
@@ -20,5 +22,5 @@ const ChatListWindow::Chat& ChatListRecentItem::getChat() const {
QVariant ChatListRecentItem::data(int role) const {
switch (role) {
- case Qt::DisplayRole: return P2QSTRING(chat_.chatName);
+ case Qt::DisplayRole: return chat_.impromptuJIDs.empty() ? P2QSTRING(chat_.chatName) : P2QSTRING(chat_.getImpromptuTitle());
case DetailTextRole: return P2QSTRING(chat_.activity);
/*case Qt::TextColorRole: return textColor_;
@@ -26,5 +28,5 @@ QVariant ChatListRecentItem::data(int role) const {
case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
case StatusTextRole: return statusText_;*/
- case AvatarRole: return QVariant(QString(chat_.avatarPath.string().c_str()));
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
case PresenceIconRole: return getPresenceIcon();
default: return QVariant();
@@ -33,14 +35,5 @@ QVariant ChatListRecentItem::data(int role) const {
QIcon ChatListRecentItem::getPresenceIcon() const {
- QString iconString;
- switch (chat_.statusType) {
- case StatusShow::Online: iconString = "online";break;
- case StatusShow::Away: iconString = "away";break;
- case StatusShow::XA: iconString = "away";break;
- case StatusShow::FFC: iconString = "online";break;
- case StatusShow::DND: iconString = "dnd";break;
- case StatusShow::None: iconString = "offline";break;
- }
- return QIcon(":/icons/" + iconString + ".png");
+ return QIcon(statusShowTypeToIconPath(chat_.statusType));
}
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.h b/Swift/QtUI/ChatList/ChatListRecentItem.h
index 4e7bc3e..3f27a68 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.h
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.h
@@ -24,5 +24,6 @@ namespace Swift {
AvatarRole = Qt::UserRole + 1,
PresenceIconRole = Qt::UserRole + 2/*,
- StatusShowTypeRole = Qt::UserRole + 3*/
+ StatusShowTypeRole = Qt::UserRole + 3,
+ IdleRole = Qt::UserRole + 4*/
};
ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
diff --git a/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
new file mode 100644
index 0000000..05bf6c2
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Base/Path.h>
+
+#include <Swift/QtUI/ChatList/ChatListWhiteboardItem.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtResourceHelper.h>
+
+namespace Swift {
+ ChatListWhiteboardItem::ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) {
+
+ }
+
+ const ChatListWindow::Chat& ChatListWhiteboardItem::getChat() const {
+ return chat_;
+ }
+
+ QVariant ChatListWhiteboardItem::data(int role) const {
+ switch (role) {
+ case Qt::DisplayRole: return P2QSTRING(chat_.chatName);
+ case DetailTextRole: return P2QSTRING(chat_.activity);
+ /*case Qt::TextColorRole: return textColor_;
+ case Qt::BackgroundColorRole: return backgroundColor_;
+ case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
+ case StatusTextRole: return statusText_;*/
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
+ case PresenceIconRole: return getPresenceIcon();
+ default: return QVariant();
+ }
+ }
+
+ QIcon ChatListWhiteboardItem::getPresenceIcon() const {
+ return QIcon(statusShowTypeToIconPath(chat_.statusType));
+ }
+}
+
diff --git a/Swift/QtUI/ChatList/ChatListWhiteboardItem.h b/Swift/QtUI/ChatList/ChatListWhiteboardItem.h
new file mode 100644
index 0000000..2dc6255
--- /dev/null
+++ b/Swift/QtUI/ChatList/ChatListWhiteboardItem.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QList>
+#include <QIcon>
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/MUC/MUCBookmark.h>
+#include <Swift/Controllers/UIInterfaces/ChatListWindow.h>
+
+#include <Swift/QtUI/ChatList/ChatListItem.h>
+
+namespace Swift {
+ class ChatListWhiteboardItem : public ChatListItem {
+ public:
+ enum RecentItemRoles {
+ DetailTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2/*,
+ StatusShowTypeRole = Qt::UserRole + 3*/
+ };
+ ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent);
+ const ChatListWindow::Chat& getChat() const;
+ QVariant data(int role) const;
+ private:
+ QIcon getPresenceIcon() const;
+ ChatListWindow::Chat chat_;
+ };
+}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.cpp b/Swift/QtUI/ChatList/QtChatListWindow.cpp
index 42eb43b..ea65dd6 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.cpp
+++ b/Swift/QtUI/ChatList/QtChatListWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -9,25 +9,28 @@
#include <boost/bind.hpp>
-#include <QMenu>
#include <QContextMenuEvent>
+#include <QMenu>
+#include <QMimeData>
+#include <QUrl>
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h>
+#include <Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h>
+#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
+#include <Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h>
+#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
+#include <Swift/Controllers/UIEvents/ShowWhiteboardUIEvent.h>
#include <Swift/QtUI/ChatList/ChatListMUCItem.h>
#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
+#include <Swift/QtUI/ChatList/ChatListWhiteboardItem.h>
#include <Swift/QtUI/QtAddBookmarkWindow.h>
#include <Swift/QtUI/QtEditBookmarkWindow.h>
#include <Swift/QtUI/QtUISettingConstants.h>
-#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
-#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
-#include <Swift/Controllers/UIEvents/AddMUCBookmarkUIEvent.h>
-#include <Swift/Controllers/UIEvents/RemoveMUCBookmarkUIEvent.h>
-#include <Swift/Controllers/UIEvents/EditMUCBookmarkUIEvent.h>
-#include <Swift/Controllers/Settings/SettingsProvider.h>
-
namespace Swift {
-QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent) {
+QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent), isOnline_(false) {
eventStream_ = uiEventStream;
- settings_ = settings;;
+ settings_ = settings;
bookmarksEnabled_ = false;
model_ = new ChatListModel();
@@ -42,4 +45,5 @@ QtChatListWindow::QtChatListWindow(UIEventStream *uiEventStream, SettingsProvide
setAnimated(true);
setIndentation(0);
+ setDragEnabled(true);
setRootIsDecorated(true);
setupContextMenus();
@@ -55,4 +59,5 @@ QtChatListWindow::~QtChatListWindow() {
delete delegate_;
delete mucMenu_;
+ delete mucRecentsMenu_;
delete emptyMenu_;
}
@@ -65,4 +70,8 @@ void QtChatListWindow::handleSettingChanged(const std::string& setting) {
}
+void QtChatListWindow::handleClearRecentsRequested() {
+ onClearRecentsRequested();
+}
+
void QtChatListWindow::setBookmarksEnabled(bool enabled) {
bookmarksEnabled_ = enabled;
@@ -78,10 +87,12 @@ void QtChatListWindow::handleClicked(const QModelIndex& index) {
void QtChatListWindow::setupContextMenus() {
mucMenu_ = new QMenu();
- mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
- mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
- mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark()));
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Edit Bookmark"), this, SLOT(handleEditBookmark()));
+ onlineOnlyActions_ << mucMenu_->addAction(tr("Remove Bookmark"), this, SLOT(handleRemoveBookmark()));
+ mucRecentsMenu_ = new QMenu();
+ onlineOnlyActions_ << mucRecentsMenu_->addAction(tr("Add to Bookmarks"), this, SLOT(handleAddBookmarkFromRecents()));
+ mucRecentsMenu_->addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
emptyMenu_ = new QMenu();
- emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
-
+ onlineOnlyActions_ << emptyMenu_->addAction(tr("Add New Bookmark"), this, SLOT(handleAddBookmark()));
}
@@ -98,4 +109,9 @@ void QtChatListWindow::handleItemActivated(const QModelIndex& index) {
}
}
+ else if (ChatListWhiteboardItem* whiteboardItem = dynamic_cast<ChatListWhiteboardItem*>(item)) {
+ if (!whiteboardItem->getChat().isMUC || bookmarksEnabled_) {
+ eventStream_->send(boost::make_shared<ShowWhiteboardUIEvent>(whiteboardItem->getChat().jid));
+ }
+ }
}
@@ -112,4 +128,12 @@ void QtChatListWindow::removeMUCBookmark(const MUCBookmark& bookmark) {
}
+void QtChatListWindow::addWhiteboardSession(const ChatListWindow::Chat& chat) {
+ model_->addWhiteboardSession(chat);
+}
+
+void QtChatListWindow::removeWhiteboardSession(const JID& jid) {
+ model_->removeWhiteboardSession(jid);
+}
+
void QtChatListWindow::setRecents(const std::list<ChatListWindow::Chat>& recents) {
model_->setRecents(recents);
@@ -120,4 +144,8 @@ void QtChatListWindow::setUnreadCount(int unread) {
}
+void QtChatListWindow::setOnline(bool isOnline) {
+ isOnline_ = isOnline;
+}
+
void QtChatListWindow::handleRemoveBookmark() {
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(contextMenuItem_);
@@ -126,4 +154,15 @@ void QtChatListWindow::handleRemoveBookmark() {
}
+void QtChatListWindow::handleAddBookmarkFromRecents() {
+ ChatListRecentItem* item = dynamic_cast<ChatListRecentItem*>(contextMenuItem_);
+ if (item) {
+ const ChatListWindow::Chat& chat = item->getChat();
+ MUCBookmark bookmark(chat.jid, chat.jid.toBare().toString());
+ bookmark.setNick(chat.nick);
+ bookmark.setPassword(chat.password);
+ eventStream_->send(boost::shared_ptr<UIEvent>(new AddMUCBookmarkUIEvent(bookmark)));
+ }
+}
+
void QtChatListWindow::handleAddBookmark() {
(new QtAddBookmarkWindow(eventStream_))->show();
@@ -138,4 +177,9 @@ void QtChatListWindow::handleEditBookmark() {
}
+void QtChatListWindow::dragEnterEvent(QDragEnterEvent *event) {
+ if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
+ event->acceptProposedAction();
+ }
+}
void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
@@ -143,8 +187,14 @@ void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
ChatListItem* baseItem = index.isValid() ? static_cast<ChatListItem*>(index.internalPointer()) : NULL;
contextMenuItem_ = baseItem;
+
+ foreach(QAction* action, onlineOnlyActions_) {
+ action->setEnabled(isOnline_);
+ }
+
if (!baseItem) {
emptyMenu_->exec(QCursor::pos());
return;
}
+
ChatListMUCItem* mucItem = dynamic_cast<ChatListMUCItem*>(baseItem);
if (mucItem) {
@@ -153,14 +203,19 @@ void QtChatListWindow::contextMenuEvent(QContextMenuEvent* event) {
}
mucMenu_->exec(QCursor::pos());
+ return;
}
- else {
- QMenu menu;
- QAction* clearRecents = menu.addAction(tr("Clear recents"));
- menu.addAction(clearRecents);
- QAction* result = menu.exec(event->globalPos());
- if (result == clearRecents) {
- onClearRecentsRequested();
+
+ ChatListRecentItem* recentItem = dynamic_cast<ChatListRecentItem*>(baseItem);
+ if (recentItem) {
+ const ChatListWindow::Chat& chat = recentItem->getChat();
+ if (chat.isMUC) {
+ mucRecentsMenu_->exec(QCursor::pos());
+ return;
}
}
+
+ QMenu menu;
+ menu.addAction(tr("Clear recents"), this, SLOT(handleClearRecentsRequested()));
+ menu.exec(event->globalPos());
}
diff --git a/Swift/QtUI/ChatList/QtChatListWindow.h b/Swift/QtUI/ChatList/QtChatListWindow.h
index 33131ce..823e6dc 100644
--- a/Swift/QtUI/ChatList/QtChatListWindow.h
+++ b/Swift/QtUI/ChatList/QtChatListWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -23,8 +23,11 @@ namespace Swift {
void addMUCBookmark(const MUCBookmark& bookmark);
void removeMUCBookmark(const MUCBookmark& bookmark);
+ void addWhiteboardSession(const ChatListWindow::Chat& chat);
+ void removeWhiteboardSession(const JID& jid);
void setBookmarksEnabled(bool enabled);
void setRecents(const std::list<ChatListWindow::Chat>& recents);
void setUnreadCount(int unread);
void clearBookmarks();
+ virtual void setOnline(bool isOnline);
signals:
@@ -35,8 +38,11 @@ namespace Swift {
void handleEditBookmark();
void handleRemoveBookmark();
+ void handleAddBookmarkFromRecents();
void handleClicked(const QModelIndex& index);
void handleSettingChanged(const std::string& setting);
+ void handleClearRecentsRequested();
protected:
+ void dragEnterEvent(QDragEnterEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
@@ -49,6 +55,9 @@ namespace Swift {
QMenu* mucMenu_;
QMenu* emptyMenu_;
+ QMenu* mucRecentsMenu_;
ChatListItem* contextMenuItem_;
SettingsProvider* settings_;
+ QList<QAction*> onlineOnlyActions_;
+ bool isOnline_;
};
diff --git a/Swift/QtUI/ChatSnippet.cpp b/Swift/QtUI/ChatSnippet.cpp
index ab31d29..3436531 100644
--- a/Swift/QtUI/ChatSnippet.cpp
+++ b/Swift/QtUI/ChatSnippet.cpp
@@ -1,11 +1,13 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+#include <Swift/QtUI/ChatSnippet.h>
+
#include <QFile>
-#include "ChatSnippet.h"
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -40,3 +42,57 @@ QString ChatSnippet::wrapResizable(const QString& text) {
}
-};
+QString ChatSnippet::directionToCSS(Direction direction) {
+ return direction == RTL ? QString("rtl") : QString("ltr");
+}
+
+ChatSnippet::Direction ChatSnippet::getDirection(const ChatWindow::ChatMessage& message) {
+ boost::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
+ std::string text = "";
+ foreach (boost::shared_ptr<ChatWindow::ChatMessagePart> part, message.getParts()) {
+ if ((textPart = boost::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
+ text = textPart->text;
+ break;
+ }
+ }
+ return getDirection(text);
+}
+
+ChatSnippet::Direction ChatSnippet::getDirection(const std::string& message) {
+ return getDirection(P2QSTRING(message));
+}
+
+ChatSnippet::Direction ChatSnippet::getDirection(const QString& message) {
+ /*
+ for (int i = 0; i < message.size(); ++i) {
+ switch (message.at(i).direction()) {
+ case QChar::DirL:
+ case QChar::DirLRE:
+ case QChar::DirLRO:
+ return ChatSnippet::LTR;
+ case QChar::DirR:
+ case QChar::DirAL:
+ case QChar::DirRLE:
+ case QChar::DirRLO:
+ return ChatSnippet::RTL;
+ case QChar::DirEN:
+ case QChar::DirES:
+ case QChar::DirET:
+ case QChar::DirAN:
+ case QChar::DirCS:
+ case QChar::DirB:
+ case QChar::DirWS:
+ case QChar::DirON:
+ case QChar::DirS:
+ case QChar::DirPDF:
+ case QChar::DirNSM:
+ case QChar::DirBN:
+ break;
+ }
+ }
+ return ChatSnippet::LTR;
+ */
+ return message.isRightToLeft() ? ChatSnippet::RTL : ChatSnippet::LTR;
+}
+
+
+}
diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h
index f79f487..f60d486 100644
--- a/Swift/QtUI/ChatSnippet.h
+++ b/Swift/QtUI/ChatSnippet.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -11,9 +11,18 @@
#include <QString>
#include <QDateTime>
-#include "QtChatTheme.h"
+
+#include <Swiften/Base/foreach.h>
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+#include <Swift/QtUI/QtChatTheme.h>
+
namespace Swift {
class ChatSnippet {
public:
+ enum Direction {
+ RTL,
+ LTR
+ };
+
ChatSnippet(bool appendToPrevious);
virtual ~ChatSnippet();
@@ -32,7 +41,9 @@ namespace Swift {
result.replace("%message%", "&#37;message&#37;");
result.replace("%sender%", "&#37;sender&#37;");
+ result.replace("%wrapped_sender%", "&#37;wrapped_sender&#37;");
result.replace("%time%", "%&#37;time&#37;");
result.replace("%shortTime%", "%&#37;shortTime&#37;");
result.replace("%userIconPath%", "&#37;userIconPath&#37;");
+ result.replace("\t", " ");
result.replace(" ", "&nbsp;&nbsp;");
return result;
@@ -41,5 +52,11 @@ namespace Swift {
static QString timeToEscapedString(const QDateTime& time);
+ static Direction getDirection(const std::string& message);
+ static Direction getDirection(const ChatWindow::ChatMessage& message);
+ static Direction getDirection(const QString& message);
+
protected:
+ static QString directionToCSS(Direction direction);
+
QString wrapResizable(const QString& text);
void setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet> continuationFallback) {
diff --git a/Swift/QtUI/CocoaApplicationActivateHelper.h b/Swift/QtUI/CocoaApplicationActivateHelper.h
index c831183..8bc2af5 100644
--- a/Swift/QtUI/CocoaApplicationActivateHelper.h
+++ b/Swift/QtUI/CocoaApplicationActivateHelper.h
@@ -23,5 +23,5 @@ namespace Swift {
private:
- class Private;
+ struct Private;
Private* p;
};
diff --git a/Swift/QtUI/CocoaUIHelpers.h b/Swift/QtUI/CocoaUIHelpers.h
new file mode 100644
index 0000000..25da0e3
--- /dev/null
+++ b/Swift/QtUI/CocoaUIHelpers.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/TLS/Certificate.h>
+#include <QWidget>
+
+namespace Swift {
+
+class CocoaUIHelpers {
+public:
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+};
+
+}
+
diff --git a/Swift/QtUI/CocoaUIHelpers.mm b/Swift/QtUI/CocoaUIHelpers.mm
new file mode 100644
index 0000000..3cb62f3
--- /dev/null
+++ b/Swift/QtUI/CocoaUIHelpers.mm
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "CocoaUIHelpers.h"
+
+#include <boost/shared_ptr.hpp>
+#include <boost/type_traits.hpp>
+
+#include <Cocoa/Cocoa.h>
+
+#include <Security/Security.h>
+#include <SecurityInterface/SFCertificatePanel.h>
+
+#include <Swiften/Base/foreach.h>
+
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+
+namespace Swift {
+
+void CocoaUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
+ NSWindow* parentWindow = [((NSView*)parent->winId()) window];
+ NSMutableArray* certificates = [[NSMutableArray alloc] init];
+ foreach(Certificate::ref cert, chain) {
+ // convert chain to SecCertificateRef
+ ByteArray certAsDER = cert->toDER();
+ boost::shared_ptr<boost::remove_pointer<CFDataRef>::type> certData(CFDataCreate(NULL, certAsDER.data(), certAsDER.size()), CFRelease);
+ boost::shared_ptr<OpaqueSecCertificateRef> macCert(SecCertificateCreateWithData(NULL, certData.get()), CFRelease);
+
+ // add to NSMutable array
+ [certificates addObject: (id)macCert.get()];
+ }
+
+
+ SFCertificatePanel* panel = [[SFCertificatePanel alloc] init];
+ //[panel setPolicies:(id)policies.get()];
+ [panel beginSheetForWindow:parentWindow modalDelegate:nil didEndSelector:NULL contextInfo:NULL certificates:certificates showGroup:YES];
+ [certificates release];
+}
+
+}
diff --git a/Swift/QtUI/EventViewer/EventDelegate.cpp b/Swift/QtUI/EventViewer/EventDelegate.cpp
index 9ecdd34..c0904b3 100644
--- a/Swift/QtUI/EventViewer/EventDelegate.cpp
+++ b/Swift/QtUI/EventViewer/EventDelegate.cpp
@@ -30,6 +30,7 @@ QSize EventDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIn
case ErrorEventType: return errorDelegate_.sizeHint(option, item);
case MUCInviteEventType: return mucInviteDelegate_.sizeHint(option, item);
- default: return QStyledItemDelegate::sizeHint(option, index);
}
+ assert(false);
+ return QSize();
}
@@ -45,5 +46,4 @@ void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
case ErrorEventType: errorDelegate_.paint(painter, option, item);break;
case MUCInviteEventType: mucInviteDelegate_.paint(painter, option, item);break;
- default: QStyledItemDelegate::paint(painter, option, index);
}
}
@@ -51,11 +51,19 @@ void EventDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
EventType EventDelegate::getEventType(boost::shared_ptr<StanzaEvent> event) const {
boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(event);
- if (messageEvent) return MessageEventType;
+ if (messageEvent) {
+ return MessageEventType;
+ }
boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(event);
- if (subscriptionEvent) return SubscriptionEventType;
+ if (subscriptionEvent) {
+ return SubscriptionEventType;
+ }
boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(event);
- if (errorEvent) return ErrorEventType;
+ if (errorEvent) {
+ return ErrorEventType;
+ }
boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(event);
- if (mucInviteEvent) return MUCInviteEventType;
+ if (mucInviteEvent) {
+ return MUCInviteEventType;
+ }
//I don't know what this is.
assert(false);
diff --git a/Swift/QtUI/EventViewer/QtEvent.cpp b/Swift/QtUI/EventViewer/QtEvent.cpp
index 3c6f16c..c3ff944 100644
--- a/Swift/QtUI/EventViewer/QtEvent.cpp
+++ b/Swift/QtUI/EventViewer/QtEvent.cpp
@@ -8,4 +8,5 @@
#include <QDateTime>
+#include <QColor>
#include "Swift/Controllers/XMPPEvents/MessageEvent.h"
@@ -26,6 +27,6 @@ QVariant QtEvent::data(int role) {
case Qt::ToolTipRole: return QVariant(text()).toString() + "\n" + B2QDATE(event_->getTime()).toString();
case Qt::DisplayRole: return QVariant(text());
- case Qt::TextColorRole: return active_ ? Qt::black : Qt::darkGray;
- case Qt::BackgroundColorRole: return active_ ? Qt::white : Qt::lightGray;
+ case Qt::TextColorRole: return QColor(active_ ? Qt::black : Qt::darkGray);
+ case Qt::BackgroundColorRole: return QColor(active_ ? Qt::white : Qt::lightGray);
case SenderRole: return QVariant(sender());
/*case StatusTextRole: return statusText_;
diff --git a/Swift/QtUI/EventViewer/QtEvent.h b/Swift/QtUI/EventViewer/QtEvent.h
index f5e3dee..11efd60 100644
--- a/Swift/QtUI/EventViewer/QtEvent.h
+++ b/Swift/QtUI/EventViewer/QtEvent.h
@@ -18,5 +18,5 @@ namespace Swift {
QtEvent(boost::shared_ptr<StanzaEvent> event, bool active);
QVariant data(int role);
- boost::shared_ptr<StanzaEvent> getEvent() { return event_; };
+ boost::shared_ptr<StanzaEvent> getEvent() { return event_; }
enum EventRoles {
SenderRole = Qt::UserRole
diff --git a/Swift/QtUI/FreeDesktopNotifier.cpp b/Swift/QtUI/FreeDesktopNotifier.cpp
index 2393340..1f1ccda 100644
--- a/Swift/QtUI/FreeDesktopNotifier.cpp
+++ b/Swift/QtUI/FreeDesktopNotifier.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -14,4 +14,7 @@
#include <QtDBus/QtDBus>
#include <algorithm>
+#include <Swiften/Base/Path.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -44,5 +47,5 @@ void FreeDesktopNotifier::showMessage(Type type, const std::string& subject, con
msg << applicationName.c_str();
msg << quint32(0); // ID of previous notification to replace
- msg << imageScaler.getScaledImage(picture, 48).string().c_str(); // Icon to display
+ msg << P2QSTRING(pathToString(imageScaler.getScaledImage(picture, 48))); // Icon to display
msg << subject.c_str(); // Summary / Header of the message to display
msg << body; // Body of the message to display
diff --git a/Swift/QtUI/FreeDesktopNotifier.h b/Swift/QtUI/FreeDesktopNotifier.h
index 4ba02b4..6da7621 100644
--- a/Swift/QtUI/FreeDesktopNotifier.h
+++ b/Swift/QtUI/FreeDesktopNotifier.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010 -2012 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -16,7 +16,6 @@ namespace Swift {
virtual void showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()> callback);
- virtual void purgeCallbacks() {
-#warning FIXME implement.
- };
+ virtual void purgeCallbacks() {}
+
private:
std::string applicationName;
diff --git a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
index 2fa24c2..7bd16e3 100644
--- a/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
+++ b/Swift/QtUI/MUCSearch/QtMUCSearchWindow.cpp
@@ -24,5 +24,5 @@ namespace Swift {
QtMUCSearchWindow::QtMUCSearchWindow() {
ui_.setupUi(this);
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp
index 7505905..28c44c4 100644
--- a/Swift/QtUI/MessageSnippet.cpp
+++ b/Swift/QtUI/MessageSnippet.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -12,7 +12,7 @@
namespace Swift {
-MessageSnippet::MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id) : ChatSnippet(appendToPrevious) {
+MessageSnippet::MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction) : ChatSnippet(appendToPrevious) {
if (appendToPrevious) {
- setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new MessageSnippet(message, sender, time, iconURI, isIncoming, false, theme, id)));
+ setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new MessageSnippet(message, sender, time, iconURI, isIncoming, false, theme, id, direction)));
}
if (isIncoming) {
@@ -33,9 +33,12 @@ MessageSnippet::MessageSnippet(const QString& message, const QString& sender, co
}
+ content_.replace("%direction%", directionToCSS(direction));
content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span><span class='swift_ack'></span><span class='swift_receipt'></span>"));
- content_.replace("%sender%", wrapResizable(escape(sender)));
+ content_.replace("%wrapped_sender%", wrapResizable(escape(sender)));
+ content_.replace("%sender%", escape(sender));
content_.replace("%time%", wrapResizable("<span class='swift_time'>" + timeToEscapedString(time) + "</span>"));
content_.replace("%userIconPath%", escape(iconURI));
- content_ = "<div id='" + id + "'>" + content_ + "</div>";
+ content_ = QString("<div id='%1'>%2</div>").arg(id).arg(content_);
+ content_ = "<span class='date" + time.date().toString(Qt::ISODate) + "'>" + content_ + "</span>";
}
diff --git a/Swift/QtUI/MessageSnippet.h b/Swift/QtUI/MessageSnippet.h
index c7425e9..8186d19 100644
--- a/Swift/QtUI/MessageSnippet.h
+++ b/Swift/QtUI/MessageSnippet.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -16,5 +16,5 @@ namespace Swift {
class MessageSnippet : public ChatSnippet {
public:
- MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id);
+ MessageSnippet(const QString& message, const QString& sender, const QDateTime& time, const QString& iconURI, bool isIncoming, bool appendToPrevious, QtChatTheme* theme, const QString& id, Direction direction);
virtual ~MessageSnippet();
const QString& getContent() const {
@@ -24,5 +24,5 @@ namespace Swift {
QString getContinuationElementID() const {
return "insert";
- };
+ }
private:
diff --git a/Swift/QtUI/QtAboutWidget.cpp b/Swift/QtUI/QtAboutWidget.cpp
index acdc61e..c00acf7 100644
--- a/Swift/QtUI/QtAboutWidget.cpp
+++ b/Swift/QtUI/QtAboutWidget.cpp
@@ -20,5 +20,5 @@ namespace Swift {
QtAboutWidget::QtAboutWidget() : QDialog() {
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
setWindowTitle(QString(tr("About %1")).arg("Swift"));
#endif
diff --git a/Swift/QtUI/QtAdHocCommandWindow.cpp b/Swift/QtUI/QtAdHocCommandWindow.cpp
index 88aa708..5f99dba 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.cpp
+++ b/Swift/QtUI/QtAdHocCommandWindow.cpp
@@ -1,13 +1,14 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include <Swift/QtUI/QtAdHocCommandWindow.h>
-
#include <boost/bind.hpp>
#include <QBoxLayout>
+#include <Swift/QtUI/QtAdHocCommandWindow.h>
#include <Swift/QtUI/QtFormWidget.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/Base/format.h>
#include <Swiften/Elements/Command.h>
@@ -16,5 +17,4 @@ const int FormLayoutIndex = 1;
namespace Swift {
QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) : command_(command) {
- someActions_ = false;
formWidget_ = NULL;
@@ -30,4 +30,11 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
label_->setTextFormat(Qt::PlainText);
layout_->addWidget(label_);
+
+ errorLabel_ = new QLabel(this);
+ errorLabel_->setText(QString("<b>%1</b>").arg(tr("Unable to complete the command because you have been disconnected")));
+ errorLabel_->setVisible(false);
+ errorLabel_->setFrameStyle(QFrame::Box|QFrame::Sunken);
+ layout_->addWidget(errorLabel_);
+
QWidget* buttonsWidget = new QWidget(this);
layout_->addWidget(buttonsWidget);
@@ -49,4 +56,5 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
backButton_->setEnabled(false);
completeButton_->setEnabled(false);
+
actions_[Command::Next] = nextButton_;
actions_[Command::Prev] = backButton_;
@@ -56,5 +64,17 @@ QtAdHocCommandWindow::QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocComman
QtAdHocCommandWindow::~QtAdHocCommandWindow() {
+}
+
+void QtAdHocCommandWindow::setOnline(bool online) {
+ if (!online) {
+ nextButton_->setEnabled(false);
+ backButton_->setEnabled(false);
+ completeButton_->setEnabled(false);
+ errorLabel_->setVisible(true);
+ }
+}
+void QtAdHocCommandWindow::closeEvent(QCloseEvent*) {
+ onClosing();
}
@@ -77,14 +97,10 @@ void QtAdHocCommandWindow::handleCompleteClicked() {
void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
- if (command->getForm()) {
- setForm(command->getForm());
- } else {
- setNoForm();
- }
QString notes;
foreach (Command::Note note, command->getNotes()) {
if (!notes.isEmpty()) {
notes += "\n";
- QString qNote(note.note.c_str());
+ }
+ QString qNote(P2QSTRING(note.note));
switch (note.type) {
case Command::Note::Error: notes += tr("Error: %1").arg(qNote); break;
@@ -93,6 +109,10 @@ void QtAdHocCommandWindow::handleNextStageReceived(Command::ref command) {
}
}
- }
label_->setText(notes);
+ if (command->getForm()) {
+ setForm(command->getForm());
+ } else {
+ setNoForm(notes.isEmpty());
+ }
setAvailableActions(command);
}
@@ -106,15 +126,17 @@ void QtAdHocCommandWindow::handleError(ErrorPayload::ref /*error*/) {
void QtAdHocCommandWindow::setForm(Form::ref form) {
+ form_ = form;
delete formWidget_;
formWidget_ = new QtFormWidget(form, this);
layout_->insertWidget(FormLayoutIndex, formWidget_);
show();
- formWidget_->setEditable(someActions_);
}
-void QtAdHocCommandWindow::setNoForm() {
+void QtAdHocCommandWindow::setNoForm(bool andHide) {
+ form_.reset();
delete formWidget_;
formWidget_ = NULL;
- show();
+ resize(minimumSize());
+ setVisible(!andHide);
}
@@ -122,5 +144,4 @@ typedef std::pair<Command::Action, QPushButton*> ActionButton;
void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
- someActions_ = false;
foreach (ActionButton pair, actions_) {
OutgoingAdHocCommandSession::ActionState state = command_->getActionState(pair.first);
@@ -133,5 +154,4 @@ void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
if (state & OutgoingAdHocCommandSession::Enabled) {
pair.second->setEnabled(true);
- someActions_ = true;
}
else {
@@ -139,7 +159,4 @@ void QtAdHocCommandWindow::setAvailableActions(Command::ref /*commandResult*/) {
}
}
- if (formWidget_) {
- formWidget_->setEditable(someActions_);
- }
}
diff --git a/Swift/QtUI/QtAdHocCommandWindow.h b/Swift/QtUI/QtAdHocCommandWindow.h
index 7f824f8..0e398af 100644
--- a/Swift/QtUI/QtAdHocCommandWindow.h
+++ b/Swift/QtUI/QtAdHocCommandWindow.h
@@ -23,9 +23,11 @@ namespace Swift {
QtAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
virtual ~QtAdHocCommandWindow();
+ virtual void setOnline(bool online);
private:
+ void closeEvent(QCloseEvent* event);
void handleNextStageReceived(Command::ref command);
void handleError(ErrorPayload::ref error);
void setForm(Form::ref);
- void setNoForm();
+ void setNoForm(bool andHide);
void setAvailableActions(Command::ref commandResult);
private slots:
@@ -39,4 +41,5 @@ namespace Swift {
Form::ref form_;
QLabel* label_;
+ QLabel* errorLabel_;
QPushButton* backButton_;
QPushButton* nextButton_;
@@ -45,5 +48,4 @@ namespace Swift {
std::map<Command::Action, QPushButton*> actions_;
QBoxLayout* layout_;
- bool someActions_;
};
}
diff --git a/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp b/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp
new file mode 100644
index 0000000..7f33f77
--- /dev/null
+++ b/Swift/QtUI/QtAdHocCommandWithJIDWindow.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2010-2014 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/bind.hpp>
+#include <QLabel>
+#include <QPushButton>
+#include <QBoxLayout>
+#include <QDialogButtonBox>
+#include <Swiften/Elements/Command.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/Controllers/UIEvents/RequestAdHocWithJIDUIEvent.h>
+#include <Swift/QtUI/QtAdHocCommandWithJIDWindow.h>
+#include <Swift/QtUI/QtFormWidget.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+const int FormLayoutIndex = 1;
+
+namespace Swift {
+QtAdHocCommandWithJIDWindow::QtAdHocCommandWithJIDWindow(UIEventStream* uiEventStream) : uiEventStream_(uiEventStream) {
+ QVBoxLayout* hlayout = new QVBoxLayout(this);
+
+ QLabel* jidLabel = new QLabel("JID:", this);
+ hlayout->addWidget(jidLabel);
+ jid_ = new QLineEdit(this);
+ hlayout->addWidget(jid_);
+
+ QLabel* commandLabel = new QLabel("Command:", this);
+ hlayout->addWidget(commandLabel);
+ node_ = new QLineEdit(this);
+ hlayout->addWidget(node_);
+
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
+ QPushButton* rejectButton = buttonBox->addButton("Cancel", QDialogButtonBox::RejectRole);
+ connect(rejectButton, SIGNAL(clicked()), this, SLOT(handleRejectClick()));
+ QPushButton* acceptButton = buttonBox->addButton("Complete", QDialogButtonBox::AcceptRole);
+ connect(acceptButton, SIGNAL(clicked()), this, SLOT(handleAcceptClick()));
+ hlayout->addWidget(buttonBox);
+
+ setLayout(hlayout);
+ show();
+}
+
+QtAdHocCommandWithJIDWindow::~QtAdHocCommandWithJIDWindow() {
+}
+
+void QtAdHocCommandWithJIDWindow::handleAcceptClick() {
+ const JID jid = JID(Q2PSTRING(jid_->text()));
+ const std::string node = Q2PSTRING(node_->text());
+ boost::shared_ptr<UIEvent> event(new RequestAdHocWithJIDUIEvent(jid, node));
+ uiEventStream_->send(event);
+ accept();
+}
+
+void QtAdHocCommandWithJIDWindow::handleRejectClick() {
+ reject();
+}
+
+}
diff --git a/Swift/QtUI/QtAdHocCommandWithJIDWindow.h b/Swift/QtUI/QtAdHocCommandWithJIDWindow.h
new file mode 100644
index 0000000..b168827
--- /dev/null
+++ b/Swift/QtUI/QtAdHocCommandWithJIDWindow.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2010-2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QDialog>
+#include <QLineEdit>
+
+#include <Swiften/AdHoc/OutgoingAdHocCommandSession.h>
+
+class QBoxLayout;
+
+namespace Swift {
+ class UIEventStream;
+ class QtFormWidget;
+ class QtAdHocCommandWithJIDWindow : public QDialog {
+ Q_OBJECT
+ public:
+ QtAdHocCommandWithJIDWindow(UIEventStream* eventStream);
+ virtual ~QtAdHocCommandWithJIDWindow();
+ public slots:
+ void handleAcceptClick();
+ void handleRejectClick();
+ private:
+ UIEventStream* uiEventStream_;
+ QLineEdit* jid_;
+ QLineEdit* node_;
+ };
+}
diff --git a/Swift/QtUI/QtAddBookmarkWindow.cpp b/Swift/QtUI/QtAddBookmarkWindow.cpp
index 675ea03..230f2ed 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.cpp
+++ b/Swift/QtUI/QtAddBookmarkWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -14,4 +14,8 @@ QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream) : eventStre
}
+QtAddBookmarkWindow::QtAddBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark) : eventStream_(eventStream) {
+ createFormFromBookmark(bookmark);
+}
+
bool QtAddBookmarkWindow::commit() {
boost::optional<MUCBookmark> bookmark = createBookmarkFromForm();
diff --git a/Swift/QtUI/QtAddBookmarkWindow.h b/Swift/QtUI/QtAddBookmarkWindow.h
index f026cc3..c0dc214 100644
--- a/Swift/QtUI/QtAddBookmarkWindow.h
+++ b/Swift/QtUI/QtAddBookmarkWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -17,4 +17,5 @@ namespace Swift {
public:
QtAddBookmarkWindow(UIEventStream* eventStream);
+ QtAddBookmarkWindow(UIEventStream* eventStream, const MUCBookmark& bookmark);
bool commit();
private:
diff --git a/Swift/QtUI/QtAffiliationEditor.cpp b/Swift/QtUI/QtAffiliationEditor.cpp
index ed03c23..0896b92 100644
--- a/Swift/QtUI/QtAffiliationEditor.cpp
+++ b/Swift/QtUI/QtAffiliationEditor.cpp
diff --git a/Swift/QtUI/QtAffiliationEditor.h b/Swift/QtUI/QtAffiliationEditor.h
index 913b2cc..96536eb 100644
--- a/Swift/QtUI/QtAffiliationEditor.h
+++ b/Swift/QtUI/QtAffiliationEditor.h
diff --git a/Swift/QtUI/QtAffiliationEditor.ui b/Swift/QtUI/QtAffiliationEditor.ui
index 1447884..0a9b7bf 100644
--- a/Swift/QtUI/QtAffiliationEditor.ui
+++ b/Swift/QtUI/QtAffiliationEditor.ui
@@ -12,5 +12,5 @@
</property>
<property name="windowTitle">
- <string>Dialog</string>
+ <string>Edit Affiliations</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
diff --git a/Swift/QtUI/QtAvatarWidget.cpp b/Swift/QtUI/QtAvatarWidget.cpp
index f0bdf3c..fa08c27 100644
--- a/Swift/QtUI/QtAvatarWidget.cpp
+++ b/Swift/QtUI/QtAvatarWidget.cpp
@@ -1,8 +1,10 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+
+
#include "QtAvatarWidget.h"
@@ -20,8 +22,9 @@
#include <QtSwiftUtil.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
-QtAvatarWidget::QtAvatarWidget(QWidget* parent) : QWidget(parent) {
+QtAvatarWidget::QtAvatarWidget(QWidget* parent) : QWidget(parent), editable(false) {
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0,0,0,0);
@@ -69,4 +72,7 @@ void QtAvatarWidget::setAvatar(const ByteArray& data, const std::string& type) {
void QtAvatarWidget::mousePressEvent(QMouseEvent* event) {
+ if (!editable) {
+ return;
+ }
QMenu menu;
@@ -82,5 +88,5 @@ void QtAvatarWidget::mousePressEvent(QMouseEvent* event) {
if (!fileName.isEmpty()) {
ByteArray data;
- readByteArrayFromFile(data, Q2PSTRING(fileName));
+ readByteArrayFromFile(data, stringToPath(Q2PSTRING(fileName)));
QBuffer buffer;
diff --git a/Swift/QtUI/QtAvatarWidget.h b/Swift/QtUI/QtAvatarWidget.h
index 8830d82..f4ac4cf 100644
--- a/Swift/QtUI/QtAvatarWidget.h
+++ b/Swift/QtUI/QtAvatarWidget.h
@@ -16,4 +16,5 @@ namespace Swift {
class QtAvatarWidget : public QWidget {
Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
public:
QtAvatarWidget(QWidget* parent);
@@ -29,7 +30,16 @@ namespace Swift {
}
+ void setEditable(bool b) {
+ editable = b;
+ }
+
+ bool isEditable() const {
+ return editable;
+ }
+
void mousePressEvent(QMouseEvent* event);
private:
+ bool editable;
ByteArray data;
std::string type;
diff --git a/Swift/QtUI/QtBlockListEditorWindow.cpp b/Swift/QtUI/QtBlockListEditorWindow.cpp
new file mode 100644
index 0000000..82500df
--- /dev/null
+++ b/Swift/QtUI/QtBlockListEditorWindow.cpp
@@ -0,0 +1,226 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <QtBlockListEditorWindow.h>
+#include <ui_QtBlockListEditorWindow.h>
+
+#include <boost/bind.hpp>
+
+#include <QLineEdit>
+#include <QMovie>
+#include <QShortcut>
+#include <QStyledItemDelegate>
+#include <QValidator>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Client/ClientBlockListManager.h>
+#include <Swiften/JID/JID.h>
+
+namespace Swift {
+
+class QtJIDValidator : public QValidator {
+ public:
+ QtJIDValidator(QObject* parent) : QValidator(parent) {}
+ virtual ~QtJIDValidator() {}
+ virtual QValidator::State validate(QString& input, int&) const {
+ return JID(Q2PSTRING(input)).isValid() ? Acceptable : Intermediate;
+ }
+};
+
+class QtJIDValidatedItemDelegate : public QItemDelegate {
+ public:
+ QtJIDValidatedItemDelegate(QObject* parent) : QItemDelegate(parent) {}
+ virtual ~QtJIDValidatedItemDelegate() {}
+
+ virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex&) const {
+ QLineEdit *editor = new QLineEdit(parent);
+ editor->setValidator(new QtJIDValidator(editor));
+ return editor;
+ }
+
+ void setEditorData(QWidget *editor, const QModelIndex &index) const {
+ QString value = index.model()->data(index, Qt::EditRole).toString();
+
+ QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
+ lineEdit->setText(value);
+ }
+
+ void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
+ QLineEdit *lineEdit = static_cast<QLineEdit*>(editor);
+ QString currentValue = lineEdit->text();
+ int pos = 0;
+ if (lineEdit->validator()->validate(currentValue, pos) == QValidator::Acceptable) {
+ model->setData(index, lineEdit->text(), Qt::EditRole);
+ } else {
+ model->setData(index, QString(), Qt::EditRole);
+ }
+ }
+
+ void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
+ editor->setGeometry(option.rect);
+ }
+};
+
+QtBlockListEditorWindow::QtBlockListEditorWindow() : QWidget(), ui(new Ui::QtBlockListEditorWindow), removeItemDelegate(0), editItemDelegate(0) {
+ ui->setupUi(this);
+
+ freshBlockListTemplate = tr("Double-click to add contact");
+
+ new QShortcut(QKeySequence::Close, this, SLOT(close()));
+ ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+
+ removeItemDelegate = new QtRemovableItemDelegate(style());
+ editItemDelegate = new QtJIDValidatedItemDelegate(this);
+
+ connect(ui->savePushButton, SIGNAL(clicked()), SLOT(applyChanges()));
+
+ ui->blockListTreeWidget->setColumnCount(2);
+ ui->blockListTreeWidget->header()->setStretchLastSection(false);
+ ui->blockListTreeWidget->header()->resizeSection(1, removeItemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+
+#if QT_VERSION >= 0x050000
+ ui->blockListTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+#else
+ ui->blockListTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
+#endif
+
+ ui->blockListTreeWidget->setHeaderHidden(true);
+ ui->blockListTreeWidget->setRootIsDecorated(false);
+ ui->blockListTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
+ ui->blockListTreeWidget->setItemDelegateForColumn(0, editItemDelegate);
+ ui->blockListTreeWidget->setItemDelegateForColumn(1, removeItemDelegate);
+ connect(ui->blockListTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
+ ui->blockListTreeWidget->installEventFilter(this);
+
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
+}
+
+QtBlockListEditorWindow::~QtBlockListEditorWindow() {
+}
+
+void QtBlockListEditorWindow::show() {
+ QWidget::showNormal();
+ QWidget::activateWindow();
+ QWidget::raise();
+}
+
+void QtBlockListEditorWindow::hide() {
+ QWidget::hide();
+}
+
+void QtBlockListEditorWindow::handleItemChanged(QTreeWidgetItem *item, int) {
+ // check whether changed item contains a valid JID and make it removable
+ if (item && item->text(0) != freshBlockListTemplate) {
+ item->setText(1, "");
+ }
+
+ // check for empty rows and add an empty one so the user can add items
+ bool hasEmptyRow = false;
+ for( int i = 0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i ) {
+ QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
+ if (row->text(0) == freshBlockListTemplate) {
+ hasEmptyRow = true;
+ }
+ else if (row->text(0).isEmpty()) {
+ ui->blockListTreeWidget->removeItemWidget(row, 0);
+ }
+ }
+
+ if (!hasEmptyRow) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(freshBlockListTemplate) << "x");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
+ }
+
+ if (!item) {
+ ui->blockListTreeWidget->setCurrentItem(ui->blockListTreeWidget->topLevelItem(0));
+ }
+}
+
+void QtBlockListEditorWindow::applyChanges() {
+ onSetNewBlockList(getCurrentBlockList());
+}
+
+void QtBlockListEditorWindow::setCurrentBlockList(const std::vector<JID> &blockedJIDs) {
+ ui->blockListTreeWidget->clear();
+
+ foreach(const JID& jid, blockedJIDs) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(jid.toString())) << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ ui->blockListTreeWidget->addTopLevelItem(item);
+ }
+ handleItemChanged(0,0);
+}
+
+void QtBlockListEditorWindow::setBusy(bool isBusy) {
+ if (isBusy) {
+ ui->throbberLabel->movie()->start();
+ ui->throbberLabel->show();
+ ui->blockListTreeWidget->setEnabled(false);
+ ui->savePushButton->setEnabled(false);
+ } else {
+ ui->throbberLabel->movie()->stop();
+ ui->throbberLabel->hide();
+ ui->blockListTreeWidget->setEnabled(true);
+ ui->savePushButton->setEnabled(true);
+ }
+}
+
+void QtBlockListEditorWindow::setError(const std::string& error) {
+ if (!error.empty()) {
+ ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
+ }
+ else {
+ ui->errorLabel->setText("");
+ }
+}
+
+std::vector<JID> Swift::QtBlockListEditorWindow::getCurrentBlockList() const {
+ std::vector<JID> futureBlockedJIDs;
+
+ for(int i=0; i < ui->blockListTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = ui->blockListTreeWidget->topLevelItem(i);
+ JID jid = JID(Q2PSTRING(row->text(0)));
+ if (!jid.toString().empty() && jid.isValid()) {
+ futureBlockedJIDs.push_back(jid);
+ }
+ }
+ return futureBlockedJIDs;
+}
+
+bool QtBlockListEditorWindow::eventFilter(QObject* target, QEvent* event) {
+ if (target == ui->blockListTreeWidget) {
+ if (event->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Backspace) {
+ // remove currently selected item
+ QTreeWidgetItem* currentItem = ui->blockListTreeWidget->currentItem();
+ if (currentItem->text(0) != freshBlockListTemplate) {
+ ui->blockListTreeWidget->takeTopLevelItem(ui->blockListTreeWidget->indexOfTopLevelItem(currentItem));
+ return true;
+ }
+ }
+ else if (keyEvent->key() == Qt::Key_Return) {
+ // open editor for return key d
+ ui->blockListTreeWidget->editItem(ui->blockListTreeWidget->currentItem(), 0);
+ return true;
+ }
+ }
+ }
+ return QWidget::eventFilter(target, event);
+}
+
+}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.h b/Swift/QtUI/QtBlockListEditorWindow.h
new file mode 100644
index 0000000..dd083fd
--- /dev/null
+++ b/Swift/QtUI/QtBlockListEditorWindow.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swift/Controllers/UIInterfaces/BlockListEditorWidget.h>
+#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h>
+
+#include <QWidget>
+#include <QTreeWidgetItem>
+
+namespace Ui {
+ class QtBlockListEditorWindow;
+}
+
+namespace Swift {
+
+class QtJIDValidatedItemDelegate;
+
+class QtBlockListEditorWindow : public QWidget, public BlockListEditorWidget {
+ Q_OBJECT
+
+ public:
+ QtBlockListEditorWindow();
+ virtual ~QtBlockListEditorWindow();
+
+ virtual void show();
+ virtual void hide();
+ virtual void setCurrentBlockList(const std::vector<JID>& blockedJIDs);
+ virtual void setBusy(bool isBusy);
+ virtual void setError(const std::string& error);
+ virtual std::vector<JID> getCurrentBlockList() const;
+ virtual bool eventFilter(QObject* target, QEvent* event);
+
+ private slots:
+ void handleItemChanged(QTreeWidgetItem*, int);
+ void applyChanges();
+
+ private:
+ Ui::QtBlockListEditorWindow* ui;
+ QtRemovableItemDelegate* removeItemDelegate;
+ QtJIDValidatedItemDelegate* editItemDelegate;
+ QString freshBlockListTemplate;
+};
+
+}
diff --git a/Swift/QtUI/QtBlockListEditorWindow.ui b/Swift/QtUI/QtBlockListEditorWindow.ui
new file mode 100644
index 0000000..a611890
--- /dev/null
+++ b/Swift/QtUI/QtBlockListEditorWindow.ui
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtBlockListEditorWindow</class>
+ <widget class="QWidget" name="QtBlockListEditorWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>333</width>
+ <height>262</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Edit Block List</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>5</number>
+ </property>
+ <property name="leftMargin">
+ <number>5</number>
+ </property>
+ <property name="topMargin">
+ <number>5</number>
+ </property>
+ <property name="rightMargin">
+ <number>5</number>
+ </property>
+ <property name="bottomMargin">
+ <number>5</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;The follwing list shows all contacts that you have currently blocked. You can add contacts to the list at the buttom of the list and remove contacts by clicking on the right column.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::RichText</enum>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignJustify|Qt::AlignVCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTreeWidget" name="blockListTreeWidget">
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string notr="true">1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
+ <item>
+ <widget class="QLabel" name="errorLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="throbberLabel">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::NoTextInteraction</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="savePushButton">
+ <property name="text">
+ <string>Save</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.cpp b/Swift/QtUI/QtBookmarkDetailWindow.cpp
index ae84b4b..1e84067 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.cpp
+++ b/Swift/QtUI/QtBookmarkDetailWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -16,4 +16,5 @@ QtBookmarkDetailWindow::QtBookmarkDetailWindow(QWidget* parent) : QDialog(parent
//connect(buttons_, SIGNAL(accepted()), SLOT(accept()));
//connect(buttons_, SIGNAL(rejected()), SLOT(reject()));
+ setFixedHeight(sizeHint().height());
}
@@ -50,3 +51,27 @@ boost::optional<MUCBookmark> QtBookmarkDetailWindow::createBookmarkFromForm() {
}
+void QtBookmarkDetailWindow::createFormFromBookmark(const MUCBookmark& bookmark) {
+ if (bookmark.getRoom().isValid()) {
+ room_->setText(P2QSTRING(bookmark.getRoom().toString()));
+ }
+
+ if (!bookmark.getName().empty()) {
+ name_->setText(P2QSTRING(bookmark.getName()));
+ }
+
+ if (bookmark.getNick()) {
+ nick_->setText(P2QSTRING((*bookmark.getNick())));
+ }
+
+ if (bookmark.getPassword()) {
+ password_->setText(P2QSTRING((*bookmark.getPassword())));
+ }
+
+ if (bookmark.getAutojoin()) {
+ autojoin_->setCheckState(Qt::Checked);
+ } else {
+ autojoin_->setCheckState(Qt::Unchecked);
+ }
+}
+
}
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.h b/Swift/QtUI/QtBookmarkDetailWindow.h
index fd2b7b4..b223719 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.h
+++ b/Swift/QtUI/QtBookmarkDetailWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -23,4 +23,7 @@ namespace Swift {
boost::optional<MUCBookmark> createBookmarkFromForm();
+ protected:
+ void createFormFromBookmark(const MUCBookmark& bookmark);
+
public slots:
void accept();
diff --git a/Swift/QtUI/QtBookmarkDetailWindow.ui b/Swift/QtUI/QtBookmarkDetailWindow.ui
index 4a37b2f..be55686 100644
--- a/Swift/QtUI/QtBookmarkDetailWindow.ui
+++ b/Swift/QtUI/QtBookmarkDetailWindow.ui
@@ -7,6 +7,6 @@
<x>0</x>
<y>0</y>
- <width>396</width>
- <height>282</height>
+ <width>382</width>
+ <height>207</height>
</rect>
</property>
@@ -23,16 +23,24 @@
<bool>false</bool>
</property>
- <widget class="QWidget" name="layoutWidget">
- <property name="geometry">
- <rect>
- <x>10</x>
- <y>20</y>
- <width>371</width>
- <height>241</height>
- </rect>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="leftMargin">
+ <number>12</number>
+ </property>
+ <property name="topMargin">
+ <number>12</number>
+ </property>
+ <property name="rightMargin">
+ <number>12</number>
+ </property>
+ <property name="bottomMargin">
+ <number>12</number>
</property>
+ <item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
<item row="0" column="0">
<widget class="QLabel" name="label">
@@ -111,5 +119,6 @@
</item>
</layout>
- </widget>
+ </item>
+ </layout>
</widget>
<resources/>
diff --git a/Swift/QtUI/QtCachedImageScaler.cpp b/Swift/QtUI/QtCachedImageScaler.cpp
index 7307577..45375e7 100644
--- a/Swift/QtUI/QtCachedImageScaler.cpp
+++ b/Swift/QtUI/QtCachedImageScaler.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -9,4 +9,6 @@
#include <QImage>
#include <boost/lexical_cast.hpp>
+#include <Swiften/Base/Path.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -16,14 +18,16 @@ QtCachedImageScaler::QtCachedImageScaler() {
boost::filesystem::path QtCachedImageScaler::getScaledImage(const boost::filesystem::path& imagePath, int size) {
- boost::filesystem::path scaledImagePath(imagePath.string() + "." + boost::lexical_cast<std::string>(size));
+ boost::filesystem::path scaledImagePath(imagePath);
+ std::string suffix = "." + boost::lexical_cast<std::string>(size);
+ scaledImagePath = stringToPath(pathToString(scaledImagePath) + suffix);
if (!boost::filesystem::exists(scaledImagePath)) {
- QImage image(imagePath.string().c_str());
+ QImage image(P2QSTRING(pathToString(imagePath)));
if (!image.isNull()) {
if (image.width() > size || image.height() > size) {
QImage scaledImage = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- scaledImage.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG");
+ scaledImage.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
}
else {
- image.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG");
+ image.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
}
}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.cpp b/Swift/QtUI/QtCertificateViewerDialog.cpp
new file mode 100644
index 0000000..15a52ba
--- /dev/null
+++ b/Swift/QtUI/QtCertificateViewerDialog.cpp
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtCertificateViewerDialog.h"
+#include "ui_QtCertificateViewerDialog.h"
+
+#include <Swiften/Base/foreach.h>
+
+#include <QTreeWidgetItem>
+#include <QLabel>
+#include <QDateTime>
+
+namespace Swift {
+
+QtCertificateViewerDialog::QtCertificateViewerDialog(QWidget* parent) : QDialog(parent), ui(new Ui::QtCertificateViewerDialog) {
+ ui->setupUi(this);
+ connect(ui->certChainTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
+
+ setAttribute(Qt::WA_DeleteOnClose);
+}
+
+QtCertificateViewerDialog::~QtCertificateViewerDialog() {
+ delete ui;
+}
+
+void QtCertificateViewerDialog::setCertificateChain(const std::vector<Certificate::ref>& chain) {
+ // clean widgets
+ ui->certChainTreeWidget->clear();
+
+ if (chain.empty()) return;
+
+ // convert Swift certificate chain to qt certificate chain (root goes first)
+ currentChain.clear();
+ foreach(Certificate::ref cert, chain) {
+ ByteArray certAsDer = cert->toDER();
+ QByteArray dataArray(reinterpret_cast<const char*>(certAsDer.data()), certAsDer.size());
+ currentChain.push_front(QSslCertificate(dataArray, QSsl::Der));
+ }
+
+ // fill treeWidget
+ QTreeWidgetItem* root = new QTreeWidgetItem(ui->certChainTreeWidget, QStringList(currentChain.at(0).subjectInfo(QSslCertificate::CommonName)));
+ root->setData(0, Qt::UserRole, QVariant(0));
+ root->setExpanded(true);
+ ui->certChainTreeWidget->addTopLevelItem(root);
+ if (currentChain.size() > 1) {
+ QTreeWidgetItem* parent = root;
+ for (int n = 1; n < currentChain.size(); n++) {
+ QTreeWidgetItem* link = new QTreeWidgetItem(parent, QStringList(QString("↳ ") + currentChain.at(n).subjectInfo(QSslCertificate::CommonName)));
+ link->setExpanded(true);
+ link->setData(0, Qt::UserRole, QVariant(n));
+ parent = link;
+ }
+ ui->certChainTreeWidget->setCurrentItem(parent);
+ } else {
+ ui->certChainTreeWidget->setCurrentItem(root);
+ }
+}
+
+void QtCertificateViewerDialog::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
+ QtCertificateViewerDialog* dialog = new QtCertificateViewerDialog(parent);
+ dialog->setCertificateChain(chain);
+ dialog->show();
+}
+
+void QtCertificateViewerDialog::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem*) {
+ setCertificateDetails(currentChain.at(current->data(0, Qt::UserRole).toInt()));
+}
+
+#define ADD_SECTION( TITLE ) \
+ ui->certGridLayout->addWidget(new QLabel("<strong>" + TITLE + "</strong>"), rowCount++, 0, 1, 2);
+
+#define ADD_FIELD( TITLE, VALUE) \
+ ui->certGridLayout->addWidget(new QLabel(TITLE), rowCount, 0, 1, 1, Qt::AlignRight); \
+ valueLabel = new QLabel(VALUE); \
+ valueLabel->setTextFormat(Qt::PlainText); \
+ valueLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); \
+ ui->certGridLayout->addWidget(valueLabel, rowCount++, 1, 1, 1, Qt::AlignLeft);
+
+void QtCertificateViewerDialog::setCertificateDetails(const QSslCertificate& cert) {
+ QLayoutItem* item;
+ while ((item = ui->certGridLayout->takeAt(0)) != NULL ) {
+ delete item->widget();
+ delete item;
+ }
+
+ int rowCount = 0;
+
+ ui->certGridLayout->setColumnStretch(2, 1);
+
+ QLabel* valueLabel = 0;
+
+ ADD_SECTION(tr("General"));
+ ADD_FIELD(tr("Valid From"), cert.effectiveDate().toString(Qt::TextDate));
+ ADD_FIELD(tr("Valid To"), cert.expiryDate().toString(Qt::TextDate));
+ ADD_FIELD(tr("Serial Number"), QString(cert.serialNumber().toHex()));
+ ADD_FIELD(tr("Version"), QString(cert.version()));
+
+ ADD_SECTION(tr("Subject"));
+ ADD_FIELD(tr("Organization"), cert.subjectInfo(QSslCertificate::Organization));
+ ADD_FIELD(tr("Common Name"), cert.subjectInfo(QSslCertificate::CommonName));
+ ADD_FIELD(tr("Locality"), cert.subjectInfo(QSslCertificate::LocalityName));
+ ADD_FIELD(tr("Organizational Unit"), cert.subjectInfo(QSslCertificate::OrganizationalUnitName));
+ ADD_FIELD(tr("Country"), cert.subjectInfo(QSslCertificate::CountryName));
+ ADD_FIELD(tr("State"), cert.subjectInfo(QSslCertificate::StateOrProvinceName));
+
+ if (!cert.alternateSubjectNames().empty()) {
+ ADD_SECTION(tr("Alternate Subject Names"));
+ QMultiMap<QSsl::AlternateNameEntryType, QString> altNames = cert.alternateSubjectNames();
+ foreach (const QSsl::AlternateNameEntryType &type, altNames.uniqueKeys()) {
+ foreach (QString name, altNames.values(type)) {
+ if (type == QSsl::EmailEntry) {
+ ADD_FIELD(tr("E-mail Address"), name);
+ } else {
+ ADD_FIELD(tr("DNS Name"), name);
+ }
+ }
+ }
+ }
+
+ ADD_SECTION(tr("Issuer"));
+ ADD_FIELD(tr("Organization"), cert.issuerInfo(QSslCertificate::Organization));
+ ADD_FIELD(tr("Common Name"), cert.issuerInfo(QSslCertificate::CommonName));
+ ADD_FIELD(tr("Locality"), cert.issuerInfo(QSslCertificate::LocalityName));
+ ADD_FIELD(tr("Organizational Unit"), cert.issuerInfo(QSslCertificate::OrganizationalUnitName));
+ ADD_FIELD(tr("Country"), cert.issuerInfo(QSslCertificate::CountryName));
+ ADD_FIELD(tr("State"), cert.issuerInfo(QSslCertificate::StateOrProvinceName));
+
+ ui->certGridLayout->setRowStretch(rowCount + 1, 1);
+}
+
+}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.h b/Swift/QtUI/QtCertificateViewerDialog.h
new file mode 100644
index 0000000..9475a83
--- /dev/null
+++ b/Swift/QtUI/QtCertificateViewerDialog.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QDialog>
+#include <QList>
+#include <QSslCertificate>
+#include <QTreeWidgetItem>
+
+#include <Swiften/TLS/Certificate.h>
+
+namespace Ui {
+class QtCertificateViewerDialog;
+}
+
+namespace Swift {
+
+class QtCertificateViewerDialog : public QDialog {
+ Q_OBJECT
+
+ public:
+ explicit QtCertificateViewerDialog(QWidget* parent = 0);
+ ~QtCertificateViewerDialog();
+
+ void setCertificateChain(const std::vector<Certificate::ref>& chain);
+
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+
+ private slots:
+ void currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
+
+ private:
+ void setCertificateDetails(const QSslCertificate& cert);
+
+ private:
+ Ui::QtCertificateViewerDialog *ui;
+ QList<QSslCertificate> currentChain;
+};
+
+}
diff --git a/Swift/QtUI/QtCertificateViewerDialog.ui b/Swift/QtUI/QtCertificateViewerDialog.ui
new file mode 100644
index 0000000..63a96bf
--- /dev/null
+++ b/Swift/QtUI/QtCertificateViewerDialog.ui
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtCertificateViewerDialog</class>
+ <widget class="QDialog" name="QtCertificateViewerDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>655</width>
+ <height>514</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Certificate Viewer</string>
+ </property>
+ <property name="sizeGripEnabled">
+ <bool>true</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0">
+ <item row="3" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>629</width>
+ <height>368</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QGridLayout" name="certGridLayout"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QTreeWidget" name="certChainTreeWidget">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>70</height>
+ </size>
+ </property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="showDropIndicator" stdset="0">
+ <bool>false</bool>
+ </property>
+ <property name="dragEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <property name="itemsExpandable">
+ <bool>false</bool>
+ </property>
+ <property name="expandsOnDoubleClick">
+ <bool>false</bool>
+ </property>
+ <attribute name="headerVisible">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string notr="true">1</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>QtCertificateViewerDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>QtCertificateViewerDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp
index 9921754..cf335e1 100644
--- a/Swift/QtUI/QtChatTabs.cpp
+++ b/Swift/QtUI/QtChatTabs.cpp
@@ -23,7 +23,9 @@
namespace Swift {
-QtChatTabs::QtChatTabs() : QWidget() {
-#ifndef Q_WS_MAC
+QtChatTabs::QtChatTabs(bool singleWindow) : QWidget(), singleWindow_(singleWindow) {
+#ifndef Q_OS_MAC
setWindowIcon(QIcon(":/logo-chat-16.png"));
+#else
+ setAttribute(Qt::WA_ShowWithoutActivating);
#endif
@@ -36,4 +38,5 @@ QtChatTabs::QtChatTabs() : QWidget() {
/*Closable tabs are only in Qt4.5 and later*/
tabs_->setTabsClosable(true);
+ tabs_->setMovable(true);
connect(tabs_, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabCloseRequested(int)));
#else
@@ -45,5 +48,4 @@ QtChatTabs::QtChatTabs() : QWidget() {
layout->addWidget(tabs_);
setLayout(layout);
- //resize(400, 300);
}
@@ -109,17 +111,21 @@ void QtChatTabs::handleWantsToActivate() {
void QtChatTabs::handleTabClosing() {
QWidget* widget = qobject_cast<QWidget*>(sender());
- if (!widget) {
- return;
- }
- int index = tabs_->indexOf(widget);
- if (index < 0) {
- return;
- }
+ int index;
+ if (widget && ((index = tabs_->indexOf(widget)) >= 0)) {
tabs_->removeTab(index);
if (tabs_->count() == 0) {
+ if (!singleWindow_) {
hide();
}
+ else {
+ setWindowTitle("");
+ onTitleChanged("");
+ }
+ }
+ else {
handleTabTitleUpdated(tabs_->currentWidget());
}
+ }
+}
void QtChatTabs::handleRequestedPreviousTab() {
@@ -177,8 +183,7 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
QString tabText = tabbable->windowTitle().simplified();
-
// look for spectrum-generated and other long JID localparts, and
// try to abbreviate the resulting long tab texts
- QRegExp hasTrailingGarbage("^(.[-\\w\\s&]+)([^\\s\\w].*)$");
+ QRegExp hasTrailingGarbage("^(.[-\\w\\s,&]+)([^\\s\\,w].*)$");
if (hasTrailingGarbage.exactMatch(tabText) &&
hasTrailingGarbage.cap(1).simplified().length() >= 2 &&
@@ -189,8 +194,6 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
tabText = hasTrailingGarbage.cap(1).simplified();
}
-
// QTabBar interprets &, so escape that
tabText.replace("&", "&&");
-
// see which alt[a-z] keys other tabs use
bool accelsTaken[26];
@@ -238,5 +241,5 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
case QtTabbable::WaitingActivity : tabTextColor = QColor(217, 20, 43); break;
case QtTabbable::ImpendingActivity : tabTextColor = QColor(27, 171, 32); break;
- default : tabTextColor = QColor();
+ case QtTabbable::NoActivity : tabTextColor = QColor(); break;
}
tabs_->tabBar()->setTabTextColor(index, tabTextColor);
@@ -252,5 +255,7 @@ void QtChatTabs::handleTabTitleUpdated(QWidget* widget) {
std::string current(Q2PSTRING(qobject_cast<QtTabbable*>(tabs_->currentWidget())->windowTitle()));
ChatMessageSummarizer summary;
- setWindowTitle(summary.getSummary(current, unreads).c_str());
+ QString title = summary.getSummary(current, unreads).c_str();
+ setWindowTitle(title);
+ emit onTitleChanged(title);
}
@@ -271,5 +276,18 @@ void QtChatTabs::moveEvent(QMoveEvent*) {
void QtChatTabs::checkForFirstShow() {
if (!isVisible()) {
+#ifndef Q_OS_MAC
showMinimized();
+#else
+ /* https://bugreports.qt-project.org/browse/QTBUG-19194
+ * ^ When the above is fixed we can swap the below for just show();
+ * WA_ShowWithoutActivating seems to helpfully not work, so... */
+
+ QWidget* currentWindow = QApplication::activeWindow(); /* Remember who had focus if we're the current application*/
+ show();
+ QCoreApplication::processEvents(); /* Run through the eventloop to clear the show() */
+ if (currentWindow) {
+ currentWindow->activateWindow(); /* Set focus back */
+ }
+#endif
}
}
diff --git a/Swift/QtUI/QtChatTabs.h b/Swift/QtUI/QtChatTabs.h
index 233c574..f9cd685 100644
--- a/Swift/QtUI/QtChatTabs.h
+++ b/Swift/QtUI/QtChatTabs.h
@@ -18,5 +18,5 @@ namespace Swift {
Q_OBJECT
public:
- QtChatTabs();
+ QtChatTabs(bool singleWindow);
void addTab(QtTabbable* tab);
void minimise();
@@ -24,4 +24,5 @@ namespace Swift {
signals:
void geometryChanged();
+ void onTitleChanged(const QString& title);
protected slots:
@@ -45,4 +46,5 @@ namespace Swift {
void checkForFirstShow();
QtTabWidget* tabs_;
+ bool singleWindow_;
};
}
diff --git a/Swift/QtUI/QtChatTheme.h b/Swift/QtUI/QtChatTheme.h
index c6b02a0..f72a48b 100644
--- a/Swift/QtUI/QtChatTheme.h
+++ b/Swift/QtUI/QtChatTheme.h
@@ -14,18 +14,18 @@ namespace Swift {
public:
QtChatTheme(const QString& themePath);
- QString getHeader() const {return fileContents_[Header];};
- QString getFooter() const {return fileContents_[Footer];};
- QString getContent() const {return fileContents_[Content];};
- QString getStatus() const {return fileContents_[Status];};
- QString getTopic() const {return fileContents_[Topic];};
- QString getFileTransferRequest() const {return fileContents_[FileTransferRequest];};
- QString getIncomingContent() const {return fileContents_[IncomingContent];};
- QString getIncomingNextContent() const {return fileContents_[IncomingNextContent];};
- QString getIncomingContext() const {return fileContents_[IncomingContext];};
- QString getIncomingNextContext() const {return fileContents_[IncomingNextContext];};
- QString getOutgoingContent() const {return fileContents_[OutgoingContent];};
- QString getOutgoingNextContent() const {return fileContents_[OutgoingNextContent];};
- QString getOutgoingContext() const {return fileContents_[OutgoingContext];};
- QString getOutgoingNextContext() const {return fileContents_[OutgoingNextContext];};
+ QString getHeader() const {return fileContents_[Header];}
+ QString getFooter() const {return fileContents_[Footer];}
+ QString getContent() const {return fileContents_[Content];}
+ QString getStatus() const {return fileContents_[Status];}
+ QString getTopic() const {return fileContents_[Topic];}
+ QString getFileTransferRequest() const {return fileContents_[FileTransferRequest];}
+ QString getIncomingContent() const {return fileContents_[IncomingContent];}
+ QString getIncomingNextContent() const {return fileContents_[IncomingNextContent];}
+ QString getIncomingContext() const {return fileContents_[IncomingContext];}
+ QString getIncomingNextContext() const {return fileContents_[IncomingNextContext];}
+ QString getOutgoingContent() const {return fileContents_[OutgoingContent];}
+ QString getOutgoingNextContent() const {return fileContents_[OutgoingNextContent];}
+ QString getOutgoingContext() const {return fileContents_[OutgoingContext];}
+ QString getOutgoingNextContext() const {return fileContents_[OutgoingNextContext];}
QString getTemplate() const {return fileContents_[Template];}
QString getMainCSS() const {return fileContents_[MainCSS];}
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp
index 54bce09..db4fe51 100644
--- a/Swift/QtUI/QtChatView.cpp
+++ b/Swift/QtUI/QtChatView.cpp
@@ -1,371 +1,19 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtChatView.h"
-
-#include <QtDebug>
-#include <QEventLoop>
-#include <QFile>
-#include <QDesktopServices>
-#include <QVBoxLayout>
-#include <QWebFrame>
-#include <QKeyEvent>
-#include <QStackedWidget>
-#include <QTimer>
-#include <QMessageBox>
-#include <QApplication>
-
-#include <Swiften/Base/Log.h>
-
-#include "QtWebView.h"
-#include "QtChatTheme.h"
-#include "QtChatWindow.h"
-#include "QtSwiftUtil.h"
+#include <Swift/QtUI/QtChatView.h>
namespace Swift {
-QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent), fontSizeSteps_(0) {
- theme_ = theme;
-
- QVBoxLayout* mainLayout = new QVBoxLayout(this);
- mainLayout->setSpacing(0);
- mainLayout->setContentsMargins(0,0,0,0);
- webView_ = new QtWebView(this);
- connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
- connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
- connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
- connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested()));
- connect(webView_, SIGNAL(fontGrowRequested()), SLOT(increaseFontSize()));
- connect(webView_, SIGNAL(fontShrinkRequested()), SLOT(decreaseFontSize()));
-#ifdef Q_WS_X11
- /* To give a border on Linux, where it looks bad without */
- QStackedWidget* stack = new QStackedWidget(this);
- stack->addWidget(webView_);
- stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
- stack->setLineWidth(2);
- mainLayout->addWidget(stack);
-#else
- mainLayout->addWidget(webView_);
-#endif
-
-#ifdef SWIFT_EXPERIMENTAL_FT
- setAcceptDrops(true);
-#endif
-
- webPage_ = new QWebPage(this);
- webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
- //webPage_->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
- webView_->setPage(webPage_);
- connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
+QtChatView::QtChatView(QWidget* parent) : QWidget(parent) {
- viewReady_ = false;
- isAtBottom_ = true;
- resetView();
}
-void QtChatView::handleClearRequested() {
- QMessageBox messageBox(this);
- messageBox.setWindowTitle(tr("Clear log"));
- messageBox.setText(tr("You are about to clear the contents of your chat log."));
- messageBox.setInformativeText(tr("Are you sure?"));
- messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- messageBox.setDefaultButton(QMessageBox::Yes);
- int button = messageBox.exec();
- if (button == QMessageBox::Yes) {
- logCleared();
- resetView();
- }
-}
-
-void QtChatView::handleKeyPressEvent(QKeyEvent* event) {
- webView_->keyPressEvent(event);
-}
-
-void QtChatView::addMessage(boost::shared_ptr<ChatSnippet> snippet) {
- if (viewReady_) {
- addToDOM(snippet);
- } else {
- /* If this asserts, the previous queuing code was necessary and should be reinstated */
- assert(false);
- }
-}
-
-QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) {
- QWebElement newElement = newInsertPoint_.clone();
- newElement.setInnerXml(snippet->getContent());
- Q_ASSERT(!newElement.isNull());
- return newElement;
-}
-
-void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
- rememberScrolledToBottom();
- bool insert = snippet->getAppendToPrevious();
- QWebElement continuationElement = lastElement_.findFirst("#insert");
- bool fallback = insert && continuationElement.isNull();
- boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet;
- QWebElement newElement = snippetToDOM(newSnippet);
- if (insert && !fallback) {
- Q_ASSERT(!continuationElement.isNull());
- continuationElement.replace(newElement);
- } else {
- continuationElement.removeFromDocument();
- newInsertPoint_.prependOutside(newElement);
- }
- lastElement_ = newElement;
- if (fontSizeSteps_ != 0) {
- double size = 1.0 + 0.2 * fontSizeSteps_;
- QString sizeString(QString().setNum(size, 'g', 3) + "em");
- const QWebElementCollection spans = lastElement_.findAll("span.swift_resizable");
- foreach (QWebElement span, spans) {
- span.setStyleProperty("font-size", sizeString);
- }
- }
-}
-
-void QtChatView::addLastSeenLine() {
- if (lineSeparator_.isNull()) {
- lineSeparator_ = newInsertPoint_.clone();
- lineSeparator_.setInnerXml(QString("<hr/>"));
- newInsertPoint_.prependOutside(lineSeparator_);
- }
- else {
- QWebElement lineSeparatorC = lineSeparator_.clone();
- lineSeparatorC.removeFromDocument();
- }
- newInsertPoint_.prependOutside(lineSeparator_);
-}
-
-void QtChatView::replaceLastMessage(const QString& newMessage) {
- assert(viewReady_);
- rememberScrolledToBottom();
- assert(!lastElement_.isNull());
- QWebElement replace = lastElement_.findFirst("span.swift_message");
- assert(!replace.isNull());
- QString old = lastElement_.toOuterXml();
- replace.setInnerXml(ChatSnippet::escape(newMessage));
-}
-
-void QtChatView::replaceLastMessage(const QString& newMessage, const QString& note) {
- rememberScrolledToBottom();
- replaceLastMessage(newMessage);
- QWebElement replace = lastElement_.findFirst("span.swift_time");
- assert(!replace.isNull());
- replace.setInnerXml(ChatSnippet::escape(note));
-}
-
-QString QtChatView::getLastSentMessage() {
- return lastElement_.toPlainText();
-}
-
-void QtChatView::addToJSEnvironment(const QString& name, QObject* obj) {
- webView_->page()->currentFrame()->addToJavaScriptWindowObject(name, obj);
-}
-
-void QtChatView::replaceMessage(const QString& newMessage, const QString& id, const QDateTime& editTime) {
- rememberScrolledToBottom();
- QWebElement message = document_.findFirst("#" + id);
- if (!message.isNull()) {
- QWebElement replaceContent = message.findFirst("span.swift_message");
- assert(!replaceContent.isNull());
- QString old = replaceContent.toOuterXml();
- replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
- QWebElement replaceTime = message.findFirst("span.swift_time");
- assert(!replaceTime.isNull());
- old = replaceTime.toOuterXml();
- replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime))));
- }
- else {
- qWarning() << "Trying to replace element with id " << id << " but it's not there.";
- }
-}
-
-void QtChatView::copySelectionToClipboard() {
- if (!webPage_->selectedText().isEmpty()) {
- webPage_->triggerAction(QWebPage::Copy);
- }
-}
-
-void QtChatView::setAckXML(const QString& id, const QString& xml) {
- QWebElement message = document_.findFirst("#" + id);
- /* Deliberately not asserting here, so that when we start expiring old messages it won't hit us */
- if (message.isNull()) return;
- QWebElement ackElement = message.findFirst("span.swift_ack");
- assert(!ackElement.isNull());
- 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");
-}
+QtChatView::~QtChatView() {
-void QtChatView::rememberScrolledToBottom() {
- isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
-}
-
-void QtChatView::scrollToBottom() {
- isAtBottom_ = true;
- webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
- webView_->update(); /* Work around redraw bug in some versions of Qt. */
-}
-
-void QtChatView::handleFrameSizeChanged() {
- if (isAtBottom_) {
- scrollToBottom();
- }
-}
-
-void QtChatView::handleLinkClicked(const QUrl& url) {
- QDesktopServices::openUrl(url);
-}
-
-void QtChatView::handleViewLoadFinished(bool ok) {
- Q_ASSERT(ok);
- viewReady_ = true;
-}
-
-void QtChatView::increaseFontSize(int numSteps) {
- //qDebug() << "Increasing";
- fontSizeSteps_ += numSteps;
- emit fontResized(fontSizeSteps_);
-}
-
-void QtChatView::decreaseFontSize() {
- fontSizeSteps_--;
- if (fontSizeSteps_ < 0) {
- fontSizeSteps_ = 0;
- }
- emit fontResized(fontSizeSteps_);
-}
-
-void QtChatView::resizeFont(int fontSizeSteps) {
- fontSizeSteps_ = fontSizeSteps;
- double size = 1.0 + 0.2 * fontSizeSteps_;
- QString sizeString(QString().setNum(size, 'g', 3) + "em");
- //qDebug() << "Setting to " << sizeString;
- const QWebElementCollection spans = document_.findAll("span.swift_resizable");
- foreach (QWebElement span, spans) {
- span.setStyleProperty("font-size", sizeString);
- }
- webView_->setFontSizeIsMinimal(size == 1.0);
-}
-
-void QtChatView::resetView() {
- lastElement_ = QWebElement();
- QString pageHTML = theme_->getTemplate();
- pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
- pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
- if (pageHTML.count("%@") > 3) {
- pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
- }
- pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
- pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
- pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
- QEventLoop syncLoop;
- connect(webView_, SIGNAL(loadFinished(bool)), &syncLoop, SLOT(quit()));
- webPage_->mainFrame()->setHtml(pageHTML);
- while (!viewReady_) {
- QTimer t;
- t.setSingleShot(true);
- connect(&t, SIGNAL(timeout()), &syncLoop, SLOT(quit()));
- t.start(50);
- syncLoop.exec();
- }
- document_ = webPage_->mainFrame()->documentElement();
- QWebElement chatElement = document_.findFirst("#Chat");
- newInsertPoint_ = chatElement.clone();
- newInsertPoint_.setOuterXml("<div id='swift_insert'/>");
- chatElement.appendInside(newInsertPoint_);
- Q_ASSERT(!newInsertPoint_.isNull());
-
- connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
-}
-
-QWebElement findDivElementWithID(QWebElement document, QString id) {
- QWebElementCollection divs = document.findAll("div");
- foreach(QWebElement div, divs) {
- if (div.attribute("id") == id) {
- return div;
- }
- }
- return QWebElement();
-}
-
-void QtChatView::setFileTransferProgress(QString id, const int percentageDone) {
- QWebElement ftElement = findDivElementWithID(document_, id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id!" << std::endl;
- return;
- }
- QWebElement progressBar = ftElement.findFirst("div.progressbar");
- progressBar.setStyleProperty("width", QString::number(percentageDone) + "%");
-
- QWebElement progressBarValue = ftElement.findFirst("div.progressbar-value");
- progressBarValue.setInnerXml(QString::number(percentageDone) + " %");
-}
-
-void QtChatView::setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /* msg */) {
- QWebElement ftElement = findDivElementWithID(document_, id);
- if (ftElement.isNull()) {
- SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
- return;
- }
-
- QString newInnerHTML = "";
- if (state == ChatWindow::WaitingForAccept) {
- newInnerHTML = tr("Waiting for other side to accept the transfer.") + "<br/>" +
- QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonFileTransferCancel, id);
- }
- if (state == ChatWindow::Negotiating) {
- // replace with text "Negotiaging" + Cancel button
- newInnerHTML = tr("Negotiating...") + "<br/>" +
- QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::Transferring) {
- // progress bar + Cancel Button
- newInnerHTML = "<div style=\"position: relative; width: 90%; height: 20px; border: 2px solid grey; -webkit-border-radius: 10px;\">"
- "<div class=\"progressbar\" style=\"width: 0%; height: 100%; background: #AAA; -webkit-border-radius: 6px;\">"
- "<div class=\"progressbar-value\" style=\"position: absolute; top: 0px; left: 0px; width: 100%; text-align: center; padding-top: 2px;\">"
- "0%"
- "</div>"
- "</div>"
- "</div>" +
- QtChatWindow::buildChatWindowButton(tr("Cancel"), QtChatWindow::ButtonFileTransferCancel, id);
- }
- else if (state == ChatWindow::Canceled) {
- newInnerHTML = tr("Transfer has been canceled!");
- }
- else if (state == ChatWindow::Finished) {
- // text "Successful transfer"
- newInnerHTML = tr("Transfer completed successfully.");
- }
- else if (state == ChatWindow::FTFailed) {
- newInnerHTML = tr("Transfer failed.");
- }
-
- ftElement.setInnerXml(newInnerHTML);
-}
-
-void QtChatView::setMUCInvitationJoined(QString id) {
- QWebElement divElement = findDivElementWithID(document_, id);
- QWebElement buttonElement = divElement.findFirst("input#mucinvite");
- if (!buttonElement.isNull()) {
- buttonElement.setAttribute("value", tr("Return to room"));
- }
}
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index 2e64593..52125b7 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -1,86 +1,62 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFT_QtChatView_H
-#define SWIFT_QtChatView_H
-
-#include <QString>
-#include <QWidget>
-#include <QList>
-#include <QWebElement>
+#pragma once
+#include <string>
#include <boost/shared_ptr.hpp>
+#include <boost/date_time/posix_time/posix_time.hpp>
-#include "ChatSnippet.h"
+#include <QWidget>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
-class QWebPage;
-class QUrl;
-
namespace Swift {
- class QtWebView;
- class QtChatTheme;
+ class HighlightAction;
+ class SecurityLabel;
+
class QtChatView : public QWidget {
Q_OBJECT
public:
- QtChatView(QtChatTheme* theme, QWidget* parent);
- void addMessage(boost::shared_ptr<ChatSnippet> snippet);
- void addLastSeenLine();
- void replaceLastMessage(const QString& newMessage);
- void replaceLastMessage(const QString& newMessage, const QString& note);
- 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);
+ QtChatView(QWidget* parent);
+ virtual ~QtChatView();
- QString getLastSentMessage();
- void addToJSEnvironment(const QString&, QObject*);
- void setFileTransferProgress(QString id, const int percentageDone);
- void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& msg);
- void setMUCInvitationJoined(QString id);
+ /** 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) = 0;
+ /** 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) = 0;
- signals:
- void gotFocus();
- void fontResized(int);
- void logCleared();
+ virtual void addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
+ virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) = 0;
- public slots:
- void copySelectionToClipboard();
- void scrollToBottom();
- void handleLinkClicked(const QUrl&);
- void handleKeyPressEvent(QKeyEvent* event);
- void resetView();
- void increaseFontSize(int numSteps = 1);
- void decreaseFontSize();
- void resizeFont(int fontSizeSteps);
+ virtual void addErrorMessage(const ChatWindow::ChatMessage& message) = 0;
+ virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) = 0;
+ virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) = 0;
+ virtual void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/) = 0;
+ virtual void setAckState(const std::string& id, ChatWindow::AckState state) = 0;
- private slots:
- void handleViewLoadFinished(bool);
- void handleFrameSizeChanged();
- void handleClearRequested();
+ 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 ChatWindow::FileTransferState state, const std::string& msg = "") = 0;
+ 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(const std::string& id, const ChatWindow::WhiteboardSessionState state) = 0;
+ virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) = 0;
- private:
- void headerEncode();
- void messageEncode();
- void addToDOM(boost::shared_ptr<ChatSnippet> snippet);
- QWebElement snippetToDOM(boost::shared_ptr<ChatSnippet> snippet);
+ virtual void showEmoticons(bool show) = 0;
+ virtual void addLastSeenLine() = 0;
+
+ public slots:
+ virtual void resizeFont(int fontSizeSteps) = 0;
+ virtual void scrollToBottom() = 0;
+ virtual void handleKeyPressEvent(QKeyEvent* event) = 0;
- bool viewReady_;
- bool isAtBottom_;
- QtWebView* webView_;
- QWebPage* webPage_;
- int fontSizeSteps_;
- QtChatTheme* theme_;
- QWebElement newInsertPoint_;
- QWebElement lineSeparator_;
- QWebElement lastElement_;
- QWebElement document_;
};
}
-
-#endif
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp
index 1a82a66..68104b4 100644
--- a/Swift/QtUI/QtChatWindow.cpp
+++ b/Swift/QtUI/QtChatWindow.cpp
@@ -1,66 +1,64 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtChatWindow.h"
-#include "QtSwiftUtil.h"
-#include "Swift/Controllers/Roster/Roster.h"
-#include "Swift/Controllers/Roster/RosterItem.h"
-#include "Swift/Controllers/Roster/ContactRosterItem.h"
-#include "Roster/QtOccupantListWidget.h"
-#include "SwifTools/Linkify.h"
-#include "QtChatView.h"
-#include "MessageSnippet.h"
-#include "SystemMessageSnippet.h"
-#include "QtTextEdit.h"
-#include "QtSettingsProvider.h"
-#include "QtScaledAvatarCache.h"
-
-#include <Swiften/StringCodecs/Base64.h>
-#include "SwifTools/TabComplete.h"
-#include <Swift/Controllers/UIEvents/UIEventStream.h>
-#include <Swift/Controllers/UIEvents/SendFileUIEvent.h>
-#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
-#include "QtChatWindowJSBridge.h"
+#include <Swift/QtUI/QtChatWindow.h>
#include <boost/cstdint.hpp>
-#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
-#include <QLabel>
-#include <QMessageBox>
-#include <QInputDialog>
+#include <qdebug.h>
#include <QApplication>
#include <QBoxLayout>
#include <QCloseEvent>
#include <QComboBox>
+#include <QFileDialog>
#include <QFileInfo>
+#include <QInputDialog>
+#include <QLabel>
#include <QLineEdit>
+#include <QMenu>
+#include <QMessageBox>
+#include <QMimeData>
+#include <QPushButton>
#include <QSplitter>
#include <QString>
+#include <QTextDocument>
#include <QTextEdit>
#include <QTime>
+#include <QToolButton>
#include <QUrl>
-#include <QPushButton>
-#include <QFileDialog>
-#include <QMenu>
-#include <QTextDocument>
-#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <QMimeData>
+
#include <Swiften/Base/Log.h>
-namespace Swift {
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
+#include <Swift/Controllers/Roster/Roster.h>
+#include <Swift/Controllers/Roster/RosterItem.h>
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/Controllers/UIEvents/SendFileUIEvent.h>
+#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
+
+#include <SwifTools/TabComplete.h>
-const QString QtChatWindow::ButtonFileTransferCancel = QString("filetransfer-cancel");
-const QString QtChatWindow::ButtonFileTransferSetDescription = QString("filetransfer-setdescription");
-const QString QtChatWindow::ButtonFileTransferSendRequest = QString("filetransfer-sendrequest");
-const QString QtChatWindow::ButtonFileTransferAcceptRequest = QString("filetransfer-acceptrequest");
-const QString QtChatWindow::ButtonMUCInvite = QString("mucinvite");
+#include <Swift/QtUI/Roster/QtOccupantListWidget.h>
+#include <Swift/QtUI/QtAddBookmarkWindow.h>
+#include <Swift/QtUI/QtPlainChatView.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+#include <Swift/QtUI/QtScaledAvatarCache.h>
+#include <Swift/QtUI/QtTextEdit.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/QtUtilities.h>
+#include <Swift/QtUI/QtWebKitChatView.h>
-QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageKind_(PreviosuMessageWasNone), eventStream_(eventStream) {
+namespace Swift {
+
+QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings) : QtTabbable(), contact_(contact), nextAlertId_(0), eventStream_(eventStream), blockingState_(BlockingUnsupported), isMUC_(false), supportsImpromptuChat_(false) {
settings_ = settings;
unreadCount_ = 0;
- idCounter_ = 0;
inputEnabled_ = true;
completer_ = NULL;
@@ -68,5 +66,7 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
theme_ = theme;
isCorrection_ = false;
+ labelModel_ = NULL;
correctionEnabled_ = Maybe;
+ fileTransferEnabled_ = Maybe;
updateTitleWithUnreadCount();
@@ -81,42 +81,32 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
layout->setSpacing(2);
- alertWidget_ = new QWidget(this);
- QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget_);
- layout->addWidget(alertWidget_);
- alertLabel_ = new QLabel(this);
- alertLayout->addWidget(alertLabel_);
- alertButton_ = new QPushButton(this);
- connect (alertButton_, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked()));
- alertLayout->addWidget(alertButton_);
- QPalette palette = alertWidget_->palette();
- palette.setColor(QPalette::Window, QColor(Qt::yellow));
- palette.setColor(QPalette::WindowText, QColor(Qt::black));
- alertWidget_->setStyleSheet(alertStyleSheet_);
- alertLabel_->setStyleSheet(alertStyleSheet_);
- alertWidget_->hide();
+ alertLayout_ = new QVBoxLayout();
+ layout->addLayout(alertLayout_);
- QBoxLayout* subjectLayout = new QBoxLayout(QBoxLayout::LeftToRight);
+ subjectLayout_ = new QBoxLayout(QBoxLayout::LeftToRight);
subject_ = new QLineEdit(this);
- subjectLayout->addWidget(subject_);
+ subjectLayout_->addWidget(subject_);
setSubject("");
subject_->setReadOnly(true);
- actionButton_ = new QPushButton(this);
+ QPushButton* actionButton_ = new QPushButton(this);
actionButton_->setIcon(QIcon(":/icons/actions.png"));
connect(actionButton_, SIGNAL(clicked()), this, SLOT(handleActionButtonClicked()));
- subjectLayout->addWidget(actionButton_);
-
subject_->hide();
- actionButton_->hide();
- layout->addLayout(subjectLayout);
+ layout->addLayout(subjectLayout_);
logRosterSplitter_ = new QSplitter(this);
logRosterSplitter_->setAutoFillBackground(true);
layout->addWidget(logRosterSplitter_);
- messageLog_ = new QtChatView(theme, this);
+ if (settings_->getSetting(QtUISettingConstants::USE_PLAIN_CHATS) || settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
+ messageLog_ = new QtPlainChatView(this, eventStream_);
+ }
+ 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_);
- treeWidget_ = new QtOccupantListWidget(eventStream_, settings_, this);
+ treeWidget_ = new QtOccupantListWidget(eventStream_, settings_, QtTreeWidget::MessageDefaultJID, this);
treeWidget_->hide();
logRosterSplitter_->addWidget(treeWidget_);
@@ -124,11 +114,11 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
- QWidget* midBar = new QWidget(this);
- layout->addWidget(midBar);
- midBar->setAutoFillBackground(true);
- QHBoxLayout *midBarLayout = new QHBoxLayout(midBar);
+ midBar_ = new QWidget(this);
+ //layout->addWidget(midBar);
+ midBar_->setAutoFillBackground(true);
+ QHBoxLayout *midBarLayout = new QHBoxLayout(midBar_);
midBarLayout->setContentsMargins(0,0,0,0);
midBarLayout->setSpacing(2);
- midBarLayout->addStretch();
+ //midBarLayout->addStretch();
labelsWidget_ = new QComboBox(this);
@@ -137,14 +127,23 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
labelsWidget_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
midBarLayout->addWidget(labelsWidget_,0);
+ connect(labelsWidget_, SIGNAL(currentIndexChanged(int)), this, SLOT(handleCurrentLabelChanged(int)));
+ defaultLabelsPalette_ = labelsWidget_->palette();
QHBoxLayout* inputBarLayout = new QHBoxLayout();
inputBarLayout->setContentsMargins(0,0,0,0);
inputBarLayout->setSpacing(2);
- input_ = new QtTextEdit(this);
+ input_ = new QtTextEdit(settings_, this);
input_->setAcceptRichText(false);
+ inputBarLayout->addWidget(midBar_);
inputBarLayout->addWidget(input_);
correctingLabel_ = new QLabel(tr("Correcting"), this);
inputBarLayout->addWidget(correctingLabel_);
correctingLabel_->hide();
+
+ // using an extra layout to work around Qt margin glitches on OS X
+ QHBoxLayout* actionLayout = new QHBoxLayout();
+ actionLayout->addWidget(actionButton_);
+
+ inputBarLayout->addLayout(actionLayout);
layout->addLayout(inputBarLayout);
@@ -159,5 +158,5 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
setFocusProxy(input_);
logRosterSplitter_->setFocusProxy(input_);
- midBar->setFocusProxy(input_);
+ midBar_->setFocusProxy(input_);
messageLog_->setFocusProxy(input_);
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(qAppFocusChanged(QWidget*, QWidget*)));
@@ -170,11 +169,10 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt
treeWidget_->onOccupantActionSelected.connect(boost::bind(boost::ref(onOccupantActionSelected), _1, _2));
- jsBridge = new QtChatWindowJSBridge();
- messageLog_->addToJSEnvironment("chatwindow", jsBridge);
- connect(jsBridge, SIGNAL(buttonClicked(QString,QString,QString,QString)), this, SLOT(handleHTMLButtonClicked(QString,QString,QString,QString)));
+ settings_->onSettingChanged.connect(boost::bind(&QtChatWindow::handleSettingChanged, this, _1));
+ messageLog_->showEmoticons(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+
}
QtChatWindow::~QtChatWindow() {
- delete jsBridge;
if (mucConfigurationWindow_) {
delete mucConfigurationWindow_.data();
@@ -182,4 +180,11 @@ QtChatWindow::~QtChatWindow() {
}
+void QtChatWindow::handleSettingChanged(const std::string& setting) {
+ if (setting == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
+ bool showEmoticons = settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS);
+ messageLog_->showEmoticons(showEmoticons);
+ }
+}
+
void QtChatWindow::handleLogCleared() {
onLogCleared();
@@ -190,8 +195,4 @@ void QtChatWindow::handleOccupantSelectionChanged(RosterItem* item) {
}
-bool QtChatWindow::appendToPreviousCheck(QtChatWindow::PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf) const {
- return previousMessageKind_ == messageKind && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_&& previousSenderName_ == P2QSTRING(senderName)));
-}
-
void QtChatWindow::handleFontResized(int fontSizeSteps) {
messageLog_->resizeFont(fontSizeSteps);
@@ -199,20 +200,48 @@ void QtChatWindow::handleFontResized(int fontSizeSteps) {
void QtChatWindow::handleAlertButtonClicked() {
- onAlertButtonClicked();
+ const QObject* alertWidget = QObject::sender()->parent();
+ std::map<AlertID, QWidget*>::const_iterator i = alertWidgets_.begin();
+ for ( ; i != alertWidgets_.end(); ++i) {
+ if (i->second == alertWidget) {
+ removeAlert(i->first);
+ break;
}
-
-void QtChatWindow::setAlert(const std::string& alertText, const std::string& buttonText) {
- alertLabel_->setText(alertText.c_str());
- if (buttonText.empty()) {
- alertButton_->hide();
- } else {
- alertButton_->setText(buttonText.c_str());
- alertButton_->show();
}
- alertWidget_->show();
}
-void QtChatWindow::cancelAlert() {
- alertWidget_->hide();
+QtChatWindow::AlertID QtChatWindow::addAlert(const std::string& alertText) {
+ QWidget* alertWidget = new QWidget(this);
+ QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget);
+ alertLayout_->addWidget(alertWidget);
+ QLabel* alertLabel = new QLabel(this);
+ alertLabel->setText(alertText.c_str());
+ alertLayout->addWidget(alertLabel);
+
+ QToolButton* closeButton = new QToolButton(alertWidget);
+ closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+ closeButton->setIconSize(QSize(16,16));
+ closeButton->setCursor(Qt::ArrowCursor);
+ closeButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
+ connect (closeButton, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked()));
+
+ alertLayout->addWidget(closeButton);
+ QPalette palette = alertWidget->palette();
+ palette.setColor(QPalette::Window, QColor(Qt::yellow));
+ palette.setColor(QPalette::WindowText, QColor(Qt::black));
+ alertWidget->setStyleSheet(alertStyleSheet_);
+ alertLabel->setStyleSheet(alertStyleSheet_);
+
+ AlertID id = nextAlertId_++;
+ alertWidgets_[id] = alertWidget;
+ return id;
+}
+
+void QtChatWindow::removeAlert(const AlertID id) {
+ std::map<AlertID, QWidget*>::iterator i = alertWidgets_.find(id);
+ if (i != alertWidgets_.end()) {
+ alertLayout_->removeWidget(i->second);
+ delete i->second;
+ alertWidgets_.erase(i);
+ }
}
@@ -223,5 +252,4 @@ void QtChatWindow::setTabComplete(TabComplete* completer) {
void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
event->ignore();
- QtTabbable::handleKeyPressEvent(event);
if (event->isAccepted()) {
return;
@@ -232,11 +260,15 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
if (key == Qt::Key_Tab) {
tabComplete();
- } else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
+ }
+ else if ((key == Qt::Key_Up) && input_->toPlainText().isEmpty() && !(lastSentMessage_.isEmpty())) {
beginCorrection();
- } else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
+ }
+ else if (key == Qt::Key_Down && isCorrection_ && input_->textCursor().atBlockEnd()) {
cancelCorrection();
- } else if (key == Qt::Key_Down || key == Qt::Key_Up) {
+ }
+ else if (key == Qt::Key_Down || key == Qt::Key_Up) {
/* Drop */
- } else {
+ }
+ else {
messageLog_->handleKeyPressEvent(event);
}
@@ -244,9 +276,19 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) {
void QtChatWindow::beginCorrection() {
+ boost::optional<AlertID> newCorrectingAlert;
if (correctionEnabled_ == ChatWindow::Maybe) {
- setAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
- } else if (correctionEnabled_ == ChatWindow::No) {
- setAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
+ newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message")));
+ }
+ else if (correctionEnabled_ == ChatWindow::No) {
+ newCorrectingAlert = addAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message")));
}
+
+ if (newCorrectingAlert) {
+ if (correctingAlert_) {
+ removeAlert(*correctingAlert_);
+ }
+ correctingAlert_ = newCorrectingAlert;
+ }
+
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
@@ -257,8 +299,12 @@ void QtChatWindow::beginCorrection() {
correctingLabel_->show();
input_->setStyleSheet(alertStyleSheet_);
+ labelsWidget_->setEnabled(false);
}
void QtChatWindow::cancelCorrection() {
- cancelAlert();
+ if (correctingAlert_) {
+ removeAlert(*correctingAlert_);
+ correctingAlert_.reset();
+ }
QTextCursor cursor = input_->textCursor();
cursor.select(QTextCursor::Document);
@@ -267,4 +313,5 @@ void QtChatWindow::cancelCorrection() {
correctingLabel_->hide();
input_->setStyleSheet(qApp->styleSheet());
+ labelsWidget_->setEnabled(true);
}
@@ -289,7 +336,8 @@ void QtChatWindow::tabComplete() {
if (tabCompleteCursor_.hasSelection()) {
cursor = tabCompleteCursor_;
- } else {
+ }
+ else {
cursor = input_->textCursor();
- cursor.select(QTextCursor::WordUnderCursor);
+ while(cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor) && cursor.document()->characterAt(cursor.position() - 1) != ' ') { }
}
QString root = cursor.selectedText();
@@ -319,15 +367,14 @@ void QtChatWindow::setRosterModel(Roster* roster) {
void QtChatWindow::setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels) {
- availableLabels_ = labels;
- labelsWidget_->clear();
+ delete labelModel_;
+ labelModel_ = new LabelModel();
+ labelModel_->availableLabels_ = labels;
int i = 0;
int defaultIndex = 0;
+ labelsWidget_->setModel(labelModel_);
foreach (SecurityLabelsCatalog::Item label, labels) {
- std::string selector = label.getSelector();
- std::string displayMarking = label.getLabel() ? label.getLabel()->getDisplayMarking() : "";
- QString labelName = selector.empty() ? displayMarking.c_str() : selector.c_str();
- labelsWidget_->addItem(labelName, QVariant(i));
if (label.getIsDefault()) {
defaultIndex = i;
+ break;
}
i++;
@@ -336,4 +383,25 @@ void QtChatWindow::setAvailableSecurityLabels(const std::vector<SecurityLabelsCa
}
+void QtChatWindow::handleCurrentLabelChanged(int index) {
+ if (static_cast<size_t>(index) >= labelModel_->availableLabels_.size()) {
+ qDebug() << "User selected a label that doesn't exist";
+ return;
+ }
+ const SecurityLabelsCatalog::Item& label = labelModel_->availableLabels_[index];
+ if (label.getLabel()) {
+ QPalette palette = labelsWidget_->palette();
+ //palette.setColor(QPalette::Base, P2QSTRING(label.getLabel()->getBackgroundColor()));
+ palette.setColor(labelsWidget_->backgroundRole(), P2QSTRING(label.getLabel()->getBackgroundColor()));
+ palette.setColor(labelsWidget_->foregroundRole(), P2QSTRING(label.getLabel()->getForegroundColor()));
+ labelsWidget_->setPalette(palette);
+ midBar_->setPalette(palette);
+ labelsWidget_->setAutoFillBackground(true);
+ }
+ else {
+ labelsWidget_->setAutoFillBackground(false);
+ labelsWidget_->setPalette(defaultLabelsPalette_);
+ midBar_->setPalette(defaultLabelsPalette_);
+ }
+}
void QtChatWindow::setSecurityLabelsError() {
@@ -345,5 +413,6 @@ void QtChatWindow::setSecurityLabelsEnabled(bool enabled) {
labelsWidget_->setEnabled(true);
labelsWidget_->show();
- } else {
+ }
+ else {
labelsWidget_->hide();
}
@@ -354,8 +423,12 @@ void QtChatWindow::setCorrectionEnabled(Tristate enabled) {
}
+void QtChatWindow::setFileTransferEnabled(Tristate enabled) {
+ fileTransferEnabled_ = enabled;
+}
+
SecurityLabelsCatalog::Item QtChatWindow::getSelectedSecurityLabel() {
assert(labelsWidget_->isEnabled());
- assert(labelsWidget_->currentIndex() >= 0 && static_cast<size_t>(labelsWidget_->currentIndex()) < availableLabels_.size());
- return availableLabels_[labelsWidget_->currentIndex()];
+ assert(labelsWidget_->currentIndex() >= 0 && static_cast<size_t>(labelsWidget_->currentIndex()) < labelModel_->availableLabels_.size());
+ return labelModel_->availableLabels_[labelsWidget_->currentIndex()];
}
@@ -366,9 +439,10 @@ void QtChatWindow::closeEvent(QCloseEvent* event) {
}
-void QtChatWindow::convertToMUC() {
- setAcceptDrops(false);
+void QtChatWindow::convertToMUC(MUCType mucType) {
+ impromptu_ = (mucType == ImpromptuMUC);
+ treeWidget_->setMessageTarget(impromptu_ ? QtTreeWidget::MessageDisplayJID : QtTreeWidget::MessageDefaultJID);
+ isMUC_ = true;
treeWidget_->show();
- subject_->show();
- actionButton_->show();
+ subject_->setVisible(!impromptu_);
}
@@ -432,5 +506,6 @@ void QtChatWindow::updateTitleWithUnreadCount() {
if (isWindow()) {
setWindowTitle(unreadCount_ > 0 ? QString("(%1) %2").arg(unreadCount_).arg(contact_) : contact_);
- } else {
+ }
+ else {
setWindowTitle(contact_);
}
@@ -438,42 +513,5 @@ void QtChatWindow::updateTitleWithUnreadCount() {
}
-std::string QtChatWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
- return addMessage(message, senderName, senderIsSelf, label, avatarPath, "", time);
-}
-std::string QtChatWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time) {
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
- QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
-
- QString htmlString;
- if (label) {
- htmlString = QString("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \">").arg(Qt::escape(P2QSTRING(label->getForegroundColor()))).arg(Qt::escape(P2QSTRING(label->getBackgroundColor())));
- htmlString += QString("%3</span> ").arg(Qt::escape(P2QSTRING(label->getDisplayMarking())));
- }
- QString messageHTML(Qt::escape(P2QSTRING(message)));
- messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML)));
- messageHTML.replace("\n","<br/>");
- QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
- QString styleSpanEnd = style == "" ? "" : "</span>";
- htmlString += styleSpanStart + messageHTML + styleSpanEnd;
-
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf);
- if (lastLineTracker_.getShouldMoveLastLine()) {
- /* should this be queued? */
- messageLog_->addLastSeenLine();
- /* if the line is added we should break the snippet */
- appendToPrevious = false;
- }
- QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
- std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id))));
-
- previousMessageWasSelf_ = senderIsSelf;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasMessage;
- return id;
-}
void QtChatWindow::flash() {
@@ -481,230 +519,8 @@ 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' title='" + 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' title='" + 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' title='" + tr("The receipt for this message has been received.") + "'/>";
- break;
- case ChatWindow::ReceiptRequested:
- xml = "<img src='qrc:/icons/warn.png' title='" + tr("The receipt for this message has not yet been received. The recipient(s) might not have received this message.") + "'/>";
- break;
- }
- messageLog_->setReceiptXML(P2QSTRING(id), xml);
-}
-
int QtChatWindow::getCount() {
return unreadCount_;
}
-std::string QtChatWindow::addAction(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time) {
- return addMessage(" *" + message + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time);
-}
-
-std::string formatSize(const boost::uintmax_t bytes) {
- static const char *siPrefix[] = {"k", "M", "G", "T", "P", "E", "Z", "Y", NULL};
- int power = 0;
- double engBytes = bytes;
- while (engBytes >= 1000) {
- ++power;
- engBytes = engBytes / 1000.0;
- }
- return str( boost::format("%.1lf %sB") % engBytes % (power > 0 ? siPrefix[power-1] : "") );
-}
-
-QString encodeButtonArgument(const QString& str) {
- return Qt::escape(P2QSTRING(Base64::encode(createByteArray(Q2PSTRING(str)))));
-}
-
-QString decodeButtonArgument(const QString& str) {
- return P2QSTRING(byteArrayToString(Base64::decode(Q2PSTRING(str))));
-}
-
-QString QtChatWindow::buildChatWindowButton(const QString& name, const QString& id, const QString& arg1, const QString& arg2, const QString& arg3) {
- QRegExp regex("[A-Za-z][A-Za-z0-9\\-\\_]+");
- Q_ASSERT(regex.exactMatch(id));
- QString html = QString("<input id='%2' type='submit' value='%1' onclick='chatwindow.buttonClicked(\"%2\", \"%3\", \"%4\", \"%5\");' />").arg(name).arg(id).arg(encodeButtonArgument(arg1)).arg(encodeButtonArgument(arg2)).arg(encodeButtonArgument(arg3));
- return html;
-}
-
-std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
- SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
- QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
-
- QString htmlString;
- QString formattedFileSize = P2QSTRING(formatSize(sizeInBytes));
- if (senderIsSelf) {
- // outgoing
- htmlString = tr("Send file") + ": " + P2QSTRING(filename) + " ( " + formattedFileSize + ") <br/>" +
- "<div id='" + ft_id + "'>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
- buildChatWindowButton(tr("Set Description"), ButtonFileTransferSetDescription, ft_id) +
- buildChatWindowButton(tr("Send"), ButtonFileTransferSendRequest, ft_id) +
- "</div>";
- } else {
- // incoming
- htmlString = tr("Receiving file") + ": " + P2QSTRING(filename) + " ( " + formattedFileSize + ") <br/>" +
- "<div id='" + ft_id + "'>" +
- buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
- buildChatWindowButton(tr("Accept"), ButtonFileTransferAcceptRequest, ft_id, P2QSTRING(filename)) +
- "</div>";
- }
-
- //addMessage(message, senderName, senderIsSelf, boost::shared_ptr<SecurityLabel>(), "", boost::posix_time::second_clock::local_time());
-
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasFileTransfer, senderName, senderIsSelf);
- if (lastLineTracker_.getShouldMoveLastLine()) {
- /* should this be queued? */
- messageLog_->addLastSeenLine();
- /* if the line is added we should break the snippet */
- appendToPrevious = false;
- }
- QString qAvatarPath = "qrc:/icons/avatar.png";
- std::string id = "ftmessage" + boost::lexical_cast<std::string>(idCounter_++);
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id))));
-
- previousMessageWasSelf_ = senderIsSelf;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasFileTransfer;
- return Q2PSTRING(ft_id);
-}
-
-void QtChatWindow::setFileTransferProgress(std::string id, const int percentageDone) {
- messageLog_->setFileTransferProgress(QString::fromStdString(id), percentageDone);
-}
-
-void QtChatWindow::setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg) {
- messageLog_->setFileTransferStatus(QString::fromStdString(id), state, QString::fromStdString(msg));
-}
-
-void QtChatWindow::handleHTMLButtonClicked(QString id, QString encodedArgument1, QString encodedArgument2, QString encodedArgument3) {
- QString arg1 = decodeButtonArgument(encodedArgument1);
- QString arg2 = decodeButtonArgument(encodedArgument2);
- QString arg3 = decodeButtonArgument(encodedArgument3);
-
- if (id.startsWith(ButtonFileTransferCancel)) {
- QString ft_id = arg1;
- onFileTransferCancel(Q2PSTRING(ft_id));
- }
- else if (id.startsWith(ButtonFileTransferSetDescription)) {
- QString ft_id = arg1;
- bool ok = false;
- QString text = QInputDialog::getText(this, tr("File transfer description"),
- tr("Description:"), QLineEdit::Normal, "", &ok);
- if (ok) {
- descriptions[ft_id] = text;
- }
- }
- else if (id.startsWith(ButtonFileTransferSendRequest)) {
- QString ft_id = arg1;
- QString text = descriptions.find(ft_id) == descriptions.end() ? QString() : descriptions[ft_id];
- onFileTransferStart(Q2PSTRING(ft_id), Q2PSTRING(text));
- }
- else if (id.startsWith(ButtonFileTransferAcceptRequest)) {
- QString ft_id = arg1;
- QString filename = arg2;
-
- QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename);
- if (!path.isEmpty()) {
- onFileTransferAccept(Q2PSTRING(ft_id), Q2PSTRING(path));
- }
- }
- else if (id.startsWith(ButtonMUCInvite)) {
- QString roomJID = arg1;
- QString password = arg2;
- QString elementID = arg3;
-
- eventStream_->send(boost::make_shared<JoinMUCUIEvent>(Q2PSTRING(roomJID), Q2PSTRING(password)));
- messageLog_->setMUCInvitationJoined(elementID);
- }
- else {
- SWIFT_LOG(debug) << "Unknown HTML button! ( " << Q2PSTRING(id) << " )" << std::endl;
- }
-}
-
-void QtChatWindow::addErrorMessage(const std::string& errorMessage) {
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
-
- QString errorMessageHTML(Qt::escape(P2QSTRING(errorMessage)));
- errorMessageHTML.replace("\n","<br/>");
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet("<span class=\"error\">" + errorMessageHTML + "</span>", QDateTime::currentDateTime(), false, theme_)));
-
- previousMessageWasSelf_ = false;
- previousMessageKind_ = PreviousMessageWasSystem;
-}
-
-void QtChatWindow::addSystemMessage(const std::string& message) {
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
-
- QString messageHTML(Qt::escape(P2QSTRING(message)));
- messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML)));
- messageHTML.replace("\n","<br/>");
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_)));
-
- previousMessageKind_ = PreviousMessageWasSystem;
-}
-
-void QtChatWindow::replaceWithAction(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) {
- replaceMessage(" *" + message + "*", id, time, "font-style:italic ");
-}
-
-void QtChatWindow::replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time) {
- replaceMessage(message, id, time, "");
-}
-
-void QtChatWindow::replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style) {
- if (!id.empty()) {
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
-
- QString messageHTML(Qt::escape(P2QSTRING(message)));
- messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML)));
- messageHTML.replace("\n","<br/>");
-
- QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
- QString styleSpanEnd = style == "" ? "" : "</span>";
- messageHTML = styleSpanStart + messageHTML + styleSpanEnd;
-
- messageLog_->replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
- }
- else {
- std::cerr << "Trying to replace a message with no id";
- }
-}
-
-void QtChatWindow::addPresenceMessage(const std::string& message) {
- if (isWidgetSelected()) {
- onAllMessagesRead();
- }
-
- QString messageHTML(Qt::escape(P2QSTRING(message)));
- messageHTML = P2QSTRING(Linkify::linkify(Q2PSTRING(messageHTML)));
- messageHTML.replace("\n","<br/>");
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_)));
-
- previousMessageKind_ = PreviousMessageWasPresence;
-}
-
void QtChatWindow::returnPressed() {
@@ -727,5 +543,6 @@ void QtChatWindow::handleInputChanged() {
if (input_->toPlainText().isEmpty()) {
onUserCancelsTyping();
- } else {
+ }
+ else {
onUserTyping();
}
@@ -746,4 +563,8 @@ void QtChatWindow::show() {
}
+bool QtChatWindow::isVisible() const {
+ return QWidget::isVisible();
+}
+
void QtChatWindow::activate() {
if (isWindow()) {
@@ -763,20 +584,42 @@ void QtChatWindow::moveEvent(QMoveEvent*) {
void QtChatWindow::dragEnterEvent(QDragEnterEvent *event) {
+ if (inputEnabled_) {
if (event->mimeData()->hasUrls() && event->mimeData()->urls().size() == 1) {
// TODO: check whether contact actually supports file transfer
+ if (!isMUC_) {
+ event->acceptProposedAction();
+ }
+ }
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ if (isMUC_ || supportsImpromptuChat_) {
event->acceptProposedAction();
}
}
+ }
+}
void QtChatWindow::dropEvent(QDropEvent *event) {
+ if (fileTransferEnabled_ == ChatWindow::Yes && event->mimeData()->hasUrls()) {
if (event->mimeData()->urls().size() == 1) {
onSendFileRequest(Q2PSTRING(event->mimeData()->urls().at(0).toLocalFile()));
- } else {
- addSystemMessage("Sending of multiple files at once isn't supported at this time.");
}
+ else {
+ std::string messageText(Q2PSTRING(tr("Sending of multiple files at once isn't supported at this time.")));
+ ChatMessage message;
+ message.append(boost::make_shared<ChatTextMessagePart>(messageText));
+ addSystemMessage(message, DefaultDirection);
+ }
+ }
+ else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
+ QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
+ std::vector<JID> invites;
+ while (!dataStream.atEnd()) {
+ QString jidString;
+ dataStream >> jidString;
+ invites.push_back(Q2PSTRING(jidString));
+ }
+ onInviteToChat(invites);
}
-
-void QtChatWindow::replaceLastMessage(const std::string& message) {
- messageLog_->replaceLastMessage(P2QSTRING(Linkify::linkify(message)));
}
@@ -788,4 +631,6 @@ void QtChatWindow::setSubject(const std::string& subject) {
//subject_->setVisible(!subject.empty());
subject_->setText(P2QSTRING(subject));
+ subject_->setToolTip(P2QSTRING(subject));
+ subject_->setCursorPosition(0);
}
@@ -798,16 +643,64 @@ void QtChatWindow::handleActionButtonClicked() {
QAction* invite = NULL;
+ QAction* block = NULL;
+ QAction* unblock = NULL;
+
+ if (availableRoomActions_.empty()) {
+ if (blockingState_ == IsBlocked) {
+ unblock = contextMenu.addAction(tr("Unblock"));
+ unblock->setEnabled(inputEnabled_);
+ }
+ else if (blockingState_ == IsUnblocked) {
+ block = contextMenu.addAction(tr("Block"));
+ block->setEnabled(inputEnabled_);
+ }
+
+ if (supportsImpromptuChat_) {
+ invite = contextMenu.addAction(tr("Invite person to this chat…"));
+ invite->setEnabled(inputEnabled_);
+ }
+
+ }
+ else {
foreach(ChatWindow::RoomAction availableAction, availableRoomActions_)
{
+ if (impromptu_) {
+ // hide options we don't need in impromptu chats
+ if (availableAction == ChatWindow::ChangeSubject ||
+ availableAction == ChatWindow::Configure ||
+ availableAction == ChatWindow::Affiliations ||
+ availableAction == ChatWindow::Destroy) {
+ continue;
+ }
+ }
switch(availableAction)
{
- case ChatWindow::ChangeSubject: changeSubject = contextMenu.addAction(tr("Change subject")); break;
- case ChatWindow::Configure: configure = contextMenu.addAction(tr("Configure room")); break;
- case ChatWindow::Affiliations: affiliations = contextMenu.addAction(tr("Edit affiliations")); break;
- case ChatWindow::Destroy: destroy = contextMenu.addAction(tr("Destroy room")); break;
- case ChatWindow::Invite: invite = contextMenu.addAction(tr("Invite person to this room")); break;
+ case ChatWindow::ChangeSubject:
+ changeSubject = contextMenu.addAction(tr("Change subject…"));
+ changeSubject->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Configure:
+ configure = contextMenu.addAction(tr("Configure room…"));
+ configure->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Affiliations:
+ affiliations = contextMenu.addAction(tr("Edit affiliations…"));
+ affiliations->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Destroy:
+ destroy = contextMenu.addAction(tr("Destroy room"));
+ destroy->setEnabled(inputEnabled_);
+ break;
+ case ChatWindow::Invite:
+ invite = contextMenu.addAction(tr("Invite person to this room…"));
+ invite->setEnabled(inputEnabled_);
+ break;
+ }
}
}
+ QAction* bookmark = contextMenu.addAction(tr("Add boomark..."));
+ bookmark->setEnabled(inputEnabled_);
+
QAction* result = contextMenu.exec(QCursor::pos());
if (result == NULL) {
@@ -844,9 +737,14 @@ void QtChatWindow::handleActionButtonClicked() {
}
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)), "");
+ onInviteToChat(std::vector<JID>());
+ }
+ else if (result == block) {
+ onBlockUserRequest();
}
+ else if (result == unblock) {
+ onUnblockUserRequest();
+ }
+ else if (result == bookmark) {
+ onBookmarkRequest();
}
}
@@ -861,9 +759,21 @@ void QtChatWindow::setAffiliations(MUCOccupant::Affiliation affiliation, const s
}
-void QtChatWindow::setAvailableRoomActions(const std::vector<RoomAction> &actions)
-{
+void QtChatWindow::setAvailableRoomActions(const std::vector<RoomAction>& actions) {
availableRoomActions_ = actions;
}
+void QtChatWindow::setBlockingState(BlockingState state) {
+ blockingState_ = state;
+}
+
+void QtChatWindow::setCanInitiateImpromptuChats(bool supportsImpromptu) {
+ supportsImpromptuChat_ = supportsImpromptu;
+}
+
+void QtChatWindow::showBookmarkWindow(const MUCBookmark& bookmark) {
+ QtAddBookmarkWindow* window = new QtAddBookmarkWindow(eventStream_, bookmark);
+ window->show();
+}
+
void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
if (mucConfigurationWindow_) {
@@ -875,36 +785,89 @@ void QtChatWindow::showRoomConfigurationForm(Form::ref form) {
}
-void QtChatWindow::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct) {
+void QtChatWindow::handleAppendedToLog() {
+ if (lastLineTracker_.getShouldMoveLastLine()) {
+ /* should this be queued? */
+ messageLog_->addLastSeenLine();
+ }
if (isWidgetSelected()) {
onAllMessagesRead();
}
+}
- QString htmlString = QObject::tr("You've been invited to enter the %1 room.").arg(P2QSTRING(jid.toString())) + " <br/>";
- if (!reason.empty()) {
- htmlString += QObject::tr("Reason: %1").arg(P2QSTRING(reason)) + "<br/>";
+void QtChatWindow::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) {
+ handleAppendedToLog();
+ messageLog_->addMUCInvitation(senderName, jid, reason, password, direct, isImpromptu, isContinuation);
}
- if (!direct) {
- htmlString += QObject::tr("This person may not have really sent this invitation!") + "<br/>";
+
+std::string QtChatWindow::addMessage(const 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) {
+ handleAppendedToLog();
+ return messageLog_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time, highlight);
}
- QString id = QString(ButtonMUCInvite + "%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+std::string QtChatWindow::addAction(const 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) {
+ handleAppendedToLog();
+ return messageLog_->addAction(message, senderName, senderIsSelf, label, avatarPath, time, highlight);
+}
- htmlString += "<div id='" + id + "'>" +
- buildChatWindowButton(tr("Accept Invite"), ButtonMUCInvite, Qt::escape(P2QSTRING(jid.toString())), Qt::escape(P2QSTRING(password)), id) +
- "</div>";
- bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMUCInvite, senderName, false);
- if (lastLineTracker_.getShouldMoveLastLine()) {
- /* should this be queued? */
- messageLog_->addLastSeenLine();
- /* if the line is added we should break the snippet */
- appendToPrevious = false;
+void QtChatWindow::addSystemMessage(const ChatMessage& message, Direction direction) {
+ handleAppendedToLog();
+ messageLog_->addSystemMessage(message, direction);
+}
+
+void QtChatWindow::addPresenceMessage(const ChatMessage& message, Direction direction) {
+ handleAppendedToLog();
+ messageLog_->addPresenceMessage(message, direction);
+}
+
+void QtChatWindow::addErrorMessage(const ChatMessage& message) {
+ handleAppendedToLog();
+ messageLog_->addErrorMessage(message);
+}
+
+
+void QtChatWindow::replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) {
+ handleAppendedToLog();
+ messageLog_->replaceMessage(message, id, time, highlight);
+}
+
+void QtChatWindow::replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) {
+ handleAppendedToLog();
+ messageLog_->replaceWithAction(message, id, time, highlight);
+}
+
+std::string QtChatWindow::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
+ handleAppendedToLog();
+ return messageLog_->addFileTransfer(senderName, senderIsSelf, filename, sizeInBytes);
}
- QString qAvatarPath = "qrc:/icons/avatar.png";
- messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new MessageSnippet(htmlString, Qt::escape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, false, appendToPrevious, theme_, id)));
- previousMessageWasSelf_ = false;
- previousSenderName_ = P2QSTRING(senderName);
- previousMessageKind_ = PreviousMessageWasMUCInvite;
+void QtChatWindow::setFileTransferProgress(std::string id, const int percentageDone) {
+ messageLog_->setFileTransferProgress(id, percentageDone);
+}
+
+void QtChatWindow::setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg) {
+ messageLog_->setFileTransferStatus(id, state, msg);
+}
+
+
+std::string QtChatWindow::addWhiteboardRequest(bool senderIsSelf) {
+ handleAppendedToLog();
+ return messageLog_->addWhiteboardRequest(contact_, senderIsSelf);
+}
+
+void QtChatWindow::setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state) {
+ messageLog_->setWhiteboardSessionStatus(id, state);
+}
+
+void QtChatWindow::replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour) {
+ messageLog_->replaceLastMessage(message, timestampBehaviour);
+}
+
+void QtChatWindow::setAckState(const std::string& id, AckState state) {
+ messageLog_->setAckState(id, state);
+}
+
+void QtChatWindow::setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) {
+ messageLog_->setMessageReceiptState(id, state);
}
diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h
index 4b888eb..bf37557 100644
--- a/Swift/QtUI/QtChatWindow.h
+++ b/Swift/QtUI/QtChatWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,15 +7,21 @@
#pragma once
-#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
-#include <Swift/QtUI/QtMUCConfigurationWindow.h>
-#include <Swift/QtUI/QtAffiliationEditor.h>
+#include <map>
-#include <QtTabbable.h>
+#include <QPointer>
+#include <QTextCursor>
+#include <QMap>
#include <SwifTools/LastLineTracker.h>
-#include <map>
-#include <QPointer>
-#include <QTextCursor>
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+
+#include <Swift/QtUI/ChatSnippet.h>
+#include <Swift/QtUI/QtAffiliationEditor.h>
+#include <Swift/QtUI/QtMUCConfigurationWindow.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtTabbable.h>
+
+
class QTextEdit;
@@ -36,24 +42,51 @@ namespace Swift {
class SettingsProvider;
- class QtChatWindow : public QtTabbable, public ChatWindow {
+ class LabelModel : public QAbstractListModel {
Q_OBJECT
-
public:
- static const QString ButtonFileTransferCancel;
- static const QString ButtonFileTransferSetDescription;
- static const QString ButtonFileTransferSendRequest;
- static const QString ButtonFileTransferAcceptRequest;
- static const QString ButtonMUCInvite;
+ LabelModel(QObject* parent = NULL) : QAbstractListModel(parent) {}
+
+ virtual int rowCount(const QModelIndex& /*index*/) const {
+ return static_cast<int>(availableLabels_.size());
+ }
+
+ virtual QVariant data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ boost::shared_ptr<SecurityLabel> label = availableLabels_[index.row()].getLabel();
+ if (label && role == Qt::TextColorRole) {
+ return P2QSTRING(label->getForegroundColor());
+ }
+ if (label && role == Qt::TextColorRole) {
+ return P2QSTRING(label->getBackgroundColor());
+ }
+ if (role == Qt::DisplayRole) {
+ std::string selector = availableLabels_[index.row()].getSelector();
+ std::string displayMarking = label ? label->getDisplayMarking() : "";
+ QString labelName = selector.empty() ? displayMarking.c_str() : selector.c_str();
+ return labelName;
+ }
+ return QVariant();
+ }
+
+ std::vector<SecurityLabelsCatalog::Item> availableLabels_;
+ };
+
+ class QtChatWindow : public QtTabbable, public ChatWindow {
+ Q_OBJECT
public:
QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream, SettingsProvider* settings);
~QtChatWindow();
- std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
- std::string addAction(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time);
- void addSystemMessage(const std::string& message);
- void addPresenceMessage(const std::string& message);
- void addErrorMessage(const std::string& errorMessage);
- void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time);
- void replaceWithAction(const std::string& message, const std::string& id, const boost::posix_time::ptime& time);
+ std::string addMessage(const 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);
+ std::string addAction(const 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);
+
+ void addSystemMessage(const ChatMessage& message, Direction direction);
+ void addPresenceMessage(const ChatMessage& message, Direction direction);
+ void addErrorMessage(const ChatMessage& message);
+
+ void replaceMessage(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight);
+ void replaceWithAction(const ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight);
// File transfer related stuff
std::string addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes);
@@ -61,8 +94,12 @@ namespace Swift {
void setFileTransferStatus(std::string id, const FileTransferState state, const std::string& msg);
+ std::string addWhiteboardRequest(bool senderIsSelf);
+ void setWhiteboardSessionStatus(std::string id, const ChatWindow::WhiteboardSessionState state);
+
void show();
+ bool isVisible() const;
void activate();
void setUnreadMessageCount(int count);
- void convertToMUC();
+ void convertToMUC(MUCType mucType);
// TreeWidget *getTreeWidget();
void setAvailableSecurityLabels(const std::vector<SecurityLabelsCatalog::Item>& labels);
@@ -77,5 +114,5 @@ namespace Swift {
void setTabComplete(TabComplete* completer);
int getCount();
- void replaceLastMessage(const std::string& message);
+ void replaceLastMessage(const ChatMessage& message, const TimestampBehaviour timestampBehaviour);
void setAckState(const std::string& id, AckState state);
@@ -88,16 +125,18 @@ namespace Swift {
void setSubject(const std::string& subject);
void showRoomConfigurationForm(Form::ref);
- void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true);
+ void addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct = true, bool isImpromptu = false, bool isContinuation = false);
void setAffiliations(MUCOccupant::Affiliation, const std::vector<JID>&);
void setAvailableRoomActions(const std::vector<RoomAction>& actions);
-
- static QString buildChatWindowButton(const QString& name, const QString& id, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString());
+ void setBlockingState(BlockingState state);
+ virtual void setCanInitiateImpromptuChats(bool supportsImpromptu);
+ virtual void showBookmarkWindow(const MUCBookmark& bookmark);
public slots:
void handleChangeSplitterState(QByteArray state);
void handleFontResized(int fontSizeSteps);
- void setAlert(const std::string& alertText, const std::string& buttonText = "");
- void cancelAlert();
+ AlertID addAlert(const std::string& alertText);
+ void removeAlert(const AlertID id);
void setCorrectionEnabled(Tristate enabled);
+ void setFileTransferEnabled(Tristate enabled);
signals:
@@ -127,17 +166,6 @@ namespace Swift {
void handleAlertButtonClicked();
void handleActionButtonClicked();
-
- void handleHTMLButtonClicked(QString id, QString arg1, QString arg2, QString arg3);
void handleAffiliationEditorAccepted();
-
- private:
- enum PreviousMessageKind {
- PreviosuMessageWasNone,
- PreviousMessageWasMessage,
- PreviousMessageWasSystem,
- PreviousMessageWasPresence,
- PreviousMessageWasFileTransfer,
- PreviousMessageWasMUCInvite
- };
+ void handleCurrentLabelChanged(int);
private:
@@ -146,8 +174,9 @@ namespace Swift {
void beginCorrection();
void cancelCorrection();
- std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time);
- void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style);
+ void handleSettingChanged(const std::string& setting);
+
void handleOccupantSelectionChanged(RosterItem* item);
- bool appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf) const;
+ void handleAppendedToLog();
+
int unreadCount_;
@@ -160,18 +189,16 @@ namespace Swift {
QtChatTheme* theme_;
QtTextEdit* input_;
+ QWidget* midBar_;
+ QBoxLayout* subjectLayout_;
QComboBox* labelsWidget_;
QtOccupantListWidget* treeWidget_;
QLabel* correctingLabel_;
- QLabel* alertLabel_;
- QWidget* alertWidget_;
- QPushButton* alertButton_;
+ boost::optional<AlertID> correctingAlert_;
+ QVBoxLayout* alertLayout_;
+ std::map<AlertID, QWidget*> alertWidgets_;
+ AlertID nextAlertId_;
TabComplete* completer_;
QLineEdit* subject_;
- QPushButton* actionButton_;
- std::vector<SecurityLabelsCatalog::Item> availableLabels_;
bool isCorrection_;
- bool previousMessageWasSelf_;
- PreviousMessageKind previousMessageKind_;
- QString previousSenderName_;
bool inputClearing_;
bool tabCompletion_;
@@ -180,12 +207,16 @@ namespace Swift {
QSplitter *logRosterSplitter_;
Tristate correctionEnabled_;
+ Tristate fileTransferEnabled_;
QString alertStyleSheet_;
- std::map<QString, QString> descriptions;
- QtChatWindowJSBridge* jsBridge;
QPointer<QtMUCConfigurationWindow> mucConfigurationWindow_;
QPointer<QtAffiliationEditor> affiliationEditor_;
- int idCounter_;
SettingsProvider* settings_;
std::vector<ChatWindow::RoomAction> availableRoomActions_;
+ QPalette defaultLabelsPalette_;
+ LabelModel* labelModel_;
+ BlockingState blockingState_;
+ bool impromptu_;
+ bool isMUC_;
+ bool supportsImpromptuChat_;
};
}
diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp
index 7610082..78c04c9 100644
--- a/Swift/QtUI/QtChatWindowFactory.cpp
+++ b/Swift/QtUI/QtChatWindowFactory.cpp
@@ -5,14 +5,15 @@
*/
-#include "QtChatWindowFactory.h"
+#include <Swift/QtUI/QtChatWindowFactory.h>
#include <QDesktopWidget>
-
-#include "QtChatTabs.h"
-#include "QtChatWindow.h"
-#include "QtSwiftUtil.h"
-#include "QtChatTheme.h"
#include <qdebug.h>
+#include <Swift/QtUI/QtChatTabs.h>
+#include <Swift/QtUI/QtChatWindow.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtChatTheme.h>
+#include <Swift/QtUI/QtSingleWindow.h>
+
namespace Swift {
@@ -21,5 +22,5 @@ static const QString SPLITTER_STATE = "mucSplitterState";
static const QString CHAT_TABS_GEOMETRY = "chatTabsGeometry";
-QtChatWindowFactory::QtChatWindowFactory(QSplitter* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabs* tabs, const QString& themePath) : themePath_(themePath) {
+QtChatWindowFactory::QtChatWindowFactory(QtSingleWindow* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabs* tabs, const QString& themePath) : themePath_(themePath) {
qtOnlySettings_ = qtSettings;
settings_ = settings;
diff --git a/Swift/QtUI/QtChatWindowFactory.h b/Swift/QtUI/QtChatWindowFactory.h
index 2a16c3b..63da514 100644
--- a/Swift/QtUI/QtChatWindowFactory.h
+++ b/Swift/QtUI/QtChatWindowFactory.h
@@ -7,10 +7,12 @@
#pragma once
-#include "Swift/Controllers/UIInterfaces/ChatWindowFactory.h"
-#include "Swiften/JID/JID.h"
-#include "QtSettingsProvider.h"
+#include <Swift/Controllers/UIInterfaces/ChatWindowFactory.h>
#include <QObject>
#include <QSplitter>
+
+#include <Swiften/JID/JID.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+
namespace Swift {
class QtChatTabs;
@@ -18,8 +20,9 @@ namespace Swift {
class UIEventStream;
class QtUIPreferences;
+ class QtSingleWindow;
class QtChatWindowFactory : public QObject, public ChatWindowFactory {
Q_OBJECT
public:
- QtChatWindowFactory(QSplitter* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabs* tabs, const QString& themePath);
+ QtChatWindowFactory(QtSingleWindow* splitter, SettingsProvider* settings, QtSettingsProvider* qtSettings, QtChatTabs* tabs, const QString& themePath);
~QtChatWindowFactory();
ChatWindow* createChatWindow(const JID &contact, UIEventStream* eventStream);
diff --git a/Swift/QtUI/QtChatWindowJSBridge.h b/Swift/QtUI/QtChatWindowJSBridge.h
index 8e6f0c2..5a26302 100644
--- a/Swift/QtUI/QtChatWindowJSBridge.h
+++ b/Swift/QtUI/QtChatWindowJSBridge.h
@@ -21,5 +21,5 @@ public:
virtual ~QtChatWindowJSBridge();
signals:
- void buttonClicked(QString id, QString arg1, QString arg2, QString arg3);
+ void buttonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
};
diff --git a/Swift/QtUI/QtClosableLineEdit.cpp b/Swift/QtUI/QtClosableLineEdit.cpp
new file mode 100644
index 0000000..512194b
--- /dev/null
+++ b/Swift/QtUI/QtClosableLineEdit.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+/* Contains demo Trolltech code from http://git.forwardbias.in/?p=lineeditclearbutton.git with license: */
+/****************************************************************************
+**
+** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
+**
+** Use, modification and distribution is allowed without limitation,
+** warranty, liability or support of any kind.
+**
+****************************************************************************/
+
+#include <Swift/QtUI/QtClosableLineEdit.h>
+#include <QApplication>
+#include <QToolButton>
+#include <QStyle>
+#include <QKeyEvent>
+
+namespace Swift {
+
+const int QtClosableLineEdit::clearButtonPadding = 2;
+
+QtClosableLineEdit::QtClosableLineEdit(QWidget *parent) : QLineEdit(parent) {
+ clearButton = new QToolButton(this);
+ clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
+ clearButton->setIconSize(QSize(16,16));
+ clearButton->setCursor(Qt::ArrowCursor);
+ clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
+ clearButton->hide();
+ connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked()));
+ connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&)));
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1));
+ QSize minimumSize = minimumSizeHint();
+ setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding),
+ qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding));
+}
+
+void QtClosableLineEdit::resizeEvent(QResizeEvent *) {
+ QSize size = clearButton->sizeHint();
+ int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
+ clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + 1 - size.height())/2);
+}
+
+void QtClosableLineEdit::updateCloseButton(const QString& text) {
+ clearButton->setVisible(!text.isEmpty());
+}
+
+void QtClosableLineEdit::handleCloseButtonClicked() {
+ clear();
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier));
+ QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier));
+}
+
+}
diff --git a/Swift/QtUI/QtClosableLineEdit.h b/Swift/QtUI/QtClosableLineEdit.h
new file mode 100644
index 0000000..91b4f0e
--- /dev/null
+++ b/Swift/QtUI/QtClosableLineEdit.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+/* Contains demo Trolltech code from http://git.forwardbias.in/?p=lineeditclearbutton.git with license: */
+/****************************************************************************
+**
+** Copyright (c) 2007 Trolltech ASA <info@trolltech.com>
+**
+** Use, modification and distribution is allowed without limitation,
+** warranty, liability or support of any kind.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QLineEdit>
+
+class QToolButton;
+
+namespace Swift {
+
+class QtClosableLineEdit : public QLineEdit
+{
+ Q_OBJECT
+ public:
+ QtClosableLineEdit(QWidget *parent = 0);
+
+ protected:
+ void resizeEvent(QResizeEvent *);
+
+ private slots:
+ void updateCloseButton(const QString &text);
+ void handleCloseButtonClicked();
+
+ private:
+ static const int clearButtonPadding;
+ QToolButton *clearButton;
+};
+
+}
diff --git a/Swift/QtUI/QtColorToolButton.cpp b/Swift/QtUI/QtColorToolButton.cpp
new file mode 100644
index 0000000..1d379a3
--- /dev/null
+++ b/Swift/QtUI/QtColorToolButton.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <QColorDialog>
+#include <QPainter>
+
+#include <Swift/QtUI/QtColorToolButton.h>
+
+namespace Swift {
+
+QtColorToolButton::QtColorToolButton(QWidget* parent) :
+ QToolButton(parent)
+{
+ connect(this, SIGNAL(clicked()), SLOT(onClicked()));
+ setColorIcon(Qt::transparent);
+}
+
+void QtColorToolButton::setColor(const QColor& color)
+{
+ if (color.isValid() != color_.isValid() || (color.isValid() && color != color_)) {
+ color_ = color;
+ setColorIcon(color_);
+ emit colorChanged(color_);
+ }
+}
+
+void QtColorToolButton::onClicked()
+{
+ QColor c = QColorDialog::getColor(color_, this);
+ if (c.isValid()) {
+ setColor(c);
+ }
+}
+
+void QtColorToolButton::setColorIcon(const QColor& color)
+{
+ QPixmap pix(iconSize());
+ pix.fill(color.isValid() ? color : Qt::transparent);
+ setIcon(pix);
+}
+
+}
diff --git a/Swift/QtUI/QtColorToolButton.h b/Swift/QtUI/QtColorToolButton.h
new file mode 100644
index 0000000..33d195d
--- /dev/null
+++ b/Swift/QtUI/QtColorToolButton.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QToolButton>
+
+namespace Swift {
+
+ class QtColorToolButton : public QToolButton {
+ Q_OBJECT
+ Q_PROPERTY(QColor color READ getColor WRITE setColor NOTIFY colorChanged)
+ public:
+ explicit QtColorToolButton(QWidget* parent = NULL);
+ void setColor(const QColor& color);
+ const QColor& getColor() const { return color_; }
+
+ signals:
+ void colorChanged(const QColor&);
+
+ private slots:
+ void onClicked();
+
+ private:
+ void setColorIcon(const QColor& color);
+ QColor color_;
+ };
+
+}
diff --git a/Swift/QtUI/QtConnectionSettings.ui b/Swift/QtUI/QtConnectionSettings.ui
new file mode 100644
index 0000000..2dc46d1
--- /dev/null
+++ b/Swift/QtUI/QtConnectionSettings.ui
@@ -0,0 +1,529 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtConnectionSettings</class>
+ <widget class="QDialog" name="QtConnectionSettings">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>406</width>
+ <height>454</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Connection Options</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Connection Method:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="connectionMethod">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <item>
+ <property name="text">
+ <string>Automatic</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Manual</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>BOSH</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>238</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QStackedWidget" name="stackedWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="page_3"/>
+ <widget class="QWidget" name="page_2">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Secure connection:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="manual_useTLS">
+ <item>
+ <property name="text">
+ <string>Never</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Encrypt when possible</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Always encrypt</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="manual_allowCompression">
+ <property name="text">
+ <string>Allow Compression</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="manual_allowPLAINWithoutTLS">
+ <property name="text">
+ <string>Allow sending password over insecure connection</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>4</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="manual_manualHost">
+ <property name="text">
+ <string>Manually select server</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>18</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="manual_manualHostNameLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Hostname:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="manual_manualHostName">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>4</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="manual_manualHostPortLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="manual_manualHostPort">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Connection Proxy</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_8">
+ <item>
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Proxy type:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="manual_proxyType">
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <item>
+ <property name="text">
+ <string>None</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Use system-configured proxy</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>SOCKS5</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>HTTP Connect</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_7">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="manual_manualProxy">
+ <property name="text">
+ <string>Override system-configured proxy</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <item>
+ <spacer name="horizontalSpacer_8">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>18</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="manual_manualProxyHostLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Hostname:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="manual_manualProxyHost">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>4</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="manual_manualProxyPortLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="manual_manualProxyPort">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>88</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="page_4">
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_7">
+ <item>
+ <widget class="QLabel" name="bosh_uriLabel">
+ <property name="text">
+ <string>BOSH URI:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="bosh_uri">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>4</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="bosh_manualProxy">
+ <property name="text">
+ <string>Manually select HTTP proxy</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>18</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="bosh_manualProxyHostLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Hostname:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="bosh_manualProxyHost">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>4</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="bosh_manualProxyPortLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Port:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="bosh_manualProxyPort">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>80</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Connection options will be saved when next connecting to this account.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>QtConnectionSettings</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/Swift/QtUI/QtConnectionSettingsWindow.cpp b/Swift/QtUI/QtConnectionSettingsWindow.cpp
new file mode 100644
index 0000000..737a79c
--- /dev/null
+++ b/Swift/QtUI/QtConnectionSettingsWindow.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2012 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/QtUI/QtConnectionSettingsWindow.h"
+
+#include <boost/lexical_cast.hpp>
+
+#include <QCoreApplication>
+#include <QIcon>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QtGlobal>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QFile>
+#include <QTextStream>
+#include <QMessageBox>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtURLValidator.h>
+
+namespace Swift {
+
+QtConnectionSettingsWindow::QtConnectionSettingsWindow(const ClientOptions& options) : QDialog() {
+ ui.setupUi(this);
+
+ connect(ui.connectionMethod, SIGNAL(currentIndexChanged(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
+
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostNameLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostName, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualHost, SIGNAL(toggled(bool)), ui.manual_manualHostPort, SLOT(setEnabled(bool)));
+
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHostLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyHost, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.manual_manualProxy, SIGNAL(toggled(bool)), ui.manual_manualProxyPort, SLOT(setEnabled(bool)));
+
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHostLabel, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyHost, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPortLabel, SLOT(setEnabled(bool)));
+ connect(ui.bosh_manualProxy, SIGNAL(toggled(bool)), ui.bosh_manualProxyPort, SLOT(setEnabled(bool)));
+
+ connect(ui.manual_proxyType, SIGNAL(currentIndexChanged(int)), SLOT(handleProxyTypeChanged(int)));
+
+ connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(handleAcceptRequested()));
+
+ QtURLValidator* urlValidator = new QtURLValidator(this);
+ ui.bosh_uri->setValidator(urlValidator);
+
+ ui.manual_useTLS->setCurrentIndex(2);
+
+ ui.manual_proxyType->setCurrentIndex(0);
+
+ ClientOptions defaults;
+ if (options.boshURL.isEmpty()) {
+ bool isDefault = options.useStreamCompression == defaults.useStreamCompression;
+ isDefault &= options.useTLS == defaults.useTLS;
+ isDefault &= options.allowPLAINWithoutTLS == defaults.allowPLAINWithoutTLS;
+ isDefault &= options.useStreamCompression == defaults.useStreamCompression;
+ isDefault &= options.useAcks == defaults.useAcks;
+ isDefault &= options.manualHostname == defaults.manualHostname;
+ isDefault &= options.manualPort == defaults.manualPort;
+ isDefault &= options.proxyType == defaults.proxyType;
+ isDefault &= options.manualProxyHostname == defaults.manualProxyHostname;
+ isDefault &= options.manualProxyPort == defaults.manualProxyPort;
+ if (isDefault) {
+ ui.connectionMethod->setCurrentIndex(0);
+ }
+ else {
+ ui.connectionMethod->setCurrentIndex(1);
+ ui.manual_useTLS->setCurrentIndex(options.useTLS);
+ ui.manual_allowPLAINWithoutTLS->setChecked(options.allowPLAINWithoutTLS);
+ ui.manual_allowCompression->setChecked(options.useStreamCompression);
+ if (!options.manualHostname.empty()) {
+ ui.manual_manualHost->setChecked(true);
+ ui.manual_manualHostName->setText(P2QSTRING(options.manualHostname));
+ if (options.manualPort >=0) {
+ ui.manual_manualHostPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualPort)));
+ }
+ }
+ ui.manual_proxyType->setCurrentIndex(options.proxyType);
+ if (!options.manualProxyHostname.empty()) {
+ ui.manual_manualProxy->setChecked(true);
+ ui.manual_manualProxyHost->setText(P2QSTRING(options.manualProxyHostname));
+ ui.manual_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(options.manualProxyPort)));
+ }
+ }
+ } else {
+ ui.connectionMethod->setCurrentIndex(2);
+ ui.bosh_uri->setText(P2QSTRING(options.boshURL.toString()));
+ if (!options.boshHTTPConnectProxyURL.isEmpty()) {
+ ui.bosh_manualProxy->setChecked(true);
+ ui.bosh_manualProxyHost->setText(P2QSTRING(options.boshHTTPConnectProxyURL.getHost()));
+ if (options.boshHTTPConnectProxyURL.getPort()) {
+ ui.bosh_manualProxyPort->setText(P2QSTRING(boost::lexical_cast<std::string>(*options.boshHTTPConnectProxyURL.getPort())));
+ }
+ }
+ }
+}
+
+void QtConnectionSettingsWindow::handleProxyTypeChanged(int index) {
+ bool proxySettingsVisible = index != NoProxy && index != SystemProxy;
+ ui.manual_manualProxy->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyHostLabel->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyHost->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyPortLabel->setVisible(proxySettingsVisible);
+ ui.manual_manualProxyPort->setVisible(proxySettingsVisible);
+}
+
+void QtConnectionSettingsWindow::handleAcceptRequested() {
+ if (ui.connectionMethod->currentIndex() != 2 || ui.bosh_uri->hasAcceptableInput()) {
+ accept();
+ }
+ else {
+ QMessageBox::critical(this, tr("Configuration invalid"), tr("The provided BOSH URL is not valid."));
+ }
+}
+
+ClientOptions QtConnectionSettingsWindow::getOptions() {
+ ClientOptions options;
+ if (ui.connectionMethod->currentIndex() > 0) {
+ /* Not automatic */
+ if (ui.connectionMethod->currentIndex() == 1) {
+ /* Manual */
+ options.useTLS = static_cast<ClientOptions::UseTLS>(ui.manual_useTLS->currentIndex());
+ options.useStreamCompression = ui.manual_allowCompression->isChecked();
+ options.allowPLAINWithoutTLS = ui.manual_allowPLAINWithoutTLS->isChecked();
+ if (ui.manual_manualHost->isChecked()) {
+ options.manualHostname = Q2PSTRING(ui.manual_manualHostName->text());
+ try {
+ options.manualPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualHostPort->text()));
+ } catch (const boost::bad_lexical_cast&) {
+ options.manualPort = -1;
+ }
+ }
+ options.proxyType = static_cast<ClientOptions::ProxyType>(ui.manual_proxyType->currentIndex());
+ if (ui.manual_manualProxy->isChecked()) {
+ options.manualProxyHostname = Q2PSTRING(ui.manual_manualProxyHost->text());
+ try {
+ options.manualProxyPort = boost::lexical_cast<int>(Q2PSTRING(ui.manual_manualProxyPort->text()));
+ } catch (const boost::bad_lexical_cast&) {}
+ }
+ }
+ else {
+ /* BOSH */
+ options.boshURL = URL::fromString(Q2PSTRING(ui.bosh_uri->text()));
+ if (ui.bosh_manualProxy->isChecked()) {
+ std::string host = Q2PSTRING(ui.bosh_manualProxyHost->text());
+ try {
+ int port = boost::lexical_cast<int>(Q2PSTRING(ui.bosh_manualProxyPort->text()));
+ options.boshHTTPConnectProxyURL = URL("http", host, port, "");
+ } catch (const boost::bad_lexical_cast&) {
+ options.boshHTTPConnectProxyURL = URL("http", host, "");
+ }
+ }
+ }
+ }
+ return options;
+}
+
+}
diff --git a/Swift/QtUI/QtConnectionSettingsWindow.h b/Swift/QtUI/QtConnectionSettingsWindow.h
new file mode 100644
index 0000000..3b017ab
--- /dev/null
+++ b/Swift/QtUI/QtConnectionSettingsWindow.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QDialog>
+
+#include "ui_QtConnectionSettings.h"
+
+#include <Swiften/Client/ClientOptions.h>
+
+namespace Swift {
+ class QtConnectionSettingsWindow : public QDialog {
+ Q_OBJECT
+
+ public:
+ QtConnectionSettingsWindow(const ClientOptions& options);
+
+ ClientOptions getOptions();
+
+ private slots:
+ void handleProxyTypeChanged(int);
+ void handleAcceptRequested();
+
+ private:
+ enum {
+ NoProxy = 0,
+ SystemProxy = 1,
+ SOCKS5Proxy = 2,
+ HTTPProxy = 3
+ };
+ Ui::QtConnectionSettings ui;
+ };
+}
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index 9d071b9..a347a00 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -53,6 +53,7 @@ QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups,
foreach (std::string group, allGroups) {
+ QString groupName = doubleAmpersand(group);
QCheckBox* check = new QCheckBox(groups);
- check->setText(P2QSTRING(group));
+ check->setText(groupName);
check->setCheckState(Qt::Unchecked);
checkBoxes_[group] = check;
@@ -84,5 +85,5 @@ std::string QtContactEditWidget::getName() const {
name = Q2PSTRING(name_->text());
} else {
- name = Q2PSTRING(button->text());
+ name = singleAmpersand(button->text());
}
break;
@@ -116,5 +117,5 @@ void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& sug
foreach(const std::string& name, suggestions) {
- suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(P2QSTRING(name), this));
+ suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(doubleAmpersand(name), this));
}
@@ -136,4 +137,13 @@ void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& sug
}
}
+QString QtContactEditWidget::doubleAmpersand(const std::string& name) const {
+ return P2QSTRING(name).replace("&", "&&");
+
+}
+
+std::string QtContactEditWidget::singleAmpersand(const QString& name) const {
+ return Q2PSTRING(QString(name).replace("&&", "&"));
+}
+
void QtContactEditWidget::clear() {
diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h
index 5350762..6d55b80 100644
--- a/Swift/QtUI/QtContactEditWidget.h
+++ b/Swift/QtUI/QtContactEditWidget.h
@@ -39,4 +39,8 @@ namespace Swift {
void clear();
+
+ private:
+ QString doubleAmpersand(const std::string& name) const;
+ std::string singleAmpersand(const QString& name) const;
private:
typedef std::map<std::string, QCheckBox*> CheckBoxMap;
diff --git a/Swift/QtUI/QtContactEditWindow.cpp b/Swift/QtUI/QtContactEditWindow.cpp
index 6520c0a..c175934 100644
--- a/Swift/QtUI/QtContactEditWindow.cpp
+++ b/Swift/QtUI/QtContactEditWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -76,6 +76,7 @@ void QtContactEditWindow::setEnabled(bool b) {
void QtContactEditWindow::show() {
- QWidget::show();
+ QWidget::showNormal();
QWidget::activateWindow();
+ QWidget::raise();
}
diff --git a/Swift/QtUI/QtFileTransferListItemModel.cpp b/Swift/QtUI/QtFileTransferListItemModel.cpp
index cf1de07..b9b9fd1 100644
--- a/Swift/QtUI/QtFileTransferListItemModel.cpp
+++ b/Swift/QtUI/QtFileTransferListItemModel.cpp
@@ -11,11 +11,11 @@
#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Base/FileSize.h>
#include <Swift/Controllers/FileTransfer/FileTransferController.h>
#include <Swift/Controllers/FileTransfer/FileTransferOverview.h>
+#include "QtSwiftUtil.h"
namespace Swift {
-extern std::string formatSize(const boost::uintmax_t bytes);
-
QtFileTransferListItemModel::QtFileTransferListItemModel(QObject *parent) : QAbstractItemModel(parent), fileTransferOverview(0) {
}
@@ -66,9 +66,12 @@ QVariant QtFileTransferListItemModel::data(const QModelIndex &index, int role) c
}
if (index.column() == OtherParty) {
- return QVariant(QString::fromStdString(controller->getOtherParty().toString()));
+ return QVariant(P2QSTRING(controller->getOtherParty().toString()));
}
if (index.column() == State) {
FileTransfer::State state = controller->getState();
- switch(state.state) {
+ switch(state.type) {
+ case FileTransfer::State::Initial:
+ assert(false);
+ return QVariant("");
case FileTransfer::State::WaitingForStart:
return QVariant(QObject::tr("Waiting for start"));
@@ -92,5 +95,5 @@ QVariant QtFileTransferListItemModel::data(const QModelIndex &index, int role) c
}
if (index.column() == OverallSize) {
- return QVariant(QString::fromStdString(formatSize((controller->getSize()))));
+ return QVariant(P2QSTRING(formatSize((controller->getSize()))));
}
return QVariant();
@@ -106,5 +109,5 @@ int QtFileTransferListItemModel::rowCount(const QModelIndex& /* parent */) const
QModelIndex QtFileTransferListItemModel::index(int row, int column, const QModelIndex& /* parent */) const {
- return createIndex(row, column, 0);
+ return createIndex(row, column, static_cast<void*>(0));
}
diff --git a/Swift/QtUI/QtFileTransferListItemModel.h b/Swift/QtUI/QtFileTransferListItemModel.h
index 1d892a5..28f13f8 100644
--- a/Swift/QtUI/QtFileTransferListItemModel.h
+++ b/Swift/QtUI/QtFileTransferListItemModel.h
@@ -35,5 +35,5 @@ private:
Progress,
OverallSize,
- NoOfColumns,
+ NoOfColumns
};
diff --git a/Swift/QtUI/QtFormResultItemModel.cpp b/Swift/QtUI/QtFormResultItemModel.cpp
index 5461f05..8920128 100644
--- a/Swift/QtUI/QtFormResultItemModel.cpp
+++ b/Swift/QtUI/QtFormResultItemModel.cpp
@@ -5,4 +5,10 @@
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include "QtFormResultItemModel.h"
@@ -36,5 +42,5 @@ QVariant QtFormResultItemModel::headerData(int section, Qt::Orientation /*orient
if (role != Qt::DisplayRole) return QVariant();
if (static_cast<size_t>(section) >= formResult_->getReportedFields().size()) return QVariant();
- return QVariant(QString::fromStdString(formResult_->getReportedFields().at(section)->getLabel()));
+ return QVariant(P2QSTRING(formResult_->getReportedFields().at(section)->getLabel()));
}
@@ -70,13 +76,14 @@ const std::string QtFormResultItemModel::getFieldValue(const Form::FormItem& ite
if (field->getName() == name) {
std::string delimiter = "";
- if (boost::dynamic_pointer_cast<TextMultiFormField>(field)) {
+ if (field->getType() == FormField::TextMultiType) {
delimiter = "\n";
- } else if (boost::dynamic_pointer_cast<JIDMultiFormField>(field)) {
+ }
+ else if (field->getType() == FormField::JIDMultiType) {
delimiter = ", ";
- } else if (boost::dynamic_pointer_cast<ListMultiFormField>(field)) {
+ }
+ else if (field->getType() == FormField::ListMultiType) {
delimiter = ", ";
}
-
- return boost::algorithm::join(field->getRawValues(), delimiter);
+ return boost::algorithm::join(field->getValues(), delimiter);
}
}
diff --git a/Swift/QtUI/QtFormWidget.cpp b/Swift/QtUI/QtFormWidget.cpp
index 158bc9d..b4840e9 100644
--- a/Swift/QtUI/QtFormWidget.cpp
+++ b/Swift/QtUI/QtFormWidget.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -18,4 +18,6 @@
#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swiften/Base/foreach.h>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
namespace Swift {
@@ -36,6 +38,8 @@ QtFormWidget::QtFormWidget(Form::ref form, QWidget* parent) : QWidget(parent), f
QWidget* scroll = new QWidget(this);
QGridLayout* layout = new QGridLayout(scroll);
- foreach (boost::shared_ptr<FormField> field, form->getFields()) {
- QWidget* widget = createWidget(field);
+ const std::vector<Form::FormItem> items = form->getItems();
+ if (items.empty()) { /* single item forms */
+ foreach (FormField::ref field, form->getFields()) {
+ QWidget* widget = createWidget(field, field->getType(), 0);
if (widget) {
layout->addWidget(new QLabel(field->getLabel().c_str(), this), row, 0);
@@ -43,6 +47,21 @@ QtFormWidget::QtFormWidget(Form::ref form, QWidget* parent) : QWidget(parent), f
}
}
+ } else { /* multi-item forms */
+ const Form::FormItem& headers = form->getFields();
+ for (size_t i = 0; i < items.size(); ++i) {
+ const Form::FormItem& item = items[i];
+ assert(item.size() == headers.size());
+ for (size_t j = 0; j < item.size(); ++j) {
+ QWidget* widget = createWidget(item[j], headers[j]->getType(), i);
+ if (widget) {
+ layout->addWidget(new QLabel(item[j]->getLabel().c_str(), this), row, 0);
+ layout->addWidget(widget, row++, 1);
+ }
+ }
+ }
+ }
scrollArea->setWidget(scroll);
scrollArea->setWidgetResizable(true);
+ setEditable(form->getType() != Form::CancelType && form->getType() != Form::ResultType);
}
@@ -54,18 +73,23 @@ QListWidget* QtFormWidget::createList(FormField::ref field) {
QListWidget* listWidget = new QListWidget(this);
listWidget->setSortingEnabled(false);
- listWidget->setSelectionMode(boost::dynamic_pointer_cast<ListMultiFormField>(field) ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
- boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field);
- boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field);
+ listWidget->setSelectionMode(field->getType() == FormField::ListMultiType ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
std::vector<bool> selected;
+ /* if this is an editable form, use the 'options' list, otherwise use the 'values' list */
+ if (form_->getType() != Form::FormType) {
+ foreach (const std::string& value, field->getValues()) {
+ listWidget->addItem(P2QSTRING(value));
+ selected.push_back(false);
+ }
+ } else {
foreach (FormField::Option option, field->getOptions()) {
listWidget->addItem(option.label.c_str());
- if (listSingleField) {
- selected.push_back(option.value == listSingleField->getValue());
+ if (field->getType() == FormField::ListSingleType) {
+ selected.push_back(!field->getValues().empty() && option.value == field->getValues()[0]);
}
- else if (listMultiField) {
+ else if (field->getType() == FormField::ListMultiType) {
std::string text = option.value;
- selected.push_back(std::find(listMultiField->getValue().begin(), listMultiField->getValue().end(), text) != listMultiField->getValue().end());
+ selected.push_back(std::find(field->getValues().begin(), field->getValues().end(), text) != field->getValues().end());
+ }
}
-
}
for (int i = 0; i < listWidget->count(); i++) {
@@ -76,64 +100,53 @@ QListWidget* QtFormWidget::createList(FormField::ref field) {
}
-QWidget* QtFormWidget::createWidget(FormField::ref field) {
+QWidget* QtFormWidget::createWidget(FormField::ref field, const FormField::Type type, const size_t index) {
QWidget* widget = NULL;
- boost::shared_ptr<BooleanFormField> booleanField = boost::dynamic_pointer_cast<BooleanFormField>(field);
- if (booleanField) {
+ if (type == FormField::BooleanType) {
QCheckBox* checkWidget = new QCheckBox(this);
- checkWidget->setCheckState(booleanField->getValue() ? Qt::Checked : Qt::Unchecked);
+ checkWidget->setCheckState(field->getBoolValue() ? Qt::Checked : Qt::Unchecked);
widget = checkWidget;
}
- boost::shared_ptr<FixedFormField> fixedField = boost::dynamic_pointer_cast<FixedFormField>(field);
- if (fixedField) {
- QString value = fixedField->getValue().c_str();
+ if (type == FormField::FixedType) {
+ QString value = field->getFixedValue().c_str();
widget = new QLabel(value, this);
}
- boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field);
- if (listSingleField) {
+ if (type == FormField::ListSingleType) {
widget = createList(field);
}
- boost::shared_ptr<TextMultiFormField> textMultiField = boost::dynamic_pointer_cast<TextMultiFormField>(field);
- if (textMultiField) {
- QString value = textMultiField->getValue().c_str();
- widget = new QTextEdit(value, this);
+ if (type == FormField::TextMultiType) {
+ QString value = field->getTextMultiValue().c_str();
+ QTextEdit* textWidget = new QTextEdit(this);
+ textWidget->setPlainText(value);
+ widget = textWidget;
}
- boost::shared_ptr<TextPrivateFormField> textPrivateField = boost::dynamic_pointer_cast<TextPrivateFormField>(field);
- if (textPrivateField) {
- QString value = textPrivateField->getValue().c_str();
+ if (type == FormField::TextPrivateType) {
+ QString value = field->getTextPrivateValue().c_str();
QLineEdit* lineWidget = new QLineEdit(value, this);
lineWidget->setEchoMode(QLineEdit::Password);
widget = lineWidget;
}
- boost::shared_ptr<TextSingleFormField> textSingleField = boost::dynamic_pointer_cast<TextSingleFormField>(field);
- if (textSingleField) {
- QString value = textSingleField->getValue().c_str();
+ if (type == FormField::TextSingleType) {
+ QString value = field->getTextSingleValue().c_str();
widget = new QLineEdit(value, this);
}
- boost::shared_ptr<JIDSingleFormField> jidSingleField = boost::dynamic_pointer_cast<JIDSingleFormField>(field);
- if (jidSingleField) {
- QString value = jidSingleField->getValue().toString().c_str();
+ if (type == FormField::JIDSingleType) {
+ QString value = field->getJIDSingleValue().toString().c_str();
widget = new QLineEdit(value, this);
}
- boost::shared_ptr<JIDMultiFormField> jidMultiField = boost::dynamic_pointer_cast<JIDMultiFormField>(field);
- if (jidMultiField) {
- QString text;
- bool prev = false;
- foreach (JID line, jidMultiField->getValue()) {
- if (prev) {
- text += "\n";
- }
- prev = true;
- text += line.toString().c_str();
+ if (type == FormField::JIDMultiType) {
+ QString text = boost::join(field->getValues(), "\n").c_str();
+ QTextEdit* textWidget = new QTextEdit(this);
+ textWidget->setPlainText(text);
+ widget = textWidget;
}
- widget = new QTextEdit(text, this);
- }
- boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field);
- if (listMultiField) {
+ if (type == FormField::ListMultiType) {
widget = createList(field);
}
- boost::shared_ptr<HiddenFormField> hiddenField = boost::dynamic_pointer_cast<HiddenFormField>(field);
- if (hiddenField) {
+ std::string indexString;
+ if (index) {
+ /* for multi-item forms we need to distinguish between the different rows */
+ indexString = boost::lexical_cast<std::string>(index);
}
- fields_[field->getName()] = widget;
+ fields_[field->getName() + indexString] = widget;
return widget;
}
@@ -142,97 +155,47 @@ Form::ref QtFormWidget::getCompletedForm() {
Form::ref result(new Form(Form::SubmitType));
foreach (boost::shared_ptr<FormField> field, form_->getFields()) {
- boost::shared_ptr<FormField> resultField;
- boost::shared_ptr<BooleanFormField> booleanField = boost::dynamic_pointer_cast<BooleanFormField>(field);
- if (booleanField) {
- resultField = FormField::ref(BooleanFormField::create(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked));
+ boost::shared_ptr<FormField> resultField = boost::make_shared<FormField>(field->getType());
+ if (field->getType() == FormField::BooleanType) {
+ resultField->setBoolValue(qobject_cast<QCheckBox*>(fields_[field->getName()])->checkState() == Qt::Checked);
}
- boost::shared_ptr<FixedFormField> fixedField = boost::dynamic_pointer_cast<FixedFormField>(field);
- if (fixedField) {
- resultField = FormField::ref(FixedFormField::create(fixedField->getValue()));
+ if (field->getType() == FormField::FixedType || field->getType() == FormField::HiddenType) {
+ resultField->addValue(field->getValues().empty() ? "" : field->getValues()[0]);
}
- boost::shared_ptr<ListSingleFormField> listSingleField = boost::dynamic_pointer_cast<ListSingleFormField>(field);
- if (listSingleField) {
+ if (field->getType() == FormField::ListSingleType) {
QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
if (listWidget->selectedItems().size() > 0) {
int i = listWidget->row(listWidget->selectedItems()[0]);
- resultField = FormField::ref(ListSingleFormField::create(field->getOptions()[i].value));
- }
- else {
- resultField = FormField::ref(ListSingleFormField::create());
+ resultField->addValue(field->getOptions()[i].value);
}
}
- boost::shared_ptr<TextMultiFormField> textMultiField = boost::dynamic_pointer_cast<TextMultiFormField>(field);
- if (textMultiField) {
+ if (field->getType() == FormField::TextMultiType) {
QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
QString string = widget->toPlainText();
- if (string.isEmpty()) {
- resultField = FormField::ref(TextMultiFormField::create());
- }
- else {
- resultField = FormField::ref(TextMultiFormField::create(Q2PSTRING(string)));
+ if (!string.isEmpty()) {
+ resultField->setTextMultiValue(Q2PSTRING(string));
}
}
- boost::shared_ptr<TextPrivateFormField> textPrivateField = boost::dynamic_pointer_cast<TextPrivateFormField>(field);
- if (textPrivateField) {
+ if (field->getType() == FormField::TextPrivateType || field->getType() == FormField::TextSingleType || field->getType() == FormField::JIDSingleType) {
QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
QString string = widget->text();
- if (string.isEmpty()) {
- resultField = FormField::ref(TextPrivateFormField::create());
+ if (!string.isEmpty()) {
+ resultField->addValue(Q2PSTRING(string));
}
- else {
- resultField = FormField::ref(TextPrivateFormField::create(Q2PSTRING(string)));
}
- }
- boost::shared_ptr<TextSingleFormField> textSingleField = boost::dynamic_pointer_cast<TextSingleFormField>(field);
- if (textSingleField) {
- QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
- QString string = widget->text();
- if (string.isEmpty()) {
- resultField = FormField::ref(TextSingleFormField::create());
- }
- else {
- resultField = FormField::ref(TextSingleFormField::create(Q2PSTRING(string)));
- }
- }
- boost::shared_ptr<JIDSingleFormField> jidSingleField = boost::dynamic_pointer_cast<JIDSingleFormField>(field);
- if (jidSingleField) {
- QLineEdit* widget = qobject_cast<QLineEdit*>(fields_[field->getName()]);
- QString string = widget->text();
- JID jid(Q2PSTRING(string));
- if (string.isEmpty()) {
- resultField = FormField::ref(JIDSingleFormField::create());
- }
- else {
- resultField = FormField::ref(JIDSingleFormField::create(jid));
- }
- }
- boost::shared_ptr<JIDMultiFormField> jidMultiField = boost::dynamic_pointer_cast<JIDMultiFormField>(field);
- if (jidMultiField) {
+ if (field->getType() == FormField::JIDMultiType) {
QTextEdit* widget = qobject_cast<QTextEdit*>(fields_[field->getName()]);
QString string = widget->toPlainText();
- if (string.isEmpty()) {
- resultField = FormField::ref(JIDMultiFormField::create());
- }
- else {
+ if (!string.isEmpty()) {
QStringList lines = string.split("\n");
- std::vector<JID> value;
foreach (QString line, lines) {
- value.push_back(JID(Q2PSTRING(line)));
+ resultField->addValue(Q2PSTRING(line));
}
- resultField = FormField::ref(JIDMultiFormField::create(value));
}
}
- boost::shared_ptr<ListMultiFormField> listMultiField = boost::dynamic_pointer_cast<ListMultiFormField>(field);
- if (listMultiField) {
+ if (field->getType() == FormField::ListMultiType) {
QListWidget* listWidget = qobject_cast<QListWidget*>(fields_[field->getName()]);
- std::vector<std::string> values;
foreach (QListWidgetItem* item, listWidget->selectedItems()) {
- values.push_back(field->getOptions()[listWidget->row(item)].value);
- }
- resultField = FormField::ref(ListMultiFormField::create(values));
+ resultField->addValue(field->getOptions()[listWidget->row(item)].value);
}
- boost::shared_ptr<HiddenFormField> hiddenField = boost::dynamic_pointer_cast<HiddenFormField>(field);
- if (hiddenField) {
- resultField = FormField::ref(HiddenFormField::create(hiddenField->getValue()));
}
resultField->setName(field->getName());
diff --git a/Swift/QtUI/QtFormWidget.h b/Swift/QtUI/QtFormWidget.h
index c7aae73..f58ff4b 100644
--- a/Swift/QtUI/QtFormWidget.h
+++ b/Swift/QtUI/QtFormWidget.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2011 Kevin Smith
+ * Copyright (c) 2011-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -24,5 +24,5 @@ class QtFormWidget : public QWidget {
void setEditable(bool editable);
private:
- QWidget* createWidget(FormField::ref field);
+ QWidget* createWidget(FormField::ref field, const FormField::Type type, const size_t index);
QListWidget* createList(FormField::ref field);
template<class T> void setEnabled(QWidget* rawWidget, bool editable);
diff --git a/Swift/QtUI/QtHighlightEditor.cpp b/Swift/QtUI/QtHighlightEditor.cpp
new file mode 100644
index 0000000..97774be
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditor.cpp
@@ -0,0 +1,542 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cassert>
+
+#include <boost/lexical_cast.hpp>
+
+#include <Swift/QtUI/UserSearch/QtSuggestingJIDInput.h>
+#include <Swift/Controllers/HighlightManager.cpp>
+#include <Swift/QtUI/QtHighlightEditor.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+
+#include <QTreeWidgetItem>
+#include <QFileDialog>
+
+namespace Swift {
+
+QtHighlightEditor::QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent)
+ : QWidget(parent), settings_(settings), previousRow_(-1)
+{
+ ui_.setupUi(this);
+
+ connect(ui_.listWidget, SIGNAL(currentRowChanged(int)), SLOT(onCurrentRowChanged(int)));
+
+ connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked()));
+ connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked()));
+
+ connect(ui_.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), SLOT(onApplyButtonClick()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), SLOT(onCancelButtonClick()));
+ connect(ui_.buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), SLOT(onOkButtonClick()));
+
+ connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(colorOtherSelect()));
+ connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(colorCustomSelect()));
+
+ connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
+ connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(soundOtherSelect()));
+ connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(soundCustomSelect()));
+
+ /* replace the static line-edit control with the roster autocompleter */
+ ui_.dummySenderName->setVisible(false);
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ ui_.senderName->addWidget(jid_);
+ jid_->onUserSelected.connect(boost::bind(&QtHighlightEditor::handleOnUserSelected, this, _1));
+
+ /* handle autocomplete */
+ connect(jid_, SIGNAL(textEdited(QString)), SLOT(handleContactSuggestionRequested(QString)));
+
+ /* we need to be notified if any of the state changes so that we can update our textual rule description */
+ connect(ui_.chatRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.roomRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.nickIsKeyword, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.allMsgRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.senderRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(jid_, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
+ connect(ui_.keywordRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.keyword, SIGNAL(textChanged(const QString&)), SLOT(widgetClick()));
+ connect(ui_.matchPartialWords, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.matchCase, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.noColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.customColorRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.noSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.defaultSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+ connect(ui_.customSoundRadio, SIGNAL(clicked()), SLOT(widgetClick()));
+
+ /* allow selection of a custom sound file */
+ connect(ui_.soundFileButton, SIGNAL(clicked()), SLOT(selectSoundFile()));
+
+ /* allowing reordering items */
+ connect(ui_.moveUpButton, SIGNAL(clicked()), this, SLOT(onUpButtonClicked()));
+ connect(ui_.moveDownButton, SIGNAL(clicked()), this, SLOT(onDownButtonClicked()));
+
+ setWindowTitle(tr("Highlight Rules"));
+}
+
+QtHighlightEditor::~QtHighlightEditor()
+{
+}
+
+std::string formatShortDescription(const HighlightRule &rule)
+{
+ const std::string chatOrRoom = (rule.getMatchChat() ? "chat" : "room");
+
+ std::vector<std::string> senders = rule.getSenders();
+ std::vector<std::string> keywords = rule.getKeywords();
+
+ if (senders.empty() && keywords.empty() && !rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages.";
+ }
+
+ if (rule.getNickIsKeyword()) {
+ return std::string("All ") + chatOrRoom + " messages that mention my name.";
+ }
+
+ if (!senders.empty()) {
+ return std::string("All ") + chatOrRoom + " messages from " + senders[0] + ".";
+ }
+
+ if (!keywords.empty()) {
+ return std::string("All ") + chatOrRoom + " messages mentioning the keyword '" + keywords[0] + "'.";
+ }
+
+ return "Unknown Rule";
+}
+
+void QtHighlightEditor::show()
+{
+ highlightManager_->loadSettings();
+
+ populateList();
+
+ if (ui_.listWidget->count()) {
+ selectRow(0);
+ }
+
+ /* prepare default states */
+ widgetClick();
+
+ QWidget::show();
+ QWidget::activateWindow();
+}
+
+void QtHighlightEditor::setHighlightManager(HighlightManager* highlightManager)
+{
+ highlightManager_ = highlightManager;
+}
+
+void QtHighlightEditor::setContactSuggestions(const std::vector<Contact::ref>& suggestions)
+{
+ jid_->setSuggestions(suggestions);
+}
+
+void QtHighlightEditor::colorOtherSelect()
+{
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
+}
+
+void QtHighlightEditor::colorCustomSelect()
+{
+ ui_.foregroundColor->setEnabled(true);
+ ui_.backgroundColor->setEnabled(true);
+}
+
+void QtHighlightEditor::soundOtherSelect()
+{
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
+}
+
+void QtHighlightEditor::soundCustomSelect()
+{
+ ui_.soundFile->setEnabled(true);
+ ui_.soundFileButton->setEnabled(true);
+}
+
+void QtHighlightEditor::onNewButtonClicked()
+{
+ int row = getSelectedRow() + 1;
+ populateList();
+ HighlightRule newRule;
+ newRule.setMatchMUC(true);
+ highlightManager_->insertRule(row, newRule);
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(P2QSTRING(formatShortDescription(newRule)));
+ QFont font;
+ font.setItalic(true);
+ item->setFont(font);
+ ui_.listWidget->insertItem(row, item);
+ selectRow(row);
+}
+
+void QtHighlightEditor::onDeleteButtonClicked()
+{
+ int selectedRow = getSelectedRow();
+ assert(selectedRow>=0 && selectedRow<ui_.listWidget->count());
+ delete ui_.listWidget->takeItem(selectedRow);
+ highlightManager_->removeRule(selectedRow);
+
+ if (!ui_.listWidget->count()) {
+ disableDialog();
+ ui_.deleteButton->setEnabled(false);
+ } else {
+ if (selectedRow == ui_.listWidget->count()) {
+ selectRow(ui_.listWidget->count() - 1);
+ } else {
+ selectRow(selectedRow);
+ }
+ }
+}
+
+void QtHighlightEditor::onUpButtonClicked() {
+ const size_t moveFrom = ui_.listWidget->currentRow();
+ const size_t moveTo = moveFrom - 1;
+ highlightManager_->swapRules(moveFrom, moveTo);
+ populateList();
+ selectRow(moveTo);
+}
+
+void QtHighlightEditor::onDownButtonClicked() {
+ const size_t moveFrom = ui_.listWidget->currentRow();
+ const size_t moveTo = moveFrom + 1;
+ highlightManager_->swapRules(moveFrom, moveTo);
+ populateList();
+ selectRow(moveTo);
+}
+
+void QtHighlightEditor::onCurrentRowChanged(int currentRow)
+{
+ ui_.deleteButton->setEnabled(currentRow != -1);
+ ui_.moveUpButton->setEnabled(currentRow != -1 && currentRow != 0);
+ ui_.moveDownButton->setEnabled(currentRow != -1 && currentRow != (ui_.listWidget->count()-1));
+
+ if (previousRow_ != -1) {
+ if (ui_.listWidget->count() > previousRow_) {
+ QFont font;
+ font.setItalic(false);
+ ui_.listWidget->item(previousRow_)->setFont(font);
+ highlightManager_->setRule(previousRow_, ruleFromDialog());
+ }
+ }
+
+ if (currentRow != -1) {
+ HighlightRule rule = highlightManager_->getRule(currentRow);
+ ruleToDialog(rule);
+ if (ui_.listWidget->currentItem()) {
+ QFont font;
+ font.setItalic(true);
+ ui_.listWidget->currentItem()->setFont(font);
+ ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
+ }
+ }
+
+ /* grey the dialog if we have nothing selected */
+ if (currentRow == -1) {
+ disableDialog();
+ }
+
+ previousRow_ = currentRow;
+}
+
+void QtHighlightEditor::onApplyButtonClick()
+{
+ selectRow(getSelectedRow()); /* force save */
+ highlightManager_->storeSettings();
+}
+
+void QtHighlightEditor::onCancelButtonClick()
+{
+ close();
+}
+
+void QtHighlightEditor::onOkButtonClick()
+{
+ onApplyButtonClick();
+ close();
+}
+
+void QtHighlightEditor::setChildWidgetStates()
+{
+ /* disable appropriate radio button child widgets */
+
+ if (ui_.chatRadio->isChecked()) {
+ if (ui_.nickIsKeyword->isChecked()) {
+ /* switch to another choice before we disable this button */
+ ui_.allMsgRadio->setChecked(true);
+ }
+ ui_.nickIsKeyword->setEnabled(false);
+ } else if (ui_.roomRadio->isChecked()) {
+ ui_.nickIsKeyword->setEnabled(true);
+ } else { /* chats and rooms */
+ ui_.nickIsKeyword->setEnabled(true);
+ }
+
+ if (ui_.senderRadio->isChecked()) {
+ jid_->setEnabled(true);
+ } else {
+ jid_->setEnabled(false);
+ }
+
+ if (ui_.keywordRadio->isChecked()) {
+ ui_.keyword->setEnabled(true);
+ ui_.matchPartialWords->setEnabled(true);
+ ui_.matchCase->setEnabled(true);
+ } else {
+ ui_.keyword->setEnabled(false);
+ ui_.matchPartialWords->setEnabled(false);
+ ui_.matchCase->setEnabled(false);
+ }
+
+ if (ui_.chatRadio->isChecked()) {
+ ui_.allMsgRadio->setText(tr("Apply to all chat messages"));
+ } else {
+ ui_.allMsgRadio->setText(tr("Apply to all room messages"));
+ }
+}
+
+void QtHighlightEditor::widgetClick()
+{
+ setChildWidgetStates();
+
+ HighlightRule rule = ruleFromDialog();
+
+ if (ui_.listWidget->currentItem()) {
+ ui_.listWidget->currentItem()->setText(P2QSTRING(formatShortDescription(rule)));
+ }
+}
+
+void QtHighlightEditor::disableDialog()
+{
+ ui_.chatRadio->setEnabled(false);
+ ui_.roomRadio->setEnabled(false);
+ ui_.allMsgRadio->setEnabled(false);
+ ui_.nickIsKeyword->setEnabled(false);
+ ui_.senderRadio->setEnabled(false);
+ ui_.dummySenderName->setEnabled(false);
+ ui_.keywordRadio->setEnabled(false);
+ ui_.keyword->setEnabled(false);
+ ui_.matchPartialWords->setEnabled(false);
+ ui_.matchCase->setEnabled(false);
+ ui_.noColorRadio->setEnabled(false);
+ ui_.customColorRadio->setEnabled(false);
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
+ ui_.noSoundRadio->setEnabled(false);
+ ui_.defaultSoundRadio->setEnabled(false);
+ ui_.customSoundRadio->setEnabled(false);
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
+}
+
+void QtHighlightEditor::handleContactSuggestionRequested(const QString& text)
+{
+ std::string stdText = Q2PSTRING(text);
+ onContactSuggestionsRequested(stdText);
+}
+
+void QtHighlightEditor::selectSoundFile()
+{
+ QString path = QFileDialog::getOpenFileName(this, tr("Select sound file..."), QString(), "Sounds (*.wav)");
+ ui_.soundFile->setText(path);
+}
+
+void QtHighlightEditor::handleOnUserSelected(const Contact::ref& contact) {
+ /* this might seem like it should be standard behaviour for the suggesting input box, but is not desirable in all cases */
+ if (contact->jid.isValid()) {
+ jid_->setText(P2QSTRING(contact->jid.toString()));
+ } else {
+ jid_->setText(P2QSTRING(contact->name));
+ }
+}
+
+void QtHighlightEditor::populateList()
+{
+ previousRow_ = -1;
+ ui_.listWidget->clear();
+ HighlightRulesListPtr rules = highlightManager_->getRules();
+ for (size_t i = 0; i < rules->getSize(); ++i) {
+ const HighlightRule& rule = rules->getRule(i);
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText(P2QSTRING(formatShortDescription(rule)));
+ ui_.listWidget->addItem(item);
+ }
+}
+
+void QtHighlightEditor::selectRow(int row)
+{
+ for (int i = 0; i < ui_.listWidget->count(); ++i) {
+ if (i == row) {
+ ui_.listWidget->item(i)->setSelected(true);
+ onCurrentRowChanged(i);
+ } else {
+ ui_.listWidget->item(i)->setSelected(false);
+ }
+ }
+ ui_.listWidget->setCurrentRow(row);
+}
+
+int QtHighlightEditor::getSelectedRow() const
+{
+ for (int i = 0; i < ui_.listWidget->count(); ++i) {
+ if (ui_.listWidget->item(i)->isSelected()) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+HighlightRule QtHighlightEditor::ruleFromDialog()
+{
+ HighlightRule rule;
+ HighlightAction& action = rule.getAction();
+
+ if (ui_.chatRadio->isChecked()) {
+ rule.setMatchChat(true);
+ rule.setMatchMUC(false);
+ } else {
+ rule.setMatchChat(false);
+ rule.setMatchMUC(true);
+ }
+
+ if (ui_.senderRadio->isChecked()) {
+ QString senderName = jid_->text();
+ if (!senderName.isEmpty()) {
+ std::vector<std::string> senders;
+ senders.push_back(Q2PSTRING(senderName));
+ rule.setSenders(senders);
+ action.setHighlightAllText(true);
+ }
+ }
+
+ if (ui_.keywordRadio->isChecked()) {
+ QString keywordString = ui_.keyword->text();
+ if (!keywordString.isEmpty()) {
+ std::vector<std::string> keywords;
+ keywords.push_back(Q2PSTRING(keywordString));
+ rule.setKeywords(keywords);
+ }
+ }
+
+ if (ui_.nickIsKeyword->isChecked()) {
+ rule.setNickIsKeyword(true);
+ rule.setMatchWholeWords(true);
+ rule.setMatchCase(true);
+ } else {
+ rule.setMatchWholeWords(!ui_.matchPartialWords->isChecked());
+ rule.setMatchCase(ui_.matchCase->isChecked());
+ }
+
+ if (ui_.noColorRadio->isChecked()) {
+ action.setTextColor("");
+ action.setTextBackground("");
+ } else {
+ action.setTextColor(Q2PSTRING(ui_.foregroundColor->getColor().name()));
+ action.setTextBackground(Q2PSTRING(ui_.backgroundColor->getColor().name()));
+ }
+
+ if (ui_.noSoundRadio->isChecked()) {
+ action.setPlaySound(false);
+ } else if (ui_.defaultSoundRadio->isChecked()) {
+ action.setPlaySound(true);
+ action.setSoundFile("");
+ } else {
+ action.setPlaySound(true);
+ action.setSoundFile(Q2PSTRING(ui_.soundFile->text()));
+ }
+
+ return rule;
+}
+
+void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
+{
+ ui_.chatRadio->setEnabled(true);
+ ui_.roomRadio->setEnabled(true);
+
+ if (rule.getMatchMUC()) {
+ ui_.chatRadio->setChecked(false);
+ ui_.roomRadio->setChecked(true);
+ } else {
+ ui_.chatRadio->setChecked(true);
+ ui_.roomRadio->setChecked(false);
+ }
+
+ ui_.allMsgRadio->setEnabled(true);
+ ui_.allMsgRadio->setChecked(true); /* this is the default radio button */
+ jid_->setText("");
+ ui_.keyword->setText("");
+ ui_.matchPartialWords->setChecked(false);
+ ui_.matchCase->setChecked(false);
+
+ ui_.nickIsKeyword->setEnabled(true);
+ if (rule.getNickIsKeyword()) {
+ ui_.nickIsKeyword->setChecked(true);
+ }
+
+ ui_.senderRadio->setEnabled(true);
+ std::vector<std::string> senders = rule.getSenders();
+ if (!senders.empty()) {
+ ui_.senderRadio->setChecked(true);
+ jid_->setText(P2QSTRING(senders[0]));
+ }
+
+ ui_.keywordRadio->setEnabled(true);
+ std::vector<std::string> keywords = rule.getKeywords();
+ if (!keywords.empty()) {
+ ui_.keywordRadio->setChecked(true);
+ ui_.keyword->setText(P2QSTRING(keywords[0]));
+ ui_.matchPartialWords->setChecked(!rule.getMatchWholeWords());
+ ui_.matchCase->setChecked(rule.getMatchCase());
+ }
+
+ const HighlightAction& action = rule.getAction();
+
+ ui_.noColorRadio->setEnabled(true);
+ ui_.customColorRadio->setEnabled(true);
+ if (action.getTextColor().empty() && action.getTextBackground().empty()) {
+ ui_.noColorRadio->setChecked(true);
+ ui_.foregroundColor->setEnabled(false);
+ ui_.backgroundColor->setEnabled(false);
+ } else {
+ ui_.foregroundColor->setEnabled(true);
+ ui_.backgroundColor->setEnabled(true);
+ QColor foregroundColor(P2QSTRING(action.getTextColor()));
+ ui_.foregroundColor->setColor(foregroundColor);
+ QColor backgroundColor(P2QSTRING(action.getTextBackground()));
+ ui_.backgroundColor->setColor(backgroundColor);
+ ui_.customColorRadio->setChecked(true);
+ }
+
+ ui_.noSoundRadio->setEnabled(true);
+ ui_.defaultSoundRadio->setEnabled(true);
+ ui_.customSoundRadio->setEnabled(true);
+ ui_.soundFile->setText("");
+ ui_.soundFile->setEnabled(false);
+ ui_.soundFileButton->setEnabled(false);
+ if (action.playSound()) {
+ if (action.getSoundFile().empty()) {
+ ui_.defaultSoundRadio->setChecked(true);
+ } else {
+ ui_.customSoundRadio->setChecked(true);
+ ui_.soundFile->setText(P2QSTRING(action.getSoundFile()));
+ ui_.soundFile->setEnabled(true);
+ ui_.soundFileButton->setEnabled(true);
+ }
+ } else {
+ ui_.noSoundRadio->setChecked(true);
+ }
+
+ /* set radio button child option states */
+ setChildWidgetStates();
+}
+
+}
diff --git a/Swift/QtUI/QtHighlightEditor.h b/Swift/QtUI/QtHighlightEditor.h
new file mode 100644
index 0000000..93a19b6
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditor.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swift/Controllers/HighlightRule.h>
+#include <Swift/Controllers/UIInterfaces/HighlightEditorWindow.h>
+#include <Swift/QtUI/ui_QtHighlightEditor.h>
+
+namespace Swift {
+
+ class QtSettingsProvider;
+ class QtSuggestingJIDInput;
+ class QtWebKitChatView;
+
+ class QtHighlightEditor : public QWidget, public HighlightEditorWindow {
+ Q_OBJECT
+
+ public:
+ QtHighlightEditor(QtSettingsProvider* settings, QWidget* parent = NULL);
+ virtual ~QtHighlightEditor();
+
+ virtual void show();
+ virtual void setHighlightManager(HighlightManager* highlightManager);
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
+
+ private slots:
+ void colorOtherSelect();
+ void colorCustomSelect();
+ void soundOtherSelect();
+ void soundCustomSelect();
+ void onNewButtonClicked();
+ void onDeleteButtonClicked();
+ void onUpButtonClicked();
+ void onDownButtonClicked();
+ void onCurrentRowChanged(int currentRow);
+ void onApplyButtonClick();
+ void onCancelButtonClick();
+ void onOkButtonClick();
+ void setChildWidgetStates();
+ void widgetClick();
+ void disableDialog();
+ void handleContactSuggestionRequested(const QString& text);
+ void selectSoundFile();
+
+ private:
+ void handleOnUserSelected(const Contact::ref& contact);
+ void populateList();
+ void selectRow(int row);
+ int getSelectedRow() const;
+ HighlightRule ruleFromDialog();
+ void ruleToDialog(const HighlightRule& rule);
+
+ Ui::QtHighlightEditor ui_;
+ QtSettingsProvider* settings_;
+ HighlightManager* highlightManager_;
+ QtSuggestingJIDInput* jid_;
+ int previousRow_;
+ };
+
+}
diff --git a/Swift/QtUI/QtHighlightEditor.ui b/Swift/QtUI/QtHighlightEditor.ui
new file mode 100644
index 0000000..775771f
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditor.ui
@@ -0,0 +1,479 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtHighlightEditor</class>
+ <widget class="QWidget" name="QtHighlightEditor">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>500</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>500</width>
+ <height>600</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Sunken</enum>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>463</width>
+ <height>792</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Incoming messages are checked against the following rules. First rule that matches will be executed.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidget">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <spacer name="horizontalSpacer_8">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="newButton">
+ <property name="text">
+ <string>New Rule</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteButton">
+ <property name="text">
+ <string>Remove Rule</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="moveUpButton">
+ <property name="text">
+ <string>Move Up</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="moveDownButton">
+ <property name="text">
+ <string>Move Down</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Apply Rule To</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QRadioButton" name="roomRadio">
+ <property name="text">
+ <string>Rooms</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="chatRadio">
+ <property name="text">
+ <string>Chats</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>246</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_6">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Rule Conditions</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="allMsgRadio">
+ <property name="text">
+ <string>Apply to all messages</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="nickIsKeyword">
+ <property name="text">
+ <string>Only messages mentioning me</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="senderRadio">
+ <property name="text">
+ <string>Messages from this sender:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="senderName">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="dummySenderName"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="keywordRadio">
+ <property name="text">
+ <string>Messages containing this keyword:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="keyword"/>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="matchPartialWords">
+ <property name="text">
+ <string>Match keyword within longer words</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="matchCase">
+ <property name="text">
+ <string>Keyword is case sensitive</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Highlight Action</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_5">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <item>
+ <widget class="QRadioButton" name="noColorRadio">
+ <property name="text">
+ <string>No Highlight</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="customColorRadio">
+ <property name="text">
+ <string>Custom Color</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_5">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="Swift::QtColorToolButton" name="foregroundColor">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Text</string>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtColorToolButton" name="backgroundColor">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>&amp;Background</string>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Sound Action</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_6">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_7">
+ <item>
+ <widget class="QRadioButton" name="noSoundRadio">
+ <property name="text">
+ <string>No Sound</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="defaultSoundRadio">
+ <property name="text">
+ <string>Default Sound</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="customSoundRadio">
+ <property name="text">
+ <string>Custom Sound</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_8">
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="soundFile">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="readOnly">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="soundFileButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <item>
+ <spacer name="horizontalSpacer_4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>Swift::QtColorToolButton</class>
+ <extends>QToolButton</extends>
+ <header>QtColorToolButton.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtHighlightEditorWidget.cpp b/Swift/QtUI/QtHighlightEditorWidget.cpp
new file mode 100644
index 0000000..7ff094e
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditorWidget.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cassert>
+
+#include <Swift/QtUI/QtHighlightEditorWidget.h>
+#include <Swift/QtUI/QtHighlightRulesItemModel.h>
+
+namespace Swift {
+
+QtHighlightEditorWidget::QtHighlightEditorWidget(QWidget* parent)
+ : QWidget(parent)
+{
+ ui_.setupUi(this);
+
+ itemModel_ = new QtHighlightRulesItemModel(this);
+ ui_.treeView->setModel(itemModel_);
+ ui_.ruleWidget->setModel(itemModel_);
+
+ for (int i = 0; i < QtHighlightRulesItemModel::NumberOfColumns; ++i) {
+ switch (i) {
+ case QtHighlightRulesItemModel::ApplyTo:
+ case QtHighlightRulesItemModel::Sender:
+ case QtHighlightRulesItemModel::Keyword:
+ case QtHighlightRulesItemModel::Action:
+ ui_.treeView->showColumn(i);
+ break;
+ default:
+ ui_.treeView->hideColumn(i);
+ break;
+ }
+ }
+
+ setHighlightManager(NULL); // setup buttons for empty rules list
+
+ connect(ui_.treeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), SLOT(onCurrentRowChanged(QModelIndex)));
+
+ connect(ui_.newButton, SIGNAL(clicked()), SLOT(onNewButtonClicked()));
+ connect(ui_.deleteButton, SIGNAL(clicked()), SLOT(onDeleteButtonClicked()));
+
+ connect(ui_.moveUpButton, SIGNAL(clicked()), SLOT(onMoveUpButtonClicked()));
+ connect(ui_.moveDownButton, SIGNAL(clicked()), SLOT(onMoveDownButtonClicked()));
+
+ connect(ui_.closeButton, SIGNAL(clicked()), SLOT(close()));
+
+ setWindowTitle(tr("Highlight Rules"));
+}
+
+QtHighlightEditorWidget::~QtHighlightEditorWidget()
+{
+}
+
+void QtHighlightEditorWidget::show()
+{
+ if (itemModel_->rowCount(QModelIndex())) {
+ selectRow(0);
+ }
+ QWidget::show();
+ QWidget::activateWindow();
+}
+
+void QtHighlightEditorWidget::setHighlightManager(HighlightManager* highlightManager)
+{
+ itemModel_->setHighlightManager(highlightManager);
+ ui_.newButton->setEnabled(highlightManager != NULL);
+
+ ui_.ruleWidget->setEnabled(false);
+ ui_.deleteButton->setEnabled(false);
+ ui_.moveUpButton->setEnabled(false);
+ ui_.moveDownButton->setEnabled(false);
+}
+
+void QtHighlightEditorWidget::closeEvent(QCloseEvent* event) {
+ ui_.ruleWidget->save();
+ event->accept();
+}
+
+void QtHighlightEditorWidget::onNewButtonClicked()
+{
+ int row = getSelectedRow() + 1;
+ itemModel_->insertRow(row, QModelIndex());
+ selectRow(row);
+}
+
+void QtHighlightEditorWidget::onDeleteButtonClicked()
+{
+ int row = getSelectedRow();
+ assert(row >= 0);
+
+ itemModel_->removeRow(row, QModelIndex());
+ if (row == itemModel_->rowCount(QModelIndex())) {
+ --row;
+ }
+ selectRow(row);
+}
+
+void QtHighlightEditorWidget::onMoveUpButtonClicked()
+{
+ int row = getSelectedRow();
+ assert(row > 0);
+
+ ui_.ruleWidget->save();
+ ui_.ruleWidget->setActiveIndex(QModelIndex());
+ itemModel_->swapRows(row, row - 1);
+ selectRow(row - 1);
+}
+
+void QtHighlightEditorWidget::onMoveDownButtonClicked()
+{
+ int row = getSelectedRow();
+ assert(row < itemModel_->rowCount(QModelIndex()) - 1);
+
+ ui_.ruleWidget->save();
+ ui_.ruleWidget->setActiveIndex(QModelIndex());
+ if (itemModel_->swapRows(row, row + 1)) {
+ selectRow(row + 1);
+ }
+}
+
+void QtHighlightEditorWidget::onCurrentRowChanged(const QModelIndex& index)
+{
+ ui_.ruleWidget->save();
+ ui_.ruleWidget->setActiveIndex(index);
+
+ ui_.ruleWidget->setEnabled(index.isValid());
+
+ ui_.deleteButton->setEnabled(index.isValid());
+
+ ui_.moveUpButton->setEnabled(index.isValid() && index.row() != 0);
+ ui_.moveDownButton->setEnabled(index.isValid() && index.row() != itemModel_->rowCount(QModelIndex()) - 1);
+}
+
+void QtHighlightEditorWidget::selectRow(int row)
+{
+ QModelIndex index = itemModel_->index(row, 0, QModelIndex());
+ ui_.treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
+}
+
+/** Return index of selected row or -1 if none is selected */
+int QtHighlightEditorWidget::getSelectedRow() const
+{
+ QModelIndexList rows = ui_.treeView->selectionModel()->selectedRows();
+ return rows.isEmpty() ? -1 : rows[0].row();
+}
+
+}
diff --git a/Swift/QtUI/QtHighlightEditorWidget.h b/Swift/QtUI/QtHighlightEditorWidget.h
new file mode 100644
index 0000000..1293c87
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditorWidget.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swift/Controllers/UIInterfaces/HighlightEditorWidget.h>
+#include <Swift/QtUI/ui_QtHighlightEditorWidget.h>
+
+namespace Swift {
+
+ class QtHighlightRulesItemModel;
+
+ class QtHighlightEditorWidget : public QWidget, public HighlightEditorWidget {
+ Q_OBJECT
+
+ public:
+ QtHighlightEditorWidget(QWidget* parent = NULL);
+ virtual ~QtHighlightEditorWidget();
+
+ void show();
+
+ void setHighlightManager(HighlightManager* highlightManager);
+
+ private slots:
+ void onNewButtonClicked();
+ void onDeleteButtonClicked();
+ void onMoveUpButtonClicked();
+ void onMoveDownButtonClicked();
+ void onCurrentRowChanged(const QModelIndex&);
+
+ private:
+ virtual void closeEvent(QCloseEvent* event);
+
+ void selectRow(int row);
+ int getSelectedRow() const;
+
+ Ui::QtHighlightEditorWidget ui_;
+ QtHighlightRulesItemModel* itemModel_;
+ };
+
+}
diff --git a/Swift/QtUI/QtHighlightEditorWidget.ui b/Swift/QtUI/QtHighlightEditorWidget.ui
new file mode 100644
index 0000000..0f39168
--- /dev/null
+++ b/Swift/QtUI/QtHighlightEditorWidget.ui
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtHighlightEditorWidget</class>
+ <widget class="QWidget" name="QtHighlightEditorWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>419</width>
+ <height>373</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Incoming messages are checked against the following rules. First rule that matches will be executed.</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QTreeView" name="treeView">
+ <property name="rootIsDecorated">
+ <bool>false</bool>
+ </property>
+ <property name="itemsExpandable">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Swift::QtHighlightRuleWidget" name="ruleWidget" native="true"/>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QPushButton" name="newButton">
+ <property name="text">
+ <string>New</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deleteButton">
+ <property name="text">
+ <string>Delete</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="moveUpButton">
+ <property name="text">
+ <string>Move up</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="moveDownButton">
+ <property name="text">
+ <string>Move down</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="closeButton">
+ <property name="text">
+ <string>Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>Swift::QtHighlightRuleWidget</class>
+ <extends>QWidget</extends>
+ <header>QtHighlightRuleWidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtHighlightRulesItemModel.cpp b/Swift/QtUI/QtHighlightRulesItemModel.cpp
new file mode 100644
index 0000000..fcbaddc
--- /dev/null
+++ b/Swift/QtUI/QtHighlightRulesItemModel.cpp
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <boost/algorithm/string.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <QStringList>
+#include <QColor>
+
+#include <Swift/Controllers/HighlightManager.h>
+#include <Swift/QtUI/QtHighlightRulesItemModel.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtHighlightRulesItemModel::QtHighlightRulesItemModel(QObject* parent) : QAbstractItemModel(parent), highlightManager_(NULL)
+{
+}
+
+void QtHighlightRulesItemModel::setHighlightManager(HighlightManager* highlightManager)
+{
+ emit layoutAboutToBeChanged();
+ highlightManager_ = highlightManager;
+ emit layoutChanged();
+}
+
+QVariant QtHighlightRulesItemModel::headerData(int section, Qt::Orientation /* orientation */, int role) const
+{
+ if (role == Qt::DisplayRole) {
+ switch (section) {
+ case ApplyTo: return QVariant(tr("Apply to"));
+ case Sender: return QVariant(tr("Sender"));
+ case Keyword: return QVariant(tr("Keyword"));
+ case Action: return QVariant(tr("Action"));
+ case NickIsKeyword: return QVariant(tr("Nick Is Keyword"));
+ case MatchCase: return QVariant(tr("Match Case"));
+ case MatchWholeWords: return QVariant(tr("Match Whole Words"));
+ case HighlightText: return QVariant(tr("Highlight Text"));
+ case TextColor: return QVariant(tr("Text Color"));
+ case TextBackground: return QVariant(tr("Text Background"));
+ case PlaySound: return QVariant(tr("Play Sounds"));
+ case SoundFile: return QVariant(tr("Sound File"));
+ }
+ }
+
+ return QVariant();
+}
+
+int QtHighlightRulesItemModel::columnCount(const QModelIndex& /* parent */) const
+{
+ return NumberOfColumns;
+}
+
+QVariant QtHighlightRulesItemModel::data(const QModelIndex &index, int role) const
+{
+ if (index.isValid() && highlightManager_ && (role == Qt::DisplayRole || role == Qt::EditRole)) {
+
+ const char* separator = (role == Qt::DisplayRole) ? " ; " : "\n";
+
+ if (boost::numeric_cast<std::vector<std::string>::size_type>(index.row()) < highlightManager_->getRules().size()) {
+ const HighlightRule& r = highlightManager_->getRules()[index.row()];
+ switch (index.column()) {
+ case ApplyTo: {
+ int applyTo = 0;
+ if (r.getMatchChat() && r.getMatchMUC()) {
+ applyTo = 1;
+ } else if (r.getMatchChat()) {
+ applyTo = 2;
+ } else if (r.getMatchMUC()) {
+ applyTo = 3;
+ }
+
+ if (role == Qt::DisplayRole) {
+ return QVariant(getApplyToString(applyTo));
+ } else {
+ return QVariant(applyTo);
+ }
+ }
+ case Sender: {
+ std::string s = boost::join(r.getSenders(), separator);
+ return QVariant(P2QSTRING(s));
+ }
+ case Keyword: {
+ std::string s = boost::join(r.getKeywords(), separator);
+ QString qs(P2QSTRING(s));
+ if (role == Qt::DisplayRole && r.getNickIsKeyword()) {
+ qs = tr("<nick>") + (qs.isEmpty() ? "" : separator + qs);
+ }
+ return QVariant(qs);
+ }
+ case Action: {
+ std::vector<std::string> v;
+ const HighlightAction & action = r.getAction();
+ if (action.highlightText()) {
+ v.push_back(Q2PSTRING(tr("Highlight text")));
+ }
+ if (action.playSound()) {
+ v.push_back(Q2PSTRING(tr("Play sound")));
+ }
+ std::string s = boost::join(v, separator);
+ return QVariant(P2QSTRING(s));
+ }
+ case NickIsKeyword: {
+ return QVariant(r.getNickIsKeyword());
+ }
+ case MatchCase: {
+ return QVariant(r.getMatchCase());
+ }
+ case MatchWholeWords: {
+ return QVariant(r.getMatchWholeWords());
+ }
+ case HighlightText: {
+ return QVariant(r.getAction().highlightText());
+ }
+ case TextColor: {
+ return QVariant(QColor(P2QSTRING(r.getAction().getTextColor())));
+ }
+ case TextBackground: {
+ return QVariant(QColor(P2QSTRING(r.getAction().getTextBackground())));
+ }
+ case PlaySound: {
+ return QVariant(r.getAction().playSound());
+ }
+ case SoundFile: {
+ return QVariant(P2QSTRING(r.getAction().getSoundFile()));
+ }
+ }
+ }
+ }
+ return QVariant();
+}
+
+bool QtHighlightRulesItemModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.isValid() && highlightManager_ && role == Qt::EditRole) {
+ if (boost::numeric_cast<std::vector<std::string>::size_type>(index.row()) < highlightManager_->getRules().size()) {
+ HighlightRule r = highlightManager_->getRule(index.row());
+ std::vector<int> changedColumns;
+ switch (index.column()) {
+ case ApplyTo: {
+ bool ok = false;
+ int applyTo = value.toInt(&ok);
+ if (!ok) {
+ return false;
+ }
+ r.setMatchChat(applyTo == ApplyToAll || applyTo == ApplyToChat);
+ r.setMatchMUC(applyTo == ApplyToAll || applyTo == ApplyToMUC);
+ break;
+ }
+ case Sender:
+ case Keyword: {
+ std::string s = Q2PSTRING(value.toString());
+ std::vector<std::string> v;
+ boost::split(v, s, boost::is_any_of("\n"));
+ v.erase(std::remove_if(v.begin(), v.end(), boost::lambda::_1 == ""), v.end());
+ if (index.column() == Sender) {
+ r.setSenders(v);
+ } else {
+ r.setKeywords(v);
+ }
+ break;
+ }
+ case NickIsKeyword: {
+ r.setNickIsKeyword(value.toBool());
+ changedColumns.push_back(Keyword); // "<nick>"
+ break;
+ }
+ case MatchCase: {
+ r.setMatchCase(value.toBool());
+ break;
+ }
+ case MatchWholeWords: {
+ r.setMatchWholeWords(value.toBool());
+ break;
+ }
+ case HighlightText: {
+ r.getAction().setHighlightText(value.toBool());
+ changedColumns.push_back(Action);
+ break;
+ }
+ case TextColor: {
+ QColor c = value.value<QColor>();
+ r.getAction().setTextColor(c.isValid() ? Q2PSTRING(c.name()) : "");
+ break;
+ }
+ case TextBackground: {
+ QColor c = value.value<QColor>();
+ r.getAction().setTextBackground(c.isValid() ? Q2PSTRING(c.name()) : "");
+ break;
+ }
+ case PlaySound: {
+ r.getAction().setPlaySound(value.toBool());
+ changedColumns.push_back(Action);
+ break;
+ }
+ case SoundFile: {
+ r.getAction().setSoundFile(Q2PSTRING(value.toString()));
+ break;
+ }
+ }
+
+ highlightManager_->setRule(index.row(), r);
+ emit dataChanged(index, index);
+ foreach (int column, changedColumns) {
+ QModelIndex i = createIndex(index.row(), column, static_cast<void*>(0));
+ emit dataChanged(i, i);
+ }
+ }
+ }
+
+ return false;
+}
+
+QModelIndex QtHighlightRulesItemModel::parent(const QModelIndex& /* child */) const
+{
+ return QModelIndex();
+}
+
+int QtHighlightRulesItemModel::rowCount(const QModelIndex& /* parent */) const
+{
+ return highlightManager_ ? highlightManager_->getRules().size() : 0;
+}
+
+QModelIndex QtHighlightRulesItemModel::index(int row, int column, const QModelIndex& /* parent */) const
+{
+ return createIndex(row, column, static_cast<void*>(0));
+}
+
+bool QtHighlightRulesItemModel::insertRows(int row, int count, const QModelIndex& /* parent */)
+{
+ if (highlightManager_) {
+ beginInsertRows(QModelIndex(), row, row + count);
+ while (count--) {
+ highlightManager_->insertRule(row, HighlightRule());
+ }
+ endInsertRows();
+ return true;
+ }
+ return false;
+}
+
+bool QtHighlightRulesItemModel::removeRows(int row, int count, const QModelIndex& /* parent */)
+{
+ if (highlightManager_) {
+ beginRemoveRows(QModelIndex(), row, row + count);
+ while (count--) {
+ highlightManager_->removeRule(row);
+ }
+ endRemoveRows();
+ return true;
+ }
+ return false;
+}
+
+bool QtHighlightRulesItemModel::swapRows(int row1, int row2)
+{
+ if (highlightManager_) {
+ assert(row1 >= 0 && row2 >= 0 && boost::numeric_cast<std::vector<std::string>::size_type>(row1) < highlightManager_->getRules().size() && boost::numeric_cast<std::vector<std::string>::size_type>(row2) < highlightManager_->getRules().size());
+ HighlightRule r = highlightManager_->getRule(row1);
+ highlightManager_->setRule(row1, highlightManager_->getRule(row2));
+ highlightManager_->setRule(row2, r);
+ emit dataChanged(index(row1, 0, QModelIndex()), index(row1, 0, QModelIndex()));
+ emit dataChanged(index(row2, 0, QModelIndex()), index(row2, 0, QModelIndex()));
+ return true;
+ }
+ return false;
+}
+
+QString QtHighlightRulesItemModel::getApplyToString(int applyTo)
+{
+ switch (applyTo) {
+ case ApplyToNone: return tr("None");
+ case ApplyToAll: return tr("Chat or MUC");
+ case ApplyToChat: return tr("Chat");
+ case ApplyToMUC: return tr("MUC");
+ default: return "";
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtHighlightRulesItemModel.h b/Swift/QtUI/QtHighlightRulesItemModel.h
new file mode 100644
index 0000000..ac85628
--- /dev/null
+++ b/Swift/QtUI/QtHighlightRulesItemModel.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012 Maciej Niedzielski
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QAbstractItemModel>
+
+namespace Swift {
+
+ class HighlightManager;
+
+ class QtHighlightRulesItemModel : public QAbstractItemModel {
+ Q_OBJECT
+
+ public:
+ QtHighlightRulesItemModel(QObject* parent = NULL);
+
+ void setHighlightManager(HighlightManager* highlightManager);
+
+ QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+ int columnCount(const QModelIndex& parent) const;
+ QVariant data(const QModelIndex& index, int role) const;
+ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ QModelIndex parent(const QModelIndex& child) const;
+ int rowCount(const QModelIndex& parent) const;
+ QModelIndex index(int row, int column, const QModelIndex& parent) const;
+ bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
+ bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
+ bool swapRows(int row1, int row2);
+
+ static QString getApplyToString(int);
+
+ enum Columns {
+ ApplyTo = 0,
+ Sender,
+ Keyword,
+ Action,
+ NickIsKeyword,
+ MatchCase,
+ MatchWholeWords,
+ HighlightText,
+ TextColor,
+ TextBackground,
+ PlaySound,
+ SoundFile,
+ NumberOfColumns // end of list marker
+ };
+
+ enum ApplyToValues {
+ ApplyToNone = 0,
+ ApplyToAll,
+ ApplyToChat,
+ ApplyToMUC,
+ ApplyToEOL // end of list marker
+ };
+
+ private:
+ HighlightManager* highlightManager_;
+ };
+
+}
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp
new file mode 100644
index 0000000..75eeaad
--- /dev/null
+++ b/Swift/QtUI/QtHistoryWindow.cpp
@@ -0,0 +1,264 @@
+/*
+ * Copyright (c) 2012-2013 Catalin Badea
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2013 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <QtHistoryWindow.h>
+
+#include <string>
+
+#include <boost/date_time/gregorian/gregorian.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <QTime>
+#include <QUrl>
+#include <QMenu>
+#include <QTextDocument>
+#include <QDateTime>
+#include <QLineEdit>
+
+#include <Swiften/History/HistoryMessage.h>
+
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/MessageSnippet.h>
+#include <Swift/QtUI/QtScaledAvatarCache.h>
+#include <Swift/QtUI/ChatSnippet.h>
+#include <Swift/QtUI/QtUtilities.h>
+#include <Swift/QtUI/Roster/QtTreeWidget.h>
+#include <Swift/QtUI/QtWebKitChatView.h>
+
+namespace Swift {
+
+QtHistoryWindow::QtHistoryWindow(SettingsProvider* settings, UIEventStream* eventStream) :
+ previousTopMessageWasSelf_(false),
+ previousBottomMessageWasSelf_(false) {
+ ui_.setupUi(this);
+
+ theme_ = new QtChatTheme("");
+ idCounter_ = 0;
+
+ delete ui_.conversation_;
+ conversation_ = new QtWebKitChatView(NULL, NULL, theme_, this, true); // Horrible unsafe. Do not do this. FIXME
+ QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ sizePolicy.setHorizontalStretch(80);
+ sizePolicy.setVerticalStretch(0);
+ conversation_->setSizePolicy(sizePolicy);
+
+ ui_.conversation_ = conversation_;
+ ui_.bottomLayout_->addWidget(conversation_);
+
+ delete ui_.conversationRoster_;
+ conversationRoster_ = new QtTreeWidget(eventStream, settings, QtTreeWidget::MessageDefaultJID, this);
+ QSizePolicy sizePolicy2(QSizePolicy::Preferred, QSizePolicy::Expanding);
+ sizePolicy2.setVerticalStretch(80);
+ conversationRoster_->setSizePolicy(sizePolicy2);
+ ui_.conversationRoster_ = conversationRoster_;
+ ui_.bottomLeftLayout_->setDirection(QBoxLayout::BottomToTop);
+ ui_.bottomLeftLayout_->addWidget(conversationRoster_);
+
+ setWindowTitle(tr("History"));
+
+ conversationRoster_->onSomethingSelectedChanged.connect(boost::bind(&QtHistoryWindow::handleSomethingSelectedChanged, this, _1));
+ connect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
+ connect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
+ connect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
+ connect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
+ connect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
+ connect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ connect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ connect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ connect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
+}
+
+QtHistoryWindow::~QtHistoryWindow() {
+ disconnect(conversation_, SIGNAL(scrollRequested(int)), this, SLOT(handleScrollRequested(int)));
+ disconnect(conversation_, SIGNAL(scrollReachedTop()), this, SLOT(handleScrollReachedTop()));
+ disconnect(conversation_, SIGNAL(scrollReachedBottom()), this, SLOT(handleScrollReachedBottom()));
+ disconnect(conversation_, SIGNAL(fontResized(int)), this, SLOT(handleFontResized(int)));
+ disconnect(ui_.searchBox_->lineEdit(), SIGNAL(returnPressed()), this, SLOT(handleReturnPressed()));
+ disconnect(ui_.calendarWidget_, SIGNAL(clicked(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ disconnect(ui_.calendarWidget_, SIGNAL(activated(const QDate&)), this, SLOT(handleCalendarClicked(const QDate&)));
+ disconnect(ui_.previousButton_, SIGNAL(clicked(bool)), this, SLOT(handlePreviousButtonClicked()));
+ disconnect(ui_.nextButton_, SIGNAL(clicked(bool)), this, SLOT(handleNextButtonClicked()));
+
+ delete theme_;
+ delete conversation_;
+ // TODO: delete ui_
+}
+
+void QtHistoryWindow::activate() {
+ emit wantsToActivate();
+}
+
+void QtHistoryWindow::showEvent(QShowEvent* event) {
+ emit windowOpening();
+ emit titleUpdated();
+ QWidget::showEvent(event);
+}
+
+void QtHistoryWindow::closeEvent(QCloseEvent* event) {
+ emit windowClosing();
+ event->accept();
+}
+
+void QtHistoryWindow::setRosterModel(Roster* model) {
+ conversationRoster_->setRosterModel(model);
+}
+
+void QtHistoryWindow::addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop) {
+ QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
+
+ QString messageHTML(P2QSTRING(message));
+ messageHTML = QtUtilities::htmlEscape(messageHTML);
+ QString searchTerm = ui_.searchBox_->lineEdit()->text();
+ if (searchTerm.length()) {
+ messageHTML.replace(searchTerm, "<span style='background-color: yellow'>" + searchTerm + "</span>");
+ }
+
+ // note: time uses localtime
+ QDate date = QDate(time.date().year(), time.date().month(), time.date().day());
+ QTime dayTime = QTime(time.time_of_day().hours(), time.time_of_day().minutes(), time.time_of_day().seconds());
+ QDateTime qTime = QDateTime(date, dayTime);
+
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+
+ QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
+
+ if (addAtTheTop) {
+ bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName)));
+ conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message))));
+
+ previousTopMessageWasSelf_ = senderIsSelf;
+ previousTopSenderName_ = P2QSTRING(senderName);
+ }
+ else {
+ bool appendToPrevious = ((senderIsSelf && previousBottomMessageWasSelf_) || (!senderIsSelf && !previousBottomMessageWasSelf_&& previousBottomSenderName_ == P2QSTRING(senderName)));
+ conversation_->addMessageBottom(boost::make_shared<MessageSnippet>(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message)));
+ previousBottomMessageWasSelf_ = senderIsSelf;
+ previousBottomSenderName_ = P2QSTRING(senderName);
+ }
+
+ // keep track of the days viewable in the chatView
+ if (!dates_.count(date)) {
+ dates_.insert(date);
+ }
+}
+
+void QtHistoryWindow::handleSomethingSelectedChanged(RosterItem* item) {
+ onSelectedContactChanged(item);
+}
+
+void QtHistoryWindow::resetConversationView() {
+ previousTopMessageWasSelf_ = false;
+ previousBottomMessageWasSelf_ = false;
+ previousTopSenderName_.clear();
+ previousBottomSenderName_.clear();
+
+ dates_.clear();
+ conversation_->resetView();
+}
+
+void QtHistoryWindow::handleScrollRequested(int pos) {
+ // first message starts with offset 5
+ if (pos < 5) {
+ pos = 5;
+ }
+
+ QDate currentDate;
+ foreach (const QDate& date, dates_) {
+ int snippetPosition = conversation_->getSnippetPositionByDate(date);
+ if (snippetPosition <= pos) {
+ currentDate = date;
+ }
+ }
+
+ if (ui_.calendarWidget_->selectedDate() != currentDate) {
+ ui_.calendarWidget_->setSelectedDate(currentDate);
+ }
+}
+
+void QtHistoryWindow::handleScrollReachedTop() {
+ if (dates_.empty()) {
+ return;
+ }
+
+ int year, month, day;
+ QDate firstDate = *dates_.begin();
+ firstDate.getDate(&year, &month, &day);
+ onScrollReachedTop(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+}
+
+void QtHistoryWindow::handleScrollReachedBottom() {
+ if (dates_.empty()) {
+ return;
+ }
+
+ int year, month, day;
+ QDate lastDate = *dates_.rbegin();
+ lastDate.getDate(&year, &month, &day);
+ onScrollReachedBottom(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+}
+
+void QtHistoryWindow::handleReturnPressed() {
+ onReturnPressed(ui_.searchBox_->lineEdit()->text().toStdString());
+}
+
+void QtHistoryWindow::handleCalendarClicked(const QDate& date) {
+ int year, month, day;
+ QDate tempDate = date; // getDate discards const qualifier
+ tempDate.getDate(&year, &month, &day);
+ onCalendarClicked(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));
+}
+
+void QtHistoryWindow::setDate(const boost::gregorian::date& date) {
+ ui_.calendarWidget_->setSelectedDate(QDate::fromJulianDay(date.julian_day()));
+}
+
+void QtHistoryWindow::handleNextButtonClicked() {
+ onNextButtonClicked();
+}
+
+void QtHistoryWindow::handlePreviousButtonClicked() {
+ onPreviousButtonClicked();
+}
+
+void QtHistoryWindow::handleFontResized(int fontSizeSteps) {
+ conversation_->resizeFont(fontSizeSteps);
+
+ emit fontResized(fontSizeSteps);
+}
+
+void QtHistoryWindow::resetConversationViewTopInsertPoint() {
+ previousTopMessageWasSelf_ = false;
+ previousTopSenderName_ = QString();
+ conversation_->resetTopInsertPoint();
+}
+
+std::string QtHistoryWindow::getSearchBoxText() {
+ return ui_.searchBox_->lineEdit()->text().toStdString();
+}
+
+boost::gregorian::date QtHistoryWindow::getLastVisibleDate() {
+ if (!dates_.empty()) {
+ QDate lastDate = *dates_.rbegin();
+ int year, month, day;
+ lastDate.getDate(&year, &month, &day);
+
+ return boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day));
+ }
+ return boost::gregorian::date(boost::gregorian::not_a_date_time);
+}
+
+}
diff --git a/Swift/QtUI/QtHistoryWindow.h b/Swift/QtUI/QtHistoryWindow.h
new file mode 100644
index 0000000..fcbfd7e
--- /dev/null
+++ b/Swift/QtUI/QtHistoryWindow.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2012 Catalin Badea
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2013 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <set>
+
+#include <QDate>
+
+#include <Swift/Controllers/UIInterfaces/HistoryWindow.h>
+
+#include <Swift/QtUI/QtTabbable.h>
+
+#include <Swift/QtUI/ui_QtHistoryWindow.h>
+
+namespace Swift {
+ class QtTabbable;
+ class QtTreeWidget;
+ class QtWebKitChatView;
+ class QtChatTheme;
+ class SettingsProvider;
+ class UIEventStream;
+
+ class QtHistoryWindow : public QtTabbable, public HistoryWindow {
+ Q_OBJECT
+
+ public:
+ QtHistoryWindow(SettingsProvider*, UIEventStream*);
+ ~QtHistoryWindow();
+ void activate();
+ void setRosterModel(Roster*);
+ void addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const std::string& avatarPath, const boost::posix_time::ptime& time, bool addAtTheTop);
+ void resetConversationView();
+ void resetConversationViewTopInsertPoint();
+ void setDate(const boost::gregorian::date& date);
+
+ void closeEvent(QCloseEvent* event);
+ void showEvent(QShowEvent* event);
+
+ std::string getSearchBoxText();
+ boost::gregorian::date getLastVisibleDate();
+
+ signals:
+ void fontResized(int);
+
+ public slots:
+ void handleFontResized(int fontSizeSteps);
+
+ protected slots:
+ void handleScrollRequested(int pos);
+ void handleScrollReachedTop();
+ void handleScrollReachedBottom();
+ void handleReturnPressed();
+ void handleCalendarClicked(const QDate& date);
+ void handlePreviousButtonClicked();
+ void handleNextButtonClicked();
+
+ private:
+ void handleSomethingSelectedChanged(RosterItem* item);
+
+ Ui::QtHistoryWindow ui_;
+ QtChatTheme* theme_;
+ QtWebKitChatView* conversation_;
+ QtTreeWidget* conversationRoster_;
+ std::set<QDate> dates_;
+ int idCounter_;
+ bool previousTopMessageWasSelf_;
+ QString previousTopSenderName_;
+ bool previousBottomMessageWasSelf_;
+ QString previousBottomSenderName_;
+ };
+}
diff --git a/Swift/QtUI/QtHistoryWindow.ui b/Swift/QtUI/QtHistoryWindow.ui
new file mode 100644
index 0000000..71a4577
--- /dev/null
+++ b/Swift/QtUI/QtHistoryWindow.ui
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtHistoryWindow</class>
+ <widget class="QWidget" name="QtHistoryWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>608</width>
+ <height>522</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>History</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <layout class="QHBoxLayout" name="topLayout_">
+ <item>
+ <widget class="QLabel" name="label_">
+ <property name="text">
+ <string>Search:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="searchBox_">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="nextButton_">
+ <property name="text">
+ <string>Next</string>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="previousButton_">
+ <property name="text">
+ <string>Previous</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0">
+ <widget class="QSplitter" name="bottomLayout_">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <widget class="QWidget" name="layoutWidget">
+ <layout class="QVBoxLayout" name="bottomLeftLayout_" stretch="0,0">
+ <item>
+ <widget class="QWidget" name="conversationRoster_" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>5</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCalendarWidget" name="calendarWidget_">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="conversation_" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>85</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtJoinMUCWindow.ui b/Swift/QtUI/QtJoinMUCWindow.ui
index 4c4935a..f294f8c 100644
--- a/Swift/QtUI/QtJoinMUCWindow.ui
+++ b/Swift/QtUI/QtJoinMUCWindow.ui
@@ -26,5 +26,5 @@
<widget class="QLabel" name="label_4">
<property name="text">
- <string>Room:</string>
+ <string>Room Address:</string>
</property>
</widget>
@@ -40,11 +40,8 @@
<widget class="QLabel" name="label_5">
<property name="text">
- <string>Nickname:</string>
+ <string>Your Nickname:</string>
</property>
</widget>
</item>
- <item row="1" column="1" colspan="2">
- <widget class="QLineEdit" name="nickName"/>
- </item>
<item row="0" column="1">
<widget class="QLineEdit" name="room">
@@ -57,5 +54,5 @@
<widget class="QLabel" name="label">
<property name="text">
- <string>Password:</string>
+ <string>Room Password:</string>
</property>
</widget>
@@ -64,4 +61,7 @@
<widget class="QLineEdit" name="password"/>
</item>
+ <item row="1" column="1" colspan="2">
+ <widget class="QLineEdit" name="nickName"/>
+ </item>
</layout>
</item>
@@ -121,8 +121,10 @@
<tabstops>
<tabstop>room</tabstop>
+ <tabstop>searchButton</tabstop>
<tabstop>nickName</tabstop>
+ <tabstop>password</tabstop>
+ <tabstop>instantRoom</tabstop>
<tabstop>joinAutomatically</tabstop>
<tabstop>joinButton</tabstop>
- <tabstop>searchButton</tabstop>
</tabstops>
<resources/>
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index 094f96c..eeb4317 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -31,4 +31,5 @@
#include <Swift/Controllers/UIEvents/RequestXMLConsoleUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestFileTransferListUIEvent.h>
+#include <Swift/Controllers/UIEvents/RequestHighlightEditorUIEvent.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <Swift/Controllers/SettingConstants.h>
@@ -41,4 +42,5 @@
#include <QtMainWindow.h>
#include <QtUtilities.h>
+#include <QtConnectionSettingsWindow.h>
#ifdef HAVE_SCHANNEL
@@ -54,8 +56,10 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set
setWindowTitle("Swift");
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
setWindowIcon(QIcon(":/logo-icon-16.png"));
#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);
@@ -92,4 +96,5 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set
layout->addWidget(jidLabel);
+
username_ = new QComboBox(this);
username_->setEditable(true);
@@ -97,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);
@@ -106,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);
@@ -128,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_);
@@ -136,6 +147,14 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set
loginButton_->setAutoDefault(true);
loginButton_->setDefault(true);
+ loginButton_->setAccessibleName(tr("Connect now"));
layout->addWidget(loginButton_);
+ QLabel* connectionOptionsLabel = new QLabel(this);
+ connectionOptionsLabel->setText("<a href=\"#\"><font size='-1'>" + QObject::tr("Connection Options") + "</font></a>");
+ connectionOptionsLabel->setTextFormat(Qt::RichText);
+ connectionOptionsLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
+ layout->addWidget(connectionOptionsLabel);
+ connect(connectionOptionsLabel, SIGNAL(linkActivated(const QString&)), SLOT(handleOpenConnectionOptions()));
+
message_ = new QLabel(this);
message_->setTextFormat(Qt::RichText);
@@ -183,4 +202,8 @@ QtLoginWindow::QtLoginWindow(UIEventStream* uiEventStream, SettingsProvider* set
#endif
+ highlightEditorAction_ = new QAction(tr("&Edit Highlight Rules"), this);
+ connect(highlightEditorAction_, SIGNAL(triggered()), SLOT(handleShowHighlightEditor()));
+ generalMenu_->addAction(highlightEditorAction_);
+
toggleSoundsAction_ = new QAction(tr("&Play Sounds"), this);
toggleSoundsAction_->setCheckable(true);
@@ -297,5 +320,5 @@ void QtLoginWindow::removeAvailableAccount(const std::string& jid) {
}
-void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate) {
+void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options) {
QString username = P2QSTRING(defaultJID);
int index = -1;
@@ -309,4 +332,5 @@ void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std
passwords_.append(P2QSTRING(defaultPassword));
certificateFiles_.append(P2QSTRING(defaultCertificate));
+ options_.push_back(options);
username_->addItem(username);
} else {
@@ -314,4 +338,5 @@ void QtLoginWindow::addAvailableAccount(const std::string& defaultJID, const std
passwords_[index] = P2QSTRING(defaultPassword);
certificateFiles_[index] = P2QSTRING(defaultCertificate);
+ options_[index] = options;
}
}
@@ -324,9 +349,8 @@ void QtLoginWindow::handleUsernameTextChanged() {
password_->setText(passwords_[i]);
remember_->setChecked(password_->text() != "");
+ currentOptions_ = options_[i];
}
}
- if (!certificateFile_.isEmpty()) {
- certificateButton_->setChecked(true);
- }
+ certificateButton_->setChecked(!certificateFile_.isEmpty());
}
@@ -377,5 +401,5 @@ void QtLoginWindow::loginClicked() {
#endif
- onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), certificateString, certificate, remember_->isChecked(), loginAutomatically_->isChecked());
+ onLoginRequest(Q2PSTRING(username_->currentText()), Q2PSTRING(password_->text()), certificateString, certificate, currentOptions_, remember_->isChecked(), loginAutomatically_->isChecked());
if (settings_->getSetting(SettingConstants::FORGET_PASSWORDS)) { /* Mustn't remember logins */
username_->clearEditText();
@@ -399,5 +423,5 @@ void QtLoginWindow::handleCertficateChecked(bool checked) {
}
#else
- certificateFile_ = QFileDialog::getOpenFileName(this, tr("Select an authentication certificate"), QString(), QString("*.cert;*.p12;*.pfx"));
+ certificateFile_ = QFileDialog::getOpenFileName(this, tr("Select an authentication certificate"), QString(), tr("P12 files (*.cert *.p12 *.pfx);;All files (*.*)"));
if (certificateFile_.isEmpty()) {
certificateButton_->setChecked(false);
@@ -430,4 +454,8 @@ void QtLoginWindow::handleShowFileTransferOverview() {
}
+void QtLoginWindow::handleShowHighlightEditor() {
+ uiEventStream_->send(boost::make_shared<RequestHighlightEditorUIEvent>());
+}
+
void QtLoginWindow::handleToggleSounds(bool enabled) {
settings_->storeSetting(SettingConstants::PLAY_SOUNDS, enabled);
@@ -455,4 +483,5 @@ void QtLoginWindow::setInitialMenus() {
void QtLoginWindow::morphInto(MainWindow *mainWindow) {
+ setEnabled(false);
QtMainWindow *qtMainWindow = dynamic_cast<QtMainWindow*>(mainWindow);
assert(qtMainWindow);
@@ -465,4 +494,5 @@ void QtLoginWindow::morphInto(MainWindow *mainWindow) {
menuBar_->addMenu(menu);
}
+ setFocus();
}
@@ -507,5 +537,5 @@ void QtLoginWindow::moveEvent(QMoveEvent*) {
}
-bool QtLoginWindow::askUserToTrustCertificatePermanently(const std::string& message, Certificate::ref certificate) {
+bool QtLoginWindow::askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificates) {
QMessageBox dialog(this);
@@ -513,12 +543,24 @@ bool QtLoginWindow::askUserToTrustCertificatePermanently(const std::string& mess
dialog.setInformativeText(P2QSTRING(message) + "\n\n" + tr("Would you like to permanently trust this certificate? This must only be done if you know it is correct."));
- QString detailedText = tr("Subject: %1").arg(P2QSTRING(certificate->getSubjectName())) + "\n";
- detailedText += tr("SHA-1 Fingerprint: %1").arg(P2QSTRING(certificate->getSHA1Fingerprint()));
- dialog.setDetailedText(detailedText);
-
- dialog.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ dialog.addButton(tr("Show Certificate"), QMessageBox::HelpRole);
+ dialog.addButton(QMessageBox::Yes);
+ dialog.addButton(QMessageBox::No);
dialog.setDefaultButton(QMessageBox::No);
+ while (true) {
+ int result = dialog.exec();
+ if (result == QMessageBox::Yes || result == QMessageBox::No) {
+ return result == QMessageBox::Yes;
+ }
+ // FIXME: This isn't very nice, because the dialog disappears every time. We actually need a real
+ // dialog with a custom button.
+ QtMainWindow::openCertificateDialog(certificates, &dialog);
+ }
+}
- return dialog.exec() == QMessageBox::Yes;
+void QtLoginWindow::handleOpenConnectionOptions() {
+ QtConnectionSettingsWindow connectionSettings(currentOptions_);
+ if (connectionSettings.exec() == QDialog::Accepted) {
+ currentOptions_ = connectionSettings.getOptions();
+ }
}
diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h
index 8f50a35..7415fbf 100644
--- a/Swift/QtUI/QtLoginWindow.h
+++ b/Swift/QtUI/QtLoginWindow.h
@@ -44,10 +44,10 @@ namespace Swift {
virtual void setShowNotificationToggle(bool);
virtual void setMessage(const std::string& message);
- virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate);
+ virtual void addAvailableAccount(const std::string& defaultJID, const std::string& defaultPassword, const std::string& defaultCertificate, const ClientOptions& options);
virtual void removeAvailableAccount(const std::string& jid);
virtual void setLoginAutomatically(bool loginAutomatically);
virtual void setIsLoggingIn(bool loggingIn);
void selectUser(const std::string& user);
- bool askUserToTrustCertificatePermanently(const std::string& message, Certificate::ref certificate);
+ bool askUserToTrustCertificatePermanently(const std::string& message, const std::vector<Certificate::ref>& certificate);
void hide();
QtMenus getMenus() const;
@@ -63,4 +63,5 @@ namespace Swift {
void handleShowXMLConsole();
void handleShowFileTransferOverview();
+ void handleShowHighlightEditor();
void handleToggleSounds(bool enabled);
void handleToggleNotifications(bool enabled);
@@ -72,4 +73,5 @@ namespace Swift {
void moveEvent(QMoveEvent* event);
void handleSettingChanged(const std::string& settingPath);
+ void handleOpenConnectionOptions();
protected:
@@ -82,4 +84,5 @@ namespace Swift {
QStringList passwords_;
QStringList certificateFiles_;
+ std::vector<ClientOptions> options_;
QComboBox* username_;
QLineEdit* password_;
@@ -102,5 +105,7 @@ namespace Swift {
QAction* xmlConsoleAction_;
QAction* fileTransferOverviewAction_;
+ QAction* highlightEditorAction_;
TimerFactory* timerFactory_;
+ ClientOptions currentOptions_;
};
}
diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 05c78b3..52b6bcc 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -1,9 +1,9 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtMainWindow.h"
+#include <Swift/QtUI/QtMainWindow.h>
#include <boost/optional.hpp>
@@ -22,10 +22,8 @@
#include <QTabWidget>
-#include <Swift/QtUI/QtSwiftUtil.h>
-#include <Swift/QtUI/QtTabWidget.h>
-#include <Swift/QtUI/QtSettingsProvider.h>
-#include <Swift/QtUI/QtLoginWindow.h>
-#include <Roster/QtRosterWidget.h>
+#include <Swiften/Base/Platform.h>
+
#include <Swift/Controllers/UIEvents/RequestJoinMUCUIEvent.h>
+#include <Swift/Controllers/UIEvents/RequestHistoryUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAddUserDialogUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestChatWithUserDialogUIEvent.h>
@@ -33,10 +31,26 @@
#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
#include <Swift/Controllers/UIEvents/RequestAdHocUIEvent.h>
-#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/Controllers/UIEvents/RequestBlockListDialogUIEvent.h>
#include <Swift/Controllers/SettingConstants.h>
+#include <Swift/QtUI/Roster/QtFilterWidget.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtTabWidget.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+#include <Swift/QtUI/QtLoginWindow.h>
+#include <Swift/QtUI/Roster/QtRosterWidget.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/QtAdHocCommandWithJIDWindow.h>
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+#include <Swift/QtUI/CocoaUIHelpers.h>
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+#include <Swift/QtUI/WinUIHelpers.h>
+#else
+#include <Swift/QtUI/QtCertificateViewerDialog.h>
+#endif
+
namespace Swift {
-QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus) : QWidget(), MainWindow(false), loginMenus_(loginMenus) {
+QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID) : QWidget(), MainWindow(false), loginMenus_(loginMenus) {
uiEventStream_ = uiEventStream;
settings_ = settings;
@@ -45,8 +59,9 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->setSpacing(0);
- meView_ = new QtRosterHeader(settings, this);
+ meView_ = new QtRosterHeader(settings, statusCache, this);
mainLayout->addWidget(meView_);
connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&)));
connect(meView_, SIGNAL(onEditProfileRequest()), this, SLOT(handleEditProfileRequest()));
+ connect(meView_, SIGNAL(onShowCertificateInfo()), this, SLOT(handleShowCertificateInfo()));
tabs_ = new QtTabWidget(this);
@@ -64,5 +79,7 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
treeWidget_ = new QtRosterWidget(uiEventStream_, settings_, this);
+
contactTabLayout->addWidget(treeWidget_);
+ new QtFilterWidget(this, treeWidget_, uiEventStream_, contactTabLayout);
tabs_->addTab(contactsTabWidget_, tr("&Contacts"));
@@ -81,8 +98,30 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
connect(tabs_, SIGNAL(currentChanged(int)), this, SLOT(handleTabChanged(int)));
+ tabBarCombo_ = NULL;
+ if (settings_->getSetting(QtUISettingConstants::USE_SCREENREADER)) {
+ tabs_->tabBar()->hide();
+ tabBarCombo_ = new QComboBox(this);
+ tabBarCombo_->setAccessibleName("Current View");
+ tabBarCombo_->addItem(tr("Contacts"));
+ tabBarCombo_->addItem(tr("Chats"));
+ tabBarCombo_->addItem(tr("Notices"));
+ tabBarCombo_->setCurrentIndex(tabs_->currentIndex());
+ mainLayout->addWidget(tabBarCombo_);
+ connect(tabBarCombo_, SIGNAL(currentIndexChanged(int)), tabs_, SLOT(setCurrentIndex(int)));
+ }
+
+
this->setLayout(mainLayout);
QMenu* viewMenu = new QMenu(tr("&View"), this);
menus_.push_back(viewMenu);
+
+ compactRosterAction_ = new QAction(tr("&Compact Roster"), this);
+ compactRosterAction_->setCheckable(true);
+ compactRosterAction_->setChecked(false);
+ connect(compactRosterAction_, SIGNAL(toggled(bool)), SLOT(handleCompactRosterToggled(bool)));
+ viewMenu->addAction(compactRosterAction_);
+ handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+
showOfflineAction_ = new QAction(tr("&Show offline contacts"), this);
showOfflineAction_->setCheckable(true);
@@ -92,4 +131,13 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
+ if (emoticonsExist) {
+ showEmoticonsAction_ = new QAction(tr("&Show Emoticons"), this);
+ showEmoticonsAction_->setCheckable(true);
+ showEmoticonsAction_->setChecked(false);
+ connect(showEmoticonsAction_, SIGNAL(toggled(bool)), SLOT(handleShowEmoticonsToggled(bool)));
+ viewMenu->addAction(showEmoticonsAction_);
+ handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ }
+
//QAction* compactRosterAction_ = new QAction(tr("&Compact Roster"), this);
//compactRosterAction_->setCheckable(true);
@@ -100,20 +148,45 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
QMenu* actionsMenu = new QMenu(tr("&Actions"), this);
menus_.push_back(actionsMenu);
- QAction* editProfileAction = new QAction(tr("Edit &Profile"), this);
+ QAction* editProfileAction = new QAction(tr("Edit &Profile…"), this);
connect(editProfileAction, SIGNAL(triggered()), SLOT(handleEditProfileAction()));
actionsMenu->addAction(editProfileAction);
- QAction* joinMUCAction = new QAction(tr("Enter &Room"), this);
+ onlineOnlyActions_ << editProfileAction;
+ QAction* joinMUCAction = new QAction(tr("Enter &Room…"), this);
connect(joinMUCAction, SIGNAL(triggered()), SLOT(handleJoinMUCAction()));
actionsMenu->addAction(joinMUCAction);
- addUserAction_ = new QAction(tr("&Add Contact"), this);
+ onlineOnlyActions_ << joinMUCAction;
+#ifdef SWIFT_EXPERIMENTAL_HISTORY
+ QAction* viewLogsAction = new QAction(tr("&View History…"), this);
+ connect(viewLogsAction, SIGNAL(triggered()), SLOT(handleViewLogsAction()));
+ actionsMenu->addAction(viewLogsAction);
+#endif
+ openBlockingListEditor_ = new QAction(tr("Edit &Blocking List…"), this);
+ connect(openBlockingListEditor_, SIGNAL(triggered()), SLOT(handleEditBlockingList()));
+ actionsMenu->addAction(openBlockingListEditor_);
+ onlineOnlyActions_ << openBlockingListEditor_;
+ openBlockingListEditor_->setVisible(false);
+ addUserAction_ = new QAction(tr("&Add Contact…"), this);
+ addUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
+ addUserAction_->setShortcutContext(Qt::ApplicationShortcut);
connect(addUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleAddUserActionTriggered(bool)));
actionsMenu->addAction(addUserAction_);
- editUserAction_ = new QAction(tr("&Edit Selected Contact"), this);
+ onlineOnlyActions_ << addUserAction_;
+ editUserAction_ = new QAction(tr("&Edit Selected Contact…"), this);
connect(editUserAction_, SIGNAL(triggered(bool)), treeWidget_, SLOT(handleEditUserActionTriggered(bool)));
actionsMenu->addAction(editUserAction_);
+ onlineOnlyActions_ << editUserAction_;
editUserAction_->setEnabled(false);
- chatUserAction_ = new QAction(tr("Start &Chat"), this);
+ chatUserAction_ = new QAction(tr("Start &Chat…"), this);
+ chatUserAction_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
+ chatUserAction_->setShortcutContext(Qt::ApplicationShortcut);
connect(chatUserAction_, SIGNAL(triggered(bool)), this, SLOT(handleChatUserActionTriggered(bool)));
actionsMenu->addAction(chatUserAction_);
+ onlineOnlyActions_ << chatUserAction_;
+ if (enableAdHocCommandOnJID) {
+ otherAdHocAction_ = new QAction(tr("Run Other Command"), this);
+ connect(otherAdHocAction_, SIGNAL(triggered()), this, SLOT(handleOtherAdHocActionTriggered()));
+ actionsMenu->addAction(otherAdHocAction_);
+ onlineOnlyActions_ << otherAdHocAction_;
+ }
serverAdHocMenu_ = new QMenu(tr("Run Server Command"), this);
actionsMenu->addMenu(serverAdHocMenu_);
@@ -131,5 +204,5 @@ QtMainWindow::QtMainWindow(SettingsProvider* settings, UIEventStream* uiEventStr
loginMenus_.generalMenu->insertAction(generalMenuActions.at(generalMenuActions.count()-2),toggleRequestDeliveryReceipts_);
- treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QAction::setEnabled, editUserAction_, _1));
+ treeWidget_->onSomethingSelectedChanged.connect(boost::bind(&QtMainWindow::handleSomethingSelectedChanged, this, _1));
setAvailableAdHocCommands(std::vector<DiscoItems::Item>());
@@ -154,4 +227,17 @@ void QtMainWindow::handleToggleRequestDeliveryReceipts(bool enabled) {
}
+void QtMainWindow::handleShowCertificateInfo() {
+ onShowCertificateRequest();
+}
+
+void QtMainWindow::handleEditBlockingList() {
+ uiEventStream_->send(boost::make_shared<RequestBlockListDialogUIEvent>());
+}
+
+void QtMainWindow::handleSomethingSelectedChanged(bool itemSelected) {
+ bool isOnline = addUserAction_->isEnabled();
+ editUserAction_->setEnabled(isOnline && itemSelected);
+}
+
QtEventWindow* QtMainWindow::getEventWindow() {
return eventWindow_;
@@ -202,4 +288,8 @@ void QtMainWindow::handleChatUserActionTriggered(bool /*checked*/) {
}
+void QtMainWindow::handleOtherAdHocActionTriggered() {
+ new QtAdHocCommandWithJIDWindow(uiEventStream_);
+}
+
void QtMainWindow::handleSignOutAction() {
loginMenus_.generalMenu->removeAction(toggleRequestDeliveryReceipts_);
@@ -215,4 +305,8 @@ void QtMainWindow::handleJoinMUCAction() {
}
+void QtMainWindow::handleViewLogsAction() {
+ uiEventStream_->send(boost::make_shared<RequestHistoryUIEvent>());
+}
+
void QtMainWindow::handleStatusChanged(StatusShow::Type showType, const QString &statusMessage) {
onChangeStatusRequest(showType, Q2PSTRING(statusMessage));
@@ -223,7 +317,18 @@ void QtMainWindow::handleSettingChanged(const std::string& settingPath) {
handleShowOfflineToggled(settings_->getSetting(SettingConstants::SHOW_OFFLINE));
}
+ if (settingPath == QtUISettingConstants::SHOW_EMOTICONS.getKey()) {
+ handleShowEmoticonsToggled(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+ }
if (settingPath == SettingConstants::REQUEST_DELIVERYRECEIPTS.getKey()) {
toggleRequestDeliveryReceipts_->setChecked(settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS));
}
+ if (settingPath == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ handleCompactRosterToggled(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ }
+}
+
+void QtMainWindow::handleCompactRosterToggled(bool state) {
+ settings_->storeSetting(QtUISettingConstants::COMPACT_ROSTER, state);
+ compactRosterAction_->setChecked(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
}
@@ -233,4 +338,9 @@ void QtMainWindow::handleShowOfflineToggled(bool state) {
}
+void QtMainWindow::handleShowEmoticonsToggled(bool state) {
+ settings_->storeSetting(QtUISettingConstants::SHOW_EMOTICONS, state);
+ showEmoticonsAction_->setChecked(settings_->getSetting(QtUISettingConstants::SHOW_EMOTICONS));
+}
+
void QtMainWindow::setMyNick(const std::string& nick) {
meView_->setNick(P2QSTRING(nick));
@@ -251,4 +361,15 @@ void QtMainWindow::setMyStatusText(const std::string& status) {
void QtMainWindow::setMyStatusType(StatusShow::Type type) {
meView_->setStatusType(type);
+ const bool online = (type != StatusShow::None);
+ treeWidget_->setOnline(online);
+ chatListWindow_->setOnline(online);
+ foreach (QAction *action, onlineOnlyActions_) {
+ action->setEnabled(online);
+ }
+ serverAdHocMenu_->setEnabled(online);
+}
+
+void QtMainWindow::setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) {
+ meView_->setContactRosterItem(contact);
}
@@ -257,4 +378,22 @@ void QtMainWindow::setConnecting() {
}
+void QtMainWindow::setStreamEncryptionStatus(bool tlsInPlaceAndValid) {
+ meView_->setStreamEncryptionStatus(tlsInPlaceAndValid);
+}
+
+void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain) {
+ openCertificateDialog(chain, this);
+}
+
+void QtMainWindow::openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent) {
+#if defined(SWIFTEN_PLATFORM_MACOSX)
+ CocoaUIHelpers::displayCertificateChainAsSheet(parent, chain);
+#elif defined(SWIFTEN_PLATFORM_WINDOWS)
+ WinUIHelpers::displayCertificateChainAsSheet(parent, chain);
+#else
+ QtCertificateViewerDialog::displayCertificateChainAsSheet(parent, chain);
+#endif
+}
+
void QtMainWindow::handleAdHocActionTriggered(bool /*checked*/) {
QAction* action = qobject_cast<QAction*>(sender());
@@ -285,4 +424,8 @@ void QtMainWindow::setAvailableAdHocCommands(const std::vector<DiscoItems::Item>
}
+void QtMainWindow::setBlockingCommandAvailable(bool isAvailable) {
+ openBlockingListEditor_->setVisible(isAvailable);
+}
+
}
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index bef483d..ea92c79 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2011 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,14 +7,16 @@
#pragma once
+#include <vector>
+
#include <QWidget>
#include <QMenu>
#include <QList>
-#include "Swift/Controllers/UIInterfaces/MainWindow.h"
-#include "Swift/QtUI/QtRosterHeader.h"
-#include "Swift/QtUI/EventViewer/QtEventWindow.h"
-#include "Swift/QtUI/ChatList/QtChatListWindow.h"
-#include "Swift/QtUI/QtLoginWindow.h"
-#include <vector>
+#include <Swift/Controllers/UIInterfaces/MainWindow.h>
+
+#include <Swift/QtUI/QtRosterHeader.h>
+#include <Swift/QtUI/EventViewer/QtEventWindow.h>
+#include <Swift/QtUI/ChatList/QtChatListWindow.h>
+#include <Swift/QtUI/QtLoginWindow.h>
class QComboBox;
@@ -33,9 +35,10 @@ namespace Swift {
class SettingsProvider;
class QtUIPreferences;
+ class StatusCache;
class QtMainWindow : public QWidget, public MainWindow {
Q_OBJECT
public:
- QtMainWindow(SettingsProvider*, UIEventStream* eventStream, QtLoginWindow::QtMenus loginMenus);
+ QtMainWindow(SettingsProvider*, UIEventStream* eventStream, QtLoginWindow::QtMenus loginMenus, StatusCache* statusCache, bool emoticonsExist, bool enableAdHocCommandOnJID);
virtual ~QtMainWindow();
std::vector<QMenu*> getMenus() {return menus_;}
@@ -45,18 +48,27 @@ namespace Swift {
void setMyStatusText(const std::string& status);
void setMyStatusType(StatusShow::Type type);
+ void setMyContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
void setConnecting();
+ void setStreamEncryptionStatus(bool tlsInPlaceAndValid);
+ void openCertificateDialog(const std::vector<Certificate::ref>& chain);
+ static void openCertificateDialog(const std::vector<Certificate::ref>& chain, QWidget* parent);
QtEventWindow* getEventWindow();
QtChatListWindow* getChatListWindow();
void setRosterModel(Roster* roster);
void setAvailableAdHocCommands(const std::vector<DiscoItems::Item>& commands);
+ void setBlockingCommandAvailable(bool isAvailable);
private slots:
void handleStatusChanged(StatusShow::Type showType, const QString &statusMessage);
void handleSettingChanged(const std::string& settingPath);
+ void handleCompactRosterToggled(bool);
void handleShowOfflineToggled(bool);
+ void handleShowEmoticonsToggled(bool);
void handleJoinMUCAction();
+ void handleViewLogsAction();
void handleSignOutAction();
void handleEditProfileAction();
void handleAddUserActionTriggered(bool checked);
void handleChatUserActionTriggered(bool checked);
+ void handleOtherAdHocActionTriggered();
void handleAdHocActionTriggered(bool checked);
void handleEventCountUpdated(int count);
@@ -65,4 +77,7 @@ namespace Swift {
void handleTabChanged(int index);
void handleToggleRequestDeliveryReceipts(bool enabled);
+ void handleShowCertificateInfo();
+ void handleEditBlockingList();
+ void handleSomethingSelectedChanged(bool itemSelected);
private:
@@ -75,8 +90,13 @@ namespace Swift {
QAction* editUserAction_;
QAction* chatUserAction_;
+ QAction* otherAdHocAction_;
QAction* showOfflineAction_;
+ QAction* compactRosterAction_;
+ QAction* showEmoticonsAction_;
+ QAction* openBlockingListEditor_;
QAction* toggleRequestDeliveryReceipts_;
QMenu* serverAdHocMenu_;
QtTabWidget* tabs_;
+ QComboBox* tabBarCombo_;
QWidget* contactsTabWidget_;
QWidget* eventsTabWidget_;
@@ -86,4 +106,5 @@ namespace Swift {
std::vector<DiscoItems::Item> serverAdHocCommands_;
QList<QAction*> serverAdHocCommandActions_;
+ QList<QAction*> onlineOnlyActions_;
};
}
diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp
index 08e32f5..c172caa 100644
--- a/Swift/QtUI/QtNameWidget.cpp
+++ b/Swift/QtUI/QtNameWidget.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2012 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -18,5 +18,5 @@
namespace Swift {
-QtNameWidget::QtNameWidget(SettingsProvider* settings, QWidget *parent) : QWidget(parent), settings(settings) {
+QtNameWidget::QtNameWidget(SettingsProvider* settings, QWidget *parent) : QWidget(parent), settings(settings), isOnline_(false) {
QHBoxLayout* mainLayout = new QHBoxLayout(this);
mainLayout->setSpacing(0);
@@ -42,4 +42,8 @@ void QtNameWidget::setJID(const QString& jid) {
}
+void QtNameWidget::setOnline(const bool isOnline) {
+ isOnline_ = isOnline;
+}
+
void QtNameWidget::mousePressEvent(QMouseEvent* event) {
QMenu menu;
@@ -63,4 +67,5 @@ void QtNameWidget::mousePressEvent(QMouseEvent* event) {
QAction* editProfile = new QAction(tr("Edit Profile"), this);
menu.addAction(editProfile);
+ editProfile->setEnabled(isOnline_);
QAction* result = menu.exec(event->globalPos());
diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h
index 0f00c41..460cc9a 100644
--- a/Swift/QtUI/QtNameWidget.h
+++ b/Swift/QtUI/QtNameWidget.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -21,4 +21,5 @@ namespace Swift {
void setNick(const QString& text);
void setJID(const QString& jid);
+ void setOnline(const bool isOnline);
signals:
@@ -32,5 +33,5 @@ namespace Swift {
enum Mode {
ShowNick,
- ShowJID,
+ ShowJID
};
@@ -40,4 +41,5 @@ namespace Swift {
QString jid;
QString nick;
+ bool isOnline_;
};
}
diff --git a/Swift/QtUI/QtPlainChatView.cpp b/Swift/QtUI/QtPlainChatView.cpp
new file mode 100644
index 0000000..23bf0af
--- /dev/null
+++ b/Swift/QtUI/QtPlainChatView.cpp
@@ -0,0 +1,413 @@
+/*
+ * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtPlainChatView.h>
+
+#include <QTextEdit>
+#include <QScrollBar>
+#include <QVBoxLayout>
+#include <QPushButton>
+#include <QLabel>
+#include <QDialog>
+#include <QProgressBar>
+#include <QFileDialog>
+#include <QInputDialog>
+#include <QMenu>
+
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/FileSize.h>
+
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
+
+#include <Swift/QtUI/ChatSnippet.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+
+namespace Swift {
+
+QtPlainChatView::QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream)
+: QtChatView(window), window_(window), eventStream_(eventStream), idGenerator_(0) {
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+ log_ = new LogTextEdit(this);
+ log_->setReadOnly(true);
+ log_->setAccessibleName(tr("Chat Messages"));
+ 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);
+ const std::string idx = senderIsSelf ? "" : senderName;
+ lastMessageLabel_[idx] = label;
+ return idx;
+}
+
+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 <i>%2 ")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+ const std::string idx = senderIsSelf ? "" : senderName;
+ lastMessageLabel_[idx] = label;
+ return idx;
+}
+
+void QtPlainChatView::addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction /*direction*/)
+{
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction /*direction*/)
+{
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::addErrorMessage(const ChatWindow::ChatMessage& message)
+{
+ QString text = "<p><i>";
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/)
+{
+ QString text = "<p>";
+ if (lastMessageLabel_[id]) {
+ text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
+ }
+ QString name = id.empty() ? "you" : P2QSTRING(id);
+ text += QString(tr("At %1 %2 corrected the last message to:")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name) + "<br/>";
+ text += chatMessageToString(message);
+ text += "</p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& /*highlight*/)
+{
+ QString text = "<p>";
+ if (lastMessageLabel_[id]) {
+ text += P2QSTRING(lastMessageLabel_[id]->getLabel()) + "<br/>";
+ }
+ QString name = id.empty() ? "you" : P2QSTRING(id);
+ text += QString(tr("At %1 %2 corrected the last action to: <i>")).arg(ChatSnippet::timeToEscapedString(B2QDATE(time))).arg(name);
+ text += chatMessageToString(message);
+ text += "</i></p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/)
+{
+ QString text = "<p>The last message was corrected to:<br/>";
+ text += chatMessageToString(message);
+ text += "</p>";
+ log_->append(text);
+}
+
+void QtPlainChatView::setAckState(const std::string& /*id*/, ChatWindow::AckState state)
+{
+ if (state == ChatWindow::Failed) {
+ addSystemMessage(ChatWindow::ChatMessage("Message delivery failed due to disconnection from server."), ChatWindow::DefaultDirection);
+ }
+}
+
+std::string QtPlainChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes)
+{
+ const std::string ftId = "ft" + boost::lexical_cast<std::string>(idGenerator_++);
+ const std::string sizeString = formatSize(sizeInBytes);
+
+ FileTransfer* transfer;
+ if (senderIsSelf) {
+ QString description = QInputDialog::getText(this, tr("File transfer description"),
+ tr("Description:"), QLineEdit::Normal, "");
+ /* NOTE: it is not possible to abort if description is not provided, since we must always return a valid transfer id */
+ const std::string message = std::string() + "Confirm file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>";
+ transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, Q2PSTRING(description), message, true);
+ addSystemMessage(ChatWindow::ChatMessage("Preparing to start file transfer..."), ChatWindow::DefaultDirection);
+ } else { /* incoming transfer */
+ const std::string message = std::string() + "Incoming file transfer: <i>" + filename + " (" + sizeString + " bytes)</i>";
+ transfer = new FileTransfer(this, senderIsSelf, ftId, filename, ChatWindow::WaitingForAccept, "", message, true);
+ addSystemMessage("Incoming file transfer from " + senderName + "...", ChatWindow::DefaultDirection);
+ }
+
+ fileTransfers_[ftId] = transfer;
+ layout()->addWidget(transfer->dialog_);
+
+ return ftId;
+}
+
+void QtPlainChatView::setFileTransferProgress(std::string id, const int percentageDone)
+{
+ FileTransferMap::iterator transfer = fileTransfers_.find(id);
+ if (transfer != fileTransfers_.end()) {
+ transfer->second->bar_->setValue(percentageDone);
+ }
+}
+
+void QtPlainChatView::setFileTransferStatus(std::string id, const ChatWindow::FileTransferState state, const std::string& msg)
+{
+ FileTransferMap::iterator transferIter = fileTransfers_.find(id);
+ if (transferIter == fileTransfers_.end()) {
+ return;
+ }
+
+ /* store the layout index so we can restore it to the same location */
+ FileTransfer* oldTransfer = transferIter->second;
+ const int layoutIndex = layout()->indexOf(oldTransfer->dialog_);
+ layout()->removeWidget(oldTransfer->dialog_);
+ const std::string &label = (!msg.empty() ? msg : oldTransfer->message_);
+ FileTransfer* transfer = new FileTransfer(this, oldTransfer->senderIsSelf_, oldTransfer->ftId_, oldTransfer->filename_, state, oldTransfer->description_, label, false);
+ fileTransfers_[oldTransfer->ftId_] = transfer; /* replace the transfer object for this file id */
+ delete oldTransfer;
+
+ /* insert the new dialog at the old position in the layout list */
+ QBoxLayout* parentLayout = dynamic_cast<QBoxLayout*>(layout());
+ assert(parentLayout);
+ parentLayout->insertWidget(layoutIndex, transfer->dialog_);
+
+ /* log the transfer end result as a system message */
+ if (state == ChatWindow::Finished) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer completed successfully."), ChatWindow::DefaultDirection);
+ } else if (state == ChatWindow::Canceled) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer was canceled."), ChatWindow::DefaultDirection);
+ } else if (state == ChatWindow::FTFailed) {
+ addSystemMessage(ChatWindow::ChatMessage("The file transfer failed."), ChatWindow::DefaultDirection);
+ }
+}
+
+void QtPlainChatView::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& /*reason*/, const std::string& password, bool /*direct*/, bool isImpromptu, bool isContinuation)
+{
+ PopupDialog *invite = new PopupDialog(this);
+
+ QLabel* statusLabel = new QLabel;
+ std::string msg = senderName + " has invited you to join " + jid.toString() + "...";
+ statusLabel->setText(P2QSTRING(msg));
+ invite->layout_->addWidget(statusLabel);
+ invite->layout_->addWidget(new QLabel); /* padding */
+
+ AcceptMUCInviteAction* accept = new AcceptMUCInviteAction(invite, "Accept", jid, senderName, password, isImpromptu, isContinuation);
+ connect(accept, SIGNAL(clicked()), SLOT(acceptMUCInvite()));
+ invite->layout_->addWidget(accept);
+
+ AcceptMUCInviteAction* reject = new AcceptMUCInviteAction(invite, "Reject", jid, senderName, password, isImpromptu, isContinuation);
+ connect(reject, SIGNAL(clicked()), SLOT(rejectMUCInvite()));
+ invite->layout_->addWidget(reject);
+ statusLabel->setText(P2QSTRING(msg));
+
+ layout()->addWidget(invite->dialog_);
+
+ addSystemMessage(ChatWindow::ChatMessage(msg), ChatWindow::DefaultDirection);
+}
+
+void QtPlainChatView::scrollToBottom()
+{
+ log_->ensureCursorVisible();
+ log_->verticalScrollBar()->setValue(log_->verticalScrollBar()->maximum());
+}
+
+void QtPlainChatView::fileTransferAccept()
+{
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (!action) {
+ return;
+ }
+
+ FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
+ if (transferIter == fileTransfers_.end()) {
+ return;
+ }
+
+ FileTransfer* transfer = transferIter->second;
+
+ if (transfer->senderIsSelf_) { /* if we are the sender, kick of the transfer */
+ window_->onFileTransferStart(transfer->ftId_, transfer->description_);
+ } else { /* ask the user where to save the file first */
+ QString path = QFileDialog::getSaveFileName(this, tr("Save File"), P2QSTRING(transfer->filename_));
+ if (path.isEmpty()) {
+ fileTransferReject(); /* because the user did not select a desintation path */
+ return;
+ }
+ window_->onFileTransferAccept(transfer->ftId_, Q2PSTRING(path));
+ }
+
+ setFileTransferStatus(transfer->ftId_, ChatWindow::Negotiating, transfer->message_);
+}
+
+void QtPlainChatView::fileTransferReject()
+{
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (action) {
+ window_->onFileTransferCancel(action->id_);
+ fileTransferFinish();
+ }
+}
+
+void QtPlainChatView::fileTransferFinish()
+{
+ FileTransfer::Action* action = dynamic_cast<FileTransfer::Action*>(sender());
+ if (action) {
+ FileTransferMap::iterator transferIter = fileTransfers_.find(action->id_);
+ if (transferIter != fileTransfers_.end()) {
+ delete transferIter->second; /* cause the dialog to close */
+ fileTransfers_.erase(transferIter);
+ }
+ }
+}
+
+void QtPlainChatView::acceptMUCInvite()
+{
+ AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
+ if (action) {
+ eventStream_->send(boost::make_shared<JoinMUCUIEvent>(action->jid_.toString(), action->password_, boost::optional<std::string>(), false, false, action->isImpromptu_, action->isContinuation_));
+ delete action->parent_;
+ }
+}
+
+void QtPlainChatView::rejectMUCInvite()
+{
+ AcceptMUCInviteAction *action = dynamic_cast<AcceptMUCInviteAction*>(sender());
+ if (action) {
+ /* NOTE: no action required to reject an invite? */
+ delete action->parent_;
+ }
+}
+
+QtPlainChatView::FileTransfer::FileTransfer(QtPlainChatView* parent, bool senderIsSelf, const std::string& ftId, const std::string& filename, const ChatWindow::FileTransferState state, const std::string &desc, const std::string& msg, bool initializing)
+: PopupDialog(parent), bar_(0), senderIsSelf_(senderIsSelf), ftId_(ftId), filename_(filename), description_(desc), message_(msg), initializing_(initializing)
+{
+ QHBoxLayout* layout = new QHBoxLayout;
+ QLabel* statusLabel = new QLabel;
+ layout_->addWidget(statusLabel);
+ layout_->addWidget(new QLabel); /* padding */
+
+ if (initializing_) {
+ FileTransfer::Action* accept = new FileTransfer::Action(senderIsSelf?"Confirm":"Accept", ftId);
+ parent->connect(accept, SIGNAL(clicked()), SLOT(fileTransferAccept()));
+ layout_->addWidget(accept);
+ FileTransfer::Action* reject = new FileTransfer::Action(senderIsSelf?"Cancel":"Reject", ftId);
+ parent->connect(reject, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(reject);
+ statusLabel->setText(P2QSTRING(msg));
+ return;
+ }
+
+ std::string status = msg;
+
+ switch (state) {
+ case ChatWindow::WaitingForAccept: {
+ status = "Waiting for user to accept <i>" + filename + "</i>...";
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Negotiating: {
+ status = "Preparing to transfer <i>" + filename + "</i>...";
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Transferring: {
+ status = "Transferring <i>" + filename + "</i>...";
+ bar_ = new QProgressBar;
+ bar_->setRange(0, 100);
+ bar_->setValue(0);
+ layout->addWidget(bar_);
+ FileTransfer::Action* cancel = new FileTransfer::Action("Cancel", ftId);
+ parent->connect(cancel, SIGNAL(clicked()), SLOT(fileTransferReject()));
+ layout_->addWidget(cancel);
+ break;
+ }
+ case ChatWindow::Canceled: {
+ status = "File <i>" + filename + "</i> was canceled.";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ case ChatWindow::Finished: {
+ status = "File <i>" + filename + "</i> was transfered successfully.";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ case ChatWindow::FTFailed: {
+ status = "File transfer failed: <i>" + filename + "</i>";
+ FileTransfer::Action* finish = new FileTransfer::Action("Hide", ftId);
+ parent->connect(finish, SIGNAL(clicked()), SLOT(fileTransferFinish()));
+ layout_->addWidget(finish);
+ break;
+ }
+ }
+
+ statusLabel->setText(P2QSTRING(status));
+}
+
+void QtPlainChatView::LogTextEdit::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu *menu = createStandardContextMenu();
+ menu->exec(event->globalPos());
+ delete menu;
+}
+
+}
diff --git a/Swift/QtUI/QtPlainChatView.h b/Swift/QtUI/QtPlainChatView.h
new file mode 100644
index 0000000..06613f9
--- /dev/null
+++ b/Swift/QtUI/QtPlainChatView.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2013-2014 Kevin Smith and Remko Tronçon
+ * 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 <QTextEdit>
+
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+
+#include <Swift/QtUI/QtChatView.h>
+#include <Swift/QtUI/QtChatWindow.h>
+
+class QTextEdit;
+class QProgressBar;
+
+namespace Swift {
+ class HighlightAction;
+ class SecurityLabel;
+
+ class QtPlainChatView : public QtChatView {
+ Q_OBJECT
+ public:
+ QtPlainChatView(QtChatWindow *window, UIEventStream* eventStream);
+ 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*/, const ChatWindow::TimestampBehaviour /*timestampBehaviour*/);
+ 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*/);
+ 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*/) {};
+ virtual void fileTransferAccept();
+ virtual void fileTransferReject();
+ virtual void fileTransferFinish();
+ virtual void acceptMUCInvite();
+ virtual void rejectMUCInvite();
+
+ private:
+ struct PopupDialog {
+ PopupDialog(QtPlainChatView* parent) {
+ dialog_ = new QFrame(parent);
+ dialog_->setFrameShape(QFrame::Panel);
+ dialog_->setFrameShadow(QFrame::Raised);
+ layout_ = new QHBoxLayout;
+ dialog_->setLayout(layout_);
+ }
+ virtual ~PopupDialog() {
+ delete dialog_;
+ }
+ QFrame* dialog_;
+ QHBoxLayout* layout_;
+ };
+
+ struct AcceptMUCInviteAction : public QPushButton {
+ AcceptMUCInviteAction(PopupDialog* parent, const std::string& text, const JID& jid, const std::string& senderName, const std::string& password, bool isImpromptu, bool isContinuation)
+ : QPushButton(P2QSTRING(text)), parent_(parent), jid_(jid), senderName_(senderName), password_(password), isImpromptu_(isImpromptu), isContinuation_(isContinuation) {}
+ PopupDialog *parent_;
+ JID jid_;
+ std::string senderName_;
+ std::string password_;
+ bool isImpromptu_;
+ bool isContinuation_;
+ };
+
+ struct FileTransfer : public PopupDialog {
+ struct Action : QPushButton {
+ Action(const std::string& text, const std::string& id)
+ : QPushButton(P2QSTRING(text)), id_(id) {}
+ std::string id_;
+ };
+ FileTransfer(QtPlainChatView* parent, bool senderIsSelf, const std::string& ftId, const std::string& filename, const ChatWindow::FileTransferState state, const std::string& desc, const std::string& msg, bool initializing);
+ QProgressBar* bar_;
+ bool senderIsSelf_;
+ std::string ftId_;
+ std::string filename_;
+ std::string description_;
+ std::string message_;
+ bool initializing_;
+ };
+
+ class LogTextEdit : public QTextEdit {
+ public:
+ LogTextEdit(QWidget* parent) : QTextEdit(parent) {}
+ virtual ~LogTextEdit() {}
+ virtual void contextMenuEvent(QContextMenuEvent *event);
+ };
+
+ typedef std::map<std::string, FileTransfer*> FileTransferMap;
+ QtChatWindow* window_;
+ UIEventStream* eventStream_;
+ LogTextEdit* log_;
+ FileTransferMap fileTransfers_;
+ std::map<std::string, boost::shared_ptr<SecurityLabel> > lastMessageLabel_;
+ int idGenerator_;
+
+ };
+}
diff --git a/Swift/QtUI/QtProfileWindow.cpp b/Swift/QtUI/QtProfileWindow.cpp
index 0faa78f..9526d63 100644
--- a/Swift/QtUI/QtProfileWindow.cpp
+++ b/Swift/QtUI/QtProfileWindow.cpp
@@ -1,109 +1,110 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
#include "QtProfileWindow.h"
+#include "ui_QtProfileWindow.h"
-#include <QImage>
-#include <QPixmap>
-#include <QSizePolicy>
-#include <QGridLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QPushButton>
+#include <QCloseEvent>
#include <QMovie>
+#include <QShortcut>
+#include <QTextDocument>
-#include "QtSwiftUtil.h"
-#include "QtAvatarWidget.h"
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
namespace Swift {
-QtProfileWindow::QtProfileWindow() {
- setWindowTitle(tr("Edit Profile"));
-
- QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
- sizePolicy.setHorizontalStretch(0);
- sizePolicy.setVerticalStretch(0);
- sizePolicy.setHeightForWidth(this->sizePolicy().hasHeightForWidth());
- setSizePolicy(sizePolicy);
-
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->setContentsMargins(10, 10, 10, 10);
-
- QHBoxLayout* topLayout = new QHBoxLayout();
-
- avatar = new QtAvatarWidget(this);
- topLayout->addWidget(avatar);
-
- QVBoxLayout* fieldsLayout = new QVBoxLayout();
-
- QHBoxLayout* horizontalLayout_2 = new QHBoxLayout();
- nicknameLabel = new QLabel(tr("Nickname:"), this);
- horizontalLayout_2->addWidget(nicknameLabel);
- nickname = new QLineEdit(this);
- horizontalLayout_2->addWidget(nickname);
-
- fieldsLayout->addLayout(horizontalLayout_2);
+QtProfileWindow::QtProfileWindow() :
+ QWidget(),
+ ui(new Ui::QtProfileWindow) {
+ ui->setupUi(this);
- errorLabel = new QLabel(this);
- errorLabel->setAlignment(Qt::AlignHCenter);
- fieldsLayout->addWidget(errorLabel);
+ ui->statusLabel->setText(tr("Retrieving profile information for this user."));
+ ui->statusLabel->setVisible(false);
- fieldsLayout->addItem(new QSpacerItem(198, 17, QSizePolicy::Minimum, QSizePolicy::Expanding));
- topLayout->addLayout(fieldsLayout);
+ ui->emptyLabel->setText(tr("No profile information is available for this user."));
+ ui->emptyLabel->setVisible(false);
- layout->addLayout(topLayout);
-
- QHBoxLayout* horizontalLayout = new QHBoxLayout();
- horizontalLayout->setContentsMargins(0, 0, 0, 0);
- horizontalLayout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
-
- throbberLabel = new QLabel(this);
- throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- horizontalLayout->addWidget(throbberLabel);
+ new QShortcut(QKeySequence::Close, this, SLOT(close()));
+ ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave()));
+ setEditable(false);
+ setAttribute(Qt::WA_DeleteOnClose);
+}
- saveButton = new QPushButton(tr("Save"), this);
- saveButton->setDefault( true );
- connect(saveButton, SIGNAL(clicked()), SLOT(handleSave()));
- horizontalLayout->addWidget(saveButton);
+QtProfileWindow::~QtProfileWindow() {
+ delete ui;
+}
- fieldsLayout->addLayout(horizontalLayout);
+void QtProfileWindow::setJID(const JID& jid) {
+ this->jid = jid;
+ updateTitle();
+}
- resize(360, 120);
+void QtProfileWindow::setVCard(VCard::ref vcard) {
+ ui->vcard->setVCard(vcard);
+ if (vcard->isEmpty()) {
+ ui->vcard->setVisible(false);
+ ui->emptyLabel->setVisible(true);
+ } else {
+ ui->vcard->setVisible(true);
+ ui->emptyLabel->setVisible(false);
}
-void QtProfileWindow::setVCard(Swift::VCard::ref vcard) {
- this->vcard = vcard;
- nickname->setText(P2QSTRING(vcard->getNickname()));
- avatar->setAvatar(vcard->getPhoto(), vcard->getPhotoType());
+ updateWindowSize();
}
void QtProfileWindow::setEnabled(bool b) {
- nickname->setEnabled(b);
- nicknameLabel->setEnabled(b);
- avatar->setEnabled(b);
- saveButton->setEnabled(b);
+ ui->vcard->setEnabled(b);
+ ui->savePushButton->setEnabled(b);
+}
+
+void QtProfileWindow::setEditable(bool b) {
+ ui->throbberLabel->setVisible(b);
+ ui->errorLabel->setVisible(b);
+ ui->savePushButton->setVisible(b);
+ ui->vcard->setEditable(b);
+ updateTitle();
}
void QtProfileWindow::setProcessing(bool processing) {
if (processing) {
- throbberLabel->movie()->start();
- throbberLabel->show();
+ ui->throbberLabel->movie()->start();
+ ui->throbberLabel->show();
+ ui->statusLabel->setVisible(true);
+ ui->vcard->setVisible(false);
}
else {
- throbberLabel->hide();
- throbberLabel->movie()->stop();
+ ui->throbberLabel->hide();
+ ui->throbberLabel->movie()->stop();
+ ui->statusLabel->setVisible(false);
+ ui->vcard->setVisible(true);
}
+
+ updateWindowSize();
}
-void QtProfileWindow::show() {
- QWidget::show();
- QWidget::activateWindow();
+void QtProfileWindow::setError(const std::string& error) {
+ if (!error.empty()) {
+ ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
+ }
+ else {
+ ui->errorLabel->setText("");
+ }
}
-void QtProfileWindow::hideEvent(QHideEvent* event) {
- QWidget::hideEvent(event);
+void QtProfileWindow::show() {
+ QWidget::showNormal();
+ QWidget::activateWindow();
+ QWidget::raise();
}
@@ -112,22 +113,44 @@ void QtProfileWindow::hide() {
}
-void QtProfileWindow::handleSave() {
- assert(vcard);
- vcard->setNickname(Q2PSTRING(nickname->text()));
- vcard->setPhoto(avatar->getAvatarData());
- vcard->setPhotoType(avatar->getAvatarType());
- onVCardChangeRequest(vcard);
+void QtProfileWindow::updateTitle() {
+ QString jidString;
+ if (jid.isValid()) {
+ jidString = QString(" ( %1 )").arg(P2QSTRING(jid.toString()));
}
-void QtProfileWindow::setError(const std::string& error) {
- if (!error.empty()) {
- errorLabel->setText("<font color='red'>" + P2QSTRING(error) + "</font>");
+ if (ui->vcard->isEditable()) {
+ setWindowTitle(tr("Edit Profile") + jidString);
+ } else {
+ setWindowTitle(tr("Show Profile") + jidString);
}
- else {
- errorLabel->setText("");
}
+
+void QtProfileWindow::updateWindowSize() {
+ int width = 0;
+ int height = 0;
+
+ QSize size = ui->statusLabel->size();
+ width = std::max(width, size.width());
+ height = std::max(height, size.height() * 3);
+
+ size = ui->emptyLabel->size();
+ width = std::max(width, size.width());
+ height = std::max(height, size.height() * 3);
+
+ size = ui->vcard->size();
+ width = std::max(width, size.width());
+ height = std::max(height, size.height());
+
+ resize(width, height);
}
+void QtProfileWindow::closeEvent(QCloseEvent* event) {
+ event->accept();
+ onWindowAboutToBeClosed(jid);
+}
+void QtProfileWindow::handleSave() {
+ onVCardChangeRequest(ui->vcard->getVCard());
+}
}
diff --git a/Swift/QtUI/QtProfileWindow.h b/Swift/QtUI/QtProfileWindow.h
index edb9cce..57cc2df 100644
--- a/Swift/QtUI/QtProfileWindow.h
+++ b/Swift/QtUI/QtProfileWindow.h
@@ -5,31 +5,46 @@
*/
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
#pragma once
-#include <QWidget>
+#include <Swiften/JID/JID.h>
#include <Swift/Controllers/UIInterfaces/ProfileWindow.h>
-class QLabel;
-class QLineEdit;
-class QHBoxLayout;
-class QPushButton;
+#include <QWidget>
+
+namespace Ui {
+ class QtProfileWindow;
+}
namespace Swift {
- class QtAvatarWidget;
class QtProfileWindow : public QWidget, public ProfileWindow {
Q_OBJECT
+
public:
QtProfileWindow();
+ virtual ~QtProfileWindow();
+
+ virtual void setJID(const JID& jid);
+ virtual void setVCard(VCard::ref vcard);
- void setVCard(Swift::VCard::ref);
- void setEnabled(bool);
- void setProcessing(bool);
- virtual void setError(const std::string&);
- void show();
- void hide();
+ virtual void setEnabled(bool b);
+ virtual void setProcessing(bool processing);
+ virtual void setError(const std::string& error);
+ virtual void setEditable(bool b);
- void hideEvent (QHideEvent* event);
+ virtual void show();
+ virtual void hide();
+
+ private:
+ void updateTitle();
+ void updateWindowSize();
+ virtual void closeEvent(QCloseEvent* event);
private slots:
@@ -37,12 +52,7 @@ namespace Swift {
private:
- VCard::ref vcard;
- QtAvatarWidget* avatar;
- QLabel* nicknameLabel;
- QLineEdit* nickname;
- QLabel* throbberLabel;
- QLabel* errorLabel;
- QHBoxLayout* horizontalLayout;
- QPushButton* saveButton;
+ Ui::QtProfileWindow* ui;
+ JID jid;
};
+
}
diff --git a/Swift/QtUI/QtProfileWindow.ui b/Swift/QtUI/QtProfileWindow.ui
new file mode 100644
index 0000000..ed2986d
--- /dev/null
+++ b/Swift/QtUI/QtProfileWindow.ui
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtProfileWindow</class>
+ <widget class="QWidget" name="QtProfileWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>334</width>
+ <height>197</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Edit Profile</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="Swift::QtVCardWidget" name="vcard" native="true"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="statusLabel">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="emptyLabel">
+ <property name="text">
+ <string>TextLabel</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="throbberLabel">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::NoTextInteraction</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="errorLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="savePushButton">
+ <property name="text">
+ <string>Save</string>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>Swift::QtVCardWidget</class>
+ <extends>QWidget</extends>
+ <header>Swift/QtUI/QtVCardWidget/QtVCardWidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtResourceHelper.cpp b/Swift/QtUI/QtResourceHelper.cpp
new file mode 100644
index 0000000..f76c438
--- /dev/null
+++ b/Swift/QtUI/QtResourceHelper.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swift/QtUI/QtResourceHelper.h>
+
+namespace Swift {
+
+QString statusShowTypeToIconPath(StatusShow::Type type) {
+ QString iconString;
+ switch (type) {
+ case StatusShow::Online: iconString = "online";break;
+ case StatusShow::Away: iconString = "away";break;
+ case StatusShow::XA: iconString = "away";break;
+ case StatusShow::FFC: iconString = "online";break;
+ case StatusShow::DND: iconString = "dnd";break;
+ case StatusShow::None: iconString = "offline";break;
+ }
+ return QString(":/icons/%1.png").arg(iconString);
+}
+
+}
+
diff --git a/Swift/QtUI/QtResourceHelper.h b/Swift/QtUI/QtResourceHelper.h
new file mode 100644
index 0000000..034a941
--- /dev/null
+++ b/Swift/QtUI/QtResourceHelper.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QString>
+
+#include <Swiften/Elements/StatusShow.h>
+
+namespace Swift {
+
+QString statusShowTypeToIconPath(StatusShow::Type type);
+
+}
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 98e75c2..d5029ad 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,13 +7,15 @@
#include "QtRosterHeader.h"
-#include <QHBoxLayout>
-#include <QVBoxLayout>
+#include <QBitmap>
+#include <qdebug.h>
#include <QFileInfo>
+#include <QHBoxLayout>
+#include <QHelpEvent>
#include <QIcon>
-#include <QSizePolicy>
-#include <qdebug.h>
#include <QMouseEvent>
#include <QPainter>
-#include <QBitmap>
+#include <QSizePolicy>
+#include <QToolTip>
+#include <QVBoxLayout>
#include "QtStatusWidget.h"
@@ -21,8 +23,9 @@
#include <Swift/QtUI/QtClickableLabel.h>
#include <Swift/QtUI/QtNameWidget.h>
+#include <Swift/QtUI/Roster/RosterTooltip.h>
#include "QtScaledAvatarCache.h"
namespace Swift {
-QtRosterHeader::QtRosterHeader(SettingsProvider* settings, QWidget* parent) : QWidget(parent) {
+QtRosterHeader::QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent) : QWidget(parent), statusEdit_(NULL) {
QHBoxLayout* topLayout = new QHBoxLayout();
topLayout->setSpacing(3);
@@ -46,12 +49,25 @@ QtRosterHeader::QtRosterHeader(SettingsProvider* settings, QWidget* parent) : QW
topLayout->addLayout(rightLayout);
+ QHBoxLayout* nameAndSecurityLayout = new QHBoxLayout();
+ nameAndSecurityLayout->setContentsMargins(4,0,0,0);
+
nameWidget_ = new QtNameWidget(settings, this);
connect(nameWidget_, SIGNAL(onChangeNickRequest()), this, SIGNAL(onEditProfileRequest()));
- rightLayout->addWidget(nameWidget_);
+ nameAndSecurityLayout->addWidget(nameWidget_);
+
+ securityInfoButton_ = new QToolButton(this);
+ securityInfoButton_->setStyleSheet("QToolButton { border: none; } QToolButton:hover { border: 1px solid #bebebe; } QToolButton:pressed { border: 1px solid #757575; background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #777777, stop: 1 #d4d4d4);}");
+ //securityInfoButton_->setAutoRaise(true);
+ securityInfoButton_->setIcon(QIcon(":/icons/lock.png"));
+ securityInfoButton_->setToolTip(tr("Connection is secured"));
+ connect(securityInfoButton_, SIGNAL(clicked()), this, SIGNAL(onShowCertificateInfo()));
+ nameAndSecurityLayout->addWidget(securityInfoButton_);
+ rightLayout->addLayout(nameAndSecurityLayout);
- statusWidget_ = new QtStatusWidget(this);
+ statusWidget_ = new QtStatusWidget(statusCache, this);
connect(statusWidget_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleChangeStatusRequest(StatusShow::Type, const QString&)));
rightLayout->addWidget(statusWidget_);
+
show();
}
@@ -67,4 +83,12 @@ void QtRosterHeader::setStatusText(const QString& statusMessage) {
void QtRosterHeader::setStatusType(StatusShow::Type type) {
statusWidget_->setStatusType(type);
+ if (type == StatusShow::None) {
+ nameWidget_->setOnline(false);
+ disconnect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()));
+ }
+ else {
+ nameWidget_->setOnline(true);
+ connect(avatarLabel_, SIGNAL(clicked()), this, SIGNAL(onEditProfileRequest()), Qt::UniqueConnection);
+ }
}
@@ -73,4 +97,19 @@ void QtRosterHeader::setConnecting() {
}
+void QtRosterHeader::setStreamEncryptionStatus(bool tlsInPlace) {
+ securityInfoButton_->setVisible(tlsInPlace);
+}
+
+bool QtRosterHeader::event(QEvent* event) {
+ if (event->type() == QEvent::ToolTip) {
+ QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
+ QtScaledAvatarCache scaledAvatarCache(avatarSize_);
+ QString text = RosterTooltip::buildDetailedTooltip(contact_.get(), &scaledAvatarCache);
+ QToolTip::showText(helpEvent->globalPos(), text);
+ return true;
+ }
+ return QWidget::event(event);
+}
+
void QtRosterHeader::setAvatar(const QString& path) {
QString scaledAvatarPath = QtScaledAvatarCache(avatarSize_).getScaledAvatarPath(path);
@@ -89,4 +128,8 @@ void QtRosterHeader::setNick(const QString& nick) {
}
+void QtRosterHeader::setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact) {
+ contact_ = contact;
+}
+
void QtRosterHeader::setJID(const QString& jid) {
nameWidget_->setJID(jid);
diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h
index 050460c..eafbc02 100644
--- a/Swift/QtUI/QtRosterHeader.h
+++ b/Swift/QtUI/QtRosterHeader.h
@@ -11,8 +11,10 @@
#include <QPixmap>
#include <QSize>
-#include <QToolBar>
+#include <QToolButton>
#include <string>
-#include "Swiften/Elements/StatusShow.h"
+#include <Swiften/Elements/StatusShow.h>
+#include <Swiften/Elements/VCard.h>
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
#include "QtTextEdit.h"
@@ -25,20 +27,26 @@ namespace Swift {
class QtNameWidget;
class SettingsProvider;
+ class StatusCache;
class QtRosterHeader : public QWidget {
Q_OBJECT
public:
- QtRosterHeader(SettingsProvider* settings, QWidget* parent = NULL);
+ QtRosterHeader(SettingsProvider* settings, StatusCache* statusCache, QWidget* parent = NULL);
void setAvatar(const QString& path);
void setJID(const QString& jid);
void setNick(const QString& nick);
+ void setContactRosterItem(boost::shared_ptr<ContactRosterItem> contact);
void setStatusText(const QString& statusMessage);
void setStatusType(StatusShow::Type type);
void setConnecting();
+ void setStreamEncryptionStatus(bool tlsInPlace);
+ private:
+ bool event(QEvent* event);
signals:
void onChangeStatusRequest(StatusShow::Type showType, const QString &statusMessage);
void onEditProfileRequest();
+ void onShowCertificateInfo();
private slots:
@@ -49,7 +57,8 @@ namespace Swift {
QtNameWidget* nameWidget_;
QtTextEdit* statusEdit_;
- QToolBar* toolBar_;
QtStatusWidget* statusWidget_;
+ QToolButton* securityInfoButton_;
static const int avatarSize_;
+ boost::shared_ptr<ContactRosterItem> contact_;
};
}
diff --git a/Swift/QtUI/QtScaledAvatarCache.cpp b/Swift/QtUI/QtScaledAvatarCache.cpp
index 6abff87..46ec2fc 100644
--- a/Swift/QtUI/QtScaledAvatarCache.cpp
+++ b/Swift/QtUI/QtScaledAvatarCache.cpp
@@ -15,4 +15,7 @@
#include <QByteArray>
+#include <Swiften/Base/Log.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
namespace Swift {
@@ -32,5 +35,5 @@ QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) {
if (!QFileInfo(targetFile).exists()) {
QPixmap avatarPixmap;
- avatarPixmap.load(path);
+ if (avatarPixmap.load(path)) {
QPixmap maskedAvatar(avatarPixmap.size());
maskedAvatar.fill(QColor(0, 0, 0, 0));
@@ -45,4 +48,7 @@ QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) {
return path;
}
+ } else {
+ SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl;
+ }
}
return targetFile;
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index 64e88d4..a98cdf3 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -109,5 +109,5 @@ QSettings* QtSettingsProvider::getQSettings() {
void QtSettingsProvider::updatePermissions() {
-#if !defined(Q_WS_WIN) && !defined(Q_WS_MAC)
+#if !defined(Q_OS_WIN) && !defined(Q_OS_MAC)
QFile file(settings_.fileName());
if (file.exists()) {
diff --git a/Swift/QtUI/QtSingleWindow.cpp b/Swift/QtUI/QtSingleWindow.cpp
new file mode 100644
index 0000000..c970296
--- /dev/null
+++ b/Swift/QtUI/QtSingleWindow.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2010-2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtSingleWindow.h>
+
+
+#include <Swiften/Base/foreach.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+#include <Swift/QtUI/QtChatTabs.h>
+
+namespace Swift {
+
+static const QString SINGLE_WINDOW_GEOMETRY = QString("SINGLE_WINDOW_GEOMETRY");
+static const QString SINGLE_WINDOW_SPLITS = QString("SINGLE_WINDOW_SPLITS");
+
+QtSingleWindow::QtSingleWindow(QtSettingsProvider* settings) : QSplitter() {
+ settings_ = settings;
+ QVariant geometryVariant = settings_->getQSettings()->value(SINGLE_WINDOW_GEOMETRY);
+ if (geometryVariant.isValid()) {
+ restoreGeometry(geometryVariant.toByteArray());
+ }
+ connect(this, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int)));
+ restoreSplitters();
+}
+
+QtSingleWindow::~QtSingleWindow() {
+
+}
+
+void QtSingleWindow::addWidget(QWidget* widget) {
+ QtChatTabs* tabs = dynamic_cast<QtChatTabs*>(widget);
+ if (tabs) {
+ connect(tabs, SIGNAL(onTitleChanged(const QString&)), this, SLOT(handleTabsTitleChanged(const QString&)));
+ }
+ QSplitter::addWidget(widget);
+}
+
+void QtSingleWindow::handleTabsTitleChanged(const QString& title) {
+ setWindowTitle(title);
+}
+
+void QtSingleWindow::handleSplitterMoved(int, int) {
+ QList<QVariant> variantValues;
+ QList<int> intValues = sizes();
+ foreach (int value, intValues) {
+ variantValues.append(QVariant(value));
+ }
+ settings_->getQSettings()->setValue(SINGLE_WINDOW_SPLITS, QVariant(variantValues));
+}
+
+void QtSingleWindow::restoreSplitters() {
+ QList<QVariant> variantValues = settings_->getQSettings()->value(SINGLE_WINDOW_SPLITS).toList();
+ QList<int> intValues;
+ foreach (QVariant value, variantValues) {
+ intValues.append(value.toInt());
+ }
+ setSizes(intValues);
+}
+
+void QtSingleWindow::insertAtFront(QWidget* widget) {
+ insertWidget(0, widget);
+ restoreSplitters();
+}
+
+void QtSingleWindow::handleGeometryChanged() {
+ settings_->getQSettings()->setValue(SINGLE_WINDOW_GEOMETRY, saveGeometry());
+
+}
+
+void QtSingleWindow::resizeEvent(QResizeEvent*) {
+ handleGeometryChanged();
+}
+
+void QtSingleWindow::moveEvent(QMoveEvent*) {
+ handleGeometryChanged();
+}
+
+}
diff --git a/Swift/QtUI/QtSingleWindow.h b/Swift/QtUI/QtSingleWindow.h
new file mode 100644
index 0000000..b55b3c9
--- /dev/null
+++ b/Swift/QtUI/QtSingleWindow.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010-2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QSplitter>
+
+namespace Swift {
+ class QtSettingsProvider;
+
+ class QtSingleWindow : public QSplitter {
+ Q_OBJECT
+ public:
+ QtSingleWindow(QtSettingsProvider* settings);
+ virtual ~QtSingleWindow();
+ void insertAtFront(QWidget* widget);
+ void addWidget(QWidget* widget);
+ protected:
+ void resizeEvent(QResizeEvent*);
+ void moveEvent(QMoveEvent*);
+ private slots:
+ void handleSplitterMoved(int, int);
+ void handleTabsTitleChanged(const QString& title);
+ private:
+ void handleGeometryChanged();
+ void restoreSplitters();
+
+ private:
+
+ QtSettingsProvider* settings_;
+ };
+
+}
+
diff --git a/Swift/QtUI/QtSoundPlayer.cpp b/Swift/QtUI/QtSoundPlayer.cpp
index 387c6f3..3f3782d 100644
--- a/Swift/QtUI/QtSoundPlayer.cpp
+++ b/Swift/QtUI/QtSoundPlayer.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -10,5 +10,7 @@
#include <iostream>
-#include "SwifTools/Application/ApplicationPathProvider.h"
+#include <SwifTools/Application/ApplicationPathProvider.h>
+#include <QtSwiftUtil.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
@@ -17,8 +19,9 @@ QtSoundPlayer::QtSoundPlayer(ApplicationPathProvider* applicationPathProvider) :
}
-void QtSoundPlayer::playSound(SoundEffect sound) {
+void QtSoundPlayer::playSound(SoundEffect sound, const std::string& soundResource) {
+
switch (sound) {
case MessageReceived:
- playSound("/sounds/message-received.wav");
+ playSound(soundResource.empty() ? "/sounds/message-received.wav" : soundResource);
break;
}
@@ -28,5 +31,8 @@ void QtSoundPlayer::playSound(const std::string& soundResource) {
boost::filesystem::path resourcePath = applicationPathProvider->getResourcePath(soundResource);
if (boost::filesystem::exists(resourcePath)) {
- QSound::play(resourcePath.string().c_str());
+ QSound::play(P2QSTRING(pathToString(resourcePath)));
+ }
+ else if (boost::filesystem::exists(soundResource)) {
+ QSound::play(P2QSTRING(soundResource));
}
else {
diff --git a/Swift/QtUI/QtSoundPlayer.h b/Swift/QtUI/QtSoundPlayer.h
index 6945f45..f8da392 100644
--- a/Swift/QtUI/QtSoundPlayer.h
+++ b/Swift/QtUI/QtSoundPlayer.h
@@ -20,5 +20,5 @@ namespace Swift {
QtSoundPlayer(ApplicationPathProvider* applicationPathProvider);
- void playSound(SoundEffect sound);
+ void playSound(SoundEffect sound, const std::string& soundResource);
private:
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp
new file mode 100644
index 0000000..db2b1e7
--- /dev/null
+++ b/Swift/QtUI/QtSpellCheckerWindow.cpp
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2011 Vlad Voicu
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "Swift/QtUI/QtSpellCheckerWindow.h"
+
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/Controllers/SettingConstants.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+#include <QCoreApplication>
+#include <QFileDialog>
+#include <QDir>
+#include <QStringList>
+#include <QTimer>
+
+namespace Swift {
+
+QtSpellCheckerWindow::QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent) : QDialog(parent) {
+ settings_ = settings;
+ ui_.setupUi(this);
+#ifdef HAVE_HUNSPELL
+ ui_.hunspellOptions->show();
+#else
+ ui_.hunspellOptions->hide();
+ QTimer::singleShot(0, this, SLOT(shrinkWindow()));
+#endif
+ connect(ui_.spellChecker, SIGNAL(toggled(bool)), this, SLOT(handleChecker(bool)));
+ connect(ui_.cancel, SIGNAL(clicked()), this, SLOT(handleCancel()));
+ connect(ui_.apply, SIGNAL(clicked()), this, SLOT(handleApply()));
+ connect(ui_.pathButton, SIGNAL(clicked()), this, SLOT(handlePathButton()));
+ setFromSettings();
+}
+
+void QtSpellCheckerWindow::shrinkWindow() {
+ resize(0,0);
+}
+
+void QtSpellCheckerWindow::setFromSettings() {
+ ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER));
+ ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
+ ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE)));
+ std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ QString filename = "*.dic";
+ QDir dictDirectory = QDir(P2QSTRING(currentPath));
+ QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
+ showFiles(files);
+ setEnabled(settings_->getSetting(SettingConstants::SPELL_CHECKER));
+}
+
+void QtSpellCheckerWindow::handleChecker(bool state) {
+ setEnabled(state);
+}
+
+void QtSpellCheckerWindow::setEnabled(bool state) {
+ ui_.pathContent->setEnabled(state);
+ ui_.languageView->setEnabled(state);
+ ui_.pathButton->setEnabled(state);
+ ui_.pathLabel->setEnabled(state);
+ ui_.currentLanguage->setEnabled(state);
+ ui_.currentLanguageValue->setEnabled(state);
+ ui_.language->setEnabled(state);
+}
+
+void QtSpellCheckerWindow::handleApply() {
+ settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
+ QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
+ if (!selectedLanguage.empty()) {
+ settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text()));
+ }
+ this->done(0);
+}
+
+void QtSpellCheckerWindow::handleCancel() {
+ this->done(0);
+}
+
+void QtSpellCheckerWindow::handlePathButton() {
+ std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath));
+ if (dirpath != P2QSTRING(currentPath)) {
+ ui_.languageView->clear();
+ settings_->storeSetting(SettingConstants::DICT_FILE, "");
+ ui_.currentLanguageValue->setText(" ");
+ }
+ if (!dirpath.isEmpty()) {
+ if (!dirpath.endsWith("/")) {
+ dirpath.append("/");
+ }
+ settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath));
+ QDir dictDirectory = QDir(dirpath);
+ ui_.pathContent->setText(dirpath);
+ QString filename = "*.dic";
+ QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
+ showFiles(files);
+ }
+}
+
+void QtSpellCheckerWindow::handlePersonalPathButton() {
+ std::string currentPath = settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH);
+ QString filename = QFileDialog::getOpenFileName(this, tr("Select Personal Dictionary"), P2QSTRING(currentPath), tr("(*.dic"));
+ settings_->storeSetting(SettingConstants::PERSONAL_DICT_PATH, Q2PSTRING(filename));
+}
+
+void QtSpellCheckerWindow::showFiles(const QStringList& files) {
+ ui_.languageView->clear();
+ for (int i = 0; i < files.size(); ++i) {
+ ui_.languageView->insertItem(i, files[i]);
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtSpellCheckerWindow.h b/Swift/QtUI/QtSpellCheckerWindow.h
new file mode 100644
index 0000000..7b63318
--- /dev/null
+++ b/Swift/QtUI/QtSpellCheckerWindow.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2011 Vlad Voicu
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include "ui_QtSpellCheckerWindow.h"
+
+#include <QDialog>
+
+namespace Swift {
+ class SettingsProvider;
+ class QtSpellCheckerWindow : public QDialog, protected Ui::QtSpellCheckerWindow {
+ Q_OBJECT
+ public:
+ QtSpellCheckerWindow(SettingsProvider* settings, QWidget* parent = NULL);
+ public slots:
+ void handleChecker(bool state);
+ void handleCancel();
+ void handlePathButton();
+ void handlePersonalPathButton();
+ void handleApply();
+ private slots:
+ void shrinkWindow();
+ private:
+ void setEnabled(bool state);
+ void setFromSettings();
+ void showFiles(const QStringList& files);
+ SettingsProvider* settings_;
+ Ui::QtSpellCheckerWindow ui_;
+ };
+}
diff --git a/Swift/QtUI/QtSpellCheckerWindow.ui b/Swift/QtUI/QtSpellCheckerWindow.ui
new file mode 100644
index 0000000..b7f5161
--- /dev/null
+++ b/Swift/QtUI/QtSpellCheckerWindow.ui
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtSpellCheckerWindow</class>
+ <widget class="QDialog" name="QtSpellCheckerWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>399</width>
+ <height>265</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QCheckBox" name="spellChecker">
+ <property name="text">
+ <string>Spell Checker Enabled</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="hunspellOptions" native="true">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="pathLabel">
+ <property name="text">
+ <string>Dictionary Path:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="pathContent"/>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pathButton">
+ <property name="text">
+ <string>Change</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="currentLanguage">
+ <property name="text">
+ <string>Current Language:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="currentLanguageValue">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="language">
+ <property name="text">
+ <string>Language:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="languageView"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QPushButton" name="cancel">
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="apply">
+ <property name="text">
+ <string>Apply</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index 0e2731a..8cc366a 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -7,4 +7,8 @@
#include "QtStatusWidget.h"
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+
#include <QBoxLayout>
#include <QComboBox>
@@ -24,8 +28,18 @@
#include "Swift/QtUI/QtSwiftUtil.h"
#include <Swift/Controllers/StatusUtil.h>
+#include <Swift/Controllers/StatusCache.h>
+
+namespace lambda = boost::lambda;
namespace Swift {
-QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) {
+QtStatusWidget::QtStatusWidget(StatusCache* statusCache, QWidget *parent) : QWidget(parent), statusCache_(statusCache), editCursor_(Qt::IBeamCursor), viewCursor_(Qt::PointingHandCursor) {
+ allTypes_.push_back(StatusShow::Online);
+ allTypes_.push_back(StatusShow::FFC);
+ allTypes_.push_back(StatusShow::Away);
+ allTypes_.push_back(StatusShow::XA);
+ allTypes_.push_back(StatusShow::DND);
+ allTypes_.push_back(StatusShow::None);
+
isClicking_ = false;
connecting_ = false;
@@ -135,5 +149,20 @@ void QtStatusWidget::generateList() {
item->setData(Qt::UserRole, QVariant(type));
}
+ std::vector<StatusCache::PreviousStatus> previousStatuses = statusCache_->getMatches(Q2PSTRING(text), 8);
+ foreach (StatusCache::PreviousStatus savedStatus, previousStatuses) {
+ if (savedStatus.first.empty() || std::find_if(allTypes_.begin(), allTypes_.end(),
+ savedStatus.second == lambda::_1 && savedStatus.first == lambda::bind(&statusShowTypeToFriendlyName, lambda::_1)) != allTypes_.end()) {
+ continue;
+ }
+ QListWidgetItem* item = new QListWidgetItem(P2QSTRING(savedStatus.first), menu_);
+ item->setIcon(icons_[savedStatus.second]);
+ item->setToolTip(item->text());
+ item->setStatusTip(item->toolTip());
+ item->setData(Qt::UserRole, QVariant(savedStatus.second));
+ }
foreach (StatusShow::Type type, icons_.keys()) {
+ if (Q2PSTRING(text) == statusShowTypeToFriendlyName(type)) {
+ continue;
+ }
QListWidgetItem* item = new QListWidgetItem(P2QSTRING(statusShowTypeToFriendlyName(type)), menu_);
item->setIcon(icons_[type]);
@@ -142,6 +171,18 @@ void QtStatusWidget::generateList() {
item->setData(Qt::UserRole, QVariant(type));
}
+ resizeMenu();
}
+void QtStatusWidget::resizeMenu() {
+ int height = menu_->sizeHintForRow(0) * menu_->count();
+ int marginLeft;
+ int marginTop;
+ int marginRight;
+ int marginBottom;
+ menu_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
+ height += marginTop + marginBottom;
+
+ menu_->setGeometry(menu_->x(), menu_->y(), menu_->width(), height);
+}
void QtStatusWidget::handleClicked() {
@@ -160,16 +201,9 @@ void QtStatusWidget::handleClicked() {
x = screenWidth - width;
}
- std::vector<StatusShow::Type> types;
- types.push_back(StatusShow::Online);
- types.push_back(StatusShow::FFC);
- types.push_back(StatusShow::Away);
- types.push_back(StatusShow::XA);
- types.push_back(StatusShow::DND);
- types.push_back(StatusShow::None);
- foreach (StatusShow::Type type, types) {
- if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
+ //foreach (StatusShow::Type type, allTypes_) {
+ // if (statusEdit_->text() == P2QSTRING(statusShowTypeToFriendlyName(type))) {
statusEdit_->setText("");
- }
- }
+ // }
+ //}
generateList();
@@ -206,4 +240,5 @@ void QtStatusWidget::handleEditComplete() {
viewMode();
emit onChangeStatusRequest(selectedStatusType_, statusText_);
+ statusCache_->addRecent(Q2PSTRING(statusText_), selectedStatusType_);
}
diff --git a/Swift/QtUI/QtStatusWidget.h b/Swift/QtUI/QtStatusWidget.h
index 75bcf52..87e8d4a 100644
--- a/Swift/QtUI/QtStatusWidget.h
+++ b/Swift/QtUI/QtStatusWidget.h
@@ -23,8 +23,10 @@ namespace Swift {
class QtLineEdit;
class QtElidingLabel;
+ class StatusCache;
+
class QtStatusWidget : public QWidget {
Q_OBJECT
public:
- QtStatusWidget(QWidget *parent);
+ QtStatusWidget(StatusCache* statusCache, QWidget *parent);
~QtStatusWidget();
StatusShow::Type getSelectedStatusShow();
@@ -46,7 +48,9 @@ namespace Swift {
static QString getNoMessage();
private:
+ void resizeMenu();
void viewMode();
void setNewToolTip();
//QComboBox *types_;
+ StatusCache* statusCache_;
QStackedWidget* stack_;
QLabel* statusIcon_;
@@ -65,4 +69,5 @@ namespace Swift {
bool connecting_;
static const QString NO_MESSAGE;
+ std::vector<StatusShow::Type> allTypes_;
};
}
diff --git a/Swift/QtUI/QtSubscriptionRequestWindow.cpp b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
index d22cbd0..460366b 100644
--- a/Swift/QtUI/QtSubscriptionRequestWindow.cpp
+++ b/Swift/QtUI/QtSubscriptionRequestWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -12,12 +12,15 @@
#include <QLabel>
-#include "Swift/QtUI/QtSwiftUtil.h"
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(boost::shared_ptr<SubscriptionRequestEvent> event, QWidget* parent) : QDialog(parent), event_(event) {
- QString text = QString(tr("%1 would like to add you to their contact list.\n Would you like to add them to your contact list and share your status when you're online? \n\nIf you choose to defer this choice, you will be asked again when you next login.")).arg(event->getJID().toString().c_str());
+ QString text = QString(tr("%1 would like to add you to their contact list.")).arg(P2QSTRING(event->getJID().toString()));
QVBoxLayout* layout = new QVBoxLayout();
QLabel* label = new QLabel(text, this);
layout->addWidget(label);
+ label = new QLabel(tr("Would you like to add them to your contact list and share your status when you're online?"));
+ //layout->addWidget(new QLabel);
+ layout->addWidget(label);
if (event_->getConcluded()) {
@@ -28,8 +31,8 @@ QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(boost::shared_ptr<Subsc
layout->addWidget(okButton);
} else {
- QPushButton* yesButton = new QPushButton(tr("Yes"), this);
+ QPushButton* yesButton = new QPushButton(tr("Accept"), this);
yesButton->setDefault(true);
connect(yesButton, SIGNAL(clicked()), this, SLOT(handleYes()));
- QPushButton* noButton = new QPushButton(tr("No"), this);
+ QPushButton* noButton = new QPushButton(tr("Reject"), this);
connect(noButton, SIGNAL(clicked()), this, SLOT(handleNo()));
QPushButton* deferButton = new QPushButton(tr("Defer"), this);
@@ -41,6 +44,9 @@ QtSubscriptionRequestWindow::QtSubscriptionRequestWindow(boost::shared_ptr<Subsc
buttonLayout->addWidget(noButton);
buttonLayout->addWidget(deferButton);
-
+ layout->addWidget(new QLabel);
layout->addLayout(buttonLayout);
+ layout->addWidget(new QLabel);
+ QLabel* footer = new QLabel(tr("(If you choose to defer this choice, you will be asked again when you next login.)"));
+ layout->addWidget(footer);
}
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 9602336..d2224ba 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -1,32 +1,34 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtSwift.h"
+#include <Swift/QtUI/QtSwift.h>
#include <string>
-#include <QSplitter>
-#include <QFile>
+#include <map>
+
#include <boost/bind.hpp>
+
+#include <QFile>
#include <QMessageBox>
#include <QApplication>
+#include <QMap>
+#include <qdebug.h>
-#include <QtLoginWindow.h>
-#include <QtChatTabs.h>
-#include <QtSystemTray.h>
-#include <QtSoundPlayer.h>
-#include <QtSwiftUtil.h>
-#include <QtUIFactory.h>
-#include <QtChatWindowFactory.h>
#include <Swiften/Base/Log.h>
-#include <Swift/Controllers/Storages/CertificateFileStorageFactory.h>
-#include <Swift/Controllers/Storages/FileStoragesFactory.h>
-#include <SwifTools/Application/PlatformApplicationPathProvider.h>
-#include <string>
+#include <Swiften/Base/Path.h>
#include <Swiften/Base/Platform.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Client/Client.h>
+#include <Swiften/Base/Paths.h>
+
+#include <SwifTools/Application/PlatformApplicationPathProvider.h>
+#include <SwifTools/AutoUpdater/AutoUpdater.h>
+#include <SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h>
+
+#include <Swift/Controllers/Storages/CertificateFileStorageFactory.h>
+#include <Swift/Controllers/Storages/FileStoragesFactory.h>
#include <Swift/Controllers/Settings/XMLSettingsProvider.h>
#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
@@ -34,30 +36,37 @@
#include <Swift/Controllers/ApplicationInfo.h>
#include <Swift/Controllers/BuildVersion.h>
-#include <SwifTools/AutoUpdater/AutoUpdater.h>
-#include <SwifTools/AutoUpdater/PlatformAutoUpdaterFactory.h>
-#include "Swiften/Base/Paths.h"
+#include <Swift/Controllers/StatusCache.h>
+
+#include <Swift/QtUI/QtLoginWindow.h>
+#include <Swift/QtUI/QtChatTabs.h>
+#include <Swift/QtUI/QtSystemTray.h>
+#include <Swift/QtUI/QtSoundPlayer.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUIFactory.h>
+#include <Swift/QtUI/QtChatWindowFactory.h>
+#include <Swift/QtUI/QtSingleWindow.h>
#if defined(SWIFTEN_PLATFORM_WINDOWS)
-#include "WindowsNotifier.h"
+#include <Swift/QtUI/WindowsNotifier.h>
#elif defined(HAVE_GROWL)
-#include "SwifTools/Notifier/GrowlNotifier.h"
+#include <SwifTools/Notifier/GrowlNotifier.h>
#elif defined(SWIFTEN_PLATFORM_LINUX)
-#include "FreeDesktopNotifier.h"
+#include <Swift/QtUI/FreeDesktopNotifier.h>
#else
-#include "SwifTools/Notifier/NullNotifier.h"
+#include <SwifTools/Notifier/NullNotifier.h>
#endif
#if defined(SWIFTEN_PLATFORM_MACOSX)
-#include "SwifTools/Dock/MacOSXDock.h"
+#include <SwifTools/Dock/MacOSXDock.h>
#else
-#include "SwifTools/Dock/NullDock.h"
+#include <SwifTools/Dock/NullDock.h>
#endif
#if defined(SWIFTEN_PLATFORM_MACOSX)
-#include "QtURIHandler.h"
+#include <Swift/QtUI/QtURIHandler.h>
#elif defined(SWIFTEN_PLATFORM_WIN32)
#include <SwifTools/URIHandler/NullURIHandler.h>
#else
-#include "QtDBUSURIHandler.h"
+#include <Swift/QtUI/QtDBUSURIHandler.h>
#endif
@@ -65,7 +74,7 @@ namespace Swift{
#if defined(SWIFTEN_PLATFORM_MACOSX)
-#define SWIFT_APPCAST_URL "http://swift.im/appcast/swift-mac-dev.xml"
+//#define SWIFT_APPCAST_URL "http://swift.im/appcast/swift-mac-dev.xml"
#else
-#define SWIFT_APPCAST_URL ""
+//#define SWIFT_APPCAST_URL ""
#endif
@@ -81,4 +90,8 @@ po::options_description QtSwift::getOptionsDescription() {
("multi-account", po::value<int>()->default_value(1), "Number of accounts to open windows for (unsupported)")
("start-minimized", "Don't show the login/roster window at startup")
+ ("enable-jid-adhocs", "Enable AdHoc commands to custom JID's.")
+#if QT_VERSION >= 0x040800
+ ("language", po::value<std::string>(), "Use a specific language, instead of the system-wide one")
+#endif
;
return result;
@@ -98,10 +111,24 @@ XMLSettingsProvider* QtSwift::loadSettingsFile(const QString& fileName) {
}
-QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMainThreadCaller_), autoUpdater_(NULL), idleDetector_(&idleQuerier_, networkFactories_.getTimerFactory(), 1000) {
- if (options.count("netbook-mode")) {
- splitter_ = new QSplitter();
- } else {
- splitter_ = NULL;
+void QtSwift::loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons) {
+ QFile file(fileName);
+ if (file.exists() && file.open(QIODevice::ReadOnly)) {
+ while (!file.atEnd()) {
+ QString line = file.readLine();
+ line.replace("\n", "");
+ line.replace("\r", "");
+ QStringList tokens = line.split(" ");
+ if (tokens.size() == 2) {
+ QString emoticonFile = tokens[1];
+ if (!emoticonFile.startsWith(":/") && !emoticonFile.startsWith("qrc:/")) {
+ emoticonFile = "file://" + emoticonFile;
+ }
+ emoticons[Q2PSTRING(tokens[0])] = Q2PSTRING(emoticonFile);
+ }
+ }
+ }
}
+
+QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMainThreadCaller_), autoUpdater_(NULL), idleDetector_(&idleQuerier_, networkFactories_.getTimerFactory(), 1000) {
QCoreApplication::setApplicationName(SWIFT_APPLICATION_NAME);
QCoreApplication::setOrganizationName(SWIFT_ORGANIZATION_NAME);
@@ -110,9 +137,19 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
qtSettings_ = new QtSettingsProvider();
- xmlSettings_ = loadSettingsFile(P2QSTRING((Paths::getExecutablePath() / "system-settings.xml").string()));
+ xmlSettings_ = loadSettingsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "system-settings.xml")));
settingsHierachy_ = new SettingsProviderHierachy();
settingsHierachy_->addProviderToTopOfStack(xmlSettings_);
settingsHierachy_->addProviderToTopOfStack(qtSettings_);
+ std::map<std::string, std::string> emoticons;
+ loadEmoticonsFile(":/emoticons/emoticons.txt", emoticons);
+ loadEmoticonsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "emoticons.txt")), emoticons);
+
+ if (options.count("netbook-mode")) {
+ splitter_ = new QtSingleWindow(qtSettings_);
+ } else {
+ splitter_ = NULL;
+ }
+
int numberOfAccounts = 1;
try {
@@ -124,12 +161,13 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
if (options.count("debug")) {
- Swift::logging = true;
+ Log::setLogLevel(Swift::Log::debug);
}
- tabs_ = options.count("no-tabs") && !(splitter_ > 0) ? NULL : new QtChatTabs();
+ bool enableAdHocCommandOnJID = options.count("enable-jid-adhocs") > 0;
+ tabs_ = options.count("no-tabs") && !splitter_ ? NULL : new QtChatTabs(splitter_ != NULL);
bool startMinimized = options.count("start-minimized") > 0;
applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME);
- storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir());
- certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory());
+ storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir(), networkFactories_.getCryptoProvider());
+ certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory(), networkFactories_.getCryptoProvider());
chatWindowFactory_ = new QtChatWindowFactory(splitter_, settingsHierachy_, qtSettings_, tabs_, "");
soundPlayer_ = new QtSoundPlayer(applicationPathProvider_);
@@ -164,4 +202,6 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
#endif
+ statusCache_ = new StatusCache(applicationPathProvider_);
+
if (splitter_) {
splitter_->show();
@@ -173,5 +213,5 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
systemTrays_.push_back(new QtSystemTray());
}
- QtUIFactory* uiFactory = new QtUIFactory(settingsHierachy_, qtSettings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, networkFactories_.getTimerFactory(), startMinimized);
+ QtUIFactory* uiFactory = new QtUIFactory(settingsHierachy_, qtSettings_, tabs_, splitter_, systemTrays_[i], chatWindowFactory_, networkFactories_.getTimerFactory(), statusCache_, startMinimized, !emoticons.empty(), enableAdHocCommandOnJID);
uiFactories_.push_back(uiFactory);
MainController* mainController = new MainController(
@@ -188,4 +228,5 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
uriHandler_,
&idleDetector_,
+ emoticons,
options.count("latency-debug") > 0);
mainControllers_.push_back(mainController);
@@ -209,7 +250,4 @@ QtSwift::~QtSwift() {
}
delete notifier_;
- delete settingsHierachy_;
- delete qtSettings_;
- delete xmlSettings_;
foreach (QtSystemTray* tray, systemTrays_) {
delete tray;
@@ -217,4 +255,8 @@ QtSwift::~QtSwift() {
delete tabs_;
delete splitter_;
+ delete settingsHierachy_;
+ delete qtSettings_;
+ delete xmlSettings_;
+ delete statusCache_;
delete uriHandler_;
delete dock_;
diff --git a/Swift/QtUI/QtSwift.h b/Swift/QtUI/QtSwift.h
index d30ed7c..1ea8886 100644
--- a/Swift/QtUI/QtSwift.h
+++ b/Swift/QtUI/QtSwift.h
@@ -51,4 +51,6 @@ namespace Swift {
class SettingsProviderHierachy;
class XMLSettingsProvider;
+ class StatusCache;
+ class QtSingleWindow;
class QtSwift : public QObject {
@@ -60,4 +62,5 @@ namespace Swift {
private:
XMLSettingsProvider* loadSettingsFile(const QString& fileName);
+ void loadEmoticonsFile(const QString& fileName, std::map<std::string, std::string>& emoticons);
private:
QtEventLoop clientMainThreadCaller_;
@@ -71,5 +74,5 @@ namespace Swift {
XMLSettingsProvider* xmlSettings_;
SettingsProviderHierachy* settingsHierachy_;
- QSplitter* splitter_;
+ QtSingleWindow* splitter_;
QtSoundPlayer* soundPlayer_;
Dock* dock_;
@@ -81,4 +84,5 @@ namespace Swift {
AutoUpdater* autoUpdater_;
Notifier* notifier_;
+ StatusCache* statusCache_;
PlatformIdleQuerier idleQuerier_;
ActualIdleDetector idleDetector_;
diff --git a/Swift/QtUI/QtSwiftUtil.h b/Swift/QtUI/QtSwiftUtil.h
index 2d0f970..c903af1 100644
--- a/Swift/QtUI/QtSwiftUtil.h
+++ b/Swift/QtUI/QtSwiftUtil.h
@@ -10,3 +10,5 @@
#define Q2PSTRING(a) std::string(a.toUtf8())
+#include <boost/date_time/posix_time/posix_time.hpp>
+
#define B2QDATE(a) QDateTime::fromTime_t((a - boost::posix_time::from_time_t(0)).total_seconds())
diff --git a/Swift/QtUI/QtSystemTray.cpp b/Swift/QtUI/QtSystemTray.cpp
index 123e6a3..83018b8 100644
--- a/Swift/QtUI/QtSystemTray.cpp
+++ b/Swift/QtUI/QtSystemTray.cpp
@@ -1,24 +1,45 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+#pragma GCC diagnostic ignored "-Wredundant-decls"
+
#include "Swift/QtUI/QtSystemTray.h"
+#include <QtDebug>
+#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
+#include <QDBusInterface>
+#endif
#include <QIcon>
#include <QPixmap>
#include <QResource>
+#include <QMenu>
+#include <QAction>
namespace Swift {
-QtSystemTray::QtSystemTray() : QObject(), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
+QtSystemTray::QtSystemTray() : QObject(), statusType_(StatusShow::None), trayMenu_(0), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
trayIcon_ = new QSystemTrayIcon(offlineIcon_);
trayIcon_->setToolTip("Swift");
connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
connect(&throbberMovie_, SIGNAL(frameChanged(int)), this, SLOT(handleThrobberFrameChanged(int)));
+#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
+ bool isUnity = QDBusInterface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher").isValid();
+ if (isUnity) {
+ // Add an activation menu, because this is the only way to get the application to the
+ // front on Unity. See the README for sni-qt (which handles Qt tray icons for Unity)
+ trayMenu_ = new QMenu();
+ QAction* showAction = new QAction(QString("Show/Hide"), this);
+ connect(showAction, SIGNAL(triggered()), SIGNAL(clicked()));
+ trayMenu_->addAction(showAction);
+ trayIcon_->setContextMenu(trayMenu_);
+ }
+#endif
trayIcon_->show();
}
QtSystemTray::~QtSystemTray() {
+ delete trayMenu_;
delete trayIcon_;
}
diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h
index cc7321b..8691e19 100644
--- a/Swift/QtUI/QtSystemTray.h
+++ b/Swift/QtUI/QtSystemTray.h
@@ -13,6 +13,8 @@
class QIcon;
+class QMenu;
namespace Swift {
+
class QtSystemTray : public QObject, public SystemTray {
Q_OBJECT
@@ -36,4 +38,5 @@ namespace Swift {
StatusShow::Type statusType_;
QSystemTrayIcon* trayIcon_;
+ QMenu* trayMenu_;
QIcon onlineIcon_;
QIcon awayIcon_;
diff --git a/Swift/QtUI/QtTabbable.cpp b/Swift/QtUI/QtTabbable.cpp
index 84a5100..124d1b4 100644
--- a/Swift/QtUI/QtTabbable.cpp
+++ b/Swift/QtUI/QtTabbable.cpp
@@ -5,13 +5,28 @@
*/
-#include "QtTabbable.h"
+#include <Swift/QtUI/QtTabbable.h>
#include <QApplication>
+#include <QKeyEvent>
-#include "QtChatTabs.h"
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Platform.h>
+
+#include <Swift/QtUI/QtChatTabs.h>
+#include <Swift/QtUI/QtUtilities.h>
namespace Swift {
+QtTabbable::QtTabbable() : QWidget() {
+ shortcuts << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), window(), SLOT(close()));
+ shortcuts << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageUp), window(), SIGNAL(requestPreviousTab()));
+ shortcuts << new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_PageDown), window(), SIGNAL(requestNextTab()));
+ shortcuts << new QShortcut(QKeySequence(Qt::ALT + Qt::Key_A), window(), SIGNAL(requestActiveTab()));
+}
+
QtTabbable::~QtTabbable() {
+ foreach (QShortcut* shortcut, shortcuts) {
+ delete shortcut;
+ }
emit windowClosing();
}
@@ -26,34 +41,18 @@ bool QtTabbable::isWidgetSelected() {
}
-void QtTabbable::keyPressEvent(QKeyEvent *event) {
- handleKeyPressEvent(event);
-}
-
-void QtTabbable::handleKeyPressEvent(QKeyEvent *event) {
- event->ignore();
- int key = event->key();
- Qt::KeyboardModifiers modifiers = event->modifiers();
- if (key == Qt::Key_W && modifiers == Qt::ControlModifier) {
- close();
- event->accept();
- } else if (
- (key == Qt::Key_PageUp && modifiers == Qt::ControlModifier)
-// || (key == Qt::Key_Left && modifiers == (Qt::ControlModifier & Qt::ShiftModifier))
- ) {
- emit requestPreviousTab();
- event->accept();
- } else if (
- (key == Qt::Key_PageDown && modifiers == Qt::ControlModifier)
-// || (key == Qt::Key_Right && modifiers == (Qt::ControlModifier & Qt::ShiftModifier)
- || (key == Qt::Key_Tab && modifiers == Qt::ControlModifier)
- ) {
+bool QtTabbable::event(QEvent* event) {
+ QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
+ if (keyEvent) {
+ // According to Qt's focus documentation, one can only override CTRL+TAB via reimplementing QWidget::event().
+#ifdef SWIFTEN_PLATFORM_LINUX
+ if (keyEvent->modifiers() == QtUtilities::ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab && event->type() != QEvent::KeyRelease) {
+#else
+ if (keyEvent->modifiers() == QtUtilities::ctrlHardwareKeyModifier && keyEvent->key() == Qt::Key_Tab) {
+#endif
emit requestNextTab();
- event->accept();
- } else if (
- (key == Qt::Key_A && modifiers == Qt::AltModifier)
- ) {
- emit requestActiveTab();
- event->accept();
+ return true;
+ }
}
+ return QWidget::event(event);
}
diff --git a/Swift/QtUI/QtTabbable.h b/Swift/QtUI/QtTabbable.h
index baab15c..fc131ca 100644
--- a/Swift/QtUI/QtTabbable.h
+++ b/Swift/QtUI/QtTabbable.h
@@ -7,6 +7,7 @@
#pragma once
-#include <QKeyEvent>
#include <QWidget>
+#include <QShortcut>
+#include <QList>
@@ -16,14 +17,11 @@ namespace Swift {
public:
enum AlertType {NoActivity, WaitingActivity, ImpendingActivity};
- ~QtTabbable();
+ virtual ~QtTabbable();
bool isWidgetSelected();
- virtual AlertType getWidgetAlertState() {return NoActivity;};
+ virtual AlertType getWidgetAlertState() {return NoActivity;}
virtual int getCount() {return 0;}
protected:
- QtTabbable() : QWidget() {};
- void keyPressEvent(QKeyEvent* event);
-
- protected slots:
- void handleKeyPressEvent(QKeyEvent* event);
+ QtTabbable();
+ bool event(QEvent* event);
signals:
@@ -37,4 +35,7 @@ namespace Swift {
void requestActiveTab();
void requestFlash();
+
+ private:
+ QList<QShortcut*> shortcuts;
};
}
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index 3a62325..8551f3d 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,13 +7,40 @@
#include <Swift/QtUI/QtTextEdit.h>
+#include <boost/tuple/tuple.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/bind.hpp>
+
+#include <QApplication>
#include <QFontMetrics>
#include <QKeyEvent>
+#include <QDebug>
+#include <QMenu>
+
+#include <Swiften/Base/foreach.h>
+
+#include <SwifTools/SpellCheckerFactory.h>
+#include <SwifTools/SpellChecker.h>
+
+#include <Swift/Controllers/SettingConstants.h>
+
+#include <Swift/QtUI/QtSpellCheckerWindow.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
namespace Swift {
-QtTextEdit::QtTextEdit(QWidget* parent) : QTextEdit(parent){
+QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent) {
connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged()));
+ checker_ = NULL;
+ settings_ = settings;
+#ifdef HAVE_SPELLCHECKER
+ setUpSpellChecker();
+#endif
handleTextChanged();
-};
+}
+
+QtTextEdit::~QtTextEdit() {
+ delete checker_;
+}
void QtTextEdit::keyPressEvent(QKeyEvent* event) {
@@ -36,11 +63,44 @@ void QtTextEdit::keyPressEvent(QKeyEvent* event) {
}
else if ((key == Qt::Key_Up)
- || (key == Qt::Key_Down)
- ){
+ || (key == Qt::Key_Down)) {
emit unhandledKeyPressEvent(event);
QTextEdit::keyPressEvent(event);
}
+ else if ((key == Qt::Key_K && modifiers == QtUtilities::ctrlHardwareKeyModifier)) {
+ QTextCursor cursor = textCursor();
+ cursor.setPosition(toPlainText().size(), QTextCursor::KeepAnchor);
+ cursor.removeSelectedText();
+ }
else {
QTextEdit::keyPressEvent(event);
+#ifdef HAVE_SPELLCHECKER
+ if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) {
+ underlineMisspells();
+ }
+#endif
+ }
+}
+
+void QtTextEdit::underlineMisspells() {
+ QTextCursor cursor = textCursor();
+ misspelledPositions_.clear();
+ QTextCharFormat normalFormat;
+ cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
+ cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor, 1);
+ cursor.setCharFormat(normalFormat);
+ if (checker_ == NULL) {
+ return;
+ }
+ QTextCharFormat spellingErrorFormat;
+ spellingErrorFormat.setUnderlineColor(QColor(Qt::red));
+ spellingErrorFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
+ std::string fragment = Q2PSTRING(cursor.selectedText());
+ checker_->checkFragment(fragment, misspelledPositions_);
+ foreach (PositionPair position, misspelledPositions_) {
+ cursor.setPosition(boost::get<0>(position), QTextCursor::MoveAnchor);
+ cursor.setPosition(boost::get<1>(position), QTextCursor::KeepAnchor);
+ cursor.setCharFormat(spellingErrorFormat);
+ cursor.clearSelection();
+ cursor.setCharFormat(normalFormat);
}
}
@@ -54,4 +114,22 @@ void QtTextEdit::handleTextChanged() {
}
+void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition) {
+ QTextCursor cursor = textCursor();
+ PositionPair wordPosition = getWordFromCursor(cursorPosition);
+ cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
+ cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
+ QTextCharFormat normalFormat;
+ cursor.insertText(word, normalFormat);
+}
+
+PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) {
+ for (PositionPairList::iterator it = misspelledPositions_.begin(); it != misspelledPositions_.end(); ++it) {
+ if (cursorPosition >= boost::get<0>(*it) && cursorPosition <= boost::get<1>(*it)) {
+ return *it;
+ }
+ }
+ return boost::make_tuple(-1,-1);
+}
+
QSize QtTextEdit::sizeHint() const {
QFontMetrics inputMetrics(currentFont());
@@ -67,6 +145,95 @@ QSize QtTextEdit::sizeHint() const {
}
+void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) {
+ QMenu* menu = createStandardContextMenu();
+ QTextCursor cursor = cursorForPosition(event->pos());
+#ifdef HAVE_SPELLCHECKER
+ QAction* insertPoint = menu->actions().first();
+ QAction* settingsAction = new QAction(tr("Spell Checker Options"), menu);
+ menu->insertAction(insertPoint, settingsAction);
+ menu->insertAction(insertPoint, menu->addSeparator());
+ addSuggestions(menu, event);
+ QAction* result = menu->exec(event->globalPos());
+ if (result == settingsAction) {
+ spellCheckerSettingsWindow();
+ }
+ for (std::vector<QAction*>::iterator it = replaceWordActions_.begin(); it != replaceWordActions_.end(); ++it) {
+ if (*it == result) {
+ replaceMisspelledWord((*it)->text(), cursor.position());
+ }
+ }
+#else
+ menu->exec(event->globalPos());
+#endif
+ delete menu;
}
+void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event)
+{
+ replaceWordActions_.clear();
+ QAction* insertPoint = menu->actions().first();
+ QTextCursor cursor = cursorForPosition(event->pos());
+ PositionPair wordPosition = getWordFromCursor(cursor.position());
+ if (boost::get<0>(wordPosition) < 0) {
+ // The click was executed outside a spellable word so no
+ // suggestions are necessary
+ return;
+ }
+ cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor);
+ cursor.setPosition(boost::get<1>(wordPosition), QTextCursor::KeepAnchor);
+ std::vector<std::string> wordList;
+ checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList);
+ if (wordList.size() == 0) {
+ QAction* noSuggestions = new QAction(tr("No Suggestions"), menu);
+ noSuggestions->setDisabled(true);
+ menu->insertAction(insertPoint, noSuggestions);
+ }
+ else {
+ for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) {
+ QAction* wordAction = new QAction(it->c_str(), menu);
+ menu->insertAction(insertPoint, wordAction);
+ replaceWordActions_.push_back(wordAction);
+ }
+ }
+ menu->insertAction(insertPoint, menu->addSeparator());
+}
+#ifdef HAVE_SPELLCHECKER
+void QtTextEdit::setUpSpellChecker()
+{
+ delete checker_;
+ checker_ = NULL;
+ if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) {
+ std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE);
+ checker_ = SpellCheckerFactory().createSpellChecker(dictPath + dictFile);
+ }
+}
+#endif
+
+void QtTextEdit::spellCheckerSettingsWindow() {
+ if (!spellCheckerWindow_) {
+ spellCheckerWindow_ = new QtSpellCheckerWindow(settings_);
+ settings_->onSettingChanged.connect(boost::bind(&QtTextEdit::handleSettingChanged, this, _1));
+ spellCheckerWindow_->show();
+ }
+ else {
+ spellCheckerWindow_->show();
+ spellCheckerWindow_->raise();
+ spellCheckerWindow_->activateWindow();
+ }
+}
+
+void QtTextEdit::handleSettingChanged(const std::string& settings) {
+ if (settings == SettingConstants::SPELL_CHECKER.getKey()
+ || settings == SettingConstants::DICT_PATH.getKey()
+ || settings == SettingConstants::DICT_FILE.getKey()) {
+#ifdef HAVE_SPELLCHECKER
+ setUpSpellChecker();
+ underlineMisspells();
+#endif
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtTextEdit.h b/Swift/QtUI/QtTextEdit.h
index 075728b..a8df4d3 100644
--- a/Swift/QtUI/QtTextEdit.h
+++ b/Swift/QtUI/QtTextEdit.h
@@ -6,19 +6,45 @@
#pragma once
+
+#include <SwifTools/SpellParser.h>
+
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/Controllers/SettingConstants.h>
+
#include <QTextEdit>
+#include <QPointer>
namespace Swift {
+ class SpellChecker;
+ class QtSpellCheckerWindow;
class QtTextEdit : public QTextEdit {
Q_OBJECT
public:
- QtTextEdit(QWidget* parent = 0);
+ QtTextEdit(SettingsProvider* settings, QWidget* parent = 0);
+ virtual ~QtTextEdit();
virtual QSize sizeHint() const;
signals:
+ void wordCorrected(QString& word);
void returnPressed();
void unhandledKeyPressEvent(QKeyEvent* event);
+ public slots:
+ void handleSettingChanged(const std::string& settings);
protected:
virtual void keyPressEvent(QKeyEvent* event);
+ virtual void contextMenuEvent(QContextMenuEvent* event);
private slots:
void handleTextChanged();
+ private:
+ SpellChecker *checker_;
+ std::vector<QAction*> replaceWordActions_;
+ PositionPairList misspelledPositions_;
+ SettingsProvider *settings_;
+ QPointer<QtSpellCheckerWindow> spellCheckerWindow_;
+ void addSuggestions(QMenu* menu, QContextMenuEvent* event);
+ void replaceMisspelledWord(const QString& word, int cursorPosition);
+ void setUpSpellChecker();
+ void underlineMisspells();
+ void spellCheckerSettingsWindow();
+ PositionPair getWordFromCursor(int cursorPosition);
};
}
diff --git a/Swift/QtUI/QtTranslator.h b/Swift/QtUI/QtTranslator.h
index fdafaf0..a2129f0 100644
--- a/Swift/QtUI/QtTranslator.h
+++ b/Swift/QtUI/QtTranslator.h
@@ -17,5 +17,9 @@ class QtTranslator : public Swift::Translator {
virtual std::string translate(const std::string& text, const std::string& context) {
+#if QT_VERSION >= 0x050000
+ return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0).toUtf8());
+#else
return std::string(QCoreApplication::translate(context.c_str(), text.c_str(), 0, QCoreApplication::UnicodeUTF8).toUtf8());
+#endif
}
};
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index 2a50592..b0c1492 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -1,36 +1,43 @@
/*
- * Copyright (c) 2010-2012 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtUIFactory.h"
+#include <Swift/QtUI/QtUIFactory.h>
#include <QSplitter>
-#include "QtXMLConsoleWidget.h"
-#include "QtChatTabs.h"
-#include "QtMainWindow.h"
-#include "QtLoginWindow.h"
-#include "QtSystemTray.h"
-#include "QtSettingsProvider.h"
-#include "QtMainWindow.h"
-#include "QtChatWindow.h"
-#include "QtJoinMUCWindow.h"
-#include "QtChatWindowFactory.h"
-#include "QtSwiftUtil.h"
-#include "MUCSearch/QtMUCSearchWindow.h"
-#include "UserSearch/QtUserSearchWindow.h"
-#include "QtProfileWindow.h"
-#include "QtContactEditWindow.h"
-#include "QtAdHocCommandWindow.h"
-#include "QtFileTransferListWidget.h"
+#include <Swift/QtUI/QtXMLConsoleWidget.h>
+#include <Swift/QtUI/QtChatTabs.h>
+#include <Swift/QtUI/QtMainWindow.h>
+#include <Swift/QtUI/QtLoginWindow.h>
+#include <Swift/QtUI/QtSystemTray.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
+#include <Swift/QtUI/QtMainWindow.h>
+#include <Swift/QtUI/QtChatWindow.h>
+#include <Swift/QtUI/QtJoinMUCWindow.h>
+#include <Swift/QtUI/QtChatWindowFactory.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/MUCSearch/QtMUCSearchWindow.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchWindow.h>
+#include <Swift/QtUI/QtProfileWindow.h>
+#include <Swift/QtUI/QtContactEditWindow.h>
+#include <Swift/QtUI/QtAdHocCommandWindow.h>
+#include <Swift/QtUI/QtFileTransferListWidget.h>
+#include <Swift/QtUI/QtHighlightEditor.h>
+#include <Swift/QtUI/Whiteboard/QtWhiteboardWindow.h>
#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/QtHistoryWindow.h>
+#include <Swiften/Whiteboard/WhiteboardSession.h>
+#include <Swift/QtUI/QtSingleWindow.h>
+#include <Swift/QtUI/QtBlockListEditorWindow.h>
namespace Swift {
-QtUIFactory::QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, bool startMinimized) : settings(settings), qtOnlySettings(qtOnlySettings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), timerFactory_(timerFactory), lastMainWindow(NULL), loginWindow(NULL), startMinimized(startMinimized) {
+QtUIFactory::QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist, bool enableAdHocCommandOnJID) : settings(settings), qtOnlySettings(qtOnlySettings), tabs(tabs), netbookSplitter(netbookSplitter), systemTray(systemTray), chatWindowFactory(chatWindowFactory), timerFactory_(timerFactory), lastMainWindow(NULL), loginWindow(NULL), statusCache(statusCache), startMinimized(startMinimized), emoticonsExist_(emoticonsExist), enableAdHocCommandOnJID_(enableAdHocCommandOnJID) {
chatFontSize = settings->getSetting(QtUISettingConstants::CHATWINDOW_FONT_SIZE);
+ historyFontSize_ = settings->getSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE);
}
@@ -45,4 +52,23 @@ XMLConsoleWidget* QtUIFactory::createXMLConsoleWidget() {
}
+HistoryWindow* QtUIFactory::createHistoryWindow(UIEventStream* uiEventStream) {
+ QtHistoryWindow* window = new QtHistoryWindow(settings, uiEventStream);
+ tabs->addTab(window);
+ if (!tabs->isVisible()) {
+ tabs->show();
+ }
+
+ connect(window, SIGNAL(fontResized(int)), this, SLOT(handleHistoryWindowFontResized(int)));
+
+ window->handleFontResized(historyFontSize_);
+ window->show();
+ return window;
+}
+
+void QtUIFactory::handleHistoryWindowFontResized(int size) {
+ historyFontSize_ = size;
+ settings->storeSetting(QtUISettingConstants::HISTORYWINDOW_FONT_SIZE, size);
+}
+
FileTransferListWidget* QtUIFactory::createFileTransferListWidget() {
QtFileTransferListWidget* widget = new QtFileTransferListWidget();
@@ -56,5 +82,5 @@ FileTransferListWidget* QtUIFactory::createFileTransferListWidget() {
MainWindow* QtUIFactory::createMainWindow(UIEventStream* eventStream) {
- lastMainWindow = new QtMainWindow(settings, eventStream, loginWindow->getMenus());
+ lastMainWindow = new QtMainWindow(settings, eventStream, loginWindow->getMenus(), statusCache, emoticonsExist_, enableAdHocCommandOnJID_);
return lastMainWindow;
}
@@ -63,5 +89,5 @@ LoginWindow* QtUIFactory::createLoginWindow(UIEventStream* eventStream) {
loginWindow = new QtLoginWindow(eventStream, settings, timerFactory_);
if (netbookSplitter) {
- netbookSplitter->insertWidget(0, loginWindow);
+ netbookSplitter->insertAtFront(loginWindow);
}
connect(systemTray, SIGNAL(clicked()), loginWindow, SLOT(toggleBringToFront()));
@@ -120,6 +146,6 @@ void QtUIFactory::handleChatWindowFontResized(int size) {
UserSearchWindow* QtUIFactory::createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) {
- return new QtUserSearchWindow(eventStream, type, groups);
-};
+ return new QtUserSearchWindow(eventStream, type, groups, qtOnlySettings);
+}
JoinMUCWindow* QtUIFactory::createJoinMUCWindow(UIEventStream* uiEventStream) {
@@ -135,6 +161,18 @@ ContactEditWindow* QtUIFactory::createContactEditWindow() {
}
-void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) {
- new QtAdHocCommandWindow(command);
+WhiteboardWindow* QtUIFactory::createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession) {
+ return new QtWhiteboardWindow(whiteboardSession);
+}
+
+HighlightEditorWindow* QtUIFactory::createHighlightEditorWindow() {
+ return new QtHighlightEditor(qtOnlySettings);
+}
+
+BlockListEditorWidget *QtUIFactory::createBlockListEditorWidget() {
+ return new QtBlockListEditorWindow();
+}
+
+AdHocCommandWindow* QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) {
+ return new QtAdHocCommandWindow(command);
}
diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h
index 29d9d1c..9c07e76 100644
--- a/Swift/QtUI/QtUIFactory.h
+++ b/Swift/QtUI/QtUIFactory.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2012 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -25,11 +25,16 @@ namespace Swift {
class QtChatWindow;
class TimerFactory;
+ class historyWindow_;
+ class WhiteboardSession;
+ class StatusCache;
+ class QtSingleWindow;
class QtUIFactory : public QObject, public UIFactory {
Q_OBJECT
public:
- QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QSplitter* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, bool startMinimized);
+ QtUIFactory(SettingsProviderHierachy* settings, QtSettingsProvider* qtOnlySettings, QtChatTabs* tabs, QtSingleWindow* netbookSplitter, QtSystemTray* systemTray, QtChatWindowFactory* chatWindowFactory, TimerFactory* timerFactory, StatusCache* statusCache, bool startMinimized, bool emoticonsExist, bool enableAdHocCommandOnJID);
virtual XMLConsoleWidget* createXMLConsoleWidget();
+ virtual HistoryWindow* createHistoryWindow(UIEventStream*);
virtual MainWindow* createMainWindow(UIEventStream* eventStream);
virtual LoginWindow* createLoginWindow(UIEventStream* eventStream);
@@ -43,9 +48,13 @@ namespace Swift {
virtual ContactEditWindow* createContactEditWindow();
virtual FileTransferListWidget* createFileTransferListWidget();
- virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
+ virtual WhiteboardWindow* createWhiteboardWindow(boost::shared_ptr<WhiteboardSession> whiteboardSession);
+ virtual HighlightEditorWindow* createHighlightEditorWindow();
+ virtual BlockListEditorWidget* createBlockListEditorWidget();
+ virtual AdHocCommandWindow* createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
private slots:
void handleLoginWindowGeometryChanged();
void handleChatWindowFontResized(int);
+ void handleHistoryWindowFontResized(int);
private:
@@ -53,5 +62,5 @@ namespace Swift {
QtSettingsProvider* qtOnlySettings;
QtChatTabs* tabs;
- QSplitter* netbookSplitter;
+ QtSingleWindow* netbookSplitter;
QtSystemTray* systemTray;
QtChatWindowFactory* chatWindowFactory;
@@ -59,7 +68,11 @@ namespace Swift {
QtMainWindow* lastMainWindow;
QtLoginWindow* loginWindow;
+ StatusCache* statusCache;
std::vector<QPointer<QtChatWindow> > chatWindows;
bool startMinimized;
int chatFontSize;
+ int historyFontSize_;
+ bool emoticonsExist_;
+ bool enableAdHocCommandOnJID_;
};
}
diff --git a/Swift/QtUI/QtUISettingConstants.cpp b/Swift/QtUI/QtUISettingConstants.cpp
index 046ccc1..6b4f870 100644
--- a/Swift/QtUI/QtUISettingConstants.cpp
+++ b/Swift/QtUI/QtUISettingConstants.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2012 Kevin Smith
+ * Copyright (c) 2012-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -14,3 +14,7 @@ const SettingsProvider::Setting<int> QtUISettingConstants::CURRENT_ROSTER_TAB("c
const SettingsProvider::Setting<bool> QtUISettingConstants::SHOW_NICK_IN_ROSTER_HEADER("showNickInRosterHeader", true);
const SettingsProvider::Setting<int> QtUISettingConstants::CHATWINDOW_FONT_SIZE("chatWindowFontSize", 0);
+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);
+const SettingsProvider::Setting<bool> QtUISettingConstants::USE_SCREENREADER("screenreader", false);
}
diff --git a/Swift/QtUI/QtUISettingConstants.h b/Swift/QtUI/QtUISettingConstants.h
index 82f98bb..d0329fe 100644
--- a/Swift/QtUI/QtUISettingConstants.h
+++ b/Swift/QtUI/QtUISettingConstants.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2012 Kevin Smith
+ * Copyright (c) 2012-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -17,4 +17,8 @@ namespace Swift {
static const SettingsProvider::Setting<bool> SHOW_NICK_IN_ROSTER_HEADER;
static const SettingsProvider::Setting<int> CHATWINDOW_FONT_SIZE;
+ static const SettingsProvider::Setting<int> HISTORYWINDOW_FONT_SIZE;
+ static const SettingsProvider::Setting<bool> SHOW_EMOTICONS;
+ static const SettingsProvider::Setting<bool> USE_PLAIN_CHATS;
+ static const SettingsProvider::Setting<bool> USE_SCREENREADER;
};
}
diff --git a/Swift/QtUI/QtURLValidator.cpp b/Swift/QtUI/QtURLValidator.cpp
new file mode 100644
index 0000000..4d56b98
--- /dev/null
+++ b/Swift/QtUI/QtURLValidator.cpp
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtURLValidator.h>
+
+#include <Swiften/Base/URL.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+QtURLValidator::QtURLValidator(QObject* parent) : QValidator(parent) {
+
+}
+
+QValidator::State QtURLValidator::validate(QString& input, int&) const {
+ URL url = URL::fromString(Q2PSTRING(input));
+ bool valid = !url.isEmpty();
+ valid &= (url.getScheme() == "http" || url.getScheme() == "https");
+ return valid ? Acceptable : Intermediate;
+}
+
+}
+
diff --git a/Swift/QtUI/QtURLValidator.h b/Swift/QtUI/QtURLValidator.h
new file mode 100644
index 0000000..fa17253
--- /dev/null
+++ b/Swift/QtUI/QtURLValidator.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <QValidator>
+
+namespace Swift {
+ class QtURLValidator : public QValidator {
+ Q_OBJECT
+ public:
+ QtURLValidator(QObject* parent);
+ virtual QValidator::State validate(QString& input, int& pos) const;
+ };
+}
+
diff --git a/Swift/QtUI/QtUtilities.cpp b/Swift/QtUI/QtUtilities.cpp
index be9d179..0fe2bf2 100644
--- a/Swift/QtUI/QtUtilities.cpp
+++ b/Swift/QtUI/QtUtilities.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,6 +7,7 @@
#include "QtUtilities.h"
+#include <QTextDocument>
#include <QWidget>
-#ifdef Q_WS_X11
+#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
#include <QX11Info>
#include <X11/Xlib.h>
@@ -18,9 +19,11 @@
namespace QtUtilities {
+
void setX11Resource(QWidget* widget, const QString& c) {
-#ifdef Q_WS_X11
+#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
char res_class[] = SWIFT_APPLICATION_NAME;
XClassHint hint;
- hint.res_name = (QString(SWIFT_APPLICATION_NAME) + "-" + c).toUtf8().data();
+ QByteArray resName = (QString(SWIFT_APPLICATION_NAME) + "-" + c).toUtf8();
+ hint.res_name = resName.data();
hint.res_class = res_class;
XSetClassHint(widget->x11Info().display(), widget->winId(), &hint);
@@ -31,3 +34,11 @@ void setX11Resource(QWidget* widget, const QString& c) {
}
+QString htmlEscape(const QString& s) {
+#if QT_VERSION >= 0x050000
+ return s.toHtmlEscaped();
+#else
+ return Qt::escape(s);
+#endif
+}
+
}
diff --git a/Swift/QtUI/QtUtilities.h b/Swift/QtUI/QtUtilities.h
index 6e64d6e..6f82dfd 100644
--- a/Swift/QtUI/QtUtilities.h
+++ b/Swift/QtUI/QtUtilities.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -10,5 +10,13 @@ class QWidget;
class QString;
+#include <QKeyEvent>
+
namespace QtUtilities {
void setX11Resource(QWidget* widget, const QString& c);
-};
+ QString htmlEscape(const QString& s);
+ #ifdef SWIFTEN_PLATFORM_MACOSX
+ const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::MetaModifier;
+ #else
+ const Qt::KeyboardModifier ctrlHardwareKeyModifier = Qt::ControlModifier;
+ #endif
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp b/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp
new file mode 100644
index 0000000..ebd62bc
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtCloseButton.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtCloseButton.h"
+
+#include <QMouseEvent>
+#include <QPainter>
+#include <QStyle>
+#include <QStyleOption>
+
+namespace Swift {
+
+QtCloseButton::QtCloseButton(QWidget *parent) : QAbstractButton(parent) {
+
+}
+
+QSize QtCloseButton::sizeHint() const {
+ return QSize(style()->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0), style()->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0));
+}
+
+bool QtCloseButton::event(QEvent *e) {
+ if (e->type() == QEvent::Enter || e->type() == QEvent::Leave) {
+ update();
+ }
+ return QAbstractButton::event(e);
+}
+
+void QtCloseButton::paintEvent(QPaintEvent *) {
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::HighQualityAntialiasing);
+ QStyleOption opt;
+ opt.init(this);
+ opt.state |= QStyle::State_AutoRaise;
+ if (underMouse() && !isDown()) {
+ opt.state |= QStyle::State_Raised;
+ } else if (isDown()) {
+ opt.state |= QStyle::State_Sunken;
+ }
+ style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &painter, this);
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtCloseButton.h b/Swift/QtUI/QtVCardWidget/QtCloseButton.h
new file mode 100644
index 0000000..cb92e12
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtCloseButton.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QAbstractButton>
+
+namespace Swift {
+
+ class QtCloseButton : public QAbstractButton {
+ Q_OBJECT
+ public:
+ explicit QtCloseButton(QWidget *parent = 0);
+ virtual QSize sizeHint() const;
+
+ protected:
+ virtual bool event(QEvent *e);
+ virtual void paintEvent(QPaintEvent* );
+ };
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
new file mode 100644
index 0000000..d50585c
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "QtRemovableItemDelegate.h"
+#include <Swiften/Base/Platform.h>
+#include <QEvent>
+#include <QPainter>
+
+namespace Swift {
+
+QtRemovableItemDelegate::QtRemovableItemDelegate(const QStyle* style) : style(style) {
+
+}
+
+void QtRemovableItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
+ QStyleOption opt;
+ opt.state = option.state;
+ opt.state |= QStyle::State_AutoRaise;
+ if (option.state.testFlag(QStyle::State_MouseOver)) {
+ opt.state |= QStyle::State_Raised;
+ }
+ opt.rect = option.rect;
+ painter->save();
+ painter->fillRect(option.rect, option.state & QStyle::State_Selected ? option.palette.highlight() : option.palette.base());
+ if (index.data().toString().isEmpty()) {
+#ifdef SWIFTEN_PLATFORM_MACOSX
+ // workaround for Qt not painting relative to the cell we're in, on OS X
+ int height = style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0);
+ painter->translate(option.rect.x(), option.rect.y() + (option.rect.height() - height)/2);
+#endif
+ style->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, painter);
+ }
+ painter->restore();
+}
+
+QWidget* QtRemovableItemDelegate::createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const {
+ return NULL;
+}
+
+bool QtRemovableItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
+ if (index.data().toString().isEmpty() && event->type() == QEvent::MouseButtonRelease) {
+ model->removeRow(index.row());
+ return true;
+ } else {
+ return QItemDelegate::editorEvent(event, model, option, index);
+ }
+}
+
+QSize QtRemovableItemDelegate::sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const {
+ QSize size(style->pixelMetric(QStyle::PM_TabCloseIndicatorWidth, 0, 0) + 2, style->pixelMetric(QStyle::PM_TabCloseIndicatorHeight, 0, 0) + 2);
+ return size;
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h
new file mode 100644
index 0000000..75137e1
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QItemDelegate>
+
+namespace Swift {
+
+class QtRemovableItemDelegate : public QItemDelegate {
+ public:
+ QtRemovableItemDelegate(const QStyle* style);
+
+ virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex&) const;
+ virtual QWidget* createEditor(QWidget*, const QStyleOptionViewItem&, const QModelIndex&) const;
+ virtual QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const;
+
+ protected:
+ virtual bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index);
+
+ private:
+ const QStyle* style;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
new file mode 100644
index 0000000..877a598
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+
+#include "QtResizableLineEdit.h"
+
+namespace Swift {
+
+QtResizableLineEdit::QtResizableLineEdit(QWidget* parent) :
+ QLineEdit(parent), editable(false) {
+ connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
+ setMinimumWidth(30);
+}
+
+QtResizableLineEdit::~QtResizableLineEdit() {
+}
+
+bool QtResizableLineEdit::isEditable() const {
+ return editable;
+}
+void QtResizableLineEdit::setEditable(const bool editable) {
+ this->editable = editable;
+ if (editable) {
+ setReadOnly(false);
+ } else {
+ setReadOnly(true);
+ }
+}
+
+
+QSize QtResizableLineEdit::sizeHint() const {
+ int horizontalMargin = 10;
+ int verticalMargin = 6;
+ QSize textDimensions;
+#if QT_VERSION >= 0x040700
+ textDimensions = fontMetrics().boundingRect(text().isEmpty() ? placeholderText() : text()).size();
+#else
+ textDimensions = fontMetrics().boundingRect(text().isEmpty() ? QString(" ") : text()).size();
+#endif
+ textDimensions.setWidth(textDimensions.width() + horizontalMargin);
+ textDimensions.setHeight(textDimensions.height() + verticalMargin);
+ return textDimensions;
+}
+
+void QtResizableLineEdit::textChanged(QString) {
+ updateGeometry();
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h
new file mode 100644
index 0000000..9022d38
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QLineEdit>
+
+namespace Swift {
+
+ class QtResizableLineEdit : public QLineEdit {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+
+ public:
+ explicit QtResizableLineEdit(QWidget* parent = 0);
+ ~QtResizableLineEdit();
+
+ bool isEditable() const;
+ void setEditable(const bool);
+
+ virtual QSize sizeHint() const;
+
+ private slots:
+ void textChanged(QString);
+
+ private:
+ bool editable;
+ };
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
new file mode 100644
index 0000000..bade009
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtTagComboBox.h"
+
+#include <QAbstractItemView>
+#include <QtGui>
+
+namespace Swift {
+
+QtTagComboBox::QtTagComboBox(QWidget* parent) : QComboBox(parent) {
+ setEditable(false);
+ displayModel = new QStandardItemModel();
+ displayItem = new QStandardItem();
+ displayItem->setText("");
+ displayModel->insertRow(0, displayItem);
+ editMenu = new QMenu();
+ this->setModel(displayModel);
+ editable = true;
+}
+
+QtTagComboBox::~QtTagComboBox() {
+
+}
+
+bool QtTagComboBox::isEditable() const {
+ return editable;
+}
+
+void QtTagComboBox::setEditable(const bool editable) {
+ this->editable = editable;
+}
+
+void QtTagComboBox::addTag(const QString &id, const QString &label) {
+ QAction* tagAction = new QAction(editMenu);
+ tagAction->setText(label);
+ tagAction->setCheckable(true);
+ tagAction->setData(QString(id));
+ editMenu->addAction(tagAction);
+}
+
+void QtTagComboBox::setTag(const QString &id, bool value) {
+ QList<QAction*> tagActions = editMenu->actions();
+ foreach(QAction* action, tagActions) {
+ if (action->data() == id) {
+ action->setChecked(value);
+ updateDisplayItem();
+ return;
+ }
+ }
+}
+
+bool QtTagComboBox::isTagSet(const QString &id) const {
+ QList<QAction*> tagActions = editMenu->actions();
+ foreach(QAction* action, tagActions) {
+ if (action->data() == id) {
+ return action->isChecked();
+ }
+ }
+ return false;
+}
+
+void QtTagComboBox::showPopup() {
+
+}
+
+void QtTagComboBox::hidePopup() {
+
+}
+
+bool QtTagComboBox::event(QEvent* event) {
+ if (event->type() == QEvent::MouseButtonPress ||
+ event->type() == QEvent::KeyRelease) {
+ if (!editable) return true;
+
+ QPoint p = mapToGlobal(QPoint(0,0));
+ p += QPoint(0, height());
+ editMenu->exec(p);
+ updateDisplayItem();
+ return true;
+ }
+ return QComboBox::event(event);
+}
+
+void QtTagComboBox::updateDisplayItem() {
+ QList<QAction*> tagActions = editMenu->actions();
+ QString text = "";
+ foreach(QAction* action, tagActions) {
+ if (action->isChecked()) {
+ if (text != "") {
+ text += ", ";
+ }
+ text += action->text();
+ }
+ }
+ setItemText(0, text);
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtTagComboBox.h b/Swift/QtUI/QtVCardWidget/QtTagComboBox.h
new file mode 100644
index 0000000..37a60af
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtTagComboBox.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QComboBox>
+#include <QMenu>
+#include <QStandardItem>
+#include <QStandardItemModel>
+
+namespace Swift {
+
+class QtTagComboBox : public QComboBox {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+
+ public:
+ explicit QtTagComboBox(QWidget* parent = 0);
+ ~QtTagComboBox();
+
+ bool isEditable() const;
+ void setEditable(const bool);
+
+ void addTag(const QString& id, const QString& label);
+ void setTag(const QString& id, bool value);
+ bool isTagSet(const QString& id) const;
+
+ virtual void showPopup();
+ virtual void hidePopup();
+
+ virtual bool event(QEvent* event);
+
+ private:
+ void updateDisplayItem();
+
+ private:
+ bool editable;
+ QStandardItemModel* displayModel;
+ QStandardItem* displayItem;
+ QMenu* editMenu;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
new file mode 100644
index 0000000..af17d97
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardAddressField.h"
+
+#include <QGridLayout>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardAddressField::QtVCardAddressField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address")), streetLineEdit(NULL), poboxLineEdit(NULL), addressextLineEdit(NULL), cityLineEdit(NULL), pocodeLineEdit(NULL), regionLineEdit(NULL), countryLineEdit(NULL), textFieldGridLayout(NULL), textFieldGridLayoutItem(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardAddressField::~QtVCardAddressField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardAddressField::setupContentWidgets() {
+ textFieldGridLayout = new QGridLayout();
+
+ streetLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(streetLineEdit, 0, 0, Qt::AlignVCenter);
+
+ poboxLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(poboxLineEdit, 0, 1, Qt::AlignVCenter);
+
+ addressextLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(addressextLineEdit, 1, 0, Qt::AlignVCenter);
+
+ cityLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(cityLineEdit, 2, 0, Qt::AlignVCenter);
+
+ pocodeLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(pocodeLineEdit, 2, 1, Qt::AlignVCenter);
+
+ regionLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(regionLineEdit, 3, 0, Qt::AlignVCenter);
+
+ countryLineEdit = new QtResizableLineEdit(this);
+ textFieldGridLayout->addWidget(countryLineEdit, 4, 0, Qt::AlignVCenter);
+ textFieldGridLayout->setVerticalSpacing(2);
+ getGridLayout()->addLayout(textFieldGridLayout, getGridLayout()->rowCount()-1, 2, 5, 2, Qt::AlignVCenter);
+ textFieldGridLayoutItem = getGridLayout()->itemAtPosition(getGridLayout()->rowCount()-1, 2);
+
+#if QT_VERSION >= 0x040700
+ streetLineEdit->setPlaceholderText(tr("Street"));
+ poboxLineEdit->setPlaceholderText(tr("PO Box"));
+ addressextLineEdit->setPlaceholderText(tr("Address Extension"));
+ cityLineEdit->setPlaceholderText(tr("City"));
+ pocodeLineEdit->setPlaceholderText(tr("Postal Code"));
+ regionLineEdit->setPlaceholderText(tr("Region"));
+ countryLineEdit->setPlaceholderText(tr("Country"));
+#endif
+
+ deliveryTypeLabel = new QLabel(this);
+ deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-3, 4, Qt::AlignVCenter);
+
+ domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
+ getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+
+ internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
+ getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
+
+ buttonGroup = new QButtonGroup(this);
+ buttonGroup->addButton(domesticRadioButton);
+ buttonGroup->addButton(internationalRadioButton);
+
+ setTabOrder(internationalRadioButton, getTagComboBox());
+ getTagComboBox()->addTag("postal", tr("Postal"));
+ getTagComboBox()->addTag("parcel", tr("Parcel"));
+
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+
+ textFields << streetLineEdit << poboxLineEdit << addressextLineEdit << cityLineEdit << pocodeLineEdit << regionLineEdit << countryLineEdit;
+ childWidgets << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
+}
+
+void QtVCardAddressField::customCleanup() {
+ foreach(QWidget* widget, textFields) {
+ widget->hide();
+ textFieldGridLayout->removeWidget(widget);
+ }
+ getGridLayout()->removeItem(textFieldGridLayoutItem);
+}
+
+
+
+bool QtVCardAddressField::isEmpty() const {
+ return streetLineEdit->text().isEmpty() &&
+ poboxLineEdit->text().isEmpty() &&
+ addressextLineEdit->text().isEmpty() &&
+ cityLineEdit->text().isEmpty() &&
+ pocodeLineEdit->text().isEmpty() &&
+ regionLineEdit->text().isEmpty() &&
+ countryLineEdit->text().isEmpty();
+}
+
+void QtVCardAddressField::setAddress(const VCard::Address& address) {
+ setPreferred(address.isPreferred);
+ setHome(address.isHome);
+ setWork(address.isWork);
+ getTagComboBox()->setTag("postal", address.isPostal);
+ getTagComboBox()->setTag("parcel", address.isParcel);
+ domesticRadioButton->setChecked(address.deliveryType == VCard::DomesticDelivery);
+ internationalRadioButton->setChecked(address.deliveryType == VCard::InternationalDelivery);
+ streetLineEdit->setText(P2QSTRING(address.street));
+ poboxLineEdit->setText(P2QSTRING(address.poBox));
+ addressextLineEdit->setText(P2QSTRING(address.addressExtension));
+ cityLineEdit->setText(P2QSTRING(address.locality));
+ pocodeLineEdit->setText(P2QSTRING(address.postalCode));
+ regionLineEdit->setText(P2QSTRING(address.region));
+ countryLineEdit->setText(P2QSTRING(address.country));
+}
+
+VCard::Address QtVCardAddressField::getAddress() const {
+ VCard::Address address;
+ address.isPreferred = getPreferred();
+ address.isHome = getHome();
+ address.isWork = getWork();
+ address.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
+ address.isPostal = getTagComboBox()->isTagSet("postal");
+ address.isParcel = getTagComboBox()->isTagSet("parcel");
+ address.street = Q2PSTRING(streetLineEdit->text());
+ address.poBox = Q2PSTRING(poboxLineEdit->text());
+ address.addressExtension = Q2PSTRING(addressextLineEdit->text());
+ address.locality = Q2PSTRING(cityLineEdit->text());
+ address.postalCode = Q2PSTRING(pocodeLineEdit->text());
+ address.region = Q2PSTRING(regionLineEdit->text());
+ address.country = Q2PSTRING(countryLineEdit->text());
+ return address;
+}
+
+void QtVCardAddressField::handleEditibleChanged(bool isEditable) {
+ assert(streetLineEdit);
+ assert(poboxLineEdit);
+ assert(addressextLineEdit);
+ assert(cityLineEdit);
+ assert(pocodeLineEdit);
+ assert(regionLineEdit);
+ assert(countryLineEdit);
+ assert(deliveryTypeLabel);
+ assert(domesticRadioButton);
+ assert(internationalRadioButton);
+
+ streetLineEdit->setEditable(isEditable);
+ poboxLineEdit->setEditable(isEditable);
+ addressextLineEdit->setEditable(isEditable);
+ cityLineEdit->setEditable(isEditable);
+ pocodeLineEdit->setEditable(isEditable);
+ regionLineEdit->setEditable(isEditable);
+ countryLineEdit->setEditable(isEditable);
+
+ deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
+ deliveryTypeLabel->setVisible(!isEditable);
+
+ domesticRadioButton->setVisible(isEditable);
+ internationalRadioButton->setVisible(isEditable);
+
+ foreach (QWidget* widget, textFields) {
+ QtResizableLineEdit* lineEdit;
+ if ((lineEdit = dynamic_cast<QtResizableLineEdit*>(widget))) {
+ lineEdit->setVisible(isEditable ? true : !lineEdit->text().isEmpty());
+ lineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+ }
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h
new file mode 100644
index 0000000..5a1256a
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include <QButtonGroup>
+#include <QRadioButton>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+#include "QtVCardHomeWork.h"
+
+namespace Swift {
+
+class QtVCardAddressField : public QtVCardGeneralField, public QtVCardHomeWork {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Address", UNLIMITED_INSTANCES, QtVCardAddressField)
+
+ QtVCardAddressField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardAddressField();
+
+ virtual bool isEmpty() const;
+
+ void setAddress(const VCard::Address& address);
+ VCard::Address getAddress() const;
+
+ protected:
+ virtual void setupContentWidgets();
+ virtual void customCleanup();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QList<QWidget*> textFields;
+ QtResizableLineEdit* streetLineEdit;
+ QtResizableLineEdit* poboxLineEdit;
+ QtResizableLineEdit* addressextLineEdit;
+ QtResizableLineEdit* cityLineEdit;
+ QtResizableLineEdit* pocodeLineEdit;
+ QtResizableLineEdit* regionLineEdit;
+ QtResizableLineEdit* countryLineEdit;
+ QGridLayout* textFieldGridLayout;
+ QLayoutItem* textFieldGridLayoutItem;
+
+ QLabel* deliveryTypeLabel;
+ QRadioButton* domesticRadioButton;
+ QRadioButton* internationalRadioButton;
+ QButtonGroup* buttonGroup;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp
new file mode 100644
index 0000000..ba3d25f
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardAddressLabelField.h"
+
+#include <QGridLayout>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardAddressLabelField::QtVCardAddressLabelField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Address Label")), addressLabelPlainTextEdit(NULL), deliveryTypeLabel(NULL), domesticRadioButton(NULL), internationalRadioButton(NULL), buttonGroup(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardAddressLabelField::~QtVCardAddressLabelField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardAddressLabelField::setupContentWidgets() {
+ addressLabelPlainTextEdit = new QPlainTextEdit(this);
+ addressLabelPlainTextEdit->setTabChangesFocus(true);
+ getGridLayout()->addWidget(addressLabelPlainTextEdit, getGridLayout()->rowCount()-1, 2, 3, 2, Qt::AlignVCenter);
+
+ deliveryTypeLabel = new QLabel(this);
+ deliveryTypeLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ getGridLayout()->addWidget(deliveryTypeLabel, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+
+ domesticRadioButton = new QRadioButton(tr("Domestic Delivery"), this);
+ getGridLayout()->addWidget(domesticRadioButton, getGridLayout()->rowCount()-2, 4, Qt::AlignVCenter);
+
+ internationalRadioButton = new QRadioButton(tr("International Delivery"), this);
+ getGridLayout()->addWidget(internationalRadioButton, getGridLayout()->rowCount()-1, 4, Qt::AlignVCenter);
+
+ buttonGroup = new QButtonGroup(this);
+ buttonGroup->addButton(domesticRadioButton);
+ buttonGroup->addButton(internationalRadioButton);
+
+ setTabOrder(internationalRadioButton, getTagComboBox());
+ getTagComboBox()->addTag("postal", tr("Postal"));
+ getTagComboBox()->addTag("parcel", tr("Parcel"));
+
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ deliveryTypeLabel->hide();
+ childWidgets << addressLabelPlainTextEdit << deliveryTypeLabel << domesticRadioButton << internationalRadioButton;
+}
+
+bool QtVCardAddressLabelField::isEmpty() const {
+ return addressLabelPlainTextEdit->toPlainText().isEmpty();
+}
+
+void QtVCardAddressLabelField::setAddressLabel(const VCard::AddressLabel& addressLabel) {
+ setPreferred(addressLabel.isPreferred);
+ setHome(addressLabel.isHome);
+ setWork(addressLabel.isWork);
+ getTagComboBox()->setTag("postal", addressLabel.isPostal);
+ getTagComboBox()->setTag("parcel", addressLabel.isParcel);
+ domesticRadioButton->setChecked(addressLabel.deliveryType == VCard::DomesticDelivery);
+ internationalRadioButton->setChecked(addressLabel.deliveryType == VCard::InternationalDelivery);
+ std::string joinedLines = boost::algorithm::join(addressLabel.lines, "\n");
+ addressLabelPlainTextEdit->setPlainText(P2QSTRING(joinedLines));
+}
+
+VCard::AddressLabel QtVCardAddressLabelField::getAddressLabel() const {
+ VCard::AddressLabel addressLabel;
+ addressLabel.isPreferred = getPreferred();
+ addressLabel.isHome = getHome();
+ addressLabel.isWork = getWork();
+ addressLabel.deliveryType = domesticRadioButton->isChecked() ? VCard::DomesticDelivery : (internationalRadioButton->isChecked() ? VCard::InternationalDelivery : VCard::None);
+ addressLabel.isPostal = getTagComboBox()->isTagSet("postal");
+ addressLabel.isParcel = getTagComboBox()->isTagSet("parcel");
+
+ std::string lines = Q2PSTRING(addressLabelPlainTextEdit->toPlainText());
+ boost::split(addressLabel.lines, lines, boost::is_any_of("\n"));
+ return addressLabel;
+}
+
+void QtVCardAddressLabelField::handleEditibleChanged(bool isEditable) {
+ assert(addressLabelPlainTextEdit);
+ assert(deliveryTypeLabel);
+ assert(domesticRadioButton);
+ assert(internationalRadioButton);
+
+ addressLabelPlainTextEdit->setReadOnly(!isEditable);
+ addressLabelPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
+
+ deliveryTypeLabel->setText(buttonGroup->checkedButton() == 0 ? "" : buttonGroup->checkedButton()->text());
+ deliveryTypeLabel->setVisible(!isEditable);
+
+ domesticRadioButton->setVisible(isEditable);
+ internationalRadioButton->setVisible(isEditable);
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h
new file mode 100644
index 0000000..a665d31
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QButtonGroup>
+#include <QPlainTextEdit>
+#include <QRadioButton>
+
+#include <Swiften/Elements/VCard.h>
+
+#include <Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h>
+
+namespace Swift {
+
+class QtVCardAddressLabelField : public QtVCardGeneralField, public QtVCardHomeWork {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Address Label", UNLIMITED_INSTANCES, QtVCardAddressLabelField)
+
+ QtVCardAddressLabelField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardAddressLabelField();
+
+ virtual bool isEmpty() const;
+
+ void setAddressLabel(const VCard::AddressLabel& addressLabel);
+ VCard::AddressLabel getAddressLabel() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QPlainTextEdit* addressLabelPlainTextEdit;
+
+ QLabel* deliveryTypeLabel;
+ QRadioButton* domesticRadioButton;
+ QRadioButton* internationalRadioButton;
+ QButtonGroup* buttonGroup;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp
new file mode 100644
index 0000000..7b0d02e
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardBirthdayField.h"
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardBirthdayField::QtVCardBirthdayField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Birthday"), false, false), birthdayLabel(NULL), birthdayDateEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardBirthdayField::~QtVCardBirthdayField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardBirthdayField::setupContentWidgets() {
+ birthdayLabel = new QLabel(this);
+ birthdayLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ birthdayDateEdit = new QDateEdit(this);
+ birthdayDateEdit->setCalendarPopup(true);
+
+ QHBoxLayout* birthdayLayout = new QHBoxLayout();
+ birthdayLayout->addWidget(birthdayLabel);
+ birthdayLayout->addWidget(birthdayDateEdit);
+
+ getGridLayout()->addLayout(birthdayLayout, getGridLayout()->rowCount()-1, 2, Qt::AlignVCenter);
+
+ getTagComboBox()->hide();
+ birthdayLabel->hide();
+ childWidgets << birthdayLabel << birthdayDateEdit;
+}
+
+bool QtVCardBirthdayField::isEmpty() const {
+ return false;
+}
+
+void QtVCardBirthdayField::setBirthday(const boost::posix_time::ptime& birthday) {
+ birthdayDateEdit->setDate(B2QDATE(birthday).date());
+}
+
+boost::posix_time::ptime QtVCardBirthdayField::getBirthday() const {
+ return boost::posix_time::from_time_t(QDateTime(birthdayDateEdit->date()).toTime_t());
+}
+
+void QtVCardBirthdayField::handleEditibleChanged(bool isEditable) {
+ birthdayLabel->setText(birthdayDateEdit->date().toString(Qt::DefaultLocaleLongDate));
+ birthdayDateEdit->setVisible(isEditable);
+ birthdayLabel->setVisible(!isEditable);
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h
new file mode 100644
index 0000000..4be6e27
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QDateEdit>
+#include <Swiften/Elements/VCard.h>
+
+#include "QtCloseButton.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardBirthdayField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Birthday", 1, QtVCardBirthdayField)
+
+ QtVCardBirthdayField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardBirthdayField();
+
+ virtual bool isEmpty() const;
+
+ void setBirthday(const boost::posix_time::ptime& addressLabel);
+ boost::posix_time::ptime getBirthday() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QLabel* birthdayLabel;
+ QDateEdit* birthdayDateEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp
new file mode 100644
index 0000000..183e64d
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardDescriptionField.h"
+
+#include <boost/algorithm/string.hpp>
+#include <QFontMetrics>
+#include <QGridLayout>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardDescriptionField::QtVCardDescriptionField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Description"), false, false), descriptionPlainTextEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardDescriptionField::~QtVCardDescriptionField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardDescriptionField::setupContentWidgets() {
+ descriptionPlainTextEdit = new QPlainTextEdit(this);
+ descriptionPlainTextEdit->setMinimumHeight(70);
+ getGridLayout()->addWidget(descriptionPlainTextEdit, getGridLayout()->rowCount()-1, 2, 2, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << descriptionPlainTextEdit;
+}
+
+bool QtVCardDescriptionField::isEmpty() const {
+ return descriptionPlainTextEdit->toPlainText().isEmpty();
+}
+
+void QtVCardDescriptionField::setDescription(const std::string& description) {
+ descriptionPlainTextEdit->setPlainText(P2QSTRING(description));
+}
+
+std::string QtVCardDescriptionField::getDescription() const {
+ return Q2PSTRING(descriptionPlainTextEdit->toPlainText());
+}
+
+void QtVCardDescriptionField::handleEditibleChanged(bool isEditable) {
+ assert(descriptionPlainTextEdit);
+
+ if (isEditable) {
+ descriptionPlainTextEdit->setMinimumHeight(70);
+ } else {
+ QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont());
+ QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999);
+ QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A");
+ int left, top, right, bottom;
+ getContentsMargins(&left, &top, &right, &bottom);
+ int height = boundingRect.height() + top + bottom + inputMetrics.height();
+ descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height);
+ }
+ descriptionPlainTextEdit->setReadOnly(!isEditable);
+ descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }");
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h
new file mode 100644
index 0000000..3b1b3d9
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include <QPlainTextEdit>
+
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardDescriptionField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Description", 1, QtVCardDescriptionField)
+
+ QtVCardDescriptionField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardDescriptionField();
+
+ virtual bool isEmpty() const;
+
+ void setDescription(const std::string& description);
+ std::string getDescription() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QPlainTextEdit* descriptionPlainTextEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h b/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h
new file mode 100644
index 0000000..168c01b
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QGridLayout>
+#include <QObject>
+#include <QString>
+#include <typeinfo>
+
+#define GENERIC_QT_VCARD_FIELD_INFO(MENU_NAME, ALLOWED_INSTANCES, FIELD_CLASS) \
+ class FieldInfo : public QtVCardFieldInfo { \
+ public: \
+ virtual ~FieldInfo() { \
+ } \
+ \
+ virtual QString getMenuName() const { \
+ return QObject::tr(MENU_NAME); \
+ } \
+ \
+ virtual int getAllowedInstances() const { \
+ return ALLOWED_INSTANCES; \
+ } \
+ \
+ virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const { \
+ return new FIELD_CLASS(parent, layout, editable); \
+ } \
+ \
+ virtual bool testInstance(QWidget* widget) const { \
+ return dynamic_cast<FIELD_CLASS*>(widget) != 0; \
+ } \
+ };
+
+class QWidget;
+
+namespace Swift {
+
+ class QtVCardFieldInfo {
+ public:
+ static const int UNLIMITED_INSTANCES = -1;
+
+ virtual ~QtVCardFieldInfo() {
+ }
+ virtual QString getMenuName() const = 0;
+ virtual int getAllowedInstances() const = 0;
+ virtual QWidget* createFieldInstance(QWidget* parent, QGridLayout* layout, bool editable) const = 0;
+ virtual bool testInstance(QWidget*) const = 0;
+ };
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
new file mode 100644
index 0000000..155bd4f
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
+
+#include <cassert>
+
+#include <QHBoxLayout>
+#include <QToolTip>
+
+namespace Swift {
+
+QtVCardGeneralField::QtVCardGeneralField(QWidget* parent, QGridLayout* layout, bool editable, int row, QString label, bool preferrable, bool taggable) :
+ QWidget(parent), editable(editable), preferrable(preferrable), starVisible(false), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label),
+ tagComboBox(0), tagLabel(NULL), closeButton(0) {
+}
+
+QtVCardGeneralField::~QtVCardGeneralField() {
+
+}
+
+void QtVCardGeneralField::initialize() {
+ if (preferrable) {
+ preferredCheckBox = new QCheckBox(this);
+ preferredCheckBox->setToolTip(tr("Stars can be used to mark preferred contact details."));
+ preferredCheckBox->setStyleSheet(
+ "QCheckBox::indicator { width: 18px; height: 18px; }"
+ "QCheckBox::indicator:checked { image: url(:/icons/star-checked.png); }"
+ "QCheckBox::indicator:unchecked { image: url(:/icons/star-unchecked); }"
+ );
+ layout->addWidget(preferredCheckBox, row, 0, Qt::AlignVCenter);
+ childWidgets << preferredCheckBox;
+ connect(preferredCheckBox, SIGNAL(stateChanged(int)), SLOT(handlePreferredStarStateChanged(int)));
+ }
+ label = new QLabel(this);
+ label->setText(labelText);
+ layout->addWidget(label, row, 1, Qt::AlignVCenter | Qt::AlignRight);
+
+ tagLabel = new QLabel(this);
+ tagLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+
+ tagComboBox = new QtTagComboBox(this);
+ closeButton = new QtCloseButton(this);
+ connect(closeButton, SIGNAL(clicked()), SLOT(handleCloseButtonClicked()));
+
+ QHBoxLayout* tagLayout = new QHBoxLayout();
+ tagLayout->addWidget(tagLabel);
+ tagLayout->addWidget(tagComboBox);
+
+ setupContentWidgets();
+ layout->addLayout(tagLayout, row, 4, Qt::AlignTop);
+ layout->addWidget(closeButton, row, 5, Qt::AlignCenter);
+ closeButton->resize(12, 12);
+ tagLabel->hide();
+
+ childWidgets << label << tagComboBox << tagLabel << closeButton;
+ setEditable(editable);
+}
+
+bool QtVCardGeneralField::isEditable() const {
+ return editable;
+}
+
+void QtVCardGeneralField::setEditable(bool editable) {
+ assert(tagComboBox);
+ assert(closeButton);
+
+ this->editable = editable;
+ if (taggable) {
+ tagLabel->setText(tagComboBox->itemText(0));
+ tagComboBox->setVisible(editable);
+ tagLabel->setVisible(!editable);
+ } else {
+ tagLabel->hide();
+ tagComboBox->hide();
+ }
+ closeButton->setVisible(editable);
+ updatePreferredStarVisibility();
+ editableChanged(this->editable);
+}
+
+void QtVCardGeneralField::setStarVisible(const bool isVisible) {
+ starVisible = isVisible;
+ updatePreferredStarVisibility();
+}
+
+bool QtVCardGeneralField::getStarVisible() const {
+ return starVisible;
+}
+
+void QtVCardGeneralField::setPreferred(const bool preferred) {
+ if (preferredCheckBox) preferredCheckBox->setChecked(preferred);
+ updatePreferredStarVisibility();
+}
+
+bool QtVCardGeneralField::getPreferred() const {
+ return preferredCheckBox ? preferredCheckBox->isChecked() : false;
+}
+
+void QtVCardGeneralField::customCleanup() {
+}
+
+QtTagComboBox* QtVCardGeneralField::getTagComboBox() const {
+ return tagComboBox;
+}
+
+QGridLayout* QtVCardGeneralField::getGridLayout() const {
+ return layout;
+}
+
+void QtVCardGeneralField::handleCloseButtonClicked() {
+ customCleanup();
+ foreach(QWidget* widget, childWidgets) {
+ widget->hide();
+ layout->removeWidget(widget);
+ }
+ deleteField(this);
+}
+
+void QtVCardGeneralField::handlePreferredStarStateChanged(int state) {
+ if (state == Qt::Checked) {
+ QToolTip::showText(QCursor::pos(), tr("Marked as your preferred %1. Click again to undo.").arg(labelText));
+ }
+}
+
+void QtVCardGeneralField::updatePreferredStarVisibility() {
+ if (preferredCheckBox) {
+ bool showStar = false;
+ if (editable) {
+ if (starVisible) {
+ showStar = true;
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ preferredCheckBox->setVisible(showStar);
+ preferredCheckBox->setEnabled(editable);
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
new file mode 100644
index 0000000..4f4cccd
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QCheckBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QWidget>
+
+#include "QtCloseButton.h"
+#include "QtTagComboBox.h"
+
+namespace Swift {
+
+/*
+ * covers features like:
+ * - preffered (star ceckbox)
+ * - combo check boxh
+ * - label
+ * - remove button
+ */
+class QtVCardGeneralField : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable NOTIFY editableChanged)
+ Q_PROPERTY(bool empty READ isEmpty)
+
+ public:
+ explicit QtVCardGeneralField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false, int row = 0, QString label = QString(),
+ bool preferrable = true, bool taggable = true);
+ virtual ~QtVCardGeneralField();
+
+ void initialize();
+
+ virtual bool isEditable() const;
+ virtual void setEditable(bool);
+
+ virtual bool isEmpty() const = 0;
+
+ void setStarVisible(const bool isVisible);
+ bool getStarVisible() const;
+
+ void setPreferred(const bool preferred);
+ bool getPreferred() const;
+
+ protected:
+ virtual void setupContentWidgets() = 0;
+ virtual void customCleanup();
+
+ QtTagComboBox* getTagComboBox() const;
+ QGridLayout* getGridLayout() const;
+
+ signals:
+ void editableChanged(bool);
+ void deleteField(QtVCardGeneralField*);
+
+ public slots:
+ void handleCloseButtonClicked();
+ void handlePreferredStarStateChanged(int statte);
+
+ protected:
+ QList<QWidget*> childWidgets;
+
+ private:
+ void updatePreferredStarVisibility();
+
+ private:
+ bool editable;
+ bool preferrable;
+ bool starVisible;
+ bool taggable;
+ QGridLayout* layout;
+ int row;
+ QCheckBox* preferredCheckBox;
+ QLabel* label;
+ QString labelText;
+ QtTagComboBox* tagComboBox;
+ QLabel* tagLabel;
+ QtCloseButton* closeButton;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp
new file mode 100644
index 0000000..3119a80
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardHomeWork.h"
+
+namespace Swift {
+
+QtVCardHomeWork::QtVCardHomeWork() : tagComboBox(0) {
+}
+
+QtVCardHomeWork::~QtVCardHomeWork() {
+}
+
+void QtVCardHomeWork::setTagComboBox(QtTagComboBox* tagBox) {
+ tagComboBox = tagBox;
+ tagComboBox->addTag("home", QObject::tr("Home"));
+ tagComboBox->addTag("work", QObject::tr("Work"));
+}
+
+void QtVCardHomeWork::setHome(const bool home) {
+ tagComboBox->setTag("home", home);
+}
+
+bool QtVCardHomeWork::getHome() const {
+ return tagComboBox->isTagSet("home");
+}
+
+void QtVCardHomeWork::setWork(const bool work) {
+ tagComboBox->setTag("work", work);
+}
+
+bool QtVCardHomeWork::getWork() const {
+ return tagComboBox->isTagSet("work");
+}
+
+}
+
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h
new file mode 100644
index 0000000..768d984
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardHomeWork.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QObject>
+
+#include "QtTagComboBox.h"
+
+namespace Swift {
+
+class QtVCardHomeWork {
+ public:
+ QtVCardHomeWork();
+ virtual ~QtVCardHomeWork();
+
+ void setTagComboBox(QtTagComboBox* tagBox);
+
+ void setHome(const bool home);
+ bool getHome() const;
+ void setWork(const bool work);
+ bool getWork() const;
+
+ private:
+ QtTagComboBox* tagComboBox;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
new file mode 100644
index 0000000..bae9771
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardInternetEMailField.h"
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QTextDocument>
+#include <Swiften/Base/Log.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+
+namespace Swift {
+
+QtVCardInternetEMailField::QtVCardInternetEMailField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("E-Mail")), emailLineEdit(NULL), emailLabel(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardInternetEMailField::~QtVCardInternetEMailField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardInternetEMailField::setupContentWidgets() {
+ emailLabel = new QLabel(this);
+ emailLabel->setOpenExternalLinks(true);
+ emailLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ emailLineEdit = new QtResizableLineEdit(this);
+#if QT_VERSION >= 0x040700
+ emailLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
+#endif
+ QHBoxLayout* emailLayout = new QHBoxLayout();
+ emailLayout->addWidget(emailLabel);
+ emailLayout->addWidget(emailLineEdit);
+ getGridLayout()->addLayout(emailLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ setTabOrder(emailLineEdit, getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ emailLabel->hide();
+ childWidgets << emailLabel << emailLineEdit;
+}
+
+bool QtVCardInternetEMailField::isEmpty() const {
+ return emailLineEdit->text().isEmpty();
+}
+
+void QtVCardInternetEMailField::setInternetEMailAddress(const VCard::EMailAddress& address) {
+ assert(address.isInternet);
+ setPreferred(address.isPreferred);
+ setHome(address.isHome);
+ setWork(address.isWork);
+ emailLineEdit->setText(P2QSTRING(address.address));
+}
+
+VCard::EMailAddress QtVCardInternetEMailField::getInternetEMailAddress() const {
+ VCard::EMailAddress address;
+ address.isInternet = true;
+ address.isPreferred = getPreferred();
+ address.isHome = getHome();
+ address.isWork = getWork();
+ address.address = Q2PSTRING(emailLineEdit->text());
+ return address;
+}
+
+void QtVCardInternetEMailField::handleEditibleChanged(bool isEditable) {
+ assert(emailLineEdit);
+ assert(emailLabel);
+
+ if (isEditable) {
+ emailLineEdit->show();
+ emailLabel->hide();
+ } else {
+ emailLineEdit->hide();
+ emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(QtUtilities::htmlEscape(emailLineEdit->text())));
+ emailLabel->show();
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h
new file mode 100644
index 0000000..3f8a27f
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+#include "QtVCardHomeWork.h"
+
+namespace Swift {
+
+class QtVCardInternetEMailField : public QtVCardGeneralField, public QtVCardHomeWork {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("E-Mail", UNLIMITED_INSTANCES, QtVCardInternetEMailField)
+
+ QtVCardInternetEMailField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardInternetEMailField();
+
+ virtual bool isEmpty() const;
+
+ void setInternetEMailAddress(const VCard::EMailAddress& address);
+ VCard::EMailAddress getInternetEMailAddress() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QtResizableLineEdit* emailLineEdit;
+ QLabel* emailLabel;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp
new file mode 100644
index 0000000..28a4438
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardJIDField.h"
+
+#include <QGridLayout>
+#include <QTextDocument>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+
+namespace Swift {
+
+QtVCardJIDField::QtVCardJIDField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("JID"), false, false), jidLabel(NULL), jidLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardJIDField::~QtVCardJIDField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardJIDField::setupContentWidgets() {
+ jidLabel = new QLabel(this);
+ jidLabel->setOpenExternalLinks(true);
+ jidLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ jidLineEdit = new QtResizableLineEdit(this);
+#if QT_VERSION >= 0x040700
+ jidLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
+#endif
+ QHBoxLayout* jidLayout = new QHBoxLayout();
+ jidLayout->addWidget(jidLabel);
+ jidLayout->addWidget(jidLineEdit);
+ getGridLayout()->addLayout(jidLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+
+ jidLabel->hide();
+ getTagComboBox()->hide();
+
+ childWidgets << jidLabel << jidLineEdit;
+}
+
+bool QtVCardJIDField::isEmpty() const {
+ return jidLineEdit->text().isEmpty();
+}
+
+void QtVCardJIDField::setJID(const JID& jid) {
+ std::string jidStr = jid.toBare().toString();
+ jidLineEdit->setText(P2QSTRING(jidStr));
+}
+
+JID QtVCardJIDField::getJID() const {
+ return JID(Q2PSTRING(jidLineEdit->text()));
+}
+
+void QtVCardJIDField::handleEditibleChanged(bool isEditable) {
+ assert(jidLineEdit);
+ assert(jidLabel);
+
+ if (isEditable) {
+ jidLineEdit->show();
+ jidLabel->hide();
+ } else {
+ jidLineEdit->hide();
+ jidLabel->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(QtUtilities::htmlEscape(jidLineEdit->text())));
+ jidLabel->show();
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h
new file mode 100644
index 0000000..016bcf8
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardJIDField.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardJIDField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("JID", UNLIMITED_INSTANCES, QtVCardJIDField)
+
+ QtVCardJIDField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardJIDField();
+
+ virtual bool isEmpty() const;
+
+ void setJID(const JID& jid);
+ JID getJID() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QLabel* jidLabel;
+ QtResizableLineEdit* jidLineEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
new file mode 100644
index 0000000..d5a7262
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h>
+
+#include <boost/algorithm/string.hpp>
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QHeaderView>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardOrganizationField::QtVCardOrganizationField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Organisation"), false, false), organizationLabel(NULL), organizationLineEdit(NULL), unitsTreeWidget(NULL), itemDelegate(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardOrganizationField::~QtVCardOrganizationField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardOrganizationField::setupContentWidgets() {
+ organizationLabel = new QLabel(this);
+ organizationLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
+ organizationLineEdit = new QtResizableLineEdit(this);
+ QHBoxLayout* organizationLayout = new QHBoxLayout();
+ organizationLayout->addWidget(organizationLabel);
+ organizationLayout->addWidget(organizationLineEdit);
+
+ getGridLayout()->addLayout(organizationLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+
+ itemDelegate = new QtRemovableItemDelegate(style());
+
+ unitsTreeWidget = new QTreeWidget(this);
+ connect(unitsTreeWidget->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), SLOT(handleRowsRemoved(QModelIndex,int,int)));
+ unitsTreeWidget->setColumnCount(2);
+ unitsTreeWidget->header()->setStretchLastSection(false);
+ unitsTreeWidget->header()->resizeSection(1, itemDelegate->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+
+#if QT_VERSION >= 0x050000
+ unitsTreeWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch);
+#else
+ unitsTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
+#endif
+
+ unitsTreeWidget->setHeaderHidden(true);
+ unitsTreeWidget->setRootIsDecorated(false);
+ unitsTreeWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
+ unitsTreeWidget->setItemDelegateForColumn(1, itemDelegate);
+ connect(unitsTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), SLOT(handleItemChanged(QTreeWidgetItem*,int)));
+ getGridLayout()->addWidget(unitsTreeWidget, getGridLayout()->rowCount()-1, 4, 2, 1);
+
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+
+ getTagComboBox()->hide();
+ organizationLabel->hide();
+ childWidgets << organizationLabel << organizationLineEdit << unitsTreeWidget;
+}
+
+bool QtVCardOrganizationField::isEmpty() const {
+ return organizationLineEdit->text().isEmpty() && unitsTreeWidget->model()->rowCount() != 0;
+}
+
+void QtVCardOrganizationField::setOrganization(const VCard::Organization& organization) {
+ organizationLineEdit->setText(P2QSTRING(organization.name));
+ unitsTreeWidget->clear();
+ foreach(std::string unit, organization.units) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(P2QSTRING(unit)) << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+ }
+
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+}
+
+VCard::Organization QtVCardOrganizationField::getOrganization() const {
+ VCard::Organization organization;
+ organization.name = Q2PSTRING(organizationLineEdit->text());
+ for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
+ if (!row->text(0).isEmpty()) {
+ organization.units.push_back(Q2PSTRING(row->text(0)));
+ }
+ }
+
+ return organization;
+}
+
+void QtVCardOrganizationField::handleEditibleChanged(bool isEditable) {
+ assert(organizationLineEdit);
+ assert(unitsTreeWidget);
+
+ organizationLineEdit->setVisible(isEditable);
+ organizationLabel->setVisible(!isEditable);
+
+ if (!isEditable) {
+ QString label;
+ for(int i=0; i < unitsTreeWidget->topLevelItemCount(); ++i) {
+ QTreeWidgetItem* row = unitsTreeWidget->topLevelItem(i);
+ if (!row->text(0).isEmpty()) {
+ label += row->text(0) + ", ";
+ }
+ }
+ label += organizationLineEdit->text();
+ organizationLabel->setText(label);
+ }
+ unitsTreeWidget->setVisible(isEditable);
+}
+
+void QtVCardOrganizationField::handleItemChanged(QTreeWidgetItem *, int) {
+ guaranteeEmptyRow();
+}
+
+void QtVCardOrganizationField::handleRowsRemoved(const QModelIndex&, int, int) {
+ guaranteeEmptyRow();
+}
+
+void QtVCardOrganizationField::guaranteeEmptyRow() {
+ bool hasEmptyRow = false;
+ QList<QTreeWidgetItem*> rows = unitsTreeWidget->findItems("", Qt::MatchFixedString);
+ foreach(QTreeWidgetItem* row, rows) {
+ if (row->text(0).isEmpty()) {
+ hasEmptyRow = true;
+ }
+ }
+
+ if (!hasEmptyRow) {
+ QTreeWidgetItem* item = new QTreeWidgetItem(QStringList("") << "");
+ item->setFlags(item->flags() | Qt::ItemIsEditable);
+ unitsTreeWidget->addTopLevelItem(item);
+ unitsTreeWidget->setCurrentItem(item);
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h
new file mode 100644
index 0000000..47868a7
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QTreeWidget>
+
+#include <Swiften/Elements/VCard.h>
+
+#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h>
+#include <Swift/QtUI/QtVCardWidget/QtResizableLineEdit.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardFieldInfo.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
+
+namespace Swift {
+
+class QtVCardOrganizationField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Organization", UNLIMITED_INSTANCES, QtVCardOrganizationField)
+
+ QtVCardOrganizationField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardOrganizationField();
+
+ virtual bool isEmpty() const;
+
+ void setOrganization(const VCard::Organization& organization);
+ VCard::Organization getOrganization() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private slots:
+ void handleItemChanged(QTreeWidgetItem*, int);
+ void handleRowsRemoved(const QModelIndex&, int, int);
+
+ private:
+ void guaranteeEmptyRow();
+
+ private:
+ QLabel* organizationLabel;
+ QtResizableLineEdit* organizationLineEdit;
+ QTreeWidget* unitsTreeWidget;
+ QtRemovableItemDelegate* itemDelegate;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
new file mode 100644
index 0000000..b29171f
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h>
+
+#include <Swift/QtUI/QtVCardWidget/ui_QtVCardPhotoAndNameFields.h>
+
+#include <QMenu>
+
+namespace Swift {
+
+QtVCardPhotoAndNameFields::QtVCardPhotoAndNameFields(QWidget* parent) :
+ QWidget(parent),
+ ui(new Ui::QtVCardPhotoAndNameFields) {
+ ui->setupUi(this);
+ ui->lineEditPREFIX->hide();
+ ui->lineEditMIDDLE->hide();
+ ui->lineEditSUFFIX->hide();
+ ui->lineEditFN->hide();
+ ui->lineEditNICKNAME->hide();
+ ui->labelFULLNAME->hide();
+
+#if QT_VERSION >= 0x040700
+ ui->lineEditFN->setPlaceholderText(tr("Formatted Name"));
+ ui->lineEditNICKNAME->setPlaceholderText(tr("Nickname"));
+ ui->lineEditPREFIX->setPlaceholderText(tr("Prefix"));
+ ui->lineEditGIVEN->setPlaceholderText(tr("Given Name"));
+ ui->lineEditMIDDLE->setPlaceholderText(tr("Middle Name"));
+ ui->lineEditFAMILY->setPlaceholderText(tr("Last Name"));
+ ui->lineEditSUFFIX->setPlaceholderText(tr("Suffix"));
+#endif
+
+ setEditable(false);
+}
+
+QtVCardPhotoAndNameFields::~QtVCardPhotoAndNameFields() {
+ delete ui;
+}
+
+bool QtVCardPhotoAndNameFields::isEditable() const {
+ return editable;
+}
+
+void QtVCardPhotoAndNameFields::setEditable(bool editable) {
+ this->editable = editable;
+
+ ui->avatarWidget->setEditable(editable);
+ ui->lineEditFN->setVisible(editable ? true : !ui->lineEditFN->text().isEmpty());
+ ui->lineEditFN->setEditable(editable);
+ ui->lineEditFN->setStyleSheet(editable ? "" : "QLineEdit {border: none; background-color: transparent;}");
+
+ ui->lineEditNICKNAME->setVisible(editable ? true : !ui->lineEditNICKNAME->text().isEmpty());
+ ui->lineEditNICKNAME->setEditable(editable);
+ ui->lineEditNICKNAME->setStyleSheet(editable ? "" : "QLineEdit {border: none; background-color: transparent;}");
+
+ // prefix given middle last suffix
+ ui->lineEditPREFIX->setVisible(editable);
+ ui->lineEditGIVEN->setVisible(editable);
+ ui->lineEditMIDDLE->setVisible(editable);
+ ui->lineEditFAMILY->setVisible(editable);
+ ui->lineEditSUFFIX->setVisible(editable);
+ ui->labelFULLNAME->setVisible(!editable);
+
+ QStringList fullname;
+ fullname << ui->lineEditPREFIX->text() << ui->lineEditGIVEN->text() << ui->lineEditMIDDLE->text();
+ fullname << ui->lineEditFAMILY->text() << ui->lineEditSUFFIX->text();
+ for (QStringList::iterator i = fullname.begin(); i != fullname.end(); i++) {
+ *i = i->trimmed();
+ }
+ ui->labelFULLNAME->setText(fullname.join(" "));
+}
+
+void QtVCardPhotoAndNameFields::setAvatar(const ByteArray &data, const std::string &type) {
+ ui->avatarWidget->setAvatar(data, type);
+}
+
+ByteArray QtVCardPhotoAndNameFields::getAvatarData() const {
+ return ui->avatarWidget->getAvatarData();
+}
+
+std::string QtVCardPhotoAndNameFields::getAvatarType() const {
+ return ui->avatarWidget->getAvatarType();
+}
+
+void QtVCardPhotoAndNameFields::setFormattedName(const QString formattedName) {
+ ui->lineEditFN->setText(formattedName);
+}
+
+QString QtVCardPhotoAndNameFields::getFormattedName() const {
+ return ui->lineEditFN->text();
+}
+
+void QtVCardPhotoAndNameFields::setNickname(const QString nickname) {
+ ui->lineEditNICKNAME->setText(nickname);
+}
+
+QString QtVCardPhotoAndNameFields::getNickname() const {
+ return ui->lineEditNICKNAME->text();
+}
+
+void QtVCardPhotoAndNameFields::setPrefix(const QString prefix) {
+ ui->lineEditPREFIX->setText(prefix);
+}
+
+QString QtVCardPhotoAndNameFields::getPrefix() const {
+ return ui->lineEditPREFIX->text();
+}
+
+void QtVCardPhotoAndNameFields::setGivenName(const QString givenName) {
+ ui->lineEditGIVEN->setText(givenName);
+}
+
+QString QtVCardPhotoAndNameFields::getGivenName() const {
+ return ui->lineEditGIVEN->text();
+}
+
+void QtVCardPhotoAndNameFields::setMiddleName(const QString middleName) {
+ ui->lineEditMIDDLE->setText(middleName);
+}
+
+QString QtVCardPhotoAndNameFields::getMiddleName() const {
+ return ui->lineEditMIDDLE->text();
+}
+
+void QtVCardPhotoAndNameFields::setFamilyName(const QString familyName) {
+ ui->lineEditFAMILY->setText(familyName);
+}
+
+QString QtVCardPhotoAndNameFields::getFamilyName() const {
+ return ui->lineEditFAMILY->text();
+}
+
+void QtVCardPhotoAndNameFields::setSuffix(const QString suffix) {
+ ui->lineEditSUFFIX->setText(suffix);
+}
+
+QString QtVCardPhotoAndNameFields::getSuffix() const {
+ return ui->lineEditSUFFIX->text();
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
new file mode 100644
index 0000000..6a5ae46
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QMenu>
+#include <QWidget>
+
+#include <Swiften/Base/ByteArray.h>
+
+namespace Ui {
+ class QtVCardPhotoAndNameFields;
+}
+
+
+namespace Swift {
+
+ class QtVCardPhotoAndNameFields : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+
+ public:
+ explicit QtVCardPhotoAndNameFields(QWidget* parent = 0);
+ ~QtVCardPhotoAndNameFields();
+
+ bool isEditable() const;
+ void setEditable(bool);
+
+ void setAvatar(const ByteArray& data, const std::string& type);
+ ByteArray getAvatarData() const;
+ std::string getAvatarType() const;
+
+ void setFormattedName(const QString formattedName);
+ QString getFormattedName() const;
+
+ void setNickname(const QString nickname);
+ QString getNickname() const;
+
+ void setPrefix(const QString prefix);
+ QString getPrefix() const;
+
+ void setGivenName(const QString givenName);
+ QString getGivenName() const;
+
+ void setMiddleName(const QString middleName);
+ QString getMiddleName() const;
+
+ void setFamilyName(const QString familyName);
+ QString getFamilyName() const;
+
+ void setSuffix(const QString suffix);
+ QString getSuffix() const;
+
+ private:
+ Ui::QtVCardPhotoAndNameFields* ui;
+ bool editable;
+ };
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.ui b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.ui
new file mode 100644
index 0000000..04da2bc
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.ui
@@ -0,0 +1,251 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtVCardPhotoAndNameFields</class>
+ <widget class="QWidget" name="QtVCardPhotoAndNameFields">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>522</width>
+ <height>81</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0" rowminimumheight="0,0,0,0,0">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <property name="horizontalSpacing">
+ <number>5</number>
+ </property>
+ <property name="verticalSpacing">
+ <number>1</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item row="0" column="0" rowspan="5">
+ <widget class="Swift::QtAvatarWidget" name="avatarWidget" native="true">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" stdset="0">
+ <string/>
+ </property>
+ <property name="flat" stdset="0">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditFN">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>18</pointsize>
+ <weight>50</weight>
+ <bold>false</bold>
+ </font>
+ </property>
+ <property name="toolTip">
+ <string>Formatted Name</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditNICKNAME">
+ <property name="toolTip">
+ <string>Nickname</string>
+ </property>
+ <property name="frame">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>2</number>
+ </property>
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinimumSize</enum>
+ </property>
+ <item>
+ <widget class="QLabel" name="labelFULLNAME">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditPREFIX">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string>Prefix</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditGIVEN">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string>Given Name</string>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="readOnly">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditMIDDLE">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string>Middle Name</string>
+ </property>
+ <property name="styleSheet">
+ <string notr="true"/>
+ </property>
+ <property name="frame">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditFAMILY">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string>Last Name</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Swift::QtResizableLineEdit" name="lineEditSUFFIX">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="toolTip">
+ <string>Suffix</string>
+ </property>
+ <property name="readOnly">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>Swift::QtResizableLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>QtResizableLineEdit.h</header>
+ </customwidget>
+ <customwidget>
+ <class>Swift::QtAvatarWidget</class>
+ <extends>QWidget</extends>
+ <header>Swift/QtUI/QtAvatarWidget.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp
new file mode 100644
index 0000000..af28d28
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardRoleField.h"
+
+#include <QGridLayout>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardRoleField::QtVCardRoleField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Role"), false, false), roleLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardRoleField::~QtVCardRoleField() {
+}
+
+void QtVCardRoleField::setupContentWidgets() {
+ roleLineEdit = new QtResizableLineEdit(this);
+ getGridLayout()->addWidget(roleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << roleLineEdit;
+}
+
+bool QtVCardRoleField::isEmpty() const {
+ return roleLineEdit->text().isEmpty();
+}
+
+void QtVCardRoleField::setRole(const std::string& role) {
+ roleLineEdit->setText(P2QSTRING(role));
+}
+
+std::string QtVCardRoleField::getRole() const {
+ return Q2PSTRING(roleLineEdit->text());
+}
+
+void QtVCardRoleField::handleEditibleChanged(bool isEditable) {
+ assert(roleLineEdit);
+
+ roleLineEdit->setEditable(isEditable);
+ roleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h
new file mode 100644
index 0000000..3c819ed
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardRoleField.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardRoleField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Role", UNLIMITED_INSTANCES, QtVCardRoleField)
+
+ QtVCardRoleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardRoleField();
+
+ virtual bool isEmpty() const;
+
+ void setRole(const std::string& role);
+ std::string getRole() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QtResizableLineEdit* roleLineEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp
new file mode 100644
index 0000000..401d0a0
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardTelephoneField.h"
+
+#include <QGridLayout>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardTelephoneField::QtVCardTelephoneField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Telephone")), telephoneLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardTelephoneField::~QtVCardTelephoneField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardTelephoneField::setupContentWidgets() {
+ telephoneLineEdit = new QtResizableLineEdit(this);
+#if QT_VERSION >= 0x040700
+ telephoneLineEdit->setPlaceholderText(tr("0118 999 881 999 119 7253"));
+#endif
+ getGridLayout()->addWidget(telephoneLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ setTabOrder(telephoneLineEdit, getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+
+ getTagComboBox()->addTag("voice", QObject::tr("Voice"));
+ getTagComboBox()->addTag("fax", QObject::tr("Fax"));
+ getTagComboBox()->addTag("pager", QObject::tr("Pager"));
+ getTagComboBox()->addTag("msg", QObject::tr("Voice Messaging"));
+ getTagComboBox()->addTag("cell", QObject::tr("Cell"));
+ getTagComboBox()->addTag("video", QObject::tr("Video"));
+ getTagComboBox()->addTag("bbs", QObject::tr("Bulletin Board System"));
+ getTagComboBox()->addTag("modem", QObject::tr("Modem"));
+ getTagComboBox()->addTag("isdn", QObject::tr("ISDN"));
+ getTagComboBox()->addTag("pcs", QObject::tr("Personal Communication Services"));
+
+ childWidgets << telephoneLineEdit;
+}
+
+bool QtVCardTelephoneField::isEmpty() const {
+ return telephoneLineEdit->text().isEmpty();
+}
+
+void QtVCardTelephoneField::setTelephone(const VCard::Telephone& telephone) {
+ setPreferred(telephone.isPreferred);
+ setHome(telephone.isHome);
+ setWork(telephone.isWork);
+
+ telephoneLineEdit->setText(P2QSTRING(telephone.number));
+
+ getTagComboBox()->setTag("voice", telephone.isVoice);
+ getTagComboBox()->setTag("fax", telephone.isFax);
+ getTagComboBox()->setTag("pager", telephone.isPager);
+ getTagComboBox()->setTag("msg", telephone.isMSG);
+ getTagComboBox()->setTag("cell", telephone.isCell);
+ getTagComboBox()->setTag("video", telephone.isVideo);
+ getTagComboBox()->setTag("bbs", telephone.isBBS);
+ getTagComboBox()->setTag("modem", telephone.isModem);
+ getTagComboBox()->setTag("isdn", telephone.isISDN);
+ getTagComboBox()->setTag("pcs", telephone.isPCS);
+}
+
+VCard::Telephone QtVCardTelephoneField::getTelephone() const {
+ VCard::Telephone telephone;
+
+ telephone.number = Q2PSTRING(telephoneLineEdit->text());
+
+ telephone.isPreferred = getPreferred();
+ telephone.isHome = getHome();
+ telephone.isWork = getWork();
+
+ telephone.isVoice = getTagComboBox()->isTagSet("voice");
+ telephone.isFax = getTagComboBox()->isTagSet("fax");
+ telephone.isPager = getTagComboBox()->isTagSet("pager");
+ telephone.isMSG = getTagComboBox()->isTagSet("msg");
+ telephone.isCell = getTagComboBox()->isTagSet("cell");
+ telephone.isVideo = getTagComboBox()->isTagSet("video");
+ telephone.isBBS = getTagComboBox()->isTagSet("bbs");
+ telephone.isModem = getTagComboBox()->isTagSet("modem");
+ telephone.isISDN = getTagComboBox()->isTagSet("isdn");
+ telephone.isPCS = getTagComboBox()->isTagSet("pcs");
+
+ return telephone;
+}
+
+void QtVCardTelephoneField::handleEditibleChanged(bool isEditable) {
+ assert(telephoneLineEdit);
+
+ telephoneLineEdit->setEditable(isEditable);
+ telephoneLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h
new file mode 100644
index 0000000..b433e3c
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+#include "QtVCardHomeWork.h"
+
+namespace Swift {
+
+class QtVCardTelephoneField : public QtVCardGeneralField, public QtVCardHomeWork {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Telephone", UNLIMITED_INSTANCES, QtVCardTelephoneField)
+
+ QtVCardTelephoneField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardTelephoneField();
+
+ virtual bool isEmpty() const;
+
+ void setTelephone(const VCard::Telephone& telephone);
+ VCard::Telephone getTelephone() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QtResizableLineEdit* telephoneLineEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp
new file mode 100644
index 0000000..64b05c0
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardTitleField.h"
+
+#include <QGridLayout>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardTitleField::QtVCardTitleField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Title"), false, false), titleLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardTitleField::~QtVCardTitleField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardTitleField::setupContentWidgets() {
+ titleLineEdit = new QtResizableLineEdit(this);
+ getGridLayout()->addWidget(titleLineEdit, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ childWidgets << titleLineEdit;
+}
+
+bool QtVCardTitleField::isEmpty() const {
+ return titleLineEdit->text().isEmpty();
+}
+
+void QtVCardTitleField::setTitle(const std::string& title) {
+ titleLineEdit->setText(P2QSTRING(title));
+}
+
+std::string QtVCardTitleField::getTitle() const {
+ return Q2PSTRING(titleLineEdit->text());
+}
+
+void QtVCardTitleField::handleEditibleChanged(bool isEditable) {
+ assert(titleLineEdit);
+
+ titleLineEdit->setEditable(isEditable);
+ titleLineEdit->setStyleSheet(isEditable ? "" : "QLineEdit { border: none; background: transparent; }");
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h
new file mode 100644
index 0000000..28dc603
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardTitleField.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardTitleField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("Title", UNLIMITED_INSTANCES, QtVCardTitleField)
+
+ QtVCardTitleField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardTitleField();
+
+ virtual bool isEmpty() const;
+
+ void setTitle(const std::string& title);
+ std::string getTitle() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QtResizableLineEdit* titleLineEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp
new file mode 100644
index 0000000..18241b4
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardURLField.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2012-2014 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardURLField.h"
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QTextDocument>
+#include <boost/algorithm/string.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+
+
+namespace Swift {
+
+QtVCardURLField::QtVCardURLField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("URL"), false, false), urlLabel(NULL), urlLineEdit(NULL) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardURLField::~QtVCardURLField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardURLField::setupContentWidgets() {
+ urlLabel = new QLabel(this);
+ urlLabel->setOpenExternalLinks(true);
+ urlLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ urlLineEdit = new QtResizableLineEdit(this);
+
+ QHBoxLayout* urlLayout = new QHBoxLayout();
+ urlLayout->addWidget(urlLabel);
+ urlLayout->addWidget(urlLineEdit);
+
+ getGridLayout()->addLayout(urlLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ getTagComboBox()->hide();
+ urlLabel->hide();
+ childWidgets << urlLabel << urlLineEdit;
+}
+
+bool QtVCardURLField::isEmpty() const {
+ return urlLineEdit->text().isEmpty();
+}
+
+void QtVCardURLField::setURL(const std::string& url) {
+ urlLineEdit->setText(P2QSTRING(url));
+}
+
+std::string QtVCardURLField::getURL() const {
+ return Q2PSTRING(urlLineEdit->text());
+}
+
+void QtVCardURLField::handleEditibleChanged(bool isEditable) {
+ assert(urlLineEdit);
+ assert(urlLabel);
+
+ if (isEditable) {
+ urlLineEdit->show();
+ urlLabel->hide();
+ } else {
+ urlLineEdit->hide();
+ urlLabel->setText(QString("<a href=\"%1\">%1</a>").arg(QtUtilities::htmlEscape(urlLineEdit->text())));
+ urlLabel->show();
+ }
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardURLField.h b/Swift/QtUI/QtVCardWidget/QtVCardURLField.h
new file mode 100644
index 0000000..2c011d8
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardURLField.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/VCard.h>
+
+#include "QtResizableLineEdit.h"
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+
+namespace Swift {
+
+class QtVCardURLField : public QtVCardGeneralField {
+ Q_OBJECT
+
+ public:
+ GENERIC_QT_VCARD_FIELD_INFO("URL", UNLIMITED_INSTANCES, QtVCardURLField)
+
+ QtVCardURLField(QWidget* parent = 0, QGridLayout* layout = 0, bool editable = false);
+ virtual ~QtVCardURLField();
+
+ virtual bool isEmpty() const;
+
+ void setURL(const std::string& url);
+ std::string getURL() const;
+
+ protected:
+ virtual void setupContentWidgets();
+
+ public slots:
+ void handleEditibleChanged(bool isEditable);
+
+ private:
+ QLabel* urlLabel;
+ QtResizableLineEdit* urlLineEdit;
+};
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
new file mode 100644
index 0000000..7dfc06a
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
@@ -0,0 +1,407 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/QtVCardWidget/QtVCardWidget.h>
+
+#include <QDebug>
+#include <QLineEdit>
+#include <QMenu>
+
+#include <Swift/QtUI/QtVCardWidget/ui_QtVCardWidget.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardAddressField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardJIDField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardRoleField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardTitleField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardURLField.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardWidget::QtVCardWidget(QWidget* parent) :
+ QWidget(parent),
+ ui(new ::Ui::QtVCardWidget) {
+ ui->setupUi(this);
+
+ ui->cardFields->setColumnStretch(0,0);
+ ui->cardFields->setColumnStretch(1,0);
+ ui->cardFields->setColumnStretch(2,2);
+ ui->cardFields->setColumnStretch(3,1);
+ ui->cardFields->setColumnStretch(4,2);
+ menu = new QMenu(this);
+
+ toolButton = new QToolButton(this);
+ toolButton->setText(tr("Add Field"));
+ toolButton->setArrowType(Qt::NoArrow);
+ toolButton->setAutoRaise(false);
+ toolButton->setPopupMode(QToolButton::InstantPopup);
+ toolButton->hide();
+ toolButton->setMenu(menu);
+
+ addFieldType(menu, boost::make_shared<QtVCardInternetEMailField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardTelephoneField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardAddressField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardAddressLabelField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardBirthdayField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardJIDField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardDescriptionField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardRoleField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardTitleField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardOrganizationField::FieldInfo>());
+ addFieldType(menu, boost::make_shared<QtVCardURLField::FieldInfo>());
+
+ setEditable(false);
+}
+
+QtVCardWidget::~QtVCardWidget() {
+ delete ui;
+}
+
+bool QtVCardWidget::isEditable() const {
+ return editable;
+}
+
+void QtVCardWidget::setEditable(bool editable) {
+ this->editable = editable;
+
+ ui->photoAndName->setProperty("editable", QVariant(editable));
+
+ foreach(QtVCardGeneralField* field, fields) {
+ field->setEditable(editable);
+ }
+ toolButton->setVisible(editable);
+
+ editableChanged(editable);
+}
+
+void QtVCardWidget::setVCard(VCard::ref vcard) {
+ clearFields();
+ this->vcard = vcard;
+ ui->photoAndName->setFormattedName(P2QSTRING(vcard->getFullName()));
+ ui->photoAndName->setNickname(P2QSTRING(vcard->getNickname()));
+ ui->photoAndName->setPrefix(P2QSTRING(vcard->getPrefix()));
+ ui->photoAndName->setGivenName(P2QSTRING(vcard->getGivenName()));
+ ui->photoAndName->setMiddleName(P2QSTRING(vcard->getMiddleName()));
+ ui->photoAndName->setFamilyName(P2QSTRING(vcard->getFamilyName()));
+ ui->photoAndName->setSuffix(P2QSTRING(vcard->getSuffix()));
+ ui->photoAndName->setAvatar(vcard->getPhoto(), vcard->getPhotoType());
+
+ foreach (const VCard::EMailAddress& address, vcard->getEMailAddresses()) {
+ if (address.isInternet) {
+ QtVCardInternetEMailField* internetEmailField = new QtVCardInternetEMailField(this, ui->cardFields);
+ internetEmailField->initialize();
+ internetEmailField->setInternetEMailAddress(address);
+ appendField(internetEmailField);
+ }
+ }
+
+ foreach (const VCard::Telephone& telephone, vcard->getTelephones()) {
+ QtVCardTelephoneField* telField = new QtVCardTelephoneField(this, ui->cardFields);
+ telField->initialize();
+ telField->setTelephone(telephone);
+ appendField(telField);
+ }
+
+ foreach (const VCard::Address& address, vcard->getAddresses()) {
+ QtVCardAddressField* addressField = new QtVCardAddressField(this, ui->cardFields);
+ addressField->initialize();
+ addressField->setAddress(address);
+ appendField(addressField);
+ }
+
+ foreach (const VCard::AddressLabel& label, vcard->getAddressLabels()) {
+ QtVCardAddressLabelField* addressLabelField = new QtVCardAddressLabelField(this, ui->cardFields);
+ addressLabelField->initialize();
+ addressLabelField->setAddressLabel(label);
+ appendField(addressLabelField);
+ }
+
+ if (!vcard->getBirthday().is_not_a_date_time()) {
+ QtVCardBirthdayField* bdayField = new QtVCardBirthdayField(this, ui->cardFields);
+ bdayField->initialize();
+ bdayField->setBirthday(vcard->getBirthday());
+ appendField(bdayField);
+ }
+
+ foreach (const JID& jid, vcard->getJIDs()) {
+ QtVCardJIDField* jidField = new QtVCardJIDField(this, ui->cardFields);
+ jidField->initialize();
+ jidField->setJID(jid);
+ appendField(jidField);
+ }
+
+ if (!vcard->getDescription().empty()) {
+ QtVCardDescriptionField* descField = new QtVCardDescriptionField(this, ui->cardFields);
+ descField->initialize();
+ descField->setDescription(vcard->getDescription());
+ appendField(descField);
+ }
+
+ foreach (const VCard::Organization& org, vcard->getOrganizations()) {
+ QtVCardOrganizationField* orgField = new QtVCardOrganizationField(this, ui->cardFields);
+ orgField->initialize();
+ orgField->setOrganization(org);
+ appendField(orgField);
+ }
+
+ foreach (const std::string& role, vcard->getRoles()) {
+ QtVCardRoleField* roleField = new QtVCardRoleField(this, ui->cardFields);
+ roleField->initialize();
+ roleField->setRole(role);
+ appendField(roleField);
+ }
+
+ foreach (const std::string& title, vcard->getTitles()) {
+ QtVCardTitleField* titleField = new QtVCardTitleField(this, ui->cardFields);
+ titleField->initialize();
+ titleField->setTitle(title);
+ appendField(titleField);
+ }
+
+ foreach (const std::string& url, vcard->getURLs()) {
+ QtVCardURLField* urlField = new QtVCardURLField(this, ui->cardFields);
+ urlField->initialize();
+ urlField->setURL(url);
+ appendField(urlField);
+ }
+
+ relayoutToolButton();
+ setEditable(editable);
+ window()->resize(sizeHint().width(), size().height() < 200 ? 200 : size().height());
+}
+
+VCard::ref QtVCardWidget::getVCard() {
+ clearEmptyFields();
+ vcard->setFullName(Q2PSTRING(ui->photoAndName->getFormattedName()));
+ vcard->setNickname(Q2PSTRING(ui->photoAndName->getNickname()));
+ vcard->setPrefix(Q2PSTRING(ui->photoAndName->getPrefix()));
+ vcard->setGivenName(Q2PSTRING(ui->photoAndName->getGivenName()));
+ vcard->setMiddleName(Q2PSTRING(ui->photoAndName->getMiddleName()));
+ vcard->setFamilyName(Q2PSTRING(ui->photoAndName->getFamilyName()));
+ vcard->setSuffix(Q2PSTRING(ui->photoAndName->getSuffix()));
+ vcard->setPhoto(ui->photoAndName->getAvatarData());
+ vcard->setPhotoType(ui->photoAndName->getAvatarType());
+
+ vcard->clearEMailAddresses();
+ vcard->clearJIDs();
+ vcard->clearURLs();
+ vcard->clearTelephones();
+ vcard->clearRoles();
+ vcard->clearTitles();
+ vcard->clearOrganizations();
+ vcard->clearAddresses();
+ vcard->clearAddressLabels();
+
+
+ QtVCardBirthdayField* bdayField = NULL;
+ QtVCardDescriptionField* descriptionField = NULL;
+
+ foreach(QtVCardGeneralField* field, fields) {
+ QtVCardInternetEMailField* emailField;
+ if ((emailField = dynamic_cast<QtVCardInternetEMailField*>(field))) {
+ vcard->addEMailAddress(emailField->getInternetEMailAddress());
+ continue;
+ }
+
+ QtVCardTelephoneField* telephoneField;
+ if ((telephoneField = dynamic_cast<QtVCardTelephoneField*>(field))) {
+ vcard->addTelephone(telephoneField->getTelephone());
+ continue;
+ }
+
+ QtVCardAddressField* addressField;
+ if ((addressField = dynamic_cast<QtVCardAddressField*>(field))) {
+ vcard->addAddress(addressField->getAddress());
+ continue;
+ }
+
+ QtVCardAddressLabelField* addressLabelField;
+ if ((addressLabelField = dynamic_cast<QtVCardAddressLabelField*>(field))) {
+ vcard->addAddressLabel(addressLabelField->getAddressLabel());
+ continue;
+ }
+
+ if ((bdayField = dynamic_cast<QtVCardBirthdayField*>(field))) {
+ continue;
+ }
+
+ QtVCardJIDField* jidField;
+ if ((jidField = dynamic_cast<QtVCardJIDField*>(field))) {
+ vcard->addJID(jidField->getJID());
+ continue;
+ }
+
+ if ((descriptionField = dynamic_cast<QtVCardDescriptionField*>(field))) {
+ continue;
+ }
+
+ QtVCardOrganizationField* orgField;
+ if ((orgField = dynamic_cast<QtVCardOrganizationField*>(field))) {
+ vcard->addOrganization(orgField->getOrganization());
+ continue;
+ }
+
+ QtVCardRoleField* roleField;
+ if ((roleField = dynamic_cast<QtVCardRoleField*>(field))) {
+ vcard->addRole(roleField->getRole());
+ continue;
+ }
+
+ QtVCardTitleField* titleField;
+ if ((titleField = dynamic_cast<QtVCardTitleField*>(field))) {
+ vcard->addTitle(titleField->getTitle());
+ continue;
+ }
+
+ QtVCardURLField* urlField;
+ if ((urlField = dynamic_cast<QtVCardURLField*>(field))) {
+ vcard->addURL(urlField->getURL());
+ continue;
+ }
+ }
+
+ if (bdayField) {
+ vcard->setBirthday(bdayField->getBirthday());
+ } else {
+ vcard->setBirthday(boost::posix_time::ptime());
+ }
+
+ if (descriptionField) {
+ vcard->setDescription(descriptionField->getDescription());
+ } else {
+ vcard->setDescription("");
+ }
+
+ return vcard;
+}
+
+void QtVCardWidget::addField() {
+ QAction* action = NULL;
+ if ((action = dynamic_cast<QAction*>(sender()))) {
+ boost::shared_ptr<QtVCardFieldInfo> fieldInfo = actionFieldInfo[action];
+ QWidget* newField = fieldInfo->createFieldInstance(this, ui->cardFields, true);
+ QtVCardGeneralField* newGeneralField = dynamic_cast<QtVCardGeneralField*>(newField);
+ if (newGeneralField) {
+ newGeneralField->initialize();
+ }
+ appendField(newGeneralField);
+ relayoutToolButton();
+ }
+}
+
+void QtVCardWidget::removeField(QtVCardGeneralField *field) {
+ int sameFields = 0;
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if ((vcardField != field) && (typeid(*vcardField) == typeid(*field))) {
+ sameFields++;
+ fieldToChange = vcardField;
+ }
+ }
+
+ if ((sameFields == 1) && fieldToChange) {
+ fieldToChange->setStarVisible(false);
+ }
+
+ fields.remove(field);
+ delete field;
+}
+
+void QtVCardWidget::addFieldType(QMenu* menu, boost::shared_ptr<QtVCardFieldInfo> fieldType) {
+ if (!fieldType->getMenuName().isEmpty()) {
+ QAction* action = new QAction(tr("Add ") + fieldType->getMenuName(), this);
+ actionFieldInfo[action] = fieldType;
+ connect(action, SIGNAL(triggered()), this, SLOT(addField()));
+ menu->addAction(action);
+ }
+}
+
+int QtVCardWidget::fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo> fieldType) {
+ int instances = 0;
+ for (int n = 0; n < ui->cardFields->count(); n++) {
+ if (fieldType->testInstance(ui->cardFields->itemAt(n)->widget())) instances++;
+ }
+ return instances;
+}
+
+void layoutDeleteChildren(QLayout *layout) {
+ while(layout->count() > 0) {
+ QLayoutItem* child;
+ if ((child = layout->takeAt(0)) != 0) {
+ if (child->layout()) {
+ layoutDeleteChildren(child->layout());
+ }
+ if (dynamic_cast<QToolButton*>(child->widget())) {
+ delete child;
+ break;
+ }
+ delete child->widget();
+ delete child;
+ }
+ }
+}
+
+void QtVCardWidget::clearFields() {
+ foreach(QtVCardGeneralField* field, fields) {
+ delete field;
+ }
+ fields.clear();
+
+ assert(ui->cardFields->count() >= 0);
+ layoutDeleteChildren(ui->cardFields);
+}
+
+void QtVCardWidget::clearEmptyFields() {
+ std::vector<QtVCardGeneralField*> items_to_remove;
+ foreach (QtVCardGeneralField* field, fields) {
+ if (field->property("empty").isValid() && field->property("empty").toBool()) {
+ ui->cardFields->removeWidget(field);
+ items_to_remove.push_back(field);
+ delete field;
+ }
+ }
+
+ foreach(QtVCardGeneralField* field, items_to_remove) {
+ fields.remove(field);
+ }
+}
+
+void QtVCardWidget::appendField(QtVCardGeneralField *field) {
+ connect(field, SIGNAL(deleteField(QtVCardGeneralField*)), SLOT(removeField(QtVCardGeneralField*)));
+
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if (typeid(*vcardField) == typeid(*field)) {
+ fieldToChange = vcardField;
+ break;
+ }
+ }
+
+ if (fieldToChange) {
+ fieldToChange->setStarVisible(true);
+ field->setStarVisible(true);
+ }
+
+ fields.push_back(field);
+}
+
+void QtVCardWidget::relayoutToolButton() {
+ ui->cardFields->addWidget(toolButton, ui->cardFields->rowCount(), ui->cardFields->columnCount()-2, 1, 1, Qt::AlignRight);
+}
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.h b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h
new file mode 100644
index 0000000..29ed499
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QWidget>
+#include <QToolButton>
+#include <Swiften/Elements/VCard.h>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include "QtVCardFieldInfo.h"
+#include "QtVCardGeneralField.h"
+#include "QtVCardPhotoAndNameFields.h"
+
+namespace Ui {
+ class QtVCardWidget;
+}
+
+namespace Swift {
+
+ class QtVCardWidget : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(bool editable READ isEditable WRITE setEditable)
+
+ public :
+ explicit QtVCardWidget(QWidget* parent = 0);
+ ~QtVCardWidget();
+
+ bool isEditable() const;
+ void setEditable(bool);
+
+ void setVCard(VCard::ref vcard);
+ VCard::ref getVCard();
+
+ signals:
+ void editableChanged(bool editable);
+
+ private slots:
+ void addField();
+ void removeField(QtVCardGeneralField* field);
+
+ private:
+ void addFieldType(QMenu*, boost::shared_ptr<QtVCardFieldInfo>);
+ int fieldTypeInstances(boost::shared_ptr<QtVCardFieldInfo>);
+ void clearFields();
+ void clearEmptyFields();
+ void appendField(QtVCardGeneralField* field);
+ void relayoutToolButton();
+
+ private:
+ VCard::ref vcard;
+ Ui::QtVCardWidget* ui;
+ QToolButton* toolButton;
+ bool editable;
+ QMenu* menu;
+ std::list<QtVCardGeneralField*> fields;
+ std::map<QAction*, boost::shared_ptr<QtVCardFieldInfo> > actionFieldInfo;
+ };
+
+}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui b/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui
new file mode 100644
index 0000000..4fc8605
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.ui
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtVCardWidget</class>
+ <widget class="QWidget" name="QtVCardWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>535</width>
+ <height>126</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" rowstretch="1" columnstretch="1,0">
+ <property name="leftMargin">
+ <number>5</number>
+ </property>
+ <property name="topMargin">
+ <number>5</number>
+ </property>
+ <property name="rightMargin">
+ <number>5</number>
+ </property>
+ <property name="bottomMargin">
+ <number>5</number>
+ </property>
+ <item row="0" column="0" colspan="2">
+ <layout class="QVBoxLayout" name="card" stretch="0,0,1">
+ <property name="spacing">
+ <number>2</number>
+ </property>
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
+ <item>
+ <widget class="Swift::QtVCardPhotoAndNameFields" name="photoAndName" native="true"/>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>523</width>
+ <height>110</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetMinAndMaxSize</enum>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QGridLayout" name="cardFields"/>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Preferred</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>1000</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>Swift::QtVCardPhotoAndNameFields</class>
+ <extends>QWidget</extends>
+ <header>QtVCardPhotoAndNameFields.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
new file mode 100644
index 0000000..a510e34
--- /dev/null
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -0,0 +1,945 @@
+/*
+ * Copyright (c) 2010-2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "QtWebKitChatView.h"
+
+#include <QtDebug>
+#include <QEventLoop>
+#include <QFile>
+#include <QDesktopServices>
+#include <QVBoxLayout>
+#include <QWebFrame>
+#include <QKeyEvent>
+#include <QStackedWidget>
+#include <QTimer>
+#include <QMessageBox>
+#include <QApplication>
+#include <QInputDialog>
+#include <QFileDialog>
+
+#include <Swiften/Base/Log.h>
+#include <Swiften/Base/FileSize.h>
+#include <Swiften/StringCodecs/Base64.h>
+
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/Controllers/UIEvents/JoinMUCUIEvent.h>
+
+#include <Swift/QtUI/QtWebView.h>
+#include <Swift/QtUI/QtChatWindow.h>
+#include <Swift/QtUI/QtChatWindowJSBridge.h>
+#include <Swift/QtUI/QtScaledAvatarCache.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtUtilities.h>
+#include <Swift/QtUI/MessageSnippet.h>
+#include <Swift/QtUI/SystemMessageSnippet.h>
+
+namespace Swift {
+
+const QString QtWebKitChatView::ButtonWhiteboardSessionCancel = QString("whiteboard-cancel");
+const QString QtWebKitChatView::ButtonWhiteboardSessionAcceptRequest = QString("whiteboard-acceptrequest");
+const QString QtWebKitChatView::ButtonWhiteboardShowWindow = QString("whiteboard-showwindow");
+const QString QtWebKitChatView::ButtonFileTransferCancel = QString("filetransfer-cancel");
+const QString QtWebKitChatView::ButtonFileTransferSetDescription = QString("filetransfer-setdescription");
+const QString QtWebKitChatView::ButtonFileTransferSendRequest = QString("filetransfer-sendrequest");
+const QString QtWebKitChatView::ButtonFileTransferAcceptRequest = QString("filetransfer-acceptrequest");
+const QString QtWebKitChatView::ButtonMUCInvite = QString("mucinvite");
+
+QtWebKitChatView::QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll) : QtChatView(parent), window_(window), eventStream_(eventStream), fontSizeSteps_(0), disableAutoScroll_(disableAutoScroll), previousMessageKind_(PreviosuMessageWasNone), previousMessageWasSelf_(false), showEmoticons_(false), insertingLastLine_(false), idCounter_(0) {
+ theme_ = theme;
+
+ QVBoxLayout* mainLayout = new QVBoxLayout(this);
+ mainLayout->setSpacing(0);
+ mainLayout->setContentsMargins(0,0,0,0);
+ webView_ = new QtWebView(this);
+ connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
+ connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
+ connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
+ connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested()));
+ connect(webView_, SIGNAL(fontGrowRequested()), SLOT(increaseFontSize()));
+ connect(webView_, SIGNAL(fontShrinkRequested()), SLOT(decreaseFontSize()));
+#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
+ /* To give a border on Linux, where it looks bad without */
+ QStackedWidget* stack = new QStackedWidget(this);
+ stack->addWidget(webView_);
+ stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+ stack->setLineWidth(2);
+ mainLayout->addWidget(stack);
+#else
+ mainLayout->addWidget(webView_);
+#endif
+
+#ifdef SWIFT_EXPERIMENTAL_FT
+ setAcceptDrops(true);
+#endif
+
+ webPage_ = new QWebPage(this);
+ webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
+ if (Log::getLogLevel() == Log::debug) {
+ webPage_->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
+ }
+ webView_->setPage(webPage_);
+ connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
+ connect(webPage_, SIGNAL(scrollRequested(int, int, const QRect&)), SLOT(handleScrollRequested(int, int, const QRect&)));
+
+ viewReady_ = false;
+ isAtBottom_ = true;
+ resetView();
+
+ jsBridge = new QtChatWindowJSBridge();
+ addToJSEnvironment("chatwindow", jsBridge);
+ connect(jsBridge, SIGNAL(buttonClicked(QString,QString,QString,QString,QString,QString)), this, SLOT(handleHTMLButtonClicked(QString,QString,QString,QString,QString,QString)));
+
+}
+
+QtWebKitChatView::~QtWebKitChatView() {
+ delete jsBridge;
+}
+
+void QtWebKitChatView::handleClearRequested() {
+ QMessageBox messageBox(this);
+ messageBox.setWindowTitle(tr("Clear log"));
+ messageBox.setText(tr("You are about to clear the contents of your chat log."));
+ messageBox.setInformativeText(tr("Are you sure?"));
+ messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ messageBox.setDefaultButton(QMessageBox::Yes);
+ int button = messageBox.exec();
+ if (button == QMessageBox::Yes) {
+ logCleared();
+ resetView();
+ }
+}
+
+void QtWebKitChatView::handleKeyPressEvent(QKeyEvent* event) {
+ webView_->keyPressEvent(event);
+}
+
+void QtWebKitChatView::addMessageBottom(boost::shared_ptr<ChatSnippet> snippet) {
+ if (viewReady_) {
+ addToDOM(snippet);
+ } else {
+ /* If this asserts, the previous queuing code was necessary and should be reinstated */
+ assert(false);
+ }
+}
+
+void QtWebKitChatView::addMessageTop(boost::shared_ptr<ChatSnippet> snippet) {
+ // save scrollbar maximum value
+ if (!topMessageAdded_) {
+ scrollBarMaximum_ = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
+ }
+ topMessageAdded_ = true;
+
+ QWebElement continuationElement = firstElement_.findFirst("#insert");
+
+ bool insert = snippet->getAppendToPrevious();
+ bool fallback = continuationElement.isNull();
+
+ boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet;
+ QWebElement newElement = snippetToDOM(newSnippet);
+
+ if (insert && !fallback) {
+ Q_ASSERT(!continuationElement.isNull());
+ continuationElement.replace(newElement);
+ } else {
+ continuationElement.removeFromDocument();
+ topInsertPoint_.prependOutside(newElement);
+ }
+
+ firstElement_ = newElement;
+
+ if (lastElement_.isNull()) {
+ lastElement_ = firstElement_;
+ }
+
+ if (fontSizeSteps_ != 0) {
+ double size = 1.0 + 0.2 * fontSizeSteps_;
+ QString sizeString(QString().setNum(size, 'g', 3) + "em");
+ const QWebElementCollection spans = firstElement_.findAll("span.swift_resizable");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("font-size", sizeString);
+ }
+ }
+}
+
+QWebElement QtWebKitChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) {
+ QWebElement newElement = newInsertPoint_.clone();
+ newElement.setInnerXml(snippet->getContent());
+ Q_ASSERT(!newElement.isNull());
+ return newElement;
+}
+
+void QtWebKitChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {
+ //qDebug() << snippet->getContent();
+ rememberScrolledToBottom();
+ bool insert = snippet->getAppendToPrevious();
+ QWebElement continuationElement = lastElement_.findFirst("#insert");
+ bool fallback = insert && continuationElement.isNull();
+ boost::shared_ptr<ChatSnippet> newSnippet = (insert && fallback) ? snippet->getContinuationFallbackSnippet() : snippet;
+ QWebElement newElement = snippetToDOM(newSnippet);
+ if (insert && !fallback) {
+ Q_ASSERT(!continuationElement.isNull());
+ continuationElement.replace(newElement);
+ } else {
+ continuationElement.removeFromDocument();
+ newInsertPoint_.prependOutside(newElement);
+ }
+ lastElement_ = newElement;
+ if (fontSizeSteps_ != 0) {
+ double size = 1.0 + 0.2 * fontSizeSteps_;
+ QString sizeString(QString().setNum(size, 'g', 3) + "em");
+ const QWebElementCollection spans = lastElement_.findAll("span.swift_resizable");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("font-size", sizeString);
+ }
+ }
+ //qDebug() << "-----------------";
+ //qDebug() << webPage_->mainFrame()->toHtml();
+}
+
+void QtWebKitChatView::addLastSeenLine() {
+ /* if the line is added we should break the snippet */
+ insertingLastLine_ = true;
+ if (lineSeparator_.isNull()) {
+ lineSeparator_ = newInsertPoint_.clone();
+ lineSeparator_.setInnerXml(QString("<hr/>"));
+ newInsertPoint_.prependOutside(lineSeparator_);
+ }
+ else {
+ QWebElement lineSeparatorC = lineSeparator_.clone();
+ lineSeparatorC.removeFromDocument();
+ }
+ newInsertPoint_.prependOutside(lineSeparator_);
+}
+
+void QtWebKitChatView::replaceLastMessage(const QString& newMessage, const ChatWindow::TimestampBehaviour timestampBehaviour) {
+ assert(viewReady_);
+ rememberScrolledToBottom();
+ assert(!lastElement_.isNull());
+ QWebElement replace = lastElement_.findFirst("span.swift_message");
+ assert(!replace.isNull());
+ QString old = lastElement_.toOuterXml();
+ replace.setInnerXml(ChatSnippet::escape(newMessage));
+ if (timestampBehaviour == ChatWindow::UpdateTimestamp) {
+ replace = lastElement_.findFirst("span.swift_time");
+ assert(!replace.isNull());
+ replace.setInnerXml(ChatSnippet::timeToEscapedString(QDateTime::currentDateTime()));
+ }
+}
+
+void QtWebKitChatView::replaceLastMessage(const QString& newMessage, const QString& note) {
+ rememberScrolledToBottom();
+ replaceLastMessage(newMessage, ChatWindow::KeepTimestamp);
+ QWebElement replace = lastElement_.findFirst("span.swift_time");
+ assert(!replace.isNull());
+ replace.setInnerXml(ChatSnippet::escape(note));
+}
+
+QString QtWebKitChatView::getLastSentMessage() {
+ return lastElement_.toPlainText();
+}
+
+void QtWebKitChatView::addToJSEnvironment(const QString& name, QObject* obj) {
+ webView_->page()->currentFrame()->addToJavaScriptWindowObject(name, obj);
+}
+
+void QtWebKitChatView::replaceMessage(const QString& newMessage, const QString& id, const QDateTime& editTime) {
+ rememberScrolledToBottom();
+ QWebElement message = document_.findFirst("#" + id);
+ if (!message.isNull()) {
+ QWebElement replaceContent = message.findFirst("span.swift_inner_message");
+ assert(!replaceContent.isNull());
+ QString old = replaceContent.toOuterXml();
+ replaceContent.setInnerXml(ChatSnippet::escape(newMessage));
+ QWebElement replaceTime = message.findFirst("span.swift_time");
+ assert(!replaceTime.isNull());
+ old = replaceTime.toOuterXml();
+ replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime))));
+ }
+ else {
+ qWarning() << "Trying to replace element with id " << id << " but it's not there.";
+ }
+}
+
+void QtWebKitChatView::showEmoticons(bool show) {
+ showEmoticons_ = show;
+ {
+ const QWebElementCollection spans = document_.findAll("span.swift_emoticon_image");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("display", show ? "inline" : "none");
+ }
+ }
+ {
+ const QWebElementCollection spans = document_.findAll("span.swift_emoticon_text");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("display", show ? "none" : "inline");
+ }
+ }
+}
+
+void QtWebKitChatView::copySelectionToClipboard() {
+ if (!webPage_->selectedText().isEmpty()) {
+ webPage_->triggerAction(QWebPage::Copy);
+ }
+}
+
+void QtWebKitChatView::setAckXML(const QString& id, const QString& xml) {
+ QWebElement message = document_.findFirst("#" + id);
+ /* Deliberately not asserting here, so that when we start expiring old messages it won't hit us */
+ if (message.isNull()) return;
+ QWebElement ackElement = message.findFirst("span.swift_ack");
+ assert(!ackElement.isNull());
+ ackElement.setInnerXml(xml);
+}
+
+void QtWebKitChatView::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 QtWebKitChatView::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 QtWebKitChatView::rememberScrolledToBottom() {
+ isAtBottom_ = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) >= (webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical) - 1);
+}
+
+void QtWebKitChatView::scrollToBottom() {
+ isAtBottom_ = true;
+ webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical));
+ webView_->update(); /* Work around redraw bug in some versions of Qt. */
+}
+
+void QtWebKitChatView::handleFrameSizeChanged() {
+ if (topMessageAdded_) {
+ // adjust new scrollbar position
+ int newMaximum = webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical);
+ webPage_->mainFrame()->setScrollBarValue(Qt::Vertical, newMaximum - scrollBarMaximum_);
+ topMessageAdded_ = false;
+ }
+
+ if (isAtBottom_ && !disableAutoScroll_) {
+ scrollToBottom();
+ }
+}
+
+void QtWebKitChatView::handleLinkClicked(const QUrl& url) {
+ QDesktopServices::openUrl(url);
+}
+
+void QtWebKitChatView::handleViewLoadFinished(bool ok) {
+ Q_ASSERT(ok);
+ viewReady_ = true;
+}
+
+void QtWebKitChatView::increaseFontSize(int numSteps) {
+ //qDebug() << "Increasing";
+ fontSizeSteps_ += numSteps;
+ emit fontResized(fontSizeSteps_);
+}
+
+void QtWebKitChatView::decreaseFontSize() {
+ fontSizeSteps_--;
+ if (fontSizeSteps_ < 0) {
+ fontSizeSteps_ = 0;
+ }
+ emit fontResized(fontSizeSteps_);
+}
+
+void QtWebKitChatView::resizeFont(int fontSizeSteps) {
+ fontSizeSteps_ = fontSizeSteps;
+ double size = 1.0 + 0.2 * fontSizeSteps_;
+ QString sizeString(QString().setNum(size, 'g', 3) + "em");
+ //qDebug() << "Setting to " << sizeString;
+ const QWebElementCollection spans = document_.findAll("span.swift_resizable");
+ Q_FOREACH (QWebElement span, spans) {
+ span.setStyleProperty("font-size", sizeString);
+ }
+ webView_->setFontSizeIsMinimal(size == 1.0);
+}
+
+void QtWebKitChatView::resetView() {
+ lastElement_ = QWebElement();
+ firstElement_ = lastElement_;
+ topMessageAdded_ = false;
+ scrollBarMaximum_ = 0;
+ QString pageHTML = theme_->getTemplate();
+ pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
+ if (pageHTML.count("%@") > 3) {
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
+ }
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
+ pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
+ QEventLoop syncLoop;
+ connect(webView_, SIGNAL(loadFinished(bool)), &syncLoop, SLOT(quit()));
+ webPage_->mainFrame()->setHtml(pageHTML);
+ while (!viewReady_) {
+ QTimer t;
+ t.setSingleShot(true);
+ connect(&t, SIGNAL(timeout()), &syncLoop, SLOT(quit()));
+ t.start(50);
+ syncLoop.exec();
+ }
+ document_ = webPage_->mainFrame()->documentElement();
+
+ resetTopInsertPoint();
+ QWebElement chatElement = document_.findFirst("#Chat");
+ newInsertPoint_ = chatElement.clone();
+ newInsertPoint_.setOuterXml("<div id='swift_insert'/>");
+ chatElement.appendInside(newInsertPoint_);
+ Q_ASSERT(!newInsertPoint_.isNull());
+
+ scrollToBottom();
+
+ connect(webPage_->mainFrame(), SIGNAL(contentsSizeChanged(const QSize&)), this, SLOT(handleFrameSizeChanged()), Qt::UniqueConnection);
+}
+
+static QWebElement findElementWithID(QWebElement document, QString elementName, QString id) {
+ QWebElementCollection elements = document.findAll(elementName);
+ Q_FOREACH(QWebElement element, elements) {
+ if (element.attribute("id") == id) {
+ return element;
+ }
+ }
+ return QWebElement();
+}
+
+void QtWebKitChatView::setFileTransferProgress(QString id, const int percentageDone) {
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id!" << std::endl;
+ return;
+ }
+ QWebElement progressBar = ftElement.findFirst("div.progressbar");
+ progressBar.setStyleProperty("width", QString::number(percentageDone) + "%");
+
+ QWebElement progressBarValue = ftElement.findFirst("div.progressbar-value");
+ progressBarValue.setInnerXml(QString::number(percentageDone) + " %");
+}
+
+void QtWebKitChatView::setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& /* msg */) {
+ QWebElement ftElement = findElementWithID(document_, "div", id);
+ if (ftElement.isNull()) {
+ SWIFT_LOG(debug) << "Tried to access FT UI via invalid id! id = " << Q2PSTRING(id) << std::endl;
+ return;
+ }
+
+ QString newInnerHTML = "";
+ if (state == ChatWindow::WaitingForAccept) {
+ newInnerHTML = tr("Waiting for other side to accept the transfer.") + "<br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ if (state == ChatWindow::Negotiating) {
+ // replace with text "Negotiaging" + Cancel button
+ newInnerHTML = tr("Negotiating...") + "<br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::Transferring) {
+ // progress bar + Cancel Button
+ newInnerHTML = "<div style=\"position: relative; width: 90%; height: 20px; border: 2px solid grey; -webkit-border-radius: 10px;\">"
+ "<div class=\"progressbar\" style=\"width: 0%; height: 100%; background: #AAA; -webkit-border-radius: 6px;\">"
+ "<div class=\"progressbar-value\" style=\"position: absolute; top: 0px; left: 0px; width: 100%; text-align: center; padding-top: 2px;\">"
+ "0%"
+ "</div>"
+ "</div>"
+ "</div>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, id);
+ }
+ else if (state == ChatWindow::Canceled) {
+ newInnerHTML = tr("Transfer has been canceled!");
+ }
+ else if (state == ChatWindow::Finished) {
+ // text "Successful transfer"
+ newInnerHTML = tr("Transfer completed successfully.");
+ }
+ else if (state == ChatWindow::FTFailed) {
+ newInnerHTML = tr("Transfer failed.");
+ }
+
+ ftElement.setInnerXml(newInnerHTML);
+}
+
+void QtWebKitChatView::setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state) {
+ QWebElement divElement = findElementWithID(document_, "div", id);
+ QString newInnerHTML;
+ if (state == ChatWindow::WhiteboardAccepted) {
+ newInnerHTML = tr("Started whiteboard chat") + "<br/>" + buildChatWindowButton(tr("Show whiteboard"), ButtonWhiteboardShowWindow, id);
+ } else if (state == ChatWindow::WhiteboardTerminated) {
+ newInnerHTML = tr("Whiteboard chat has been canceled");
+ } else if (state == ChatWindow::WhiteboardRejected) {
+ newInnerHTML = tr("Whiteboard chat request has been rejected");
+ }
+ divElement.setInnerXml(newInnerHTML);
+}
+
+void QtWebKitChatView::setMUCInvitationJoined(QString id) {
+ QWebElement divElement = findElementWithID(document_, "div", id);
+ QWebElement buttonElement = findElementWithID(divElement, "input", "mucinvite");
+ if (!buttonElement.isNull()) {
+ buttonElement.setAttribute("value", tr("Return to room"));
+ }
+}
+
+void QtWebKitChatView::handleScrollRequested(int, int dy, const QRect&) {
+ rememberScrolledToBottom();
+
+ int pos = webPage_->mainFrame()->scrollBarValue(Qt::Vertical) - dy;
+ emit scrollRequested(pos);
+
+ if (pos == 0) {
+ emit scrollReachedTop();
+ }
+ else if (pos == webPage_->mainFrame()->scrollBarMaximum(Qt::Vertical)) {
+ emit scrollReachedBottom();
+ }
+}
+
+int QtWebKitChatView::getSnippetPositionByDate(const QDate& date) {
+ QWebElement message = webPage_->mainFrame()->documentElement().findFirst(".date" + date.toString(Qt::ISODate));
+
+ return message.geometry().top();
+}
+
+void QtWebKitChatView::resetTopInsertPoint() {
+ QWebElement continuationElement = firstElement_.findFirst("#insert");
+ continuationElement.removeFromDocument();
+ firstElement_ = QWebElement();
+
+ topInsertPoint_.removeFromDocument();
+ QWebElement chatElement = document_.findFirst("#Chat");
+ topInsertPoint_ = chatElement.clone();
+ topInsertPoint_.setOuterXml("<div id='swift_insert'/>");
+ chatElement.prependInside(topInsertPoint_);
+}
+
+
+std::string QtWebKitChatView::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) {
+ return addMessage(chatMessageToHTML(message), senderName, senderIsSelf, label, avatarPath, "", time, highlight, ChatSnippet::getDirection(message));
+}
+
+QString QtWebKitChatView::getHighlightSpanStart(const std::string& text, const std::string& background) {
+ QString ecsapeColor = QtUtilities::htmlEscape(P2QSTRING(text));
+ QString escapeBackground = QtUtilities::htmlEscape(P2QSTRING(background));
+ if (ecsapeColor.isEmpty()) {
+ ecsapeColor = "black";
+ }
+ if (escapeBackground.isEmpty()) {
+ escapeBackground = "yellow";
+ }
+ return QString("<span style=\"color: %1; background: %2\">").arg(ecsapeColor).arg(escapeBackground);
+}
+
+QString QtWebKitChatView::getHighlightSpanStart(const HighlightAction& highlight) {
+ return getHighlightSpanStart(highlight.getTextColor(), highlight.getTextBackground());
+}
+
+QString QtWebKitChatView::chatMessageToHTML(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))) {
+ QString textStyle = showEmoticons_ ? "style='display:none'" : "";
+ QString imageStyle = showEmoticons_ ? "" : "style='display:none'";
+ result += "<span class='swift_emoticon_image' " + imageStyle + "><img src='" + P2QSTRING(emoticonPart->imagePath) + "'/></span><span class='swift_emoticon_text' " + textStyle + ">" + QtUtilities::htmlEscape(P2QSTRING(emoticonPart->alternativeText)) + "</span>";
+ continue;
+ }
+ if ((highlightPart = boost::dynamic_pointer_cast<ChatWindow::ChatHighlightingMessagePart>(part))) {
+ QString spanStart = getHighlightSpanStart(highlightPart->foregroundColor, highlightPart->backgroundColor);
+ result += spanStart + QtUtilities::htmlEscape(P2QSTRING(highlightPart->text)) + "</span>";
+ continue;
+ }
+
+ }
+ return result;
+}
+
+std::string QtWebKitChatView::addMessage(
+ const QString& message,
+ const std::string& senderName,
+ bool senderIsSelf,
+ boost::shared_ptr<SecurityLabel> label,
+ const std::string& avatarPath,
+ const QString& style,
+ const boost::posix_time::ptime& time,
+ const HighlightAction& highlight,
+ ChatSnippet::Direction direction) {
+
+ QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());
+
+ QString htmlString;
+ if (label) {
+ htmlString = QString("<span style=\"border: thin dashed grey; padding-left: .5em; padding-right: .5em; color: %1; background-color: %2; font-size: 90%; margin-right: .5em; \" class='swift_label'>").arg(QtUtilities::htmlEscape(P2QSTRING(label->getForegroundColor()))).arg(QtUtilities::htmlEscape(P2QSTRING(label->getBackgroundColor())));
+ htmlString += QString("%1</span> ").arg(QtUtilities::htmlEscape(P2QSTRING(label->getDisplayMarking())));
+ }
+
+ QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
+ QString styleSpanEnd = style == "" ? "" : "</span>";
+ QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : "";
+ htmlString += "<span class='swift_inner_message'>" + styleSpanStart + highlightSpanStart + message + highlightSpanEnd + styleSpanEnd + "</span>" ;
+
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMessage, senderName, senderIsSelf);
+
+ QString qAvatarPath = scaledAvatarPath.isEmpty() ? "qrc:/icons/avatar.png" : QUrl::fromLocalFile(scaledAvatarPath).toEncoded();
+ std::string id = "id" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(time), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), direction));
+
+ previousMessageWasSelf_ = senderIsSelf;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasMessage;
+ return id;
+}
+
+std::string QtWebKitChatView::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) {
+ return addMessage(" *" + chatMessageToHTML(message) + "*", senderName, senderIsSelf, label, avatarPath, "font-style:italic ", time, highlight, ChatSnippet::getDirection(message));
+}
+
+static QString encodeButtonArgument(const QString& str) {
+ return QtUtilities::htmlEscape(P2QSTRING(Base64::encode(createByteArray(Q2PSTRING(str)))));
+}
+
+static QString decodeButtonArgument(const QString& str) {
+ return P2QSTRING(byteArrayToString(Base64::decode(Q2PSTRING(str))));
+}
+
+QString QtWebKitChatView::buildChatWindowButton(const QString& name, const QString& id, const QString& arg1, const QString& arg2, const QString& arg3, const QString& arg4, const QString& arg5) {
+ QRegExp regex("[A-Za-z][A-Za-z0-9\\-\\_]+");
+ Q_ASSERT(regex.exactMatch(id));
+ QString html = QString("<input id='%2' type='submit' value='%1' onclick='chatwindow.buttonClicked(\"%2\", \"%3\", \"%4\", \"%5\", \"%6\", \"%7\");' />").arg(name).arg(id).arg(encodeButtonArgument(arg1)).arg(encodeButtonArgument(arg2)).arg(encodeButtonArgument(arg3)).arg(encodeButtonArgument(arg4)).arg(encodeButtonArgument(arg5));
+ return html;
+}
+
+std::string QtWebKitChatView::addFileTransfer(const std::string& senderName, bool senderIsSelf, const std::string& filename, const boost::uintmax_t sizeInBytes) {
+ SWIFT_LOG(debug) << "addFileTransfer" << std::endl;
+ QString ft_id = QString("ft%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+
+ QString actionText;
+ QString htmlString;
+ QString formattedFileSize = P2QSTRING(formatSize(sizeInBytes));
+ if (senderIsSelf) {
+ // outgoing
+ actionText = tr("Send file");
+ htmlString = actionText + ": " + P2QSTRING(filename) + " ( " + formattedFileSize + ") <br/>" +
+ "<div id='" + ft_id + "'>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
+ buildChatWindowButton(tr("Set Description"), ButtonFileTransferSetDescription, ft_id) +
+ buildChatWindowButton(tr("Send"), ButtonFileTransferSendRequest, ft_id) +
+ "</div>";
+ } else {
+ // incoming
+ actionText = tr("Receiving file");
+ htmlString = actionText + ": " + P2QSTRING(filename) + " ( " + formattedFileSize + ") <br/>" +
+ "<div id='" + ft_id + "'>" +
+ buildChatWindowButton(tr("Cancel"), ButtonFileTransferCancel, ft_id) +
+ buildChatWindowButton(tr("Accept"), ButtonFileTransferAcceptRequest, ft_id, P2QSTRING(filename)) +
+ "</div>";
+ }
+
+ //addMessage(message, senderName, senderIsSelf, boost::shared_ptr<SecurityLabel>(), "", boost::posix_time::second_clock::local_time());
+
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasFileTransfer, senderName, senderIsSelf);
+
+ QString qAvatarPath = "qrc:/icons/avatar.png";
+ std::string id = "ftmessage" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
+
+ previousMessageWasSelf_ = senderIsSelf;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasFileTransfer;
+ return Q2PSTRING(ft_id);
+}
+
+void QtWebKitChatView::setFileTransferProgress(std::string id, const int percentageDone) {
+ setFileTransferProgress(P2QSTRING(id), percentageDone);
+}
+
+void QtWebKitChatView::setFileTransferStatus(std::string id, const ChatWindow::FileTransferState state, const std::string& msg) {
+ setFileTransferStatus(P2QSTRING(id), state, P2QSTRING(msg));
+}
+
+std::string QtWebKitChatView::addWhiteboardRequest(const QString& contact, bool senderIsSelf) {
+ QString wb_id = QString("wb%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+ QString htmlString;
+ QString actionText;
+ if (senderIsSelf) {
+ actionText = tr("Starting whiteboard chat");
+ htmlString = "<div id='" + wb_id + "'>" + actionText + "<br />"+
+ buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
+ "</div>";
+ } else {
+ actionText = tr("%1 would like to start a whiteboard chat");
+ htmlString = "<div id='" + wb_id + "'>" + actionText.arg(QtUtilities::htmlEscape(contact)) + ": <br/>" +
+ buildChatWindowButton(tr("Cancel"), ButtonWhiteboardSessionCancel, wb_id) +
+ buildChatWindowButton(tr("Accept"), ButtonWhiteboardSessionAcceptRequest, wb_id) +
+ "</div>";
+ }
+ QString qAvatarPath = "qrc:/icons/avatar.png";
+ std::string id = "wbmessage" + boost::lexical_cast<std::string>(idCounter_++);
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(contact), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, false, false, theme_, P2QSTRING(id), ChatSnippet::getDirection(actionText)));
+ previousMessageWasSelf_ = false;
+ previousSenderName_ = contact;
+ return Q2PSTRING(wb_id);
+}
+
+void QtWebKitChatView::setWhiteboardSessionStatus(const std::string& id, const ChatWindow::WhiteboardSessionState state) {
+ setWhiteboardSessionStatus(P2QSTRING(id), state);
+}
+
+
+
+
+void QtWebKitChatView::handleHTMLButtonClicked(QString id, QString encodedArgument1, QString encodedArgument2, QString encodedArgument3, QString encodedArgument4, QString encodedArgument5) {
+ QString arg1 = decodeButtonArgument(encodedArgument1);
+ QString arg2 = decodeButtonArgument(encodedArgument2);
+ QString arg3 = decodeButtonArgument(encodedArgument3);
+ QString arg4 = decodeButtonArgument(encodedArgument4);
+ QString arg5 = decodeButtonArgument(encodedArgument5);
+
+ if (id.startsWith(ButtonFileTransferCancel)) {
+ QString ft_id = arg1;
+ window_->onFileTransferCancel(Q2PSTRING(ft_id));
+ }
+ else if (id.startsWith(ButtonFileTransferSetDescription)) {
+ QString ft_id = arg1;
+ bool ok = false;
+ QString text = QInputDialog::getText(this, tr("File transfer description"),
+ tr("Description:"), QLineEdit::Normal, "", &ok);
+ if (ok) {
+ descriptions_[ft_id] = text;
+ }
+ }
+ else if (id.startsWith(ButtonFileTransferSendRequest)) {
+ QString ft_id = arg1;
+ QString text = descriptions_.find(ft_id) == descriptions_.end() ? QString() : descriptions_[ft_id];
+ window_->onFileTransferStart(Q2PSTRING(ft_id), Q2PSTRING(text));
+ }
+ else if (id.startsWith(ButtonFileTransferAcceptRequest)) {
+ QString ft_id = arg1;
+ QString filename = arg2;
+
+ QString path = QFileDialog::getSaveFileName(this, tr("Save File"), filename);
+ if (!path.isEmpty()) {
+ window_->onFileTransferAccept(Q2PSTRING(ft_id), Q2PSTRING(path));
+ }
+ }
+ else if (id.startsWith(ButtonWhiteboardSessionAcceptRequest)) {
+ QString id = arg1;
+ setWhiteboardSessionStatus(id, ChatWindow::WhiteboardAccepted);
+ window_->onWhiteboardSessionAccept();
+ }
+ else if (id.startsWith(ButtonWhiteboardSessionCancel)) {
+ QString id = arg1;
+ setWhiteboardSessionStatus(id, ChatWindow::WhiteboardTerminated);
+ window_->onWhiteboardSessionCancel();
+ }
+ else if (id.startsWith(ButtonWhiteboardShowWindow)) {
+ QString id = arg1;
+ window_->onWhiteboardWindowShow();
+ }
+ else if (id.startsWith(ButtonMUCInvite)) {
+ QString roomJID = arg1;
+ QString password = arg2;
+ QString elementID = arg3;
+ QString isImpromptu = arg4;
+ QString isContinuation = arg5;
+ eventStream_->send(boost::make_shared<JoinMUCUIEvent>(Q2PSTRING(roomJID), Q2PSTRING(password), boost::optional<std::string>(), false, false, isImpromptu.contains("true"), isContinuation.contains("true")));
+ setMUCInvitationJoined(elementID);
+ }
+ else {
+ SWIFT_LOG(debug) << "Unknown HTML button! ( " << Q2PSTRING(id) << " )" << std::endl;
+ }
+}
+
+void QtWebKitChatView::addErrorMessage(const ChatWindow::ChatMessage& errorMessage) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
+
+ QString errorMessageHTML(chatMessageToHTML(errorMessage));
+
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>("<span class=\"error\">" + errorMessageHTML + "</span>", QDateTime::currentDateTime(), false, theme_, ChatSnippet::getDirection(errorMessage)));
+
+ previousMessageWasSelf_ = false;
+ previousMessageKind_ = PreviousMessageWasSystem;
+}
+
+void QtWebKitChatView::addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
+
+ QString messageHTML = chatMessageToHTML(message);
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, getActualDirection(message, direction)));
+
+ previousMessageKind_ = PreviousMessageWasSystem;
+}
+
+void QtWebKitChatView::replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) {
+ replaceMessage(" *" + chatMessageToHTML(message) + "*", id, time, "font-style:italic ", highlight);
+}
+
+void QtWebKitChatView::replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) {
+ replaceMessage(chatMessageToHTML(message), id, time, "", highlight);
+}
+
+void QtWebKitChatView::replaceMessage(const QString& message, const std::string& id, const boost::posix_time::ptime& time, const QString& style, const HighlightAction& highlight) {
+ if (!id.empty()) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
+
+ QString messageHTML(message);
+
+ QString styleSpanStart = style == "" ? "" : "<span style=\"" + style + "\">";
+ QString styleSpanEnd = style == "" ? "" : "</span>";
+ QString highlightSpanStart = highlight.highlightAllText() ? getHighlightSpanStart(highlight) : "";
+ QString highlightSpanEnd = highlight.highlightAllText() ? "</span>" : "";
+ messageHTML = styleSpanStart + highlightSpanStart + messageHTML + highlightSpanEnd + styleSpanEnd;
+
+ replaceMessage(messageHTML, P2QSTRING(id), B2QDATE(time));
+ }
+ else {
+ std::cerr << "Trying to replace a message with no id";
+ }
+}
+
+void QtWebKitChatView::addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
+
+ QString messageHTML = chatMessageToHTML(message);
+ addMessageBottom(boost::make_shared<SystemMessageSnippet>(messageHTML, QDateTime::currentDateTime(), false, theme_, getActualDirection(message, direction)));
+
+ previousMessageKind_ = PreviousMessageWasPresence;
+}
+
+void QtWebKitChatView::replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour) {
+ replaceLastMessage(chatMessageToHTML(message), timestampBehaviour);
+}
+
+void QtWebKitChatView::addMUCInvitation(const std::string& senderName, const JID& jid, const std::string& reason, const std::string& password, bool direct, bool isImpromptu, bool isContinuation) {
+ if (window_->isWidgetSelected()) {
+ window_->onAllMessagesRead();
+ }
+
+ QString message;
+ if (isImpromptu) {
+ message = QObject::tr("You've been invited to join a chat.") + "\n";
+ } else {
+ message = QObject::tr("You've been invited to enter the %1 room.").arg(P2QSTRING(jid.toString())) + "\n";
+ }
+ QString htmlString = message;
+ if (!reason.empty()) {
+ htmlString += QObject::tr("Reason: %1").arg(P2QSTRING(reason)) + "\n";
+ }
+ if (!direct) {
+ htmlString += QObject::tr("This person may not have really sent this invitation!") + "\n";
+ }
+ htmlString = chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING(htmlString)));
+
+
+ QString id = QString(ButtonMUCInvite + "%1").arg(P2QSTRING(boost::lexical_cast<std::string>(idCounter_++)));
+ htmlString += "<div id='" + id + "'>" +
+ buildChatWindowButton(chatMessageToHTML(ChatWindow::ChatMessage(Q2PSTRING((tr("Accept Invite"))))), ButtonMUCInvite, QtUtilities::htmlEscape(P2QSTRING(jid.toString())), QtUtilities::htmlEscape(P2QSTRING(password)), id, QtUtilities::htmlEscape(isImpromptu ? "true" : "false"), QtUtilities::htmlEscape(isContinuation ? "true" : "false")) +
+ "</div>";
+
+ bool appendToPrevious = appendToPreviousCheck(PreviousMessageWasMUCInvite, senderName, false);
+
+ QString qAvatarPath = "qrc:/icons/avatar.png";
+
+ addMessageBottom(boost::make_shared<MessageSnippet>(htmlString, QtUtilities::htmlEscape(P2QSTRING(senderName)), B2QDATE(boost::posix_time::second_clock::local_time()), qAvatarPath, false, appendToPrevious, theme_, id, ChatSnippet::getDirection(message)));
+ previousMessageWasSelf_ = false;
+ previousSenderName_ = P2QSTRING(senderName);
+ previousMessageKind_ = PreviousMessageWasMUCInvite;
+}
+
+void QtWebKitChatView::setAckState(std::string const& id, ChatWindow::AckState state) {
+ QString xml;
+ switch (state) {
+ case ChatWindow::Pending:
+ xml = "<img src='qrc:/icons/throbber.gif' title='" + tr("This message has not been received by your server yet.") + "'/>";
+ displayReceiptInfo(P2QSTRING(id), false);
+ break;
+ case ChatWindow::Received:
+ xml = "";
+ displayReceiptInfo(P2QSTRING(id), true);
+ break;
+ case ChatWindow::Failed: xml = "<img src='qrc:/icons/error.png' title='" + tr("This message may not have been transmitted.") + "'/>"; break;
+ }
+ setAckXML(P2QSTRING(id), xml);
+}
+
+void QtWebKitChatView::setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) {
+ QString xml;
+ switch (state) {
+ case ChatWindow::ReceiptReceived:
+ xml = "<img src='qrc:/icons/check.png' title='" + tr("The receipt for this message has been received.") + "'/>";
+ break;
+ case ChatWindow::ReceiptRequested:
+ xml = "<img src='qrc:/icons/warn.png' title='" + tr("The receipt for this message has not yet been received. The recipient(s) might not have received this message.") + "'/>";
+ break;
+ case ChatWindow::ReceiptFailed:
+ xml = "<img src='qrc:/icons/error.png' title='" + tr("Failed to transmit message to the receipient(s).") + "'/>";
+ }
+ setReceiptXML(P2QSTRING(id), xml);
+}
+
+bool QtWebKitChatView::appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf) {
+ bool result = previousMessageKind_ == messageKind && ((senderIsSelf && previousMessageWasSelf_) || (!senderIsSelf && !previousMessageWasSelf_&& previousSenderName_ == P2QSTRING(senderName)));
+ if (insertingLastLine_) {
+ insertingLastLine_ = false;
+ return false;
+ }
+ return result;
+}
+
+ChatSnippet::Direction QtWebKitChatView::getActualDirection(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) {
+ if (direction == ChatWindow::DefaultDirection) {
+ return QCoreApplication::translate("QApplication", "QT_LAYOUT_DIRECTION") == "RTL" ? ChatSnippet::RTL : ChatSnippet::LTR;
+ }
+ else {
+ return ChatSnippet::getDirection(message);
+ }
+}
+
+// void QtWebKitChatView::setShowEmoticons(bool value) {
+// showEmoticons_ = value;
+// }
+
+
+}
diff --git a/Swift/QtUI/QtWebKitChatView.h b/Swift/QtUI/QtWebKitChatView.h
new file mode 100644
index 0000000..925ceeb
--- /dev/null
+++ b/Swift/QtUI/QtWebKitChatView.h
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2010-2014 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QString>
+#include <QWidget>
+#include <QList>
+#include <QWebElement>
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+
+#include <Swift/QtUI/ChatSnippet.h>
+#include <Swift/QtUI/QtChatView.h>
+
+class QWebPage;
+class QUrl;
+class QDate;
+
+namespace Swift {
+ class QtWebView;
+ class QtChatTheme;
+ class QtChatWindowJSBridge;
+ class UIEventStream;
+ class QtChatWindow;
+ class QtWebKitChatView : public QtChatView {
+ Q_OBJECT
+
+ public:
+ static const QString ButtonWhiteboardSessionCancel;
+ static const QString ButtonWhiteboardSessionAcceptRequest;
+ static const QString ButtonWhiteboardShowWindow;
+ static const QString ButtonFileTransferCancel;
+ static const QString ButtonFileTransferSetDescription;
+ static const QString ButtonFileTransferSendRequest;
+ static const QString ButtonFileTransferAcceptRequest;
+ static const QString ButtonMUCInvite;
+ public:
+ QtWebKitChatView(QtChatWindow* window, UIEventStream* eventStream, QtChatTheme* theme, QWidget* parent, bool disableAutoScroll = false);
+ ~QtWebKitChatView();
+
+ /** 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) SWIFTEN_OVERRIDE;
+ /** 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) SWIFTEN_OVERRIDE;
+
+ virtual void addSystemMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
+ virtual void addPresenceMessage(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction) SWIFTEN_OVERRIDE;
+
+ virtual void addErrorMessage(const ChatWindow::ChatMessage& message) SWIFTEN_OVERRIDE;
+ virtual void replaceMessage(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) SWIFTEN_OVERRIDE;
+ virtual void replaceWithAction(const ChatWindow::ChatMessage& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight) SWIFTEN_OVERRIDE;
+ void replaceLastMessage(const ChatWindow::ChatMessage& message, const ChatWindow::TimestampBehaviour timestampBehaviour);
+ 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) SWIFTEN_OVERRIDE;
+ virtual void setFileTransferProgress(std::string, const int percentageDone) SWIFTEN_OVERRIDE;
+ virtual void setFileTransferStatus(std::string, const ChatWindow::FileTransferState state, const std::string& msg = "") SWIFTEN_OVERRIDE;
+ 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(const std::string& id, const ChatWindow::WhiteboardSessionState state) SWIFTEN_OVERRIDE;
+ virtual void setMessageReceiptState(const std::string& id, ChatWindow::ReceiptState state) SWIFTEN_OVERRIDE;
+
+ virtual void showEmoticons(bool show) SWIFTEN_OVERRIDE;
+ void addMessageTop(boost::shared_ptr<ChatSnippet> snippet);
+ void addMessageBottom(boost::shared_ptr<ChatSnippet> snippet);
+
+ int getSnippetPositionByDate(const QDate& date); // FIXME : This probably shouldn't have been public
+ void addLastSeenLine();
+
+ private: // previously public, now private
+ void replaceLastMessage(const QString& newMessage, const ChatWindow::TimestampBehaviour timestampBehaviour);
+ void replaceLastMessage(const QString& newMessage, const QString& note);
+ 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);
+ void setFileTransferStatus(QString id, const ChatWindow::FileTransferState state, const QString& msg);
+ void setWhiteboardSessionStatus(QString id, const ChatWindow::WhiteboardSessionState state);
+ void setMUCInvitationJoined(QString id);
+
+ signals:
+ void gotFocus();
+ void fontResized(int);
+ void logCleared();
+ void scrollRequested(int pos);
+ void scrollReachedTop();
+ void scrollReachedBottom();
+
+ public slots:
+ void copySelectionToClipboard();
+ void handleLinkClicked(const QUrl&);
+ void resetView();
+ void resetTopInsertPoint();
+ void increaseFontSize(int numSteps = 1);
+ void decreaseFontSize();
+ void resizeFont(int fontSizeSteps);
+ void scrollToBottom();
+ void handleKeyPressEvent(QKeyEvent* event);
+
+ private slots:
+ void handleViewLoadFinished(bool);
+ void handleFrameSizeChanged();
+ void handleClearRequested();
+ void handleScrollRequested(int dx, int dy, const QRect& rectToScroll);
+ void handleHTMLButtonClicked(QString id, QString arg1, QString arg2, QString arg3, QString arg4, QString arg5);
+
+ private:
+ enum PreviousMessageKind {
+ PreviosuMessageWasNone,
+ PreviousMessageWasMessage,
+ PreviousMessageWasSystem,
+ PreviousMessageWasPresence,
+ PreviousMessageWasFileTransfer,
+ PreviousMessageWasMUCInvite
+ };
+ std::string addMessage(
+ const QString& message,
+ const std::string& senderName,
+ bool senderIsSelf,
+ boost::shared_ptr<SecurityLabel> label,
+ const std::string& avatarPath,
+ const QString& style,
+ const boost::posix_time::ptime& time,
+ const HighlightAction& highlight,
+ ChatSnippet::Direction direction);
+ void replaceMessage(
+ const QString& message,
+ const std::string& id,
+ const boost::posix_time::ptime& time,
+ const QString& style,
+ const HighlightAction& highlight);
+ bool appendToPreviousCheck(PreviousMessageKind messageKind, const std::string& senderName, bool senderIsSelf);
+ static ChatSnippet::Direction getActualDirection(const ChatWindow::ChatMessage& message, ChatWindow::Direction direction);
+ QString getHighlightSpanStart(const std::string& text, const std::string& background);
+ QString getHighlightSpanStart(const HighlightAction& highlight);
+ QString chatMessageToHTML(const ChatWindow::ChatMessage& message);
+ static QString buildChatWindowButton(const QString& name, const QString& id, const QString& arg1 = QString(), const QString& arg2 = QString(), const QString& arg3 = QString(), const QString& arg4 = QString(), const QString& arg5 = QString());
+
+ private:
+ void headerEncode();
+ void messageEncode();
+ void addToDOM(boost::shared_ptr<ChatSnippet> snippet);
+ QWebElement snippetToDOM(boost::shared_ptr<ChatSnippet> snippet);
+
+ QtChatWindow* window_;
+ UIEventStream* eventStream_;
+ bool viewReady_;
+ bool isAtBottom_;
+ bool topMessageAdded_;
+ int scrollBarMaximum_;
+ QtWebView* webView_;
+ QWebPage* webPage_;
+ int fontSizeSteps_;
+ QtChatTheme* theme_;
+ QWebElement newInsertPoint_;
+ QWebElement topInsertPoint_;
+ QWebElement lineSeparator_;
+ QWebElement lastElement_;
+ QWebElement firstElement_;
+ QWebElement document_;
+ bool disableAutoScroll_;
+ QtChatWindowJSBridge* jsBridge;
+ PreviousMessageKind previousMessageKind_;
+ bool previousMessageWasSelf_;
+ bool showEmoticons_;
+ bool insertingLastLine_;
+ int idCounter_;
+ QString previousSenderName_;
+ std::map<QString, QString> descriptions_;
+ };
+}
diff --git a/Swift/QtUI/QtWebView.cpp b/Swift/QtUI/QtWebView.cpp
index 388f06a..33fa817 100644
--- a/Swift/QtUI/QtWebView.cpp
+++ b/Swift/QtUI/QtWebView.cpp
@@ -10,5 +10,7 @@
#include <QKeyEvent>
#include <QFocusEvent>
+#include <boost/numeric/conversion/cast.hpp>
#include <QMenu>
+#include <Swiften/Base/Log.h>
namespace Swift {
@@ -18,4 +20,7 @@ QtWebView::QtWebView(QWidget* parent) : QWebView(parent), fontSizeIsMinimal(fals
filteredActions.push_back(QWebPage::CopyImageToClipboard);
filteredActions.push_back(QWebPage::Copy);
+ if (Log::getLogLevel() == Log::debug) {
+ filteredActions.push_back(QWebPage::InspectElement);
+ }
}
@@ -31,5 +36,5 @@ void QtWebView::keyPressEvent(QKeyEvent* event) {
event->text(),
event->isAutoRepeat(),
- event->count());
+ boost::numeric_cast<unsigned short>(event->count()));
QWebView::keyPressEvent(translatedEvent);
delete translatedEvent;
diff --git a/Swift/QtUI/QtWin32NotifierWindow.h b/Swift/QtUI/QtWin32NotifierWindow.h
index b8d9c77..cd43cf2 100644
--- a/Swift/QtUI/QtWin32NotifierWindow.h
+++ b/Swift/QtUI/QtWin32NotifierWindow.h
@@ -24,5 +24,5 @@ namespace Swift {
virtual HWND getID() const {
- return winId();
+ return (HWND) winId();
}
};
diff --git a/Swift/QtUI/QtXMLConsoleWidget.cpp b/Swift/QtUI/QtXMLConsoleWidget.cpp
index e674df8..f8ab28e 100644
--- a/Swift/QtUI/QtXMLConsoleWidget.cpp
+++ b/Swift/QtUI/QtXMLConsoleWidget.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,4 +7,6 @@
#include "QtXMLConsoleWidget.h"
+#include <string>
+
#include <QCloseEvent>
#include <QTextEdit>
@@ -14,6 +16,7 @@
#include <QCheckBox>
-#include "QtSwiftUtil.h"
-#include <string>
+#include <Swiften/Base/format.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -76,9 +79,13 @@ void QtXMLConsoleWidget::closeEvent(QCloseEvent* event) {
void QtXMLConsoleWidget::handleDataRead(const SafeByteArray& data) {
- appendTextIfEnabled(std::string(tr("<!-- IN -->").toUtf8()) + "\n" + safeByteArrayToString(data) + "\n", QColor(33,98,33));
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ std::string tag = Q2PSTRING(tr("<!-- IN %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
+ appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(33,98,33));
}
void QtXMLConsoleWidget::handleDataWritten(const SafeByteArray& data) {
- appendTextIfEnabled(std::string(tr("<!-- OUT -->").toUtf8()) + "\n" + safeByteArrayToString(data) + "\n", QColor(155,1,0));
+ boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
+ std::string tag = Q2PSTRING(tr("<!-- OUT %1 -->").arg(P2QSTRING(boost::posix_time::to_iso_extended_string(now))));
+ appendTextIfEnabled(tag + "\n" + safeByteArrayToString(data) + "\n", QColor(155,1,0));
}
@@ -97,5 +104,9 @@ void QtXMLConsoleWidget::appendTextIfEnabled(const std::string& data, const QCol
cursor.endEditBlock();
- if (scrollToBottom) {
+ // Checking for the scrollbar again, because it could have appeared after inserting text.
+ // In practice, I suspect that the scrollbar is always there, but hidden, but since we were
+ // explicitly testing for this already above, I'm leaving the code in.
+ scrollBar = textEdit->verticalScrollBar();
+ if (scrollToBottom && scrollBar) {
scrollBar->setValue(scrollBar->maximum());
}
diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp
index a575cb0..776d90c 100644
--- a/Swift/QtUI/Roster/DelegateCommons.cpp
+++ b/Swift/QtUI/Roster/DelegateCommons.cpp
@@ -15,8 +15,10 @@ namespace Swift {
void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags) {
QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic));
+ painter->setClipRect(region);
painter->drawText(region, flags, adjustedText.simplified());
+ painter->setClipping(false);
}
-void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const {
+void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, bool isIdle, int unreadCount, bool compact) const {
painter->save();
QRect fullRegion(option.rect);
@@ -30,4 +32,5 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem
QRect presenceIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth, fullRegion.height() - verticalMargin));
+ QRect idleIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth*2, fullRegion.height() - verticalMargin));
int calculatedAvatarSize = presenceIconRegion.height();
//This overlaps the presenceIcon, so must be painted first
@@ -52,4 +55,8 @@ void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem
presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
+ if (isIdle) {
+ idleIcon.paint(painter, idleIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
+ }
+
QFontMetrics nameMetrics(nameFont);
painter->setFont(nameFont);
diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h
index 8732598..0684410 100644
--- a/Swift/QtUI/Roster/DelegateCommons.h
+++ b/Swift/QtUI/Roster/DelegateCommons.h
@@ -18,5 +18,5 @@ namespace Swift {
class DelegateCommons {
public:
- DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()) {
+ DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()), idleIcon(QIcon(":/icons/zzz.png")) {
detailFontSizeDrop = nameFont.pointSize() >= 10 ? 2 : 0;
detailFont.setStyle(QFont::StyleItalic);
@@ -27,5 +27,5 @@ namespace Swift {
QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index, bool compact) const;
- void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const;
+ void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, bool isIdle, int unreadCount, bool compact) const;
int detailFontSizeDrop;
@@ -39,4 +39,5 @@ namespace Swift {
static const int presenceIconWidth;
static const int unreadCountSize;
+ QIcon idleIcon;
};
}
diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp
new file mode 100644
index 0000000..64eb312
--- /dev/null
+++ b/Swift/QtUI/Roster/QtFilterWidget.cpp
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <QEvent>
+#include <QKeyEvent>
+#include <QLayout>
+#include <QString>
+#include <QVBoxLayout>
+
+#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/QtUI/QtClosableLineEdit.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/Roster/QtFilterWidget.h>
+
+namespace Swift {
+
+QtFilterWidget::QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout) : QWidget(parent), treeView_(treeView), eventStream_(eventStream), fuzzyRosterFilter_(0), isModifierSinglePressed_(false) {
+ int targetIndex = layout->indexOf(treeView);
+
+ QVBoxLayout* vboxLayout = new QVBoxLayout(this);
+ vboxLayout->setSpacing(0);
+ vboxLayout->setContentsMargins(0,0,0,0);
+
+ filterLineEdit_ = new QtClosableLineEdit(this);
+ filterLineEdit_->hide();
+ vboxLayout->addWidget(filterLineEdit_);
+
+ vboxLayout->addWidget(treeView);
+ setLayout(vboxLayout);
+ layout->insertWidget(targetIndex, this);
+
+ filterLineEdit_->installEventFilter(this);
+ treeView->installEventFilter(this);
+
+ sourceModel_ = treeView_->model();
+}
+
+QtFilterWidget::~QtFilterWidget() {
+
+}
+
+bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {
+ if (event->type() == QEvent::KeyPress ||
+ event->type() == QEvent::KeyRelease ||
+ // InputMethodQuery got introduced in Qt 5.
+#if QT_VERSION >= 0x050000
+ event->type() == QEvent::InputMethodQuery ||
+#endif
+ event->type() == QEvent::InputMethod) {
+ event->ignore();
+ QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
+ if (keyEvent) {
+ if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) {
+ return false;
+ } else if ((keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) && filterLineEdit_->text().isEmpty()) {
+ return false;
+ } else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyPress) {
+ isModifierSinglePressed_ = true;
+ } else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyRelease && isModifierSinglePressed_) {
+ QPoint itemOffset(2,2);
+ QPoint contextMenuPosition = treeView_->visualRect(treeView_->currentIndex()).topLeft() + itemOffset;;
+ QApplication::postEvent(treeView_, new QContextMenuEvent(QContextMenuEvent::Keyboard, contextMenuPosition, treeView_->mapToGlobal(contextMenuPosition)));
+ return true;
+ } else if (keyEvent->key() == Qt::Key_Return) {
+ JID target = treeView_->selectedJID();
+ if (target.isValid()) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
+ }
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ } else if (keyEvent->key() == Qt::Key_Escape) {
+ filterLineEdit_->setText("");
+ } else {
+ isModifierSinglePressed_ = false;
+ }
+ }
+
+ filterLineEdit_->event(event);
+
+ if (event->type() == QEvent::KeyRelease) {
+ updateRosterFilters();
+ }
+ return true;
+ }
+ return false;
+}
+
+void QtFilterWidget::popAllFilters() {
+ std::vector<RosterFilter*> filters = treeView_->getRoster()->getFilters();
+ foreach(RosterFilter* filter, filters) {
+ filters_.push_back(filter);
+ treeView_->getRoster()->removeFilter(filter);
+ }
+ treeView_->getRoster()->onFilterAdded.connect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.connect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
+}
+
+void QtFilterWidget::pushAllFilters() {
+ treeView_->getRoster()->onFilterAdded.disconnect(boost::bind(&QtFilterWidget::handleFilterAdded, this, _1));
+ treeView_->getRoster()->onFilterRemoved.disconnect(boost::bind(&QtFilterWidget::handleFilterRemoved, this, _1));
+ foreach(RosterFilter* filter, filters_) {
+ treeView_->getRoster()->addFilter(filter);
+ }
+ filters_.clear();
+}
+
+void QtFilterWidget::updateRosterFilters() {
+ if (fuzzyRosterFilter_) {
+ if (filterLineEdit_->text().isEmpty()) {
+ // remove currently installed search filter and put old filters back
+ treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
+ delete fuzzyRosterFilter_;
+ fuzzyRosterFilter_ = NULL;
+ pushAllFilters();
+ } else {
+ // remove currently intsalled search filter and put new search filter in place
+ updateSearchFilter();
+ }
+ } else {
+ if (!filterLineEdit_->text().isEmpty()) {
+ // remove currently installed filters and put a search filter in place
+ popAllFilters();
+ updateSearchFilter();
+ }
+ }
+ filterLineEdit_->setVisible(!filterLineEdit_->text().isEmpty());
+}
+
+void QtFilterWidget::updateSearchFilter() {
+ if (fuzzyRosterFilter_) {
+ treeView_->getRoster()->removeFilter(fuzzyRosterFilter_);
+ delete fuzzyRosterFilter_;
+ fuzzyRosterFilter_ = NULL;
+ }
+ fuzzyRosterFilter_ = new FuzzyRosterFilter(Q2PSTRING(filterLineEdit_->text()));
+ treeView_->getRoster()->addFilter(fuzzyRosterFilter_);
+ treeView_->setCurrentIndex(sourceModel_->index(0, 0, sourceModel_->index(0,0)));
+}
+
+void QtFilterWidget::handleFilterAdded(RosterFilter* filter) {
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
+}
+
+void QtFilterWidget::handleFilterRemoved(RosterFilter* filter) {
+ /* make sure we don't end up adding this one back in later */
+ filters_.erase(std::remove(filters_.begin(), filters_.end(), filter), filters_.end());
+ if (filter != fuzzyRosterFilter_) {
+ filterLineEdit_->setText("");
+ updateRosterFilters();
+ }
+}
+
+}
diff --git a/Swift/QtUI/Roster/QtFilterWidget.h b/Swift/QtUI/Roster/QtFilterWidget.h
new file mode 100644
index 0000000..d0307ea
--- /dev/null
+++ b/Swift/QtUI/Roster/QtFilterWidget.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+
+#include <QBoxLayout>
+#include <QWidget>
+
+#include <Swift/Controllers/Roster/RosterFilter.h>
+#include <Swift/Controllers/Roster/FuzzyRosterFilter.h>
+
+#include <Swift/QtUI/Roster/QtTreeWidget.h>
+
+namespace Swift {
+class UIEventStream;
+class QtClosableLineEdit;
+class QtFilterWidget : public QWidget {
+ Q_OBJECT
+ public:
+ QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout = 0);
+ virtual ~QtFilterWidget();
+
+ protected:
+ bool eventFilter(QObject*, QEvent* event);
+
+ private:
+ void popAllFilters();
+ void pushAllFilters();
+
+ void updateRosterFilters();
+ void updateSearchFilter();
+
+ void handleFilterAdded(RosterFilter* filter);
+ void handleFilterRemoved(RosterFilter* filter);
+
+ private:
+ QtClosableLineEdit* filterLineEdit_;
+ QtTreeWidget* treeView_;
+ UIEventStream* eventStream_;
+ std::vector<RosterFilter*> filters_;
+ QAbstractItemModel* sourceModel_;
+ FuzzyRosterFilter* fuzzyRosterFilter_;
+ bool isModifierSinglePressed_;
+};
+
+}
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
index 5d26c46..4f1baf3 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2011-2012 Kevin Smith
+ * Copyright (c) 2011-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -6,5 +6,5 @@
-#include "Roster/QtOccupantListWidget.h"
+#include <Swift/QtUI/Roster/QtOccupantListWidget.h>
#include <QContextMenuEvent>
@@ -13,12 +13,13 @@
#include <QInputDialog>
-#include "Swift/Controllers/Roster/ContactRosterItem.h"
-#include "Swift/Controllers/Roster/GroupRosterItem.h"
-#include "Swift/Controllers/UIEvents/UIEventStream.h"
-#include "QtSwiftUtil.h"
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
+#include <Swift/Controllers/Roster/GroupRosterItem.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QtTreeWidget(eventStream, settings, parent) {
+QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent) : QtTreeWidget(eventStream, settings, privateMessageTarget, parent) {
}
@@ -59,4 +60,5 @@ void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) {
case ChatWindow::MakeVisitor: text = tr("Remove voice"); break;
case ChatWindow::AddContact: text = tr("Add to contacts"); break;
+ case ChatWindow::ShowProfile: text = tr("Show profile"); break;
}
QAction* action = contextMenu.addAction(text);
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h
index 729115a..c944658 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.h
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2011-2012 Kevin Smith
+ * Copyright (c) 2011-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,8 +7,9 @@
#pragma once
-#include "Swift/QtUI/Roster/QtTreeWidget.h"
+#include <Swift/QtUI/Roster/QtTreeWidget.h>
-#include "Swiften/Base/boost_bsignals.h"
-#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include <Swiften/Base/boost_bsignals.h>
+
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
@@ -18,5 +19,5 @@ class QtOccupantListWidget : public QtTreeWidget {
Q_OBJECT
public:
- QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent = 0);
+ QtOccupantListWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget privateMessageTarget, QWidget* parent = NULL);
virtual ~QtOccupantListWidget();
void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions);
diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp
index e3fee24..8c296e5 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.cpp
+++ b/Swift/QtUI/Roster/QtRosterWidget.cpp
@@ -1,28 +1,33 @@
/*
- * Copyright (c) 2011 Kevin Smith
+ * Copyright (c) 2011-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Roster/QtRosterWidget.h"
+#include <Swift/QtUI/Roster/QtRosterWidget.h>
#include <QContextMenuEvent>
#include <QMenu>
+#include <QMessageBox>
#include <QInputDialog>
#include <QFileDialog>
+#include <QPushButton>
-#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h"
-#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h"
-#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h"
-#include "Swift/Controllers/UIEvents/SendFileUIEvent.h"
-#include "QtContactEditWindow.h"
-#include "Swift/Controllers/Roster/ContactRosterItem.h"
-#include "Swift/Controllers/Roster/GroupRosterItem.h"
-#include "Swift/Controllers/UIEvents/UIEventStream.h"
-#include "QtSwiftUtil.h"
+#include <Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h>
+#include <Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h>
+#include <Swift/Controllers/UIEvents/RenameGroupUIEvent.h>
+#include <Swift/Controllers/UIEvents/SendFileUIEvent.h>
+#include <Swift/Controllers/UIEvents/RequestWhiteboardUIEvent.h>
+#include <Swift/Controllers/UIEvents/ShowProfileForRosterItemUIEvent.h>
+#include <Swift/Controllers/UIEvents/RequestChangeBlockStateUIEvent.h>
+#include <Swift/QtUI/QtContactEditWindow.h>
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
+#include <Swift/Controllers/Roster/GroupRosterItem.h>
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QtTreeWidget(eventStream, settings, parent) {
+QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QtTreeWidget(eventStream, settings, MessageDefaultJID, parent) {
}
@@ -55,10 +60,35 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
QMenu contextMenu;
if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
- QAction* editContact = contextMenu.addAction(tr("Edit"));
+ QAction* editContact = contextMenu.addAction(tr("Edit…"));
+ editContact->setEnabled(isOnline());
QAction* removeContact = contextMenu.addAction(tr("Remove"));
+ removeContact->setEnabled(isOnline());
+ QAction* showProfileForContact = contextMenu.addAction(tr("Show Profile"));
+
+ QAction* unblockContact = NULL;
+ if (contact->blockState() == ContactRosterItem::IsBlocked ||
+ contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ unblockContact = contextMenu.addAction(tr("Unblock"));
+ unblockContact->setEnabled(isOnline());
+ }
+
+ QAction* blockContact = NULL;
+ if (contact->blockState() == ContactRosterItem::IsUnblocked) {
+ blockContact = contextMenu.addAction(tr("Block"));
+ blockContact->setEnabled(isOnline());
+ }
+
#ifdef SWIFT_EXPERIMENTAL_FT
QAction* sendFile = NULL;
if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
sendFile = contextMenu.addAction(tr("Send File"));
+ sendFile->setEnabled(isOnline());
+ }
+#endif
+#ifdef SWIFT_EXPERIMENTAL_WB
+ QAction* startWhiteboardChat = NULL;
+ if (contact->supportsFeature(ContactRosterItem::WhiteboardFeature)) {
+ startWhiteboardChat = contextMenu.addAction(tr("Start Whiteboard Chat"));
+ startWhiteboardChat->setEnabled(isOnline());
}
#endif
@@ -72,4 +102,24 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
}
}
+ else if (result == showProfileForContact) {
+ eventStream_->send(boost::make_shared<ShowProfileForRosterItemUIEvent>(contact->getJID()));
+ }
+ else if (unblockContact && result == unblockContact) {
+ if (contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ QMessageBox messageBox(QMessageBox::Question, tr("Swift"), tr("%2 is currently blocked because of a block on all users of the %1 service.\n %2 cannot be unblocked individually; do you want to unblock all %1 users?").arg(P2QSTRING(contact->getJID().getDomain()), P2QSTRING(contact->getJID().toString())), QMessageBox::NoButton, this);
+ QPushButton* unblockDomainButton = messageBox.addButton(tr("Unblock %1 domain").arg(P2QSTRING(contact->getJID().getDomain())), QMessageBox::AcceptRole);
+ messageBox.addButton(QMessageBox::Abort);
+
+ messageBox.exec();
+ if (messageBox.clickedButton() == unblockDomainButton) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID().getDomain()));
+ }
+ } else {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Unblocked, contact->getJID()));
+ }
+ }
+ else if (blockContact && result == blockContact) {
+ eventStream_->send(boost::make_shared<RequestChangeBlockStateUIEvent>(RequestChangeBlockStateUIEvent::Blocked, contact->getJID()));
+ }
#ifdef SWIFT_EXPERIMENTAL_FT
else if (sendFile && result == sendFile) {
@@ -80,7 +130,18 @@ void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
}
#endif
+#ifdef SWIFT_EXPERIMENTAL_WB
+ else if (startWhiteboardChat && result == startWhiteboardChat) {
+ eventStream_->send(boost::make_shared<RequestWhiteboardUIEvent>(contact->getJID()));
+ }
+#endif
}
else if (GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item)) {
QAction* renameGroupAction = contextMenu.addAction(tr("Rename"));
+ if (P2QSTRING(group->getDisplayName()) == tr("Contacts")) {
+ renameGroupAction->setEnabled(false);
+ }
+ else {
+ renameGroupAction->setEnabled(isOnline());
+ }
QAction* result = contextMenu.exec(event->globalPos());
if (result == renameGroupAction) {
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp
index 5fdf138..f296088 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.cpp
+++ b/Swift/QtUI/Roster/QtTreeWidget.cpp
@@ -1,9 +1,9 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "Roster/QtTreeWidget.h"
+#include <Swift/QtUI/Roster/QtTreeWidget.h>
#include <boost/smart_ptr/make_shared.hpp>
@@ -11,6 +11,12 @@
#include <QUrl>
+#include <QMimeData>
+#include <QObject>
+#include <QLabel>
+#include <QTimer>
+#include <QToolTip>
#include <Swiften/Base/Platform.h>
+
#include <Swift/Controllers/Roster/ContactRosterItem.h>
#include <Swift/Controllers/Roster/GroupRosterItem.h>
@@ -18,14 +24,16 @@
#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
#include <Swift/Controllers/UIEvents/SendFileUIEvent.h>
-#include <QtSwiftUtil.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
+
#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/Roster/RosterModel.h>
+#include <QtSwiftUtil.h>
namespace Swift {
-QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent) : QTreeView(parent) {
+QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent) : QTreeView(parent), tooltipShown_(false), messageTarget_(messageTarget) {
eventStream_ = eventStream;
settings_ = settings;
- model_ = new RosterModel(this);
+ model_ = new RosterModel(this, settings_->getSetting(QtUISettingConstants::USE_SCREENREADER));
setModel(model_);
delegate_ = new RosterDelegate(this, settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
@@ -42,4 +50,5 @@ QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, SettingsProvider* setting
setAcceptDrops(true);
#endif
+ setDragEnabled(true);
setRootIsDecorated(true);
connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&)));
@@ -65,4 +74,12 @@ void QtTreeWidget::handleSettingChanged(const std::string& setting) {
}
+void QtTreeWidget::handleRefreshTooltip() {
+ if (tooltipShown_) {
+ QPoint position = QCursor::pos();
+ QModelIndex index = indexAt(mapFromGlobal(position));
+ QToolTip::showText(position, model_->data(index, Qt::ToolTipRole).toString());
+ }
+}
+
void QtTreeWidget::setRosterModel(Roster* roster) {
roster_ = roster;
@@ -71,4 +88,9 @@ void QtTreeWidget::setRosterModel(Roster* roster) {
}
+void QtTreeWidget::refreshTooltip() {
+ // Qt needs some time to emit the events we need to detect tooltip's visibility correctly; 20 ms should be enough
+ QTimer::singleShot(20, this, SLOT(handleRefreshTooltip()));
+}
+
QtTreeWidgetItem* QtTreeWidget::getRoot() {
return treeRoot_;
@@ -116,10 +138,8 @@ void QtTreeWidget::currentChanged(const QModelIndex& current, const QModelIndex&
}
-
void QtTreeWidget::handleItemActivated(const QModelIndex& index) {
- RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
- ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
- if (contact) {
- eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(contact->getJID())));
+ JID target = jidFromIndex(index);
+ if (target.isValid()) {
+ eventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(target)));
}
}
@@ -157,5 +177,22 @@ void QtTreeWidget::dragMoveEvent(QDragMoveEvent* event) {
}
}
- event->ignore();
+ QTreeView::dragMoveEvent(event);
+}
+
+bool QtTreeWidget::event(QEvent* event) {
+ QChildEvent* childEvent = NULL;
+ if ((childEvent = dynamic_cast<QChildEvent*>(event))) {
+ if (childEvent->polished()) {
+ if (dynamic_cast<QLabel*>(childEvent->child())) {
+ tooltipShown_ = true;
+ }
+ }
+ else if (childEvent->removed()) {
+ if (childEvent->child()->objectName() == "qtooltip_label") {
+ tooltipShown_ = false;
+ }
+ }
+ }
+ return QAbstractItemView::event(event);
}
@@ -192,3 +229,35 @@ void QtTreeWidget::show() {
}
+void QtTreeWidget::setMessageTarget(MessageTarget messageTarget) {
+ messageTarget_ = messageTarget;
+}
+
+JID QtTreeWidget::jidFromIndex(const QModelIndex& index) const {
+ JID target;
+ if (messageTarget_ == MessageDisplayJID) {
+ target = JID(Q2PSTRING(index.data(DisplayJIDRole).toString()));
+ target = target.toBare();
+ }
+ if (!target.isValid()) {
+ target = JID(Q2PSTRING(index.data(JIDRole).toString()));
+ }
+ return target;
+}
+
+JID QtTreeWidget::selectedJID() const {
+ QModelIndexList list = selectedIndexes();
+ if (list.size() != 1) {
+ return JID();
+ }
+ return jidFromIndex(list[0]);
+}
+
+void QtTreeWidget::setOnline(bool isOnline) {
+ isOnline_ = isOnline;
+}
+
+bool QtTreeWidget::isOnline() const {
+ return isOnline_;
+}
+
}
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index 7c10a6a..12d34f5 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,11 +7,14 @@
#pragma once
-#include <QTreeView>
-#include <QModelIndex>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDragMoveEvent>
-#include "Swift/QtUI/Roster/RosterModel.h"
-#include "Swift/QtUI/Roster/RosterDelegate.h"
+#include <QModelIndex>
+#include <QTreeView>
+
+#include <Swift/QtUI/Roster/RosterDelegate.h>
+#include <Swift/QtUI/Roster/RosterModel.h>
+
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
namespace Swift {
@@ -22,5 +25,7 @@ class QtTreeWidget : public QTreeView{
Q_OBJECT
public:
- QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, QWidget* parent = 0);
+ enum MessageTarget {MessageDefaultJID, MessageDisplayJID};
+
+ QtTreeWidget(UIEventStream* eventStream, SettingsProvider* settings, MessageTarget messageTarget, QWidget* parent = 0);
~QtTreeWidget();
void show();
@@ -28,4 +33,11 @@ class QtTreeWidget : public QTreeView{
void setRosterModel(Roster* roster);
Roster* getRoster() {return roster_;}
+ void refreshTooltip();
+ void setMessageTarget(MessageTarget messageTarget);
+ JID jidFromIndex(const QModelIndex& index) const;
+ JID selectedJID() const;
+ void setOnline(bool isOnline);
+
+ public:
boost::signal<void (RosterItem*)> onSomethingSelectedChanged;
@@ -37,13 +49,17 @@ class QtTreeWidget : public QTreeView{
void handleClicked(const QModelIndex&);
void handleSettingChanged(const std::string& setting);
+ void handleRefreshTooltip();
+
protected:
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
void dragMoveEvent(QDragMoveEvent* event);
-
- protected:
+ bool event(QEvent* event);
QModelIndexList getSelectedIndexes() const;
+ bool isOnline() const;
+
private:
void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
+
protected slots:
virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
@@ -57,4 +73,7 @@ class QtTreeWidget : public QTreeView{
QtTreeWidgetItem* treeRoot_;
SettingsProvider* settings_;
+ bool tooltipShown_;
+ MessageTarget messageTarget_;
+ bool isOnline_;
};
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index 7e6428b..aef588c 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -36,4 +36,5 @@ RosterDelegate::~RosterDelegate() {
void RosterDelegate::setCompact(bool compact) {
compact_ = compact;
+ emit sizeHintChanged(QModelIndex());
}
@@ -74,7 +75,8 @@ void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem&
? index.data(PresenceIconRole).value<QIcon>()
: QIcon(":/icons/offline.png");
+ bool isIdle = index.data(IdleRole).isValid() ? index.data(IdleRole).toBool() : false;
QString name = index.data(Qt::DisplayRole).toString();
QString statusText = index.data(StatusTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0, compact_);
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, isIdle, 0, compact_);
}
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 1fc20dd..730ffbb 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -1,9 +1,9 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "RosterModel.h"
+#include <Swift/QtUI/Roster/RosterModel.h>
#include <boost/bind.hpp>
@@ -11,21 +11,28 @@
#include <QColor>
#include <QIcon>
+#include <QMimeData>
#include <qdebug.h>
-#include "Swiften/Elements/StatusShow.h"
-#include "Swift/Controllers/Roster/ContactRosterItem.h"
-#include "Swift/Controllers/Roster/GroupRosterItem.h"
+#include <Swiften/Elements/StatusShow.h>
+#include <Swiften/Base/Path.h>
+
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
+#include <Swift/Controllers/Roster/GroupRosterItem.h>
#include <Swift/Controllers/StatusUtil.h>
-#include "QtSwiftUtil.h"
-#include "Swift/QtUI/Roster/QtTreeWidget.h"
+#include <Swift/QtUI/Roster/QtTreeWidget.h>
+#include <Swift/QtUI/Roster/RosterTooltip.h>
+#include <Swift/QtUI/QtResourceHelper.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
-RosterModel::RosterModel(QtTreeWidget* view) : view_(view) {
- roster_ = NULL;
+RosterModel::RosterModel(QtTreeWidget* view, bool screenReaderMode) : roster_(NULL), view_(view), screenReader_(screenReaderMode) {
+ const int tooltipAvatarSize = 96; // maximal suggested size according to XEP-0153
+ cachedImageScaler_ = new QtScaledAvatarCache(tooltipAvatarSize);
}
RosterModel::~RosterModel() {
+ delete cachedImageScaler_;
}
@@ -41,5 +48,6 @@ void RosterModel::setRoster(Roster* roster) {
void RosterModel::reLayout() {
//emit layoutChanged();
- reset();
+ beginResetModel();
+ endResetModel(); // TODO: Not sure if this isn't too early?
if (!roster_) {
return;
@@ -61,5 +69,14 @@ void RosterModel::handleDataChanged(RosterItem* item) {
if (modelIndex.isValid()) {
emit dataChanged(modelIndex, modelIndex);
+ view_->refreshTooltip();
+ }
+}
+
+Qt::ItemFlags RosterModel::flags(const QModelIndex& index) const {
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (dynamic_cast<GroupRosterItem*>(getItem(index)) == NULL) {
+ flags |= Qt::ItemIsDragEnabled;
}
+ return flags;
}
@@ -77,5 +94,5 @@ QVariant RosterModel::data(const QModelIndex& index, int role) const {
switch (role) {
- case Qt::DisplayRole: return P2QSTRING(item->getDisplayName());
+ case Qt::DisplayRole: return getScreenReaderTextOr(item, P2QSTRING(item->getDisplayName()));
case Qt::TextColorRole: return getTextColor(item);
case Qt::BackgroundColorRole: return getBackgroundColor(item);
@@ -85,8 +102,26 @@ QVariant RosterModel::data(const QModelIndex& index, int role) const {
case PresenceIconRole: return getPresenceIcon(item);
case ChildCountRole: return getChildCount(item);
+ case IdleRole: return getIsIdle(item);
+ case JIDRole: return getJID(item);
+ case DisplayJIDRole: return getDisplayJID(item);
default: return QVariant();
}
}
+QString RosterModel::getScreenReaderTextOr(RosterItem* item, const QString& alternative) const {
+ QString name = P2QSTRING(item->getDisplayName());
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ if (contact && screenReader_) {
+ name += ": " + P2QSTRING(statusShowTypeToFriendlyName(contact->getStatusShow()));
+ if (!contact->getStatusText().empty()) {
+ name += " (" + P2QSTRING(contact->getStatusText()) + ")";
+ }
+ return name;
+ }
+ else {
+ return alternative;
+ }
+}
+
int RosterModel::getChildCount(RosterItem* item) const {
GroupRosterItem* group = dynamic_cast<GroupRosterItem*>(item);
@@ -94,4 +129,9 @@ int RosterModel::getChildCount(RosterItem* item) const {
}
+bool RosterModel::getIsIdle(RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ return contact ? !contact->getIdleText().empty() : false;
+}
+
QColor RosterModel::intToColor(int color) const {
return QColor(
@@ -125,11 +165,5 @@ QString RosterModel::getToolTip(RosterItem* item) const {
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
if (contact) {
- if (contact->getDisplayJID().isValid()) {
- tip += "\n" + P2QSTRING(contact->getDisplayJID().toBare().toString());
- }
- tip += "\n " + P2QSTRING(statusShowTypeToFriendlyName(contact->getStatusShow()));
- if (!getStatusText(item).isEmpty()) {
- tip += ": " + getStatusText(item);
- }
+ return RosterTooltip::buildDetailedTooltip(contact, cachedImageScaler_);
}
return tip;
@@ -141,5 +175,5 @@ QString RosterModel::getAvatar(RosterItem* item) const {
return "";
}
- return QString(contact->getAvatarPath().c_str());
+ return P2QSTRING(pathToString(contact->getAvatarPath()));
}
@@ -150,17 +184,27 @@ QString RosterModel::getStatusText(RosterItem* item) const {
}
+QString RosterModel::getJID(RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ return contact ? P2QSTRING(contact->getJID().toString()) : QString();
+}
+
+QString RosterModel::getDisplayJID(RosterItem* item) const {
+ ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
+ QString result = contact ? P2QSTRING(contact->getDisplayJID().toString()) : QString();
+ if (result.isEmpty()) {
+ result = getJID(item);
+ }
+ return result;
+}
+
QIcon RosterModel::getPresenceIcon(RosterItem* item) const {
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
if (!contact) return QIcon();
- QString iconString;
- switch (contact->getStatusShow()) {
- case StatusShow::Online: iconString = "online";break;
- case StatusShow::Away: iconString = "away";break;
- case StatusShow::XA: iconString = "away";break;
- case StatusShow::FFC: iconString = "online";break;
- case StatusShow::DND: iconString = "dnd";break;
- case StatusShow::None: iconString = "offline";break;
+ if (contact->blockState() == ContactRosterItem::IsBlocked ||
+ contact->blockState() == ContactRosterItem::IsDomainBlocked) {
+ return QIcon(":/icons/stop.png");
}
- return QIcon(":/icons/" + iconString + ".png");
+
+ return QIcon(statusShowTypeToIconPath(contact->getStatusShow()));
}
@@ -216,3 +260,19 @@ int RosterModel::rowCount(const QModelIndex& parent) const {
}
+QMimeData* RosterModel::mimeData(const QModelIndexList& indexes) const {
+ QMimeData* data = QAbstractItemModel::mimeData(indexes);
+
+ ContactRosterItem *item = dynamic_cast<ContactRosterItem*>(getItem(indexes.first()));
+ if (item == NULL) {
+ return data;
+ }
+
+ /* only a single JID in this list */
+ QByteArray itemData;
+ QDataStream dataStream(&itemData, QIODevice::WriteOnly);
+ dataStream << P2QSTRING(item->getJID().toString());
+ data->setData("application/vnd.swift.contact-jid-list", itemData);
+ return data;
+}
+
}
diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h
index bd34e9c..2b05044 100644
--- a/Swift/QtUI/Roster/RosterModel.h
+++ b/Swift/QtUI/Roster/RosterModel.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -7,9 +7,11 @@
#pragma once
-#include "Swift/Controllers/Roster/Roster.h"
-
#include <QAbstractItemModel>
#include <QList>
+#include <Swift/Controllers/Roster/Roster.h>
+
+#include <Swift/QtUI/QtScaledAvatarCache.h>
+
namespace Swift {
enum RosterRoles {
@@ -19,4 +21,7 @@ namespace Swift {
StatusShowTypeRole = Qt::UserRole + 3,
ChildCountRole = Qt::UserRole + 4,
+ IdleRole = Qt::UserRole + 5,
+ JIDRole = Qt::UserRole + 6,
+ DisplayJIDRole = Qt::UserRole + 7
};
@@ -26,7 +31,8 @@ namespace Swift {
Q_OBJECT
public:
- RosterModel(QtTreeWidget* view);
+ RosterModel(QtTreeWidget* view, bool screenReaderMode);
~RosterModel();
void setRoster(Roster* swiftRoster);
+ Qt::ItemFlags flags(const QModelIndex& index) const;
int columnCount(const QModelIndex& parent = QModelIndex()) const;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
@@ -35,4 +41,6 @@ namespace Swift {
QModelIndex parent(const QModelIndex& index) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ QMimeData* mimeData(const QModelIndexList& indexes) const;
+
signals:
void itemExpanded(const QModelIndex& item, bool expanded);
@@ -47,9 +55,17 @@ namespace Swift {
QString getAvatar(RosterItem* item) const;
QString getStatusText(RosterItem* item) const;
+ QString getJID(RosterItem* item) const;
+ QString getDisplayJID(RosterItem* item) const;
QIcon getPresenceIcon(RosterItem* item) const;
int getChildCount(RosterItem* item) const;
+ bool getIsIdle(RosterItem* item) const;
void reLayout();
+ /** calculates screenreader-friendly text if in screenreader mode, otherwise uses alternative text */
+ QString getScreenReaderTextOr(RosterItem* item, const QString& alternative) const;
+ private:
Roster* roster_;
QtTreeWidget* view_;
+ QtScaledAvatarCache* cachedImageScaler_;
+ bool screenReader_;
};
}
diff --git a/Swift/QtUI/Roster/RosterTooltip.cpp b/Swift/QtUI/Roster/RosterTooltip.cpp
new file mode 100644
index 0000000..86f175d
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterTooltip.cpp
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swift/QtUI/Roster/RosterTooltip.h>
+
+#include <QObject>
+#include <QString>
+#include <QApplication>
+
+#include <Swiften/Base/Path.h>
+
+#include <Swift/Controllers/Roster/ContactRosterItem.h>
+#include <Swift/Controllers/StatusUtil.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtScaledAvatarCache.h>
+#include <Swift/QtUI/QtUtilities.h>
+#include <Swift/QtUI/QtResourceHelper.h>
+
+using namespace QtUtilities;
+
+namespace Swift {
+
+QString RosterTooltip::buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler) {
+ QString tooltipTemplate;
+ if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ tooltipTemplate = QString(
+ "<table style='white-space:pre'>"
+ "<tr>"
+ "<td>"
+ "<img src=\"%1\" />"
+ "</td>"
+ "<td>"
+ "<p style='font-size: 14px'>%3 %2</p>"
+ "<table><tr><td valign='middle'>%5</td><td valign='middle'>%4</td></tr></table>"
+ "%6"
+ "%7"
+ "%8"
+ "%9"
+ "</td>"
+ "</tr>"
+ "</table>");
+ } else {
+ tooltipTemplate = QString(
+ "<table style='white-space:pre'>"
+ "<tr>"
+ "<td>"
+ "<img src=\"%1\" />"
+ "</td>"
+ "<td>"
+ "<p style='font-size: 14px'>%2 %3</p>"
+ "<table><tr><td valign='middle'>%4</td><td valign='middle'>%5</td></tr></table>"
+ "%6"
+ "%7"
+ "%8"
+ "%9"
+ "</td>"
+ "</tr>"
+ "</table>");
+ }
+ // prepare tooltip
+ QString fullName = P2QSTRING(contact->getDisplayName());
+
+ QString vCardSummary;
+ VCard::ref vCard = contact->getVCard();
+ if (vCard) {
+ fullName = P2QSTRING(vCard->getFullName()).trimmed();
+ if (fullName.isEmpty()) {
+ fullName = (P2QSTRING(vCard->getGivenName()) + " " + P2QSTRING(vCard->getFamilyName())).trimmed();
+ }
+ if (fullName.isEmpty()) {
+ fullName = P2QSTRING(contact->getDisplayName());
+ }
+ vCardSummary = buildVCardSummary(vCard);
+ } else {
+ contact->onVCardRequested();
+ }
+
+ QString scaledAvatarPath = cachedImageScaler->getScaledAvatarPath(P2QSTRING(contact->getAvatarPath().empty() ? ":/icons/avatar.png" : pathToString(contact->getAvatarPath())));
+
+ QString bareJID = contact->getDisplayJID().toString().empty() ? "" : "( " + P2QSTRING(contact->getDisplayJID().toString()) + " )";
+
+ QString presenceIconTag = QString("<img src='%1' />").arg(statusShowTypeToIconPath(contact->getStatusShow()));
+
+ QString statusMessage = contact->getStatusText().empty() ? QObject::tr("(No message)") : P2QSTRING(contact->getStatusText());
+
+ QString idleString = P2QSTRING(contact->getIdleText());
+ if (!idleString.isEmpty()) {
+ idleString = QObject::tr("Idle since %1").arg(idleString);
+ idleString = htmlEscape(idleString) + "<br/>";
+ }
+
+ QString lastSeen = P2QSTRING(contact->getOfflineSinceText());
+ if (!lastSeen.isEmpty()) {
+ lastSeen = QObject::tr("Last seen %1").arg(lastSeen);
+ lastSeen = htmlEscape(lastSeen) + "<br/>";
+ }
+
+ QString mucOccupant= P2QSTRING(contact->getMUCAffiliationText());
+ if (!mucOccupant.isEmpty()) {
+ mucOccupant = htmlEscape(mucOccupant) + "<br/>";
+ }
+
+ return tooltipTemplate.arg(scaledAvatarPath, htmlEscape(fullName), htmlEscape(bareJID), presenceIconTag, htmlEscape(statusMessage), mucOccupant, idleString, lastSeen, vCardSummary);
+}
+
+QString RosterTooltip::buildVCardSummary(VCard::ref vcard) {
+ QString summary;
+ summary = "<table>";
+
+ // star | name | content
+ QString currentBlock;
+ foreach (const VCard::Telephone& tel, vcard->getTelephones()) {
+ QString type = tel.isFax ? QObject::tr("Fax") : QObject::tr("Telephone");
+ QString field = buildVCardField(tel.isPreferred, type, htmlEscape(P2QSTRING(tel.number)));
+ if (tel.isPreferred) {
+ currentBlock = field;
+ break;
+ }
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach (const VCard::EMailAddress& mail, vcard->getEMailAddresses()) {
+ QString field = buildVCardField(mail.isPreferred, QObject::tr("E-Mail"), htmlEscape(P2QSTRING(mail.address)));
+ if (mail.isPreferred) {
+ currentBlock = field;
+ break;
+ }
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach (const VCard::Organization& org, vcard->getOrganizations()) {
+ QString field = buildVCardField(false, QObject::tr("Organization"), htmlEscape(P2QSTRING(org.name)));
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ currentBlock = "";
+ foreach(const std::string& title, vcard->getTitles()) {
+ QString field = buildVCardField(false, QObject::tr("Title"), htmlEscape(P2QSTRING(title)));
+ currentBlock += field;
+ }
+ summary += currentBlock;
+
+ summary += "</table>";
+ return summary;
+}
+
+QString RosterTooltip::buildVCardField(bool preferred, const QString& name, const QString& content) {
+ QString rowTemplate;
+ if (QApplication::layoutDirection() == Qt::RightToLeft) {
+ rowTemplate = QString("<tr><td>%3</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%1</td></tr>");
+ } else {
+ rowTemplate = QString("<tr><td>%1</td><td valign='middle'><strong>%2</strong></td><td valign='middle'>%3</td></tr>");
+ }
+ return rowTemplate.arg(preferred ? "<img src=':/icons/star-checked.png' />" : "", name, content);
+}
+
+}
diff --git a/Swift/QtUI/Roster/RosterTooltip.h b/Swift/QtUI/Roster/RosterTooltip.h
new file mode 100644
index 0000000..37f5da2
--- /dev/null
+++ b/Swift/QtUI/Roster/RosterTooltip.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QString>
+
+#include <Swiften/Elements/VCard.h>
+
+namespace Swift {
+
+class ContactRosterItem;
+class QtScaledAvatarCache;
+
+class RosterTooltip {
+ public:
+ static QString buildDetailedTooltip(ContactRosterItem* contact, QtScaledAvatarCache* cachedImageScaler);
+
+ private:
+ static QString buildVCardSummary(VCard::ref vcard);
+ static QString buildVCardField(bool preferred, const QString& name, const QString& content);
+};
+
+}
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index 68a0782..26e738a 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -1,3 +1,3 @@
-import os, shutil, datetime, re
+import os, shutil, datetime, re, time
import Version
@@ -21,5 +21,10 @@ Import("env")
myenv = env.Clone()
+
+# Disable warnings that affect Qt
myenv["CXXFLAGS"] = filter(lambda x : x != "-Wfloat-equal", myenv["CXXFLAGS"])
+if "clang" in env["CC"] :
+ myenv.Append(CXXFLAGS = ["-Wno-float-equal", "-Wno-shorten-64-to-32", "-Wno-missing-prototypes", "-Wno-unreachable-code", "-Wno-disabled-macro-expansion", "-Wno-unused-private-field", "-Wno-extra-semi", "-Wno-duplicate-enum", "-Wno-missing-variable-declarations", "-Wno-conversion", "-Wno-undefined-reinterpret-cast"])
+
myenv.UseFlags(env["SWIFT_CONTROLLERS_FLAGS"])
myenv.UseFlags(env["SWIFTOOLS_FLAGS"])
@@ -32,4 +37,6 @@ if myenv["HAVE_SPARKLE"] :
myenv.UseFlags(env["SWIFTEN_FLAGS"])
myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"])
+if myenv.get("HAVE_BREAKPAD") :
+ myenv.UseFlags(env["BREAKPAD_FLAGS"])
if myenv.get("HAVE_GROWL", False) :
myenv.UseFlags(myenv["GROWL_FLAGS"])
@@ -40,4 +47,7 @@ if myenv.get("HAVE_SNARL", False) :
myenv.UseFlags(myenv["SNARL_FLAGS"])
myenv.Append(CPPDEFINES = ["HAVE_SNARL"])
+if myenv.get("HAVE_HUNSPELL", True):
+ myenv.Append(CPPDEFINES = ["HAVE_HUNSPELL"])
+ myenv.UseFlags(myenv["HUNSPELL_FLAGS"])
if env["PLATFORM"] == "win32" :
myenv.Append(LIBS = ["cryptui"])
@@ -47,13 +57,22 @@ myenv.Tool("qt4", toolpath = ["#/BuildTools/SCons/Tools"])
myenv.Tool("nsis", toolpath = ["#/BuildTools/SCons/Tools"])
myenv.Tool("wix", toolpath = ["#/BuildTools/SCons/Tools"])
-qt4modules = ['QtCore', 'QtGui', 'QtWebKit']
+myenv.Tool("textfile", toolpath = ["#/BuildTools/SCons/Tools"])
+qt4modules = ['QtCore', 'QtWebKit', 'QtGui']
+if myenv["qt5"] :
+ qt_version = '5'
+ qt4modules += ['QtWidgets', 'QtWebKitWidgets', 'QtMultimedia']
+else :
+ qt_version = '4'
if env["PLATFORM"] == "posix" :
qt4modules += ["QtDBus"]
-myenv.EnableQt4Modules(qt4modules, debug = False)
+if env["PLATFORM"] != "win32" and env["PLATFORM"] != "darwin" :
+ qt4modules += ["QtNetwork"]
+
+myenv.EnableQt4Modules(qt4modules, debug = False, version = qt_version)
myenv.Append(CPPPATH = ["."])
if env["PLATFORM"] == "win32" :
- #myenv["LINKFLAGS"] = ["/SUBSYSTEM:CONSOLE"]
+ #myenv.Append(LINKFLAGS = ["/SUBSYSTEM:CONSOLE"])
myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"])
myenv.Append(LIBS = "qtmain")
@@ -61,5 +80,5 @@ if env["PLATFORM"] == "win32" :
myenv.Append(LIBS = "Cryptui")
myenv.Append(CPPDEFINES = "HAVE_SCHANNEL")
- if env["debug"] :
+ if env["debug"] and not env["optimize"]:
myenv.Append(LINKFLAGS = ["/NODEFAULTLIB:msvcrt"])
@@ -69,12 +88,13 @@ sources = [
"main.cpp",
"QtAboutWidget.cpp",
+ "QtSpellCheckerWindow.cpp",
"QtAvatarWidget.cpp",
"QtUIFactory.cpp",
"QtChatWindowFactory.cpp",
- "QtChatWindow.cpp",
"QtClickableLabel.cpp",
"QtLoginWindow.cpp",
"QtMainWindow.cpp",
"QtProfileWindow.cpp",
+ "QtBlockListEditorWindow.cpp",
"QtNameWidget.cpp",
"QtSettingsProvider.cpp",
@@ -83,5 +103,8 @@ sources = [
"QtSwift.cpp",
"QtURIHandler.cpp",
+ "QtChatWindow.cpp",
"QtChatView.cpp",
+ "QtWebKitChatView.cpp",
+ "QtPlainChatView.cpp",
"QtChatTheme.cpp",
"QtChatTabs.cpp",
@@ -93,7 +116,9 @@ sources = [
"QtTextEdit.cpp",
"QtXMLConsoleWidget.cpp",
+ "QtHistoryWindow.cpp",
"QtFileTransferListWidget.cpp",
"QtFileTransferListItemModel.cpp",
"QtAdHocCommandWindow.cpp",
+ "QtAdHocCommandWithJIDWindow.cpp",
"QtUtilities.cpp",
"QtBookmarkDetailWindow.cpp",
@@ -102,4 +127,8 @@ sources = [
"QtContactEditWindow.cpp",
"QtContactEditWidget.cpp",
+ "QtSingleWindow.cpp",
+ "QtHighlightEditor.cpp",
+ "QtColorToolButton.cpp",
+ "QtClosableLineEdit.cpp",
"ChatSnippet.cpp",
"MessageSnippet.cpp",
@@ -110,4 +139,5 @@ sources = [
"QtLineEdit.cpp",
"QtJoinMUCWindow.cpp",
+ "QtConnectionSettingsWindow.cpp",
"Roster/RosterModel.cpp",
"Roster/QtTreeWidget.cpp",
@@ -116,6 +146,8 @@ sources = [
"Roster/GroupItemDelegate.cpp",
"Roster/DelegateCommons.cpp",
+ "Roster/QtFilterWidget.cpp",
"Roster/QtRosterWidget.cpp",
"Roster/QtOccupantListWidget.cpp",
+ "Roster/RosterTooltip.cpp",
"EventViewer/EventModel.cpp",
"EventViewer/EventDelegate.cpp",
@@ -128,4 +160,5 @@ sources = [
"ChatList/ChatListMUCItem.cpp",
"ChatList/ChatListRecentItem.cpp",
+ "ChatList/ChatListWhiteboardItem.cpp",
"MUCSearch/QtMUCSearchWindow.cpp",
"MUCSearch/MUCSearchModel.cpp",
@@ -133,5 +166,10 @@ sources = [
"MUCSearch/MUCSearchEmptyItem.cpp",
"MUCSearch/MUCSearchDelegate.cpp",
+ "UserSearch/ContactListDelegate.cpp",
+ "UserSearch/ContactListModel.cpp",
+ "UserSearch/QtContactListWidget.cpp",
+ "UserSearch/QtSuggestingJIDInput.cpp",
"UserSearch/QtUserSearchFirstPage.cpp",
+ "UserSearch/QtUserSearchFirstMultiJIDPage.cpp",
"UserSearch/QtUserSearchFieldsPage.cpp",
"UserSearch/QtUserSearchResultsPage.cpp",
@@ -140,4 +178,9 @@ sources = [
"UserSearch/UserSearchModel.cpp",
"UserSearch/UserSearchDelegate.cpp",
+ "Whiteboard/FreehandLineItem.cpp",
+ "Whiteboard/GView.cpp",
+ "Whiteboard/TextDialog.cpp",
+ "Whiteboard/QtWhiteboardWindow.cpp",
+ "Whiteboard/ColorWidget.cpp",
"QtSubscriptionRequestWindow.cpp",
"QtRosterHeader.cpp",
@@ -148,18 +191,60 @@ sources = [
"QtMUCConfigurationWindow.cpp",
"QtAffiliationEditor.cpp",
- "QtUISettingConstants.cpp"
+ "QtUISettingConstants.cpp",
+ "QtURLValidator.cpp",
+ "QtResourceHelper.cpp"
]
+# QtVCardWidget
+sources.extend([
+ "QtVCardWidget/QtCloseButton.cpp",
+ "QtVCardWidget/QtRemovableItemDelegate.cpp",
+ "QtVCardWidget/QtResizableLineEdit.cpp",
+ "QtVCardWidget/QtTagComboBox.cpp",
+ "QtVCardWidget/QtVCardHomeWork.cpp",
+ "QtVCardWidget/QtVCardAddressField.cpp",
+ "QtVCardWidget/QtVCardAddressLabelField.cpp",
+ "QtVCardWidget/QtVCardBirthdayField.cpp",
+ "QtVCardWidget/QtVCardDescriptionField.cpp",
+ "QtVCardWidget/QtVCardInternetEMailField.cpp",
+ "QtVCardWidget/QtVCardJIDField.cpp",
+ "QtVCardWidget/QtVCardOrganizationField.cpp",
+ "QtVCardWidget/QtVCardPhotoAndNameFields.cpp",
+ "QtVCardWidget/QtVCardRoleField.cpp",
+ "QtVCardWidget/QtVCardTelephoneField.cpp",
+ "QtVCardWidget/QtVCardTitleField.cpp",
+ "QtVCardWidget/QtVCardURLField.cpp",
+ "QtVCardWidget/QtVCardGeneralField.cpp",
+ "QtVCardWidget/QtVCardWidget.cpp"
+])
+
+myenv.Uic4("QtVCardWidget/QtVCardPhotoAndNameFields.ui")
+myenv.Uic4("QtVCardWidget/QtVCardWidget.ui")
+myenv.Uic4("QtProfileWindow.ui")
+
+
+# Determine the version
myenv["SWIFT_VERSION"] = Version.getBuildVersion(env.Dir("#").abspath, "swift")
-version_match = re.match("(\d+)\.(\d+).*", myenv["SWIFT_VERSION"])
-myenv["SWIFT_VERSION_MAJOR"] = int(version_match.group(1)) if version_match else 0
-myenv["SWIFT_VERSION_MINOR"] = int(version_match.group(2)) if version_match else 0
+if env["PLATFORM"] == "win32" :
+ swift_windows_version = Version.convertToWindowsVersion(myenv["SWIFT_VERSION"])
+ myenv["SWIFT_VERSION_MAJOR"] = swift_windows_version[0]
+ myenv["SWIFT_VERSION_MINOR"] = swift_windows_version[1]
+ myenv["SWIFT_VERSION_PATCH"] = swift_windows_version[2]
+
if env["PLATFORM"] == "win32" :
- res = myenv.RES("#/Swift/resources/Windows/Swift.rc")
+ res_env = myenv.Clone()
+ res_env.Append(CPPDEFINES = [
+ ("SWIFT_COPYRIGHT_YEAR", "\"\\\"2010-%s\\\"\"" % str(time.localtime()[0])),
+ ("SWIFT_VERSION_MAJOR", "${SWIFT_VERSION_MAJOR}"),
+ ("SWIFT_VERSION_MINOR", "${SWIFT_VERSION_MINOR}"),
+ ("SWIFT_VERSION_PATCH", "${SWIFT_VERSION_PATCH}"),
+ ])
+ res = res_env.RES("#/Swift/resources/Windows/Swift.rc")
# For some reason, SCons isn't picking up the dependency correctly
# Adding it explicitly until i figure out why
myenv.Depends(res, "../Controllers/BuildVersion.h")
sources += [
+ "WinUIHelpers.cpp",
"CAPICertificateSelector.cpp",
"WindowsNotifier.cpp",
@@ -175,9 +260,12 @@ if env["PLATFORM"] == "posix" :
if env["PLATFORM"] == "darwin" :
sources += ["CocoaApplicationActivateHelper.mm"]
+ sources += ["CocoaUIHelpers.mm"]
if env["PLATFORM"] == "darwin" or env["PLATFORM"] == "win32" :
swiftProgram = myenv.Program("Swift", sources)
else :
- swiftProgram = myenv.Program("swift", sources)
+ sources += ["QtCertificateViewerDialog.cpp"];
+ myenv.Uic4("QtCertificateViewerDialog.ui");
+ swiftProgram = myenv.Program("swift-im", sources)
if env["PLATFORM"] != "darwin" and env["PLATFORM"] != "win32" :
@@ -189,4 +277,5 @@ myenv.Uic4("MUCSearch/QtMUCSearchWindow.ui")
myenv.Uic4("UserSearch/QtUserSearchWizard.ui")
myenv.Uic4("UserSearch/QtUserSearchFirstPage.ui")
+myenv.Uic4("UserSearch/QtUserSearchFirstMultiJIDPage.ui")
myenv.Uic4("UserSearch/QtUserSearchFieldsPage.ui")
myenv.Uic4("UserSearch/QtUserSearchResultsPage.ui")
@@ -194,4 +283,9 @@ myenv.Uic4("QtBookmarkDetailWindow.ui")
myenv.Uic4("QtAffiliationEditor.ui")
myenv.Uic4("QtJoinMUCWindow.ui")
+myenv.Uic4("QtHistoryWindow.ui")
+myenv.Uic4("QtConnectionSettings.ui")
+myenv.Uic4("QtHighlightEditor.ui")
+myenv.Uic4("QtBlockListEditorWindow.ui")
+myenv.Uic4("QtSpellCheckerWindow.ui")
myenv.Qrc("DefaultTheme.qrc")
myenv.Qrc("Swift.qrc")
@@ -202,4 +296,7 @@ commonResources = {
}
+myenv["TEXTFILESUFFIX"] = ""
+myenv.MyTextfile(target = "COPYING", source = [myenv.File("../../COPYING.gpl"), myenv.File("../../COPYING.thirdparty")], LINESEPARATOR = "\n\n========\n\n\n")
+
################################################################################
# Translation
@@ -229,5 +326,6 @@ if ARGUMENTS.get("update_translations", False) :
if ARGUMENTS.get("remove_obsolete_translations", False) :
remove_obsolete_option = " -no-obsolete"
- t = myenv.Command(translation_sources, [], [myenv.Action("$QT4_LUPDATE -I " + env.Dir("#").abspath + remove_obsolete_option + " -silent -no-ui-lines -codecfortr utf-8 -recursive Swift -ts " + " ".join(translation_sources), cmdstr = "$QT4_LUPDATECOMSTR")])
+ for translation_source in filter(lambda x: not x.endswith("_en.ts"), translation_sources) :
+ t = myenv.Command([translation_source], [], [myenv.Action("$QT4_LUPDATE -I " + env.Dir("#").abspath + remove_obsolete_option + " -silent -codecfortr utf-8 -recursive Swift -ts " + translation_source, cmdstr = "$QT4_LUPDATECOMSTR")])
myenv.AlwaysBuild(t)
@@ -254,5 +352,7 @@ if env["PLATFORM"] == "darwin" :
app = myenv.AppBundle("Swift", version = myenv["SWIFT_VERSION"], resources = commonResources, frameworks = frameworks, handlesXMPPURIs = True)
if env["DIST"] :
- myenv.Command(["Swift-${SWIFT_VERSION}.dmg"], [app], ["Swift/Packaging/MacOSX/package.sh " + app.path + " Swift/Packaging/MacOSX/Swift.dmg.gz $TARGET $QTDIR"])
+ myenv.Command(["#/Packages/Swift/Swift-${SWIFT_VERSION}.dmg"], [app], ["Swift/Packaging/MacOSX/package.sh " + app.path + " Swift/Packaging/MacOSX/Swift.dmg.gz $TARGET $QTDIR"])
+ dsym = myenv.Command(["Swift-${SWIFT_VERSION}.dSYM"], ["Swift"], ["dsymutil -o ${TARGET} ${SOURCE}"])
+ myenv.Command(["#/Packages/Swift/Swift-${SWIFT_VERSION}.dSYM.zip"], dsym, ["cd ${SOURCE.dir} && zip -r ${TARGET.abspath} ${SOURCE.name}"])
if env.get("SWIFT_INSTALLDIR", "") :
@@ -269,5 +369,5 @@ if env.get("SWIFT_INSTALLDIR", "") :
if env["PLATFORM"] == "win32" :
- if env["DIST"] :
+ if env["DIST"] or ARGUMENTS.get("dump_trace") :
commonResources[""] = commonResources.get("", []) + [
#os.path.join(env["OPENSSL_DIR"], "bin", "ssleay32.dll"),
@@ -275,11 +375,25 @@ if env["PLATFORM"] == "win32" :
"#/Swift/resources/images",
]
- qtimageformats = ["gif", "ico", "jpeg", "mng", "svg", "tiff"]
- qtlibs = ["QtCore4", "QtGui4", "QtNetwork4", "QtWebKit4", "QtXMLPatterns4", "phonon4"]
- myenv.WindowsBundle("Swift",
+ if env["SWIFTEN_DLL"] :
+ commonResources[""] = commonResources.get("", []) + ["#/Swiften/${SWIFTEN_LIBRARY_FILE}"]
+ qtplugins = {}
+ qtplugins["imageformats"] = ["gif", "ico", "jpeg", "mng", "svg", "tiff"]
+ qtlibs = ["QtCore", "QtGui", "QtNetwork", "QtWebKit", "QtXMLPatterns"]
+ if qt_version == '4' :
+ qtlibs.append("phonon")
+ qtlibs = [lib + '4' for lib in qtlibs]
+ else :
+ qtlibs += ['QtQuick', 'QtQml', 'QtPositioning', 'QtMultimedia', 'QtSql', 'QtSensors', 'QtWidgets', 'QtWebKitWidgets', 'QtMultimediaWidgets', 'QtOpenGL', 'QtPrintSupport']
+ qtlibs = [lib.replace('Qt', 'Qt5') for lib in qtlibs]
+ qtlibs += ['icuin51', 'icuuc51', 'icudt51', 'libGLESv2', 'libEGL']
+ qtplugins["platforms"] = ['windows']
+ qtplugins["accessible"] = ["taccessiblewidgets"]
+ windowsBundleFiles = myenv.WindowsBundle("Swift",
resources = commonResources,
- qtimageformats = qtimageformats,
- qtlibs = qtlibs)
+ qtplugins = qtplugins,
+ qtlibs = qtlibs,
+ qtversion = qt_version)
+ if env["DIST"] :
#myenv.Append(NSIS_OPTIONS = [
# "/DmsvccRedistributableDir=\"" + env["vcredist"] + "\"",
@@ -287,5 +401,4 @@ if env["PLATFORM"] == "win32" :
# ])
#myenv.Nsis("../Packaging/nsis/swift.nsi")
- #myenv.WiX("../Packaging/wix/swift.msi", ["../Packaging/WiX/Swift.wxs"])
if env["SCONS_STAGE"] == "build" and env.get("wix_bindir", None):
def convertToRTF(env, target, source) :
@@ -306,11 +419,9 @@ if env["PLATFORM"] == "win32" :
outfile.close()
infile.close()
- env.Command(["Swift/COPYING.rtf"], ["../../COPYING"], convertToRTF)
+ copying = env.Command(["Swift/COPYING.rtf"], ["COPYING"], convertToRTF)
wixvariables = {
- 'VCCRTFile': env.get("vcredist", "c:\\Program Files\\Common Files\\Merge Modules") + "\\Microsoft_VC90_CRT_x86.msm",
- # FIXME: Not including patch version, but that shouldn't be
- # a problem. It just allows downgrading between development versions
- 'Version': str(myenv["SWIFT_VERSION_MAJOR"]) + "." + str(myenv["SWIFT_VERSION_MINOR"]) + ".0"
+ 'VCCRTFile': env["vcredist"],
+ 'Version': str(myenv["SWIFT_VERSION_MAJOR"]) + "." + str(myenv["SWIFT_VERSION_MINOR"]) + "." + str(myenv["SWIFT_VERSION_PATCH"])
}
wixincludecontent = "<Include>"
@@ -319,24 +430,12 @@ if env["PLATFORM"] == "win32" :
wixincludecontent += "</Include>"
myenv.WriteVal("..\\Packaging\\Wix\\variables.wxs", env.Value(wixincludecontent))
- heatDependencies = ['Swift/COPYING.rtf', 'Swift/Swift.exe']
- for dir, resourceFiles in commonResources.items():
- for resource in resourceFiles:
- e = env.Entry(resource)
- if e.isdir():
- for subresource in env.Glob(str(e) + "/*") :
- heatDependencies.append("Swift/" + e.name + "/" + subresource.name)
- else:
- if resource[-3:] != ".qm":
- heatDependencies.append("Swift/" + resource)
- for resource in qtlibs:
- heatDependencies.append("Swift/" + resource + ".dll")
- for resource in qtimageformats:
- heatDependencies.append("Swift/imageformats/q" + resource + "4.dll")
- for lang in translation_languages:
- heatDependencies.append("Swift/translations/swift_" + lang + ".qm")
- myenv.WiX_Heat('..\\Packaging\\WiX\\gen_files.wxs', heatDependencies)
+ myenv["WIX_SOURCE_OBJECT_DIR"] = "Swift\\QtUI\\Swift"
+ myenv.WiX_Heat('..\\Packaging\\WiX\\gen_files.wxs', windowsBundleFiles + copying)
myenv.WiX_Candle('..\\Packaging\\WiX\\Swift.wixobj', '..\\Packaging\\WiX\\Swift.wxs')
myenv.WiX_Candle('..\\Packaging\\WiX\\gen_files.wixobj', '..\\Packaging\\WiX\\gen_files.wxs')
- myenv.WiX_Light('..\\Packaging\\WiX\\Swift-' + myenv["SWIFT_VERSION"] + '.msi', ['..\\Packaging\\WiX\\gen_files.wixobj','..\\Packaging\\WiX\\Swift.wixobj'])
+ myenv.WiX_Light('#/Packages/Swift/Swift-' + myenv["SWIFT_VERSION"] + '.msi', ['..\\Packaging\\WiX\\gen_files.wixobj','..\\Packaging\\WiX\\Swift.wixobj'])
+
+ if myenv["debug"] :
+ myenv.InstallAs('#/Packages/Swift/Swift-' + myenv["SWIFT_VERSION"] + '.pdb', "Swift.pdb")
diff --git a/Swift/QtUI/Swift.qrc b/Swift/QtUI/Swift.qrc
index 61d8cc0..eeef80d 100644
--- a/Swift/QtUI/Swift.qrc
+++ b/Swift/QtUI/Swift.qrc
@@ -11,4 +11,5 @@
<file alias="icons/offline.png">../resources/icons/offline.png</file>
<file alias="icons/certificate.png">../resources/icons/certificate.png</file>
+ <file alias="icons/lock.png">../resources/icons/lock.png</file>
<file alias="icons/error.png">../resources/icons/error.png</file>
<file alias="icons/warn.png">../resources/icons/warn.png</file>
@@ -20,5 +21,26 @@
<file alias="icons/new-chat.png">../resources/icons/new-chat.png</file>
<file alias="icons/actions.png">../resources/icons/actions.png</file>
- <file alias="COPYING">../../COPYING</file>
+ <file alias="COPYING">COPYING</file>
+ <file alias="icons/line.png">../resources/icons/line.png</file>
+ <file alias="icons/rect.png">../resources/icons/rect.png</file>
+ <file alias="icons/circle.png">../resources/icons/circle.png</file>
+ <file alias="icons/handline.png">../resources/icons/handline.png</file>
+ <file alias="icons/text.png">../resources/icons/text.png</file>
+ <file alias="icons/polygon.png">../resources/icons/polygon.png</file>
+ <file alias="icons/cursor.png">../resources/icons/cursor.png</file>
+ <file alias="icons/eraser.png">../resources/icons/eraser.png</file>
+ <file alias="emoticons/emoticons.txt">../resources/emoticons/emoticons.txt</file>
+ <file alias="emoticons/evilgrin.png">../resources/emoticons/evilgrin.png</file>
+ <file alias="emoticons/grin.png">../resources/emoticons/grin.png</file>
+ <file alias="emoticons/happy.png">../resources/emoticons/happy.png</file>
+ <file alias="emoticons/smile.png">../resources/emoticons/smile.png</file>
+ <file alias="emoticons/surprised.png">../resources/emoticons/surprised.png</file>
+ <file alias="emoticons/tongue.png">../resources/emoticons/tongue.png</file>
+ <file alias="emoticons/unhappy.png">../resources/emoticons/unhappy.png</file>
+ <file alias="emoticons/wink.png">../resources/emoticons/wink.png</file>
+ <file alias="icons/star-checked.png">../resources/icons/star-checked2.png</file>
+ <file alias="icons/star-unchecked.png">../resources/icons/star-unchecked2.png</file>
+ <file alias="icons/zzz.png">../resources/icons/zzz.png</file>
+ <file alias="icons/stop.png">../resources/icons/stop.png</file>
</qresource>
</RCC>
diff --git a/Swift/QtUI/SystemMessageSnippet.cpp b/Swift/QtUI/SystemMessageSnippet.cpp
index c78fe36..39349bc 100644
--- a/Swift/QtUI/SystemMessageSnippet.cpp
+++ b/Swift/QtUI/SystemMessageSnippet.cpp
@@ -11,10 +11,11 @@
namespace Swift {
-SystemMessageSnippet::SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme) : ChatSnippet(appendToPrevious) {
+SystemMessageSnippet::SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme, Direction direction) : ChatSnippet(appendToPrevious) {
if (appendToPrevious) {
- setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(message, time, false, theme)));
+ setContinuationFallbackSnippet(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(message, time, false, theme, direction)));
}
content_ = theme->getStatus();
+ content_.replace("%direction%", directionToCSS(direction));
content_.replace("%message%", wrapResizable("<span class='swift_message'>" + escape(message) + "</span>"));
content_.replace("%shortTime%", wrapResizable(escape(time.toString("h:mm"))));
diff --git a/Swift/QtUI/SystemMessageSnippet.h b/Swift/QtUI/SystemMessageSnippet.h
index 69d231f..34b0d40 100644
--- a/Swift/QtUI/SystemMessageSnippet.h
+++ b/Swift/QtUI/SystemMessageSnippet.h
@@ -16,5 +16,5 @@ namespace Swift {
class SystemMessageSnippet : public ChatSnippet {
public:
- SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme);
+ SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme, Direction direction);
virtual ~SystemMessageSnippet();
diff --git a/Swift/QtUI/UserSearch/ContactListDelegate.cpp b/Swift/QtUI/UserSearch/ContactListDelegate.cpp
new file mode 100644
index 0000000..56c479b
--- /dev/null
+++ b/Swift/QtUI/UserSearch/ContactListDelegate.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/UserSearch/ContactListDelegate.h>
+#include <Swift/QtUI/UserSearch/ContactListModel.h>
+#include <Swift/Controllers/Contact.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+ContactListDelegate::ContactListDelegate(bool compact) : compact_(compact) {
+}
+
+ContactListDelegate::~ContactListDelegate() {
+}
+
+void ContactListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
+ if (!index.isValid()) {
+ return;
+ }
+ const Contact::ref contact = static_cast<Contact*>(index.internalPointer())->shared_from_this();
+ QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
+ QString avatarPath = index.data(ContactListModel::AvatarRole).value<QString>();
+ QIcon presenceIcon =index.data(ChatListRecentItem::PresenceIconRole).isValid() && !index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>().isNull()
+ ? index.data(ChatListRecentItem::PresenceIconRole).value<QIcon>()
+ : QIcon(":/icons/offline.png");
+ QString name = P2QSTRING(contact->name);
+ QString statusText = P2QSTRING(contact->jid.toString());
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, false, 0, compact_);
+}
+
+QSize ContactListDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
+ QFontMetrics nameMetrics(common_.nameFont);
+ QFontMetrics statusMetrics(common_.detailFont);
+ int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height();
+ return QSize(150, sizeByText);
+}
+
+void ContactListDelegate::setCompact(bool compact) {
+ compact_ = compact;
+}
+
+}
diff --git a/Swift/QtUI/UserSearch/ContactListDelegate.h b/Swift/QtUI/UserSearch/ContactListDelegate.h
new file mode 100644
index 0000000..7680aba
--- /dev/null
+++ b/Swift/QtUI/UserSearch/ContactListDelegate.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QStyledItemDelegate>
+
+#include <Swift/QtUI/Roster/DelegateCommons.h>
+
+namespace Swift {
+
+class ContactListDelegate : public QStyledItemDelegate {
+ public:
+ ContactListDelegate(bool compact);
+ virtual ~ContactListDelegate();
+
+ QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+ public slots:
+ void setCompact(bool compact);
+
+ private:
+ bool compact_;
+ DelegateCommons common_;
+};
+}
diff --git a/Swift/QtUI/UserSearch/ContactListModel.cpp b/Swift/QtUI/UserSearch/ContactListModel.cpp
new file mode 100644
index 0000000..ef6383c
--- /dev/null
+++ b/Swift/QtUI/UserSearch/ContactListModel.cpp
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/UserSearch/ContactListModel.h>
+
+#include <QMimeData>
+
+#include <Swiften/Base/Path.h>
+#include <Swiften/Base/foreach.h>
+#include <Swiften/Elements/StatusShow.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtResourceHelper.h>
+
+namespace Swift {
+
+QDataStream& operator >>(QDataStream& in, StatusShow::Type& e){
+ quint32 buffer;
+ in >> buffer;
+ switch(buffer) {
+ case StatusShow::Online:
+ e = StatusShow::Online;
+ break;
+ case StatusShow::Away:
+ e = StatusShow::Away;
+ break;
+ case StatusShow::FFC:
+ e = StatusShow::FFC;
+ break;
+ case StatusShow::XA:
+ e = StatusShow::XA;
+ break;
+ case StatusShow::DND:
+ e = StatusShow::DND;
+ break;
+ default:
+ e = StatusShow::None;
+ break;
+ }
+ return in;
+}
+
+ContactListModel::ContactListModel(bool editable) : QAbstractItemModel(), editable_(editable) {
+}
+
+void ContactListModel::setList(const std::vector<Contact::ref>& list) {
+ emit layoutAboutToBeChanged();
+ contacts_ = list;
+ emit layoutChanged();
+}
+
+const std::vector<Contact::ref>& ContactListModel::getList() const {
+ return contacts_;
+}
+
+Contact::ref ContactListModel::getContact(const size_t i) const {
+ return contacts_[i];
+}
+
+Qt::ItemFlags ContactListModel::flags(const QModelIndex& index) const {
+ Qt::ItemFlags flags = QAbstractItemModel::flags(index);
+ if (index.isValid()) {
+ flags = flags & ~Qt::ItemIsDropEnabled;
+ } else {
+ flags = Qt::ItemIsDropEnabled | flags;
+ }
+ return flags;
+}
+
+int ContactListModel::columnCount(const QModelIndex&) const {
+ return editable_ ? 2 : 1;
+}
+
+QVariant ContactListModel::data(const QModelIndex& index, int role) const {
+ if (boost::numeric_cast<size_t>(index.row()) < contacts_.size()) {
+ const Contact::ref& contact = contacts_[index.row()];
+ if (role == Qt::EditRole) {
+ return P2QSTRING(contact->jid.toString());
+ }
+ return dataForContact(contact, role);
+ } else {
+ return QVariant();
+ }
+}
+
+QModelIndex ContactListModel::index(int row, int column, const QModelIndex& parent) const {
+ if (!hasIndex(row, column, parent)) {
+ return QModelIndex();
+ }
+
+ return boost::numeric_cast<size_t>(row) < contacts_.size() ? createIndex(row, column, contacts_[row].get()) : QModelIndex();
+}
+
+QModelIndex ContactListModel::parent(const QModelIndex& index) const {
+ if (!index.isValid()) {
+ return QModelIndex();
+ }
+ return QModelIndex();
+}
+
+int ContactListModel::rowCount(const QModelIndex& /*parent*/) const {
+ return contacts_.size();
+}
+
+bool ContactListModel::removeRows(int row, int /*count*/, const QModelIndex& /*parent*/) {
+ if (boost::numeric_cast<size_t>(row) < contacts_.size()) {
+ emit layoutAboutToBeChanged();
+ contacts_.erase(contacts_.begin() + row);
+ emit layoutChanged();
+ onListChanged(getList());
+ return true;
+ }
+ return false;
+}
+
+QVariant ContactListModel::dataForContact(const Contact::ref& contact, int role) const {
+ switch (role) {
+ case Qt::DisplayRole: return P2QSTRING(contact->name);
+ case DetailTextRole: return P2QSTRING(contact->jid.toString());
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(contact->avatarPath)));
+ case PresenceIconRole: return getPresenceIconForContact(contact);
+ default: return QVariant();
+ }
+}
+
+QIcon ContactListModel::getPresenceIconForContact(const Contact::ref& contact) const {
+ return QIcon(statusShowTypeToIconPath(contact->statusType));
+}
+
+}
diff --git a/Swift/QtUI/UserSearch/ContactListModel.h b/Swift/QtUI/UserSearch/ContactListModel.h
new file mode 100644
index 0000000..e582ac4
--- /dev/null
+++ b/Swift/QtUI/UserSearch/ContactListModel.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+#include <boost/bind.hpp>
+#include <Swiften/Base/boost_bsignals.h>
+
+#include <QAbstractItemModel>
+
+#include <Swift/Controllers/Contact.h>
+#include <Swift/QtUI/ChatList/ChatListItem.h>
+#include <Swift/QtUI/ChatList/ChatListGroupItem.h>
+#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
+
+namespace Swift {
+ class ContactListModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ enum ContactRoles {
+ DetailTextRole = Qt::UserRole,
+ AvatarRole = Qt::UserRole + 1,
+ PresenceIconRole = Qt::UserRole + 2
+ };
+
+ public:
+ ContactListModel(bool editable);
+
+ void setList(const std::vector<Contact::ref>& list);
+ const std::vector<Contact::ref>& getList() const;
+ Contact::ref getContact(const size_t i) const;
+
+ Qt::ItemFlags flags(const QModelIndex& index) const;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
+
+ private:
+ QVariant dataForContact(const Contact::ref& contact, int role) const;
+ QIcon getPresenceIconForContact(const Contact::ref& contact) const;
+
+ signals:
+ void onListChanged(std::vector<Contact::ref> list);
+ void onJIDsDropped(const std::vector<JID>& contact);
+
+ private:
+ bool editable_;
+ std::vector<Contact::ref> contacts_;
+ };
+
+}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
new file mode 100644
index 0000000..6504f3e
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
+
+#include <Swift/QtUI/UserSearch/ContactListModel.h>
+#include <Swift/QtUI/UserSearch/ContactListDelegate.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h>
+
+#include <QHeaderView>
+
+namespace Swift {
+
+QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* settings) : QTreeView(parent), settings_(settings), limited_(false) {
+ contactListModel_ = new ContactListModel(true);
+ setModel(contactListModel_);
+
+ connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SIGNAL(onListChanged(std::vector<Contact::ref>)));
+ connect(contactListModel_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SIGNAL(onJIDsAdded(std::vector<JID>)));
+
+ setSelectionMode(QAbstractItemView::SingleSelection);
+ setSelectionBehavior(QAbstractItemView::SelectRows);
+ setUniformRowHeights(true);
+
+ setAlternatingRowColors(true);
+ setIndentation(0);
+ setHeaderHidden(true);
+ setExpandsOnDoubleClick(false);
+ setItemsExpandable(false);
+ setEditTriggers(QAbstractItemView::DoubleClicked);
+
+ contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ removableItemDelegate_ = new QtRemovableItemDelegate(style());
+
+ setItemDelegateForColumn(0, contactListDelegate_);
+ setItemDelegateForColumn(1, removableItemDelegate_);
+
+ header()->resizeSection(1, removableItemDelegate_->sizeHint(QStyleOptionViewItem(), QModelIndex()).width());
+
+ header()->setStretchLastSection(false);
+#if QT_VERSION >= 0x050000
+ header()->setSectionResizeMode(0, QHeaderView::Stretch);
+#else
+ header()->setResizeMode(0, QHeaderView::Stretch);
+#endif
+}
+
+QtContactListWidget::~QtContactListWidget() {
+ delete contactListDelegate_;
+ delete removableItemDelegate_;
+}
+
+void QtContactListWidget::setList(const std::vector<Contact::ref>& list) {
+ contactListModel_->setList(list);
+}
+
+std::vector<Contact::ref> QtContactListWidget::getList() const {
+ return contactListModel_->getList();
+}
+
+Contact::ref QtContactListWidget::getContact(const size_t i) {
+ return contactListModel_->getContact(i);
+}
+
+void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) {
+ limited_ = limited;
+}
+
+bool QtContactListWidget::isFull() const {
+ return limited_ && (getList().size() == 1);
+}
+
+void QtContactListWidget::updateContacts(const std::vector<Contact::ref>& contactUpdates) {
+ std::vector<Contact::ref> contacts = contactListModel_->getList();
+ foreach(const Contact::ref& contactUpdate, contactUpdates) {
+ for(size_t n = 0; n < contacts.size(); n++) {
+ if (contactUpdate->jid == contacts[n]->jid) {
+ contacts[n] = contactUpdate;
+ break;
+ }
+ }
+ }
+ contactListModel_->setList(contacts);
+}
+
+void QtContactListWidget::handleSettingsChanged(const std::string&) {
+ contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+}
+
+}
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.h b/Swift/QtUI/UserSearch/QtContactListWidget.h
new file mode 100644
index 0000000..112f3ee
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtContactListWidget.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+
+#include <QTreeView>
+
+#include <Swift/Controllers/Contact.h>
+#include <Swiften/Base/Log.h>
+
+#include <QDragEnterEvent>
+#include <QDragMoveEvent>
+#include <QDropEvent>
+
+namespace Swift {
+
+class ContactListDelegate;
+class ContactListModel;
+class SettingsProvider;
+class QtRemovableItemDelegate;
+
+class QtContactListWidget : public QTreeView {
+ Q_OBJECT
+public:
+ QtContactListWidget(QWidget* parent, SettingsProvider* settings);
+ virtual ~QtContactListWidget();
+
+ void setList(const std::vector<Contact::ref>& list);
+ std::vector<Contact::ref> getList() const;
+ Contact::ref getContact(const size_t i);
+ void setMaximumNoOfContactsToOne(bool limited);
+ bool isFull() const;
+
+public slots:
+ void updateContacts(const std::vector<Contact::ref>& contactUpdates);
+
+signals:
+ void onListChanged(std::vector<Contact::ref> list);
+ void onJIDsAdded(const std::vector<JID>& jids);
+
+private:
+ void handleSettingsChanged(const std::string&);
+
+private:
+ SettingsProvider* settings_;
+ ContactListModel* contactListModel_;
+ ContactListDelegate* contactListDelegate_;
+ QtRemovableItemDelegate* removableItemDelegate_;
+ bool limited_;
+};
+
+}
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
new file mode 100644
index 0000000..57033d8
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swift/QtUI/UserSearch/QtSuggestingJIDInput.h>
+#include <Swift/QtUI/UserSearch/ContactListDelegate.h>
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/QtUI/QtUISettingConstants.h>
+#include <Swift/QtUI/UserSearch/ContactListModel.h>
+
+#include <Swiften/Base/boost_bsignals.h>
+#include <boost/bind.hpp>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+#include <QAbstractItemView>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QKeyEvent>
+
+
+namespace Swift {
+
+QtSuggestingJIDInput::QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings) : QLineEdit(parent), settings_(settings) {
+ treeViewPopup_ = new QTreeView();
+ treeViewPopup_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
+ //treeViewPopup_->setAttribute(Qt::WA_ShowWithoutActivating);
+ treeViewPopup_->setAlternatingRowColors(true);
+ treeViewPopup_->setIndentation(0);
+ treeViewPopup_->setHeaderHidden(true);
+ treeViewPopup_->setExpandsOnDoubleClick(false);
+ treeViewPopup_->setItemsExpandable(false);
+ treeViewPopup_->setSelectionMode(QAbstractItemView::SingleSelection);
+ treeViewPopup_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+ treeViewPopup_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ QSizePolicy policy(treeViewPopup_->sizePolicy());
+ policy.setVerticalPolicy(QSizePolicy::Expanding);
+ treeViewPopup_->setSizePolicy(policy);
+ treeViewPopup_->hide();
+ treeViewPopup_->setFocusProxy(this);
+ connect(treeViewPopup_, SIGNAL(clicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
+ connect(treeViewPopup_, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex)));
+
+ contactListModel_ = new ContactListModel(false);
+ treeViewPopup_->setModel(contactListModel_);
+
+ contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ treeViewPopup_->setItemDelegate(contactListDelegate_);
+
+ settings_->onSettingChanged.connect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
+}
+
+QtSuggestingJIDInput::~QtSuggestingJIDInput() {
+ settings_->onSettingChanged.disconnect(boost::bind(&QtSuggestingJIDInput::handleSettingsChanged, this, _1));
+ delete treeViewPopup_;
+}
+
+Contact::ref QtSuggestingJIDInput::getContact() {
+ if (!!currentContact_) {
+ return currentContact_;
+ }
+
+ if (!text().isEmpty()) {
+ JID jid(Q2PSTRING(text()));
+ if (jid.isValid()) {
+ Contact::ref manualContact = boost::make_shared<Contact>();
+ manualContact->name = jid.toString();
+ manualContact->jid = jid;
+ return manualContact;
+ }
+ }
+ return boost::shared_ptr<Contact>();
+}
+
+void QtSuggestingJIDInput::setSuggestions(const std::vector<Contact::ref>& suggestions) {
+ contactListModel_->setList(suggestions);
+ positionPopup();
+ if (!suggestions.empty()) {
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(0, 0));
+ showPopup();
+ } else {
+ currentContact_.reset();
+ hidePopup();
+ }
+}
+
+void QtSuggestingJIDInput::clear() {
+ setText("");
+ currentContact_.reset();
+}
+
+void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) {
+ if (event->key() == Qt::Key_Up) {
+ if (contactListModel_->rowCount() > 0) {
+ int row = treeViewPopup_->currentIndex().row();
+ row = (row + contactListModel_->rowCount() - 1) % contactListModel_->rowCount();
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
+ }
+ } else if (event->key() == Qt::Key_Down) {
+ if (contactListModel_->rowCount() > 0) {
+ int row = treeViewPopup_->currentIndex().row();
+ row = (row + contactListModel_->rowCount() + 1) % contactListModel_->rowCount();
+ treeViewPopup_->setCurrentIndex(contactListModel_->index(row, 0));
+ }
+ } else if (event->key() == Qt::Key_Return && treeViewPopup_->isVisible()) {
+ QModelIndex index = treeViewPopup_->currentIndex();
+ if (!contactListModel_->getList().empty() && index.isValid()) {
+ currentContact_ = contactListModel_->getContact(index.row());
+ if (currentContact_->jid.isValid()) {
+ setText(P2QSTRING(currentContact_->jid.toString()));
+ } else {
+ setText(P2QSTRING(currentContact_->name));
+ }
+ hidePopup();
+ clearFocus();
+ } else {
+ currentContact_.reset();
+ }
+ editingDone();
+ } else {
+ QLineEdit::keyPressEvent(event);
+ }
+}
+
+void QtSuggestingJIDInput::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) {
+ /* Using the now argument gives use the wrong widget. This is part of the code needed
+ to prevent stealing of focus when opening a the suggestion window. */
+ QWidget* now = qApp->focusWidget();
+ if (!now || (now != treeViewPopup_ && now != this && !now->isAncestorOf(this) && !now->isAncestorOf(treeViewPopup_) && !this->isAncestorOf(now) && !treeViewPopup_->isAncestorOf(now))) {
+ hidePopup();
+ }
+}
+
+void QtSuggestingJIDInput::handleSettingsChanged(const std::string& setting) {
+ if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) {
+ contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER));
+ }
+}
+
+void QtSuggestingJIDInput::handleClicked(const QModelIndex& index) {
+ if (index.isValid()) {
+ currentContact_ = contactListModel_->getContact(index.row());
+ onUserSelected(currentContact_);
+ hidePopup();
+ }
+}
+
+void QtSuggestingJIDInput::positionPopup() {
+ QDesktopWidget* desktop = QApplication::desktop();
+ int screen = desktop->screenNumber(this);
+ QPoint point = mapToGlobal(QPoint(0, height()));
+ QRect geometry = desktop->availableGeometry(screen);
+ int x = point.x();
+ int y = point.y();
+ int width = this->width();
+ int height = 80;
+
+ int screenWidth = geometry.x() + geometry.width();
+ if (x + width > screenWidth) {
+ x = screenWidth - width;
+ }
+
+ height = treeViewPopup_->sizeHintForRow(0) * contactListModel_->rowCount();
+ height = height > 200 ? 200 : height;
+
+ int marginLeft;
+ int marginTop;
+ int marginRight;
+ int marginBottom;
+ treeViewPopup_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom);
+ height += marginTop + marginBottom;
+ width += marginLeft + marginRight;
+
+ treeViewPopup_->setGeometry(x, y, width, height);
+ treeViewPopup_->move(x, y);
+ treeViewPopup_->setMaximumWidth(width);
+}
+
+void QtSuggestingJIDInput::showPopup() {
+ treeViewPopup_->show();
+ activateWindow();
+ connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)), Qt::QueuedConnection);
+ setFocus();
+}
+
+void QtSuggestingJIDInput::hidePopup() {
+ disconnect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(handleApplicationFocusChanged(QWidget*, QWidget*)));
+ treeViewPopup_->hide();
+}
+
+}
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h
new file mode 100644
index 0000000..23e7b94
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QLineEdit>
+#include <QTreeView>
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swift/Controllers/Contact.h>
+
+namespace Swift {
+
+class ContactListDelegate;
+class SettingsProvider;
+class ContactListModel;
+
+class QtSuggestingJIDInput : public QLineEdit {
+ Q_OBJECT
+ public:
+ QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings);
+ virtual ~QtSuggestingJIDInput();
+
+ Contact::ref getContact();
+
+ void setSuggestions(const std::vector<Contact::ref>& suggestions);
+
+ void clear();
+
+ boost::signal<void (const Contact::ref&)> onUserSelected;
+
+ signals:
+ void editingDone();
+
+ protected:
+ virtual void keyPressEvent(QKeyEvent* event);
+
+ private:
+ void handleSettingsChanged(const std::string& setting);
+
+ private slots:
+ void handleClicked(const QModelIndex& index);
+ void handleApplicationFocusChanged(QWidget* old, QWidget* now);
+
+ private:
+ void positionPopup();
+ void showPopup();
+ void hidePopup();
+
+ private:
+ SettingsProvider* settings_;
+ ContactListModel* contactListModel_;
+ QTreeView* treeViewPopup_;
+ ContactListDelegate* contactListDelegate_;
+ Contact::ref currentContact_;
+};
+
+}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
index f4189e7..d8c70b6 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchDetailsPage.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2011 Remko Tronçon
+ * Copyright (c) 2011-2014 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -8,4 +8,5 @@
#include <QVBoxLayout>
+#include <QLabel>
#include <boost/bind.hpp>
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
new file mode 100644
index 0000000..2c34aa6
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h"
+
+#include <QMessageBox>
+#include <QMimeData>
+#include <QUrl>
+
+#include "Swift/QtUI/QtSwiftUtil.h"
+#include <Swift/Controllers/Settings/SettingsProvider.h>
+#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
+#include <Swift/QtUI/UserSearch/QtSuggestingJIDInput.h>
+
+namespace Swift {
+
+QtUserSearchFirstMultiJIDPage::QtUserSearchFirstMultiJIDPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings) {
+ setupUi(this);
+ setTitle(title);
+ QString introText = "";
+ switch (type) {
+ case UserSearchWindow::AddContact:
+ introText = tr("Add another user to your contact list");
+ break;
+ case UserSearchWindow::ChatToContact:
+ introText = tr("Chat to another user");
+ break;
+ case UserSearchWindow::InviteToChat:
+ introText = tr("Invite contact to chat");
+ break;
+ }
+
+ setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(introText));
+
+ contactList_ = new QtContactListWidget(this, settings);
+ horizontalLayout_5->addWidget(contactList_);
+
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ horizontalLayout_6->insertWidget(0, jid_);
+
+ connect(contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(emitCompletenessCheck()));
+ connect(jid_, SIGNAL(editingDone()), this, SLOT(handleEditingDone()));
+
+ setAcceptDrops(true);
+}
+
+bool QtUserSearchFirstMultiJIDPage::isComplete() const {
+ return !contactList_->getList().empty();
+}
+
+void QtUserSearchFirstMultiJIDPage::reset() {
+ jid_->clear();
+ reason_->clear();
+}
+
+void QtUserSearchFirstMultiJIDPage::emitCompletenessCheck() {
+ emit completeChanged();
+}
+
+void QtUserSearchFirstMultiJIDPage::handleEditingDone() {
+ addContactButton_->setFocus();
+}
+
+void QtUserSearchFirstMultiJIDPage::dragEnterEvent(QDragEnterEvent *event) {
+ if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")
+ || event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ if (!contactList_->isFull()) {
+ event->acceptProposedAction();
+ }
+ }
+}
+
+void QtUserSearchFirstMultiJIDPage::dropEvent(QDropEvent *event) {
+ if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-list")) {
+ QByteArray dataBytes = event->mimeData()->data("application/vnd.swift.contact-jid-list");
+ QDataStream dataStream(&dataBytes, QIODevice::ReadOnly);
+ std::vector<JID> jids;
+ while (!dataStream.atEnd()) {
+ QString jidString;
+ dataStream >> jidString;
+ jids.push_back(Q2PSTRING(jidString));
+ }
+ onJIDsDropped(jids);
+ } else if (event->mimeData()->hasFormat("application/vnd.swift.contact-jid-muc")) {
+ QMessageBox* messageBox = new QMessageBox(this);
+ messageBox->setText(tr("You can't invite a room to chat."));
+ messageBox->setWindowTitle(tr("Error inviting room to chat"));
+ messageBox->show();
+ }
+}
+
+}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
new file mode 100644
index 0000000..431dd3c
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <QWizardPage>
+
+#include <Swift/QtUI/UserSearch/ui_QtUserSearchFirstMultiJIDPage.h>
+#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
+
+namespace Swift {
+ class UserSearchModel;
+ class UserSearchDelegate;
+ class UserSearchResult;
+ class UIEventStream;
+ class QtContactListWidget;
+ class ContactSuggester;
+ class AvatarManager;
+ class VCardManager;
+ class SettingsProvider;
+ class QtSuggestingJIDInput;
+
+ class QtUserSearchFirstMultiJIDPage : public QWizardPage, public Ui::QtUserSearchFirstMultiJIDPage {
+ Q_OBJECT
+ public:
+ QtUserSearchFirstMultiJIDPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
+ virtual bool isComplete() const;
+ void reset();
+
+ signals:
+ void onJIDsDropped(std::vector<JID> jid);
+
+ public slots:
+ void emitCompletenessCheck();
+ void handleEditingDone();
+ virtual void dragEnterEvent(QDragEnterEvent *event);
+ virtual void dropEvent(QDropEvent *event);
+
+ public:
+ QtContactListWidget* contactList_;
+ QtSuggestingJIDInput* jid_;
+ };
+}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.ui b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.ui
new file mode 100644
index 0000000..4a87f41
--- /dev/null
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.ui
@@ -0,0 +1,222 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QtUserSearchFirstMultiJIDPage</class>
+ <widget class="QWizardPage" name="QtUserSearchFirstMultiJIDPage">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>477</width>
+ <height>500</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string/>
+ </property>
+ <property name="title">
+ <string>Add a user</string>
+ </property>
+ <property name="subTitle">
+ <string>Add another user to your contact list. If you know their address you can add them directly, or you can search for them.</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="howLabel_">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5"/>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Choose another contact</string>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ <property name="checkable">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <property name="spacing">
+ <number>-1</number>
+ </property>
+ <property name="margin">
+ <number>6</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_6" stretch="0">
+ <property name="spacing">
+ <number>-1</number>
+ </property>
+ <item>
+ <widget class="QPushButton" name="addContactButton_">
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Add Contact</string>
+ </property>
+ <property name="default">
+ <bool>false</bool>
+ </property>
+ <property name="flat">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QRadioButton" name="byLocalSearch_">
+ <property name="text">
+ <string>I'd like to search my server</string>
+ </property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QRadioButton" name="byRemoteSearch_">
+ <property name="text">
+ <string>I'd like to search another server:</string>
+ </property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="service_">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="addViaSearchButton_">
+ <property name="text">
+ <string>Add via Search</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Reason:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="reason_"/>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>77</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="errorLabel_">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
index 7a91a98..af53a26 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.cpp
@@ -9,10 +9,17 @@
#include "Swift/QtUI/QtSwiftUtil.h"
+#include <Swiften/Base/Log.h>
+
namespace Swift {
-QtUserSearchFirstPage::QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title) {
+QtUserSearchFirstPage::QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings) {
setupUi(this);
setTitle(title);
setSubTitle(QString(tr("%1. If you know their address you can enter it directly, or you can search for them.")).arg(type == UserSearchWindow::AddContact ? tr("Add another user to your contact list") : tr("Chat to another user")));
+ jid_ = new QtSuggestingJIDInput(this, settings);
+ horizontalLayout_2->addWidget(jid_);
+ setTabOrder(byJID_, jid_);
+ setTabOrder(jid_, byLocalSearch_);
+ setTabOrder(byLocalSearch_, byRemoteSearch_);
connect(jid_, SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
connect(service_->lineEdit(), SIGNAL(textChanged(const QString&)), this, SLOT(emitCompletenessCheck()));
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
index d23b87d..d7487b0 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.h
@@ -12,4 +12,6 @@
#include <Swift/Controllers/UIInterfaces/UserSearchWindow.h>
+#include <Swift/QtUI/UserSearch/QtSuggestingJIDInput.h>
+
namespace Swift {
class UserSearchModel;
@@ -21,8 +23,10 @@ namespace Swift {
Q_OBJECT
public:
- QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title);
+ QtUserSearchFirstPage(UserSearchWindow::Type type, const QString& title, SettingsProvider* settings);
virtual bool isComplete() const;
public slots:
void emitCompletenessCheck();
+ public:
+ QtSuggestingJIDInput* jid_;
};
}
diff --git a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.ui b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.ui
index 46a1277..24d401e 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchFirstPage.ui
+++ b/Swift/QtUI/UserSearch/QtUserSearchFirstPage.ui
@@ -12,5 +12,5 @@
</property>
<property name="windowTitle">
- <string></string>
+ <string/>
</property>
<property name="title">
@@ -24,5 +24,5 @@
<widget class="QLabel" name="howLabel_">
<property name="text">
- <string></string>
+ <string/>
</property>
</widget>
@@ -35,19 +35,39 @@
<string>I know their address:</string>
</property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
</widget>
</item>
- <item>
- <widget class="QLineEdit" name="jid_"/>
- </item>
</layout>
</item>
<item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
<widget class="QRadioButton" name="byLocalSearch_">
<property name="text">
<string>I'd like to search my server</string>
</property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -56,4 +76,7 @@
<string>I'd like to search another server:</string>
</property>
+ <property name="autoExclusive">
+ <bool>true</bool>
+ </property>
</widget>
</item>
@@ -89,5 +112,5 @@
<widget class="QLabel" name="errorLabel_">
<property name="text">
- <string></string>
+ <string/>
</property>
<property name="alignment">
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
index 2b11d02..babe115 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -11,58 +11,52 @@
#include <QWizardPage>
#include <QMovie>
+#include <boost/bind.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Base/foreach.h>
-#include "Swift/Controllers/UIEvents/UIEventStream.h"
-#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h"
-#include "Swift/Controllers/UIEvents/AddContactUIEvent.h"
-#include "Swift/QtUI/UserSearch/UserSearchModel.h"
-#include "Swift/QtUI/UserSearch/UserSearchDelegate.h"
-#include "Swift/QtUI/QtSwiftUtil.h"
-#include "Swift/QtUI/QtFormResultItemModel.h"
-#include "QtUserSearchFirstPage.h"
-#include "QtUserSearchFieldsPage.h"
-#include "QtUserSearchResultsPage.h"
-#include "QtUserSearchDetailsPage.h"
+#include <Swift/Controllers/UIEvents/UIEventStream.h>
+#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>
+#include <Swift/Controllers/UIEvents/AddContactUIEvent.h>
+#include <Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h>
+#include <Swift/Controllers/UIEvents/InviteToMUCUIEvent.h>
+#include <Swift/QtUI/UserSearch/UserSearchModel.h>
+#include <Swift/QtUI/UserSearch/UserSearchDelegate.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swift/QtUI/QtFormResultItemModel.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchFirstPage.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchResultsPage.h>
+#include <Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h>
+#include <Swift/QtUI/UserSearch/QtContactListWidget.h>
+
+#include <Swiften/Base/Log.h>
namespace Swift {
-QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups) : eventStream_(eventStream), type_(type), model_(NULL) {
+QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider) : eventStream_(eventStream), type_(type), model_(NULL), firstMultiJIDPage_(NULL), settings_(settingsProvider), searchNext_(false), supportsImpromptu_(false) {
setupUi(this);
-#ifndef Q_WS_MAC
+#ifndef Q_OS_MAC
setWindowIcon(QIcon(":/logo-icon-16.png"));
#endif
- QString title(type == UserSearchWindow::AddContact ? tr("Add Contact") : tr("Chat to User"));
+ QString title;
+ switch(type) {
+ case AddContact:
+ title = tr("Add Contact");
+ break;
+ case ChatToContact:
+ title = tr("Chat to Users");
+ break;
+ case InviteToChat:
+ title = tr("Add Users to Chat");
+ break;
+ }
setWindowTitle(title);
delegate_ = new UserSearchDelegate();
- firstPage_ = new QtUserSearchFirstPage(type, title);
- connect(firstPage_->byJID_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
- connect(firstPage_->byLocalSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
- connect(firstPage_->byRemoteSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
-#if QT_VERSION >= 0x040700
- firstPage_->jid_->setPlaceholderText(tr("alice@wonderland.lit"));
-#endif
- firstPage_->service_->setEnabled(false);
- setPage(1, firstPage_);
-
- fieldsPage_ = new QtUserSearchFieldsPage();
- fieldsPage_->fetchingThrobber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
- fieldsPage_->fetchingThrobber_->movie()->stop();
- setPage(2, fieldsPage_);
-
- resultsPage_ = new QtUserSearchResultsPage();
-
-#ifdef SWIFT_PLATFORM_MACOSX
- resultsPage_->results_->setAlternatingRowColors(true);
-#endif
- if (type == AddContact) {
- connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
- }
- else {
- connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(accept()));
- }
- setPage(3, resultsPage_);
+ setFirstPage(title);
+ setSecondPage();
+ setThirdPage();
detailsPage_ = new QtUserSearchDetailsPage(groups);
@@ -79,5 +73,14 @@ QtUserSearchWindow::~QtUserSearchWindow() {
void QtUserSearchWindow::handleCurrentChanged(int page) {
- if (page == 2 && lastPage_ == 1) {
+ searchNext_ = false;
+ if (firstMultiJIDPage_) {
+ firstMultiJIDPage_->reset();
+ }
+ resultsPage_->emitCompletenessCheck();
+ if (page == 1 && lastPage_ == 3) {
+ addSearchedJIDToList(getContact());
+ setSecondPage();
+ }
+ else if (page == 2 && lastPage_ == 1) {
setError("");
/* next won't be called if JID is selected */
@@ -85,7 +88,20 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
clearForm();
onFormRequested(server);
+ setThirdPage();
}
else if (page == 3 && lastPage_ == 2) {
+ JID server = getServerToSearch();
handleSearch();
+
+ if (type_ == AddContact) {
+ bool remote = firstPage_->byRemoteSearch_->isChecked();
+ firstPage_->byRemoteSearch_->setChecked(remote);
+ firstPage_->service_->setEditText(P2QSTRING(server.toString()));
+ } else {
+ bool remote = firstMultiJIDPage_->byRemoteSearch_->isChecked();
+ setFirstPage();
+ firstMultiJIDPage_->byRemoteSearch_->setChecked(remote);
+ firstMultiJIDPage_->service_->setEditText(P2QSTRING(server.toString()));
+ }
}
else if (page == 4) {
@@ -98,20 +114,60 @@ void QtUserSearchWindow::handleCurrentChanged(int page) {
JID QtUserSearchWindow::getServerToSearch() {
+ if (type_ == AddContact) {
return firstPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstPage_->service_->currentText().trimmed())) : myServer_;
+ } else {
+ return firstMultiJIDPage_->byRemoteSearch_->isChecked() ? JID(Q2PSTRING(firstMultiJIDPage_->service_->currentText().trimmed())) : myServer_;
+ }
}
void QtUserSearchWindow::handleAccepted() {
- JID jid = getContactJID();
-
- if (type_ == AddContact) {
+ JID jid;
+ std::vector<JID> jids;
+ switch(type_) {
+ case AddContact:
+ jid = getContactJID();
eventStream_->send(boost::make_shared<AddContactUIEvent>(jid, detailsPage_->getName(), detailsPage_->getSelectedGroups()));
- }
- else {
- boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(jid));
+ break;
+ case ChatToContact:
+ if (contactVector_.size() == 1) {
+ boost::shared_ptr<UIEvent> event(new RequestChatUIEvent(contactVector_[0]->jid));
eventStream_->send(event);
+ break;
+ }
+
+ foreach(Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+
+ eventStream_->send(boost::make_shared<CreateImpromptuMUCUIEvent>(jids, JID(), Q2PSTRING(firstMultiJIDPage_->reason_->text())));
+ break;
+ case InviteToChat:
+ foreach(Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+ eventStream_->send(boost::make_shared<InviteToMUCUIEvent>(roomJID_, jids, Q2PSTRING(firstMultiJIDPage_->reason_->text())));
+ break;
+ }
+}
+
+void QtUserSearchWindow::handleContactSuggestionRequested(const QString& text) {
+ std::string stdText = Q2PSTRING(text);
+ onContactSuggestionsRequested(stdText);
+}
+
+void QtUserSearchWindow::addContact() {
+ if (!!firstMultiJIDPage_->jid_->getContact()) {
+ contactVector_.push_back(firstMultiJIDPage_->jid_->getContact());
+ firstMultiJIDPage_->jid_->clear();
+ }
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->emitCompletenessCheck();
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
}
}
int QtUserSearchWindow::nextId() const {
+ if (type_ == AddContact) {
switch (currentId()) {
case 1: return firstPage_->byJID_->isChecked() ? (type_ == AddContact ? 4 : -1) : 2;
@@ -121,4 +177,13 @@ int QtUserSearchWindow::nextId() const {
default: return -1;
}
+ } else {
+ switch (currentId()) {
+ case 1: return searchNext_ ? 2 : -1;
+ case 2: return 3;
+ case 3: return 1;
+ case 4: return -1;
+ default: return -1;
+ }
+ }
}
@@ -148,15 +213,16 @@ void QtUserSearchWindow::handleSearch() {
if (fieldsPage_->getFormWidget()) {
search->setForm(fieldsPage_->getFormWidget()->getCompletedForm());
+ search->getForm()->clearEmptyTextFields();
} else {
- if (fieldsPage_->nickInput_->isEnabled()) {
+ if (fieldsPage_->nickInput_->isEnabled() && !fieldsPage_->nickInput_->text().isEmpty()) {
search->setNick(Q2PSTRING(fieldsPage_->nickInput_->text()));
}
- if (fieldsPage_->firstInput_->isEnabled()) {
+ if (fieldsPage_->firstInput_->isEnabled() && !fieldsPage_->firstInput_->text().isEmpty()) {
search->setFirst(Q2PSTRING(fieldsPage_->firstInput_->text()));
}
- if (fieldsPage_->lastInput_->isEnabled()) {
+ if (fieldsPage_->lastInput_->isEnabled() && !fieldsPage_->lastInput_->text().isEmpty()) {
search->setLast(Q2PSTRING(fieldsPage_->lastInput_->text()));
}
- if (fieldsPage_->emailInput_->isEnabled()) {
+ if (fieldsPage_->emailInput_->isEnabled() && !fieldsPage_->emailInput_->text().isEmpty()) {
search->setEMail(Q2PSTRING(fieldsPage_->emailInput_->text()));
}
@@ -167,5 +233,13 @@ void QtUserSearchWindow::handleSearch() {
JID QtUserSearchWindow::getContactJID() const {
JID jid;
- if (!firstPage_->byJID_->isChecked()) {
+
+ bool useSearchResult;
+ if (type_ == AddContact) {
+ useSearchResult = !firstPage_->byJID_->isChecked();
+ } else {
+ useSearchResult = true;
+ }
+
+ if (useSearchResult) {
if (dynamic_cast<UserSearchModel*>(model_)) {
UserSearchResult* userItem = static_cast<UserSearchResult*>(resultsPage_->results_->currentIndex().internalPointer());
@@ -173,5 +247,5 @@ JID QtUserSearchWindow::getContactJID() const {
jid = userItem->getJID();
}
- } else {
+ } else if (dynamic_cast<QtFormResultItemModel*>(model_)) {
int row = resultsPage_->results_->currentIndex().row();
@@ -179,10 +253,10 @@ JID QtUserSearchWindow::getContactJID() const {
JID fallbackJid;
foreach(FormField::ref field, item) {
- if (boost::dynamic_pointer_cast<JIDSingleFormField>(field)) {
- jid = JID(field->getRawValues().at(0));
+ if (field->getType() == FormField::JIDSingleType) {
+ jid = JID(field->getJIDSingleValue());
break;
}
if (field->getName() == "jid") {
- fallbackJid = field->getRawValues().at(0);
+ fallbackJid = field->getValues()[0];
}
}
@@ -198,4 +272,19 @@ JID QtUserSearchWindow::getContactJID() const {
}
+Contact::ref QtUserSearchWindow::getContact() const {
+ return boost::make_shared<Contact>("", getContactJID(), StatusShow::None, "");
+}
+
+void QtUserSearchWindow::addSearchedJIDToList(const Contact::ref& contact) {
+ std::vector<JID> jids;
+ jids.push_back(contact->jid);
+ handleJIDsAdded(jids);
+ firstMultiJIDPage_->jid_->clear();
+}
+
+void QtUserSearchWindow::handleOnSearchedJIDSelected(const Contact::ref& contact) {
+ firstPage_->jid_->setText(P2QSTRING(contact->jid.toString()));
+}
+
void QtUserSearchWindow::show() {
clear();
@@ -204,4 +293,5 @@ void QtUserSearchWindow::show() {
void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) {
+ if (type_ == AddContact) {
firstPage_->service_->clear();
foreach (JID jid, services) {
@@ -209,4 +299,11 @@ void QtUserSearchWindow::addSavedServices(const std::vector<JID>& services) {
}
firstPage_->service_->clearEditText();
+ } else {
+ firstMultiJIDPage_->service_->clear();
+ foreach (JID jid, services) {
+ firstMultiJIDPage_->service_->addItem(P2QSTRING(jid.toString()));
+ }
+ firstMultiJIDPage_->service_->clearEditText();
+ }
}
@@ -221,5 +318,5 @@ void QtUserSearchWindow::setSearchFields(boost::shared_ptr<SearchPayload> fields
} else {
fieldsPage_->setFormWidget(NULL);
- bool enabled[8] = {fields->getNick(), fields->getNick(), fields->getFirst(), fields->getFirst(), fields->getLast(), fields->getLast(), fields->getEMail(), fields->getEMail()};
+ bool enabled[8] = {!!fields->getNick(), !!fields->getNick(), !!fields->getFirst(), !!fields->getFirst(), !!fields->getLast(), !!fields->getLast(), !!fields->getEMail(), !!fields->getEMail()};
QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_};
for (int i = 0; i < 8; i++) {
@@ -246,4 +343,95 @@ void QtUserSearchWindow::prepopulateJIDAndName(const JID& jid, const std::string
}
+void QtUserSearchWindow::setContactSuggestions(const std::vector<Contact::ref>& suggestions) {
+ if (type_ == AddContact) {
+ firstPage_->jid_->setSuggestions(suggestions);
+ } else {
+ firstMultiJIDPage_->jid_->setSuggestions(suggestions);
+ }
+}
+
+void QtUserSearchWindow::setJIDs(const std::vector<JID> &jids) {
+ foreach(JID jid, jids) {
+ addSearchedJIDToList(boost::make_shared<Contact>("", jid, StatusShow::None, ""));
+ }
+ onJIDUpdateRequested(jids);
+}
+
+void QtUserSearchWindow::setRoomJID(const JID& roomJID) {
+ roomJID_ = roomJID;
+}
+
+std::string QtUserSearchWindow::getReason() const {
+ return Q2PSTRING(firstMultiJIDPage_->reason_->text());
+}
+
+std::vector<JID> QtUserSearchWindow::getJIDs() const {
+ std::vector<JID> jids;
+ foreach (Contact::ref contact, contactVector_) {
+ jids.push_back(contact->jid);
+ }
+ return jids;
+}
+
+void QtUserSearchWindow::setCanStartImpromptuChats(bool supportsImpromptu) {
+ supportsImpromptu_ = supportsImpromptu;
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->contactList_->setMaximumNoOfContactsToOne(!supportsImpromptu_);
+ }
+}
+
+void QtUserSearchWindow::updateContacts(const std::vector<Contact::ref>& contacts) {
+ if (type_ != AddContact) {
+ firstMultiJIDPage_->contactList_->updateContacts(contacts);
+ }
+}
+
+void QtUserSearchWindow::addContacts(const std::vector<Contact::ref>& contacts) {
+ if (type_ != AddContact) {
+ /* prevent duplicate JIDs from appearing in the contact list */
+ foreach (Contact::ref newContact, contacts) {
+ bool found = false;
+ foreach (Contact::ref oldContact, contactVector_) {
+ if (newContact->jid == oldContact->jid) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ contactVector_.push_back(newContact);
+ }
+ }
+ if (!supportsImpromptu_ && contactVector_.size() > 1) {
+ contactVector_.resize(1); /* can't chat with more than one user */
+ }
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->emitCompletenessCheck();
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? true : (contactVector_.size() < 1));
+ }
+ }
+}
+
+void QtUserSearchWindow::setCanSupplyDescription(bool allowed) {
+ firstMultiJIDPage_->label->setVisible(allowed);
+ firstMultiJIDPage_->reason_->setVisible(allowed);
+}
+
+void QtUserSearchWindow::handleAddViaSearch() {
+ searchNext_ = true;
+ next();
+}
+
+void QtUserSearchWindow::handleListChanged(std::vector<Contact::ref> list) {
+ contactVector_ = list;
+ if (type_ == ChatToContact) {
+ firstMultiJIDPage_->groupBox->setEnabled(supportsImpromptu_ ? 1 : (contactVector_.size() < 1));
+ }
+}
+
+void QtUserSearchWindow::handleJIDsAdded(std::vector<JID> jids) {
+ onJIDAddRequested(jids);
+}
+
void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results) {
UserSearchModel *newModel = new UserSearchModel();
@@ -255,4 +443,5 @@ void QtUserSearchWindow::setResults(const std::vector<UserSearchResult>& results
model_ = newModel;
resultsPage_->setNoResults(model_->rowCount() == 0);
+ resultsPage_->emitCompletenessCheck();
}
@@ -263,8 +452,13 @@ void QtUserSearchWindow::setResultsForm(Form::ref results) {
resultsPage_->results_->setItemDelegate(new QItemDelegate());
resultsPage_->results_->setHeaderHidden(false);
+#if QT_VERSION >= 0x050000
+ resultsPage_->results_->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
+#else
resultsPage_->results_->header()->setResizeMode(QHeaderView::ResizeToContents);
+#endif
delete model_;
model_ = newModel;
resultsPage_->setNoResults(model_->rowCount() == 0);
+ resultsPage_->emitCompletenessCheck();
}
@@ -273,4 +467,61 @@ void QtUserSearchWindow::setSelectedService(const JID& jid) {
}
+void QtUserSearchWindow::setFirstPage(QString title) {
+ if (page(1) != 0) {
+ removePage(1);
+ }
+ if (type_ == AddContact) {
+ firstPage_ = new QtUserSearchFirstPage(type_, title.isEmpty() ? firstPage_->title() : title, settings_);
+ connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
+ firstPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::handleOnSearchedJIDSelected, this, _1));
+ connect(firstPage_->byJID_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+ connect(firstPage_->byLocalSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+ connect(firstPage_->byRemoteSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange()));
+#if QT_VERSION >= 0x040700
+ firstPage_->jid_->setPlaceholderText(tr("alice@wonderland.lit"));
+#endif
+ firstPage_->service_->setEnabled(false);
+ setPage(1, firstPage_);
+ } else {
+ firstMultiJIDPage_ = new QtUserSearchFirstMultiJIDPage(type_, title.isEmpty() ? firstMultiJIDPage_->title() : title, settings_);
+ connect(firstMultiJIDPage_->addContactButton_, SIGNAL(clicked()), this, SLOT(addContact()));
+ connect(firstMultiJIDPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString)));
+ firstMultiJIDPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::addSearchedJIDToList, this, _1));
+ connect(firstMultiJIDPage_->addViaSearchButton_, SIGNAL(clicked()), this, SLOT(handleAddViaSearch()));
+ connect(firstMultiJIDPage_->contactList_, SIGNAL(onListChanged(std::vector<Contact::ref>)), this, SLOT(handleListChanged(std::vector<Contact::ref>)));
+ connect(firstMultiJIDPage_->contactList_, SIGNAL(onJIDsAdded(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
+ connect(firstMultiJIDPage_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>)));
+ setPage(1, firstMultiJIDPage_);
+ }
+}
+
+void QtUserSearchWindow::setSecondPage() {
+ if (page(2) != 0) {
+ removePage(2);
+ }
+ fieldsPage_ = new QtUserSearchFieldsPage();
+ fieldsPage_->fetchingThrobber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ fieldsPage_->fetchingThrobber_->movie()->stop();
+ setPage(2, fieldsPage_);
+}
+
+void QtUserSearchWindow::setThirdPage() {
+ if (page(3) != 0) {
+ removePage(3);
+ }
+ resultsPage_ = new QtUserSearchResultsPage();
+
+#ifdef SWIFT_PLATFORM_MACOSX
+ resultsPage_->results_->setAlternatingRowColors(true);
+#endif
+ if (type_ == AddContact) {
+ connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
+ }
+ else {
+ connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next()));
+ }
+ setPage(3, resultsPage_);
+}
+
void QtUserSearchWindow::clearForm() {
fieldsPage_->fetchingThrobber_->show();
@@ -288,19 +539,26 @@ void QtUserSearchWindow::clearForm() {
void QtUserSearchWindow::clear() {
- firstPage_->errorLabel_->setVisible(false);
QString howText;
if (type_ == AddContact) {
+ firstPage_->errorLabel_->setVisible(false);
howText = QString(tr("How would you like to find the user to add?"));
- }
- else {
- howText = QString(tr("How would you like to find the user to chat to?"));
- }
firstPage_->howLabel_->setText(howText);
firstPage_->byJID_->setChecked(true);
+ handleFirstPageRadioChange();
+ } else {
+ contactVector_.clear();
+ firstMultiJIDPage_->contactList_->setList(contactVector_);
+ firstMultiJIDPage_->errorLabel_->setVisible(false);
+ if (type_ == ChatToContact) {
+ howText = QString(tr("Who would you like to chat to?"));
+ } else if (type_ == InviteToChat) {
+ howText = QString(tr("Who do you want to invite to the chat?"));
+ }
+ firstMultiJIDPage_->howLabel_->setText(howText);
+ }
clearForm();
resultsPage_->results_->setModel(NULL);
delete model_;
model_ = NULL;
- handleFirstPageRadioChange();
restart();
lastPage_ = 1;
@@ -309,9 +567,18 @@ void QtUserSearchWindow::clear() {
void QtUserSearchWindow::setError(const QString& error) {
if (error.isEmpty()) {
+ if (type_ == AddContact) {
firstPage_->errorLabel_->hide();
+ } else {
+ firstMultiJIDPage_->errorLabel_->hide();
+ }
}
else {
+ if (type_ == AddContact) {
firstPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
firstPage_->errorLabel_->show();
+ } else {
+ firstMultiJIDPage_->errorLabel_->setText(QString("<font color='red'>%1</font>").arg(error));
+ firstMultiJIDPage_->errorLabel_->show();
+ }
restart();
lastPage_ = 1;
diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.h b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
index 32e851a..255b8fe 100644
--- a/Swift/QtUI/UserSearch/QtUserSearchWindow.h
+++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.h
@@ -1,4 +1,4 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
@@ -19,13 +19,15 @@ namespace Swift {
class UIEventStream;
class QtUserSearchFirstPage;
+ class QtUserSearchFirstMultiJIDPage;
class QtUserSearchFieldsPage;
class QtUserSearchResultsPage;
class QtUserSearchDetailsPage;
class QtFormResultItemModel;
+ class SettingsProvider;
class QtUserSearchWindow : public QWizard, public UserSearchWindow, private Ui::QtUserSearchWizard {
Q_OBJECT
public:
- QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups);
+ QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider);
virtual ~QtUserSearchWindow();
@@ -42,11 +44,32 @@ namespace Swift {
virtual void setNameSuggestions(const std::vector<std::string>& suggestions);
virtual void prepopulateJIDAndName(const JID& jid, const std::string& name);
+ virtual void setContactSuggestions(const std::vector<Contact::ref>& suggestions);
+ virtual void setJIDs(const std::vector<JID> &jids);
+ virtual void setRoomJID(const JID &roomJID);
+ virtual std::string getReason() const;
+ virtual std::vector<JID> getJIDs() const;
+ virtual void setCanStartImpromptuChats(bool supportsImpromptu);
+ virtual void updateContacts(const std::vector<Contact::ref> &contacts);
+ virtual void addContacts(const std::vector<Contact::ref>& contacts);
+ virtual void setCanSupplyDescription(bool allowed);
protected:
virtual int nextId() const;
+
private slots:
void handleFirstPageRadioChange();
virtual void handleCurrentChanged(int);
virtual void handleAccepted();
+ void handleContactSuggestionRequested(const QString& text);
+ void addContact();
+ void handleAddViaSearch();
+ void handleListChanged(std::vector<Contact::ref> list);
+ void handleJIDsAdded(std::vector<JID> jids);
+
+ private:
+ void setFirstPage(QString title = "");
+ void setSecondPage();
+ void setThirdPage();
+
private:
void clearForm();
@@ -55,4 +78,7 @@ namespace Swift {
void handleSearch();
JID getContactJID() const;
+ Contact::ref getContact() const;
+ void addSearchedJIDToList(const Contact::ref& contact);
+ void handleOnSearchedJIDSelected(const Contact::ref& contact);
private:
@@ -62,9 +88,15 @@ namespace Swift {
UserSearchDelegate* delegate_;
QtUserSearchFirstPage* firstPage_;
+ QtUserSearchFirstMultiJIDPage* firstMultiJIDPage_;
QtUserSearchFieldsPage* fieldsPage_;
QtUserSearchResultsPage* resultsPage_;
QtUserSearchDetailsPage* detailsPage_;
JID myServer_;
+ JID roomJID_;
int lastPage_;
+ std::vector<Contact::ref> contactVector_;
+ SettingsProvider* settings_;
+ bool searchNext_;
+ bool supportsImpromptu_;
};
}
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.cpp b/Swift/QtUI/Whiteboard/ColorWidget.cpp
new file mode 100644
index 0000000..e96b760
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/ColorWidget.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+
+#include "ColorWidget.h"
+#include <QPainter>
+#include <QMouseEvent>
+
+namespace Swift {
+ ColorWidget::ColorWidget(QWidget* parent) : QWidget(parent) {
+ setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ }
+
+ QSize ColorWidget::sizeHint() const {
+ return QSize(20, 20);
+ }
+
+ void ColorWidget::setColor(QColor color) {
+ this->color = color;
+ update();
+ }
+
+ void ColorWidget::paintEvent(QPaintEvent* /*event*/) {
+ QPainter painter(this);
+ painter.fillRect(0, 0, 20, 20, color);
+ }
+
+ void ColorWidget::mouseReleaseEvent(QMouseEvent* event) {
+ if (event->button() == Qt::LeftButton) {
+ emit clicked();
+ }
+ }
+}
+
diff --git a/Swift/QtUI/Whiteboard/ColorWidget.h b/Swift/QtUI/Whiteboard/ColorWidget.h
new file mode 100644
index 0000000..ae1af0f
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/ColorWidget.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QWidget>
+
+namespace Swift {
+ class ColorWidget : public QWidget {
+ Q_OBJECT
+ public:
+ ColorWidget(QWidget* parent = 0);
+ QSize sizeHint() const;
+
+ public slots:
+ void setColor(QColor color);
+
+ private:
+ QColor color;
+
+ protected:
+ void paintEvent(QPaintEvent* /*event*/);
+ void mouseReleaseEvent(QMouseEvent* event);
+
+ signals:
+ void clicked();
+
+ };
+}
+
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
new file mode 100644
index 0000000..8821062
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "FreehandLineItem.h"
+
+
+namespace Swift {
+ FreehandLineItem::FreehandLineItem(QGraphicsItem* parent) : QGraphicsItem(parent) {
+ }
+
+ QRectF FreehandLineItem::boundingRect() const
+ {
+ return boundRect;
+ }
+
+ void FreehandLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
+ {
+ painter->setPen(pen_);
+ if (points_.size() > 0) {
+ QVector<QPointF>::const_iterator it = points_.begin();
+ QPointF previous = *it;
+ ++it;
+ for (; it != points_.end(); ++it) {
+ painter->drawLine(previous, *it);
+ previous = *it;
+ }
+ }
+ }
+
+ void FreehandLineItem::setStartPoint(QPointF point)
+ {
+ points_.clear();
+ points_.append(point);
+ QRectF rect(point, point);
+ prepareGeometryChange();
+ boundRect = rect;
+ }
+
+ void FreehandLineItem::lineTo(QPointF point)
+ {
+ qreal x1, x2, y1, y2;
+ x1 = points_.last().x();
+ x2 = point.x();
+ y1 = points_.last().y();
+ y2 = point.y();
+ if (x1 > x2) {
+ qreal temp = x1;
+ x1 = x2;
+ x2 = temp;
+ }
+ if (y1 > y2) {
+ qreal temp = y1;
+ y1 = y2;
+ y2 = temp;
+ }
+ QRectF rect(x1-1, y1-1, x2+1-x1, y2+1-y1);
+
+ points_.append(point);
+
+ prepareGeometryChange();
+ boundRect |= rect;
+ }
+
+ bool FreehandLineItem::collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/) const
+ {
+ QVector<QPointF>::const_iterator it;
+ QSizeF size(1,1);
+ for (it = points_.begin(); it != points_.end(); ++it) {
+ if (path.intersects(QRectF(*it, size))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void FreehandLineItem::setPen(const QPen& pen)
+ {
+ pen_ = pen;
+ update(boundRect);
+ }
+
+ QPen FreehandLineItem::pen() const
+ {
+ return pen_;
+ }
+
+ const QVector<QPointF>& FreehandLineItem::points() const {
+ return points_;
+ }
+
+ int FreehandLineItem::type() const {
+ return Type;
+ }
+}
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.h b/Swift/QtUI/Whiteboard/FreehandLineItem.h
new file mode 100644
index 0000000..b1af3d1
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QGraphicsItem>
+#include <QPainter>
+#include <iostream>
+
+namespace Swift {
+ class FreehandLineItem : public QGraphicsItem {
+ public:
+ enum {Type = UserType + 1};
+ FreehandLineItem(QGraphicsItem* parent = 0);
+ QRectF boundingRect() const;
+ void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/ = 0);
+ void setStartPoint(QPointF point);
+ void lineTo(QPointF point);
+ bool collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/ = Qt::IntersectsItemShape) const;
+ void setPen(const QPen& pen);
+ QPen pen() const;
+ const QVector<QPointF>& points() const;
+ int type() const;
+
+ private:
+ QPen pen_;
+ QVector<QPointF> points_;
+ QRectF boundRect;
+ };
+}
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
new file mode 100644
index 0000000..d725cbb
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -0,0 +1,499 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "GView.h"
+#include <QtSwiftUtil.h>
+
+namespace Swift {
+ GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), brush(QColor(Qt::white)), defaultBrush(QColor(Qt::white)) {
+ selectionRect = 0;
+ lastItem = 0;
+ zValue = 0;
+ }
+
+ void GView::setLineWidth(int i) {
+ pen.setWidth(i);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultPen.setWidth(i);
+ }
+ }
+
+ void GView::setLineColor(QColor color) {
+ pen.setColor(color);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultPen.setColor(color);
+ }
+ lineColorChanged(color);
+ }
+
+ QColor GView::getLineColor() {
+ return pen.color();
+ }
+
+ void GView::setBrushColor(QColor color) {
+ brush.setColor(color);
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush);
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ } else {
+ defaultBrush.setColor(color);
+ }
+ brushColorChanged(color);
+ }
+
+ QColor GView::getBrushColor() {
+ return brush.color();
+ }
+
+ void GView::setMode(Mode mode) {
+ this->mode = mode;
+ lastItem = 0;
+ deselect();
+ }
+
+ void GView::addItem(QGraphicsItem* item, QString id, int pos) {
+ itemsMap_.insert(id, item);
+ if (pos > items_.size()) {
+ item->setZValue(zValue++);
+ scene()->addItem(item);
+ items_.append(item);
+ } else {
+ QGraphicsItem* temp = items_.at(pos-1);
+ item->setZValue(temp->zValue());
+ scene()->addItem(item);
+ item->stackBefore(temp);
+ items_.insert(pos-1, item);
+ }
+ }
+
+ void GView::clear() {
+ scene()->clear();
+ items_.clear();
+ itemsMap_.clear();
+ lastItem = 0;
+ selectionRect = 0;
+ brush = QBrush(QColor(Qt::white));
+ defaultBrush = QBrush(QColor(Qt::white));
+ pen = QPen();
+ pen.setWidth(1);
+ defaultPen = pen;
+ lineWidthChanged(1);
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ QGraphicsItem* GView::getItem(QString id) {
+ return itemsMap_.value(id);
+ }
+
+ void GView::deleteItem(QString id) {
+ deselect(id);
+ QGraphicsItem* item = itemsMap_.value(id);
+ items_.removeOne(item);
+ itemsMap_.remove(id);
+ scene()->removeItem(item);
+ delete item;
+ }
+
+ QString GView::getNewID() {
+ return P2QSTRING(idGenerator.generateID());
+ }
+
+ void GView::mouseMoveEvent(QMouseEvent* event)
+ {
+ if (!mousePressed) {
+ return;
+ }
+
+ if (mode == Line) {
+ QGraphicsLineItem* item = qgraphicsitem_cast<QGraphicsLineItem*>(lastItem);
+ if(item != 0) {
+ QLineF line = item->line();
+ line.setP1(this->mapToScene(event->pos()));
+ item->setLine(line);
+
+ }
+ }
+ else if (mode == Rect) {
+ QGraphicsRectItem* item = qgraphicsitem_cast<QGraphicsRectItem*>(lastItem);
+ if (item != 0) {
+ QPointF beginPoint = item->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ QRectF rect = item->rect();
+ if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopLeft(beginPoint);
+ rect.setBottomRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopRight(beginPoint);
+ rect.setBottomLeft(newPoint);
+ }
+ else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomLeft(beginPoint);
+ rect.setTopRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomRight(beginPoint);
+ rect.setTopLeft(newPoint);
+ }
+ item->setRect(rect);
+ }
+ }
+ else if (mode == Circle) {
+ QGraphicsEllipseItem* item = qgraphicsitem_cast<QGraphicsEllipseItem*>(lastItem);
+ QPainterPath path;
+ QPointF beginPoint = item->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ QRectF rect = item->rect();
+ if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopLeft(beginPoint);
+ rect.setBottomRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopRight(beginPoint);
+ rect.setBottomLeft(newPoint);
+ }
+ else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomLeft(beginPoint);
+ rect.setTopRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomRight(beginPoint);
+ rect.setTopLeft(newPoint);
+ }
+
+ item->setRect(rect);
+ }
+ else if (mode == HandLine) {
+ FreehandLineItem* item = qgraphicsitem_cast<FreehandLineItem*>(lastItem);
+ if (item != 0) {
+ QPointF newPoint = this->mapToScene(event->pos());
+ item->lineTo(newPoint);
+ }
+ }
+ else if (mode == Polygon) {
+ QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(lastItem);
+ QPointF newPoint = this->mapToScene(event->pos());
+ QPolygonF polygon = item->polygon();
+ polygon.erase(polygon.end()-1);
+ polygon.append(newPoint);
+ item->setPolygon(polygon);
+ }
+ else if (mode == Select) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ if (item != 0) {
+ QPainterPath path;
+ QPointF beginPoint = selectionRect->data(0).toPointF();
+ QPointF newPoint = this->mapToScene(event->pos());
+ item->setPos(beginPoint + newPoint);
+ selectionRect->setPos(beginPoint + newPoint);
+ }
+ }
+ }
+
+ void GView::mousePressEvent(QMouseEvent *event)
+ {
+ mousePressed = true;
+ deselect();
+ if (mode == Line) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == Rect) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(0, point);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == Rubber) {
+ QPointF point = this->mapToScene(event->pos());
+ int w = pen.width();
+ QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
+ QList<QGraphicsItem*> list = scene()->items(rect);
+ if (!list.isEmpty())
+ {
+ QGraphicsItem* item = scene()->items(rect).first();
+ QString id = item->data(100).toString();
+ int pos = items_.indexOf(item)+1;
+ itemDeleted(id, pos);
+ deleteItem(id);
+ }
+ }
+ else if (mode == Circle) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(0, point);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else if (mode == HandLine) {
+ QPointF point = this->mapToScene(event->pos());
+ FreehandLineItem* item = new FreehandLineItem;
+ QString id = getNewID();
+ item->setPen(pen);
+ item->setStartPoint(point);
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ scene()->addItem(item);
+ lastItem = item;
+ }
+ else if (mode == Text) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsTextItem* item = scene()->addText("");
+ QString id = getNewID();
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ item->setDefaultTextColor(pen.color());
+ textDialog = new TextDialog(item, this);
+ connect(textDialog, SIGNAL(accepted(QGraphicsTextItem*)), this, SLOT(handleTextItemModified(QGraphicsTextItem*)));
+ textDialog->setAttribute(Qt::WA_DeleteOnClose);
+ textDialog->show();
+ item->setPos(point);
+ lastItem = item;
+ }
+ else if (mode == Polygon) {
+ QPointF point = this->mapToScene(event->pos());
+ QGraphicsPolygonItem* item = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
+ if (item == 0) {
+ QPolygonF polygon;
+ polygon.append(point);
+ polygon.append(point);
+ item = scene()->addPolygon(polygon, pen, brush);
+ QString id = getNewID();
+ item->setZValue(10000000);
+ item->setData(100, id);
+ item->setData(101, items_.size());
+ lastItem = item;
+ }
+ else {
+ QPolygonF polygon;
+ polygon = item->polygon();
+ polygon.append(point);
+ item->setPolygon(polygon);
+ }
+ }
+ else if (mode == Select) {
+ QPointF point = this->mapToScene(event->pos());
+ int w = pen.width();
+ if (w == 0) {
+ w = 1;
+ }
+ QRectF rect(point.x()-w, point.y()-w, w*2, w*2);
+ QList<QGraphicsItem*> list = scene()->items(rect);
+ if (!list.isEmpty()) {
+ QPen pen;
+ pen.setColor(QColor(Qt::gray));
+ pen.setStyle(Qt::DashLine);
+ QGraphicsItem *item = scene()->items(rect).first();
+ selectionRect = scene()->addRect(item->boundingRect(), pen);
+ selectionRect->setZValue(1000000);
+ selectionRect->setData(0, item->pos()-point);
+ selectionRect->setPos(item->pos());
+ QVariant var(QVariant::UserType);
+ var.setValue(item);
+ selectionRect->setData(1, var);
+ setActualPenAndBrushFromItem(item);
+ }
+ }
+ }
+
+ void GView::mouseReleaseEvent(QMouseEvent* /*event*/)
+ {
+ mousePressed = false;
+ QGraphicsPolygonItem* polygon = dynamic_cast<QGraphicsPolygonItem*>(lastItem);
+ if (polygon && polygon->polygon().size() >= 3) {
+ lastItemChanged(polygon, items_.indexOf(polygon)+1, Update);
+ } else if (lastItem) {
+ zValue++;
+ lastItem->setZValue(zValue++);
+ items_.append(lastItem);
+ itemsMap_.insert(lastItem->data(100).toString(), lastItem);
+
+ lastItemChanged(lastItem, items_.size(), New);
+ } else if (selectionRect){
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ lastItemChanged(item, items_.indexOf(item)+1, Update);
+ }
+ }
+
+
+ void GView::handleTextItemModified(QGraphicsTextItem* item) {
+ lastItemChanged(item, item->data(101).toInt(), Update);
+ }
+
+ void GView::moveUpSelectedItem()
+ {
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ int pos = items_.indexOf(item);
+ if (pos < items_.size()-1) {
+ lastItemChanged(item, pos+1, MoveUp);
+ move(item, pos+2);
+ }
+ }
+ }
+
+ void GView::moveDownSelectedItem()
+ {
+ if (selectionRect) {
+ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>();
+ int pos = items_.indexOf(item);
+ if (pos > 0) {
+ lastItemChanged(item, pos+1, MoveDown);
+ move(item, pos);
+ }
+ }
+ }
+
+ void GView::move(QGraphicsItem* item, int npos) {
+ int pos = items_.indexOf(item);
+ QGraphicsItem* itemAfter = NULL;
+ if (npos-1 > pos) {
+ if (npos == items_.size()) {
+ item->setZValue(zValue++);
+ } else {
+ itemAfter = items_.at(npos);
+ }
+
+ items_.insert(npos, item);
+ items_.removeAt(pos);
+ } else if (npos-1 < pos) {
+ itemAfter = items_.at(npos-1);
+ items_.insert(npos-1, item);
+ items_.removeAt(pos+1);
+ }
+ if (itemAfter) {
+ item->setZValue(itemAfter->zValue());
+ item->stackBefore(itemAfter);
+ }
+ }
+
+ void GView::changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush) {
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem) {
+ lineItem->setPen(pen);
+ }
+
+ FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (handLineItem) {
+ handLineItem->setPen(pen);
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem) {
+ rectItem->setPen(pen);
+ rectItem->setBrush(brush);
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem) {
+ textItem->setDefaultTextColor(pen.color());
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ polygonItem->setPen(pen);
+ polygonItem->setBrush(brush);
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ ellipseItem->setPen(pen);
+ ellipseItem->setBrush(brush);
+ }
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ void GView::setActualPenAndBrushFromItem(QGraphicsItem* item) {
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem) {
+ pen = lineItem->pen();
+ }
+
+ FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (handLineItem) {
+ pen = handLineItem->pen();
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem) {
+ pen = rectItem->pen();
+ brush = rectItem->brush();
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem) {
+ pen.setColor(textItem->defaultTextColor());
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ pen = polygonItem->pen();
+ brush = polygonItem->brush();
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ pen = ellipseItem->pen();
+ brush = ellipseItem->brush();
+ }
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+
+ void GView::deselect() {
+ if (selectionRect != 0) {
+ pen = defaultPen;
+ brush = defaultBrush;
+ scene()->removeItem(selectionRect);
+ delete selectionRect;
+ selectionRect = 0;
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+ }
+
+ void GView::deselect(QString id) {
+ if (selectionRect != 0) {
+ QGraphicsItem* item = getItem(id);
+ if (item && selectionRect->data(1).value<QGraphicsItem*>() == item) {
+ pen = defaultPen;
+ brush = defaultBrush;
+ scene()->removeItem(selectionRect);
+ delete selectionRect;
+ selectionRect = 0;
+ lineWidthChanged(pen.width());
+ lineColorChanged(pen.color());
+ brushColorChanged(brush.color());
+ }
+ }
+ }
+}
diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h
new file mode 100644
index 0000000..6a4fd2f
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/GView.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QGraphicsView>
+#include <QGraphicsLineItem>
+#include <QMouseEvent>
+#include <QPen>
+#include <iostream>
+#include <Swiften/Base/IDGenerator.h>
+
+#include "TextDialog.h"
+#include "FreehandLineItem.h"
+
+namespace Swift {
+ class GView : public QGraphicsView {
+ Q_OBJECT
+ public:
+ enum Mode { Rubber, Line, Rect, Circle, HandLine, Text, Polygon, Select };
+ enum Type { New, Update, MoveUp, MoveDown };
+ GView(QGraphicsScene* scene, QWidget* parent = 0);
+ void setLineWidth(int i);
+ void setLineColor(QColor color);
+ QColor getLineColor();
+ void setBrushColor(QColor color);
+ QColor getBrushColor();
+ void setMode(Mode mode);
+ void mouseMoveEvent(QMouseEvent* event);
+ void mousePressEvent(QMouseEvent* event);
+ void mouseReleaseEvent(QMouseEvent* /*event*/);
+ void addItem(QGraphicsItem* item, QString id, int pos);
+ void clear();
+ QGraphicsItem* getItem(QString id);
+ void deleteItem(QString id);
+ QString getNewID();
+ void move(QGraphicsItem* item, int npos);
+ void deselect(QString id);
+
+ public slots:
+ void moveUpSelectedItem();
+ void moveDownSelectedItem();
+
+ private slots:
+ void handleTextItemModified(QGraphicsTextItem*);
+ private:
+ void changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush);
+ void setActualPenAndBrushFromItem(QGraphicsItem* item);
+ void deselect();
+
+ int zValue;
+ bool mousePressed;
+ QPen pen;
+ QBrush brush;
+ QPen defaultPen;
+ QBrush defaultBrush;
+ Mode mode;
+ QGraphicsItem* lastItem;
+ QGraphicsRectItem* selectionRect;
+ TextDialog* textDialog;
+ QMap<QString, QGraphicsItem*> itemsMap_;
+ QList<QGraphicsItem*> items_;
+ IDGenerator idGenerator;
+
+ signals:
+ void lastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
+ void itemDeleted(QString id, int pos);
+ void lineWidthChanged(int i);
+ void lineColorChanged(QColor color);
+ void brushColorChanged(QColor color);
+ };
+}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
new file mode 100644
index 0000000..89de95e
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -0,0 +1,394 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtWhiteboardWindow.h"
+
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+#include <Swiften/Whiteboard/WhiteboardSession.h>
+#include <Swiften/Elements/WhiteboardPayload.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardLineElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardRectElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardInsertOperation.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardUpdateOperation.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardDeleteOperation.h>
+#include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h>
+
+#include <QMessageBox>
+#include <QLabel>
+
+namespace Swift {
+ QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession) : QWidget() {
+#ifndef Q_OS_MAC
+ setWindowIcon(QIcon(":/logo-icon-16.png"));
+#endif
+ layout = new QVBoxLayout(this);
+ hLayout = new QHBoxLayout;
+ sidebarLayout = new QVBoxLayout;
+ toolboxLayout = new QGridLayout;
+
+ scene = new QGraphicsScene(this);
+ scene->setSceneRect(0, 0, 400, 400);
+
+ graphicsView = new GView(scene, this);
+ graphicsView->setMode(GView::Line);
+ connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int, GView::Type)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int, GView::Type)));
+ connect(graphicsView, SIGNAL(itemDeleted(QString, int)), this, SLOT(handleItemDeleted(QString, int)));
+
+ widthBox = new QSpinBox(this);
+ connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int)));
+ connect(graphicsView, SIGNAL(lineWidthChanged(int)), widthBox, SLOT(setValue(int)));
+ widthBox->setValue(1);
+
+ moveUpButton = new QPushButton("Move Up", this);
+ connect(moveUpButton, SIGNAL(clicked()), graphicsView, SLOT(moveUpSelectedItem()));
+
+ moveDownButton = new QPushButton("Move Down", this);
+ connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem()));
+
+ strokeLayout = new QHBoxLayout;
+ strokeColor = new ColorWidget;
+ strokeLayout->addWidget(new QLabel("Stroke:"));
+ strokeLayout->addWidget(strokeColor);
+ connect(strokeColor, SIGNAL(clicked()), this, SLOT(showColorDialog()));
+ connect(graphicsView, SIGNAL(lineColorChanged(QColor)), strokeColor, SLOT(setColor(QColor)));
+
+ fillLayout = new QHBoxLayout;
+ fillColor = new ColorWidget;
+ fillLayout->addWidget(new QLabel("Fill:"));
+ fillLayout->addWidget(fillColor);
+ connect(fillColor, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
+ connect(graphicsView, SIGNAL(brushColorChanged(QColor)), fillColor, SLOT(setColor(QColor)));
+
+ rubberButton = new QToolButton(this);
+ rubberButton->setIcon(QIcon(":/icons/eraser.png"));
+ rubberButton->setCheckable(true);
+ rubberButton->setAutoExclusive(true);
+ connect(rubberButton, SIGNAL(clicked()), this, SLOT(setRubberMode()));
+
+ lineButton = new QToolButton(this);
+ lineButton->setIcon(QIcon(":/icons/line.png"));
+ lineButton->setCheckable(true);
+ lineButton->setAutoExclusive(true);
+ lineButton->setChecked(true);
+ connect(lineButton, SIGNAL(clicked()), this, SLOT(setLineMode()));
+
+ rectButton = new QToolButton(this);
+ rectButton->setIcon(QIcon(":/icons/rect.png"));
+ rectButton->setCheckable(true);
+ rectButton->setAutoExclusive(true);
+ connect(rectButton, SIGNAL(clicked()), this, SLOT(setRectMode()));
+
+ circleButton = new QToolButton(this);
+ circleButton->setIcon(QIcon(":/icons/circle.png"));
+ circleButton->setCheckable(true);
+ circleButton->setAutoExclusive(true);
+ connect(circleButton, SIGNAL(clicked()), this, SLOT(setCircleMode()));
+
+ handLineButton = new QToolButton(this);
+ handLineButton->setIcon(QIcon(":/icons/handline.png"));
+ handLineButton->setCheckable(true);
+ handLineButton->setAutoExclusive(true);
+ connect(handLineButton, SIGNAL(clicked()), this, SLOT(setHandLineMode()));
+
+ textButton = new QToolButton(this);
+ textButton->setIcon(QIcon(":/icons/text.png"));
+ textButton->setCheckable(true);
+ textButton->setAutoExclusive(true);
+ connect(textButton, SIGNAL(clicked()), this, SLOT(setTextMode()));
+
+ polygonButton = new QToolButton(this);
+ polygonButton->setIcon(QIcon(":/icons/polygon.png"));
+ polygonButton->setCheckable(true);
+ polygonButton->setAutoExclusive(true);
+ connect(polygonButton, SIGNAL(clicked()), this, SLOT(setPolygonMode()));
+
+ selectButton = new QToolButton(this);
+ selectButton->setIcon(QIcon(":/icons/cursor.png"));
+ selectButton->setCheckable(true);
+ selectButton->setAutoExclusive(true);
+ connect(selectButton, SIGNAL(clicked()), this, SLOT(setSelectMode()));
+
+ toolboxLayout->addWidget(rubberButton, 0, 0);
+ toolboxLayout->addWidget(selectButton, 0, 1);
+ toolboxLayout->addWidget(lineButton, 0, 2);
+ toolboxLayout->addWidget(circleButton, 1, 0);
+ toolboxLayout->addWidget(handLineButton, 1, 1);
+ toolboxLayout->addWidget(rectButton, 1, 2);
+ toolboxLayout->addWidget(textButton, 2, 0);
+ toolboxLayout->addWidget(polygonButton, 2, 1);
+
+ sidebarLayout->addLayout(toolboxLayout);
+ sidebarLayout->addSpacing(30);
+ sidebarLayout->addWidget(moveUpButton);
+ sidebarLayout->addWidget(moveDownButton);
+ sidebarLayout->addSpacing(40);
+ sidebarLayout->addWidget(widthBox);
+ sidebarLayout->addLayout(strokeLayout);
+ sidebarLayout->addLayout(fillLayout);
+ sidebarLayout->addStretch();
+ hLayout->addWidget(graphicsView);
+ hLayout->addLayout(sidebarLayout);
+ layout->addLayout(hLayout);
+ this->setLayout(layout);
+
+ setSession(whiteboardSession);
+ }
+
+ void QtWhiteboardWindow::handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation) {
+ WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation);
+ if (insertOp) {
+ WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::New);
+ insertOp->getElement()->accept(visitor);
+ }
+
+ WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation);
+ if (updateOp) {
+ WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::Update);
+ updateOp->getElement()->accept(visitor);
+ if (updateOp->getPos() != updateOp->getNewPos()) {
+ graphicsView->move(graphicsView->getItem(P2QSTRING(updateOp->getElement()->getID())), updateOp->getNewPos());
+ }
+ }
+
+ WhiteboardDeleteOperation::ref deleteOp = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(operation);
+ if (deleteOp) {
+ graphicsView->deleteItem(P2QSTRING(deleteOp->getElementID()));
+ }
+ }
+
+ void QtWhiteboardWindow::changeLineWidth(int i)
+ {
+ graphicsView->setLineWidth(i);
+ }
+
+ void QtWhiteboardWindow::showColorDialog()
+ {
+ QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel);
+ if(color.isValid())
+ graphicsView->setLineColor(color);
+ }
+
+ void QtWhiteboardWindow::showBrushColorDialog()
+ {
+ QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel);
+ if(color.isValid())
+ graphicsView->setBrushColor(color);
+ }
+
+ void QtWhiteboardWindow::setRubberMode()
+ {
+ graphicsView->setMode(GView::Rubber);
+ }
+
+ void QtWhiteboardWindow::setLineMode()
+ {
+ graphicsView->setMode(GView::Line);
+ }
+
+ void QtWhiteboardWindow::setRectMode()
+ {
+ graphicsView->setMode(GView::Rect);
+ }
+
+ void QtWhiteboardWindow::setCircleMode()
+ {
+ graphicsView->setMode(GView::Circle);
+ }
+
+ void QtWhiteboardWindow::setHandLineMode()
+ {
+ graphicsView->setMode(GView::HandLine);
+ }
+
+ void QtWhiteboardWindow::setTextMode()
+ {
+ graphicsView->setMode(GView::Text);
+ }
+
+ void QtWhiteboardWindow::setPolygonMode()
+ {
+ graphicsView->setMode(GView::Polygon);
+ }
+
+ void QtWhiteboardWindow::setSelectMode()
+ {
+ graphicsView->setMode(GView::Select);
+ }
+
+ void QtWhiteboardWindow::show()
+ {
+ QWidget::show();
+ }
+
+ void QtWhiteboardWindow::setSession(WhiteboardSession::ref session) {
+ graphicsView->clear();
+ whiteboardSession_ = session;
+ whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1));
+ whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this));
+ whiteboardSession_->onSessionTerminated.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this));
+ }
+
+ void QtWhiteboardWindow::activateWindow() {
+ QWidget::activateWindow();
+ }
+
+ void QtWhiteboardWindow::setName(const std::string& name) {
+ setWindowTitle(P2QSTRING(name));
+ }
+
+ void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type) {
+ WhiteboardElement::ref el;
+ QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item);
+ if (lineItem != 0) {
+ QLine line = lineItem->line().toLine();
+ QColor color = lineItem->pen().color();
+ WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1()+lineItem->pos().x(), line.y1()+lineItem->pos().y(), line.x2()+lineItem->pos().x(), line.y2()+lineItem->pos().y());
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+ element->setPenWidth(lineItem->pen().width());
+
+ element->setID(lineItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
+ if (freehandLineItem != 0) {
+ WhiteboardFreehandPathElement::ref element = boost::make_shared<WhiteboardFreehandPathElement>();
+ QColor color = freehandLineItem->pen().color();
+ std::vector<std::pair<int, int> > points;
+ QVector<QPointF>::const_iterator it = freehandLineItem->points().constBegin();
+ for ( ; it != freehandLineItem->points().constEnd(); ++it) {
+ points.push_back(std::pair<int, int>(
+ boost::numeric_cast<int>(it->x()+item->pos().x()),
+ boost::numeric_cast<int>(it->y()+item->pos().y())));
+ }
+
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+ element->setPenWidth(freehandLineItem->pen().width());
+ element->setPoints(points);
+
+ element->setID(freehandLineItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item);
+ if (rectItem != 0) {
+ QRectF rect = rectItem->rect();
+ WhiteboardRectElement::ref element = boost::make_shared<WhiteboardRectElement>(rect.x()+item->pos().x(), rect.y()+item->pos().y(), rect.width(), rect.height());
+ QColor penColor = rectItem->pen().color();
+ QColor brushColor = rectItem->brush().color();
+
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setPenWidth(rectItem->pen().width());
+
+ element->setID(rectItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item);
+ if (textItem != 0) {
+ QPointF point = textItem->pos();
+ WhiteboardTextElement::ref element = boost::make_shared<WhiteboardTextElement>(point.x(), point.y());
+ element->setText(textItem->toPlainText().toStdString());
+ element->setSize(textItem->font().pointSize());
+ QColor color = textItem->defaultTextColor();
+ element->setColor(WhiteboardColor(color.red(), color.green(), color.blue(), color.alpha()));
+
+ element->setID(textItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item);
+ if (polygonItem) {
+ WhiteboardPolygonElement::ref element = boost::make_shared<WhiteboardPolygonElement>();
+ QPolygonF polygon = polygonItem->polygon();
+ std::vector<std::pair<int, int> > points;
+ QVector<QPointF>::const_iterator it = polygon.begin();
+ for (; it != polygon.end(); ++it) {
+ points.push_back(std::pair<int, int>(
+ boost::numeric_cast<int>(it->x()+item->pos().x()),
+ boost::numeric_cast<int>(it->y()+item->pos().y())));
+ }
+
+ element->setPoints(points);
+
+ QColor penColor = polygonItem->pen().color();
+ QColor brushColor = polygonItem->brush().color();
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenWidth(polygonItem->pen().width());
+
+ element->setID(polygonItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ QRectF rect = ellipseItem->rect();
+ int cx = boost::numeric_cast<int>(rect.x()+rect.width()/2 + item->pos().x());
+ int cy = boost::numeric_cast<int>(rect.y()+rect.height()/2 + item->pos().y());
+ int rx = boost::numeric_cast<int>(rect.width()/2);
+ int ry = boost::numeric_cast<int>(rect.height()/2);
+ WhiteboardEllipseElement::ref element = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry);
+
+ QColor penColor = ellipseItem->pen().color();
+ QColor brushColor = ellipseItem->brush().color();
+ element->setPenColor(WhiteboardColor(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setBrushColor(WhiteboardColor(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenWidth(ellipseItem->pen().width());
+
+ element->setID(ellipseItem->data(100).toString().toStdString());
+ el = element;
+ }
+
+ if (type == GView::New) {
+ WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>();
+ insertOp->setPos(pos);
+ insertOp->setElement(el);
+ whiteboardSession_->sendOperation(insertOp);
+ } else {
+ WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>();
+ updateOp->setPos(pos);
+ if (type == GView::Update) {
+ updateOp->setNewPos(pos);
+ } else if (type == GView::MoveUp) {
+ updateOp->setNewPos(pos+1);
+ } else if (type == GView::MoveDown) {
+ updateOp->setNewPos(pos-1);
+ }
+ updateOp->setElement(el);
+ whiteboardSession_->sendOperation(updateOp);
+ }
+ }
+
+ void QtWhiteboardWindow::handleItemDeleted(QString id, int pos) {
+ WhiteboardDeleteOperation::ref deleteOp = boost::make_shared<WhiteboardDeleteOperation>();
+ deleteOp->setElementID(Q2PSTRING(id));
+ deleteOp->setPos(pos);
+ whiteboardSession_->sendOperation(deleteOp);
+ }
+
+ void QtWhiteboardWindow::handleSessionTerminate() {
+ hide();
+ }
+
+ void QtWhiteboardWindow::closeEvent(QCloseEvent* event) {
+ QMessageBox box(this);
+ box.setText(tr("Closing window is equivalent closing the session. Are you sure you want to do this?"));
+ box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ box.setIcon(QMessageBox::Question);
+ if (box.exec() == QMessageBox::Yes) {
+ whiteboardSession_->cancel();
+ } else {
+ event->ignore();
+ }
+ }
+}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
new file mode 100644
index 0000000..3957bb7
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h>
+#include <Swiften/Elements/Message.h>
+#include <Swiften/Whiteboard/WhiteboardSession.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardElement.h>
+
+#include <QWidget>
+#include <QGraphicsView>
+#include <QGraphicsScene>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QGridLayout>
+#include <QPainter>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QColorDialog>
+#include <QToolButton>
+#include <QCloseEvent>
+
+#include "GView.h"
+#include "ColorWidget.h"
+
+namespace Swift {
+ class QtWhiteboardWindow : public QWidget, public WhiteboardWindow
+ {
+ Q_OBJECT
+ public:
+ QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession);
+ void show();
+ void setSession(WhiteboardSession::ref session);
+ void activateWindow();
+ void setName(const std::string& name);
+
+ private slots:
+ void changeLineWidth(int i);
+ void showColorDialog();
+ void showBrushColorDialog();
+ void setRubberMode();
+ void setLineMode();
+ void setRectMode();
+ void setCircleMode();
+ void setHandLineMode();
+ void setTextMode();
+ void setPolygonMode();
+ void setSelectMode();
+ void handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type);
+ void handleItemDeleted(QString id, int pos);
+
+ private:
+ void handleSessionTerminate();
+ void handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation);
+ void closeEvent(QCloseEvent* event);
+
+ private:
+ QGraphicsScene* scene;
+ GView* graphicsView;
+ QVBoxLayout* layout;
+ QVBoxLayout* sidebarLayout;
+ QHBoxLayout* hLayout;
+ QGridLayout* toolboxLayout;
+ QHBoxLayout* strokeLayout;
+ QHBoxLayout* fillLayout;
+ ColorWidget* strokeColor;
+ ColorWidget* fillColor;
+ QWidget* widget;
+ QPushButton* moveUpButton;
+ QPushButton* moveDownButton;
+ QSpinBox* widthBox;
+ QToolButton* rubberButton;
+ QToolButton* lineButton;
+ QToolButton* rectButton;
+ QToolButton* circleButton;
+ QToolButton* handLineButton;
+ QToolButton* textButton;
+ QToolButton* polygonButton;
+ QToolButton* selectButton;
+
+ std::string lastOpID;
+ WhiteboardSession::ref whiteboardSession_;
+ };
+}
diff --git a/Swift/QtUI/Whiteboard/TextDialog.cpp b/Swift/QtUI/Whiteboard/TextDialog.cpp
new file mode 100644
index 0000000..021895a
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/TextDialog.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "TextDialog.h"
+
+namespace Swift {
+ TextDialog::TextDialog(QGraphicsTextItem* item, QWidget* parent) : QDialog(parent)
+ {
+ this->item = item;
+
+ layout = new QVBoxLayout(this);
+ hLayout = new QHBoxLayout;
+
+ editor = new QLineEdit(this);
+ connect(editor, SIGNAL(textChanged(const QString&)), this, SLOT(changeItemText(const QString&)));
+
+ fontSizeBox = new QSpinBox(this);
+ fontSizeBox->setMinimum(1);
+ connect(fontSizeBox, SIGNAL(valueChanged(int)), this, SLOT(changeItemFontSize(int)));
+ fontSizeBox->setValue(13);
+
+
+ buttonBox = new QDialogButtonBox(this);
+ buttonBox->setStandardButtons(QDialogButtonBox::Ok);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+
+ hLayout->addWidget(editor);
+ hLayout->addWidget(fontSizeBox);
+ layout->addLayout(hLayout);
+ layout->addWidget(buttonBox);
+ }
+
+ void TextDialog::changeItemText(const QString &text)
+ {
+ item->setPlainText(text);
+ }
+
+ void TextDialog::changeItemFontSize(int i)
+ {
+ QFont font = item->font();
+ font.setPointSize(i);
+ item->setFont(font);
+ }
+
+ void TextDialog::accept() {
+ emit accepted(item);
+ done(QDialog::Accepted);
+ }
+}
diff --git a/Swift/QtUI/Whiteboard/TextDialog.h b/Swift/QtUI/Whiteboard/TextDialog.h
new file mode 100644
index 0000000..64a0fe2
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/TextDialog.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <QDialog>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QDialogButtonBox>
+#include <QLineEdit>
+#include <QGraphicsTextItem>
+#include <QSpinBox>
+
+#include <iostream>
+
+namespace Swift {
+ class TextDialog : public QDialog
+ {
+ Q_OBJECT
+ public:
+ TextDialog(QGraphicsTextItem* item, QWidget* parent = 0);
+
+ private:
+ QGraphicsTextItem* item;
+ QLineEdit* editor;
+ QDialogButtonBox* buttonBox;
+ QVBoxLayout* layout;
+ QHBoxLayout* hLayout;
+ QSpinBox* fontSizeBox;
+
+ signals:
+ void accepted(QGraphicsTextItem* item);
+
+ private slots:
+ void accept();
+ void changeItemText(const QString &text);
+ void changeItemFontSize(int i);
+ };
+}
+
diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
new file mode 100644
index 0000000..74c6c1d
--- /dev/null
+++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/Whiteboard/WhiteboardElementVisitor.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardLineElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardPolygonElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardTextElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardEllipseElement.h>
+#include <Swiften/Elements/Whiteboard/WhiteboardFreehandPathElement.h>
+#include <Swift/QtUI/Whiteboard/GView.h>
+#include <QtSwiftUtil.h>
+
+namespace Swift {
+ class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor {
+ public:
+ WhiteboardElementDrawingVisitor(GView* graphicsView, int pos, GView::Type type) : graphicsView_(graphicsView), pos_(pos), type_(type) {}
+
+ void visit(WhiteboardLineElement& element) {
+ QGraphicsLineItem *item;
+ if (type_ == GView::New) {
+ item = new QGraphicsLineItem(element.x1(), element.y1(), element.x2(), element.y2());
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ QLineF line(element.x1(), element.y1(), element.x2(), element.y2());
+ item->setLine(line);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ if (item) {
+ QPen pen;
+ WhiteboardColor color = element.getColor();
+ pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ item->setPen(pen);
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardFreehandPathElement& element) {
+ FreehandLineItem *item;
+ if (type_ == GView::New) {
+ item = new FreehandLineItem;
+ } else {
+ item = qgraphicsitem_cast<FreehandLineItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+
+ if (item) {
+ QPen pen;
+ WhiteboardColor color = element.getColor();
+ pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ item->setPen(pen);
+
+ std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
+ item->setStartPoint(QPointF(it->first, it->second));
+ for (++it; it != element.getPoints().end(); ++it) {
+ item->lineTo(QPointF(it->first, it->second));
+ }
+
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ if (type_ == GView::New) {
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ }
+ }
+
+ void visit(WhiteboardRectElement& element) {
+ QGraphicsRectItem* item;
+ if (type_ == GView::New) {
+ item = new QGraphicsRectItem(element.getX(), element.getY(), element.getWidth(), element.getHeight());
+ graphicsView_->addItem(item, P2QSTRING(element.getID()), pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsRectItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ QRectF rect(element.getX(), element.getY(), element.getWidth(), element.getHeight());
+ item->setRect(rect);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+
+ if (item) {
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardPolygonElement& element) {
+ QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
+ if (item == 0 && type_ == GView::New) {
+ item = new QGraphicsPolygonItem();
+ QString id = P2QSTRING(element.getID());
+ item->setData(100, id);
+ graphicsView_->addItem(item, id, pos_);
+ }
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+
+ item->setPos(0,0);
+ QPolygonF polygon;
+ std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
+ for (; it != element.getPoints().end(); ++it) {
+ polygon.append(QPointF(it->first, it->second));
+ }
+ item->setPolygon(polygon);
+ }
+
+ void visit(WhiteboardTextElement& element) {
+ QGraphicsTextItem* item;
+ QString id = P2QSTRING(element.getID());
+ if (type_ == GView::New) {
+ item = new QGraphicsTextItem;
+ graphicsView_->addItem(item, id, pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsTextItem*>(graphicsView_->getItem(id));
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ if (item) {
+ item->setPlainText(P2QSTRING(element.getText()));
+ item->setPos(QPointF(element.getX(), element.getY()));
+ QFont font = item->font();
+ font.setPointSize(element.getSize());
+ item->setFont(font);
+ WhiteboardColor color = element.getColor();
+ item->setDefaultTextColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ item->setData(100, id);
+ }
+ }
+
+ void visit(WhiteboardEllipseElement& element) {
+ QRectF rect;
+ QGraphicsEllipseItem* item;
+ QString id = P2QSTRING(element.getID());
+ rect.setTopLeft(QPointF(element.getCX()-element.getRX(), element.getCY()-element.getRY()));
+ rect.setBottomRight(QPointF(element.getCX()+element.getRX(), element.getCY()+element.getRY()));
+ if (type_ == GView::New) {
+ item = new QGraphicsEllipseItem(rect);
+ graphicsView_->addItem(item, id, pos_);
+ } else {
+ item = qgraphicsitem_cast<QGraphicsEllipseItem*>(graphicsView_->getItem(id));
+ item->setRect(rect);
+ item->setPos(0,0);
+ graphicsView_->deselect(P2QSTRING(element.getID()));
+ }
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ WhiteboardColor penColor = element.getPenColor();
+ WhiteboardColor brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+ item->setData(100, id);
+ }
+
+ private:
+ GView* graphicsView_;
+ int pos_;
+ GView::Type type_;
+ };
+}
diff --git a/Swift/QtUI/WinUIHelpers.cpp b/Swift/QtUI/WinUIHelpers.cpp
new file mode 100644
index 0000000..161ff1d
--- /dev/null
+++ b/Swift/QtUI/WinUIHelpers.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "WinUIHelpers.h"
+
+#include <windows.h>
+#include <Wincrypt.h>
+#include <cryptuiapi.h>
+#pragma comment(lib, "cryptui.lib")
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/foreach.h>
+
+namespace Swift {
+
+void WinUIHelpers::displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain) {
+ if (chain.empty()) {
+ return;
+ }
+
+ // create certificate store to store the certificate chain in
+ HCERTSTORE chainStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG, NULL);
+ if (!chainStore) {
+ return;
+ }
+
+ ByteArray certAsDER = chain[0]->toDER();
+ boost::shared_ptr<const CERT_CONTEXT> certificate_chain;
+ {
+ PCCERT_CONTEXT certChain;
+ BOOL ok = CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, &certChain);
+ // maybe free the cert contex we created
+ if (!ok || !certChain) {
+ return;
+ }
+ certificate_chain.reset(certChain, CertFreeCertificateContext);
+ }
+
+ for (size_t i = 1; i < chain.size(); ++i) {
+ ByteArray certAsDER = chain[i]->toDER();
+ CertAddCertificateContextToStore(chainStore, CertCreateCertificateContext(X509_ASN_ENCODING, vecptr(certAsDER), certAsDER.size()), CERT_STORE_ADD_ALWAYS, NULL);
+ }
+
+ CRYPTUI_VIEWCERTIFICATE_STRUCT viewDialogProperties = { 0 };
+ viewDialogProperties.dwSize = sizeof(viewDialogProperties);
+ viewDialogProperties.hwndParent = (HWND) parent->winId();
+ viewDialogProperties.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE | CRYPTUI_ENABLE_REVOCATION_CHECKING;
+ viewDialogProperties.pCertContext = certificate_chain.get();
+ viewDialogProperties.cStores = 1;
+ viewDialogProperties.rghStores = &chainStore;
+ BOOL properties_changed;
+
+ // blocking call that shows modal certificate dialog
+ BOOL rv = ::CryptUIDlgViewCertificate(&viewDialogProperties, &properties_changed);
+}
+
+}
diff --git a/Swift/QtUI/WinUIHelpers.h b/Swift/QtUI/WinUIHelpers.h
new file mode 100644
index 0000000..d34d236
--- /dev/null
+++ b/Swift/QtUI/WinUIHelpers.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/TLS/Certificate.h>
+#include <QWidget>
+
+namespace Swift {
+
+class WinUIHelpers {
+public:
+ static void displayCertificateChainAsSheet(QWidget* parent, const std::vector<Certificate::ref>& chain);
+};
+
+}
+
diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp
index fc3bf15..d734713 100644
--- a/Swift/QtUI/main.cpp
+++ b/Swift/QtUI/main.cpp
@@ -20,4 +20,7 @@
#include <Swift/Controllers/BuildVersion.h>
#include <SwifTools/Application/PlatformApplicationPathProvider.h>
+#include <SwifTools/CrashReporter.h>
+#include <stdlib.h>
+#include <Swiften/Base/Path.h>
#include "QtSwift.h"
@@ -28,21 +31,11 @@ int main(int argc, char* argv[]) {
QApplication app(argc, argv);
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
+ Swift::PlatformApplicationPathProvider applicationPathProvider(SWIFT_APPLICATION_NAME);
- // Translation
- QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
- boost::filesystem::path someTranslationPath = Swift::PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME).getResourcePath("/translations/swift_en.qm");
- QTranslator qtTranslator;
- if (!someTranslationPath.empty()) {
-#if QT_VERSION >= 0x040800
- qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", someTranslationPath.parent_path().string().c_str());
-#else
- //std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), someTranslationPath.parent_path().string().c_str());
+ Swift::CrashReporter crashReporter(applicationPathProvider.getDataDir() / "crashes");
+
+#if QT_VERSION < 0x050000
+ QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
- }
- app.installTranslator(&qtTranslator);
- QtTranslator swiftTranslator;
- Swift::Translator::setInstance(&swiftTranslator);
// Parse program options
@@ -72,4 +65,29 @@ int main(int argc, char* argv[]) {
}
+ // Translation
+#if QT_VERSION < 0x050000
+ QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
+#endif
+ boost::filesystem::path someTranslationPath = applicationPathProvider.getResourcePath("/translations/swift_en.qm");
+
+ QTranslator qtTranslator;
+ if (!someTranslationPath.empty()) {
+#if QT_VERSION >= 0x040800
+ if (vm.count("language") > 0) {
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
+ }
+ else {
+ qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
+ }
+#else
+ //std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), P2QSTRING(Swift::pathToString(someTranslationPath)));
+#endif
+ }
+ app.installTranslator(&qtTranslator);
+ QtTranslator swiftTranslator;
+ Swift::Translator::setInstance(&swiftTranslator);
+
+
Swift::QtSwift swift(vm);
int result = app.exec();