aboutsummaryrefslogtreecommitdiff
path: root/lib/accountregistry.h
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-08-24 23:59:48 +0200
committerTobias Fella <fella@posteo.de>2021-08-26 18:16:07 +0200
commit8d21c8a6579ad9c63e331ffb42e3ed81b9c73caf (patch)
treef31b2f3e7217302e4dd37e288be6fa6d219401d1 /lib/accountregistry.h
parent6953e55361f600a591c08b9cd287a350230b3ef8 (diff)
downloadlibquotient-8d21c8a6579ad9c63e331ffb42e3ed81b9c73caf.tar.gz
libquotient-8d21c8a6579ad9c63e331ffb42e3ed81b9c73caf.zip
Add AccountRegistry
Basic session management class; Created from Quaternion's AccountRegistry and NeoChat's AccountListModel. The connections can be accessed by the user's id, this technically limits it to one connection for each matrix account.
Diffstat (limited to 'lib/accountregistry.h')
-rw-r--r--lib/accountregistry.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/accountregistry.h b/lib/accountregistry.h
new file mode 100644
index 00000000..e87da3e8
--- /dev/null
+++ b/lib/accountregistry.h
@@ -0,0 +1,45 @@
+// SPDX-FileCopyrightText: 2020 Kitsune Ral <Kitsune-Ral@users.sf.net>
+// SPDX-FileCopyrightText: Tobias Fella <fella@posteo.de>
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#pragma once
+
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <QtCore/QAbstractListModel>
+
+namespace Quotient {
+class Connection;
+
+class AccountRegistry : public QAbstractListModel {
+ Q_OBJECT
+public:
+ enum EventRoles {
+ ConnectionRole = Qt::UserRole + 1,
+ };
+
+ static AccountRegistry &instance() {
+ static AccountRegistry _instance;
+ return _instance;
+ }
+
+ const QVector<Connection*> accounts() const;
+ void add(Connection* a);
+ void drop(Connection* a);
+ bool isLoggedIn(const QString& userId) const;
+ bool isEmpty() const;
+ int count() const;
+ bool contains(Connection*) const;
+ Connection* get(const QString& userId);
+
+ [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
+
+ [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
+
+private:
+ AccountRegistry();
+
+ QVector<Connection *> m_accounts;
+};
+} \ No newline at end of file