Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/JobItem.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * 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 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * 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 | * 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 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * 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 | */ | ||||
20 | | ||||
21 | import QtQuick 2.8 | ||||
22 | import QtQuick.Window 2.2 | ||||
23 | import QtQuick.Layouts 1.1 | ||||
24 | | ||||
25 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
26 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
27 | | ||||
28 | import org.kde.notificationmanager 1.0 as NotificationManager | ||||
29 | | ||||
30 | import org.kde.plasma.private.notifications 2.0 as Notifications | ||||
31 | | ||||
32 | ColumnLayout { | ||||
33 | id: jobItem | ||||
34 | | ||||
35 | property int jobState | ||||
36 | property int error | ||||
37 | property string errorText | ||||
38 | | ||||
39 | property alias percentage: progressBar.value | ||||
40 | property alias suspendable: suspendButton.visible | ||||
41 | property alias killable: killButton.visible | ||||
42 | | ||||
43 | property bool hovered | ||||
44 | property QtObject jobDetails | ||||
45 | // TOOD make an alias on visible if we're not doing an animation | ||||
46 | property bool showDetails | ||||
47 | | ||||
48 | readonly property alias menuOpen: otherFileActionsMenu.visible | ||||
49 | | ||||
50 | signal suspendJobClicked | ||||
51 | signal resumeJobClicked | ||||
52 | signal killJobClicked | ||||
53 | | ||||
54 | signal openUrl(string url) | ||||
55 | signal fileActionInvoked | ||||
56 | | ||||
57 | spacing: 0 | ||||
58 | | ||||
59 | PlasmaComponents.Label { | ||||
60 | Layout.fillWidth: true | ||||
61 | textFormat: Text.PlainText | ||||
62 | wrapMode: Text.WordWrap | ||||
63 | text: jobItem.errorText || (jobItem.jobDetails ? jobItem.jobDetails.text : "") | ||||
64 | visible: text !== "" | ||||
65 | } | ||||
66 | | ||||
67 | RowLayout { | ||||
68 | Layout.fillWidth: true | ||||
69 | spacing: units.smallSpacing | ||||
70 | | ||||
71 | PlasmaComponents.ProgressBar { | ||||
72 | id: progressBar | ||||
73 | Layout.fillWidth: true | ||||
74 | minimumValue: 0 | ||||
75 | maximumValue: 100 | ||||
76 | // TODO do we actually need the window visible check? perhaps I do because it can be in popup or expanded plasmoid | ||||
77 | indeterminate: visible && Window.window && Window.window.visible && percentage < 1 | ||||
78 | && jobItem.jobState === NotificationManager.Notifications.JobStateRunning | ||||
79 | // is this too annoying? | ||||
80 | && (jobItem.jobDetails.processedBytes === 0 || jobItem.jobDetails.totalBytes === 0) | ||||
81 | && jobItem.jobDetails.processedFiles === 0 | ||||
82 | //&& jobItem.jobDetails.processedDirectories === 0 | ||||
83 | } | ||||
84 | | ||||
85 | RowLayout { | ||||
86 | id: jobActionsRow | ||||
87 | spacing: 0 | ||||
88 | | ||||
89 | PlasmaComponents.ToolButton { | ||||
90 | id: suspendButton | ||||
91 | tooltip: i18nc("Pause running job", "Pause") | ||||
92 | iconSource: "media-playback-pause" | ||||
93 | onClicked: jobItem.jobState === NotificationManager.Notifications.JobStateSuspended ? jobItem.resumeJobClicked() | ||||
94 | : jobItem.suspendJobClicked() | ||||
95 | } | ||||
96 | | ||||
97 | PlasmaComponents.ToolButton { | ||||
98 | id: killButton | ||||
99 | tooltip: i18nc("Cancel running job", "Cancel") | ||||
100 | iconSource: "media-playback-stop" | ||||
101 | onClicked: jobItem.killJobClicked() | ||||
102 | } | ||||
103 | | ||||
104 | PlasmaComponents.ToolButton { | ||||
105 | id: expandButton | ||||
106 | Layout.leftMargin: units.smallSpacing | ||||
107 | iconSource: checked ? "arrow-down" : (LayoutMirroring.enabled ? "arrow-left" : "arrow-right") | ||||
108 | tooltip: checked ? i18nc("A button tooltip; hides item details", "Hide Details") | ||||
109 | : i18nc("A button tooltip; expands the item to show details", "Show Details") | ||||
110 | checkable: true | ||||
111 | } | ||||
112 | } | ||||
113 | } | ||||
114 | | ||||
115 | Loader { | ||||
116 | Layout.fillWidth: true | ||||
117 | active: expandButton.checked | ||||
118 | // Loader doesn't reset its height when unloaded, just hide it altogether | ||||
119 | visible: active | ||||
120 | sourceComponent: JobDetails { | ||||
121 | jobDetails: jobItem.jobDetails | ||||
122 | } | ||||
123 | } | ||||
124 | | ||||
125 | Flow { // it's a Flow so it can wrap if too long | ||||
126 | id: jobDoneActions | ||||
127 | Layout.fillWidth: true | ||||
128 | spacing: units.smallSpacing | ||||
129 | // We want the actions to be right-aligned but Flow also reverses | ||||
130 | // the order of items, so we put them in reverse order | ||||
131 | layoutDirection: Qt.RightToLeft | ||||
132 | visible: url && url.toString() !== "" | ||||
133 | | ||||
134 | property var url: { | ||||
135 | if (jobItem.jobState !== NotificationManager.Notifications.JobStateStopped | ||||
136 | || jobItem.error | ||||
137 | || !jobItem.jobDetails | ||||
138 | || jobItem.jobDetails.totalFiles <= 0) { | ||||
139 | return null; | ||||
140 | } | ||||
141 | | ||||
142 | // For a single file show actions for it | ||||
143 | if (jobItem.jobDetails.totalFiles === 1) { | ||||
144 | return jobItem.jobDetails.descriptionUrl; | ||||
145 | } else { | ||||
146 | return jobItem.jobDetails.destUrl; | ||||
147 | } | ||||
148 | } | ||||
149 | | ||||
150 | PlasmaComponents.Button { | ||||
151 | id: otherFileActionsButton | ||||
152 | iconName: "application-menu" | ||||
153 | tooltip: i18n("More Options...") | ||||
154 | checkable: true | ||||
155 | onPressedChanged: { | ||||
156 | if (pressed) { | ||||
157 | checked = Qt.binding(function() { | ||||
158 | return otherFileActionsMenu.visible; | ||||
159 | }); | ||||
160 | otherFileActionsMenu.open(-1, -1); | ||||
161 | } | ||||
162 | } | ||||
163 | | ||||
164 | Notifications.FileMenu { | ||||
165 | id: otherFileActionsMenu | ||||
166 | url: jobDoneActions.url || "" | ||||
167 | visualParent: otherFileActionsButton | ||||
168 | onActionTriggered: jobItem.fileActionInvoked() | ||||
169 | } | ||||
170 | } | ||||
171 | | ||||
172 | PlasmaComponents.Button { | ||||
173 | // would be nice to have the file icon here? | ||||
174 | text: jobItem.jobDetails && jobItem.jobDetails.totalFiles > 1 ? i18n("Open Containing Folder") : i18n("Open") | ||||
175 | onClicked: jobItem.openUrl(jobDoneActions.url) | ||||
176 | width: minimumWidth | ||||
177 | } | ||||
178 | } | ||||
179 | | ||||
180 | states: [ | ||||
181 | State { | ||||
182 | when: jobItem.jobState === NotificationManager.Notifications.JobStateSuspended | ||||
183 | PropertyChanges { | ||||
184 | target: suspendButton | ||||
185 | tooltip: i18nc("Resume paused job", "Resume") | ||||
186 | iconSource: "media-playback-start" | ||||
187 | } | ||||
188 | PropertyChanges { | ||||
189 | target: progressBar | ||||
190 | enabled: false | ||||
191 | } | ||||
192 | }, | ||||
193 | State { | ||||
194 | when: jobItem.jobState === NotificationManager.Notifications.JobStateStopped | ||||
195 | PropertyChanges { | ||||
196 | target: jobActionsRow | ||||
197 | visible: false | ||||
198 | } | ||||
199 | PropertyChanges { | ||||
200 | target: expandButton | ||||
201 | checked: false | ||||
202 | } | ||||
203 | } | ||||
204 | ] | ||||
205 | } |