Debian Codegraph @

plugins/CuraDrive/src/qml/components/BackupListItem.qml

raw
1 // Copyright (c) 2022 Ultimaker B.V.
2 // Cura is released under the terms of the LGPLv3 or higher.
3
4 import QtQuick 2.7
5 import QtQuick.Controls 2.1
6 import QtQuick.Layouts 1.3
7
8 import UM 1.5 as UM
9 import Cura 1.0 as Cura
10
11 Item
12 {
13 id: backupListItem
14 width: parent.width
15 height: showDetails ? dataRow.height + backupDetails.height : dataRow.height
16 property bool showDetails: false
17
18 // Backup details toggle animation.
19 Behavior on height
20 {
21 PropertyAnimation
22 {
23 duration: 70
24 }
25 }
26
27 RowLayout
28 {
29 id: dataRow
30 spacing: UM.Theme.getSize("wide_margin").width
31 width: parent.width
32 height: 50 * screenScaleFactor
33
34 UM.SimpleButton
35 {
36 width: UM.Theme.getSize("section_icon").width
37 height: UM.Theme.getSize("section_icon").height
38 color: UM.Theme.getColor("small_button_text")
39 hoverColor: UM.Theme.getColor("small_button_text_hover")
40 iconSource: UM.Theme.getIcon("Information")
41 onClicked: backupListItem.showDetails = !backupListItem.showDetails
42 }
43
44 UM.Label
45 {
46 text: new Date(modelData.generated_time).toLocaleString(UM.Preferences.getValue("general/language"))
47 elide: Text.ElideRight
48 Layout.minimumWidth: 100 * screenScaleFactor
49 Layout.maximumWidth: 500 * screenScaleFactor
50 Layout.fillWidth: true
51 }
52
53 UM.Label
54 {
55 text: modelData.metadata.description
56 elide: Text.ElideRight
57 Layout.minimumWidth: 100 * screenScaleFactor
58 Layout.maximumWidth: 500 * screenScaleFactor
59 Layout.fillWidth: true
60 }
61
62 Cura.SecondaryButton
63 {
64 text: catalog.i18nc("@button", "Restore")
65 enabled: !CuraDrive.isCreatingBackup && !CuraDrive.isRestoringBackup
66 onClicked: confirmRestoreDialog.visible = true
67 busy: CuraDrive.backupIdBeingRestored == modelData.backup_id && CuraDrive.isRestoringBackup
68 }
69
70 UM.SimpleButton
71 {
72 width: UM.Theme.getSize("message_close").width
73 height: UM.Theme.getSize("message_close").height
74 color: UM.Theme.getColor("small_button_text")
75 hoverColor: UM.Theme.getColor("small_button_text_hover")
76 iconSource: UM.Theme.getIcon("Cancel")
77 onClicked: confirmDeleteDialog.visible = true
78 }
79 }
80
81 BackupListItemDetails
82 {
83 id: backupDetails
84 backupDetailsData: modelData
85 width: parent.width
86 visible: parent.showDetails
87 anchors.top: dataRow.bottom
88 }
89
90 Cura.MessageDialog
91 {
92 id: confirmDeleteDialog
93 title: catalog.i18nc("@dialog:title", "Delete Backup")
94 text: catalog.i18nc("@dialog:info", "Are you sure you want to delete this backup? This cannot be undone.")
95 standardButtons: Dialog.Yes | Dialog.No
96 onAccepted: CuraDrive.deleteBackup(modelData.backup_id)
97 }
98
99 Cura.MessageDialog
100 {
101 id: confirmRestoreDialog
102 title: catalog.i18nc("@dialog:title", "Restore Backup")
103 text: catalog.i18nc("@dialog:info", "You will need to restart Cura before your backup is restored. Do you want to close Cura now?")
104 standardButtons: Dialog.Yes | Dialog.No
105 onAccepted: CuraDrive.restoreBackup(modelData.backup_id)
106 }
107 }