~ubuntu-branches/ubuntu/quantal/colord/quantal-proposed

« back to all changes in this revision

Viewing changes to libcolord/cd-device.c

  • Committer: Package Import Robot
  • Author(s): Christopher James Halse Rogers
  • Date: 2012-03-01 17:33:00 UTC
  • mto: (1.1.4) (2.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20120301173300-q1s2bs8yubnybln8
ImportĀ upstreamĀ versionĀ 0.1.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        gchar                   *serial;
64
64
        gchar                   *format;
65
65
        gchar                   *vendor;
 
66
        gchar                   **profiling_inhibitors;
66
67
        guint64                  created;
67
68
        guint64                  modified;
68
69
        GPtrArray               *profiles;
90
91
        PROP_MODE,
91
92
        PROP_SCOPE,
92
93
        PROP_OWNER,
 
94
        PROP_PROFILING_INHIBITORS,
93
95
        PROP_LAST
94
96
};
95
97
 
226
228
}
227
229
 
228
230
/**
 
231
 * cd_device_get_profiling_inhibitors:
 
232
 * @device: a #CdDevice instance.
 
233
 *
 
234
 * Gets any profiling inhibitors for the device.
 
235
 *
 
236
 * Return value: (transfer none): A strv, or %NULL for invalid
 
237
 *
 
238
 * Since: 0.1.17
 
239
 **/
 
240
const gchar **
 
241
cd_device_get_profiling_inhibitors (CdDevice *device)
 
242
{
 
243
        g_return_val_if_fail (CD_IS_DEVICE (device), NULL);
 
244
        g_return_val_if_fail (device->priv->proxy != NULL, NULL);
 
245
        return (const gchar **) device->priv->profiling_inhibitors;
 
246
}
 
247
 
 
248
/**
229
249
 * cd_device_get_created:
230
250
 * @device: a #CdDevice instance.
231
251
 *
404
424
        gchar *object_path_tmp;
405
425
        gsize len;
406
426
        guint i;
407
 
        GVariantIter iter;
408
427
 
409
428
        g_ptr_array_set_size (device->priv->profiles, 0);
410
429
        if (profiles == NULL)
411
430
                goto out;
412
 
        len = g_variant_iter_init (&iter, profiles);
 
431
        len = g_variant_n_children (profiles);
413
432
        for (i=0; i<len; i++) {
414
433
                g_variant_get_child (profiles, i,
415
434
                                     "o", &object_path_tmp);
464
483
static void
465
484
cd_device_set_metadata_from_variant (CdDevice *device, GVariant *variant)
466
485
{
467
 
        GVariantIter *iter = NULL;
 
486
        GVariantIter iter;
468
487
        const gchar *prop_key;
469
488
        const gchar *prop_value;
470
489
 
472
491
        g_hash_table_remove_all (device->priv->metadata);
473
492
 
474
493
        /* insert the new metadata */
475
 
        g_variant_get (variant, "a{ss}",
476
 
                       &iter);
