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 jobError | ||||
37 | | ||||
38 | property alias percentage: progressBar.value | ||||
39 | property alias suspendable: suspendButton.visible | ||||
40 | property alias killable: killButton.visible | ||||
41 | | ||||
42 | property bool hovered | ||||
43 | property QtObject jobDetails | ||||
44 | // TOOD make an alias on visible if we're not doing an animation | ||||
45 | property bool showDetails | ||||
46 | | ||||
47 | readonly property alias menuOpen: otherFileActionsMenu.visible | ||||
48 | | ||||
49 | signal suspendJobClicked | ||||
50 | signal resumeJobClicked | ||||
51 | signal killJobClicked | ||||
52 | | ||||
53 | signal openUrl(string url) | ||||
54 | signal fileActionInvoked | ||||
55 | | ||||
56 | spacing: 0 | ||||
57 | | ||||
58 | RowLayout { | ||||
59 | id: progressRow | ||||
60 | Layout.fillWidth: true | ||||
61 | spacing: units.smallSpacing | ||||
62 | | ||||
63 | PlasmaComponents.ProgressBar { | ||||
64 | id: progressBar | ||||
65 | Layout.fillWidth: true | ||||
66 | minimumValue: 0 | ||||
67 | maximumValue: 100 | ||||
68 | // TODO do we actually need the window visible check? perhaps I do because it can be in popup or expanded plasmoid | ||||
69 | indeterminate: visible && Window.window && Window.window.visible && percentage < 1 | ||||
70 | && jobItem.jobState === NotificationManager.Notifications.JobStateRunning | ||||
71 | // is this too annoying? | ||||
72 | && (jobItem.jobDetails.processedBytes === 0 || jobItem.jobDetails.totalBytes === 0) | ||||
73 | && jobItem.jobDetails.processedFiles === 0 | ||||
74 | //&& jobItem.jobDetails.processedDirectories === 0 | ||||
75 | } | ||||
76 | | ||||
77 | RowLayout { | ||||
78 | spacing: 0 | ||||
79 | | ||||
80 | PlasmaComponents.ToolButton { | ||||
81 | id: suspendButton | ||||
82 | tooltip: i18nc("Pause running job", "Pause") | ||||
83 | iconSource: "media-playback-pause" | ||||
84 | onClicked: jobItem.jobState === NotificationManager.Notifications.JobStateSuspended ? jobItem.resumeJobClicked() | ||||
85 | : jobItem.suspendJobClicked() | ||||
86 | } | ||||
87 | | ||||
88 | PlasmaComponents.ToolButton { | ||||
89 | id: killButton | ||||
90 | tooltip: i18nc("Cancel running job", "Cancel") | ||||
91 | iconSource: "media-playback-stop" | ||||
92 | onClicked: jobItem.killJobClicked() | ||||
93 | } | ||||
94 | | ||||
95 | PlasmaComponents.ToolButton { | ||||
96 | id: expandButton | ||||
97 | Layout.leftMargin: units.smallSpacing | ||||
98 | iconSource: checked ? "arrow-down" : (LayoutMirroring.enabled ? "arrow-left" : "arrow-right") | ||||
99 | tooltip: checked ? i18nc("A button tooltip; hides item details", "Hide Details") | ||||
100 | : i18nc("A button tooltip; expands the item to show details", "Show Details") | ||||
101 | checkable: true | ||||
102 | enabled: jobItem.jobDetails && jobItem.jobDetails.hasDetails | ||||
103 | } | ||||
104 | } | ||||
105 | } | ||||
106 | | ||||
107 | Loader { | ||||
108 | Layout.fillWidth: true | ||||
109 | active: expandButton.checked | ||||
110 | // Loader doesn't reset its height when unloaded, just hide it altogether | ||||
111 | visible: active | ||||
112 | sourceComponent: JobDetails { | ||||
113 | jobDetails: jobItem.jobDetails | ||||
114 | } | ||||
115 | } | ||||
116 | | ||||
117 | Flow { // it's a Flow so it can wrap if too long | ||||
118 | id: jobDoneActions | ||||
119 | Layout.fillWidth: true | ||||
120 | spacing: units.smallSpacing | ||||
121 | // We want the actions to be right-aligned but Flow also reverses | ||||
122 | // the order of items, so we put them in reverse order | ||||
123 | layoutDirection: Qt.RightToLeft | ||||
124 | visible: url && url.toString() !== "" | ||||
125 | | ||||
126 | property var url: { | ||||
127 | if (jobItem.jobState !== NotificationManager.Notifications.JobStateStopped | ||||
128 | || jobItem.jobError | ||||
129 | || !jobItem.jobDetails | ||||
130 | || jobItem.jobDetails.totalFiles <= 0) { | ||||
131 | return null; | ||||
132 | } | ||||
133 | | ||||
134 | // For a single file show actions for it | ||||
135 | if (jobItem.jobDetails.totalFiles === 1) { | ||||
136 | return jobItem.jobDetails.descriptionUrl; | ||||
137 | } else { | ||||
138 | return jobItem.jobDetails.destUrl; | ||||
139 | } | ||||
140 | } | ||||
141 | | ||||
142 | PlasmaComponents.Button { | ||||
143 | id: otherFileActionsButton | ||||
144 | iconName: "application-menu" | ||||
145 | tooltip: i18n("More Options...") | ||||
146 | checkable: true | ||||
147 | onPressedChanged: { | ||||
148 | if (pressed) { | ||||
149 | checked = Qt.binding(function() { | ||||
150 | return otherFileActionsMenu.visible; | ||||
151 | }); | ||||
152 | otherFileActionsMenu.open(-1, -1); | ||||
153 | } | ||||
154 | } | ||||
155 | | ||||
156 | Notifications.FileMenu { | ||||
157 | id: otherFileActionsMenu | ||||
158 | url: jobDoneActions.url || "" | ||||
159 | visualParent: otherFileActionsButton | ||||
160 | onActionTriggered: jobItem.fileActionInvoked() | ||||
161 | } | ||||
162 | } | ||||
163 | | ||||
164 | PlasmaComponents.Button { | ||||
165 | // would be nice to have the file icon here? | ||||
166 | text: jobItem.jobDetails && jobItem.jobDetails.totalFiles > 1 ? i18n("Open Containing Folder") : i18n("Open") | ||||
167 | onClicked: jobItem.openUrl(jobDoneActions.url) | ||||
168 | width: minimumWidth | ||||
169 | } | ||||
170 | } | ||||
171 | | ||||
172 | states: [ | ||||
173 | State { | ||||
174 | when: jobItem.jobState === NotificationManager.Notifications.JobStateSuspended | ||||
175 | PropertyChanges { | ||||
176 | target: suspendButton | ||||
177 | tooltip: i18nc("Resume paused job", "Resume") | ||||
178 | iconSource: "media-playback-start" | ||||
179 | } | ||||
180 | PropertyChanges { | ||||
181 | target: progressBar | ||||
182 | enabled: false | ||||
183 | } | ||||
184 | }, | ||||
185 | State { | ||||
186 | when: jobItem.jobState === NotificationManager.Notifications.JobStateStopped | ||||
187 | PropertyChanges { | ||||
188 | target: progressRow | ||||
189 | visible: false | ||||
190 | } | ||||
191 | PropertyChanges { | ||||
192 | target: expandButton | ||||
193 | checked: false | ||||
194 | } | ||||
195 | } | ||||
196 | ] | ||||
197 | } |