Skip to content
Snippets Groups Projects
Root.qml 10.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • // 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 "./pages"
    
    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
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
    Pane {
    
        id: timelineRoot
    
        palette: Nheko.colors
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        background: null
        padding: 0
    
        RoomDirectoryModel {
            id: publicRooms
        }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        //Timer {
        //    onTriggered: gc()
        //    interval: 1000
        //    running: true
        //    repeat: true
        //}
    
    
        EmojiPicker {
            id: emojiPopup
    
            colors: palette
            model: TimelineManager.completerFor("allemoji", "")
        }
    
        Component {
            id: userProfileComponent
    
            UserProfile {
            }
    
        }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        function showAliasEditor(settings) {
            var dialog = aliasEditor.createObject(timelineRoot, {
                "roomSettings": settings
            });
            dialog.show();
            destroyOnClose(dialog);
        }
    
        Component {
            id: aliasEditor
    
            AliasEditor {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        }
    
        function showPLEditor(settings) {
            var dialog = plEditor.createObject(timelineRoot, {
                "roomSettings": settings
            });
            dialog.show();
            destroyOnClose(dialog);
        }
    
    
        Component {
            id: plEditor
    
            PowerLevelEditor {
            }
        }
    
    
    
        Component {
            id: roomSettingsComponent
    
            RoomSettings {
            }
    
        }
    
    
        Component {
            id: allowedRoomSettingsComponent
    
            AllowedRoomsSettingsDialog {
            }
    
        }
    
        function showAllowedRoomsEditor(settings) {
            var dialog = allowedRoomSettingsComponent.createObject(timelineRoot, {
                "roomSettings": settings
            });
            dialog.show();
            destroyOnClose(dialog);
        }
    
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        Component {
            id: roomMembersComponent
    
            RoomMembers {
            }
    
    Loren Burkholder's avatar
    Loren Burkholder committed
    
    
        Component {
            id: mobileCallInviteDialog
    
            CallInvite {
            }
    
        }
    
        Component {
            id: quickSwitcherComponent
    
            QuickSwitcher {
            }
    
        }
    
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        Component {
            id: deviceVerificationDialog
    
            DeviceVerification {
            }
    
        }
    
    Loren Burkholder's avatar
    Loren Burkholder committed
    
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        Component {
            id: inviteDialog
    
            InviteDialog {
            }
    
    Loren Burkholder's avatar
    Loren Burkholder committed
    
    
        Component {
            id: packSettingsComponent
    
            ImagePackSettingsDialog {
            }
    
        }
    
    
        Component {
            id: readReceiptsDialog
    
            ReadReceipts {
            }
    
        }
    
    
        Component {
            id: rawMessageDialog
    
            RawMessageDialog {
            }
    
        }
    
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        Component {
            id: logoutDialog
    
            LogoutDialog {
            }
    
        Component {
            id: joinRoomDialog
    
            JoinRoomDialog {
            }
    
        Component {
            id: confirmJoinRoomDialog
    
            ConfirmJoinRoomDialog {
            }
    
        }
    
    
        Component {
            id: leaveRoomComponent
    
            LeaveRoomDialog {
            }
    
        Component {
            id: imageOverlay
    
            ImageOverlay {
            }
    
        }
    
    
        Component {
            id: userSettingsPage
    
            UserSettingsPage {
            }
    
        }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Shortcut {
            sequence: StandardKey.Quit
            onActivated: Qt.quit()
        }
    
    
        Shortcut {
            sequence: "Ctrl+K"
            onActivated: {
                var quickSwitch = quickSwitcherComponent.createObject(timelineRoot);
                quickSwitch.open();
    
                destroyOnClosed(quickSwitch);
    
            // Add alternative shortcut, because sometimes Alt+A is stolen by the TextEdit
            sequences: ["Alt+A", "Ctrl+Shift+A"]
    
            onActivated: Rooms.nextRoomWithActivity()
        }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Shortcut {
            sequence: "Ctrl+Down"
    
            onActivated: Rooms.nextRoom()
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Shortcut {
            sequence: "Ctrl+Up"
    
            onActivated: Rooms.previousRoom()
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        Connections {
            function onOpenLogoutDialog() {
                var dialog = logoutDialog.createObject(timelineRoot);
                dialog.open();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
            function onOpenJoinRoomDialog() {
                var dialog = joinRoomDialog.createObject(timelineRoot);
                dialog.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
            function onShowRoomJoinPrompt(summary) {
                var dialog = confirmJoinRoomDialog.createObject(timelineRoot, {"summary": summary});
                dialog.show();
                destroyOnClose(dialog);
            }
    
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            target: Nheko
        }
    
    
            function onNewDeviceVerificationRequest(flow) {
    
                var dialog = deviceVerificationDialog.createObject(timelineRoot, {
                    "flow": flow
                });
                dialog.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        function destroyOnClose(obj) {
    
            if (obj.closing != undefined) obj.closing.connect(() => obj.destroy(1000));
            else if (obj.aboutToHide != undefined) obj.aboutToHide.connect(() => obj.destroy(1000));
    
        function destroyOnClosed(obj) {
    
            obj.aboutToHide.connect(() => obj.destroy(1000));
    
            function onOpenProfile(profile) {
    
                var userProfile = userProfileComponent.createObject(timelineRoot, {
                    "profile": profile
                });
                userProfile.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(userProfile);
    
            function onShowImagePackSettings(room, packlist) {
    
                var packSet = packSettingsComponent.createObject(timelineRoot, {
    
                    "packlist": packlist
                });
                packSet.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(packSet);
    
            function onOpenRoomMembersDialog(members, room) {
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                var membersDialog = roomMembersComponent.createObject(timelineRoot, {
                    "members": members,
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                });
                membersDialog.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(membersDialog);
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            }
    
    
            function onOpenRoomSettingsDialog(settings) {
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                var roomSettings = roomSettingsComponent.createObject(timelineRoot, {
                    "roomSettings": settings
                });
                roomSettings.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(roomSettings);
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            }
    
    
            function onOpenInviteUsersDialog(invitees) {
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                var dialog = inviteDialog.createObject(timelineRoot, {
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                    "roomId": Rooms.currentRoom.roomId,
    
                    "plainRoomName": Rooms.currentRoom.plainRoomName,
    
                    "invitees": invitees
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                });
    
    Loren Burkholder's avatar
    Loren Burkholder committed
                dialog.show();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
    Loren Burkholder's avatar
    Loren Burkholder committed
            }
    
            function onOpenLeaveRoomDialog(roomid, reason) {
    
                var dialog = leaveRoomComponent.createObject(timelineRoot, {
    
                    "roomId": roomid,
                    "reason": reason
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            function onShowImageOverlay(room, eventId, url, originalWidth, proportionalHeight) {
    
                var dialog = imageOverlay.createObject(timelineRoot, {
                    "room": room,
                    "eventId": eventId,
    
                    "url": url,
                    "originalWidth": originalWidth ?? 0,
                    "proportionalHeight": proportionalHeight ?? 0
    
                dialog.showFullScreen();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                destroyOnClose(dialog);
    
            target: TimelineManager
        }
    
        Connections {
            function onNewInviteState() {
                if (CallManager.haveCallInvite && Settings.mobileMode) {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    var dialog = mobileCallInviteDialog.createObject(timelineRoot);
    
                    dialog.open();
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                    destroyOnClose(dialog);
    
                }
            }
    
            target: CallManager
    
    Loren Burkholder's avatar
    Loren Burkholder committed
        }
    
    
        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();
            }
    
        StackView {
            id: mainWindow
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            initialItem: welcomePage
        }
    
        Component {
            id: welcomePage
    
            WelcomePage {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Component {
            id: chatPage
    
            ChatPage {
            }
        }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Component {
            id: loginPage
    
            LoginPage {
            }
        }
    
    
        Component {
            id: registerPage
    
    
            RegisterPage {
    
        Snackbar { id: snackbar }
    
    
    Nicolas Werner's avatar
    Nicolas Werner committed
        Connections {
            function onSwitchToChatPage() {
    
    Nicolas Werner's avatar
    Nicolas Werner committed
                mainWindow.replace(null, chatPage);
            }
            function onSwitchToLoginPage(error) {
                mainWindow.replace(welcomePage, {}, loginPage, {"error": error}, StackView.PopTransition);
    
            function onShowNotification(msg) {
                snackbar.showNotification(msg);
                console.log("New snack: " + msg);
            }
    
    Nicolas Werner's avatar
    Nicolas Werner committed
            target: MainWindow
        }