/** * cd_sane_add_device_if_from_colord_sane **/ static void cd_sane_add_device_if_from_colord_sane (gpointer data, gpointer user_data) { CdDevice *device = (CdDevice *) data; CdMainDev *sane_device; CdMainPrivate *priv = (CdMainPrivate *) user_data; const gchar *cmdline; gboolean ret; GError *error = NULL; ret = cd_device_connect_sync (device, NULL, &error); if (!ret) { g_warning ("failed to receive list of devices: %s", error->message); g_error_free (error); return; } cmdline = cd_device_get_metadata_item (device, CD_DEVICE_METADATA_OWNER_CMDLINE); if (g_strcmp0 (cmdline, priv->argv0) == 0) { sane_device = g_new (CdMainDev, 1); sane_device->device = g_object_ref (device); sane_device->id = (gchar *)cd_device_get_id (device); sane_device->valid = FALSE; g_ptr_array_add (priv->array, sane_device); } }
/** * cd_edid_install_profile: * @scope: where to install the profile, e.g. %CD_EDID_SCOPE_USER * @edid: the EDID data, typically just 128 bytes in size * @edid_len: the size in bytes of @edid_len * @profile_fn: the profile filename to install * * Install a profile for a given monitor. * * Return value: a %CdEdidError, e.g. %CD_EDID_ERROR_OK * * Since: 0.1.34 **/ CdEdidError cd_edid_install_profile (unsigned char *edid, int edid_len, CdEdidScope scope, char *profile_fn) { CdClient *client = NULL; CdDevice *device = NULL; CdEdidError rc = CD_EDID_ERROR_OK; CdProfile *profile = NULL; gboolean ret; gchar *md5 = NULL; GError *error = NULL; GFile *file; g_return_val_if_fail (profile_fn != NULL, CD_EDID_ERROR_RESOURCE); /* bad input */ if (edid == NULL || edid_len == 0) { rc = CD_EDID_ERROR_NO_DATA; goto out; } /* conect to daemon */ client = cd_client_new (); ret = cd_client_connect_sync (client, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_ACCESS_CONFIG; g_warning ("Failed to connect to colord: %s", error->message); g_error_free (error); goto out; } /* find device that matches the output EDID */ md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, (const gchar *)edid, (gssize) edid_len); device = cd_client_find_device_by_property_sync (client, CD_DEVICE_METADATA_OUTPUT_EDID_MD5, md5, NULL, &error); if (device == NULL) { rc = CD_EDID_ERROR_MONITOR_NOT_FOUND; g_warning ("Failed to find device that matches %s: %s", md5, error->message); g_error_free (error); goto out; } /* read device properties */ ret = cd_device_connect_sync (device, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_ACCESS_CONFIG; g_warning ("device disappeared: %s", error->message); g_error_free (error); goto out; } /* import profile */ file = g_file_new_for_path (profile_fn); profile = cd_client_import_profile_sync (client, file, NULL, &error); if (profile == NULL) { rc = CD_EDID_ERROR_NO_PROFILE; g_warning ("Could not import profile %s: %s", profile_fn, error->message); g_error_free (error); goto out; } /* add profile to device */ ret = cd_device_add_profile_sync (device, CD_DEVICE_RELATION_HARD, profile, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_SET_CONFIG; g_warning ("could not add profile %s to device %s: %s", cd_profile_get_id (profile), cd_device_get_id (device), error->message); g_error_free (error); goto out; } /* install system-wide */ if (scope == CD_EDID_SCOPE_SYSTEM) { ret = cd_profile_install_system_wide_sync (profile, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_PROFILE_COPY; g_warning ("could not set profile %s systemwide: %s", cd_profile_get_id (profile), error->message); g_error_free (error); goto out; } } out: if (client != NULL) g_object_unref (client); if (device != NULL) g_object_unref (device); if (profile != NULL) g_object_unref (profile); g_free (md5); return rc; }
/** * cd_edid_get_profile: * @edid: the EDID data, typically just 128 bytes in size * @edid_len: the size in bytes of @edid_len * @profile_fn: the returned profile filename, use free() when done * * Get an associated monitor profile. * * Return value: a %CdEdidError, e.g. %CD_EDID_ERROR_OK * * Since: 0.1.34 **/ CdEdidError cd_edid_get_profile (unsigned char *edid, int edid_len, char **profile_fn) { CdClient *client = NULL; CdDevice *device = NULL; CdProfile *profile = NULL; const gchar *filename; gboolean ret; gchar *md5 = NULL; GError *error = NULL; CdEdidError rc = CD_EDID_ERROR_OK; /* bad input */ if (edid == NULL || edid_len == 0) { rc = CD_EDID_ERROR_NO_DATA; goto out; } /* conect to daemon */ client = cd_client_new (); ret = cd_client_connect_sync (client, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_ACCESS_CONFIG; g_warning ("Failed to connect to colord: %s", error->message); g_error_free (error); goto out; } /* find device that matches the output EDID */ md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, (const gchar *)edid, (gssize) edid_len); device = cd_client_find_device_by_property_sync (client, CD_DEVICE_METADATA_OUTPUT_EDID_MD5, md5, NULL, &error); if (device == NULL) { rc = CD_EDID_ERROR_MONITOR_NOT_FOUND; g_warning ("Failed to find device that matches %s: %s", md5, error->message); g_error_free (error); goto out; } /* read device properties */ ret = cd_device_connect_sync (device, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_ACCESS_CONFIG; g_warning ("device disappeared: %s", error->message); g_error_free (error); goto out; } /* get the default profile for the device */ profile = cd_device_get_default_profile (device); if (profile == NULL) { rc = CD_EDID_ERROR_NO_PROFILE; g_warning ("No profile for %s: %s", cd_device_get_id (device), error->message); g_error_free (error); goto out; } /* read profile properties */ ret = cd_profile_connect_sync (profile, NULL, &error); if (!ret) { rc = CD_EDID_ERROR_ACCESS_CONFIG; g_warning ("profile disappeared: %s", error->message); g_error_free (error); goto out; } /* get filename */ filename = cd_profile_get_filename (profile); if (filename == NULL) { rc = CD_EDID_ERROR_INVALID_PROFILE; goto out; } /* return filename of profile */ if (profile_fn != NULL) *profile_fn = strdup (filename); out: if (client != NULL) g_object_unref (client); if (device != NULL) g_object_unref (device); if (profile != NULL) g_object_unref (profile); g_free (md5); return rc; }
static void gcm_prefs_setup_space_combobox (GcmPickerPrivate *priv, GtkWidget *widget) { CdColorspace colorspace; CdDevice *device_tmp; CdProfile *profile; const gchar *filename; const gchar *tmp; gboolean has_profile = FALSE; gboolean has_vcgt; gboolean ret; GtkTreeIter iter; GtkTreeModel *model; guint i; g_autofree gchar *text = NULL; g_autoptr(GError) error = NULL; g_autoptr(GPtrArray) devices = NULL; g_autoptr(GPtrArray) profile_array = NULL; /* get new list */ profile_array = cd_client_get_profiles_sync (priv->client, NULL, &error); if (profile_array == NULL) { g_warning ("failed to get profiles: %s", error->message); return; } /* update each list */ for (i = 0; i < profile_array->len; i++) { profile = g_ptr_array_index (profile_array, i); /* connect to the profile */ ret = cd_profile_connect_sync (profile, NULL, &error); if (!ret) { g_warning ("failed to connect to profile: %s", error->message); return; } /* ignore profiles from other user accounts */ if (!cd_profile_has_access (profile)) continue; /* is a printer profile */ filename = cd_profile_get_filename (profile); if (filename == NULL) continue; /* only for correct kind */ has_vcgt = cd_profile_get_has_vcgt (profile); tmp = cd_profile_get_metadata_item (profile, CD_PROFILE_METADATA_STANDARD_SPACE); colorspace = cd_profile_get_colorspace (profile); if (!has_vcgt && tmp != NULL && colorspace == CD_COLORSPACE_RGB) { gcm_prefs_combobox_add_profile (widget, profile, &iter); /* set active option */ if (g_strcmp0 (tmp, "adobe-rgb") == 0) { priv->profile_filename = filename; gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter); } has_profile = TRUE; } } /* add device profiles */ devices = cd_client_get_devices_by_kind_sync (priv->client, CD_DEVICE_KIND_DISPLAY, NULL, &error); for (i = 0; i < devices->len; i++) { device_tmp = g_ptr_array_index (devices, i); /* connect to the device */ ret = cd_device_connect_sync (device_tmp, NULL, &error); if (!ret) { g_warning ("failed to connect to device: %s", error->message); return; } profile = cd_device_get_default_profile (device_tmp); if (profile == NULL) continue; /* connect to the profile */ ret = cd_profile_connect_sync (profile, NULL, &error); if (!ret) { g_warning ("failed to connect to profile: %s", error->message); return; } /* add device profile */ gcm_prefs_combobox_add_profile (widget, profile, NULL); g_object_unref (profile); has_profile = TRUE; } if (!has_profile) { /* TRANSLATORS: this is when there are no profiles that can be used; * the search term is either "RGB" or "CMYK" */ text = g_strdup_printf (_("No %s color spaces available"), cd_colorspace_to_localised_string (CD_COLORSPACE_RGB)); model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_list_store_append (GTK_LIST_STORE(model), &iter); gtk_list_store_set (GTK_LIST_STORE(model), &iter, GCM_PREFS_COMBO_COLUMN_TEXT, text, -1); gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); gtk_widget_set_sensitive (widget, FALSE); } }