Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/JobDetails.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.Layouts 1.1 | ||||
23 | | ||||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
25 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
26 | | ||||
27 | import org.kde.kcoreaddons 1.0 as KCoreAddons | ||||
28 | | ||||
29 | import org.kde.notificationmanager 1.0 as NotificationManager | ||||
30 | | ||||
31 | GridLayout { | ||||
32 | id: detailsGrid | ||||
33 | | ||||
34 | property QtObject jobDetails | ||||
35 | | ||||
36 | columns: 2 | ||||
37 | rowSpacing: Math.round(units.smallSpacing / 2) | ||||
38 | columnSpacing: units.smallSpacing | ||||
39 | | ||||
40 | // once you use Layout.column/Layout.row *all* of the items in the Layout have to use them | ||||
41 | Repeater { | ||||
42 | model: [1, 2] | ||||
43 | | ||||
44 | PlasmaExtras.DescriptiveLabel { | ||||
45 | Layout.column: 0 | ||||
46 | Layout.row: index | ||||
47 | Layout.alignment: Qt.AlignTop | Qt.AlignRight | ||||
48 | text: jobDetails["descriptionLabel" + modelData] && jobDetails["descriptionValue" + modelData] | ||||
49 | ? i18nc("Row description, e.g. Source", "%1:", jobDetails["descriptionLabel" + modelData]) : "" | ||||
50 | font: theme.smallestFont | ||||
51 | textFormat: Text.PlainText | ||||
52 | visible: text !== "" | ||||
53 | } | ||||
54 | } | ||||
55 | | ||||
56 | Repeater { | ||||
57 | model: [1, 2] | ||||
58 | | ||||
59 | PlasmaExtras.DescriptiveLabel { | ||||
60 | id: descriptionValueLabel | ||||
61 | Layout.column: 1 | ||||
62 | Layout.row: index | ||||
63 | Layout.fillWidth: true | ||||
64 | font: theme.smallestFont | ||||
65 | elide: Text.ElideMiddle | ||||
66 | textFormat: Text.PlainText | ||||
67 | wrapMode: Text.WrapAtWordBoundaryOrAnywhere | ||||
68 | maximumLineCount: 5 | ||||
69 | visible: text !== "" | ||||
70 | | ||||
71 | Component.onCompleted: bindText() | ||||
72 | function bindText() { | ||||
73 | text = Qt.binding(function() { | ||||
74 | return jobDetails["descriptionLabel" + modelData] && jobDetails["descriptionValue" + modelData] | ||||
75 | ? jobDetails["descriptionValue" + modelData] : ""; | ||||
76 | }); | ||||
77 | } | ||||
78 | | ||||
79 | MouseArea { | ||||
80 | anchors.fill: parent | ||||
81 | acceptedButtons: Qt.RightButton | ||||
82 | onPressed: { | ||||
83 | // break binding so it doesn't update while the menu is opened | ||||
84 | descriptionValueLabel.text = descriptionValueLabel.text; | ||||
85 | descriptionValueMenu.open(mouse.x, mouse.y) | ||||
86 | } | ||||
87 | } | ||||
88 | | ||||
89 | EditContextMenu { | ||||
90 | id: descriptionValueMenu | ||||
91 | target: descriptionValueLabel | ||||
92 | // defer re-binding until after the "Copy" action in the menu has triggered | ||||
93 | onClosed: Qt.callLater(descriptionValueLabel.bindText) | ||||
94 | } | ||||
95 | } | ||||
96 | } | ||||
97 | | ||||
98 | Repeater { | ||||
99 | model: ["Bytes", "Files", "Directories"] | ||||
100 | | ||||
101 | PlasmaExtras.DescriptiveLabel { | ||||
102 | Layout.column: 1 | ||||
103 | Layout.row: 2 + index | ||||
104 | Layout.fillWidth: true | ||||
105 | text: { | ||||
106 | var processed = jobDetails["processed" + modelData]; | ||||
107 | var total = jobDetails["total" + modelData]; | ||||
108 | | ||||
109 | if (processed > 0 || total > 1) { | ||||
110 | if (processed > 0 && total > 0 && processed <= total) { | ||||
111 | switch(modelData) { | ||||
112 | case "Bytes": | ||||
113 | return i18nc("How many bytes have been copied", "%2 of %1", | ||||
114 | KCoreAddons.Format.formatByteSize(total), | ||||
115 | KCoreAddons.Format.formatByteSize(processed)) | ||||
116 | case "Files": | ||||
117 | return i18ncp("How many files have been copied", "%2 of %1 file", "%2 of %1 files", | ||||
118 | total, processed); | ||||
119 | case "Directories": | ||||
120 | return i18ncp("How many dirs have been copied", "%2 of %1 folder", "%2 of %1 folders", | ||||
121 | total, processed); | ||||
122 | } | ||||
123 | } else { | ||||
124 | switch(modelData) { | ||||
125 | case "Bytes": | ||||
126 | return KCoreAddons.Format.formatByteSize(processed || total) | ||||
127 | case "Files": | ||||
128 | return i18np("%1 file", "%1 files", (processed || total)); | ||||
129 | case "Directories": | ||||
130 | return i18np("%1 folder", "%1 folders", (processed || total)); | ||||
131 | } | ||||
132 | } | ||||
133 | } | ||||
134 | | ||||
135 | return ""; | ||||
136 | } | ||||
137 | font: theme.smallestFont | ||||
138 | textFormat: Text.PlainText | ||||
139 | visible: text !== "" | ||||
140 | } | ||||
141 | } | ||||
142 | | ||||
143 | PlasmaExtras.DescriptiveLabel { | ||||
144 | Layout.column: 1 | ||||
145 | Layout.row: 2 + 3 | ||||
146 | Layout.fillWidth: true | ||||
147 | text: jobDetails.speed > 0 ? i18nc("Bytes per second", "%1/s", | ||||
148 | KCoreAddons.Format.formatByteSize(jobDetails.speed)) : "" | ||||
149 | font: theme.smallestFont | ||||
150 | textFormat: Text.PlainText | ||||
151 | visible: text !== "" | ||||
152 | } | ||||
153 | } |