Merge lp:~fourdollars/indicator-power/xenial into lp:indicator-power

Proposed by Shih-Yuan Lee
Status: Superseded
Proposed branch: lp:~fourdollars/indicator-power/xenial
Merge into: lp:indicator-power
Diff against target: 464 lines (+158/-20) (has conflicts)
7 files modified
src/device-provider-upower.c (+5/-1)
src/device.c (+37/-5)
src/device.h (+4/-1)
src/service.c (+18/-6)
src/testing.c (+2/-1)
tests/test-device.cc (+86/-3)
tests/test-notify.cc (+6/-3)
Text conflict in tests/test-device.cc
To merge this branch: bzr merge lp:~fourdollars/indicator-power/xenial
Reviewer Review Type Date Requested Status
Indicator Applet Developers Pending
Review via email: mp+314125@code.launchpad.net

This proposal has been superseded by a proposal from 2017-01-05.

To post a comment you must log in.

Unmerged revisions

293. By Shih-Yuan Lee

Make device with power supply has higher sorting priority. (LP: #1100546)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/device-provider-upower.c'
2--- src/device-provider-upower.c 2014-09-08 14:50:22 +0000
3+++ src/device-provider-upower.c 2017-01-05 04:46:40 +0000
4@@ -113,6 +113,7 @@
5 gint64 time_to_empty = 0;
6 gint64 time_to_full = 0;
7 gint64 time;
8+ gboolean power_supply = FALSE;
9 IndicatorPowerDevice * device;
10 priv_t * p = get_priv(data->self);
11 GVariant * dict = g_variant_get_child_value (response, 0);
12@@ -122,6 +123,7 @@
13 g_variant_lookup (dict, "Percentage", "d", &percentage);
14 g_variant_lookup (dict, "TimeToEmpty", "x", &time_to_empty);
15 g_variant_lookup (dict, "TimeToFull", "x", &time_to_full);
16+ g_variant_lookup (dict, "PowerSupply", "b", &power_supply);
17 time = time_to_empty ? time_to_empty : time_to_full;
18
19 if ((device = g_hash_table_lookup (p->devices, data->path)))
20@@ -131,6 +133,7 @@
21 INDICATOR_POWER_DEVICE_OBJECT_PATH, data->path,
22 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
23 INDICATOR_POWER_DEVICE_TIME, time,
24+ INDICATOR_POWER_DEVICE_POWER_SUPPLY, power_supply,
25 NULL);
26 }
27 else
28@@ -139,7 +142,8 @@
29 kind,
30 percentage,
31 state,
32- (time_t)time);
33+ (time_t)time,
34+ power_supply);
35
36 g_hash_table_insert (p->devices,
37 g_strdup (data->path),
38
39=== modified file 'src/device.c'
40--- src/device.c 2016-05-26 18:32:08 +0000
41+++ src/device.c 2017-01-05 04:46:40 +0000
42@@ -42,6 +42,7 @@
43 the time-remaining field for this device, or 0 if not applicable.
44 This is used when generating the time-remaining string. */
45 GTimer * inestimable;
46+ gboolean power_supply;
47 };
48
49 /* Properties */
50@@ -53,6 +54,7 @@
51 PROP_OBJECT_PATH,
52 PROP_PERCENTAGE,
53 PROP_TIME,
54+ PROP_POWER_SUPPLY,
55 N_PROPERTIES
56 };
57
58@@ -116,6 +118,12 @@
59 0,
60 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
61
62+ properties[PROP_POWER_SUPPLY] = g_param_spec_boolean (INDICATOR_POWER_DEVICE_POWER_SUPPLY,
63+ "power supply",
64+ "The device's power supply",
65+ FALSE,
66+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
67+
68 g_object_class_install_properties (object_class, N_PROPERTIES, properties);
69 }
70
71@@ -132,6 +140,7 @@
72 priv->object_path = NULL;
73 priv->percentage = 0.0;
74 priv->time = 0;
75+ priv->power_supply = FALSE;
76
77 self->priv = priv;
78 }
79@@ -190,6 +199,10 @@
80 g_value_set_uint64 (value, (guint64)priv->time);
81 break;
82
83+ case PROP_POWER_SUPPLY:
84+ g_value_set_boolean (value, priv->power_supply);
85+ break;
86+
87 default:
88 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);
89 break;
90@@ -225,6 +238,10 @@
91 p->time = (time_t) g_value_get_uint64(value);
92 break;
93
94+ case PROP_POWER_SUPPLY:
95+ p->power_supply = g_value_get_boolean (value);
96+ break;
97+
98 default:
99 G_OBJECT_WARN_INVALID_PROPERTY_ID(o, prop_id, pspec);
100 break;
101@@ -304,6 +321,16 @@
102 return device->priv->time;
103 }
104
105+gboolean
106+indicator_power_device_get_power_supply (const IndicatorPowerDevice * device)
107+{
108+ /* LCOV_EXCL_START */
109+ g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), FALSE);
110+ /* LCOV_EXCL_STOP */
111+
112+ return device->priv->power_supply;
113+}
114+
115 /***
116 ****
117 ****
118@@ -867,7 +894,8 @@
119 UpDeviceKind kind,
120 gdouble percentage,
121 UpDeviceState state,
122- time_t timestamp)
123+ time_t timestamp,
124+ gboolean power_supply)
125 {
126 GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE,
127 INDICATOR_POWER_DEVICE_KIND, kind,
128@@ -875,6 +903,7 @@
129 INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path,
130 INDICATOR_POWER_DEVICE_PERCENTAGE, percentage,
131 INDICATOR_POWER_DEVICE_TIME, (guint64)timestamp,
132+ INDICATOR_POWER_DEVICE_POWER_SUPPLY, power_supply,
133 NULL);
134 return INDICATOR_POWER_DEVICE(o);
135 }
136@@ -882,7 +911,7 @@
137 IndicatorPowerDevice *
138 indicator_power_device_new_from_variant (GVariant * v)
139 {
140- g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdut)")), NULL);
141+ g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdutb)")), NULL);
142
143 UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN;
144 UpDeviceState state = UP_DEVICE_STATE_UNKNOWN;
145@@ -890,18 +919,21 @@
146 const gchar * object_path = NULL;
147 gdouble percentage = 0;
148 guint64 time = 0;
149+ gboolean power_supply = FALSE;
150
151- g_variant_get (v, "(&su&sdut)",
152+ g_variant_get (v, "(&su&sdutb)",
153 &object_path,
154 &kind,
155 &icon,
156 &percentage,
157 &state,
158- &time);
159+ &time,
160+ &power_supply);
161
162 return indicator_power_device_new (object_path,
163 kind,
164 percentage,
165 state,
166- (time_t)time);
167+ (time_t)time,
168+ power_supply);
169 }
170
171=== modified file 'src/device.h'
172--- src/device.h 2014-07-24 20:20:16 +0000
173+++ src/device.h 2017-01-05 04:46:40 +0000
174@@ -44,6 +44,7 @@
175 #define INDICATOR_POWER_DEVICE_OBJECT_PATH "object-path"
176 #define INDICATOR_POWER_DEVICE_PERCENTAGE "percentage"
177 #define INDICATOR_POWER_DEVICE_TIME "time"
178+#define INDICATOR_POWER_DEVICE_POWER_SUPPLY "power-supply"
179
180 typedef enum
181 {
182@@ -107,7 +108,8 @@
183 UpDeviceKind kind,
184 gdouble percentage,
185 UpDeviceState state,
186- time_t time);
187+ time_t time,
188+ gboolean power_supply);
189
190 /**
191 * Convenience wrapper around indicator_power_device_new()
192@@ -121,6 +123,7 @@
193 const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device);
194 gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device);
195 time_t indicator_power_device_get_time (const IndicatorPowerDevice * device);
196+gboolean indicator_power_device_get_power_supply (const IndicatorPowerDevice * device);
197
198 GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device);
199 GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device);
200
201=== modified file 'src/service.c'
202--- src/service.c 2016-05-26 18:21:09 +0000
203+++ src/service.c 2017-01-05 04:46:40 +0000
204@@ -162,11 +162,12 @@
205 }
206
207 /* sort devices from most interesting to least interesting on this criteria:
208- 1. discharging items from least time remaining until most time remaining
209- 2. charging items from most time left to charge to least time left to charge
210- 3. charging items with an unknown time remaining
211- 4. discharging items with an unknown time remaining
212- 5. batteries, then non-line power, then line-power */
213+ 1. device that supplied the power to the system
214+ 2. discharging items from least time remaining until most time remaining
215+ 3. charging items from most time left to charge to least time left to charge
216+ 4. charging items with an unknown time remaining
217+ 5. discharging items with an unknown time remaining
218+ 6. batteries, then non-line power, then line-power */
219 static gint
220 device_compare_func (gconstpointer ga, gconstpointer gb)
221 {
222@@ -174,6 +175,8 @@
223 int state;
224 const IndicatorPowerDevice * a = ga;
225 const IndicatorPowerDevice * b = gb;
226+ const gboolean a_power_supply = indicator_power_device_get_power_supply (a);
227+ const gboolean b_power_supply = indicator_power_device_get_power_supply (b);
228 const int a_state = indicator_power_device_get_state (a);
229 const int b_state = indicator_power_device_get_state (b);
230 const gdouble a_percentage = indicator_power_device_get_percentage (a);
231@@ -183,6 +186,14 @@
232
233 ret = 0;
234
235+ if (!ret)
236+ {
237+ if (a_power_supply == TRUE && b_power_supply == FALSE)
238+ ret = -1;
239+ else if (a_power_supply == FALSE && b_power_supply == TRUE)
240+ ret = 1;
241+ }
242+
243 state = UP_DEVICE_STATE_DISCHARGING;
244 if (!ret && (((a_state == state) && a_time) ||
245 ((b_state == state) && b_time)))
246@@ -1436,7 +1447,8 @@
247 UP_DEVICE_KIND_BATTERY,
248 percent,
249 state,
250- time_left);
251+ time_left,
252+ TRUE);
253 }
254
255 return device;
256
257=== modified file 'src/testing.c'
258--- src/testing.c 2014-10-14 19:50:47 +0000
259+++ src/testing.c 2017-01-05 04:46:40 +0000
260@@ -301,7 +301,8 @@
261 UP_DEVICE_KIND_BATTERY,
262 50.0,
263 UP_DEVICE_STATE_DISCHARGING,
264- 60*30);
265+ 60*30,
266+ TRUE);
267
268
269 /* Mock Provider */
270
271=== modified file 'tests/test-device.cc'
272--- tests/test-device.cc 2016-05-26 19:02:10 +0000
273+++ tests/test-device.cc 2017-01-05 04:46:40 +0000
274@@ -205,7 +205,8 @@
275 UP_DEVICE_KIND_BATTERY,
276 50.0,
277 UP_DEVICE_STATE_CHARGING,
278- 30);
279+ 30,
280+ TRUE);
281 ASSERT_TRUE (device != NULL);
282 ASSERT_TRUE (INDICATOR_IS_POWER_DEVICE(device));
283 ASSERT_EQ (UP_DEVICE_KIND_BATTERY, indicator_power_device_get_kind(device));
284@@ -213,6 +214,7 @@
285 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
286 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
287 ASSERT_EQ (30, indicator_power_device_get_time(device));
288+ ASSERT_TRUE (indicator_power_device_get_power_supply(device));
289
290 // cleanup
291 g_object_unref (device);
292@@ -220,13 +222,14 @@
293
294 TEST_F(DeviceTest, NewFromVariant)
295 {
296- auto variant = g_variant_new("(susdut)",
297+ auto variant = g_variant_new("(susdutb)",
298 "/object/path",
299 guint32(UP_DEVICE_KIND_BATTERY),
300 "icon",
301 50.0,
302 guint32(UP_DEVICE_STATE_CHARGING),
303- guint64(30));
304+ guint64(30),
305+ TRUE);
306 IndicatorPowerDevice * device = indicator_power_device_new_from_variant (variant);
307 ASSERT_TRUE (variant != NULL);
308 ASSERT_TRUE (device != NULL);
309@@ -236,6 +239,7 @@
310 ASSERT_STREQ ("/object/path", indicator_power_device_get_object_path(device));
311 ASSERT_EQ (50, int(indicator_power_device_get_percentage(device)));
312 ASSERT_EQ (30, indicator_power_device_get_time(device));
313+ ASSERT_TRUE (indicator_power_device_get_power_supply(device));
314
315 // cleanup
316 g_object_unref (device);
317@@ -840,11 +844,44 @@
318 should be the the maximum of the times for all those that are charging. */
319 TEST_F(DeviceTest, ChoosePrimary)
320 {
321+<<<<<<< TREE
322+=======
323+ struct Description
324+ {
325+ const char * path;
326+ UpDeviceKind kind;
327+ UpDeviceState state;
328+ guint64 time;
329+ double percentage;
330+ gboolean power_supply;
331+ };
332+
333+ const Description descriptions[] = {
334+ { "/some/path/d0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 60.0, TRUE }, // 0
335+ { "/some/path/d1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 80.0, TRUE }, // 1
336+ { "/some/path/d2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 100.0, TRUE }, // 2
337+
338+ { "/some/path/c0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 60.0, TRUE }, // 3
339+ { "/some/path/c1", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 80.0, TRUE }, // 4
340+ { "/some/path/c2", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 100.0, TRUE }, // 5
341+
342+ { "/some/path/f0", UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0, TRUE }, // 6
343+ { "/some/path/m0", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_DISCHARGING, 20, 80.0, FALSE }, // 7
344+ { "/some/path/m1", UP_DEVICE_KIND_MOUSE, UP_DEVICE_STATE_FULLY_CHARGED, 0, 100.0, FALSE }, // 8
345+ { "/some/path/pw", UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_STATE_UNKNOWN, 0, 0.0, TRUE } // 9
346+ };
347+
348+ std::vector<IndicatorPowerDevice*> devices;
349+ for(const auto& desc : descriptions)
350+ devices.push_back(indicator_power_device_new(desc.path, desc.kind, desc.percentage, desc.state, time_t(desc.time), desc.power_supply));
351+
352+>>>>>>> MERGE-SOURCE
353 const struct {
354 std::string description;
355 std::string expected;
356 std::vector<std::string> devices;
357 } tests[] = {
358+<<<<<<< TREE
359 {
360 "one discharging battery",
361 "battery discharging 10m 60% bat01",
362@@ -942,6 +979,30 @@
363 "phone unknown 0m 61% phone01",
364 { "phone unknown 0m 61% phone01" }
365 }
366+=======
367+
368+ { { 0 }, descriptions[0] }, // 1 discharging
369+ { { 0, 1 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 20, 70.0, TRUE } }, // 2 discharging
370+ { { 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 90.0, TRUE } }, // 2 discharging
371+ { { 0, 1, 2 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 80.0, TRUE } }, // 3 discharging
372+ { { 0, 1, 2, 7 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 30, 80.0, TRUE } }, // ignore mouse
373+
374+ { { 3 }, descriptions[3] }, // 1 charging
375+ { { 3, 4 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 20, 70.0, TRUE } }, // 2 charging
376+ { { 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 90.0, TRUE } }, // 2 charging
377+ { { 3, 4, 5 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 80.0, TRUE } }, // 3 charging
378+ { { 3, 4, 5, 8 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 30, 80.0, TRUE } }, // ignore mouse
379+
380+ { { 6 }, descriptions[6] }, // 1 charged
381+ { { 6, 0 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 80.0, TRUE } }, // 1 charged, 1 discharging
382+ { { 6, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_CHARGING, 10, 80.0, TRUE } }, // 1 charged, 1 charging
383+ { { 6, 0, 3 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 73.3, TRUE } }, // 1 charged, 1 charging, 1 discharging
384+ { { 6, 0, 3, 7, 8 }, { nullptr, UP_DEVICE_KIND_BATTERY, UP_DEVICE_STATE_DISCHARGING, 10, 73.3, TRUE } }, // ignore mouse
385+
386+ { { 0, 9 }, descriptions[0] }, // everything comes before power lines except devices without power supply
387+ { { 3, 9 }, descriptions[3] },
388+ { { 7, 9 }, descriptions[9] },
389+>>>>>>> MERGE-SOURCE
390 };
391
392 for(const auto& test : tests)
393@@ -953,15 +1014,37 @@
394
395 // run the test
396 auto primary = indicator_power_service_choose_primary_device(device_glist);
397+<<<<<<< TREE
398 EXPECT_EQ(test.expected, device2str(primary));
399 g_clear_object(&primary);
400+=======
401+ EXPECT_STREQ(x.path, indicator_power_device_get_object_path(primary));
402+ EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
403+ EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
404+ EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
405+ EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
406+ EXPECT_EQ(x.power_supply, indicator_power_device_get_power_supply(primary));
407+ g_object_unref(primary);
408+>>>>>>> MERGE-SOURCE
409
410 // reverse the list and repeat the test
411 // to confirm that list order doesn't matter
412+<<<<<<< TREE
413 device_glist = g_list_reverse(device_glist);
414 primary = indicator_power_service_choose_primary_device(device_glist);
415 EXPECT_EQ(test.expected, device2str(primary));
416 g_clear_object(&primary);
417+=======
418+ device_glist = g_list_reverse (device_glist);
419+ primary = indicator_power_service_choose_primary_device (device_glist);
420+ EXPECT_STREQ(x.path, indicator_power_device_get_object_path(primary));
421+ EXPECT_EQ(x.kind, indicator_power_device_get_kind(primary));
422+ EXPECT_EQ(x.state, indicator_power_device_get_state(primary));
423+ EXPECT_EQ(x.time, indicator_power_device_get_time(primary));
424+ EXPECT_EQ(int(ceil(x.percentage)), int(ceil(indicator_power_device_get_percentage(primary))));
425+ EXPECT_EQ(x.power_supply, indicator_power_device_get_power_supply(primary));
426+ g_object_unref(primary);
427+>>>>>>> MERGE-SOURCE
428
429 // cleanup
430 g_list_free_full(device_glist, g_object_unref);
431
432=== modified file 'tests/test-notify.cc'
433--- tests/test-notify.cc 2016-05-16 17:59:03 +0000
434+++ tests/test-notify.cc 2017-01-05 04:46:40 +0000
435@@ -235,7 +235,8 @@
436 UP_DEVICE_KIND_BATTERY,
437 50.0,
438 UP_DEVICE_STATE_DISCHARGING,
439- 30);
440+ 30,
441+ TRUE);
442
443 // confirm that the power levels trigger at the right percentages
444 for (int i=100; i>=0; --i)
445@@ -313,7 +314,8 @@
446 UP_DEVICE_KIND_BATTERY,
447 50.0,
448 UP_DEVICE_STATE_DISCHARGING,
449- 30);
450+ 30,
451+ TRUE);
452
453 // set up a notifier and give it the battery so changing the battery's
454 // charge should show up on the bus.
455@@ -385,7 +387,8 @@
456 UP_DEVICE_KIND_BATTERY,
457 percent_low + 1.0,
458 UP_DEVICE_STATE_DISCHARGING,
459- 30);
460+ 30,
461+ TRUE);
462
463 // the file we expect to play on a low battery notification...
464 const char* expected_file = XDG_DATA_HOME "/" GETTEXT_PACKAGE "/sounds/" LOW_BATTERY_SOUND;

Subscribers

People subscribed via source and target branches