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.h
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.h')
-rw-r--r--Swift/QtUI/ServerList/ServerListModel.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/Swift/QtUI/ServerList/ServerListModel.h b/Swift/QtUI/ServerList/ServerListModel.h
new file mode 100644
index 0000000..86541a0
--- /dev/null
+++ b/Swift/QtUI/ServerList/ServerListModel.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2018 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/signals2.hpp>
+
+#include <QAbstractItemModel>
+
+#include <Swiften/Elements/StatusShow.h>
+#include <Swiften/JID/JID.h>
+
+namespace Swift {
+
+ class SwiftAccountData {
+ public:
+ struct SwiftAccountDataItem {
+ SwiftAccountDataItem(std::string serverID) : serverID_(serverID) {}
+ //FIXME eliminate serverID_, the userJID_ will be the ID when we connect with the actual data.
+ std::string serverID_;
+ QString iconPath_;
+ JID userJID_;
+ size_t unreadCount_ = 0;
+ StatusShow status_ = StatusShow::None;
+ boost::signals2::scoped_connection dataChangedConnection_;
+ boost::signals2::signal<void ()> onDataChanged;
+ void handleChangeStatusRequest(StatusShow::Type show, const std::string& /*statusText*/) {
+ status_ = show;
+ onDataChanged();
+ }
+ };
+ public:
+ SwiftAccountData() {}
+ ~SwiftAccountData() {
+ for (auto account : accounts_) {
+ delete account;
+ }
+ }
+ //FIXME make addAccount with SwiftAccountDataItem, and added after a succesfull connection to the server has been established.
+ void addAccount(JID userJID) {
+ SwiftAccountDataItem* newItem = new SwiftAccountDataItem(userJID);
+ newItem->dataChangedConnection_ = newItem->onDataChanged.connect(boost::bind(&SwiftAccountData::handleDataChanged, this));
+ accounts_.push_back(newItem);
+ }
+ SwiftAccountDataItem* getAccount(int index) {
+ if (index >= accounts_.size()) {
+ return nullptr;
+ }
+ return accounts_[index];
+ }
+ size_t size() {
+ return accounts_.size();
+ }
+ public:
+ boost::signals2::signal<void()> onDataChanged;
+ private:
+ void handleDataChanged() {
+ onDataChanged();
+ }
+ private:
+ QList<SwiftAccountDataItem*> accounts_;
+ };
+
+ class ServerListModel : public QAbstractItemModel {
+ Q_OBJECT
+ public:
+ ServerListModel();
+ ~ServerListModel();
+
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
+ QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
+ QModelIndex parent(const QModelIndex& index) const override;
+
+ QMimeData* mimeData(const QModelIndexList& indexes) const override;
+
+ virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
+ virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
+
+ void setModelData(SwiftAccountData* data) { modelData_ = data; }
+ void handleDataChanged();
+ private:
+ SwiftAccountData* modelData_;
+ };
+}