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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
|
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls.Material
import QtQuick.Dialogs
import Qt.labs.qmlmodels
import Main
DelegateChooser {
role: "type"
DelegateChoice {
roleValue: "readonly"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
enabled: modelData.enabled ?? true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
elide: Text.ElideRight
font.weight: Font.Light
wrapMode: Text.WordWrap
Component.onCompleted: text = modelData.statusText ?? displayText(modelData.value, modelData.inputMethodHints)
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
IconOnlyButton {
text: qsTr("Copy")
icon.source: App.faUrlBase + "files-o"
onClicked: App.copyText(copyText)
Component.onCompleted: copyText = modelData.statusText ?? modelData.value.toString()
property string copyText: ""
}
HelpButton {
configCategory: objectConfigPage.configCategory
}
}
required property var modelData
}
}
DelegateChoice {
roleValue: "string"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
enabled: modelData.enabled ?? true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
text: displayText(modelData.value, modelData.inputMethodHints)
elide: Text.ElideRight
font.weight: Font.Light
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
id: helpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: stringDlg.visible = true
EditTextFieldDialog {
id: stringDlg
helpButton: helpButton
}
required property var modelData
property alias dialog: stringDlg
}
}
DelegateChoice {
roleValue: "deviceid"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
enabled: modelData.enabled ?? true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
}
Label {
Layout.fillWidth: true
text: modelData.value ?? ""
elide: Text.ElideRight
font.weight: Font.Light
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
id: deviceIdHelpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: (modelData.enabled ?? true) ? deviceIdDlg.visible = true : App.performHapticFeedback()
CustomDialog {
id: deviceIdDlg
title: modelData.label
standardButtons: objectConfigPage.standardButtons
contentItem: ColumnLayout {
GridLayout {
columns: deviceIdDlg.width > 550 ? 2 : 1
ComboBox {
id: editedDeviceIdValue
Layout.fillWidth: true
enabled: modelData?.enabled ?? true
editable: true
onAccepted: deviceIdDlg.accept()
}
RowLayout {
IconOnlyButton {
text: qsTr("Clear")
enabled: modelData.enabled ?? true
icon.source: App.faUrlBase + "undo"
onClicked: {
editedDeviceIdValue.currentIndex = -1;
editedDeviceIdValue.editText = "";
}
}
IconOnlyButton {
text: qsTr("Refresh list of devices")
icon.source: App.faUrlBase + "refresh"
onClicked: deviceIdDlg.refreshDeviceList()
}
CopyPasteButtons {
edit: editedDeviceIdValue
textProperty: "editText"
}
}
}
RowLayout {
id: devideIdInfo
ForkAwesomeIcon {
iconName: devideIdInfo.isIdOk ? "check" : "exclamation-triangle"
}
Label {
text: devideIdInfo.isIdValid ? (devideIdInfo.isIdExisting ? qsTr("This device has already been added!") : qsTr("The device ID looks valid.")) : qsTr("The entered device ID looks invalid!")
}
property bool isIdValid: editedDeviceIdValue.editText.match(validIdRegex)
property bool isIdExisting: (modelData?.enabled ?? true) && App.hasDevice(editedDeviceIdValue.editText)
property bool isIdOk: isIdValid && !isIdExisting
property var validIdRegex: /^[0-9A-z]{7}(-[0-9A-z]{7}){7}$/
}
}
onAboutToShow: {
deviceIdDlg.refreshDeviceList();
editedDeviceIdValue.currentIndex = -1;
editedDeviceIdValue.editText = modelData.value ?? "";
}
onAccepted: objectConfigPage.updateValue(modelData.index, modelData.key, editedDeviceIdValue.editText)
onRejected: editedDeviceIdValue.editText = objectConfigPage.configObject[modelData.key]
onHelpRequested: deviceIdHelpButton.clicked()
function refreshDeviceList() {
App.requestFromSyncthing("GET", "system/discovery", {}, (res, error) => {
const currentIndex = editedDeviceIdValue.currentIndex;
const currentText = editedDeviceIdValue.editText;
editedDeviceIdValue.model = Object.keys(res);
editedDeviceIdValue.currentIndex = currentIndex;
editedDeviceIdValue.editText = currentText;
});
}
}
required property var modelData
property alias dialog: deviceIdDlg
}
}
DelegateChoice {
roleValue: "options"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
text: optionsValue.editText // `${optionsValue.editText} (${modelData.value})`
elide: Text.ElideRight
font.weight: Font.Light
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
id: optionsHelpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: optionsDlg.visible = true
CustomDialog {
id: optionsDlg
title: modelData.label
standardButtons: objectConfigPage.standardButtons
contentItem: ScrollView {
id: optionsScrollView
contentWidth: availableWidth
ColumnLayout {
id: optionsDlgLayout
width: optionsScrollView.width - optionsScrollView.effectiveScrollBarWidth
ComboBox {
id: optionsValue
Layout.fillWidth: true
model: modelData.options
editable: true
valueRole: "value"
textRole: "label"
enabled: modelData?.enabled ?? true
onAccepted: optionsDlg.accept()
Component.onCompleted: {
//popup.popupType = Popup.Native;
editText = textOfValue(modelData.value);
currentIndex = indexOfValue(modelData.value);
}
readonly property var currentOption: modelData.options.get(optionsValue.currentIndex)
readonly property string currentValueOrEditText: {
const currentOption = optionsValue.currentOption;
return (currentOption?.label === optionsValue.editText) ? currentOption?.value : optionsValue.editText;
}
function textOfValue(value) {
const displayText = optionsValue.textAt(optionsValue.indexOfValue(value));
return displayText.length === 0 ? value : displayText;
}
}
Label {
id: optionsHelpLabel
Layout.fillWidth: true
wrapMode: Text.WordWrap
visible: text.length > 0
text: {
const currentOption = optionsValue.currentOption;
return (currentOption?.label === optionsValue.editText) ? (currentOption?.desc ?? "") : qsTr("A custom value has been entered.");
}
}
}
}
onAccepted: {
const changeHandler = modelData.onChanged;
objectConfigPage.updateValue(modelData.index, modelData.key, optionsValue.currentValueOrEditText);
if (typeof changeHandler === "function") {
changeHandler(objectConfigPage.configObject);
}
}
onRejected: optionsValue.editText = optionsValue.textOfValue(objectConfigPage.configObject[modelData.key])
onHelpRequested: optionsHelpButton.clicked()
}
required property var modelData
property alias dialog: optionsDlg
}
}
DelegateChoice {
roleValue: "devices"
ItemDelegate {
id: devicesDelegate
width: parent?.width
contentItem: ColumnLayout {
width: objectListView.width
RowLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
id: devicesHelpButton
configCategory: objectConfigPage.configCategory
}
}
ColumnLayout {
Layout.fillWidth: true
Repeater {
model: devicesDelegate.devicesModel
ItemDelegate {
id: deviceEntry
Layout.fillWidth: true
contentItem: RowLayout {
Layout.fillWidth: true
Label {
id: deviceNameOrIdLabel
Layout.fillWidth: true
text: App.connection.deviceNameOrId(modelData.deviceID)
elide: Text.ElideRight
font.weight: Font.Light
}
Switch {
id: deviceSwitch
checked: devicesDelegate.isDeviceEnabled(modelData.deviceID)
onCheckedChanged: devicesDelegate.setDeviceEnabled(modelData.deviceID, deviceSwitch.checked)
}
IconOnlyButton {
id: encryptionButton
text: deviceEntry.isEncryptionEnabled ? qsTr("Change encryption password") : qsTr("Set encryption password")
enabled: deviceSwitch.checked
icon.source: App.faUrlBase + (deviceEntry.isEncryptionEnabled ? "lock" : "unlock")
onClicked: encryptionPasswordDlg.open()
}
CustomDialog {
id: encryptionPasswordDlg
title: qsTr("Set encryption password for sharing with \"%1\"").arg(deviceNameOrIdLabel.text)
standardButtons: objectConfigPage.standardButtons
contentItem: RowLayout {
TextField {
id: encryptionKeyValue
Layout.fillWidth: true
text: modelData.encryptionPassword
placeholderText: qsTr("If untrusted, enter encryption password")
onAccepted: encryptionKeyDlg.accept()
}
CopyPasteButtons {
edit: encryptionKeyValue
}
}
onAccepted: {
deviceEntry.isEncryptionEnabled = encryptionKeyValue.text.length > 0;
devicesDelegate.setDeviceProperty(modelData.deviceID, "encryptionPassword", encryptionKeyValue.text);
}
onRejected: encryptionKeyValue.text = Qt.binding(() => modelData.encryptionPassword)
onHelpRequested: App.requestOpeningUrl("https://docs.syncthing.net/users/untrusted.html")
}
}
onClicked: deviceSwitch.toggle()
required property var modelData
property bool isEncryptionEnabled: modelData.encryptionPassword?.length > 0
}
}
}
}
required property var modelData
property var devicesModel: {
const devices = [];
const idsToSelect = modelData.selectIds;
const sharedDevices = objectConfigPage.configObject[modelData.key];
const myId = App.connection.myId;
if (typeof idsToSelect === "object") {
for (const idToSelect of idsToSelect) {
if (idToSelect !== myId) {
sharedDevices.push({deviceID: idToSelect, encryptionPassword: "", introducedBy: ""});
}
}
}
for (const sharedDev of sharedDevices) {
if (sharedDev.deviceID !== myId) {
devices.push(sharedDev);
}
}
const otherDevices = App.connection.deviceIds;
for (const otherDevID of otherDevices) {
if (otherDevID !== myId && devices.find((existingDev) => existingDev.deviceID === otherDevID) === undefined) {
devices.push({deviceID: otherDevID, encryptionPassword: "", introducedBy: ""});
}
}
return devices;
}
function findDevice(deviceID) {
return objectConfigPage.configObject[modelData.key].find((device) => device.deviceID === deviceID);
}
function isDeviceEnabled(deviceID) {
return findDevice(deviceID) !== undefined;
}
function setDeviceEnabled(deviceID, enabled) {
const devices = objectConfigPage.configObject[modelData.key];
const index = devices.findIndex((device) => device.deviceID === deviceID);
if (enabled && index < 0) {
devices.push({deviceID: deviceID, encryptionPassword: "", introducedBy: ""});
objectConfigPage.hasUnsavedChanges = true;
} else if (!enabled && index >= 0) {
devices.splice(index, 1);
objectConfigPage.hasUnsavedChanges = true;
}
}
function setDeviceProperty(deviceID, key, value) {
const device = findDevice(deviceID);
if (device !== undefined) {
device[key] = value;
objectConfigPage.hasUnsavedChanges = true;
}
}
}
}
DelegateChoice {
roleValue: "number"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
text: displayText(modelData.value, modelData.inputMethodHints)
elide: Text.ElideRight
font.weight: Font.Light
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
id: numberHelpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: numberDlg.visible = true
CustomDialog {
id: numberDlg
title: modelData.label
standardButtons: objectConfigPage.standardButtons
contentItem: TextField {
id: editedNumberValue
text: modelData.value
inputMethodHints: modelData.inputMethodHints ?? Qt.ImhNone
validator: DoubleValidator {
id: numberValidator
locale: "en"
}
onAccepted: numberDlg.accept()
}
onAccepted: objectConfigPage.updateValue(modelData.index, modelData.key, Number.fromLocaleString(Qt.locale(numberValidator.locale), editedNumberValue.text))
onRejected: editedNumberValue.text = objectConfigPage.configObject[modelData.key]
onHelpRequested: numberHelpButton.clicked()
}
required property var modelData
property alias dialog: numberDlg
}
}
DelegateChoice {
roleValue: "object"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
Label {
id: objNameLabel
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
readonly property int modelIndex: modelData.index
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
configCategory: objectConfigPage.configCategory
}
}
onClicked: {
const currentPath = objectConfigPage.path;
const configObject = objectConfigPage.configObject;
const pathKey = Array.isArray(configObject) ? "*" : modelData.key;
const neestedPath = currentPath.length > 0 ? `${currentPath}.${pathKey}` : pathKey;
objectConfigPage.stackView.push("ObjectConfigPage.qml", {
title: objNameLabel.text,
configObject: configObject[modelData.key],
parentObject: configObject,
isDangerous: objectConfigPage.isDangerous,
readOnly: objectConfigPage.readOnly,
stackView: objectConfigPage.stackView,
parentPage: objectConfigPage,
objectNameLabel: objNameLabel,
path: neestedPath,
helpUrl: modelData.helpUrl ?? "",
itemLabel: modelData.itemLabel ?? "",
configTemplates: objectConfigPage.configTemplates,
specialEntries: objectConfigPage.specialEntriesByKey[neestedPath] ?? [],
specialEntriesByKey: objectConfigPage.specialEntriesByKey ?? {}},
StackView.PushTransition)
}
required property var modelData
}
}
DelegateChoice {
roleValue: "boolean"
ItemDelegate {
width: objectListView.width
onClicked: booleanSwitch.toggle()
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
visible: text.length > 0
elide: Text.ElideRight
font.weight: Font.Light
wrapMode: Text.WordWrap
Component.onCompleted: text = modelData.statusText ?? ""
}
}
Switch {
id: booleanSwitch
checked: modelData.value
onCheckedChanged: objectConfigPage.updateValue(modelData.index, modelData.key, booleanSwitch.checked)
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
HelpButton {
configCategory: objectConfigPage.configCategory
}
}
required property var modelData
}
}
DelegateChoice {
roleValue: "function"
ItemDelegate {
width: objectListView.width
onClicked: modelData.value()
contentItem: ColumnLayout {
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
visible: text.length > 0
elide: Text.ElideRight
font.weight: Font.Light
wrapMode: Text.WordWrap
Component.onCompleted: text = modelData.statusText ?? ""
}
}
required property var modelData
}
}
DelegateChoice {
roleValue: "filepath"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
enabled: modelData.enabled ?? true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
Layout.fillWidth: true
text: modelData.value
elide: Text.ElideRight
font.weight: Font.Light
wrapMode: Text.WordWrap
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
IconOnlyButton {
text: qsTr("Clear")
enabled: modelData.enabled ?? true
icon.source: App.faUrlBase + "undo"
onClicked: objectConfigPage.updateValue(modelData.index, modelData.key, "")
}
IconOnlyButton {
id: manualFileDlgButton
text: qsTr("Edit manually")
enabled: modelData.enabled ?? true
icon.source: App.faUrlBase + "pencil"
onClicked: manualFileDlg.open()
}
HelpButton {
id: fileHelpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: (modelData.enabled ?? true) && fileDlg.open()
FileDialog {
id: fileDlg
title: modelData.label
fileMode: modelData.fileMode ?? FileDialog.OpenFile
onAccepted: objectConfigPage.updateValue(modelData.index, modelData.key, App.resolveUrl(fileDlg.selectedFile))
}
EditTextFieldDialog {
id: manualFileDlg
helpButton: fileHelpButton
}
required property var modelData
property alias manualButton: manualFileDlgButton
property alias dialog: manualFileDlg
}
}
DelegateChoice {
roleValue: "folderpath"
ItemDelegate {
width: objectListView.width
contentItem: RowLayout {
ColumnLayout {
Layout.fillWidth: true
enabled: modelData.enabled ?? true
Label {
Layout.fillWidth: true
text: modelData.label
elide: Text.ElideRight
font.weight: Font.Medium
wrapMode: Text.WordWrap
}
Label {
id: folderpathValue
Layout.fillWidth: true
text: modelData.value
elide: Text.ElideRight
font.weight: Font.Light
wrapMode: Text.WordWrap
}
}
ArrayElementButtons {
page: objectConfigPage
rowData: modelData
}
IconOnlyButton {
text: qsTr("Clear")
enabled: modelData.enabled ?? true
icon.source: App.faUrlBase + "undo"
onClicked: objectConfigPage.updateValue(modelData.index, modelData.key, "")
}
IconOnlyButton {
id: manualFolderDlgButton
text: qsTr("Edit manually")
enabled: modelData.enabled ?? true
icon.source: App.faUrlBase + "pencil"
onClicked: manualFolderDlg.open()
}
HelpButton {
id: folderHelpButton
configCategory: objectConfigPage.configCategory
}
}
onClicked: (modelData.enabled ?? true) && folderDlg.open()
FolderDialog {
id: folderDlg
title: modelData.label
currentFolder: encodeURIComponent(folderpathValue.text)
onAccepted: objectConfigPage.updateValue(modelData.index, modelData.key, App.resolveUrl(folderDlg.selectedFolder))
}
EditTextFieldDialog {
id: manualFolderDlg
helpButton: folderHelpButton
}
required property var modelData
property alias manualButton: manualFolderDlgButton
property alias dialog: manualFolderDlg
}
}
required property var objectConfigPage
function displayText(data, inputMethodHints = Qt.ImhNone) {
return (inputMethodHints & Qt.ImhHiddenText) ? (data?.toString() ? "•••" : "") : (data?.toString() ?? "");
}
}
|