File: ImportPage.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,281 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 QtQuick.Dialogs

import Main

Page {
    id: importPage
    title: qsTr("Select settings to import")
    Layout.fillWidth: true
    Layout.fillHeight: true
    CustomFlickable {
        id: mainView
        anchors.fill: parent
        contentHeight: mainLayout.height
        ColumnLayout {
            id: mainLayout
            width: mainView.width
            spacing: 0
            ItemDelegate {
                Layout.fillWidth: true
                visible: importPage.availableSettings.error !== undefined
                contentItem: RowLayout {
                    spacing: 15
                    ForkAwesomeIcon {
                        iconName: "exclamation-circle"
                    }
                    ColumnLayout {
                        Layout.fillWidth: true
                        Label {
                            Layout.fillWidth: true
                            text: qsTr("An error occurred when checking selected directory")
                            elide: Text.ElideRight
                            font.weight: Font.Medium
                            wrapMode: Text.WordWrap
                        }
                        Label {
                            Layout.fillWidth: true
                            text: importPage.availableSettings.error ?? ""
                            elide: Text.ElideRight
                            font.weight: Font.Light
                            wrapMode: Text.WordWrap
                        }
                    }
                }
            }
            ItemDelegate {
                Layout.fillWidth: true
                enabled: availableSettings.appConfigPath !== undefined
                onClicked: appConfig.toggle()
                contentItem: RowLayout {
                    spacing: 15
                    ForkAwesomeIcon {
                        iconName: "cog"
                    }
                    ColumnLayout {
                        Layout.fillWidth: true
                        Label {
                            Layout.fillWidth: true
                            text: qsTr("App configuration")
                            elide: Text.ElideRight
                            font.weight: Font.Medium
                            wrapMode: Text.WordWrap
                        }
                        Label {
                            Layout.fillWidth: true
                            text: qsTr("Replace the app configuration with the one from the selected directory.")
                            elide: Text.ElideRight
                            font.weight: Font.Light
                            wrapMode: Text.WordWrap
                        }
                    }
                    Switch {
                        id: appConfig
                    }
                }
            }
            ItemDelegate {
                id: fullImportDelegate
                Layout.fillWidth: true
                enabled: availableSettings.syncthingHomePath !== undefined
                onClicked: {
                    fullImport.toggle();
                    fullImport.toggled();
                }
                contentItem: RowLayout {
                    spacing: 15
                    ForkAwesomeIcon {
                        iconName: "syncthing"
                    }
                    ColumnLayout {
                        Layout.fillWidth: true
                        Label {
                            Layout.fillWidth: true
                            text: qsTr("Full Syncthing configuration and database")
                            elide: Text.ElideRight
                            font.weight: Font.Medium
                            wrapMode: Text.WordWrap
                        }
                        Label {
                            Layout.fillWidth: true
                            text: qsTr("Replace entire (existing) Syncthing configuration and database with the one from the selected directory. Use this with care as restoring the database is potentially dangerous.")
                            elide: Text.ElideRight
                            font.weight: Font.Light
                            wrapMode: Text.WordWrap
                        }
                    }
                    Switch {
                        id: fullImport
                        onToggled: {
                            if (fullImport.checked) {
                                folderSelection.selectionEnabled = false;
                                deviceSelection.selectionEnabled = false;
                            }
                        }
                    }
                }
            }
            SelectiveImportDelegate {
                id: folderSelection
                enabled: availableSettings.folders !== undefined && !fullImport.checked
                iconName: "folder"
                text: qsTr("Selected folders")
                description: qsTr("Merge the selected folders into the existing Syncthing configuration. You can change paths in case they differ on this device.")
                dialogTitle: qsTr("Select folders to import")
                model: ListModel {
                    id: foldersModel
                    Component.onCompleted: {
                        const folders = importPage.availableSettings.folders;
                        if (folders?.length > 0) {
                            folders.forEach((folder, index) => foldersModel.append({index: index, displayName: folder.label?.length > 0 ? folder.label : folder.id, path: folder.path, checked: false}));
                        }
                    }
                }
            }
            SelectiveImportDelegate {
                id: deviceSelection
                enabled: availableSettings.devices !== undefined && !fullImport.checked
                iconName: "sitemap"
                text: qsTr("Selected devices")
                description: qsTr("Merge the selected devices into the existing Syncthing configuration.")
                dialogTitle: qsTr("Select devices to import")
                model: ListModel {
                    id: devicesModel
                    Component.onCompleted: {
                        const devices = importPage.availableSettings.devices;
                        if (devices?.length > 0) {
                            devices.forEach((device, index) => devicesModel.append({index: index, displayName: device.name?.length > 0 ? `${device.name}\n${device.deviceID}` : device.deviceID, checked: false}));
                        }
                    }
                }
            }
        }
    }
    property alias folderSelection: folderSelection
    property alias deviceSelection: deviceSelection
    required property var availableSettings
    readonly property bool isDangerous: fullImport.checked
    property list<Action> actions: [
        Action {
            text: qsTr("Import selected")
            icon.source: App.faUrlBase + "download"
            onTriggered: App.importSettings(importPage.availableSettings, importPage.computeSelectedConfig())
        }
    ]
    function back() {
        App.importSettings(importPage.availableSettings, {aborted: true});
        return false;
    }
    function computeSelectedConfig() {
        return {
            appConfig: appConfig.checked,
            syncthingHome: fullImport.checked,
            selectedFolders: folderSelection.selectionEnabled ? handleSelectedIndexes(foldersModel) : [],
            selectedDevices: deviceSelection.selectionEnabled ? handleSelectedIndexes(devicesModel) : [],
        }
    }
    function handleSelectedIndexes(model) {
        const indexes = [];
        const folders = importPage.availableSettings.folders;
        for (let i = 0, count = model.count; i !== count; ++i) {
            const modelData = model.get(i);
            if (modelData.checked) {
                // update paths
                const path = modelData.path;
                if (path !== undefined && folders?.length > 0 && i < folders?.length) {
                    folders[i].path = path;
                }
                indexes.push(i);
            }
        }
        return indexes;
    }
}