nheko/resources/qml/Root.qml

504 lines
10 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./delegates"
import "./device-verification"
import "./dialogs"
import "./emoji"
2022-01-09 06:56:02 +01:00
import "./pages"
import "./voip"
2022-01-30 19:14:33 +01:00
import "./ui"
import Qt.labs.platform 1.1 as Platform
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.3
import QtQuick.Window 2.15
import im.nheko 1.0
import im.nheko.EmojiModel 1.0
2022-01-12 19:09:46 +01:00
Pane {
id: timelineRoot
palette: Nheko.colors
2022-01-12 19:09:46 +01:00
background: null
padding: 0
FontMetrics {
id: fontMetrics
}
RoomDirectoryModel {
id: publicRooms
}
//Timer {
// onTriggered: gc()
// interval: 1000
// running: true
// repeat: true
//}
EmojiPicker {
id: emojiPopup
colors: palette
model: TimelineManager.completerFor("allemoji", "")
}
Component {
id: userProfileComponent
UserProfile {
}
}
2022-07-08 17:28:28 +02:00
function showAliasEditor(settings) {
var dialog = aliasEditor.createObject(timelineRoot, {
"roomSettings": settings
});
dialog.show();
destroyOnClose(dialog);
}
Component {
id: aliasEditor
AliasEditor {
2022-05-27 16:31:54 +02:00
}
2022-07-08 17:28:28 +02:00
}
function showPLEditor(settings) {
var dialog = plEditor.createObject(timelineRoot, {
"roomSettings": settings
});
dialog.show();
destroyOnClose(dialog);
}
2022-05-27 16:31:54 +02:00
Component {
id: plEditor
PowerLevelEditor {
}
}
Component {
id: roomSettingsComponent
RoomSettings {
}
}
2021-07-17 22:16:18 +02:00
Component {
id: roomMembersComponent
RoomMembers {
}
2021-07-19 20:31:08 +02:00
2021-07-17 22:16:18 +02:00
}
Component {
id: mobileCallInviteDialog
CallInvite {
}
}
Component {
id: quickSwitcherComponent
QuickSwitcher {
}
}
2021-07-17 22:16:18 +02:00
Component {
id: deviceVerificationDialog
DeviceVerification {
}
}
2021-07-19 20:31:08 +02:00
2021-07-17 22:16:18 +02:00
Component {
id: inviteDialog
InviteDialog {
}
2021-07-19 20:31:08 +02:00
2021-07-17 22:16:18 +02:00
}
Component {
id: packSettingsComponent
ImagePackSettingsDialog {
}
}
Component {
id: readReceiptsDialog
ReadReceipts {
}
}
2021-07-31 04:13:58 +02:00
Component {
id: rawMessageDialog
RawMessageDialog {
}
}
2021-09-30 02:15:25 +02:00
Component {
id: logoutDialog
LogoutDialog {
}
2021-09-30 02:15:25 +02:00
}
2021-09-25 03:32:06 +02:00
Component {
id: joinRoomDialog
JoinRoomDialog {
}
2021-09-25 03:32:06 +02:00
}
Component {
id: confirmJoinRoomDialog
ConfirmJoinRoomDialog {
}
}
Component {
id: leaveRoomComponent
LeaveRoomDialog {
}
}
Component {
id: imageOverlay
ImageOverlay {
}
}
2022-01-09 00:28:03 +01:00
Component {
id: userSettingsPage
UserSettingsPage {
}
}
2022-01-24 00:41:55 +01:00
Shortcut {
sequence: StandardKey.Quit
onActivated: Qt.quit()
}
Shortcut {
sequence: "Ctrl+K"
onActivated: {
var quickSwitch = quickSwitcherComponent.createObject(timelineRoot);
quickSwitch.open();
2022-03-01 01:59:06 +01:00
destroyOnClosed(quickSwitch);
}
}
Shortcut {
// Add alternative shortcut, because sometimes Alt+A is stolen by the TextEdit
sequences: ["Alt+A", "Ctrl+Shift+A"]
onActivated: Rooms.nextRoomWithActivity()
}
2021-05-28 23:25:57 +02:00
Shortcut {
sequence: "Ctrl+Down"
onActivated: Rooms.nextRoom()
2021-05-28 23:25:57 +02:00
}
2021-05-28 23:25:57 +02:00
Shortcut {
sequence: "Ctrl+Up"
onActivated: Rooms.previousRoom()
2021-05-28 23:25:57 +02:00
}
2021-09-30 02:15:25 +02:00
Connections {
function onOpenLogoutDialog() {
var dialog = logoutDialog.createObject(timelineRoot);
dialog.open();
destroyOnClose(dialog);
2021-09-30 02:15:25 +02:00
}
2021-09-25 03:32:06 +02:00
function onOpenJoinRoomDialog() {
var dialog = joinRoomDialog.createObject(timelineRoot);
dialog.show();
destroyOnClose(dialog);
2021-09-25 03:32:06 +02:00
}
function onShowRoomJoinPrompt(summary) {
var dialog = confirmJoinRoomDialog.createObject(timelineRoot, {"summary": summary});
dialog.show();
destroyOnClose(dialog);
}
2021-09-30 02:15:25 +02:00
target: Nheko
}
Connections {
function onNewDeviceVerificationRequest(flow) {
var dialog = deviceVerificationDialog.createObject(timelineRoot, {
"flow": flow
});
dialog.show();
destroyOnClose(dialog);
}
target: VerificationManager
}
function destroyOnClose(obj) {
if (obj.closing != undefined) obj.closing.connect(() => obj.destroy(1000));
else if (obj.aboutToHide != undefined) obj.aboutToHide.connect(() => obj.destroy(1000));
}
2022-03-01 01:59:06 +01:00
function destroyOnClosed(obj) {
obj.aboutToHide.connect(() => obj.destroy(1000));
2022-03-01 01:59:06 +01:00
}
Connections {
function onOpenProfile(profile) {
var userProfile = userProfileComponent.createObject(timelineRoot, {
"profile": profile
});
userProfile.show();
destroyOnClose(userProfile);
}
function onShowImagePackSettings(room, packlist) {
var packSet = packSettingsComponent.createObject(timelineRoot, {
"room": room,
"packlist": packlist
});
packSet.show();
destroyOnClose(packSet);
}
2021-08-13 23:58:26 +02:00
function onOpenRoomMembersDialog(members, room) {
2021-06-11 02:13:12 +02:00
var membersDialog = roomMembersComponent.createObject(timelineRoot, {
"members": members,
2021-08-13 23:58:26 +02:00
"room": room
2021-06-11 02:13:12 +02:00
});
membersDialog.show();
destroyOnClose(membersDialog);
2021-06-11 02:13:12 +02:00
}
function onOpenRoomSettingsDialog(settings) {
2021-06-11 02:13:12 +02:00
var roomSettings = roomSettingsComponent.createObject(timelineRoot, {
"roomSettings": settings
});
roomSettings.show();
destroyOnClose(roomSettings);
2021-06-11 02:13:12 +02:00
}
function onOpenInviteUsersDialog(invitees) {
2021-06-11 02:13:12 +02:00
var dialog = inviteDialog.createObject(timelineRoot, {
2021-07-17 22:16:18 +02:00
"roomId": Rooms.currentRoom.roomId,
2021-07-21 01:17:20 +02:00
"plainRoomName": Rooms.currentRoom.plainRoomName,
2021-07-18 00:23:21 +02:00
"invitees": invitees
2021-07-17 22:16:18 +02:00
});
2021-06-11 02:13:12 +02:00
dialog.show();
destroyOnClose(dialog);
2021-06-11 02:13:12 +02:00
}
2022-03-30 23:38:38 +02:00
function onOpenLeaveRoomDialog(roomid, reason) {
var dialog = leaveRoomComponent.createObject(timelineRoot, {
2022-03-30 23:38:38 +02:00
"roomId": roomid,
"reason": reason
});
dialog.open();
destroyOnClose(dialog);
}
2022-05-10 03:19:53 +02:00
function onShowImageOverlay(room, eventId, url, originalWidth, proportionalHeight) {
var dialog = imageOverlay.createObject(timelineRoot, {
"room": room,
"eventId": eventId,
"url": url,
"originalWidth": originalWidth ?? 0,
"proportionalHeight": proportionalHeight ?? 0
});
2022-05-10 03:19:53 +02:00
dialog.showFullScreen();
destroyOnClose(dialog);
}
target: TimelineManager
}
Connections {
function onNewInviteState() {
if (CallManager.haveCallInvite && Settings.mobileMode) {
2022-02-25 17:24:00 +01:00
var dialog = mobileCallInviteDialog.createObject(timelineRoot);
dialog.open();
destroyOnClose(dialog);
}
}
target: CallManager
2021-06-11 02:13:12 +02:00
}
SelfVerificationCheck {
}
InputDialog {
id: uiaPassPrompt
echoMode: TextInput.Password
title: UIA.title
prompt: qsTr("Please enter your login password to continue:")
onAccepted: (t) => {
return UIA.continuePassword(t);
}
}
InputDialog {
id: uiaEmailPrompt
title: UIA.title
prompt: qsTr("Please enter a valid email address to continue:")
onAccepted: (t) => {
return UIA.continueEmail(t);
}
}
PhoneNumberInputDialog {
id: uiaPhoneNumberPrompt
title: UIA.title
prompt: qsTr("Please enter a valid phone number to continue:")
onAccepted: (p, t) => {
return UIA.continuePhoneNumber(p, t);
}
}
InputDialog {
id: uiaTokenPrompt
title: UIA.title
prompt: qsTr("Please enter the token, which has been sent to you:")
onAccepted: (t) => {
return UIA.submit3pidToken(t);
}
}
Platform.MessageDialog {
id: uiaErrorDialog
buttons: Platform.MessageDialog.Ok
}
Platform.MessageDialog {
id: uiaConfirmationLinkDialog
buttons: Platform.MessageDialog.Ok
text: qsTr("Wait for the confirmation link to arrive, then continue.")
onAccepted: UIA.continue3pidReceived()
}
Connections {
function onPassword() {
console.log("UIA: password needed");
uiaPassPrompt.show();
}
function onEmail() {
uiaEmailPrompt.show();
}
function onPhoneNumber() {
uiaPhoneNumberPrompt.show();
}
function onPrompt3pidToken() {
uiaTokenPrompt.show();
}
function onConfirm3pidToken() {
uiaConfirmationLinkDialog.open();
}
function onError(msg) {
uiaErrorDialog.text = msg;
uiaErrorDialog.open();
}
target: UIA
}
2022-01-09 00:28:03 +01:00
StackView {
id: mainWindow
anchors.fill: parent
2022-01-24 00:41:55 +01:00
initialItem: welcomePage
}
Component {
id: welcomePage
WelcomePage {
2022-01-09 00:28:03 +01:00
}
}
2022-01-12 19:09:46 +01:00
Component {
id: chatPage
ChatPage {
}
}
2022-01-24 00:41:55 +01:00
Component {
id: loginPage
LoginPage {
}
}
2022-01-28 15:24:56 +01:00
Component {
id: registerPage
RegisterPage {
2022-01-28 15:24:56 +01:00
}
}
2022-01-30 19:14:33 +01:00
Snackbar { id: snackbar }
2022-01-12 19:09:46 +01:00
Connections {
function onSwitchToChatPage() {
2022-01-24 00:41:55 +01:00
mainWindow.replace(null, chatPage);
}
function onSwitchToLoginPage(error) {
mainWindow.replace(welcomePage, {}, loginPage, {"error": error}, StackView.PopTransition);
2022-01-12 19:09:46 +01:00
}
2022-01-30 19:14:33 +01:00
function onShowNotification(msg) {
snackbar.showNotification(msg);
console.log("New snack: " + msg);
}
2022-01-12 19:09:46 +01:00
target: MainWindow
}
}