Spectral/qml/main.qml

218 lines
5.0 KiB
QML
Raw Normal View History

2018-12-07 01:18:42 +00:00
import QtQuick 2.12
import QtQuick.Controls 2.4
2018-07-12 01:44:41 +00:00
import QtQuick.Layouts 1.3
2018-12-07 01:18:42 +00:00
import QtQuick.Controls.Material 2.4
import Qt.labs.settings 1.0
import Qt.labs.platform 1.0 as Platform
2018-10-01 08:07:48 +00:00
import Spectral.Panel 2.0
2018-10-01 08:07:48 +00:00
import Spectral.Component 2.0
import Spectral.Page 2.0
import Spectral.Effect 2.0
2018-10-01 08:07:48 +00:00
import Spectral 0.1
2018-10-01 08:07:48 +00:00
import Spectral.Setting 0.1
2018-02-23 14:39:14 +00:00
ApplicationWindow {
2018-12-16 02:47:58 +00:00
Material.theme: MPalette.theme
Material.background: MPalette.background
2018-11-16 12:30:42 +00:00
2018-02-23 14:39:14 +00:00
width: 960
height: 640
2018-09-15 11:07:38 +00:00
minimumWidth: 720
minimumHeight: 360
2018-09-04 13:13:14 +00:00
id: window
visible: true
title: qsTr("Spectral")
2018-12-16 02:47:58 +00:00
background: Rectangle {
color: MSettings.darkTheme ? "#303030" : "#FFFFFF"
}
Platform.SystemTrayIcon {
visible: MSettings.showTray
iconSource: "qrc:/assets/img/icon.png"
menu: Platform.Menu {
Platform.MenuItem {
text: qsTr("Hide Window")
onTriggered: hideWindow()
}
Platform.MenuItem {
text: qsTr("Quit")
onTriggered: Qt.quit()
}
}
onActivated: showWindow()
}
2018-02-27 11:07:50 +00:00
Controller {
id: spectralController
2018-08-19 06:51:09 +00:00
quitOnLastWindowClosed: !MSettings.showTray
2018-10-19 14:02:12 +00:00
onNotificationClicked: {
2018-11-17 13:12:56 +00:00
roomListForm.enteredRoom = spectralController.connection.room(roomId)
roomForm.goToEvent(eventId)
2018-10-19 14:02:12 +00:00
showWindow()
}
2018-09-20 00:23:42 +00:00
onErrorOccured: {
roomListForm.errorControl.error = error
roomListForm.errorControl.detail = detail
roomListForm.errorControl.visible = true
2018-09-20 00:23:42 +00:00
}
onSyncDone: roomListForm.errorControl.visible = false
2018-02-26 12:41:20 +00:00
}
2018-02-23 14:39:14 +00:00
2018-11-22 12:35:49 +00:00
Shortcut {
sequence: StandardKey.Quit
onActivated: Qt.quit()
}
Dialog {
property bool busy: false
width: 360
height: 300
x: (window.width - width) / 2
y: (window.height - height) / 2
id: loginDialog
parent: ApplicationWindow.overlay
title: "Login"
contentItem: ColumnLayout {
AutoTextField {
Layout.fillWidth: true
id: serverField
placeholderText: "Server Address"
text: "https://matrix.org"
}
AutoTextField {
Layout.fillWidth: true
id: usernameField
placeholderText: "Username"
}
AutoTextField {
Layout.fillWidth: true
id: passwordField
placeholderText: "Password"
echoMode: TextInput.Password
}
}
footer: DialogButtonBox {
Button {
text: "OK"
flat: true
enabled: !loginDialog.busy
onClicked: loginDialog.doLogin()
}
Button {
text: "Cancel"
flat: true
enabled: !loginDialog.busy
onClicked: loginDialog.close()
}
ToolTip {
id: loginButtonTooltip
2018-11-18 12:08:01 +00:00
}
}
2018-11-17 13:12:56 +00:00
onVisibleChanged: {
if (visible) spectralController.onErrorOccured.connect(showError)
else spectralController.onErrorOccured.disconnect(showError)
}
function showError(error, detail) {
loginDialog.busy = false
loginButtonTooltip.text = error + ": " + detail
loginButtonTooltip.open()
}
function doLogin() {
if (!(serverField.text.startsWith("http") && serverField.text.includes("://"))) {
loginButtonTooltip.text = "Server address should start with http(s)://"
loginButtonTooltip.open()
return
}
loginDialog.busy = true
spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text)
spectralController.connectionAdded.connect(function(conn) {
busy = false
loginDialog.close()
})
}
}
SplitView {
anchors.fill: parent
2018-09-22 14:28:47 +00:00
RoomListPanel {
width: window.width * 0.35
Layout.minimumWidth: 180
2018-09-22 14:28:47 +00:00
id: roomListForm
2018-09-22 14:28:47 +00:00
clip: true
2018-09-22 14:28:47 +00:00
controller: spectralController
2018-02-23 14:39:14 +00:00
onLeaveRoom: roomForm.saveReadMarker(room)
}
2018-02-23 14:39:14 +00:00
RoomPanel {
Layout.fillWidth: true
Layout.minimumWidth: 480
id: roomForm
2018-09-04 13:13:14 +00:00
clip: true
2018-09-04 13:13:14 +00:00
currentRoom: roomListForm.enteredRoom
2018-02-23 14:39:14 +00:00
}
}
Binding {
target: imageProvider
property: "connection"
value: spectralController.connection
2018-02-23 14:39:14 +00:00
}
2018-09-13 00:22:41 +00:00
function showWindow() {
window.show()
window.raise()
window.requestActivate()
}
function hideWindow() {
window.hide()
}
Component.onCompleted: {
spectralController.initiated.connect(function() {
if (spectralController.accountCount == 0) loginDialog.open()
})
}
2018-02-23 14:39:14 +00:00
}