2018-02-27 05:10:08 +00:00
|
|
|
#include "controller.h"
|
|
|
|
|
2018-02-27 11:07:50 +00:00
|
|
|
#include "libqmatrixclient/connection.h"
|
2018-02-27 05:10:08 +00:00
|
|
|
|
2018-02-27 11:07:50 +00:00
|
|
|
Controller::Controller(QObject *parent) : QObject(parent) {
|
2018-02-27 11:37:53 +00:00
|
|
|
connect(connection, &Connection::connected, this, &Controller::connected);
|
|
|
|
connect(connection, &Connection::resolveError, this, &Controller::reconnect);
|
|
|
|
connect(connection, &Connection::syncError, this, &Controller::reconnect);
|
|
|
|
connect(connection, &Connection::syncDone, this, &Controller::resync);
|
2018-02-27 11:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Controller::~Controller() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-27 11:37:53 +00:00
|
|
|
void Controller::login(QString home, QString user, QString pass) {
|
|
|
|
if(home.isEmpty()) home = "matrix.org";
|
2018-02-27 11:07:50 +00:00
|
|
|
|
2018-02-27 11:37:53 +00:00
|
|
|
qDebug() << "UserID:" << userID;
|
|
|
|
qDebug() << "Token:" << token;
|
|
|
|
qDebug() << "Home:" << home;
|
|
|
|
qDebug() << "User:" << user;
|
|
|
|
qDebug() << "Pass:" << pass;
|
2018-02-27 11:07:50 +00:00
|
|
|
|
|
|
|
if(!userID.isEmpty() && !token.isEmpty()) {
|
2018-02-27 11:37:53 +00:00
|
|
|
qDebug() << "Using token.";
|
2018-02-27 11:07:50 +00:00
|
|
|
connection->connectWithToken(userID, token, "");
|
|
|
|
} else if(!user.isEmpty() && !pass.isEmpty()) {
|
2018-02-27 11:37:53 +00:00
|
|
|
qDebug() << "Using given credential.";
|
2018-02-27 11:07:50 +00:00
|
|
|
connection->connectToServer("@"+user+":"+home, pass, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::logout() {
|
|
|
|
userID = "";
|
|
|
|
token = "";
|
2018-02-27 11:37:53 +00:00
|
|
|
setIsLogin(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::connected() {
|
|
|
|
setUserID(connection->userId());
|
|
|
|
setToken(connection->accessToken());
|
|
|
|
setIsLogin(true);
|
2018-02-27 11:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::resync() {
|
|
|
|
connection->sync(30000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Controller::reconnect() {
|
|
|
|
Controller::connection->connectWithToken(userID, token, "");
|
2018-02-27 05:10:08 +00:00
|
|
|
}
|