Init RoomListModel and test sync.
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
#include "libqmatrixclient/connection.h"
|
||||
|
||||
Controller::Controller(QObject *parent) : QObject(parent) {
|
||||
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);
|
||||
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected);
|
||||
connect(m_connection, &QMatrixClient::Connection::resolveError, this, &Controller::reconnect);
|
||||
connect(m_connection, &QMatrixClient::Connection::syncError, this, &Controller::reconnect);
|
||||
connect(m_connection, &QMatrixClient::Connection::syncDone, this, &Controller::resync);
|
||||
}
|
||||
|
||||
Controller::~Controller() {
|
||||
@@ -24,10 +24,10 @@ void Controller::login(QString home, QString user, QString pass) {
|
||||
|
||||
if(!userID.isEmpty() && !token.isEmpty()) {
|
||||
qDebug() << "Using token.";
|
||||
connection->connectWithToken(userID, token, "");
|
||||
m_connection->connectWithToken(userID, token, "");
|
||||
} else if(!user.isEmpty() && !pass.isEmpty()) {
|
||||
qDebug() << "Using given credential.";
|
||||
connection->connectToServer("@"+user+":"+home, pass, "");
|
||||
m_connection->connectToServer("@"+user+":"+home, pass, "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,17 @@ void Controller::logout() {
|
||||
}
|
||||
|
||||
void Controller::connected() {
|
||||
setUserID(connection->userId());
|
||||
setToken(connection->accessToken());
|
||||
setUserID(m_connection->userId());
|
||||
setToken(m_connection->accessToken());
|
||||
roomListModel->init(m_connection);
|
||||
resync();
|
||||
setIsLogin(true);
|
||||
}
|
||||
|
||||
void Controller::resync() {
|
||||
connection->sync(30000);
|
||||
m_connection->sync(30000);
|
||||
}
|
||||
|
||||
void Controller::reconnect() {
|
||||
Controller::connection->connectWithToken(userID, token, "");
|
||||
m_connection->connectWithToken(userID, token, "");
|
||||
}
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "libqmatrixclient/connection.h"
|
||||
#include "roomlistmodel.h"
|
||||
|
||||
using namespace QMatrixClient;
|
||||
namespace QMatrixClient {
|
||||
class Connection;
|
||||
}
|
||||
|
||||
class Controller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(RoomListModel *roomListModel READ getRoomListModel NOTIFY roomListModelChanged)
|
||||
Q_PROPERTY(bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged)
|
||||
Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged)
|
||||
Q_PROPERTY(QByteArray token READ getToken WRITE setToken NOTIFY tokenChanged)
|
||||
@@ -25,6 +29,9 @@ public:
|
||||
// All the non-Q_INVOKABLE functions.
|
||||
|
||||
// All the Q_PROPERTYs.
|
||||
RoomListModel *roomListModel = new RoomListModel(this);
|
||||
RoomListModel* getRoomListModel() { return roomListModel; }
|
||||
|
||||
bool isLogin = false;
|
||||
bool getIsLogin() { return isLogin; }
|
||||
void setIsLogin(bool n) {
|
||||
@@ -53,12 +60,14 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QMatrixClient::Connection *connection = new QMatrixClient::Connection();
|
||||
QMatrixClient::Connection *m_connection = new QMatrixClient::Connection();
|
||||
|
||||
void connected();
|
||||
void resync();
|
||||
void reconnect();
|
||||
|
||||
signals:
|
||||
void roomListModelChanged();
|
||||
void isLoginChanged();
|
||||
void userIDChanged();
|
||||
void tokenChanged();
|
||||
|
||||
44
matrix/roomlistmodel.cpp
Normal file
44
matrix/roomlistmodel.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "roomlistmodel.h"
|
||||
|
||||
#include "controller.h"
|
||||
|
||||
RoomListModel::RoomListModel(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RoomListModel::init(QMatrixClient::Connection *conn) {
|
||||
qDebug() << "Registering connection.";
|
||||
m_connection = conn;
|
||||
connect(m_connection, &QMatrixClient::Connection::newRoom, this, &RoomListModel::addRoom);
|
||||
for(QMatrixClient::Room* room: m_connection->roomMap().values()) {
|
||||
connect(room, &QMatrixClient::Room::namesChanged, this, &RoomListModel::namesChanged);
|
||||
m_rooms.append(room);
|
||||
}
|
||||
}
|
||||
|
||||
RoomListModel::~RoomListModel() {
|
||||
|
||||
}
|
||||
|
||||
QMatrixClient::Room* RoomListModel::roomAt(int row)
|
||||
{
|
||||
return m_rooms.at(row);
|
||||
}
|
||||
|
||||
void RoomListModel::addRoom(QMatrixClient::Room* room)
|
||||
{
|
||||
qDebug() << "Adding room.";
|
||||
connect(room, &QMatrixClient::Room::namesChanged, this, &RoomListModel::namesChanged );
|
||||
m_rooms.append(room);
|
||||
}
|
||||
|
||||
void RoomListModel::namesChanged(QMatrixClient::Room* room)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RoomListModel::unreadMessagesChanged(QMatrixClient::Room* room)
|
||||
{
|
||||
|
||||
}
|
||||
39
matrix/roomlistmodel.h
Normal file
39
matrix/roomlistmodel.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef ROOMLISTMODEL_H
|
||||
#define ROOMLISTMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "libqmatrixclient/connection.h"
|
||||
#include "libqmatrixclient/room.h"
|
||||
|
||||
namespace QMatrixClient {
|
||||
class Connection;
|
||||
class Room;
|
||||
}
|
||||
|
||||
class RoomListModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RoomListModel(QObject *parent = nullptr);
|
||||
~RoomListModel();
|
||||
|
||||
void init(QMatrixClient::Connection*);
|
||||
|
||||
Q_INVOKABLE QMatrixClient::Room* roomAt(int row);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
void namesChanged(QMatrixClient::Room* room);
|
||||
void unreadMessagesChanged(QMatrixClient::Room* room);
|
||||
void addRoom(QMatrixClient::Room* room);
|
||||
|
||||
private:
|
||||
QMatrixClient::Connection *m_connection;
|
||||
QList<QMatrixClient::Room*> m_rooms;
|
||||
};
|
||||
|
||||
#endif // ROOMLISTMODEL_H
|
||||
Reference in New Issue
Block a user