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

« back to all changes in this revision

Viewing changes to src/cd-main.c

  • Committer: Package Import Robot
  • Author(s): Sjoerd Simons
  • Date: 2011-10-25 16:21:20 UTC
  • mto: (2.1.1 sid) (1.1.2)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: package-import@ubuntu.com-20111025162120-0aypjqn1zx9n6vgf
Tags: upstream-0.1.13
ImportĀ upstreamĀ versionĀ 0.1.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
239
239
}
240
240
 
241
241
/**
 
242
 * cd_main_device_auto_add_profile:
 
243
 **/
 
244
static gboolean
 
245
cd_main_device_auto_add_profile (CdDevice *device, CdProfile *profile)
 
246
{
 
247
        gboolean ret = FALSE;
 
248
        GError *error = NULL;
 
249
        guint64 timestamp;
 
250
 
 
251
        g_debug ("CdMain: Automatically add %s to %s",
 
252
                 cd_profile_get_id (profile),
 
253
                 cd_device_get_object_path (device));
 
254
        timestamp = cd_mapping_db_get_timestamp (mapping_db,
 
255
                                                 cd_device_get_id (device),
 
256
                                                 cd_profile_get_id (profile),
 
257
                                                 &error);
 
258
        if (timestamp == G_MAXUINT64) {
 
259
                g_debug ("CdMain: failed to assign, non-fatal: %s",
 
260
                         error->message);
 
261
                g_error_free (error);
 
262
                goto out;
 
263
        }
 
264
        ret = cd_device_add_profile (device,
 
265
                                     CD_DEVICE_RELATION_HARD,
 
266
                                     cd_profile_get_object_path (profile),
 
267
                                     timestamp,
 
268
                                     &error);
 
269
        if (!ret) {
 
270
                g_debug ("CdMain: failed to assign, non-fatal: %s",
 
271
                         error->message);
 
272
                g_error_free (error);
 
273
                goto out;
 
274
        }
 
275
out:
 
276
        return ret;
 
277
}
 
278
 
 
279
/**
242
280
 * cd_main_device_auto_add_profiles:
243
281
 **/
