diff --git a/qml/Setting.qml b/qml/Setting.qml
index a71a3a254..4eaa742e8 100644
--- a/qml/Setting.qml
+++ b/qml/Setting.qml
@@ -16,7 +16,7 @@ Page {
parent: null
}
- SettingAppearancePage {
+ SettingAppearanceForm {
id: appearanceForm
parent: null
}
diff --git a/qml/component/ImageBubble.qml b/qml/component/ImageBubble.qml
index 53ed97080..3e480d2de 100644
--- a/qml/component/ImageBubble.qml
+++ b/qml/component/ImageBubble.qml
@@ -21,8 +21,7 @@ AvatarContainer {
Image {
id: messageImage
z: -4
- sourceSize.width: width
- sourceSize.height: height
+ sourceSize.width: 128
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
MouseArea {
diff --git a/qml/component/ImageStatus.qml b/qml/component/ImageStatus.qml
index 41d4bc785..e5ce44cd0 100644
--- a/qml/component/ImageStatus.qml
+++ b/qml/component/ImageStatus.qml
@@ -32,7 +32,6 @@ Item {
layer.enabled: true
fillMode: Image.PreserveAspectCrop
sourceSize.width: item.width
- sourceSize.height: item.width
layer.effect: OpacityMask {
maskSource: Item {
@@ -74,8 +73,8 @@ Item {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
- for (var i = 0; i < 3; i++) {
- var value = (hash >> (i * 8)) & 0xFF;
+ for (var j = 0; j < 3; j++) {
+ var value = (hash >> (j * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
diff --git a/qml/component/MessageBubble.qml b/qml/component/MessageBubble.qml
index 7ff9764f4..70bfe91fa 100644
--- a/qml/component/MessageBubble.qml
+++ b/qml/component/MessageBubble.qml
@@ -42,7 +42,7 @@ AvatarContainer {
id: timeText
visible: Math.abs(time - aboveTime) > 600000 || index == 0
Layout.alignment: Qt.AlignRight
- text: Qt.formatDateTime(time, "d MMM hh:mm")
+ text: Qt.formatTime(time, "hh:mm")
color: isNotice || sentByMe ? "grey" : "white"
font.pointSize: 8
diff --git a/qml/component/MessageDelegate.qml b/qml/component/MessageDelegate.qml
index fa851a727..5b58f8a76 100644
--- a/qml/component/MessageDelegate.qml
+++ b/qml/component/MessageDelegate.qml
@@ -5,36 +5,24 @@ import QtQuick.Controls.Material 2.2
Item {
id: messageDelegate
- readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool darkTheme: Material.theme == Material.Dark
readonly property color background: darkTheme ? "#242424" : "lightgrey"
+ readonly property bool sentByMe: author === currentRoom.localUser
+ readonly property bool isState: eventType === "state" || eventType === "emote"
+ readonly property bool isMessage: eventType === "message" || eventType === "notice"
+ readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image"
+
z: -5
width: delegateLoader.width
height: delegateLoader.height
- anchors.right: !(eventType === "state" || eventType === "emote") && sentByMe ? parent.right : undefined
- anchors.horizontalCenter: (eventType === "state" || eventType === "emote") ? parent.horizontalCenter : undefined
+ anchors.right: !isState && sentByMe ? parent.right : undefined
+ anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined
Loader {
id: delegateLoader
- source: {
- switch (eventType) {
- case "notice":
- case "message":
- return "MessageBubble.qml"
- case "image":
- return "ImageBubble.qml"
- case "emote":
- case "state":
- return "StateBubble.qml"
- case "video":
- case "audio":
- case "file":
- return "FileBubble.qml"
- }
- return ""
- }
+ source: isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : ""
}
}
diff --git a/qml/form/RoomListForm.qml b/qml/form/RoomListForm.qml
index 8fef36b8d..6150801a6 100644
--- a/qml/form/RoomListForm.qml
+++ b/qml/form/RoomListForm.qml
@@ -219,7 +219,7 @@ Item {
}
MenuItem {
text: "Leave Room"
- onTriggered: listModel.connection.forgetRoom(roomListMenu.room.id)
+ onTriggered: matriqueController.forgetRoom(roomListMenu.room.id)
}
}
}
diff --git a/qml/form/SettingAppearancePage.qml b/qml/form/SettingAppearanceForm.qml
similarity index 100%
rename from qml/form/SettingAppearancePage.qml
rename to qml/form/SettingAppearanceForm.qml
diff --git a/qml/main.qml b/qml/main.qml
index 6da07d669..9ad888b24 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -17,7 +17,7 @@ ApplicationWindow {
visible: true
width: 960
height: 640
- minimumWidth: 640
+ minimumWidth: 800
minimumHeight: 480
title: qsTr("Matrique")
@@ -166,6 +166,94 @@ ApplicationWindow {
Layout.fillHeight: true
}
+ SideNavButton {
+ contentItem: MaterialIcon { icon: "\ue145"; color: "white" }
+ onClicked: addRoomMenu.popup()
+
+ Menu {
+ id: addRoomMenu
+ MenuItem {
+ text:"New Room"
+ onTriggered: addRoomDialog.open()
+
+ Dialog {
+ id: addRoomDialog
+ parent: ApplicationWindow.overlay
+
+ x: (window.width - width) / 2
+ y: (window.height - height) / 2
+ width: 360
+
+ title: "New Room"
+ modal: true
+ standardButtons: Dialog.Ok | Dialog.Cancel
+
+ contentItem: Column {
+ TextField {
+ id: addRoomDialogNameTextField
+ width: parent.width
+
+ placeholderText: "Name"
+ }
+ TextField {
+ id: addRoomDialogTopicTextField
+ width: parent.width
+ placeholderText: "Topic"
+ }
+ }
+
+ onAccepted: matriqueController.createRoom(addRoomDialogNameTextField.text, addRoomDialogTopicTextField.text)
+ }
+ }
+ MenuItem {
+ text: "Join Room"
+ onTriggered: joinRoomDialog.open()
+
+ Dialog {
+ id: joinRoomDialog
+ parent: ApplicationWindow.overlay
+
+ x: (window.width - width) / 2
+ y: (window.height - height) / 2
+ width: 360
+
+ title: "Input Room Alias or ID"
+ modal: true
+ standardButtons: Dialog.Ok | Dialog.Cancel
+
+ contentItem: TextField {
+ id: joinRoomDialogTextField
+ }
+
+ onAccepted: matriqueController.joinRoom(joinRoomDialogTextField.text)
+ }
+ }
+ MenuItem {
+ text: "Direct Chat"
+ onTriggered: directChatDialog.open()
+
+ Dialog {
+ id: directChatDialog
+ parent: ApplicationWindow.overlay
+
+ x: (window.width - width) / 2
+ y: (window.height - height) / 2
+ width: 360
+
+ title: "Input User ID"
+ modal: true
+ standardButtons: Dialog.Ok | Dialog.Cancel
+
+ contentItem: TextField {
+ id: directChatDialogTextField
+ }
+
+ onAccepted: matriqueController.createDirectChat(directChatDialogTextField.text)
+ }
+ }
+ }
+ }
+
SideNavButton {
contentItem: MaterialIcon { icon: "\ue8b8"; color: "white" }
page: settingPage
@@ -173,9 +261,7 @@ ApplicationWindow {
SideNavButton {
contentItem: MaterialIcon { icon: "\ue879"; color: "white" }
- onClicked: {
- Qt.quit();
- }
+ onClicked: Qt.quit()
}
}
}
diff --git a/res.qrc b/res.qrc
index 42cf6668f..e040dd73d 100644
--- a/res.qrc
+++ b/res.qrc
@@ -28,6 +28,6 @@
qml/form/SettingForm.qml
qml/Setting.qml
qml/form/SettingAccountForm.qml
- qml/form/SettingAppearancePage.qml
+ qml/form/SettingAppearanceForm.qml
diff --git a/src/controller.cpp b/src/controller.cpp
index 7262d72cc..2c6e4e777 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -4,26 +4,25 @@
#include "events/eventcontent.h"
#include "events/roommessageevent.h"
+#include "csapi/create_room.h"
+#include "csapi/joining.h"
+#include "csapi/leaving.h"
+
#include
#include
#include
Controller::Controller(QObject* parent) : QObject(parent) {
- connect(m_connection, &Connection::connected, this,
- &Controller::connected);
+ connect(m_connection, &Connection::connected, this, &Controller::connected);
connect(m_connection, &Connection::resolveError, this,
&Controller::reconnect);
- connect(m_connection, &Connection::syncError, this,
- &Controller::reconnect);
- connect(m_connection, &Connection::syncDone, this,
- &Controller::resync);
+ connect(m_connection, &Connection::syncError, this, &Controller::reconnect);
+ connect(m_connection, &Connection::syncDone, this, &Controller::resync);
connect(m_connection, &Connection::connected, this,
&Controller::connectionChanged);
- connect(m_connection, &Connection::connected,
- [=] { setBusy(true); });
- connect(m_connection, &Connection::syncDone,
- [=] { setBusy(false); });
+ connect(m_connection, &Connection::connected, [=] { setBusy(true); });
+ connect(m_connection, &Connection::syncDone, [=] { setBusy(false); });
}
Controller::~Controller() {
@@ -52,6 +51,7 @@ void Controller::loginWithCredentials(QString serverAddr, QString user,
}
void Controller::logout() {
+ m_connection->logout();
setUserID("");
setToken("");
setIsLogin(false);
@@ -66,10 +66,7 @@ void Controller::connected() {
setIsLogin(true);
}
-void Controller::resync() {
- m_connection->sync(30000);
- m_connection->saveState();
-}
+void Controller::resync() { m_connection->sync(30000); }
void Controller::reconnect() {
qDebug() << "Connection lost. Reconnecting...";
@@ -97,3 +94,29 @@ QString Controller::getMIME(const QUrl& fileUrl) const {
delete db;
return mime;
}
+
+void Controller::forgetRoom(const QString& roomID) {
+ ForgetRoomJob* forgetRoomJob = m_connection->forgetRoom(roomID);
+ setBusy(true);
+ forgetRoomJob->connect(forgetRoomJob, &ForgetRoomJob::finished,
+ [=] { setBusy(false); });
+}
+
+void Controller::joinRoom(const QString& alias) {
+ JoinRoomJob* joinRoomJob = m_connection->joinRoom(alias);
+ setBusy(true);
+ joinRoomJob->connect(joinRoomJob, &JoinRoomJob::finished,
+ [=] { setBusy(false); });
+}
+
+void Controller::createRoom(const QString& name, const QString& topic) {
+ CreateRoomJob* createRoomJob = m_connection->createRoom(
+ Connection::PublishRoom, "", name, topic, QStringList());
+ setBusy(true);
+ createRoomJob->connect(createRoomJob, &CreateRoomJob::finished,
+ [=] { setBusy(false); });
+}
+
+void Controller::createDirectChat(const QString& userID) {
+ m_connection->requestDirectChat(userID);
+}
diff --git a/src/controller.h b/src/controller.h
index ff2e61f01..563c0104c 100644
--- a/src/controller.h
+++ b/src/controller.h
@@ -95,9 +95,12 @@ class Controller : public QObject {
void errorOccured();
public slots:
- void postFile(Room* room, const QUrl& localFile,
- const QUrl& mxcUrl);
+ void postFile(Room* room, const QUrl& localFile, const QUrl& mxcUrl);
QString getMIME(const QUrl& fileUrl) const;
+ void forgetRoom(const QString& roomID);
+ void joinRoom(const QString& alias);
+ void createRoom(const QString& name, const QString& topic);
+ void createDirectChat(const QString& userID);
};
#endif // CONTROLLER_H
diff --git a/src/main.cpp b/src/main.cpp
index 851ddbbf7..a3caedfa7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -9,6 +9,7 @@
#include "room.h"
#include "roomlistmodel.h"
+#include "csapi/joining.h"
#include "csapi/leaving.h"
using namespace QMatrixClient;
@@ -28,8 +29,6 @@ int main(int argc, char *argv[]) {
// QNetworkProxy::setApplicationProxy(proxy);
qRegisterMetaType("Room*");
- qRegisterMetaType("LeaveRoomJob*");
- qRegisterMetaType("ForgetRoomJob*");
qRegisterMetaType("User*");