~psusi/ubuntu/natty/gnome-power-manager/sleep

« back to all changes in this revision

Viewing changes to src/gpm-upower.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2010-03-31 18:02:57 UTC
  • mfrom: (2.2.7 upstream)
  • mto: (24.1.12 squeeze)
  • mto: This revision was merged to the branch mainline in revision 170.
  • Revision ID: james.westby@ubuntu.com-20100331180257-adoalcy5arv3znld
Tags: 2.30.0-1
* New upstream release.
* debian/patches/04_cast-align.patch
  - Removed, -Werror is no longer enforced by default.
* debian/patches/07-bugreport-upower.patch
  - Removed, merged upstream.
* debian/patches/09-inhibit-consolekit-events-after-resume.patch
  - Removed, merged upstream.
* debian/patches/10-do-not-exit-if-hal-is-not-available.patch
  - Removed, merged upstream.
* debian/patches/11-only-connect-to-hal-if-there-is-no-xrandr-hardware.patch
  - Removed, merged upstream.
* debian/patches/12-DeviceKit-disks-is-now-called-UDisks.patch
  - Removed, merged upstream.
* debian/patches/90_autoconf.patch
  - Removed, obsolete.
* debian/rules
  - Remove obsolete configure switch --with-dpms-ext.
* Switch to source format 3.0 (quilt).
  - Add debian/source/format.
  - Drop quilt from Build-Depends.
  - Remove /usr/share/cdbs/1/rules/patchsys-quilt.mk include.
* debian/patches/09-fix-critical-warning-from-gpmscreensaver.patch
  - Fix up a critical warning from the GpmScreensaver code on startup. Patch
    pulled from upstream Git.
* debian/copyright
  - Update list of copyright holders and add copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 *
 
5
 * Licensed under the GNU General Public License Version 2
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
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, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib/gi18n.h>
 
25
#include <devkit-power-gobject/devicekit-power.h>
 
26
 
 
27
#include "egg-debug.h"
 
28
#include "egg-precision.h"
 
29
 
 
30
#include "gpm-upower.h"
 
31
#include "gpm-common.h"
 
32
 
 
33
#define GPM_DKP_TIME_PRECISION                  5*60
 
34
#define GPM_DKP_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 *
 
