File: MainToolBar.qml

package info (click to toggle)
syncthingtray 2.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 34,081; xml: 1,705; java: 1,258; sh: 97; javascript: 54; makefile: 25
file content (195 lines) | stat: -rw-r--r-- 8,391 bytes parent folder | download
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
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls.Material
import Qt.labs.qmlmodels

import Main

ToolBar {
    id: toolBar
    leftPadding: 0
    Material.theme: darkToolbar ? Material.Light : parent.Material.theme
    Material.background: darkToolbar ? Material.primary : Material.color(Material.LightBlue, Material.Shade100)
    ColumnLayout {
        anchors.fill: parent
        anchors.leftMargin: toolBar.leftMargin
        Material.theme: darkToolbar ? Material.Dark : toolBar.Material.theme
        RowLayout {
            visible: App.status.length !== 0
            CustomToolButton {
                id: statusButton
                visible: !busyIndicator.running
                icon.source: App.faUrlBase + "exclamation-triangle"
                text: App.hasInternalErrors || App.connection.hasErrors ? qsTr("Show notifications/errors") : qsTr("Syncthing backend status is problematic")
                onClicked: {
                    const hasInternalErrors = App.hasInternalErrors;
                    const hasConnectionErrors = App.connection.hasErrors;
                    if (hasInternalErrors && hasConnectionErrors) {
                        statusButtonMenu.showCenteredIn(statusButton);
                    } else if (hasInternalErrors) {
                        statusButton.showInternalErrors();
                    } else if (hasConnectionErrors) {
                        statusButton.showConnectionErrors();
                    } else {
                        App.performHapticFeedback();
                    }
                }
                CustomMenu {
                    id: statusButtonMenu
                    MenuItem {
                        text: qsTr("Show API errors")
                        onTriggered: statusButton.showInternalErrors()
                    }
                    MenuItem {
                        text: qsTr("Show Syncthing errors/notifications")
                        onTriggered: statusButton.showConnectionErrors()
                    }
                }
                function showInternalErrors() {
                    const settingsPage = pageStack.showPage(5);
                    if (!(settingsPage.currentItem instanceof InternalErrorsPage)) {
                        settingsPage.push("InternalErrorsPage.qml", {}, StackView.PushTransition);
                    }
                }
                function showConnectionErrors() {
                    const settingsPage = pageStack.showPage(5);
                    if (!(settingsPage.currentItem instanceof ErrorsPage)) {
                        settingsPage.push("ErrorsPage.qml", {}, StackView.PushTransition);
                    }
                }
            }
            BusyIndicator {
                id: busyIndicator
                Material.accent: Material.foreground
                running: App.connection.connecting || App.syncthingStarting || App.savingConfig || App.importExportOngoing
                visible: running
                Layout.preferredWidth: statusButton.width - Layout.margins * 2
                Layout.preferredHeight: statusButton.height - Layout.margins * 2
                Layout.margins: 5
            }
            Label {
                text: App.status
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignLeft
                verticalAlignment: Qt.AlignVCenter
                wrapMode: Text.WordWrap
                Layout.fillWidth: true
            }
            CustomToolButton {
                visible: !App.connection.connected
                icon.source: App.faUrlBase + "refresh"
                text: qsTr("Try to re-connect")
                onClicked: App.connectToSyncthing()
            }
        }
        StackLayout {
            id: toolBarStack
            currentIndex: toolBarStack.searchAvailable && (searchTextArea.text.length > 0 || searchTextArea.activeFocus) ? 1 : 0
            RowLayout {
                CustomToolButton {
                    visible: !backButton.visible
                    icon.source: App.faUrlBase + "bars"
                    text: qsTr("Toggle menu")
                    onClicked: drawer.visible ? drawer.close() : drawer.open()
                }
                CustomToolButton {
                    id: backButton
                    visible: pageStack.currentDepth > 1
                    icon.source: App.faUrlBase + "arrow-left"
                    text: qsTr("Back")
                    onClicked: pageStack.pop()
                }
                Label {
                    text: pageStack.currentPage.title
                    elide: Label.ElideRight
                    horizontalAlignment: Qt.AlignLeft
                    verticalAlignment: Qt.AlignVCenter
                    wrapMode: Text.Wrap
                    Layout.fillWidth: true
                }
                CustomToolButton {
                    visible: toolBarStack.searchAvailable
                    icon.source: App.faUrlBase + "search"
                    text: qsTr("Search")
                    onClicked: searchTextArea.focus = true
                }
                Repeater {
                    model: pageStack.currentActions
                    DelegateChooser {
                        role: "enabled"
                        DelegateChoice {
                            roleValue: true
                            CustomToolButton {
                                required property Action modelData
                                enabled: modelData.enabled
                                text: modelData.text
                                icon.source: modelData.icon.source
                                onClicked: modelData.trigger()
                            }
                        }
                    }
                }
                CustomToolButton {
                    id: extraActionsMenuButton
                    visible: pageStack.currentExtraActions.length > 0
                    icon.source: App.faUrlBase + "ellipsis-v"
                    text: qsTr("More")
                    onClicked: pageStack.currentPage?.showExtraActions() ?? extraActionsMenu.showCenteredIn(extraActionsMenuButton)
                    CustomMenu {
                        id: extraActionsMenu
                        MenuItemInstantiator {
                            menu: extraActionsMenu
                            model: {
                                const currentPage = pageStack.currentPage;
                                const extraActions = currentPage.showExtraActions === undefined ? currentPage.extraActions : undefined;
                                return extraActions ?? [];
                            }
                        }
                    }
                }
            }
            RowLayout {
                TextArea {
                    id: searchTextArea
                    Layout.fillWidth: true
                    Layout.preferredHeight: clearSearchButton.height
                    leftInset: 2
                    topInset: 7
                    bottomInset: 2
                    topPadding: 14
                    bottomPadding: 7
                    placeholderText: qsTr("Searching %1").arg(pageStack.currentPage.title)
                    onTextChanged: pageStack.updateSearchText(searchTextArea.text)
                }
                CustomToolButton {
                    id: clearSearchButton
                    icon.source: App.faUrlBase + "times-circle-o"
                    text: qsTr("Clear search")
                    onClicked: searchTextArea.clear()
                }
            }
            readonly property bool searchAvailable: pageStack?.currentPage?.model?.filterRegularExpressionPattern !== undefined
        }
    }
    Connections {
        target: pageStack
        function onSearchTextChanged() {
            searchTextArea.text = pageStack.searchText;
        }
    }
    Connections {
        target: App
        function onInternalErrorsRequested() {
            statusButton.showInternalErrors();
        }
        function onConnectionErrorsRequested() {
            statusButton.showConnectionErrors();
        }
    }

    required property LeftDrawer drawer
    required property PageStack pageStack
    property real leftMargin: 0
    property bool darkToolbar: false
    property alias busy: busyIndicator.running
}