File indexing completed on 2024-06-02 05:18:53

0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #ifndef MATRIXMANAGER_H
0005 #define MATRIXMANAGER_H
0006 
0007 #include <QObject>
0008 
0009 #include <Quotient/connection.h>
0010 
0011 class MatrixManager : public QObject
0012 {
0013     Q_OBJECT
0014     Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
0015     Q_PROPERTY(QString infoString READ infoString NOTIFY infoStringChanged)
0016     Q_PROPERTY(QString userId READ userId NOTIFY userIdChanged)
0017     Q_PROPERTY(Quotient::Connection *connection READ connection NOTIFY connectionChanged)
0018 
0019 public:
0020     explicit MatrixManager(QObject *parent = nullptr);
0021 
0022     /**
0023      * Log in to a connection
0024      * @param matrixId user id in the form @user:server.tld
0025      * @param password
0026      */
0027     Q_INVOKABLE void login(const QString &matrixId, const QString &password);
0028 
0029     /**
0030      * Log out of the connection
0031      */
0032     Q_INVOKABLE void logout();
0033 
0034     /**
0035      * Run a single sync. We're not syncing constantly, since we typically don't need it and it consumes a lot of data
0036      */
0037     Q_INVOKABLE void sync();
0038 
0039     QString infoString() const;
0040     bool connected() const;
0041     QString userId() const;
0042     Quotient::Connection *connection() const;
0043 
0044     Q_INVOKABLE void postLocation(const QString &roomId, float latitude, float longitude, const QString &description);
0045     void postEvent(const QString &roomId, const QString &type, const QJsonObject &content);
0046 
0047 Q_SIGNALS:
0048     void connectedChanged();
0049     void infoStringChanged();
0050     void userIdChanged();
0051     void connectionChanged();
0052 
0053 private:
0054     QString m_infoString;
0055 
0056     void setInfoString(const QString &infoString);
0057 };
0058 
0059 #endif //MATRIXMANAGER_H