51
gpm_upower_get_device_icon_index (DkpDevice *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 *
 
76
gpm_upower_get_device_icon (DkpDevice *device)
 
77
{
 
78
        gchar *filename = NULL;
 
79
        const gchar *prefix = NULL;
 
80
        const gchar *index_str;
 
81
        DkpDeviceType type;
 
82
        DkpDeviceState 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
                      "type", &type,
 
91
                      "state", &state,
 
92
                      "percentage", &percentage,
 
93
                      "is-present", &is_present,
 
94
                      NULL);
 
95
 
 
96
        /* get correct icon prefix */
 
97
        prefix = dkp_device_type_to_text (type);
 
98
 
 
99
        /* get the icon from some simple rules */
 
100
        if (type == DKP_DEVICE_TYPE_LINE_POWER) {
 
101
                filename = g_strdup ("gpm-ac-adapter");
 
102
        } else if (type == DKP_DEVICE_TYPE_MONITOR) {
 
103
                filename = g_strdup ("gpm-monitor");
 
104
        } else if (type == DKP_DEVICE_TYPE_UPS) {
 
105
                if (!is_present) {
 
106
                        /* battery missing */
 
107
                        filename = g_strdup_printf ("gpm-%s-missing", prefix);
 
108
 
 
109
                } else if (state == DKP_DEVICE_STATE_FULLY_CHARGED) {
 
110
                        filename = g_strdup_printf ("gpm-%s-100", prefix);
 
111
 
 
112
                } else if (state == DKP_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 == DKP_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 (type == DKP_DEVICE_TYPE_BATTERY) {
 
121
                if (!is_present) {
 
122
                        /* battery missing */
 
123
                        filename = g_strdup_printf ("gpm-%s-missing", prefix);
 
124
 
 
125
                } else if (state == DKP_DEVICE_STATE_EMPTY) {
 
126
                        filename = g_strdup_printf ("gpm-%s-empty", prefix);
 
127
 
 
128
                } else if (state == DKP_DEVICE_STATE_FULLY_CHARGED) {
 
129
                        filename = g_strdup_printf ("gpm-%s-charged", prefix);
 
130
 
 
131
#if !DKP_CHECK_VERSION(0x009)
 
132
                } else if (state == DKP_DEVICE_STATE_UNKNOWN && percentage > 95.0f) {
 
133
                        egg_warning ("fixing up unknown %f", percentage);
 
134
                        filename = g_strdup_printf ("gpm-%s-charged", prefix);
 
135
#endif
 
136
 
 
137
                } else if (state == DKP_DEVICE_STATE_CHARGING) {
 
138
                        index_str = gpm_upower_get_device_icon_index (device);
 
139
                        filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
 
140
 
 
141
                } else if (state == DKP_DEVICE_STATE_DISCHARGING) {
 
142
                        index_str = gpm_upower_get_device_icon_index (device);
 
143
                        filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
 
144
 
 
145
#if !DKP_CHECK_VERSION(0x009)
 
146
                /* the battery isn't charging or discharging, it's just
 
147
                 * sitting there half full doing nothing */
 
148
                } else {
 
149
                        DkpClient *client;
 
150
                        gboolean on_battery;
 
151
 
 
152
                        /* get battery status */
 
153
                        client = dkp_client_new ();
 
154
                        g_object_get (client,
 
155
                                      "on-battery", &on_battery,
 
156
                                      NULL);
 
157
                        g_object_unref (client);
 
158
 
 
159
                        /* try to find a suitable icon depending on AC state */
 
160
                        if (on_battery) {
 
161
                                index_str = gpm_upower_get_device_icon_index (device);
 
162
                                filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
 
163
                        } else {
 
164
                                index_str = gpm_upower_get_device_icon_index (device);
 
165
                                filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
 
166
                        }
 
167
#else
 
168
                } else if (state == DKP_DEVICE_STATE_PENDING_CHARGE) {
 
169
                        index_str = gpm_upower_get_device_icon_index (device);
 
170
                        /* FIXME: do new grey icons */
 
171
                        filename = g_strdup_printf ("gpm-%s-%s-charging", prefix, index_str);
 
172
 
 
173
                } else if (state == DKP_DEVICE_STATE_PENDING_DISCHARGE) {
 
174
                        index_str = gpm_upower_get_device_icon_index (device);
 
175
                        filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
 
176
                } else {
 
177
                        filename = g_strdup ("gpm-battery-missing");
 
178
#endif
 
179
                }
 
180
 
 
181
        } else if (type == DKP_DEVICE_TYPE_MOUSE ||
 
182
                   type == DKP_DEVICE_TYPE_KEYBOARD ||
 
183
                   type == DKP_DEVICE_TYPE_PHONE) {
 
184
                if (!is_present) {
 
185
                        /* battery missing */
 
186
                        filename = g_strdup_printf ("gpm-%s-000", prefix);
 
187
 
 
188
                } else if (state == DKP_DEVICE_STATE_FULLY_CHARGED) {
 
189
                        filename = g_strdup_printf ("gpm-%s-100", prefix);
 
190
 
 
191
                } else if (state == DKP_DEVICE_STATE_DISCHARGING) {
 
192
                        index_str = gpm_upower_get_device_icon_index (device);
 
193
                        filename = g_strdup_printf ("gpm-%s-%s", prefix, index_str);
 
194
                }
 
195
        }
 
196
 
 
197
        /* nothing matched */
 
198
        if (filename == NULL) {
 
199
                egg_warning ("nothing matched, falling back to default icon");
 
200
                filename = g_strdup ("dialog-warning");
 
201
        }
 
202
 
 
203
        egg_debug ("got filename: %s", filename);
 
204
        return filename;
 
205
}
 
206
 
 
207
/**
 
208
 * gpm_upower_get_device_summary:
 
209
 **/
 
210
gchar *
 
211
gpm_upower_get_device_summary (DkpDevice *device)
 
212
{
 
213
        const gchar *type_desc = NULL;
 
214
        gchar *description = NULL;
 
215
        guint time_to_full_round;
 
216
        guint time_to_empty_round;
 
217
        gchar *time_to_full_str;
 
218
        gchar *time_to_empty_str;
 
219
        DkpDeviceType type;
 
220
        DkpDeviceState state;
 
221
        gdouble percentage;
 
222
        gboolean is_present;
 
223
        gint64 time_to_full;
 
224
        gint64 time_to_empty;
 
225
 
 
226
        /* get device properties */
 
227
        g_object_get (device,
 
228
                      "type", &type,
 
229
                      "state", &state,
 
230
                      "percentage", &percentage,
 
231
                      "is-present", &is_present,
 
232
                      "time-to-full", &time_to_full,
 
233
                      "time-to-empty", &time_to_empty,
 
234
                      NULL);
 
235
 
 
236
        if (!is_present)
 
237
                return NULL;
 
238
 
 
239
        type_desc = gpm_device_type_to_localised_text (type, 1);
 
240
 
 
241
        /* don't display all the extra stuff for keyboards and mice */
 
242
        if (type == DKP_DEVICE_TYPE_MOUSE ||
 
243
            type == DKP_DEVICE_TYPE_KEYBOARD ||
 
244
            type == DKP_DEVICE_TYPE_PDA)
 
245
                return g_strdup_printf ("%s (%.1f%%)", type_desc, percentage);
 
246
 
 
247
        /* we care if we are on AC */
 
248
        if (type == DKP_DEVICE_TYPE_PHONE) {
 
249
                if (state == DKP_DEVICE_STATE_CHARGING || !state == DKP_DEVICE_STATE_DISCHARGING) {
 
250
                        /* TRANSLATORS: a phone is charging */
 
251
                        return g_strdup_printf (_("%s charging (%.1f%%)"), type_desc, percentage);
 
252
                }
 
253
                return g_strdup_printf ("%s (%.1f%%)", type_desc, percentage);
 
254
        }
 
255
 
 
256
        /* precalculate so we don't get Unknown time remaining */
 
257
        time_to_full_round = egg_precision_round_down (time_to_full, GPM_DKP_TIME_PRECISION);
 
258
        time_to_empty_round = egg_precision_round_down (time_to_empty, GPM_DKP_TIME_PRECISION);
 
259
 
 
260
        /* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */
 
261
        if (state == DKP_DEVICE_STATE_FULLY_CHARGED) {
 
262
 
 
263
                if (type == DKP_DEVICE_TYPE_BATTERY && time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
 
264
                        time_to_empty_str = gpm_get_timestring (time_to_empty_round);
 
265
                        /* TRANSLATORS: The laptop battery is fully charged, and we know a time */
 
266
                        description = g_strdup_printf (_("Battery is fully charged.\nProvides %s laptop runtime"),
 
267
                                                        time_to_empty_str);
 
268
                        g_free (time_to_empty_str);
 
269
                } else {
 
270
                        /* TRANSLATORS: the device is fully charged */
 
271
                        description = g_strdup_printf (_("%s is fully charged"), type_desc);
 
272
                }
 
273
 
 
274
        } else if (state == DKP_DEVICE_STATE_DISCHARGING) {
 
275
 
 
276
                if (time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
 
277
                        time_to_empty_str = gpm_get_timestring (time_to_empty_round);
 
278
                        /* TRANSLATORS: the device is discharging, and we have a time remaining */
 
279
                        description = g_strdup_printf (_("%s %s remaining (%.1f%%)"),
 
280
                                                        type_desc, time_to_empty_str, percentage);
 
281
                        g_free (time_to_empty_str);
 
282
                } else {
 
283
                        /* TRANSLATORS: the device is discharging, but we only have a percentage */
 
284
                        description = g_strdup_printf (_("%s discharging (%.1f%%)"),
 
285
                                                        type_desc, percentage);
 
286
                }
 
287
 
 
288
        } else if (state == DKP_DEVICE_STATE_CHARGING) {
 
289
 
 
290
                if (time_to_full_round > GPM_DKP_TEXT_MIN_TIME &&
 
291
                    time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
 
292
 
 
293
                        /* display both discharge and charge time */
 
294
                        time_to_full_str = gpm_get_timestring (time_to_full_round);
 
295
                        time_to_empty_str = gpm_get_timestring (time_to_empty_round);
 
296
 
 
297
                        /* TRANSLATORS: the device is charging, and we have a time to full and empty */
 
298
                        description = g_strdup_printf (_("%s %s until charged (%.1f%%)\nProvides %s battery runtime"),
 
299
                                                        type_desc, time_to_full_str, percentage, time_to_empty_str);
 
300
                        g_free (time_to_full_str);
 
301
                        g_free (time_to_empty_str);
 
302
 
 
303
                } else if (time_to_full_round > GPM_DKP_TEXT_MIN_TIME) {
 
304
 
 
305
                        /* display only charge time */
 
306
                        time_to_full_str = gpm_get_timestring (time_to_full_round);
 
307
 
 
308
                        /* TRANSLATORS: device is charging, and we have a time to full and a percentage */
 
309
                        description = g_strdup_printf (_("%s %s until charged (%.1f%%)"),
 
310
                                                type_desc, time_to_full_str, percentage);
 
311
                        g_free (time_to_full_str);
 
312
                } else {
 
313
 
 
314
                        /* TRANSLATORS: device is charging, but we only have a percentage */
 
315
                        description = g_strdup_printf (_("%s charging (%.1f%%)"),
 
316
                                                type_desc, percentage);
 
317
                }
 
318
 
 
319
#if DKP_CHECK_VERSION(0x009)
 
320
        } else if (state == DKP_DEVICE_STATE_PENDING_DISCHARGE) {
 
321
 
 
322
                /* TRANSLATORS: this is only shown for laptops with multiple batteries */
 
323
                description = g_strdup_printf (_("%s waiting to discharge (%.1f%%)"),
 
324
                                                type_desc, percentage);
 
325
 
 
326
        } else if (state == DKP_DEVICE_STATE_PENDING_CHARGE) {
 
327
 
 
328
                /* TRANSLATORS: this is only shown for laptops with multiple batteries */
 
329
                description = g_strdup_printf (_("%s waiting to charge (%.1f%%)"), type_desc, percentage);
 
330
#endif
 
331
 
 
332
        } else {
 
333
                egg_warning ("in an undefined state we are not charging or "
 
334
                             "discharging and the batteries are also not charged");
 
335
                description = g_strdup_printf ("%s (%.1f%%)", type_desc, percentage);
 
336
        }
 
337
        return description;
 
338
}
 
339
 
 
340
/**
 
341
 * gpm_upower_get_device_description:
 
342
 **/
 
343
gchar *
 
344
gpm_upower_get_device_description (DkpDevice *device)
 
345
{
 
346
        GString *details;
 
347
        const gchar *text;
 
348
        gchar *time_str;
 
349
        DkpDeviceType type;
 
350
        DkpDeviceState state;
 
351
        DkpDeviceTechnology technology;
 
352
        gdouble percentage;
 
353
        gdouble capacity;
 
354
        gdouble energy;
 
355
        gdouble energy_full;
 
356
        gdouble energy_full_design;
 
357
        gdouble energy_rate;
 
358
        gboolean is_present;
 
359
        gint64 time_to_full;
 
360
        gint64 time_to_empty;
 
361
        gchar *vendor = NULL;
 
362
        gchar *serial = NULL;
 
363
        gchar *model = NULL;
 
364
 
 
365
        g_return_val_if_fail (device != NULL, NULL);
 
366
 
 
367
        /* get device properties */
 
368
        g_object_get (device,
 
369
                      "type", &type,
 
370
                      "state", &state,
 
371
                      "percentage", &percentage,
 
372
                      "is-present", &is_present,
 
373
                      "time-to-full", &time_to_full,
 
374
                      "time-to-empty", &time_to_empty,
 
375
                      "technology", &technology,
 
376
                      "capacity", &capacity,
 
377
                      "energy", &energy,
 
378
                      "energy-full", &energy_full,
 
379
                      "energy-full-design", &energy_full_design,
 
380
                      "energy-rate", &energy_rate,
 
381
                      "vendor", &vendor,
 
382
                      "serial", &serial,
 
383
                      "model", &model,
 
384
                      NULL);
 
385
 
 
386
        details = g_string_new ("");
 
387
        text = gpm_device_type_to_localised_text (type, 1);
 
388
        /* TRANSLATORS: the type of data, e.g. Laptop battery */
 
389
        g_string_append_printf (details, "<b>%s</b> %s\n", _("Product:"), text);
 
390
 
 
391
        if (!is_present) {
 
392
                /* TRANSLATORS: device is missing */
 
393
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Missing"));
 
394
        } else if (state == DKP_DEVICE_STATE_FULLY_CHARGED) {
 
395
                /* TRANSLATORS: device is charged */
 
396
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Charged"));
 
397
        } else if (state == DKP_DEVICE_STATE_CHARGING) {
 
398
                /* TRANSLATORS: device is charging */
 
399
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Charging"));
 
400
        } else if (state == DKP_DEVICE_STATE_DISCHARGING) {
 
401
                /* TRANSLATORS: device is discharging */
 
402
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Status:"), _("Discharging"));
 
403
        }
 
404
 
 
405
        if (percentage >= 0) {
 
406
                /* TRANSLATORS: percentage */
 
407
                g_string_append_printf (details, "<b>%s</b> %.1f%%\n", _("Percentage charge:"), percentage);
 
408
        }
 
409
        if (vendor) {
 
410
                /* TRANSLATORS: manufacturer */
 
411
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Vendor:"), vendor);
 
412
        }
 
413
        if (technology != DKP_DEVICE_TECHNOLOGY_UNKNOWN) {
 
414
                text = gpm_device_technology_to_localised_text (technology);
 
415
                /* TRANSLATORS: how the battery is made, e.g. Lithium Ion */
 
416
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Technology:"), text);
 
417
        }
 
418
        if (serial) {
 
419
                /* TRANSLATORS: serial number of the battery */
 
420
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Serial number:"), serial);
 
421
        }
 
422
        if (model) {
 
423
                /* TRANSLATORS: model number of the battery */
 
424
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Model:"), model);
 
425
        }
 
426
        if (time_to_full > 0) {
 
427
                time_str = gpm_get_timestring (time_to_full);
 
428
                /* TRANSLATORS: time to fully charged */
 
429
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Charge time:"), time_str);
 
430
                g_free (time_str);
 
431
        }
 
432
        if (time_to_empty > 0) {
 
433
                time_str = gpm_get_timestring (time_to_empty);
 
434
                /* TRANSLATORS: time to empty */
 
435
                g_string_append_printf (details, "<b>%s</b> %s\n", _("Discharge time:"), time_str);
 
436
                g_free (time_str);
 
437
        }
 
438
        if (capacity > 0) {
 
439
                const gchar *condition;
 
440
                if (capacity > 99) {
 
441
                        /* TRANSLATORS: Excellent, Good, Fair and Poor are all related to battery Capacity */
 
442
                        condition = _("Excellent");
 
443
                } else if (capacity > 90) {
 
444
                        condition = _("Good");
 
445
                } else if (capacity > 70) {
 
446
                        condition = _("Fair");
 
447
                } else {
 
448
                        condition = _("Poor");
 
449
                }
 
450
                /* TRANSLATORS: %.1f is a percentage and %s the condition (Excellent, Good, ...) */
 
451
                g_string_append_printf (details, "<b>%s</b> %.1f%% (%s)\n",
 
452
                                        _("Capacity:"), capacity, condition);
 
453
        }
 
454
        if (type == DKP_DEVICE_TYPE_BATTERY) {
 
455
                if (energy > 0) {
 
456
                        /* TRANSLATORS: current charge */
 
457
                        g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
 
458
                                                _("Current charge:"), energy);
 
459
                }
 
460
                if (energy_full > 0 &&
 
461
                    energy_full_design != energy_full) {
 
462
                        /* TRANSLATORS: last full is the charge the battery was seen to charge to */
 
463
                        g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
 
464
                                                _("Last full charge:"), energy_full);
 
465
                }
 
466
                if (energy_full_design > 0) {
 
467
                        /* Translators:  */
 
468
                        /* TRANSLATORS: Design charge is the amount of charge the battery is designed to have when brand new */
 
469
                        g_string_append_printf (details, "<b>%s</b> %.1f Wh\n",
 
470
                                                _("Design charge:"), energy_full_design);
 
471
                }
 
472
                if (energy_rate > 0) {
 
473
                        /* TRANSLATORS: the charge or discharge rate */
 
474
                        g_string_append_printf (details, "<b>%s</b> %.1f W\n",
 
475
                                                _("Charge rate:"), energy_rate);
 
476
                }
 
477
        }
 
478
        if (type == DKP_DEVICE_TYPE_MOUSE ||
 
479
            type == DKP_DEVICE_TYPE_KEYBOARD) {
 
480
                if (energy > 0) {
 
481
                        /* TRANSLATORS: the current charge for CSR devices */
 
482
                        g_string_append_printf (details, "<b>%s</b> %.0f/7\n",
 
483
                                                _("Current charge:"), energy);
 
484
                }
 
485
                if (energy_full_design > 0) {
 
486
                        /* TRANSLATORS: the design charge for CSR devices */
 
487
                        g_string_append_printf (details, "<b>%s</b> %.0f/7\n",
 
488
                                                _("Design charge:"), energy_full_design);
 
489
                }
 
490
        }
 
491
        /* remove the last \n */
 
492
        g_string_truncate (details, details->len-1);
 
493
 
 
494
        g_free (vendor);
 
495
        g_free (serial);
 
496
        g_free (model);
 
497
        return g_string_free (details, FALSE);
 
498
}
 
