diff --git a/qml/main.qml b/qml/main.qml index b654309..b9cf58e 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -254,6 +254,7 @@ ApplicationWindow { onAccepted: spectralController.createRoom(currentConnection, addRoomDialogNameTextField.text, addRoomDialogTopicTextField.text) } } + MenuItem { text: "Join Room" @@ -304,7 +305,7 @@ ApplicationWindow { placeholderText: "@bot:matrix.org" } - onAccepted: currentConnection.createDirectChat(directChatDialogTextField.text) + onAccepted: spectralController.createDirectChat(currentConnection, directChatDialogTextField.text) } } } diff --git a/src/controller.cpp b/src/controller.cpp index bc78649..dbb1934 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -8,6 +8,7 @@ #include "events/roommessageevent.h" #include "csapi/joining.h" +#include "csapi/logout.h" #include #include @@ -75,7 +76,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user, }); connect(m_connection, &Connection::loginError, [=](QString error, QByteArray detail) { - emit errorOccured("Login", error); + emit errorOccured("Login Failed", error); }); } } @@ -89,7 +90,15 @@ void Controller::logout(Connection* conn) { SettingsGroup("Accounts").remove(conn->userId()); QFile(accessTokenFileName(AccountSettings(conn->userId()))).remove(); - conn->logout(); + auto job = conn->callApi(); + connect(job, &LogoutJob::finished, conn, [=] { + conn->stopSync(); + emit conn->stateChanged(); + emit conn->loggedOut(); + }); + connect(job, &LogoutJob::failure, this, [=] { + emit errorOccured("Server-side Logout Failed", job->errorString()); + }); } void Controller::addConnection(Connection* c) { @@ -172,18 +181,26 @@ bool Controller::saveAccessToken(const AccountSettings& account, void Controller::joinRoom(Connection* c, const QString& alias) { JoinRoomJob* joinRoomJob = c->joinRoom(alias); - setBusy(true); - joinRoomJob->connect(joinRoomJob, &JoinRoomJob::finished, - [=] { setBusy(false); }); + joinRoomJob->connect(joinRoomJob, &JoinRoomJob::failure, [=] { + emit errorOccured("Join Room Failed", joinRoomJob->errorString()); + }); } void Controller::createRoom(Connection* c, const QString& name, const QString& topic) { CreateRoomJob* createRoomJob = c->createRoom(Connection::PublishRoom, "", name, topic, QStringList()); - setBusy(true); - createRoomJob->connect(createRoomJob, &CreateRoomJob::finished, - [=] { setBusy(false); }); + createRoomJob->connect(createRoomJob, &CreateRoomJob::failure, [=] { + emit errorOccured("Create Room Failed", createRoomJob->errorString()); + }); +} + +void Controller::createDirectChat(Connection* c, const QString& userID) { + CreateRoomJob* createRoomJob = c->createDirectChat(userID); + createRoomJob->connect(createRoomJob, &CreateRoomJob::failure, [=] { + emit errorOccured("Create Direct Chat Failed", + createRoomJob->errorString()); + }); } void Controller::copyToClipboard(const QString& text) { diff --git a/src/controller.h b/src/controller.h index e7df9ba..35d964f 100644 --- a/src/controller.h +++ b/src/controller.h @@ -15,8 +15,6 @@ using namespace QMatrixClient; class Controller : public QObject { Q_OBJECT - - Q_PROPERTY(bool busy READ busy WRITE setBusy NOTIFY busyChanged) Q_PROPERTY(int accountCount READ accountCount NOTIFY connectionAdded NOTIFY connectionDropped) @@ -34,14 +32,6 @@ class Controller : public QObject { void dropConnection(Connection* c); // All the Q_PROPERTYs. - bool busy() { return m_busy; } - void setBusy(bool value) { - if (value != m_busy) { - m_busy = value; - emit busyChanged(); - } - } - int accountCount() { return m_connections.count(); } Q_INVOKABLE QColor color(QString userId); @@ -53,8 +43,6 @@ class Controller : public QObject { QMenu* trayMenu = new QMenu(); QVector m_connections; - bool m_busy = false; - QByteArray loadAccessToken(const AccountSettings& account); bool saveAccessToken(const AccountSettings& account, const QByteArray& accessToken); @@ -77,6 +65,7 @@ class Controller : public QObject { void logout(Connection* conn); void joinRoom(Connection* c, const QString& alias); void createRoom(Connection* c, const QString& name, const QString& topic); + void createDirectChat(Connection* c, const QString& userID); void copyToClipboard(const QString& text); void playAudio(QUrl localFile); void showMessage(const QString& title, const QString& msg, const QIcon& icon); diff --git a/src/main.cpp b/src/main.cpp index 189e186..1081040 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,11 +32,6 @@ int main(int argc, char *argv[]) { app.setQuitOnLastWindowClosed(false); - qRegisterMetaType("SpectralRoom*"); - qRegisterMetaType("User*"); - qRegisterMetaType("MessageEventType"); - qRegisterMetaType("SpectralRoom"); - qmlRegisterType("Spectral", 0, 1, "ImageItem"); qmlRegisterType("Spectral", 0, 1, "Controller"); qmlRegisterType("Spectral", 0, 1, "AccountListModel"); @@ -48,6 +43,10 @@ int main(int argc, char *argv[]) { "RoomMessageEvent", "ENUM"); qmlRegisterUncreatableType("Spectral", 0, 1, "RoomType", "ENUM"); + qRegisterMetaType("User*"); + qRegisterMetaType("MessageEventType"); + qRegisterMetaType("SpectralRoom"); + QQmlApplicationEngine engine; engine.addImportPath("qrc:/imports");