aboutsummaryrefslogtreecommitdiff
path: root/qml/main.qml
blob: fc49bb9ae4868a101749b1890c863611e1df2ca3 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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")
    onClosing: {
        // Cancel all tasks that may block the termination of event loop.
        dcAccounts.stopIo();
    }
    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
                });
        }
    }

    Component {
        id: accountsPage

        AccountsPage {
        }

    }

    DcAccounts {
        id: dcAccounts
    }

    Shortcut {
        sequence: 'Esc'
        onActivated: {
            while (pageStack.layers.depth > 1)
                pageStack.layers.pop();

        }
    }

    // Make Ctrl+Q works even when popup
    // windows are opened
    // Quit application
    Shortcut {
        sequence: 'Ctrl+Q'
        onActivated: root.close()
        context: Qt.ApplicationShortcut
    }

    // Show sidebar with 'Work offline', 'Switch
    // accounts' options
    Shortcut {
        sequence: 'Ctrl+Tab'
        onActivated: sideBar.drawerOpen = true
    }

    // Refresh network connectivity. Can be used
    // to retry fetching messages
    Shortcut {
        sequence: 'F5'
        onActivated: dcAccounts.maybeNetwork()
    }

    // Show a popup listing keyboards shortcuts
    // for KDeltaChat
    Shortcut {
        //context: Qt.ApplicationShortcut

        sequence: "F1"
        onActivated: helpPopup.open()
    }

    Controls.Popup {
        id: workNetwNotif

        modal: false
        focus: activeFocus ? false : false
        dim: false
        width: 150
        height: 50
        x: Math.round((parent.width - width) / 2)
        padding: 10
        contentChildren: [
            Text {
                text: "Network status :"
                bottomPadding: 10
                font.bold: true
                font.pixelSize: 14
            },
            Text {
                text: offlineSwitch.checked ? "We can work offline now." : "We can work online now."
                font.pixelSize: 9
                topPadding: 20
                leftPadding: 10
                bottomPadding: 20
            }
        ]
    }

    Controls.Popup {
        id: helpPopup

        modal: true
        focus: true
        anchors.centerIn: parent
        width: 200
        height: 200
        padding: 10
        contentChildren: [
            Text {
                text: "Shortcuts :"
                bottomPadding: 10
                font.bold: true
                font.pixelSize: 14
            },
            Text {
                text: "<b>F1</b>: Displays this" + "<br><b>F2</b>: Work on/offline" + "<br><b>F5</b>: Network check" + "<br><b>Shift+S</b>: Account settings" + "<br><b>Alt+C</b>: Clear search" + "<br><b>Alt+Tab</b>: Switch accounts" + "<br><b>Ctrl+F</b>: Search contacts" + "<br><b>Ctrl+N</b>: New chat" + "<br><b>Ctrl+S</b>: Send message" + "<br><b>Ctrl+Tab</b>: Show sidebar" + "<br><b>Ctrl+Q</b>: Quit"
                topPadding: 20
                leftPadding: 10
                bottomPadding: 20
            }
        ]
    }

    pageStack.initialPage: Kirigami.Page {
    }

    globalDrawer: Kirigami.GlobalDrawer {
        id: sideBar

        actions: [
            Kirigami.Action {
                text: "Maybe network"
                tooltip: "F5"
                iconName: "view-refresh"
                onTriggered: dcAccounts.maybeNetwork()
            },
            Kirigami.Action {
                shortcut: "Alt+Tab"
                text: "Switch account"
                tooltip: "Alt+Tab"
                iconName: "system-users"
                onTriggered: {
                    while (pageStack.layers.depth > 1)pageStack.layers.pop()
                    pageStack.layers.push(accountsPage);
                }
            },
            Kirigami.Action {
                text: "Shortcuts"
                tooltip: "F1"
                iconName: "preferences-desktop-keyboard"
                onTriggered: helpPopup.open()
            },
            Kirigami.Action {
                text: "Quit"
                tooltip: "Ctrl+Q"
                onTriggered: root.close()
            }
        ]

        header: Controls.Switch {
            id: offlineSwitch

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

            action: Kirigami.Action {
                id: workOff

                shortcut: "F2"
                tooltip: "F2"
                onTriggered: {
                    if (offlineSwitch.state == "on") {
                        offlineSwitch.checked = false;
                        offlineSwitch.state = "off";
                        workNetwNotif.close();
                        workNetwNotif.open();
                        console.log("Work online");
                    } else {
                        offlineSwitch.checked = true;
                        offlineSwitch.state = "on";
                        workNetwNotif.close();
                        workNetwNotif.open();
                        console.log("Work offline");
                    }
                }
            }

        }

    }

    contextDrawer: Kirigami.ContextDrawer {
        id: contextDrawer
    }

}