1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
4  * Copyright (C) 2012-2021 MATE Developers
5  *
6  * Licensed under the GNU General Public License Version 2
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include "config.h"
24 
25 #include <glib/gi18n.h>
26 #include <libupower-glib/upower.h>
27 
28 #include "egg-precision.h"
29 
30 #include "gpm-upower.h"
31 #include "gpm-common.h"
32 
33 #define GPM_UP_TIME_PRECISION			5*60
34 #define GPM_UP_TEXT_MIN_TIME			120
35 
36 /**
37  * gpm_upower_get_device_icon_index:
38  * @percent: The charge of the device
39  *
40  * The index value depends on the percentage charge:
41  *	00-10  = 000
42  *	10-30  = 020
43  *	30-50  = 040
44  *	50-70  = 060
45  *	70-90  = 080
46  *	90-100 = 100
47  *
48  * Return value: The character string for the filename suffix.
49  **/
50 static const gchar *
gpm_upower_get_device_icon_index(UpDevice * device)51 gpm_upower_get_device_icon_index (UpDevice *device)
52 {
53 	gdouble percentage;
54 	/* get device properties */
55 	g_object_get (device, "percentage", &percentage, NULL);
56 	if (percentage < 10)
57 		return "000";
58 	else if (percentage < 30)
59 		return "020";
60 	else if (percentage < 50)
61 		return "040";
62 	else if (percentage < 70)
63 		return "060";
64 	else if (percentage < 90)
65 		return "080";
66 	return "100";
67 }
68 
69 /**
70  * gpm_upower_get_device_icon:
71  *
72  * Need to free the return value
73  *
74  **/
75 gchar *
gpm_upower_get_device_icon(UpDevice * device)76 gpm_upower_get_device_icon (UpDevice *device)
77 {
78 	gchar *filename = NULL;
79 	const gchar *prefix = NULL;
80 	const gchar *index_str;
81 	UpDeviceKind kind;
82 	UpDeviceState state;
83 	gboolean is_present;
84 	gdouble percentage;
85 
86 	g_return_val_if_fail (device != NULL, NULL);
87 
88 	/* get device properties */
89 	g_object_get (device,
90 		      "kind", &kind,
91 		      "state", &state,
92 		      "percentage", &percentage,
93 		      "is-present", &is_present,
94 		      NULL);
95 
96 	/* get correct icon prefix */
97 	prefix = up_device_kind_to_string (kind);
98 
99 	/* get the icon from some simple rules */
100 	if (kind == UP_DEVICE_KIND_LINE_POWER) {
101 		filename = g_strdup ("gpm-ac-adapter");
102 	} else if (kind == UP_DEVICE_KIND_MONITOR) {
103 		filename = g_strdup ("gpm-monitor");
104 	} else if (kind == UP_DEVICE_KIND_UPS) {
105 		if (!is_present) {
106 			/* battery missing */
107 			filename = g_strdup_printf ("gpm-%s-missing", prefix);
108 
109 		} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
110 			filename = g_strdup_printf ("gpm-%s-100", prefix);
111 
112 		} else if (state == UP_DEVICE_STATE_CHARGING) {
113 			index_str = gpm_upower_get_device_icon_index (device);
114 			filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
115 
116 		} else if (state == UP_DEVICE_STATE_DISCHARGING) {
117 			index_str = gpm_upower_get_device_icon_index (device);
118 			filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
119 		}
120 	} else if (kind == UP_DEVICE_KIND_BATTERY) {
121 		if (!is_present) {
122 			/* battery missing */
123 			filename = g_strdup_printf ("gpm-%s-missing", prefix);
124 
125 		} else if (state == UP_DEVICE_STATE_EMPTY) {
126 			filename = g_strdup_printf ("gpm-%s-empty", prefix);
127 
128 		} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
129 			filename = g_strdup_printf ("gpm-%s-charged", prefix);
130 
131 		} else if (state == UP_DEVICE_STATE_CHARGING) {
132 			index_str = gpm_upower_get_device_icon_index (device);
133 			filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
134 
135 		} else if (state == UP_DEVICE_STATE_DISCHARGING) {
136 			index_str = gpm_upower_get_device_icon_index (device);
137 			filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
138 
139 		} else if (state == UP_DEVICE_STATE_PENDING_CHARGE) {
140 			index_str = gpm_upower_get_device_icon_index (device);
141 			/* FIXME: do new grey icons */
142 			filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
143 
144 		} else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) {
145 			index_str = gpm_upower_get_device_icon_index (device);
146 			filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
147 		} else {
148 			filename = g_strdup ("gpm-battery-missing");
149 		}
150 
151 	} else if (kind == UP_DEVICE_KIND_MOUSE ||
152 		   kind == UP_DEVICE_KIND_KEYBOARD ||
153 		   kind == UP_DEVICE_KIND_PHONE) {
154 		if (!is_present) {
155 			/* battery missing */
156 			filename = g_strdup_printf ("gpm-%s-000", prefix);
157 
158 		} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
159 			filename = g_strdup_printf ("gpm-%s-100", prefix);
160 
161 		} else if (state == UP_DEVICE_STATE_DISCHARGING) {
162 			index_str = gpm_upower_get_device_icon_index (device);
163 			filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
164 		}
165 	}
166 
167 	/* nothing matched */
168 	if (filename == NULL) {
169 		g_warning ("nothing matched, falling back to default icon");
170 		filename = g_strdup ("dialog-warning");
171 	}
172 
173 	g_debug ("got filename: %s", filename);
174 	return filename;
175 }
176 
177 /**
178  * gpm_upower_get_device_summary:
179  **/
180 gchar *
gpm_upower_get_device_summary(UpDevice * device)181 gpm_upower_get_device_summary (UpDevice *device)
182 {
183 	const gchar *kind_desc = NULL;
184 	gchar *description = NULL;
185 	guint time_to_full_round;
186 	guint time_to_empty_round;
187 	gchar *time_to_full_str;
188 	gchar *time_to_empty_str;
189 	UpDeviceKind kind;
190 	UpDeviceState state;
191 	gdouble percentage;
192 	gboolean is_present;
193 	gint64 time_to_full;
194 	gint64 time_to_empty;
195 
196 	/* get device properties */
197 	g_object_get (device,
198 		      "kind", &kind,
199 		      "state", &state,
200 		      "percentage", &percentage,
201 		      "is-present", &is_present,
202 		      "time-to-full", &time_to_full,
203 		      "time-to-empty", &time_to_empty,
204 		      NULL);
205 
206 	kind_desc = gpm_device_kind_to_localised_string (kind, 1);
207 
208 	/* not installed */
209 	if (!is_present) {
210 		/* TRANSLATORS: device not present */
211 		return g_strdup_printf (_("%s not present"), kind_desc);
212 	}
213 
214 	/* don't display all the extra stuff for keyboards and mice */
215 	if (kind == UP_DEVICE_KIND_MOUSE ||
216 	    kind == UP_DEVICE_KIND_KEYBOARD ||
217 	    kind == UP_DEVICE_KIND_PDA)
218 		return g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);
219 
220 	/* we care if we are on AC */
221 	if (kind == UP_DEVICE_KIND_PHONE) {
222 		if (state == UP_DEVICE_STATE_CHARGING || !(state == UP_DEVICE_STATE_DISCHARGING)) {
223 			/* TRANSLATORS: a phone is charging */
224 			return g_strdup_printf (_("%s charging (%.1f%%)"), kind_desc, percentage);
225 		}
226 		return g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);
227 	}
228 
229 	/* precalculate so we don't get Unknown time remaining */
230 	time_to_full_round = egg_precision_round_down (time_to_full, GPM_UP_TIME_PRECISION);
231 	time_to_empty_round = egg_precision_round_down (time_to_empty, GPM_UP_TIME_PRECISION);
232 
233 	/* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */
234 	if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
235 
236 		if (kind == UP_DEVICE_KIND_BATTERY && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
237 			time_to_empty_str = gpm_get_timestring (time_to_empty_round);
238 			/* TRANSLATORS: The laptop battery is fully charged, and we know a time */
239 			description = g_strdup_printf (_("Battery is fully charged.\nProvides %s laptop runtime"),
240 							time_to_empty_str);
241 			g_free (time_to_empty_str);
242 		} else {
243 			/* TRANSLATORS: the device is fully charged */
244 			description = g_strdup_printf (_("%s is fully charged"), kind_desc);
245 		}
246 
247 	} else if (state == UP_DEVICE_STATE_DISCHARGING) {
248 
249 		if (time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
250 			time_to_empty_str = gpm_get_timestring (time_to_empty_round);
251 			/* TRANSLATORS: the device is discharging, and we have a time remaining */
252 			description = g_strdup_printf (_("%s %s remaining (%.1f%%)"),
253 							kind_desc, time_to_empty_str, percentage);
254 			g_free (time_to_empty_str);
255 		} else {
256 			/* TRANSLATORS: the device is discharging, but we only have a percentage */
257 			description = g_strdup_printf (_("%s discharging (%.1f%%)"),
258 							kind_desc, percentage);
259 		}
260 
261 	} else if (state == UP_DEVICE_STATE_CHARGING) {
262 
263 		if (time_to_full_round > GPM_UP_TEXT_MIN_TIME &&
264 		    time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
265 
266 			/* display both discharge and charge time */
267 			time_to_full_str = gpm_get_timestring (time_to_full_round);
268 			time_to_empty_str = gpm_get_timestring (time_to_empty_round);
269 
270 			/* TRANSLATORS: the device is charging, and we have a time to full and empty */
271 			description = g_strdup_printf (_("%s %s until charged (%.1f%%)\nProvides %s battery runtime"),
272 							kind_desc, time_to_full_str, percentage, time_to_empty_str);
273 			g_free (time_to_full_str);
274 			g_free (time_to_empty_str);
275 
276 		} else if (time_to_full_round > GPM_UP_TEXT_MIN_TIME) {
277 
278 			/* display only charge time */
279 			time_to_full_str = gpm_get_timestring (time_to_full_round);
280 
281 			/* TRANSLATORS: device is charging, and we have a time to full and a percentage */
282 			description = g_strdup_printf (_("%s %s until charged (%.1f%%)"),
283 						kind_desc, time_to_full_str, percentage);
284 			g_free (time_to_full_str);
285 		} else {
286 
287 			/* TRANSLATORS: device is charging, but we only have a percentage */
288 			description = g_strdup_printf (_("%s charging (%.1f%%)"),
289 						kind_desc, percentage);
290 		}
291 
292 	} else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) {
293 
294 		/* TRANSLATORS: this is only shown for laptops with multiple batteries */
295 		description = g_strdup_printf (_("%s waiting to discharge (%.1f%%)"),
296 						kind_desc, percentage);
297 
298 	} else if (state == UP_DEVICE_STATE_PENDING_CHARGE) {
299 
300 		/* TRANSLATORS: this is only shown for laptops with multiple batteries */
301 		description = g_strdup_printf (_("%s waiting to charge (%.1f%%)"), kind_desc, percentage);
302 
303 	} else if (state == UP_DEVICE_STATE_EMPTY) {
304 
305 		/* TRANSLATORS: when the device has no charge left */
306 		description = g_strdup_printf (_("%s empty"), kind_desc);
307 
308 	} else {
309 		g_warning ("in an undefined state we are not charging or "
310 			     "discharging and the batteries are also not charged");
311 		description = g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);
312 	}
313 
314 	return description;
315 }
316 
317 /**
318  * gpm_upower_get_device_description:
319  **/
320 gchar *
gpm_upower_get_device_description(UpDevice * device)321 gpm_upower_get_device_description (UpDevice *device)
322 {
323 	GString	*details;
324 	const gchar *text;
325 	gchar *time_str;
326 	UpDeviceKind kind;
327 	UpDeviceState state;
328 	UpDeviceTechnology technology;
329 	gdouble percentage;
330 	gdouble capacity;
331 	gdouble energy;
332 	gdouble energy_full;
333 	gdouble energy_full_design;
334 	gdouble energy_rate;
335 	gboolean is_present;
336 	gint64 time_to_full;
337 	gint64 time_to_empty;
338 	gchar *vendor = NULL;
339 	gchar *serial = NULL;
340 	gchar *model = NULL;
341 
342 	g_return_val_if_fail (device != NULL, NULL);
343 
344 	/* get device properties */
345 	g_object_get (device,
346 		      "kind", &kind,
347 		      "state", &state,
348 		      "percentage", &percentage,
349 		      "is-present", &is_present,
350 		      "time-to-full", &time_to_full,
351 		      "time-to-empty", &time_to_empty,
352 		      "technology", &technology,
353 		      "capacity", &capacity,
354 		      "energy", &energy,
355 		      "energy-full", &energy_full,
356 		      "energy-full-design", &energy_full_design,
357 		      "energy-rate", &energy_rate,
358 		      "vendor", &vendor,
359 		      "serial", &serial,
360 		      "model", &model,
361 		      NULL);
362 
363 	details = g_string_new ("");
364 	text = gpm_device_kind_to_localised_string (kind, 1);
365 	/* TRANSLATORS: the type of data, e.g. Laptop battery */
366 	g_string_append_printf (details, "<b>%s</b> %s\n", _("Product:"), text);
367 
368 	if (!is_present) {
369 		/* TRANSLATORS: device is missing */
370 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Missing"));
371 	} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
372 		/* TRANSLATORS: device is charged */
373 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Charged"));
374 	} else if (state == UP_DEVICE_STATE_CHARGING) {
375 		/* TRANSLATORS: device is charging */
376 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Charging"));
377 	} else if (state == UP_DEVICE_STATE_DISCHARGING) {
378 		/* TRANSLATORS: device is discharging */
379 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Discharging"));
380 	}
381 
382 	if (percentage >= 0) {
383 		/* TRANSLATORS: percentage */
384 		g_string_append_printf (details, "<b>%s</b> %.1f%%\n", _("Percentage charge:"), percentage);
385 	}
386 	if (vendor) {
387 		/* TRANSLATORS: manufacturer */
388 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Vendor:"), vendor);
389 	}
390 	if (technology != UP_DEVICE_TECHNOLOGY_UNKNOWN) {
391 		text = gpm_device_technology_to_localised_string (technology);
392 		/* TRANSLATORS: how the battery is made, e.g. Lithium Ion */
393 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Technology:"), text);
394 	}
395 	if (serial) {
396 		/* TRANSLATORS: serial number of the battery */
397 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Serial number:"), serial);
398 	}
399 	if (model) {
400 		/* TRANSLATORS: model number of the battery */
401 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Model:"), model);
402 	}
403 	if (time_to_full > 0) {
404 		time_str = gpm_get_timestring (time_to_full);
405 		/* TRANSLATORS: time to fully charged */
406 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Charge time:"), time_str);
407 		g_free (time_str);
408 	}
409 	if (time_to_empty > 0) {
410 		time_str = gpm_get_timestring (time_to_empty);
411 		/* TRANSLATORS: time to empty */
412 		g_string_append_printf (details, "<b>%s</b> %s\n", _("Discharge time:"), time_str);
413 		g_free (time_str);
414 	}
415 	if (capacity > 0) {
416 		const gchar *condition;
417 		if (capacity > 99) {
418 			/* TRANSLATORS: Excellent, Good, Fair and Poor are all related to battery Capacity */
419 			condition = _("Excellent");
420 		} else if (capacity > 90) {
421 			condition = _("Good");
422 		} else if (capacity > 70) {
423 			condition = _("Fair");
424 		} else {
425 			condition = _("Poor");
426 		}
427 		/* TRANSLATORS: %.1f is a percentage and %s the condition (Excellent, Good, ...) */
428 		g_string_append_printf (details, "<b>%s</b> %.1f%% (%s)\n",
429 					_("Capacity:"), capacity, condition);
430 	}
431 	if (kind == UP_DEVICE_KIND_BATTERY) {
432 		if (energy > 0) {
433 			/* TRANSLATORS: current charge */
434 			g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
435 						_("Current charge:"), energy);
436 		}
437 		if (energy_full > 0 &&
438 		    energy_full_design != energy_full) {
439 			/* TRANSLATORS: last full is the charge the battery was seen to charge to */
440 			g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
441 						_("Last full charge:"), energy_full);
442 		}
443 		if (energy_full_design > 0) {
444 			/* Translators:  */
445 			/* TRANSLATORS: Design charge is the amount of charge the battery is designed to have when brand new */
446 			g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
447 						_("Design charge:"), energy_full_design);
448 		}
449 		if (energy_rate > 0) {
450 			/* TRANSLATORS: the charge or discharge rate */
451 			g_string_append_printf (details, "<b>%s</b> %.1f W\n",
452 						_("Charge rate:"), energy_rate);
453 		}
454 	}
455 	if (kind == UP_DEVICE_KIND_MOUSE ||
456 	    kind == UP_DEVICE_KIND_KEYBOARD) {
457 		if (energy > 0) {
458 			/* TRANSLATORS: the current charge for CSR devices */
459 			g_string_append_printf (details, "<b>%s</b> %.0f/7\n",
460 						_("Current charge:"), energy);
461 		}
462 		if (energy_full_design > 0) {
463 			/* TRANSLATORS: the design charge for CSR devices */
464 			g_string_append_printf (details, "<b>%s</b> %.0f/7\n",
465 						_("Design charge:"), energy_full_design);
466 		}
467 	}
468 	/* remove the last \n */
469 	g_string_truncate (details, details->len-1);
470 
471 	g_free (vendor);
472 	g_free (serial);
473 	g_free (model);
474 	return g_string_free (details, FALSE);
475 }
476 
477 /**
478  * gpm_device_kind_to_localised_string:
479  **/
480 const gchar *
gpm_device_kind_to_localised_string(UpDeviceKind kind,guint number)481 gpm_device_kind_to_localised_string (UpDeviceKind kind, guint number)
482 {
483 	const gchar *text = NULL;
484 	switch (kind) {
485 	case UP_DEVICE_KIND_LINE_POWER:
486 		/* TRANSLATORS: system power cord */
487 		text = ngettext ("AC adapter", "AC adapters", number);
488 		break;
489 	case UP_DEVICE_KIND_BATTERY:
490 		/* TRANSLATORS: laptop primary battery */
491 		text = ngettext ("Laptop battery", "Laptop batteries", number);
492 		break;
493 	case UP_DEVICE_KIND_UPS:
494 		/* TRANSLATORS: battery-backed AC power source */
495 		text = ngettext ("UPS", "UPSs", number);
496 		break;
497 	case UP_DEVICE_KIND_MONITOR:
498 		/* TRANSLATORS: a monitor is a device to measure voltage and current */
499 		text = ngettext ("Monitor", "Monitors", number);
500 		break;
501 	case UP_DEVICE_KIND_MOUSE:
502 		/* TRANSLATORS: wireless mice with internal batteries */
503 		text = ngettext ("Mouse", "Mice", number);
504 		break;
505 	case UP_DEVICE_KIND_KEYBOARD:
506 		/* TRANSLATORS: wireless keyboard with internal battery */
507 		text = ngettext ("Keyboard", "Keyboards", number);
508 		break;
509 	case UP_DEVICE_KIND_PDA:
510 		/* TRANSLATORS: portable device */
511 		text = ngettext ("PDA", "PDAs", number);
512 		break;
513 	case UP_DEVICE_KIND_PHONE:
514 		/* TRANSLATORS: cell phone (mobile...) */
515 		text = ngettext ("Cell phone", "Cell phones", number);
516 		break;
517 	case UP_DEVICE_KIND_MEDIA_PLAYER:
518 		/* TRANSLATORS: media player, mp3 etc */
519 		text = ngettext ("Media player", "Media players", number);
520 		break;
521 	case UP_DEVICE_KIND_TABLET:
522 		/* TRANSLATORS: tablet device */
523 		text = ngettext ("Tablet", "Tablets", number);
524 		break;
525 	case UP_DEVICE_KIND_COMPUTER:
526 		/* TRANSLATORS: tablet device */
527 		text = ngettext ("Computer", "Computers", number);
528 		break;
529 	default:
530 		g_warning ("enum unrecognised: %i", kind);
531 		text = up_device_kind_to_string (kind);
532 	}
533 	return text;
534 }
535 
536 /**
537  * gpm_device_kind_to_icon:
538  **/
539 const gchar *
gpm_device_kind_to_icon(UpDeviceKind kind)540 gpm_device_kind_to_icon (UpDeviceKind kind)
541 {
542 	const gchar *icon = NULL;
543 	switch (kind) {
544 	case UP_DEVICE_KIND_LINE_POWER:
545 		icon = "gpm-ac-adapter";
546 		break;
547 	case UP_DEVICE_KIND_BATTERY:
548 		icon = "battery";
549 		break;
550 	case UP_DEVICE_KIND_UPS:
551 		icon = "network-wired";
552 		break;
553 	case UP_DEVICE_KIND_MONITOR:
554 		icon = "application-certificate";
555 		break;
556 	case UP_DEVICE_KIND_MOUSE:
557 		icon = "input-mouse";
558 		break;
559 	case UP_DEVICE_KIND_KEYBOARD:
560 		icon = "input-keyboard";
561 		break;
562 	case UP_DEVICE_KIND_PDA:
563 		icon = "pda";
564 		break;
565 	case UP_DEVICE_KIND_PHONE:
566 		icon = "phone";
567 		break;
568 	case UP_DEVICE_KIND_MEDIA_PLAYER:
569 		icon = "multimedia-player";
570 		break;
571 	case UP_DEVICE_KIND_TABLET:
572 		icon = "input-tablet";
573 		break;
574 	case UP_DEVICE_KIND_COMPUTER:
575 		icon = "computer-apple-ipad";
576 		break;
577 	default:
578 		g_warning ("enum unrecognised: %i", kind);
579 		icon = "gtk-help";
580 	}
581 	return icon;
582 }
583 
584 /**
585  * gpm_device_technology_to_localised_string:
586  **/
587 const gchar *
gpm_device_technology_to_localised_string(UpDeviceTechnology technology_enum)588 gpm_device_technology_to_localised_string (UpDeviceTechnology technology_enum)
589 {
590 	const gchar *technology = NULL;
591 	switch (technology_enum) {
592 	case UP_DEVICE_TECHNOLOGY_LITHIUM_ION:
593 		/* TRANSLATORS: battery technology */
594 		technology = _("Lithium Ion");
595 		break;
596 	case UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
597 		/* TRANSLATORS: battery technology */
598 		technology = _("Lithium Polymer");
599 		break;
600 	case UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
601 		/* TRANSLATORS: battery technology */
602 		technology = _("Lithium Iron Phosphate");
603 		break;
604 	case UP_DEVICE_TECHNOLOGY_LEAD_ACID:
605 		/* TRANSLATORS: battery technology */
606 		technology = _("Lead acid");
607 		break;
608 	case UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
609 		/* TRANSLATORS: battery technology */
610 		technology = _("Nickel Cadmium");
611 		break;
612 	case UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
613 		/* TRANSLATORS: battery technology */
614 		technology = _("Nickel metal hydride");
615 		break;
616 	case UP_DEVICE_TECHNOLOGY_UNKNOWN:
617 		/* TRANSLATORS: battery technology */
618 		technology = _("Unknown technology");
619 		break;
620 	default:
621 		g_assert_not_reached ();
622 		break;
623 	}
624 	return technology;
625 }
626 
627 /**
628  * gpm_device_state_to_localised_string:
629  **/
630 const gchar *
gpm_device_state_to_localised_string(UpDeviceState state)631 gpm_device_state_to_localised_string (UpDeviceState state)
632 {
633 	const gchar *state_string = NULL;
634 
635 	switch (state) {
636 	case UP_DEVICE_STATE_CHARGING:
637 		/* TRANSLATORS: battery state */
638 		state_string = _("Charging");
639 		break;
640 	case UP_DEVICE_STATE_DISCHARGING:
641 		/* TRANSLATORS: battery state */
642 		state_string = _("Discharging");
643 		break;
644 	case UP_DEVICE_STATE_EMPTY:
645 		/* TRANSLATORS: battery state */
646 		state_string = _("Empty");
647 		break;
648 	case UP_DEVICE_STATE_FULLY_CHARGED:
649 		/* TRANSLATORS: battery state */
650 		state_string = _("Charged");
651 		break;
652 	case UP_DEVICE_STATE_PENDING_CHARGE:
653 		/* TRANSLATORS: battery state */
654 		state_string = _("Waiting to charge");
655 		break;
656 	case UP_DEVICE_STATE_PENDING_DISCHARGE:
657 		/* TRANSLATORS: battery state */
658 		state_string = _("Waiting to discharge");
659 		break;
660 	case UP_DEVICE_STATE_UNKNOWN:
661 		/* TRANSLATORS: battery state */
662 		state_string = _("Unknown state");
663 		break;
664 	default:
665 		g_assert_not_reached ();
666 		break;
667 	}
668 	return state_string;
669 }
670 
671