|
| 1 | +import QtQuick |
| 2 | +import QtQuick.Layouts |
| 3 | +import QtQuick.Controls.Material |
| 4 | + |
| 5 | +import Main |
| 6 | + |
| 7 | +Page { |
| 8 | + id: page |
| 9 | + title: qsTr("Pending devices") |
| 10 | + Component.onCompleted: page.load() |
| 11 | + actions: [ |
| 12 | + Action { |
| 13 | + text: qsTr("Refresh") |
| 14 | + icon.source: App.faUrlBase + "refresh" |
| 15 | + onTriggered: (source) => page.load() |
| 16 | + } |
| 17 | + ] |
| 18 | + contentItem: CustomListView { |
| 19 | + id: listView |
| 20 | + delegate: ItemDelegate { |
| 21 | + id: itemDelegate |
| 22 | + width: listView.width |
| 23 | + contentItem: ColumnLayout { |
| 24 | + width: listView.width |
| 25 | + Label { |
| 26 | + Layout.fillWidth: true |
| 27 | + text: App.deviceDisplayName(modelData.devId) |
| 28 | + elide: Text.ElideRight |
| 29 | + font.weight: Font.Medium |
| 30 | + wrapMode: Text.WordWrap |
| 31 | + } |
| 32 | + Label { |
| 33 | + Layout.fillWidth: true |
| 34 | + text: qsTr("Name: ") + (modelData.info.Name ?? modelData.info.name) |
| 35 | + elide: Text.ElideRight |
| 36 | + font.weight: Font.Light |
| 37 | + wrapMode: Text.WordWrap |
| 38 | + } |
| 39 | + Label { |
| 40 | + Layout.fillWidth: true |
| 41 | + text: qsTr("Address: ") + (modelData.info.Address ?? modelData.info.address) |
| 42 | + elide: Text.ElideRight |
| 43 | + font.weight: Font.Light |
| 44 | + wrapMode: Text.WordWrap |
| 45 | + } |
| 46 | + RowLayout { |
| 47 | + Layout.fillWidth: true |
| 48 | + Button { |
| 49 | + text: qsTr("Ignore") |
| 50 | + flat: true |
| 51 | + onClicked: page.ignoreDev(modelData.devId) |
| 52 | + } |
| 53 | + Button { |
| 54 | + text: qsTr("Add device") |
| 55 | + flat: true |
| 56 | + onClicked: pages.addDevice(modelData.devId, modelData.info.Name ?? modelData.info.name) |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + required property var modelData |
| 61 | + } |
| 62 | + model: ListModel { |
| 63 | + id: listModel |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + required property var pages |
| 68 | + required property list<Action> actions |
| 69 | + |
| 70 | + function load() { |
| 71 | + App.requestFromSyncthing("GET", "cluster/pending/devices", {}, (res, error) => { |
| 72 | + listModel.clear(); |
| 73 | + if (error.length > 0) { |
| 74 | + return; |
| 75 | + } |
| 76 | + Object.entries(res).forEach((pendingDev) => { |
| 77 | + listModel.append({devId: pendingDev[0], info: pendingDev[1]}); |
| 78 | + }); |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | + function ignoreDev(devId, info) { |
| 83 | + const cfg = App.connection.rawConfig; |
| 84 | + const ignoredDevs = cfg.remoteIgnoredDevices; |
| 85 | + if (!Array.isArray(ignoredDevs)) { |
| 86 | + return false; |
| 87 | + } |
| 88 | + ignoredDevs.push({deviceID: devId, name: info.Name ?? info.name ?? "", address: info.Address ?? info.address ?? "", time: new Date().toISOString()}); |
| 89 | + App.postSyncthingConfig(cfg, (error) => { |
| 90 | + if (error.length === 0) { |
| 91 | + page.load(); |
| 92 | + } |
| 93 | + }); |
| 94 | + return true; |
| 95 | + } |
| 96 | +} |
0 commit comments