477
 
        while (g_variant_iter_loop (iter, "{ss}",
 
494
        g_variant_iter_init (&iter, variant);
 
495
        while (g_variant_iter_loop (&iter, "{ss}",
478
496
                                    &prop_key, &prop_value)) {
479
497
                g_hash_table_insert (device->priv->metadata,
480
498
                                     g_strdup (prop_key),
484
502
}
485
503
 
486
504
/**
 
505
 * cd_device_get_nullable_str:
 
506
 *
 
507
 * We can't get nullable types from a GVariant yet. Work around...
 
508
 **/
 
509
static gchar *
 
510
cd_device_get_nullable_str (GVariant *value)
 
511
{
 
512
        const gchar *tmp;
 
513
        tmp = g_variant_get_string (value, NULL);
 
514
        if (tmp == NULL)
 
515
                return NULL;
 
516
        if (tmp[0] == '\0')
 
517
                return NULL;
 
518
        return g_strdup (tmp);
 
519
}
 
520
 
 
521
/**
487
522
 * cd_device_dbus_properties_changed_cb:
488
523
 **/
489
524
static void
508
543
                                     &property_value);
509
544
                if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_MODEL) == 0) {
510
545
                        g_free (device->priv->model);
511
 
                        device->priv->model = g_variant_dup_string (property_value, NULL);
 
546
                        device->priv->model = cd_device_get_nullable_str (property_value);
512
547
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_SERIAL) == 0) {
513
548
                        g_free (device->priv->serial);
514
 
                        device->priv->serial = g_variant_dup_string (property_value, NULL);
 
549
                        device->priv->serial = cd_device_get_nullable_str (property_value);
515
550
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_FORMAT) == 0) {
516
551
                        g_free (device->priv->format);
517
 
                        device->priv->format = g_variant_dup_string (property_value, NULL);
 
552
                        device->priv->format = cd_device_get_nullable_str (property_value);
518
553
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_VENDOR) == 0) {
519
554
                        g_free (device->priv->vendor);
520
 
                        device->priv->vendor = g_variant_dup_string (property_value, NULL);
 
555
                        device->priv->vendor = cd_device_get_nullable_str (property_value);
 
556
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_PROFILING_INHIBITORS) == 0) {
 
557
                        g_free (device->priv->profiling_inhibitors);
 
558
                        device->priv->profiling_inhibitors = g_variant_dup_strv (property_value, NULL);
521
559
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_KIND) == 0) {
522
560
                        device->priv->kind =
523
561
                                cd_device_kind_from_string (g_variant_get_string (property_value, NULL));
536
574
                        device->priv->modified = g_variant_get_uint64 (property_value);
537
575
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_METADATA) == 0) {
538
576
                        cd_device_set_metadata_from_variant (device, property_value);
 
577
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_OWNER) == 0) {
 
578
                        device->priv->owner = g_variant_get_uint32 (property_value);
539
579
                } else if (g_strcmp0 (property_name, CD_DEVICE_PROPERTY_ID) == 0) {
540
580
                        /* ignore this, we don't support it changing */;
541
581
                } else {
614
654
        GVariant *serial = NULL;
615
655
        GVariant *format = NULL;
616
656
        GVariant *vendor = NULL;
 
657
        GVariant *profiling_inhibitors = NULL;
617
658
        GVariant *colorspace = NULL;
618
659
        GVariant *scope = NULL;
619
660
        GVariant *owner = NULL;
641
682
        id = g_dbus_proxy_get_cached_property (device->priv->proxy,
642
683
                                               CD_DEVICE_PROPERTY_ID);
643
684
        if (id != NULL)
644
 
                device->priv->id = g_variant_dup_string (id, NULL);
 
685
                device->priv->id = cd_device_get_nullable_str (id);
645
686
 
646
687
        /* if the device is missing, then fail */
647
688
        if (id == NULL) {
691
732
        model = g_dbus_proxy_get_cached_property (device->priv->proxy,
692
733
                                                  CD_DEVICE_PROPERTY_MODEL);
693
734
        if (model != NULL)
694
 
                device->priv->model = g_variant_dup_string (model, NULL);
 
735
                device->priv->model = cd_device_get_nullable_str (model);
695
736
 
696
737
        /* get serial */
697
738
        serial = g_dbus_proxy_get_cached_property (device->priv->proxy,
698
739
                                                   CD_DEVICE_PROPERTY_SERIAL);
699
740
        if (serial != NULL)
700
 
                device->priv->serial = g_variant_dup_string (serial, NULL);
 
741
                device->priv->serial = cd_device_get_nullable_str (serial);
701
742
 
702
743
        /* get format */
703
744
        format = g_dbus_proxy_get_cached_property (device->priv->proxy,
704
745
                                                   CD_DEVICE_PROPERTY_FORMAT);
705
746
        if (format != NULL)
706
 
                device->priv->format = g_variant_dup_string (format, NULL);
 
747
                device->priv->format = cd_device_get_nullable_str (format);
707
748
 
708
749
        /* get vendor */
709
750
        vendor = g_dbus_proxy_get_cached_property (device->priv->proxy,
710
751
                                                   CD_DEVICE_PROPERTY_VENDOR);
711
752
        if (vendor != NULL)
712
 
                device->priv->vendor = g_variant_dup_string (vendor, NULL);
 
753
                device->priv->vendor = cd_device_get_nullable_str (vendor);
 
754
 
 
755
        /* get profiling inhibitors */
 
756
        profiling_inhibitors = g_dbus_proxy_get_cached_property (device->priv->proxy,
 
757
                                                                 CD_DEVICE_PROPERTY_PROFILING_INHIBITORS);
 
758
        if (profiling_inhibitors != NULL)
 
759
                device->priv->profiling_inhibitors = g_variant_dup_strv (profiling_inhibitors, NULL);
713
760
 
714
761
        /* get created */
715
762
        created = g_dbus_proxy_get_cached_property (device->priv->proxy,
755
802
                g_variant_unref (model);
756
803
        if (vendor != NULL)
757
804
                g_variant_unref (vendor);
 
805
        if (profiling_inhibitors != NULL)
 
806
                g_variant_unref (profiling_inhibitors);
758
807
        if (serial != NULL)
759
808
                g_variant_unref (serial);
760
809
        if (format != NULL)
1819
1868
        case PROP_VENDOR:
1820
1869
                g_value_set_string (value, device->priv->vendor);
1821
1870
                break;
 
1871
        case PROP_PROFILING_INHIBITORS:
 
1872
                g_value_set_boxed (value, device->priv->profiling_inhibitors);
 
1873
                break;
1822
1874
        case PROP_KIND:
1823
1875
                g_value_set_uint (value, device->priv->kind);
1824
1876
                break;
1984
2036
                                                              NULL,
1985
2037
                                                              G_PARAM_READABLE));
1986
2038
        /**
 
2039
         * CdDevice:profiling_inhibitors:
 
2040
         *
 
2041
         * Any profiling inhibitors.
 
2042
         *
 
2043
         * Since: 0.1.17
 
2044
         **/
 
2045
        g_object_class_install_property (object_class,
 
2046
                                         PROP_PROFILING_INHIBITORS,
 
2047
                                         g_param_spec_boxed ("profiling-inhibitors",
 
2048
                                                              NULL, NULL,
 
2049
                                                              G_TYPE_STRV,
 
2050
                                                              G_PARAM_READABLE));
 
2051
        /**
1987
2052
         * CdDevice:kind:
1988
2053
         *
1989
2054
         * The device kind, e.g. %CD_DEVICE_KIND_KEYBOARD.
2099
2164
        g_free (device->priv->serial);
2100
2165
        g_free (device->priv->format);
2101
2166
        g_free (device->priv->vendor);
 
2167
        g_strfreev (device->priv->profiling_inhibitors);
2102
2168
        g_ptr_array_unref (device->priv->profiles);
2103
2169
        if (device->priv->proxy != NULL) {
2104
2170
                ret = g_signal_handlers_disconnect_by_func (device->priv->proxy,