499
 
 
500
/**
 
501
 * gpm_device_type_to_localised_text:
 
502
 **/
 
503
const gchar *
 
504
gpm_device_type_to_localised_text (DkpDeviceType type, guint number)
 
505
{
 
506
        const gchar *text = NULL;
 
507
        switch (type) {
 
508
        case DKP_DEVICE_TYPE_LINE_POWER:
 
509
                /* TRANSLATORS: system power cord */
 
510
                text = ngettext ("AC adapter", "AC adapters", number);
 
511
                break;
 
512
        case DKP_DEVICE_TYPE_BATTERY:
 
513
                /* TRANSLATORS: laptop primary battery */
 
514
                text = ngettext ("Laptop battery", "Laptop batteries", number);
 
515
                break;
 
516
        case DKP_DEVICE_TYPE_UPS:
 
517
                /* TRANSLATORS: battery-backed AC power source */
 
518
                text = ngettext ("UPS", "UPSs", number);
 
519
                break;
 
520
        case DKP_DEVICE_TYPE_MONITOR:
 
521
                /* TRANSLATORS: a monitor is a device to measure voltage and current */
 
522
                text = ngettext ("Monitor", "Monitors", number);
 
523
                break;
 
524
        case DKP_DEVICE_TYPE_MOUSE:
 
525
                /* TRANSLATORS: wireless mice with internal batteries */
 
526
                text = ngettext ("Wireless mouse", "Wireless mice", number);
 
527
                break;
 
528
        case DKP_DEVICE_TYPE_KEYBOARD:
 
529
                /* TRANSLATORS: wireless keyboard with internal battery */
 
530
                text = ngettext ("Wireless keyboard", "Wireless keyboards", number);
 
531
                break;
 
532
        case DKP_DEVICE_TYPE_PDA:
 
533
                /* TRANSLATORS: portable device */
 
534
                text = ngettext ("PDA", "PDAs", number);
 
535
                break;
 
536
        case DKP_DEVICE_TYPE_PHONE:
 
537
                /* TRANSLATORS: cell phone (mobile...) */
 
538
                text = ngettext ("Cell phone", "Cell phones", number);
 
539
                break;
 
540
        default:
 
541
                egg_warning ("enum unrecognised: %i", type);
 
542
                text = dkp_device_type_to_text (type);
 
543
        }
 
544
        return text;
 
545
}
 
