2018-02-27 05:10:08 +00:00
|
|
|
#ifndef CONTROLLER_H
|
|
|
|
#define CONTROLLER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
2018-07-08 05:25:46 +00:00
|
|
|
#include "connection.h"
|
|
|
|
#include "user.h"
|
2018-02-28 09:10:42 +00:00
|
|
|
#include "roomlistmodel.h"
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-02-28 09:10:42 +00:00
|
|
|
namespace QMatrixClient {
|
|
|
|
class Connection;
|
|
|
|
}
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-02-27 05:10:08 +00:00
|
|
|
class Controller : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection NOTIFY connectionChanged)
|
2018-02-27 11:37:53 +00:00
|
|
|
Q_PROPERTY(bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged)
|
2018-07-07 09:38:20 +00:00
|
|
|
Q_PROPERTY(QString homeserver READ getHomeserver WRITE setHomeserver NOTIFY homeserverChanged)
|
2018-02-27 11:07:50 +00:00
|
|
|
Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged)
|
|
|
|
Q_PROPERTY(QByteArray token READ getToken WRITE setToken NOTIFY tokenChanged)
|
2018-07-07 09:38:20 +00:00
|
|
|
Q_PROPERTY(bool busy READ getBusy WRITE setBusy NOTIFY busyChanged)
|
2018-03-01 11:15:04 +00:00
|
|
|
|
2018-03-06 11:11:39 +00:00
|
|
|
public:
|
|
|
|
explicit Controller(QObject *parent = nullptr);
|
|
|
|
~Controller();
|
|
|
|
|
|
|
|
// All the Q_INVOKABLEs.
|
2018-07-07 09:38:20 +00:00
|
|
|
Q_INVOKABLE void login();
|
|
|
|
Q_INVOKABLE void loginWithCredentials(QString, QString, QString);
|
2018-03-06 11:11:39 +00:00
|
|
|
Q_INVOKABLE void logout();
|
|
|
|
|
|
|
|
// All the non-Q_INVOKABLE functions.
|
|
|
|
|
|
|
|
// All the Q_PROPERTYs.
|
2018-07-07 09:38:20 +00:00
|
|
|
QMatrixClient::Connection* m_connection = new QMatrixClient::Connection();
|
2018-03-06 11:11:39 +00:00
|
|
|
QMatrixClient::Connection* getConnection() { return m_connection; }
|
|
|
|
|
|
|
|
bool isLogin = false;
|
|
|
|
bool getIsLogin() { return isLogin; }
|
|
|
|
void setIsLogin(bool n) {
|
|
|
|
if(n != isLogin) {
|
|
|
|
isLogin = n;
|
|
|
|
emit isLoginChanged();
|
|
|
|
}
|
2018-02-27 11:37:53 +00:00
|
|
|
}
|
2018-03-06 11:11:39 +00:00
|
|
|
|
|
|
|
QString userID;
|
|
|
|
QString getUserID() { return userID; }
|
|
|
|
void setUserID(QString n) {
|
|
|
|
if(n != userID) {
|
|
|
|
userID = n;
|
|
|
|
emit userIDChanged();
|
|
|
|
}
|
2018-02-27 11:07:50 +00:00
|
|
|
}
|
2018-03-06 11:11:39 +00:00
|
|
|
|
|
|
|
QByteArray token;
|
|
|
|
QByteArray getToken() { return token; }
|
|
|
|
void setToken(QByteArray n) {
|
|
|
|
if(n != token) {
|
|
|
|
token = n;
|
|
|
|
emit tokenChanged();
|
|
|
|
}
|
2018-02-27 11:07:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 09:38:20 +00:00
|
|
|
QString homeserver;
|
|
|
|
QString getHomeserver() { return homeserver; }
|
|
|
|
void setHomeserver(QString n) {
|
|
|
|
if (n != homeserver) {
|
|
|
|
homeserver = n;
|
|
|
|
emit homeserverChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool busy = false;
|
|
|
|
bool getBusy() { return busy; }
|
|
|
|
void setBusy(bool b) {
|
|
|
|
if (b != busy) {
|
|
|
|
busy = b;
|
|
|
|
emit busyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-06 11:11:39 +00:00
|
|
|
private:
|
|
|
|
void connected();
|
|
|
|
void resync();
|
|
|
|
void reconnect();
|
2018-02-27 05:10:08 +00:00
|
|
|
|
2018-03-06 11:11:39 +00:00
|
|
|
signals:
|
|
|
|
void connectionChanged();
|
|
|
|
void isLoginChanged();
|
|
|
|
void userIDChanged();
|
|
|
|
void tokenChanged();
|
2018-07-07 09:38:20 +00:00
|
|
|
void homeserverChanged();
|
|
|
|
void busyChanged();
|
|
|
|
void errorOccured();
|
2018-02-27 05:10:08 +00:00
|
|
|
|
2018-03-06 11:11:39 +00:00
|
|
|
public slots:
|
2018-02-27 05:10:08 +00:00
|
|
|
};
|
|
|
|
|
2018-02-27 11:07:50 +00:00
|
|
|
#endif // CONTROLLER_H
|