From 4ef063ea820010fe65ed4bf779f825a4e688c819 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Sun, 15 Jul 2018 16:02:26 +0800 Subject: [PATCH] Testing upload file && minor UI tweaks. --- qml/Login.qml | 7 ++++++- qml/form/RoomForm.qml | 8 ++++++-- qml/form/RoomListForm.qml | 11 +---------- src/controller.cpp | 14 +++++++++----- src/controller.h | 6 ++---- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/qml/Login.qml b/qml/Login.qml index c5c2bfd..65de289 100644 --- a/qml/Login.qml +++ b/qml/Login.qml @@ -137,7 +137,12 @@ Page { text: "LOGIN" highlighted: true - onClicked: controller.loginWithCredentials(serverField.text, usernameField.text, passwordField.text) + onClicked: { + matriqueController.isLoginChanged.connect( function() { + if (matriqueController.isLogin) stackView.replace(roomPage) + }) + controller.loginWithCredentials(serverField.text, usernameField.text, passwordField.text) + } } } } diff --git a/qml/form/RoomForm.qml b/qml/form/RoomForm.qml index 6bb8065..5d7f301 100644 --- a/qml/form/RoomForm.qml +++ b/qml/form/RoomForm.qml @@ -148,9 +148,13 @@ Item { id: fileDialog title: "Please choose a file" folder: shortcuts.home + selectMultiple: false onAccepted: { - console.log("You chose: " + fileDialog.fileUrls) - currentRoom.uploadFile(fileDialog.fileUrls) + console.log("You chose: " + fileDialog.fileUrl) + currentRoom.uploadFile(fileDialog.fileUrl, fileDialog.fileUrl) + currentRoom.fileTransferCompleted.connect(function(id, localFile, mxcUrl) { + console.log("File transferred: " + id + ":" + mxcUrl) + }) } } } diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml index 3c79913..88ec700 100644 --- a/qml/form/RoomListForm.qml +++ b/qml/form/RoomListForm.qml @@ -146,7 +146,6 @@ Item { source: avatar ? "image://mxc/" + avatar : "" displayText: name - opaqueBackground: true } ColumnLayout { @@ -160,15 +159,7 @@ Item { Layout.fillWidth: true Layout.fillHeight: true - text: { - if (name) { - return name; - } - if (alias) { - return alias; - } - return id - } + text: name ? name : alias ? alias : id font.pointSize: 16 elide: Text.ElideRight wrapMode: Text.NoWrap diff --git a/src/controller.cpp b/src/controller.cpp index 6d02ae7..abb57db 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1,8 +1,10 @@ #include "controller.h" #include "connection.h" +#include "events/eventcontent.h" +#include "events/roommessageevent.h" -Controller::Controller(QObject *parent) : QObject(parent) { +Controller::Controller(QObject* parent) : QObject(parent) { connect(m_connection, &QMatrixClient::Connection::connected, this, &Controller::connected); connect(m_connection, &QMatrixClient::Connection::resolveError, this, @@ -56,10 +58,6 @@ void Controller::logout() { setIsLogin(false); } -void Controller::uploadFile(QString filename) { - m_connection->uploadFile(filename); -} - void Controller::connected() { qDebug() << "Logged in."; setHomeserver(m_connection->homeserver().toString()); @@ -80,3 +78,9 @@ void Controller::reconnect() { qDebug() << "Connection lost. Reconnecting..."; m_connection->connectWithToken(userID, token, ""); } + +void Controller::postFile(QMatrixClient::Room* room, + const QUrl& localFilename) { +// auto job = m_connection->uploadFile(localFilename.toLocalFile()); +// room->fileTransferInfo(localFilename.fileName()) +} diff --git a/src/controller.h b/src/controller.h index 896a346..fb44720 100644 --- a/src/controller.h +++ b/src/controller.h @@ -13,8 +13,7 @@ class Connection; class Controller : public QObject { Q_OBJECT - Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection NOTIFY - connectionChanged) + Q_PROPERTY(QMatrixClient::Connection* connection READ getConnection CONSTANT) Q_PROPERTY( bool isLogin READ getIsLogin WRITE setIsLogin NOTIFY isLoginChanged) Q_PROPERTY(QString homeserver READ getHomeserver WRITE setHomeserver NOTIFY @@ -32,8 +31,6 @@ class Controller : public QObject { Q_INVOKABLE void loginWithCredentials(QString, QString, QString); Q_INVOKABLE void logout(); - Q_INVOKABLE void uploadFile(QString); - // All the non-Q_INVOKABLE functions. // All the Q_PROPERTYs. @@ -100,6 +97,7 @@ class Controller : public QObject { void errorOccured(); public slots: + void postFile(QMatrixClient::Room* room, const QUrl& localFilename); }; #endif // CONTROLLER_H