You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nheko/resources/qml/Root.qml

519 lines
17 KiB

// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import "./dialogs"
import "./pages"
import "./ui"
import QtQuick
import QtQuick.Controls
import QtQuick.Window
import QtQuick.Dialogs
import im.nheko
Pane {
id: timelineRoot
2 years ago
function destroyOnClose(obj) {
if (obj.closing != undefined)
obj.closing.connect(() => obj.destroy(1000));
else if (obj.aboutToHide != undefined)
obj.aboutToHide.connect(() => obj.destroy(1000));
}
2 years ago
function destroyOnClosed(obj) {
obj.aboutToHide.connect(() => obj.destroy(1000));
}
//Timer {
// onTriggered: gc()
// interval: 1000
// running: true
// repeat: true
//}
function showAliasEditor(settings) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/AliasEditor.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
2 years ago
"roomSettings": settings
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function showAllowedRoomsEditor(settings) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/AllowedRoomsSettingsDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
2 years ago
"roomSettings": settings
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function showPLEditor(settings) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/PowerLevelEditor.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
2 years ago
"roomSettings": settings
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function showSpacePLApplyPrompt(settings, editingModel) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/PowerLevelSpacesApplyDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
2 years ago
"roomSettings": settings,
"editingModel": editingModel
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
background: null
padding: 0
FontMetrics {
id: fontMetrics
}
UserDirectoryModel {
id: userDirectory
}
RoomDirectoryModel {
id: publicRooms
}
Component {
id: readReceiptsDialog
ReadReceipts {
}
}
Shortcut {
sequence: StandardKey.Quit
2 years ago
onActivated: Qt.quit()
}
Shortcut {
sequence: "Ctrl+K"
2 years ago
onActivated: {
var component = Qt.createComponent("qrc:/resources/qml/QuickSwitcher.qml");
if (component.status == Component.Ready) {
var quickSwitch = component.createObject(timelineRoot);
quickSwitch.open();
destroyOnClosed(quickSwitch);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
}
Shortcut {
// Add alternative shortcut, because sometimes Alt+A is stolen by the TextEdit
sequences: ["Alt+A", "Ctrl+Shift+A"]
2 years ago
onActivated: Rooms.nextRoomWithActivity()
}
Shortcut {
sequences: ["Ctrl+Down", "Ctrl+PgDown"]
2 years ago
onActivated: Rooms.nextRoom()
}
Shortcut {
sequences: ["Ctrl+Up", "Ctrl+PgUp"]
2 years ago
onActivated: Rooms.previousRoom()
}
Connections {
2 years ago
function onOpenJoinRoomDialog() {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/JoinRoomDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot);
2 years ago
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function onOpenLogoutDialog() {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/LogoutDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot);
2 years ago
dialog.open();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
function onShowRoomJoinPrompt(summary) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ConfirmJoinRoomDialog.qml");
if (component.status == Component.Ready) {
2 years ago
var dialog = component.createObject(timelineRoot, {
"summary": summary
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
target: Nheko
}
Connections {
function onNewDeviceVerificationRequest(flow) {
var component = Qt.createComponent("qrc:/resources/qml/device-verification/DeviceVerification.qml");
if (component.status == Component.Ready) {
2 years ago
var dialog = component.createObject(timelineRoot, {
"flow": flow
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
target: VerificationManager
}
Connections {
2 years ago
function onOpenInviteUsersDialog(invitees) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/InviteDialog.qml");
if (component.status == Component.Ready) {
2 years ago
var dialog = component.createObject(timelineRoot, {
"invitees": invitees
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function onOpenLeaveRoomDialog(roomid, reason) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/LeaveRoomDialog.qml");
if (component.status == Component.Ready) {
2 years ago
var dialog = component.createObject(timelineRoot, {
"roomId": roomid,
"reason": reason
});
dialog.open();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
function onOpenProfile(profile) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/UserProfile.qml");
2 years ago
if (component.status == Component.Ready) {
var userProfile = component.createObject(timelineRoot, {
"profile": profile
});
userProfile.show();
destroyOnClose(userProfile);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
function onOpenRoomMembersDialog(members, room) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/RoomMembers.qml");
if (component.status == Component.Ready) {
var membersDialog = component.createObject(timelineRoot, {
2 years ago
"members": members,
"room": room
});
membersDialog.show();
destroyOnClose(membersDialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
4 years ago
}
function onOpenRoomSettingsDialog(settings) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/RoomSettingsDialog.qml");
if (component.status == Component.Ready) {
var roomSettings = component.createObject(timelineRoot, {
2 years ago
"roomSettings": settings
});
roomSettings.show();
destroyOnClose(roomSettings);
} else {
console.error("Failed to create component: " + component.errorString());
}
4 years ago
}
function onShowImageOverlay(room, eventId, url, originalWidth, proportionalHeight) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ImageOverlay.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
"room": room,
"eventId": eventId,
"url": url,
"originalWidth": originalWidth ?? 0,
"proportionalHeight": proportionalHeight ?? 0
2 years ago
});
dialog.showFullScreen();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function onShowImagePackSettings(room, packlist) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ImagePackSettingsDialog.qml");
2 years ago
if (component.status == Component.Ready) {
var packSet = component.createObject(timelineRoot, {
"room": room,
"packlist": packlist
});
packSet.show();
destroyOnClose(packSet);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
target: TimelineManager
}
Connections {
function onNewInviteState() {
if (CallManager.haveCallInvite && Settings.mobileMode) {
var component = Qt.createComponent("qrc:/resources/qml/voip/CallInvite.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot);
dialog.open();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
}
target: CallManager
4 years ago
}
SelfVerificationCheck {
}
InputDialog {
id: uiaPassPrompt
echoMode: TextInput.Password
prompt: qsTr("Please enter your login password to continue:")
2 years ago
title: UIA.title
onAccepted: t => {
return UIA.continuePassword(t);
}
}
InputDialog {
id: uiaEmailPrompt
prompt: qsTr("Please enter a valid email address to continue:")
2 years ago
title: UIA.title
onAccepted: t => {
return UIA.continueEmail(t);
}
}
PhoneNumberInputDialog {
id: uiaPhoneNumberPrompt
prompt: qsTr("Please enter a valid phone number to continue:")
2 years ago
title: UIA.title
onAccepted: (p, t) => {
return UIA.continuePhoneNumber(p, t);
}
}
InputDialog {
id: uiaTokenPrompt
prompt: qsTr("Please enter the token which has been sent to you:")
2 years ago
title: UIA.title
onAccepted: t => {
return UIA.submit3pidToken(t);
}
}
MessageDialog {
id: uiaConfirmationLinkDialog
buttons: MessageDialog.Ok
text: qsTr("Wait for the confirmation link to arrive, then continue.")
2 years ago
onAccepted: UIA.continue3pidReceived()
}
Connections {
2 years ago
function onConfirm3pidToken() {
uiaConfirmationLinkDialog.open();
}
function onEmail() {
uiaEmailPrompt.show();
2 years ago
}
function onFallbackAuth(fallback) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/FallbackAuthDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
"fallback": fallback
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
2 years ago
function onPassword() {
console.log("UIA: password needed");
uiaPassPrompt.show();
}
function onPhoneNumber() {
uiaPhoneNumberPrompt.show();
}
function onPrompt3pidToken() {
uiaTokenPrompt.show();
}
function onReCaptcha(recaptcha) {
var component = Qt.createComponent("qrc:/resources/qml/dialogs/ReCaptchaDialog.qml");
if (component.status == Component.Ready) {
var dialog = component.createObject(timelineRoot, {
"recaptcha": recaptcha
});
dialog.show();
destroyOnClose(dialog);
} else {
console.error("Failed to create component: " + component.errorString());
}
}
target: UIA
}
StackView {
id: mainWindow
2 years ago
property Transition popEnterOrg
property Transition popExitOrg
// for some reason direct bindings to a hidden StackView don't work, so manually store and restore here.
property Transition pushEnterOrg
property Transition pushExitOrg
property Transition replaceEnterOrg
property Transition replaceExitOrg
2 years ago
function updateTrans() {
pushEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : pushEnterOrg;
pushExit = Settings.reducedMotion ? reducedMotionTransitionExit : pushExitOrg;
popEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : popEnterOrg;
popExit = Settings.reducedMotion ? reducedMotionTransitionExit : popExitOrg;
replaceEnter = Settings.reducedMotion ? reducedMotionTransitionEnter : replaceEnterOrg;
replaceExit = Settings.reducedMotion ? reducedMotionTransitionExit : replaceExitOrg;
}
anchors.fill: parent
initialItem: welcomePage
Component.onCompleted: {
pushEnterOrg = pushEnter;
popEnterOrg = popEnter;
replaceEnterOrg = replaceEnter;
pushExitOrg = pushExit;
popExitOrg = popExit;
replaceExitOrg = replaceExit;
2 years ago
updateTrans();
}
2 years ago
Transition {
id: reducedMotionTransitionExit
PropertyAnimation {
duration: 200
from: 1
property: "opacity"
to: 0
}
}
2 years ago
Transition {
id: reducedMotionTransitionEnter
2 years ago
SequentialAnimation {
PropertyAction {
property: "opacity"
value: 0
}
PauseAnimation {
duration: 200
}
PropertyAnimation {
duration: 200
from: 0
property: "opacity"
to: 1
}
}
}
Connections {
function onReducedMotionChanged() {
mainWindow.updateTrans();
}
2 years ago
target: Settings
}
}
Component {
id: welcomePage
WelcomePage {
}
}
Component {
id: chatPage
ChatPage {
}
}
Component {
id: loginPage
LoginPage {
}
}
Component {
id: registerPage
RegisterPage {
}
}
Component {
id: userSettingsPage
UserSettingsPage {
}
}
2 years ago
Snackbar {
id: snackbar
2 years ago
}
Connections {
2 years ago
function onShowNotification(msg) {
snackbar.showNotification(msg);
console.log("New snack: " + msg);
}
function onSwitchToChatPage() {
mainWindow.replace(null, chatPage);
}
function onSwitchToLoginPage(error) {
2 years ago
mainWindow.replace(welcomePage, {}, loginPage, {
"error": error
}, StackView.PopTransition);
}
2 years ago
target: MainWindow
}
}