546
 
 
547
/**
 
548
 * gpm_device_type_to_icon:
 
549
 **/
 
550
const gchar *
 
551
gpm_device_type_to_icon (DkpDeviceType type)
 
552
{
 
553
        const gchar *icon = NULL;
 
554
        switch (type) {
 
555
        case DKP_DEVICE_TYPE_LINE_POWER:
 
556
                icon = "gpm-ac-adapter";
 
557
                break;
 
558
        case DKP_DEVICE_TYPE_BATTERY:
 
559
                icon = "battery";
 
560
                break;
 
561
        case DKP_DEVICE_TYPE_UPS:
 
562
                icon = "network-wired";
 
563
                break;
 
564
        case DKP_DEVICE_TYPE_MONITOR:
 
565
                icon = "application-certificate";
 
566
                break;
 
567
        case DKP_DEVICE_TYPE_MOUSE:
 
568
                icon = "mouse";
 
569
                break;
 
570
        case DKP_DEVICE_TYPE_KEYBOARD:
 
571
                icon = "input-keyboard";
 
572
                break;
 
573
        case DKP_DEVICE_TYPE_PDA:
 
574
                icon = "input-gaming";
 
575
                break;
 
576
        case DKP_DEVICE_TYPE_PHONE:
 
577
                icon = "camera-video";
 
578
                break;
 
579
        default:
 
580
                egg_warning ("enum unrecognised: %i", type);
 
581
                icon = "gtk-help";
 
582
        }
 
583
        return icon;
 
584
}
 
