]>
Commit | Line | Data |
---|---|---|
934ea3d9 AM |
1 | diff --git a/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp b/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp |
2 | index d1b9519..a79f5ab 100644 | |
3 | --- a/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp | |
4 | +++ b/plasma/generic/dataengines/powermanagement/powermanagementengine.cpp | |
5 | @@ -115,27 +115,31 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name) | |
6 | foreach (const Solid::Device &deviceBattery, listBattery) { | |
7 | const Solid::Battery* battery = deviceBattery.as<Solid::Battery>(); | |
8 | ||
9 | - if (battery && (battery->type() == Solid::Battery::PrimaryBattery || | |
10 | - battery->type() == Solid::Battery::UpsBattery)) { | |
11 | - const QString source = QString("Battery%1").arg(index++); | |
12 | - | |
13 | - batterySources << source; | |
14 | - m_batterySources[deviceBattery.udi()] = source; | |
15 | - | |
16 | - connect(battery, SIGNAL(chargeStateChanged(int,QString)), this, | |
17 | - SLOT(updateBatteryChargeState(int,QString))); | |
18 | - connect(battery, SIGNAL(chargePercentChanged(int,QString)), this, | |
19 | - SLOT(updateBatteryChargePercent(int,QString))); | |
20 | - connect(battery, SIGNAL(plugStateChanged(bool,QString)), this, | |
21 | - SLOT(updateBatteryPlugState(bool,QString))); | |
22 | - | |
23 | - // Set initial values | |
24 | - updateBatteryChargeState(battery->chargeState(), deviceBattery.udi()); | |
25 | - updateBatteryChargePercent(battery->chargePercent(), deviceBattery.udi()); | |
26 | - updateBatteryPlugState(battery->isPlugged(), deviceBattery.udi()); | |
27 | - } | |
28 | + const QString source = QString("Battery%1").arg(index++); | |
29 | + | |
30 | + batterySources << source; | |
31 | + m_batterySources[deviceBattery.udi()] = source; | |
32 | + | |
33 | + connect(battery, SIGNAL(chargeStateChanged(int,QString)), this, | |
34 | + SLOT(updateBatteryChargeState(int,QString))); | |
35 | + connect(battery, SIGNAL(chargePercentChanged(int,QString)), this, | |
36 | + SLOT(updateBatteryChargePercent(int,QString))); | |
37 | + connect(battery, SIGNAL(plugStateChanged(bool,QString)), this, | |
38 | + SLOT(updateBatteryPlugState(bool,QString))); | |
39 | + | |
40 | + // Set initial values | |
41 | + updateBatteryChargeState(battery->chargeState(), deviceBattery.udi()); | |
42 | + updateBatteryChargePercent(battery->chargePercent(), deviceBattery.udi()); | |
43 | + updateBatteryPlugState(battery->isPlugged(), deviceBattery.udi()); | |
44 | + updateBatteryPowerSupplyState(battery->isPowerSupply(), deviceBattery.udi()); | |
45 | + | |
46 | + setData(source, "Vendor", deviceBattery.vendor()); | |
47 | + setData(source, "Product", deviceBattery.product()); | |
48 | + setData(source, "Type", batteryType(battery)); | |
49 | } | |
50 | ||
51 | + updateBatteryNames(); | |
52 | + | |
53 | setData("Battery", "Has Battery", !batterySources.isEmpty()); | |
54 | if (!batterySources.isEmpty()) { | |
55 | setData("Battery", "Sources", batterySources); | |
56 | @@ -199,6 +203,37 @@ bool PowermanagementEngine::sourceRequestEvent(const QString &name) | |
57 | return true; | |
58 | } | |
59 | ||
60 | +QString PowermanagementEngine::batteryType(const Solid::Battery* battery) | |
61 | +{ | |
62 | + switch(battery->type()) { | |
63 | + case Solid::Battery::PrimaryBattery: | |
64 | + return QString("Battery"); | |
65 | + break; | |
66 | + case Solid::Battery::UpsBattery: | |
67 | + return QString("Ups"); | |
68 | + break; | |
69 | + case Solid::Battery::MonitorBattery: | |
70 | + return QString("Monitor"); | |
71 | + break; | |
72 | + case Solid::Battery::MouseBattery: | |
73 | + return QString("Mouse"); | |
74 | + break; | |
75 | + case Solid::Battery::KeyboardBattery: | |
76 | + return QString("Keyboad"); | |
77 | + break; | |
78 | + case Solid::Battery::PdaBattery: | |
79 | + return QString("Pda"); | |
80 | + break; | |
81 | + case Solid::Battery::PhoneBattery: | |
82 | + return QString("Phone"); | |
83 | + break; | |
84 | + default: | |
85 | + return QString("Unknown"); | |
86 | + } | |
87 | + | |
88 | + return QString("Unknown"); | |
89 | +} | |
90 | + | |
91 | bool PowermanagementEngine::updateSourceEvent(const QString &source) | |
92 | { | |
93 | if (source == "UserActivity") { | |
94 | @@ -244,6 +279,38 @@ void PowermanagementEngine::updateBatteryChargePercent(int newValue, const QStri | |
95 | setData(source, "Percent", newValue); | |
96 | } | |
97 | ||
98 | +void PowermanagementEngine::updateBatteryPowerSupplyState(bool newState, const QString& udi) | |
99 | +{ | |
100 | + const QString source = m_batterySources[udi]; | |
101 | + setData(source, "Is Power Supply", newState); | |
102 | +} | |
103 | + | |
104 | +void PowermanagementEngine::updateBatteryNames() | |
105 | +{ | |
106 | + uint unnamedBatteries = 0; | |
107 | + foreach (QString source, m_batterySources) { | |
108 | + DataContainer *batteryDataContainer = containerForSource(source); | |
109 | + if (batteryDataContainer) { | |
110 | + const QString batteryVendor = batteryDataContainer->data()["Vendor"].toString(); | |
111 | + const QString batteryProduct = batteryDataContainer->data()["Product"].toString(); | |
112 | + if (!batteryProduct.isEmpty() && batteryProduct != "Unknown Battery") { | |
113 | + if (!batteryVendor.isEmpty()) { | |
114 | + setData(source, "Pretty Name", QString(batteryVendor + ' ' + batteryProduct)); | |
115 | + } else { | |
116 | + setData(source, "Pretty Name", batteryProduct); | |
117 | + } | |
118 | + } else { | |
119 | + ++unnamedBatteries; | |
120 | + if (unnamedBatteries > 1) { | |
121 | + setData(source, "Pretty Name", i18nc("Placeholder is the battery number", "Battery %1", unnamedBatteries)); | |
122 | + } else { | |
123 | + setData(source, "Pretty Name", i18n("Battery")); | |
124 | + } | |
125 | + } | |
126 | + } | |
127 | + } | |
128 | +} | |
129 | + | |
130 | void PowermanagementEngine::updateAcPlugState(bool newState) | |
131 | { | |
132 | setData("AC Adapter", "Plugged in", newState); | |
133 | @@ -292,14 +359,23 @@ void PowermanagementEngine::deviceAdded(const QString& udi) | |
134 | SLOT(updateBatteryChargePercent(int,QString))); | |
135 | connect(battery, SIGNAL(plugStateChanged(bool,QString)), this, | |
136 | SLOT(updateBatteryPlugState(bool,QString))); | |
137 | + connect(battery, SIGNAL(powerSupplyStateChanged(bool,QString)), this, | |
138 | + SLOT(updateBatteryPowerSupplyState(bool,QString))); | |
139 | ||
140 | // Set initial values | |
141 | updateBatteryChargeState(battery->chargeState(), device.udi()); | |
142 | updateBatteryChargePercent(battery->chargePercent(), device.udi()); | |
143 | updateBatteryPlugState(battery->isPlugged(), device.udi()); | |
144 | + updateBatteryPowerSupplyState(battery->isPowerSupply(), device.udi()); | |
145 | + | |
146 | + setData(source, "Vendor", device.vendor()); | |
147 | + setData(source, "Product", device.product()); | |
148 | + setData(source, "Type", batteryType(battery)); | |
149 | ||
150 | setData("Battery", "Sources", sourceNames); | |
151 | setData("Battery", "Has Battery", !sourceNames.isEmpty()); | |
152 | + | |
153 | + updateBatteryNames(); | |
154 | } | |
155 | } | |
156 | } | |
157 | diff --git a/plasma/generic/dataengines/powermanagement/powermanagementengine.h b/plasma/generic/dataengines/powermanagement/powermanagementengine.h | |
158 | index 35e9ecf..319a17c 100644 | |
159 | --- a/plasma/generic/dataengines/powermanagement/powermanagementengine.h | |
160 | +++ b/plasma/generic/dataengines/powermanagement/powermanagementengine.h | |
161 | @@ -54,7 +54,10 @@ private slots: | |
162 | void updateBatteryChargeState(int newState, const QString& udi); | |
163 | void updateBatteryPlugState(bool newState, const QString& udi); | |
164 | void updateBatteryChargePercent(int newValue, const QString& udi); | |
165 | + void updateBatteryPowerSupplyState(bool newState, const QString& udi); | |
166 | void updateAcPlugState(bool newState); | |
167 | + void updateBatteryNames(); | |
168 | + | |
169 | void deviceRemoved(const QString& udi); | |
170 | void deviceAdded(const QString& udi); | |
171 | void batteryRemainingTimeChanged(qulonglong time); | |
172 | @@ -64,6 +67,7 @@ private slots: | |
173 | void brightnessControlsAvailableChanged(bool available); | |
174 | ||
175 | private: | |
176 | + QString batteryType(const Solid::Battery *battery); | |
177 | QStringList basicSourceNames() const; | |
178 | ||
179 | QStringList m_sources; | |
180 | diff --git a/plasma/generic/applets/batterymonitor/contents/code/logic.js b/plasma/generic/applets/batterymonitor/contents/code/logic.js | |
181 | index 974694a..34a5060 100644 | |
182 | --- a/plasma/generic/applets/batterymonitor/contents/code/logic.js | |
183 | +++ b/plasma/generic/applets/batterymonitor/contents/code/logic.js | |
184 | @@ -23,19 +23,24 @@ var disk = 1 | |
185 | ||
186 | function updateCumulative() { | |
187 | var sum = 0; | |
188 | + var count = 0; | |
189 | var charged = true; | |
190 | for (var i=0; i<batteries.count; i++) { | |
191 | var b = batteries.get(i); | |
192 | + if (!b["Is Power Supply"]) { | |
193 | + continue; | |
194 | + } | |
195 | if (b["Plugged in"]) { | |
196 | sum += b["Percent"]; | |
197 | } | |
198 | if (b["State"] != "NoCharge") { | |
199 | charged = false; | |
200 | } | |
201 | + count++; | |
202 | } | |
203 | ||
204 | if (batteries.count > 0) { | |
205 | - batteries.cumulativePercent = Math.round(sum/batteries.count); | |
206 | + batteries.cumulativePercent = Math.round(sum/count); | |
207 | } else { | |
208 | batteries.cumulativePercent = 0; | |
209 | } | |
210 | @@ -46,34 +51,40 @@ function stringForState(batteryData) { | |
211 | var pluggedIn = batteryData["Plugged in"]; | |
212 | var percent = batteryData["Percent"]; | |
213 | var state = batteryData["State"]; | |
214 | + var powerSupply = batteryData["Is Power Supply"]; | |
215 | ||
216 | + var text="<b>"; | |
217 | if (pluggedIn) { | |
218 | - if (state == "NoCharge") { | |
219 | - return i18n("<b>%1% (charged)</b>", percent); | |
220 | - } else if (state == "Discharging") { | |
221 | - return i18n("<b>%1% (discharging)</b>", percent); | |
222 | - } else {//charging | |
223 | - return i18n("<b>%1% (charging)</b>", percent); | |
224 | + // According to UPower spec, the chargeState is only valid for primary batteries | |
225 | + if (powerSupply) { | |
226 | + switch(state) { | |
227 | + case "NoCharge": text += i18n("%1% (charged)", percent); break; | |
228 | + case "Discharging": text += i18n("%1% (discharging)", percent); break; | |
229 | + default: text += i18n("%1% (charging)", percent); | |
230 | + } | |
231 | + } else { | |
232 | + text += i18n("%1%", percent); | |
233 | } | |
234 | + } else { | |
235 | + text += i18nc("Battery is not plugged in", "Not present"); | |
236 | } | |
237 | + text += "</b>"; | |
238 | ||
239 | - return i18nc("Battery is not plugged in", "<b>Not present</b>"); | |
240 | + return text; | |
241 | } | |
242 | ||
243 | function updateTooltip() { | |
244 | var text=""; | |
245 | - for (var i=0; i<batteries.count; i++) { | |
246 | - if (batteries.count == 1) { | |
247 | - text += i18n("Battery:"); | |
248 | - } else { | |
249 | - if (text != "") { | |
250 | - text += "<br/>"; | |
251 | - } | |
252 | ||
253 | - text += i18nc("tooltip: placeholder is the battery ID", "Battery %1:", i+1); | |
254 | + for (var i=0; i<batteries.count; i++) { | |
255 | + var b = batteries.get(i); | |
256 | + if (text != "") { | |
257 | + text += "<br/>"; | |
258 | } | |
259 | ||
260 | - text += " "; | |
261 | + text += b["Pretty Name"]; | |
262 | + | |
263 | + text += ": "; | |
264 | text += stringForState(pmSource.data["Battery"+i]); | |
265 | } | |
266 | ||
267 | diff --git a/plasma/generic/applets/batterymonitor/contents/config/main.xml b/plasma/generic/applets/batterymonitor/contents/config/main.xml | |
268 | index fc31b3e..28e4a8a 100644 | |
269 | --- a/plasma/generic/applets/batterymonitor/contents/config/main.xml | |
270 | +++ b/plasma/generic/applets/batterymonitor/contents/config/main.xml | |
271 | @@ -9,9 +9,6 @@ | |
272 | <entry name="showBatteryString" type="Bool"> | |
273 | <default>false</default> | |
274 | </entry> | |
275 | - <entry name="showMultipleBatteries" type="Bool"> | |
276 | - <default>false</default> | |
277 | - </entry> | |
278 | <entry name="showRemainingTime" type="Bool"> | |
279 | <default>false</default> | |
280 | </entry> | |
281 | diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml | |
282 | index 3ffb15f..bd9f491 100644 | |
283 | --- a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml | |
284 | +++ b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml | |
285 | @@ -52,7 +52,7 @@ Item { | |
286 | Repeater { | |
287 | model: dialog.model | |
288 | Components.Label { | |
289 | - text: model.count>1 ? i18nc("Placeholder is the battery ID", "Battery %1:", index+1) : i18n("Battery:") | |
290 | + text: model["Pretty Name"] + ':' | |
291 | width: labels.width | |
292 | horizontalAlignment: Text.AlignRight | |
293 | } | |
294 | diff --git a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml | |
295 | index c69c3a5..3a58aae 100644 | |
296 | --- a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml | |
297 | +++ b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml | |
298 | @@ -49,13 +49,12 @@ Item { | |
299 | property int minimumHeight | |
300 | ||
301 | property bool showOverlay: false | |
302 | - property bool showMultipleBatteries: false | |
303 | property bool hasBattery: pmSource.data["Battery"]["Has Battery"] | |
304 | ||
305 | property QtObject pmSource: plasmoid.rootItem.pmSource | |
306 | property QtObject batteries: plasmoid.rootItem.batteries | |
307 | ||
308 | - property bool singleBattery: isConstrained() || !showMultipleBatteries || !hasBattery | |
309 | + property bool singleBattery: isConstrained() || !hasBattery | |
310 | ||
311 | model: singleBattery ? 1 : batteries | |
312 | ||
313 | @@ -63,6 +62,7 @@ Item { | |
314 | ||
315 | anchors.fill: parent | |
316 | orientation: ListView.Horizontal | |
317 | + interactive: false | |
318 | ||
319 | function isConstrained() { | |
320 | return (plasmoid.formFactor == Vertical || plasmoid.formFactor == Horizontal); | |
321 | @@ -78,7 +78,6 @@ Item { | |
322 | ||
323 | function configChanged() { | |
324 | showOverlay = plasmoid.readConfig("showBatteryString"); | |
325 | - showMultipleBatteries = plasmoid.readConfig("showMultipleBatteries"); | |
326 | } | |
327 | ||
328 | delegate: Item { | |
329 | diff --git a/plasma/generic/applets/batterymonitor/contents/ui/config.ui b/plasma/generic/applets/batterymonitor/contents/ui/config.ui | |
330 | index 3df38e2..bffc755 100644 | |
331 | --- a/plasma/generic/applets/batterymonitor/contents/ui/config.ui | |
332 | +++ b/plasma/generic/applets/batterymonitor/contents/ui/config.ui | |
333 | @@ -25,16 +25,6 @@ | |
334 | </widget> | |
335 | </item> | |
336 | <item> | |
337 | - <widget class="QCheckBox" name="kcfg_showMultipleBatteries"> | |
338 | - <property name="toolTip"> | |
339 | - <string/> | |
340 | - </property> | |
341 | - <property name="text"> | |
342 | - <string>Show the state for &each battery present</string> | |
343 | - </property> | |
344 | - </widget> | |
345 | - </item> | |
346 | - <item> | |
347 | <spacer name="verticalSpacer"> | |
348 | <property name="orientation"> | |
349 | <enum>Qt::Vertical</enum> | |
a0f83d4a AM |
350 | From: Kai Uwe Broulik <kde@privat.broulik.de> |
351 | Date: Mon, 20 May 2013 19:52:21 +0000 | |
352 | Subject: No linebreak in tooltip. We do them manually anyways. | |
353 | X-Git-Url: http://quickgit.kde.org/?p=kde-workspace.git&a=commitdiff&h=175e902b88a2c6a1c1ca37f428208e83c1660937 | |
354 | --- | |
355 | No linebreak in tooltip. We do them manually anyways. | |
356 | ||
357 | CCBUG: 317404 | |
358 | --- | |
359 | ||
360 | ||
361 | --- a/plasma/generic/applets/batterymonitor/contents/code/logic.js | |
362 | +++ b/plasma/generic/applets/batterymonitor/contents/code/logic.js | |
363 | @@ -96,7 +96,7 @@ | |
364 | text += i18nc("tooltip", "AC Adapter:") + " "; | |
365 | text += pmSource.data["AC Adapter"]["Plugged in"] ? i18nc("tooltip", "<b>Plugged in</b>") : i18nc("tooltip", "<b>Not plugged in</b>"); | |
366 | } | |
367 | - batteries.tooltipText = text; | |
368 | + batteries.tooltipText = "<p style='white-space: nowrap'>" + text + "</p>"; | |
369 | } | |
370 | ||
371 | function updateBrightness() { | |
372 |