244
282
static void
246
284
{
247
285
        CdProfile *profile_tmp;
248
286
        const gchar *object_id_tmp;
249
 
        gboolean ret;
250
287
        GError *error = NULL;
251
288
        GPtrArray *array;
252
289
        guint i;
268
305
                profile_tmp = cd_profile_array_get_by_id (profiles_array,
269
306
                                                          object_id_tmp);
270
307
                if (profile_tmp != NULL) {
271
 
                        g_debug ("CdMain: Automatically add %s to %s",
272
 
                                 object_id_tmp,
273
 
                                 cd_device_get_object_path (device));
274
 
                        ret = cd_device_add_profile (device,
275
 
                                                     CD_DEVICE_RELATION_HARD,
276
 
                                                     cd_profile_get_object_path (profile_tmp),
277
 
                                                     &error);
278
 
                        if (!ret) {
279
 
                                g_debug ("CdMain: failed to assign, non-fatal: %s",
280
 
                                         error->message);
281
 
                                g_clear_error (&error);
282
 
                        }
 
308
                        cd_main_device_auto_add_profile (device, profile_tmp);
283
309
                        g_object_unref (profile_tmp);
284
310
                } else {
285
311
                        g_debug ("CdMain: profile %s is not (yet) available",
502
528
{
503
529
        CdDevice *device_tmp;
504
530
        const gchar *device_id_tmp;
505
 
        gboolean ret;
506
531
        GError *error = NULL;
507
532
        GPtrArray *array;
508
533
        guint i;
531
556
                device_tmp = cd_device_array_get_by_id (devices_array,
532
557
                                                        device_id_tmp);
533
558
                if (device_tmp != NULL) {
534
 
                        g_debug ("CdMain: Automatically add %s to %s",
535
 
                                 cd_profile_get_object_path (profile),
536
 
                                 device_id_tmp);
537
 
                        ret = cd_device_add_profile (device_tmp,
538
 
                                                     CD_DEVICE_RELATION_HARD,
539
 
                                                     cd_profile_get_object_path (profile),
540
 
                                                     &error);
541
 
                        if (!ret) {
542
 
                                g_debug ("CdMain: failed to assign, non-fatal: %s",
543
 
                                         error->message);
544
 
                                g_clear_error (&error);
545
 
                        }
 
559
                        cd_main_device_auto_add_profile (device_tmp, profile);
546
560
                        g_object_unref (device_tmp);
547
561
                } else {
548
562
                        g_debug ("CdMain: device %s is not (yet) available",
657
671
        GVariant *tuple = NULL;
658
672
        GVariant *value = NULL;
659
673
        gint fd = -1;
 
674
        guint uid;
660
675
        const gchar *metadata_key = NULL;
661
676
        const gchar *metadata_value = NULL;
662
677
        GDBusMessage *message;
857
872
 
858
873
                /* require auth */
859
874
                ret = cd_main_sender_authenticated (invocation,
860
 
                                                    sender,
861
875
                                                    "org.freedesktop.color-manager.create-device");
862
876
                if (!ret)
863
877
                        goto out;
871
885
                g_debug ("CdMain: %s:CreateDevice(%s)", sender, device_id);
872
886
                scope = cd_object_scope_from_string (scope_tmp);
873
887
                device = cd_device_array_get_by_id (devices_array, device_id);
874
 
                if (device == NULL) {
875
 
                        device = cd_main_create_device (sender,
876
 
                                                        device_id,
877
 
                                                        scope,
878
 
                                                        CD_DEVICE_MODE_UNKNOWN,
879
 
                                                        &error);
880
 
                        if (device == NULL) {
881
 
                                g_warning ("CdMain: failed to create device: %s",
882
 
                                           error->message);
883
 
                                g_dbus_method_invocation_return_gerror (invocation,
884
 
                                                                        error);
885
 
                                g_error_free (error);
886
 
                                goto out;
887
 
                        }
888
 
                } else {
 
888
                if (device != NULL) {
889
889
                        /* where we try to manually add an existing
890
890
                         * virtual device, which means promoting it to
891
891
                         * an actual physical device */
892
 
                        cd_device_set_mode (device,
893
 
                                            CD_DEVICE_MODE_PHYSICAL);
894
 
 
895
 
                        /* not new device */
896
 
                        register_on_bus = FALSE;
897
 
                }
 
892
                        if (cd_device_get_mode (device) == CD_DEVICE_MODE_VIRTUAL) {
 
893
                                cd_device_set_mode (device,
 
894
                                                    CD_DEVICE_MODE_PHYSICAL);
 
895
                                register_on_bus = FALSE;
 
896
                        } else {
 
897
                                g_dbus_method_invocation_return_error (invocation,
 
898
                                                                       CD_MAIN_ERROR,
 
899
                                                                       CD_MAIN_ERROR_ALREADY_EXISTS,
 
900
                                                                       "device id '%s' already exists",
 
901
                                                                       device_id);
 
902
                                goto out;
 
903
                        }
 
904
                }
 
905
 
 
906
                /* create device */
 
907
                device = cd_main_create_device (sender,
 
908
                                                device_id,
 
909
                                                scope,
 
910
                                                CD_DEVICE_MODE_UNKNOWN,
 
911
                                                &error);
 
912
                if (device == NULL) {
 
913
                        g_warning ("CdMain: failed to create device: %s",
 
914
                                   error->message);
 
915
                        g_dbus_method_invocation_return_gerror (invocation,
 
916
                                                                error);
 
917
                        g_error_free (error);
 
918
                        goto out;
 
919
                }
 
920
 
 
921
                /* set the owner */
 
922
                uid = cd_main_get_sender_uid (invocation, &error);
 
923
                if (uid == G_MAXUINT) {
 
924
                        g_dbus_method_invocation_return_error (invocation,
 
925
                                                               CD_MAIN_ERROR,
 
926
                                                               CD_MAIN_ERROR_FAILED,
 
927
                                                               "failed to get owner: %s",
 
928
                                                               error->message);
 
929
                        g_error_free (error);
 
930
                        goto out;
 
931
                }
 
932
                cd_device_set_owner (device, uid);
898
933
 
899
934
                /* set the properties */
900
935
                while (g_variant_iter_next (iter, "{&s&s}",
937
972
 
938
973
                /* require auth */
939
974
                ret = cd_main_sender_authenticated (invocation,
940
 
                                                    sender,
941
975
                                                    "org.freedesktop.color-manager.delete-device");
942
976
                if (!ret)
943
977
                        goto out;
973
1007
 
974
1008
                /* require auth */
975
1009
                ret = cd_main_sender_authenticated (invocation,
976
 
                                                    sender,
977
1010
                                                    "org.freedesktop.color-manager.create-profile");
978
1011
                if (!ret)
979
1012
                        goto out;
1009
1042
 
1010
1043
                /* require auth */
1011
1044
                ret = cd_main_sender_authenticated (invocation,
1012
 
                                                    sender,
1013
1045
                                                    "org.freedesktop.color-manager.create-profile");
1014
1046
                if (!ret)
1015
1047
                        goto out;
1022
1054
                g_debug ("CdMain: %s:CreateProfile(%s)", sender, device_id);
1023
1055
                profile = cd_profile_array_get_by_id (profiles_array,
1024
1056
                                                      device_id);
 
1057
                if (profile != NULL) {
 
1058
                        g_dbus_method_invocation_return_error (invocation,
 
1059
                                                               CD_MAIN_ERROR,
 
1060
                                                               CD_MAIN_ERROR_ALREADY_EXISTS,
 
1061
                                                               "profile id '%s' already exists",
 
1062
                                                               device_id);
 
1063
                        goto out;
 
1064
                }
1025
1065
                scope = cd_object_scope_from_string (scope_tmp);
 
1066
                profile = cd_main_create_profile (sender,
 
1067
                                                  device_id,
 
1068
                                                  scope,
 
1069
                                                  &error);
1026
1070
                if (profile == NULL) {
1027
 
                        profile = cd_main_create_profile (sender,
1028
 
                                                          device_id,
1029
 
                                                          scope,
1030
 
                                                          &error);
1031
 
                        if (profile == NULL) {
1032
 
                                g_dbus_method_invocation_return_gerror (invocation,
1033
 
                                                                        error);
1034
 
                                goto out;
1035
 
                        }
1036
 
                } else {
1037
 
                        /* not new profile */
1038
 
                        register_on_bus = FALSE;
1039
 
                }
 
1071
                        g_dbus_method_invocation_return_gerror (invocation,
 
1072
                                                                error);
 
1073
                        goto out;
 
1074
                }
 
1075
 
 
1076
                /* set the owner */
 
1077
                uid = cd_main_get_sender_uid (invocation, &error);
 
1078
                if (uid == G_MAXUINT) {
 
1079
                        g_dbus_method_invocation_return_error (invocation,
 
1080
                                                               CD_MAIN_ERROR,
 
1081
                                                               CD_MAIN_ERROR_FAILED,
 
1082
                                                               "failed to get owner: %s",
 
1083
                                                               error->message);
 
1084
                        g_error_free (error);
 
1085
                        goto out;
 
1086
                }
 
1087
                cd_profile_set_owner (profile, uid);
1040
1088
 
1041
1089
                /* auto add profiles from the database */
1042
1090
                cd_main_profile_auto_add_to_device (profile);
1085
1133
                }
1086
1134
 
1087
1135
                /* register on bus */
1088
 
                if (register_on_bus) {
1089
 
                        ret = cd_main_profile_register_on_bus (profile, &error);
1090
 
                        if (!ret) {
1091
 
                                g_dbus_method_invocation_return_gerror (invocation,
1092
 
                                                                        error);
1093
 
                                g_error_free (error);
1094
 
                                goto out;
1095
 
                        }
 
1136
                ret = cd_main_profile_register_on_bus (profile, &error);
 
1137
                if (!ret) {
 
1138
                        g_dbus_method_invocation_return_gerror (invocation,
 
1139
                                                                error);
 
1140
                        g_error_free (error);
 
1141
                        goto out;
1096
1142
                }
1097
1143
 
1098
1144
                /* format the value */
1178
1224
        profile_id = g_strdup_printf ("icc-%s",
1179
1225
                                      cd_profile_get_checksum (profile));
1180
1226
        cd_profile_set_id (profile, profile_id);
1181
 
        cd_profile_set_is_system_wide (profile, TRUE);
1182
1227
        ret = cd_main_add_profile (profile, &error);
1183
1228
        if (!ret) {
1184
1229
                g_warning ("CdMain: failed to add profile: %s",