Changeset View
Changeset View
Standalone View
Standalone View
plasma/package/contents/ui/VaultItem.qml
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org> | 2 | * Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org> | ||
3 | * Copyright 2020 by Nate Graham <nate@kde.org> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or | 5 | * This program is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU General Public License as | 6 | * modify it under the terms of the GNU General Public License as | ||
6 | * published by the Free Software Foundation; either version 2 of | 7 | * published by the Free Software Foundation; either version 2 of | ||
7 | * the License or (at your option) version 3 or any later version | 8 | * the License or (at your option) version 3 or any later version | ||
8 | * accepted by the membership of KDE e.V. (or its successor approved | 9 | * accepted by the membership of KDE e.V. (or its successor approved | ||
9 | * by the membership of KDE e.V.), which shall act as a proxy | 10 | * by the membership of KDE e.V.), which shall act as a proxy | ||
10 | * defined in Section 14 of version 3 of the license. | 11 | * defined in Section 14 of version 3 of the license. | ||
11 | * | 12 | * | ||
12 | * This program is distributed in the hope that it will be useful, | 13 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 16 | * GNU General Public License for more details. | ||
16 | * | 17 | * | ||
17 | * You should have received a copy of the GNU General Public License | 18 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | import QtQuick 2.1 | 22 | import QtQuick 2.1 | ||
22 | import QtQuick.Layouts 1.1 | 23 | import QtQuick.Controls 2.12 | ||
23 | import org.kde.plasma.core 2.0 as PlasmaCore | 24 | | ||
24 | import org.kde.plasma.plasmoid 2.0 | 25 | import org.kde.plasma.plasmoid 2.0 | ||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | | |||
26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | 26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||
27 | 27 | | |||
28 | MouseArea { | 28 | PlasmaExtras.ExpandableListItem { | ||
29 | id: vaultItem | 29 | id: expandableListItem | ||
30 | | ||||
31 | property alias icon: vaultIcon.source | | |||
32 | property alias name: vaultName.text | | |||
33 | property alias message: vaultMessage.text | | |||
34 | property string device: "" | | |||
35 | | ||||
36 | property bool isOpened: false | | |||
37 | property bool isBusy: false | | |||
38 | property bool isEnabled: false | | |||
39 | | ||||
40 | property bool isOfflineOnly: false | | |||
41 | | ||||
42 | signal itemExpanded(variant item); | | |||
43 | | ||||
44 | function collapse() { | | |||
45 | actionsList.visible = false; | | |||
46 | } | | |||
47 | | ||||
48 | onIsEnabledChanged: if (!isEnabled) { collapse(); } | | |||
49 | | ||||
50 | property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.actionsModel() | 30 | property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.actionsModel() | ||
51 | 31 | | |||
52 | hoverEnabled: true | | |||
53 | height: units.iconSizes.medium + 2 * units.smallSpacing | | |||
54 | + (actionsList.visible ? (actionsList.height + actionsListSpacer.height) : 0) | | |||
55 | | ||||
56 | onContainsMouseChanged: { | | |||
57 | vaultItem.ListView.view.currentIndex = (containsMouse ? index : -1) | | |||
58 | } | | |||
59 | | ||||
60 | PlasmaCore.IconItem { | | |||
61 | id: vaultIcon | | |||
62 | | ||||
63 | anchors { | | |||
64 | left: parent.left | | |||
65 | top: parent.top | | |||
66 | margins: units.smallSpacing | | |||
67 | } | | |||
68 | | ||||
69 | width: units.iconSizes.medium | | |||
70 | height: units.iconSizes.medium | | |||
71 | | ||||
72 | PlasmaCore.IconItem { | | |||
73 | anchors { | | |||
74 | left: parent.left | | |||
75 | bottom: parent.bottom | | |||
76 | } | | |||
77 | | ||||
78 | width: units.iconSizes.small | | |||
79 | height: units.iconSizes.small | | |||
80 | | ||||
81 | visible: source != "" | | |||
82 | | ||||
83 | source: { | | |||
84 | return vaultItem.message != "" ? "emblem-error" : | | |||
85 | vaultItem.isOpened ? "emblem-mounted" : | | |||
86 | vaultItem.isOfflineOnly ? "network-disconnect" : | | |||
87 | "" | | |||
88 | } | | |||
89 | } | | |||
90 | } | | |||
91 | | ||||
92 | PlasmaComponents.ToolButton { | | |||
93 | id: buttonOpenClose | | |||
94 | | ||||
95 | anchors { | | |||
96 | right: parent.right | | |||
97 | top: parent.top | | |||
98 | margins: units.smallSpacing | | |||
99 | } | | |||
100 | | ||||
101 | width: units.iconSizes.medium | | |||
102 | height: units.iconSizes.medium | | |||
103 | visible: !busyIndicator.visible | | |||
104 | | ||||
105 | iconName: isOpened ? "media-eject" : "media-mount" | | |||
106 | | ||||
107 | enabled: vaultItem.isEnabled | | |||
108 | | ||||
109 | onClicked: { | | |||
110 | vaultsModelActions.toggle(vaultItem.device); | | |||
111 | collapse(); | | |||
112 | itemExpanded(null); | | |||
113 | } | | |||
114 | } | | |||
115 | | ||||
116 | PlasmaComponents.BusyIndicator { | | |||
117 | id: busyIndicator | | |||
118 | anchors.fill: buttonOpenClose | | |||
119 | visible: isBusy | | |||
120 | } | | |||
121 | | ||||
122 | Column { | | |||
123 | anchors { | | |||
124 | left: vaultIcon.right | | |||
125 | right: buttonOpenClose.left | | |||
126 | verticalCenter: parent.verticalCenter | | |||
127 | margins: units.smallSpacing | | |||
128 | leftMargin: 2 * units.smallSpacing | | |||
129 | } | | |||
130 | | ||||
131 | PlasmaComponents.Label { | | |||
132 | id: vaultName | | |||
133 | | ||||
134 | width: parent.width | | |||
135 | height: undefined | | |||
136 | elide: Text.ElideRight | | |||
137 | } | | |||
138 | | ||||
139 | PlasmaComponents.Label { | | |||
140 | id: vaultMessage | | |||
141 | | ||||
142 | width: parent.width | | |||
143 | height: undefined | | |||
144 | elide: Text.ElideRight | | |||
145 | | ||||
146 | visible: { | | |||
147 | return vaultMessage.text != ""; | | |||
148 | } | | |||
149 | } | | |||
150 | | ||||
151 | Item { | | |||
152 | id: actionsListSpacer | | |||
153 | | ||||
154 | height: units.largeSpacing | | |||
155 | width: parent.width | | |||
156 | visible: actionsList.visible | | |||
157 | } | | |||
158 | | ||||
159 | ListView { | | |||
160 | id: actionsList | | |||
161 | | ||||
162 | height: units.iconSizes.medium * model.count | | |||
163 | width: parent.width | | |||
164 | visible: false | | |||
165 | | ||||
166 | highlight: PlasmaComponents.Highlight { | | |||
167 | id: highlight | | |||
168 | } | | |||
169 | | ||||
170 | model: actionsModel | | |||
171 | | ||||
172 | ListModel { | | |||
173 | id: actionsModel | | |||
174 | } | | |||
175 | | ||||
176 | delegate: ActionItem { | | |||
177 | icon: model.icon | 32 | icon: model.icon | ||
178 | text: model.text | 33 | iconEmblem: model.message.length !== 0 ? "emblem-error" : | ||
179 | 34 | model.isOpened ? "emblem-mounted" : | |||
180 | width: parent.width | 35 | model.isOfflineOnly ? "network-disconnect" : | ||
181 | 36 | "" | |||
182 | onActivated: { | 37 | title: model.name | ||
183 | if (model.action == "file-manager") { | 38 | subtitle: model.message | ||
184 | vaultsModelActions.openInFileManager(vaultItem.device); | 39 | defaultActionButtonAction: Action { | ||
185 | 40 | icon.name: model.isOpened ? "media-eject" : "media-mount" | |||
186 | } else if (model.action == "force-close") { | 41 | text: model.isOpened ? i18nd("plasmavault-kde", "Close vault") : i18nd("plasmavault-kde", "Open vault") | ||
187 | vaultsModelActions.forceClose(vaultItem.device); | 42 | onTriggered: { | ||
188 | 43 | if (model.isOpened) { | |||
189 | } else if (model.action == "configure") { | 44 | vaultsModelActions.toggle(model.device); | ||
190 | vaultsModelActions.configure(vaultItem.device); | 45 | } else { | ||
191 | 46 | vaultsModelActions.openInFileManager(model.device); | |||
192 | } | | |||
193 | | ||||
194 | collapse(); | | |||
195 | itemExpanded(null); | | |||
196 | } | | |||
197 | } | | |||
198 | } | | |||
199 | } | | |||
200 | | ||||
201 | MouseArea { | | |||
202 | anchors.fill: parent | | |||
203 | | ||||
204 | visible: !actionsList.visible | | |||
205 | | ||||
206 | onClicked: { | | |||
207 | if (!vaultItem.isEnabled) return; | | |||
208 | | ||||
209 | actionsList.visible = !actionsList.visible; | | |||
210 | if (actionsList.visible) { | | |||
211 | vaultItem.itemExpanded(vaultItem); | | |||
212 | | ||||
213 | actionsModel.clear(); | | |||
214 | | ||||
215 | actionsModel.append({ | | |||
216 | "icon" : "system-file-manager", | | |||
217 | "text" : i18nd("plasmavault-kde", "Open with File Manager"), | | |||
218 | "action" : "file-manager" | | |||
219 | }); | | |||
220 | | ||||
221 | if (vaultItem.message != "") { | | |||
222 | actionsModel.append({ | | |||
223 | "icon" : "window-close", | | |||
224 | "text" : i18nd("plasmavault-kde", "Forcefully close "), | | |||
225 | "action" : "force-close" | | |||
226 | }); | | |||
227 | } | 47 | } | ||
228 | | ||||
229 | actionsModel.append({ | | |||
230 | "icon" : "configure", | | |||
231 | "text" : i18nd("plasmavault-kde", "Configure Vault..."), | | |||
232 | "action" : "configure" | | |||
233 | }); | | |||
234 | } | 48 | } | ||
235 | } | 49 | } | ||
50 | isBusy: Plasmoid.busy | ||||
51 | isEnabled: model.isEnabled | ||||
52 | contextualActionsModel: [ | ||||
53 | Action { | ||||
54 | icon.name: "system-file-manager" | ||||
55 | text: i18nd("plasmavault-kde", "Open with File Manager") | ||||
56 | onTriggered: vaultsModelActions.openInFileManager(model.device); | ||||
57 | }, | ||||
58 | Action { | ||||
59 | icon.name: "window-close" | ||||
60 | text: i18nd("plasmavault-kde", "Forcefully close") | ||||
61 | onTriggered: vaultsModelActions.forceClose(model.device); | ||||
62 | enabled: model.isOpened | ||||
63 | }, | ||||
64 | Action { | ||||
65 | icon.name: "configure" | ||||
66 | text: i18nd("plasmavault-kde", "Configure Vault...") | ||||
67 | onTriggered: vaultsModelActions.configure(model.device); | ||||
236 | } | 68 | } | ||
69 | ] | ||||
237 | } | 70 | } | ||
238 | | ||||
239 | |