585
 
 
586
/**
 
587
 * gpm_device_technology_to_localised_text:
 
588
 **/
 
589
const gchar *
 
590
gpm_device_technology_to_localised_text (DkpDeviceTechnology technology_enum)
 
591
{
 
592
        const gchar *technology = NULL;
 
593
        switch (technology_enum) {
 
594
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_ION:
 
595
                /* TRANSLATORS: battery technology */
 
596
                technology = _("Lithium Ion");
 
597
                break;
 
598
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
 
599
                /* TRANSLATORS: battery technology */
 
600
                technology = _("Lithium Polymer");
 
601
                break;
 
602
        case DKP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
 
603
                /* TRANSLATORS: battery technology */
 
604
                technology = _("Lithium Iron Phosphate");
 
605
                break;
 
606
        case DKP_DEVICE_TECHNOLOGY_LEAD_ACID:
 
607
                /* TRANSLATORS: battery technology */
 
608
                technology = _("Lead acid");
 
609
                break;
 
610
        case DKP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
 
611
                /* TRANSLATORS: battery technology */
 
612
                technology = _("Nickel Cadmium");
 
613
                break;
 
614
        case DKP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
 
615
                /* TRANSLATORS: battery technology */
 
616
                technology = _("Nickel metal hydride");
 
617
                break;
 
618
        case DKP_DEVICE_TECHNOLOGY_UNKNOWN:
 
619
                /* TRANSLATORS: battery technology */
 
620
                technology = _("Unknown technology");
 
621
                break;
 
622
        default:
 
623
                g_assert_not_reached ();
 
624
                break;
 
625
        }
 
626
        return technology;
 
627
}
 
628