Skip to content
Snippets Groups Projects
  • Andreas Traczyk's avatar
    ae058405
    qml interop: remove clientwrapper · ae058405
    Andreas Traczyk authored
    The clientwrapper class masks granular object registration within
    qml, and encourages code duplication between viewmodels(adapters)
    and code lasagnafication and the misuse of declarative Qml.
    
    Change-Id: I85fef214363e62e54fc0681282323ea4861000d6
    Gitlab: #66
    ae058405
    History
    qml interop: remove clientwrapper
    Andreas Traczyk authored
    The clientwrapper class masks granular object registration within
    qml, and encourages code duplication between viewmodels(adapters)
    and code lasagnafication and the misuse of declarative Qml.
    
    Change-Id: I85fef214363e62e54fc0681282323ea4861000d6
    Gitlab: #66
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
MainApplicationWindow.qml 3.82 KiB
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls.Universal 2.12
import QtGraphicalEffects 1.14
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import net.jami.Enums 1.0

import "mainview"
import "wizardview"
import "commoncomponents"

ApplicationWindow {
    id: root

    AccountMigrationDialog{
        id: accountMigrationDialog

        visible: false

        onAccountMigrationFinished:{
            startClientByMainview()
        }
    }

    function close() {
        // If we're in the onboarding wizard or 'MinimizeOnClose'
        // is set, then we can quit
        if (!SettingsAdapter.getAppValue(Settings.MinimizeOnClose) ||
            !UtilsAdapter.getAccountListSize()) {
            Qt.quit()
        } else {
            // hide to the systray
            if (mainViewLoader.item)
                mainViewLoader.item.hide()
            else
                wizardView.hide()
        }
    }

    function slotNewAccountAdded() {
        if(mainViewLoader.newAddedAccountIndex !== -1)
            mainViewLoader.item.newAccountAdded(mainViewLoader.newAddedAccountIndex)
    }

    function startAccountMigration(){
        return accountMigrationDialog.startAccountMigrationOfTopStack()
    }

    function startClientByMainview(){
        setX(Screen.width / 2 - width / 2)
        setY(Screen.height / 2 - height / 2)

        if (!UtilsAdapter.getAccountListSize()) {
            wizardView.show()
        } else {
            mainViewLoader.setSource("qrc:/src/mainview/MainView.qml")
        }
    }

    Universal.theme: Universal.Light

    visible: false

    Loader {
        id: mainViewLoader

        property int newAddedAccountIndex: -1

        asynchronous: true
        visible: status == Loader.Ready
        source: ""

        Connections {
            target: mainViewLoader.item

            function onCloseApp() {
                root.close()
            }

            function onNoAccountIsAvailable() {
                mainViewLoader.setSource("")
                wizardViewForApplicationStart.changePageQML(0)
                wizardView.show()
            }
        }
    }

    Window {
        id: wizardView

        title: "Jami"

        minimumWidth: 500
        minimumHeight: 600

        WizardView {
            id: wizardViewForApplicationStart

            anchors.fill: parent

            onNeedToShowMainViewWindow: {
                mainViewLoader.newAddedAccountIndex = accountIndex
                if (mainViewLoader.source.toString() !== "qrc:/src/mainview/MainView.qml") {
                    mainViewLoader.loaded.disconnect(slotNewAccountAdded)
                    mainViewLoader.loaded.connect(slotNewAccountAdded)
                    mainViewLoader.setSource("qrc:/src/mainview/MainView.qml")
                } else {
                    slotNewAccountAdded()
                }
                wizardView.close()
            }

            onWizardViewIsClosed: parent.close()
        }

        // @disable-check M16
        onClosing: {
            if (mainViewLoader.source.toString() !== "qrc:/src/mainview/MainView.qml") {
                root.close()
            }
        }
        // @enable-check M16
    }

    Component.onCompleted: {
        if(!startAccountMigration()){
            startClientByMainview()
        }
    }

    overlay.modal: ColorOverlay {
        source: root.contentItem
        color: "transparent"

        // Color animation for overlay when pop up is shown.
        ColorAnimation on color {
            to: Qt.rgba(0, 0, 0, 0.33)
            duration: 500
        }
    }

    Connections {
        target: LRCInstance

        function onRestoreAppRequested() {
            if (mainViewLoader.item)
                mainViewLoader.item.show()
            else
                wizardView.show()
        }
    }
}