111
96
/* get correct icon prefix */
112
filename = g_string_new (NULL);
97
prefix = up_device_kind_to_string (kind);
114
99
/* get the icon from some simple rules */
115
100
if (kind == UP_DEVICE_KIND_LINE_POWER) {
117
g_string_append (filename, "ac-adapter-symbolic;");
118
g_string_append (filename, "ac-adapter;");
101
filename = g_strdup ("gpm-ac-adapter");
120
102
} else if (kind == UP_DEVICE_KIND_MONITOR) {
122
g_string_append (filename, "gpm-monitor-symbolic;");
123
g_string_append (filename, "gpm-monitor;");
127
kind_str = up_device_kind_to_string (kind);
130
g_string_append (filename, "battery-missing-symbolic;");
131
g_string_append_printf (filename, "gpm-%s-missing;", kind_str);
132
g_string_append_printf (filename, "gpm-%s-000;", kind_str);
133
g_string_append (filename, "battery-missing;");
103
filename = g_strdup ("gpm-monitor");
104
} else if (kind == UP_DEVICE_KIND_UPS) {
106
/* battery missing */
107
filename = g_strdup_printf ("gpm-%s-missing", prefix);
109
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
110
filename = g_strdup_printf ("gpm-%s-100", prefix);
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);
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);
120
} else if (kind == UP_DEVICE_KIND_BATTERY) {
122
/* battery missing */
123
filename = g_strdup_printf ("gpm-%s-missing", prefix);
125
} else if (state == UP_DEVICE_STATE_EMPTY) {
126
filename = g_strdup_printf ("gpm-%s-empty", prefix);
128
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
129
filename = g_strdup_printf ("gpm-%s-charged", prefix);
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);
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);
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);
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);
137
case UP_DEVICE_STATE_EMPTY:
139
g_string_append (filename, "battery-empty-symbolic;");
140
g_string_append_printf (filename, "gpm-%s-empty;", kind_str);
141
g_string_append_printf (filename, "gpm-%s-000;", kind_str);
142
g_string_append (filename, "battery-empty;");
144
case UP_DEVICE_STATE_FULLY_CHARGED:
146
g_string_append (filename, "battery-full-symbolic;");
147
g_string_append_printf (filename, "gpm-%s-full;", kind_str);
148
g_string_append_printf (filename, "gpm-%s-100;", kind_str);
149
g_string_append (filename, "battery-full;");
151
case UP_DEVICE_STATE_CHARGING:
152
case UP_DEVICE_STATE_PENDING_CHARGE:
153
suffix_str = gpm_upower_get_device_icon_suffix (device);
154
index_str = gpm_upower_get_device_icon_index (device);
156
g_string_append_printf (filename, "battery-%s-charging-symbolic;", suffix_str);
157
g_string_append_printf (filename, "gpm-%s-%s-charging;", kind_str, index_str);
158
g_string_append_printf (filename, "battery-%s-charging;", suffix_str);
160
case UP_DEVICE_STATE_DISCHARGING:
161
case UP_DEVICE_STATE_PENDING_DISCHARGE:
162
suffix_str = gpm_upower_get_device_icon_suffix (device);
163
index_str = gpm_upower_get_device_icon_index (device);
165
g_string_append_printf (filename, "battery-%s-symbolic;", suffix_str);
166
g_string_append_printf (filename, "gpm-%s-%s;", kind_str, index_str);
167
g_string_append_printf (filename, "battery-%s;", suffix_str);
171
g_string_append (filename, "battery-missing-symbolic;");
172
g_string_append (filename, "gpm-battery-missing;");
173
g_string_append (filename, "battery-missing;");
148
filename = g_strdup ("gpm-battery-missing");
151
} else if (kind == UP_DEVICE_KIND_MOUSE ||
152
kind == UP_DEVICE_KIND_KEYBOARD ||
153
kind == UP_DEVICE_KIND_PHONE) {
155
/* battery missing */
156
filename = g_strdup_printf ("gpm-%s-000", prefix);
158
} else if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
159
filename = g_strdup_printf ("gpm-%s-100", prefix);
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);
178
167
/* nothing matched */
179
if (filename->len == 0) {
168
if (filename == NULL) {
180
169
egg_warning ("nothing matched, falling back to default icon");
181
g_string_append (filename, "dialog-warning;");
170
filename = g_strdup ("dialog-warning");
184
egg_debug ("got filename: %s", filename->str);
186
iconnames = g_strsplit (filename->str, ";", -1);
187
icon = g_themed_icon_new_from_names (iconnames, -1);
189
g_strfreev (iconnames);
190
g_string_free (filename, TRUE);
173
egg_debug ("got filename: %s", filename);
220
203
"time-to-empty", &time_to_empty,
223
description = g_string_new (NULL);
224
kind_desc = gpm_device_kind_to_localised_string (kind, 1);
228
/* TRANSLATORS: device not present */
229
g_string_append_printf (description, _("%s not present"), kind_desc);
209
kind_desc = gpm_device_kind_to_localised_text (kind, 1);
233
211
/* don't display all the extra stuff for keyboards and mice */
234
212
if (kind == UP_DEVICE_KIND_MOUSE ||
235
213
kind == UP_DEVICE_KIND_KEYBOARD ||
236
kind == UP_DEVICE_KIND_PDA) {
237
g_string_append (description, kind_desc);
238
g_string_append_printf (description, " (%.0f%%)", percentage);
214
kind == UP_DEVICE_KIND_PDA)
215
return g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);
242
217
/* we care if we are on AC */
243
218
if (kind == UP_DEVICE_KIND_PHONE) {
244
219
if (state == UP_DEVICE_STATE_CHARGING || !state == UP_DEVICE_STATE_DISCHARGING) {
245
220
/* TRANSLATORS: a phone is charging */
246
g_string_append_printf (description, _("%s charging"), kind_desc);
247
g_string_append_printf (description, " (%.0f%%)", percentage);
221
return g_strdup_printf (_("%s charging (%.1f%%)"), kind_desc, percentage);
250
g_string_append (description, kind_desc);
251
g_string_append_printf (description, " (%.0f%%)", percentage);
223
return g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);
255
226
/* precalculate so we don't get Unknown time remaining */
259
230
/* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */
260
231
if (state == UP_DEVICE_STATE_FULLY_CHARGED) {
262
/* TRANSLATORS: the device is charged */
263
g_string_append_printf (description, _("%s is charged"), kind_desc);
265
233
if (kind == UP_DEVICE_KIND_BATTERY && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
266
234
time_to_empty_str = gpm_get_timestring (time_to_empty_round);
267
g_string_append (description, " - ");
268
/* TRANSLATORS: The laptop battery is charged, and we know a time */
269
g_string_append_printf (description, _("provides %s laptop runtime"), time_to_empty_str);
235
/* TRANSLATORS: The laptop battery is fully charged, and we know a time */
236
description = g_strdup_printf (_("Battery is fully charged.\nProvides %s laptop runtime"),
238
g_free (time_to_empty_str);
240
/* TRANSLATORS: the device is fully charged */
241
description = g_strdup_printf (_("%s is fully charged"), kind_desc);
273
if (state == UP_DEVICE_STATE_DISCHARGING) {
244
} else if (state == UP_DEVICE_STATE_DISCHARGING) {
275
246
if (time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
276
247
time_to_empty_str = gpm_get_timestring (time_to_empty_round);
277
248
/* TRANSLATORS: the device is discharging, and we have a time remaining */
278
g_string_append_printf (description, _("%s %s remaining"),
279
kind_desc, time_to_empty_str);
280
g_string_append_printf (description, " (%.0f%%)", percentage);
249
description = g_strdup_printf (_("%s %s remaining (%.1f%%)"),
250
kind_desc, time_to_empty_str, percentage);
251
g_free (time_to_empty_str);
282
253
/* TRANSLATORS: the device is discharging, but we only have a percentage */
283
g_string_append_printf (description, _("%s discharging"), kind_desc);
284
g_string_append_printf (description, " (%.0f%%)", percentage);
254
description = g_strdup_printf (_("%s discharging (%.1f%%)"),
255
kind_desc, percentage);
288
if (state == UP_DEVICE_STATE_CHARGING) {
258
} else if (state == UP_DEVICE_STATE_CHARGING) {
290
260
if (time_to_full_round > GPM_UP_TEXT_MIN_TIME &&
291
261
time_to_empty_round > GPM_UP_TEXT_MIN_TIME) {
294
264
time_to_full_str = gpm_get_timestring (time_to_full_round);
295
265
time_to_empty_str = gpm_get_timestring (time_to_empty_round);
297
/* TRANSLATORS: device is charging, and we have a time to full and a percentage */
298
g_string_append_printf (description, _("%s %s until charged"),
299
kind_desc, time_to_full_str);
300
g_string_append_printf (description, " (%.0f%%)", percentage);
302
g_string_append (description, " - ");
303
267
/* TRANSLATORS: the device is charging, and we have a time to full and empty */
304
g_string_append_printf (description, _("provides %s battery runtime"),
268
description = g_strdup_printf (_("%s %s until charged (%.1f%%)\nProvides %s battery runtime"),
269
kind_desc, time_to_full_str, percentage, time_to_empty_str);
270
g_free (time_to_full_str);
271
g_free (time_to_empty_str);
306
273
} else if (time_to_full_round > GPM_UP_TEXT_MIN_TIME) {
308
275
/* display only charge time */
309
276
time_to_full_str = gpm_get_timestring (time_to_full_round);
311
278
/* TRANSLATORS: device is charging, and we have a time to full and a percentage */
312
g_string_append_printf (description, _("%s %s until charged"),
313
kind_desc, time_to_full_str);
314
g_string_append_printf (description, " (%.0f%%)", percentage);
279
description = g_strdup_printf (_("%s %s until charged (%.1f%%)"),
280
kind_desc, time_to_full_str, percentage);
281
g_free (time_to_full_str);
317
284
/* TRANSLATORS: device is charging, but we only have a percentage */
318
g_string_append_printf (description, _("%s charging"), kind_desc);
319
g_string_append_printf (description, " (%.0f%%)", percentage);
285
description = g_strdup_printf (_("%s charging (%.1f%%)"),
286
kind_desc, percentage);
323
if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) {
325
/* TRANSLATORS: this is only shown for laptops with multiple batteries */
326
g_string_append_printf (description, _("%s waiting to discharge"), kind_desc);
327
g_string_append_printf (description, " (%.0f%%)", percentage);
330
if (state == UP_DEVICE_STATE_PENDING_CHARGE) {
332
/* TRANSLATORS: this is only shown for laptops with multiple batteries */
333
g_string_append_printf (description, _("%s waiting to charge"), kind_desc);
334
g_string_append_printf (description, " (%.0f%%)", percentage);
337
if (state == UP_DEVICE_STATE_EMPTY) {
339
/* TRANSLATORS: when the device has no charge left */
340
g_string_append_printf (description, _("%s empty"), kind_desc);
345
egg_warning ("in an undefined state we are not charging or "
346
"discharging and the batteries are also not charged");
347
g_string_append (description, kind_desc);
348
g_string_append_printf (description, " (%.0f%%)", percentage);
350
g_free (time_to_full_str);
351
g_free (time_to_empty_str);
352
return g_string_free (description, FALSE);
289
} else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) {
291
/* TRANSLATORS: this is only shown for laptops with multiple batteries */
292
description = g_strdup_printf (_("%s waiting to discharge (%.1f%%)"),
293
kind_desc, percentage);
295
} else if (state == UP_DEVICE_STATE_PENDING_CHARGE) {
297
/* TRANSLATORS: this is only shown for laptops with multiple batteries */
298
description = g_strdup_printf (_("%s waiting to charge (%.1f%%)"), kind_desc, percentage);
301
egg_warning ("in an undefined state we are not charging or "
302
"discharging and the batteries are also not charged");
303
description = g_strdup_printf ("%s (%.1f%%)", kind_desc, percentage);