aboutsummaryrefslogtreecommitdiff
path: root/qml/main.qml
blob: 1b7e1a45dac1982627e3705e60aeef6828846f03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import DeltaChat 1.0
import QtQuick 2.12
import QtQuick.Controls 2.12 as Controls
import org.kde.kirigami 2.12 as Kirigami

Kirigami.ApplicationWindow {
    id: root

    property DcAccountsEventEmitter eventEmitter

    title: qsTr("Delta Chat")
    Component.onCompleted: {
        console.log('starting');
        // Create an account if there is none.
        if (dcAccounts.getSelectedAccount() == null) {
            console.log("Adding first account");
            dcAccounts.addAccount();
        }
        eventEmitter = dcAccounts.getEventEmitter();
        eventEmitter.start();
        // Open selected account if there is one.
        let selectedAccount = dcAccounts.getSelectedAccount();
        if (selectedAccount) {
            if (selectedAccount.isConfigured())
                pageStack.replace("qrc:/qml/ChatlistPage.qml", {
                    "context": selectedAccount,
                    "eventEmitter": eventEmitter
                });
            else
                pageStack.replace("qrc:/qml/ConfigurePage.qml", {
                    "context": selectedAccount,
                    "eventEmitter": eventEmitter
                });
        }
        dcAccounts.startIo();
    }
    onClosing: {
        // Cancel all tasks that may block the termination of event loop.
        dcAccounts.stopIo();
    }

    Component {
        id: accountsPage

        AccountsPage {
        }

    }

    DcAccounts {
        id: dcAccounts
    }

    pageStack.initialPage: Kirigami.Page {
    }

    globalDrawer: Kirigami.GlobalDrawer {
        actions: [
            Kirigami.Action {
                text: "Maybe network"
                iconName: "view-refresh"
                onTriggered: dcAccounts.maybeNetwork()
            },
            Kirigami.Action {
                text: "Switch account"
                iconName: "system-switch-user"
                onTriggered: {
                    while (pageStack.layers.depth > 1)
                        pageStack.layers.pop();

                    pageStack.layers.push(accountsPage);
                }
            }
        ]

        header: Controls.Switch {
            text: "Work offline"
            onCheckedChanged: {
                if (checked)
                    dcAccounts.stopIo();
                else
                    dcAccounts.startIo();
            }
        }

    }

    contextDrawer: Kirigami.ContextDrawer {
        id: contextDrawer
    }

}