Init RoomListModel and test sync.
This commit is contained in:
parent
535e4bb3a0
commit
a4b00f823e
10
main.cpp
10
main.cpp
|
@ -1,7 +1,9 @@
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
|
#include <QNetworkProxy>
|
||||||
|
|
||||||
#include "matrix/controller.h"
|
#include "matrix/controller.h"
|
||||||
|
#include "matrix/roomlistmodel.h"
|
||||||
using namespace QMatrixClient;
|
using namespace QMatrixClient;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
|
@ -12,7 +14,15 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
|
// Enable this if you need proxy.
|
||||||
|
// QNetworkProxy proxy;
|
||||||
|
// proxy.setType(QNetworkProxy::HttpProxy);
|
||||||
|
// proxy.setHostName("localhost");
|
||||||
|
// proxy.setPort(1082);
|
||||||
|
// QNetworkProxy::setApplicationProxy(proxy);
|
||||||
|
|
||||||
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
qmlRegisterType<Controller>("Matrique", 0, 1, "Controller");
|
||||||
|
qmlRegisterType<RoomListModel>("Matrique", 0, 1, "RoomListModel");
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
||||||
|
|
12
matrique.pro
12
matrique.pro
|
@ -15,7 +15,8 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
matrix/controller.cpp
|
matrix/controller.cpp \
|
||||||
|
matrix/roomlistmodel.cpp
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
res.qrc
|
res.qrc
|
||||||
|
@ -40,10 +41,11 @@ DISTFILES += \
|
||||||
ImageStatus.qml \
|
ImageStatus.qml \
|
||||||
ButtonDelegate.qml \
|
ButtonDelegate.qml \
|
||||||
SideNav.qml \
|
SideNav.qml \
|
||||||
ContactListForm.qml \
|
RoomListForm.qml \
|
||||||
ContactDetailForm.qml \
|
RoomDetailForm.qml \
|
||||||
Contact.qml \
|
Room.qml \
|
||||||
Setting.qml
|
Setting.qml
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
matrix/controller.h
|
matrix/controller.h \
|
||||||
|
matrix/roomlistmodel.h
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "libqmatrixclient/connection.h"
|
||||||
|
|
||||||
Controller::Controller(QObject *parent) : QObject(parent) {
|
Controller::Controller(QObject *parent) : QObject(parent) {
|
||||||
connect(connection, &Connection::connected, this, &Controller::connected);
|
connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected);
|
||||||
connect(connection, &Connection::resolveError, this, &Controller::reconnect);
|
connect(m_connection, &QMatrixClient::Connection::resolveError, this, &Controller::reconnect);
|
||||||
connect(connection, &Connection::syncError, this, &Controller::reconnect);
|
connect(m_connection, &QMatrixClient::Connection::syncError, this, &Controller::reconnect);
|
||||||
connect(connection, &Connection::syncDone, this, &Controller::resync);
|
connect(m_connection, &QMatrixClient::Connection::syncDone, this, &Controller::resync);
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::~Controller() {
|
Controller::~Controller() {
|
||||||
|
@ -24,10 +24,10 @@ void Controller::login(QString home, QString user, QString pass) {
|
||||||
|
|
||||||
if(!userID.isEmpty() && !token.isEmpty()) {
|
if(!userID.isEmpty() && !token.isEmpty()) {
|
||||||
qDebug() << "Using token.";
|
qDebug() << "Using token.";
|
||||||
connection->connectWithToken(userID, token, "");
|
m_connection->connectWithToken(userID, token, "");
|
||||||
} else if(!user.isEmpty() && !pass.isEmpty()) {
|
} else if(!user.isEmpty() && !pass.isEmpty()) {
|
||||||
qDebug() << "Using given credential.";
|
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() {
|
void Controller::connected() {
|
||||||
setUserID(connection->userId());
|
setUserID(m_connection->userId());
|
||||||
setToken(connection->accessToken());
|
setToken(m_connection->accessToken());
|
||||||
|
roomListModel->init(m_connection);
|
||||||
|
resync();
|
||||||
setIsLogin(true);
|
setIsLogin(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::resync() {
|
void Controller::resync() {
|
||||||
connection->sync(30000);
|
m_connection->sync(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::reconnect() {
|
void Controller::reconnect() {
|
||||||
Controller::connection->connectWithToken(userID, token, "");
|
m_connection->connectWithToken(userID, token, "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,17 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "libqmatrixclient/connection.h"
|
#include "libqmatrixclient/connection.h"
|
||||||
|
#include "roomlistmodel.h"
|
||||||
|
|
||||||
using namespace QMatrixClient;
|
namespace QMatrixClient {
|
||||||
|
class Connection;
|
||||||
|
}
|
||||||
|
|
||||||
class Controller : public QObject
|
class Controller : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(RoomListModel *roomListModel READ getRoomListModel NOTIFY roomListModelChanged)
|
||||||
Q_PROPERTY(bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged)
|
Q_PROPERTY(bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged)
|
||||||
Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged)
|
Q_PROPERTY(QString userID READ getUserID WRITE setUserID NOTIFY userIDChanged)
|
||||||
Q_PROPERTY(QByteArray token READ getToken WRITE setToken NOTIFY tokenChanged)
|
Q_PROPERTY(QByteArray token READ getToken WRITE setToken NOTIFY tokenChanged)
|
||||||
|
@ -25,6 +29,9 @@ public:
|
||||||
// All the non-Q_INVOKABLE functions.
|
// All the non-Q_INVOKABLE functions.
|
||||||
|
|
||||||
// All the Q_PROPERTYs.
|
// All the Q_PROPERTYs.
|
||||||
|
RoomListModel *roomListModel = new RoomListModel(this);
|
||||||
|
RoomListModel* getRoomListModel() { return roomListModel; }
|
||||||
|
|
||||||
bool isLogin = false;
|
bool isLogin = false;
|
||||||
bool getIsLogin() { return isLogin; }
|
bool getIsLogin() { return isLogin; }
|
||||||
void setIsLogin(bool n) {
|
void setIsLogin(bool n) {
|
||||||
|
@ -53,12 +60,14 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMatrixClient::Connection *connection = new QMatrixClient::Connection();
|
QMatrixClient::Connection *m_connection = new QMatrixClient::Connection();
|
||||||
|
|
||||||
void connected();
|
void connected();
|
||||||
void resync();
|
void resync();
|
||||||
void reconnect();
|
void reconnect();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void roomListModelChanged();
|
||||||
void isLoginChanged();
|
void isLoginChanged();
|
||||||
void userIDChanged();
|
void userIDChanged();
|
||||||
void tokenChanged();
|
void tokenChanged();
|
||||||
|
|
|
@ -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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
10
qml/Home.qml
10
qml/Home.qml
|
@ -3,15 +3,15 @@ import QtQuick.Controls 2.3
|
||||||
import "qrc:/qml/form"
|
import "qrc:/qml/form"
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
ContactListForm {
|
RoomListForm {
|
||||||
id: contactListForm
|
id: roomListForm
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: 320
|
width: 320
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatForm {
|
RoomForm {
|
||||||
id: chatForm
|
id: roomForm
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: contactListForm.width
|
anchors.leftMargin: roomListForm.width
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ import QtQuick.Controls 2.3
|
||||||
import "qrc:/qml/form"
|
import "qrc:/qml/form"
|
||||||
|
|
||||||
Page {
|
Page {
|
||||||
ContactListForm {
|
property var roomListModel
|
||||||
|
|
||||||
|
RoomListForm {
|
||||||
id: contactListForm
|
id: contactListForm
|
||||||
height: parent.height
|
height: parent.height
|
||||||
width: 320
|
width: 320
|
|
@ -130,8 +130,8 @@ ApplicationWindow {
|
||||||
controller: controller
|
controller: controller
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact {
|
Room {
|
||||||
|
roomListModel: controller.roomListModel
|
||||||
}
|
}
|
||||||
|
|
||||||
Setting {
|
Setting {
|
||||||
|
|
6
res.qrc
6
res.qrc
|
@ -4,7 +4,6 @@
|
||||||
<file>asset/img/avatar.png</file>
|
<file>asset/img/avatar.png</file>
|
||||||
<file>asset/img/background.jpg</file>
|
<file>asset/img/background.jpg</file>
|
||||||
<file>asset/font/material.ttf</file>
|
<file>asset/font/material.ttf</file>
|
||||||
<file>qml/Contact.qml</file>
|
|
||||||
<file>qml/Home.qml</file>
|
<file>qml/Home.qml</file>
|
||||||
<file>qml/Login.qml</file>
|
<file>qml/Login.qml</file>
|
||||||
<file>qml/main.qml</file>
|
<file>qml/main.qml</file>
|
||||||
|
@ -12,8 +11,9 @@
|
||||||
<file>qml/component/ButtonDelegate.qml</file>
|
<file>qml/component/ButtonDelegate.qml</file>
|
||||||
<file>qml/component/ImageStatus.qml</file>
|
<file>qml/component/ImageStatus.qml</file>
|
||||||
<file>qml/component/SideNav.qml</file>
|
<file>qml/component/SideNav.qml</file>
|
||||||
<file>qml/form/ChatForm.qml</file>
|
|
||||||
<file>qml/form/ContactDetailForm.qml</file>
|
<file>qml/form/ContactDetailForm.qml</file>
|
||||||
<file>qml/form/ContactListForm.qml</file>
|
<file>qml/form/RoomForm.qml</file>
|
||||||
|
<file>qml/form/RoomListForm.qml</file>
|
||||||
|
<file>qml/Room.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in New Issue