summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2018-07-02 11:33:41 (GMT)
committerThanos Doukoudakis <thanos.doukoudakis@isode.com>2018-07-19 12:13:09 (GMT)
commit0011a649c6bf997dd3a5cf7fabe3c9733fc573f9 (patch)
tree14151eb85e0c276420e87f21e1caffca34f07ad4 /Swift/QtUI/ServerList/ServerListModel.cpp
parent0d5cd98d372c6b9235b55cd8d16e93647c9d017f (diff)
downloadswift-0011a649c6bf997dd3a5cf7fabe3c9733fc573f9.zip
swift-0011a649c6bf997dd3a5cf7fabe3c9733fc573f9.tar.bz2
Add server avatars to multiaccount
This patch implements a Model/View/Delegate for the multiple accounts a user might have. The list is shown on the left of the client, with an avatar, status presence and unread message counter. Mouse over a server avatar will show the user jid that was used to connect to the server. Server avatars are currently using the default Swift logo, server information are not connected with the actual data, and the presence icon is not being rendered. Future patches will improve this and connect to the actual server data. Test-Information Tested the changes in the UI in Windows 10 Qt5.8 and Ubuntu 16.04 Qt 5.6. Tested the status change, login, logout and saving account information during startup. Change-Id: I4aa86afffe6a02d589b47185cc587b2e09de7450
Diffstat (limited to 'Swift/QtUI/ServerList/ServerListModel.cpp')
-rw-r--r--Swift/QtUI/ServerList/ServerListModel.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/Swift/QtUI/ServerList/ServerListModel.cpp b/Swift/QtUI/ServerList/ServerListModel.cpp
new file mode 100644
index 0000000..e5dc35e
--- /dev/null
+++ b/Swift/QtUI/ServerList/ServerListModel.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+//#include <Swift/QtUI/ServerList/ServerListModel.h>
+#include <QBrush>
+#include <QColor>
+#include <QMimeData>
+
+#include "ServerListModel.h"
+
+namespace Swift {
+
+ServerListModel::ServerListModel() {
+}
+
+ServerListModel::~ServerListModel() {
+}
+
+QVariant ServerListModel::data(const QModelIndex& index, int role) const {
+ if (!index.isValid()) {
+ return QVariant();
+ }
+ SwiftAccountData::SwiftAccountDataItem* item = static_cast<SwiftAccountData::SwiftAccountDataItem*>(index.internalPointer());
+ switch (role) {
+ case Qt::DisplayRole: return QString(item->userJID_.toBare().toString().c_str());
+ case Qt::BackgroundRole: return QBrush(Qt::transparent);
+ case Qt::ToolTipRole: return QString(item->userJID_.toBare().toString().c_str());
+ default: return QVariant();
+ }
+}
+
+QModelIndex ServerListModel::index(int row, int column, const QModelIndex& /*parent*/) const {
+ if (!modelData_ || static_cast<size_t>(row) >= modelData_->size()) {
+ return QModelIndex();
+ }
+ return createIndex(row, column, modelData_->getAccount(row));
+}
+
+QModelIndex ServerListModel::parent(const QModelIndex& /*index*/) const {
+ return QModelIndex();
+}
+
+QMimeData* ServerListModel::mimeData(const QModelIndexList& indexes) const {
+ return QAbstractItemModel::mimeData(indexes);
+}
+
+int ServerListModel::rowCount(const QModelIndex& /*parent*/) const {
+ if (!modelData_) {
+ return 0;
+ }
+ return modelData_->size();
+}
+
+int ServerListModel::columnCount(const QModelIndex& /*parent*/) const {
+ if (!modelData_) {
+ return 0;
+ }
+ return 1;
+}
+
+void ServerListModel::handleDataChanged() {
+ emit layoutChanged();
+}
+
+}