~ubuntu-branches/ubuntu/maverick/devicekit-power/maverick

« back to all changes in this revision

Viewing changes to devkit-power-gobject/dkp-device.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-06 19:12:49 UTC
  • mfrom: (1.1.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20090706191249-hr0a9c2ti5u0b5lc
Tags: 009-1
* New upstream release.   
* debian/control: Add myself to uploaders (discussed with Michael).
* debian/devicekit-power.install: Upstream installs udev rules into
  /lib/udev/rules.d now, update accordingly.
* Add 0001-Add-a-notify-flag-to-set_lid_is_closed.patch: Properly fix the
  silencing of the coldplug lid event, so that the first real lid event
  actually works. Thanks to Loïc Minier! (fd.o #22574)

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
        gint64                   time_to_empty;         /* seconds */
70
70
        gint64                   time_to_full;          /* seconds */
71
71
        gdouble                  percentage;            /* percent */
 
72
        gboolean                 recall_notice;
 
73
        gchar                   *recall_vendor;
 
74
        gchar                   *recall_url;
72
75
};
73
76
 
74
77
enum {
96
99
        PROP_VOLTAGE,
97
100
        PROP_TIME_TO_EMPTY,
98
101
        PROP_TIME_TO_FULL,
99
 
        PROP_PERCENTAGE
 
102
        PROP_PERCENTAGE,
 
103
        PROP_RECALL_NOTICE,
 
104
        PROP_RECALL_VENDOR,
 
105
        PROP_RECALL_URL,
 
106
        PROP_LAST
100
107
};
101
108
 
102
109
enum {
188
195
                device->priv->capacity = g_value_get_double (value);
189
196
        else if (g_strcmp0 (key, "state") == 0)
190
197
                device->priv->state = g_value_get_uint (value);
191
 
        else {
 
198
        else if (g_strcmp0 (key, "recall-notice") == 0)
 
199
                device->priv->recall_notice = g_value_get_boolean (value);
 
200
        else if (g_strcmp0 (key, "recall-vendor") == 0)
 
201
                device->priv->recall_vendor = g_strdup (g_value_get_string (value));
 
202
        else if (g_strcmp0 (key, "recall-url") == 0)
 
203
                device->priv->recall_url = g_strdup (g_value_get_string (value));
 
204
        else
192
205
                g_warning ("unhandled property '%s'", key);
193
 
                g_assert_not_reached ();
194
 
        }
195
206
}
196
207
 
197
208
/**
382
393
        strftime (time_buf, sizeof time_buf, "%c", time_tm);
383
394
 
384
395
        g_print ("  native-path:          %s\n", device->priv->native_path);
385
 
        if (device->priv->vendor != NULL)
 
396
        if (device->priv->vendor != NULL && device->priv->vendor[0] != '\0')
386
397
                g_print ("  vendor:               %s\n", device->priv->vendor);
387
 
        if (device->priv->model != NULL)
 
398
        if (device->priv->model != NULL && device->priv->model[0] != '\0')
388
399
                g_print ("  model:                %s\n", device->priv->model);
389
 
        if (device->priv->serial != NULL)
 
400
        if (device->priv->serial != NULL && device->priv->serial[0] != '\0')
390
401
                g_print ("  serial:               %s\n", device->priv->serial);
391
402
        g_print ("  power supply:         %s\n", dkp_device_print_bool_to_text (device->priv->power_supply));
392
403
        g_print ("  updated:              %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - device->priv->update_time));
405
416
                g_print ("    rechargeable:        %s\n", dkp_device_print_bool_to_text (device->priv->is_rechargeable));
406
417
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
407
418
            device->priv->type == DKP_DEVICE_TYPE_MOUSE ||
408
 
            device->priv->type == DKP_DEVICE_TYPE_KEYBOARD)
 
419
            device->priv->type == DKP_DEVICE_TYPE_KEYBOARD ||
 
420
            device->priv->type == DKP_DEVICE_TYPE_UPS)
409
421
                g_print ("    state:               %s\n", dkp_device_state_to_text (device->priv->state));
410
422
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
411
423
                g_print ("    energy:              %g Wh\n", device->priv->energy);
418
430
                g_print ("    energy-rate:         %g W\n", device->priv->energy_rate);
419
431
        if (device->priv->type == DKP_DEVICE_TYPE_UPS ||
420
432
            device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
421
 
            device->priv->type == DKP_DEVICE_TYPE_MONITOR)
422
 
                g_print ("    voltage:             %g V\n", device->priv->voltage);
 
433
            device->priv->type == DKP_DEVICE_TYPE_MONITOR) {
 
434
                if (device->priv->voltage > 0)
 
435
                        g_print ("    voltage:             %g V\n", device->priv->voltage);
 
436
        }
423
437
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
424
438
            device->priv->type == DKP_DEVICE_TYPE_UPS) {
425
 
                if (device->priv->time_to_full >= 0) {
 
439
                if (device->priv->time_to_full > 0) {
426
440
                        time_str = dkp_device_print_time_to_text (device->priv->time_to_full);
427
441
                        g_print ("    time to full:        %s\n", time_str);
428
442
                        g_free (time_str);
429
443
                }
430
 
                if (device->priv->time_to_empty >= 0) {
 
444
                if (device->priv->time_to_empty > 0) {
431
445
                        time_str = dkp_device_print_time_to_text (device->priv->time_to_empty);
432
446
                        g_print ("    time to empty:       %s\n", time_str);
433
447
                        g_free (time_str);
438
452
            device->priv->type == DKP_DEVICE_TYPE_KEYBOARD ||
439
453
            device->priv->type == DKP_DEVICE_TYPE_UPS)
440
454
                g_print ("    percentage:          %g%%\n", device->priv->percentage);
441
 
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY)
442
 
                g_print ("    capacity:            %g%%\n", device->priv->capacity);
443
 
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY)
444
 
                g_print ("    technology:          %s\n", dkp_device_technology_to_text (device->priv->technology));
 
455
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
 
456
                if (device->priv->capacity > 0)
 
457
                        g_print ("    capacity:            %g%%\n", device->priv->capacity);
 
458
        }
 
459
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
 
460
                if (device->priv->technology != DKP_DEVICE_TECHNOLOGY_UNKNOWN)
 
461
                        g_print ("    technology:          %s\n", dkp_device_technology_to_text (device->priv->technology));
 
462
        }
445
463
        if (device->priv->type == DKP_DEVICE_TYPE_LINE_POWER)
446
464
                g_print ("    online:             %s\n", dkp_device_print_bool_to_text (device->priv->online));
 
465
        if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
 
466
                if (device->priv->recall_notice) {
 
467
                        g_print ("    recall vendor:       %s\n", device->priv->recall_vendor);
 
468
                        g_print ("    recall url:          %s\n", device->priv->recall_url);
 
469
                }
 
470
        }
447
471
 
448
472
        /* if we can, get history */
449
473
        if (device->priv->has_history) {
715
739
        case PROP_TECHNOLOGY:
716
740
                device->priv->technology = g_value_get_uint (value);
717
741
                break;
 
742
        case PROP_RECALL_NOTICE:
 
743
                device->priv->recall_notice = g_value_get_boolean (value);
 
744
                break;
 
745
        case PROP_RECALL_VENDOR:
 
746
                g_free (device->priv->recall_vendor);
 
747
                device->priv->recall_vendor = g_strdup (g_value_get_string (value));
 
748
                break;
 
749
        case PROP_RECALL_URL:
 
750
                g_free (device->priv->recall_url);
 
751
                device->priv->recall_url = g_strdup (g_value_get_string (value));
 
752
                break;
718
753
        default:
719
754
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
720
755
                break;
802
837
        case PROP_PERCENTAGE:
803
838
                g_value_set_double (value, device->priv->percentage);
804
839
                break;
 
840
        case PROP_RECALL_NOTICE:
 
841
                g_value_set_boolean (value, device->priv->recall_notice);
 
842
                break;
 
843
        case PROP_RECALL_VENDOR:
 
844
                g_value_set_string (value, device->priv->recall_vendor);
 
845
                break;
 
846
        case PROP_RECALL_URL:
 
847
                g_value_set_string (value, device->priv->recall_url);
 
848
                break;
805
849
        default:
806
850
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
807
851
                break;
1047
1091
                                         g_param_spec_double ("percentage", NULL, NULL,
1048
1092
                                                              0.0, 100.f, 100.0,
1049
1093
                                                              G_PARAM_READWRITE));
 
1094
        /**
 
1095
         * DkpDevice:recall-notice:
 
1096
         */
 
1097
        g_object_class_install_property (object_class,
 
1098
                                         PROP_RECALL_NOTICE,
 
1099
                                         g_param_spec_boolean ("recall-notice",
 
1100
                                                               NULL, NULL,
 
1101
                                                               FALSE,
 
1102
                                                               G_PARAM_READWRITE));
 
1103
        /**
 
1104
         * DkpDevice:recall-vendor:
 
1105
         */
 
1106
        g_object_class_install_property (object_class,
 
1107
                                         PROP_RECALL_VENDOR,
 
1108
                                         g_param_spec_string ("recall-vendor",
 
1109
                                                              NULL, NULL,
 
1110
                                                              NULL,
 
1111
                                                              G_PARAM_READWRITE));
 
1112
        /**
 
1113
         * DkpDevice:recall-url:
 
1114
         */
 
1115
        g_object_class_install_property (object_class,
 
1116
                                         PROP_RECALL_URL,
 
1117
                                         g_param_spec_string ("recall-url",
 
1118
                                                              NULL, NULL,
 
1119
                                                              NULL,
 
1120
                                                              G_PARAM_READWRITE));
1050
1121
 
1051
1122
        g_type_class_add_private (klass, sizeof (DkpDevicePrivate));
1052
1123
}
1082
1153
        g_free (device->priv->model);
1083
1154
        g_free (device->priv->serial);
1084
1155
        g_free (device->priv->native_path);
 
1156
        g_free (device->priv->recall_vendor);
 
1157
        g_free (device->priv->recall_url);
1085
1158
        if (device->priv->proxy_device != NULL)
1086
1159
                g_object_unref (device->priv->proxy_device);
1087
1160
        if (device->priv->proxy_props != NULL)