[gnome-color-manager/colord: 48/72] trivial: adjust to API changes in colord



commit d80b34009e2db4a902fbc060e71e646015c24c44
Author: Richard Hughes <richard hughsie com>
Date:   Wed Feb 2 17:16:15 2011 +0000

    trivial: adjust to API changes in colord

 src/cc-color-panel.c |   78 ++++++++++--------------------
 src/gcm-session.c    |  129 +++++++++++++++-----------------------------------
 2 files changed, 65 insertions(+), 142 deletions(-)
---
diff --git a/src/cc-color-panel.c b/src/cc-color-panel.c
index f2ce4b4..9c3c0a6 100644
--- a/src/cc-color-panel.c
+++ b/src/cc-color-panel.c
@@ -1052,8 +1052,9 @@ cc_color_panel_button_virtual_add_cb (GtkWidget *widget, CcColorPanel *panel)
 	CdDevice *device;
 	const gchar *model;
 	const gchar *manufacturer;
-	gboolean ret = FALSE;
+	gchar *device_id;
 	GError *error = NULL;
+	GHashTable *device_props;
 
 	/* get device details */
 	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "combobox_virtual_type"));
@@ -1064,9 +1065,28 @@ cc_color_panel_button_virtual_add_cb (GtkWidget *widget, CcColorPanel *panel)
 	manufacturer = gtk_entry_get_text (GTK_ENTRY (widget));
 
 	/* create device */
+	device_id = g_strdup_printf ("%s-%s-%s",
+				     cd_device_kind_to_string (device_kind),
+				     manufacturer,
+				     model);
+	device_props = g_hash_table_new_full (g_str_hash, g_str_equal,
+					      g_free, g_free);
+	g_hash_table_insert (device_props,
+			     g_strdup ("Kind"),
+			     g_strdup (cd_device_kind_to_string (device_kind)));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Mode"),
+			     g_strdup (cd_device_mode_to_string (CD_DEVICE_MODE_VIRTUAL)));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Model"),
+			     g_strdup (model));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Vendor"),
+			     g_strdup (manufacturer));
 	device = cd_client_create_device_sync (panel->priv->client,
-					       "virtual-fixme",
+					       device_id,
 					       CD_OBJECT_SCOPE_DISK,
+					       device_props,
 					       panel->priv->cancellable,
 					       &error);
 	if (device == NULL) {
@@ -1077,57 +1097,11 @@ cc_color_panel_button_virtual_add_cb (GtkWidget *widget, CcColorPanel *panel)
 		g_error_free (error);
 		goto out;
 	}
-
-	/* set kind */
-	ret = cd_device_set_kind_sync (device,
-				       device_kind,
-				       panel->priv->cancellable,
-				       &error);
-	if (!ret) {
-		g_warning ("failed to set property: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* set model */
-	ret = cd_device_set_model_sync (device,
-					model,
-					panel->priv->cancellable,
-					&error);
-	if (!ret) {
-		g_warning ("failed to set property: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* set manufacturer */
-	ret = cd_device_set_vendor_sync (device,
-					 manufacturer,
-					 panel->priv->cancellable,
-					 &error);
-	if (!ret) {
-		g_warning ("failed to set property: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* commit */
-	ret = cd_device_commit_sync (device,
-				     panel->priv->cancellable,
-				     &error);
-	if (!ret) {
-		g_warning ("failed to commit device: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
 out:
-	/* we're done */
+	g_hash_table_unref (device_props);
 	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "dialog_virtual"));
 	gtk_widget_hide (widget);
+	g_free (device_id);
 }
 
 /**
@@ -1415,6 +1389,7 @@ cc_color_panel_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcColor
 	GtkTreePath *path;
 	GtkWidget *widget;
 	GtkTreeIter iter;
+	CdDeviceMode device_mode;
 
 	/* This will only work in single or browse selection mode! */
 	if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
@@ -1456,8 +1431,9 @@ cc_color_panel_devices_treeview_clicked_cb (GtkTreeSelection *selection, CcColor
 	gtk_widget_set_sensitive (widget, TRUE);
 
 	/* can we delete this device? */
+	device_mode = cd_device_get_mode (panel->priv->current_device);
 	widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "button_delete"));
-	gtk_widget_set_sensitive (widget, TRUE);
+	gtk_widget_set_sensitive (widget, device_mode == CD_DEVICE_MODE_VIRTUAL);
 
 	/* can this device calibrate */
 	cc_color_panel_set_calibrate_button_sensitivity (panel);
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 899a621..131ef2d 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -942,13 +942,19 @@ gcm_session_profile_store_added_cb (GcmProfileStore *profile_store_,
 				    gpointer user_data)
 {
 	CdProfile *profile;
-	gboolean ret;
 	GError *error = NULL;
+	GHashTable *profile_props;
 
 	g_debug ("profile %s added", filename);
+	profile_props = g_hash_table_new_full (g_str_hash, g_str_equal,
+					       g_free, g_free);
+	g_hash_table_insert (profile_props,
+			     g_strdup ("Filename"),
+			     g_strdup (filename));
 	profile = cd_client_create_profile_sync (client,
 						 filename,
 						 CD_OBJECT_SCOPE_TEMPORARY,
+						 profile_props,
 						 NULL,
 						 &error);
 	if (profile == NULL) {
@@ -957,30 +963,8 @@ gcm_session_profile_store_added_cb (GcmProfileStore *profile_store_,
 		g_error_free (error);
 		goto out;
 	}
-
-	/* set filename */
-	ret = cd_profile_set_filename_sync (profile,
-					    filename,
-					    NULL,
-					    &error);
-	if (!ret) {
-		g_warning ("failed to create profile: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* commit */
-	ret = cd_profile_commit_sync (profile,
-				      NULL,
-				      &error);
-	if (!ret) {
-		g_warning ("failed to commit profile: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
 out:
+	g_hash_table_unref (profile_props);
 	if (profile != NULL)
 		g_object_unref (profile);
 }
@@ -1025,6 +1009,7 @@ gcm_x11_screen_output_added_cb (GcmX11Screen *screen_,
 	gboolean ret;
 	GcmEdid *edid;
 	GError *error = NULL;
+	GHashTable *device_props = NULL;
 
 	/* get edid */
 	edid = gcm_x11_output_get_edid (output, &error);
@@ -1035,43 +1020,6 @@ gcm_x11_screen_output_added_cb (GcmX11Screen *screen_,
 		goto out;
 	}
 
-	g_debug ("output %s added",
-		 gcm_x11_output_get_name (output));
-	device = cd_client_create_device_sync (client,
-					       gcm_x11_output_get_name (output),
-					       CD_OBJECT_SCOPE_TEMPORARY,
-					       NULL,
-					       &error);
-	if (device == NULL) {
-		g_warning ("failed to create device: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* set kind */
-	ret = cd_device_set_kind_sync (device,
-				       CD_DEVICE_KIND_DISPLAY,
-				       NULL,
-				       &error);
-	if (device == NULL) {
-		g_warning ("failed to create device: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* set colorspace */
-	ret = cd_device_set_colorspace_sync (device,
-					     CD_COLORSPACE_RGB,
-					     NULL,
-					     &error);
-	if (device == NULL) {
-		g_warning ("failed to create device: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
 
 	/* is this an internal device? */
 	ret = gcm_utils_output_is_lcd_internal (gcm_x11_output_get_name (output));
@@ -1085,41 +1033,40 @@ gcm_x11_screen_output_added_cb (GcmX11Screen *screen_,
 		vendor = gcm_edid_get_vendor_name (edid);
 	}
 
-	/* set model */
-	ret = cd_device_set_model_sync (device,
-					model,
-					NULL,
-					&error);
-	if (!ret) {
-		g_warning ("failed to set model: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* set vendor */
-	ret = cd_device_set_vendor_sync (device,
-					 vendor,
-					 NULL,
-					 &error);
-	if (!ret) {
-		g_warning ("failed to set vendor: %s",
-			   error->message);
-		g_error_free (error);
-		goto out;
-	}
-
-	/* commit */
-	ret = cd_device_commit_sync (device,
-				     NULL,
-				     &error);
-	if (!ret) {
-		g_warning ("failed to commit device: %s",
+	g_debug ("output %s added",
+		 gcm_x11_output_get_name (output));
+	device_props = g_hash_table_new_full (g_str_hash, g_str_equal,
+					      g_free, g_free);
+	g_hash_table_insert (device_props,
+			     g_strdup ("Kind"),
+			     g_strdup (cd_device_kind_to_string (CD_DEVICE_KIND_DISPLAY)));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Mode"),
+			     g_strdup (cd_device_mode_to_string (CD_DEVICE_MODE_PHYSICAL)));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Colorspace"),
+			     g_strdup (cd_colorspace_to_string (CD_COLORSPACE_RGB)));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Vendor"),
+			     g_strdup (vendor));
+	g_hash_table_insert (device_props,
+			     g_strdup ("Model"),
+			     g_strdup (model));
+	device = cd_client_create_device_sync (client,
+					       gcm_x11_output_get_name (output),
+					       CD_OBJECT_SCOPE_TEMPORARY,
+					       device_props,
+					       NULL,
+					       &error);
+	if (device == NULL) {
+		g_warning ("failed to create device: %s",
 			   error->message);
 		g_error_free (error);
 		goto out;
 	}
 out:
+	if (device_props != NULL)
+		g_hash_table_unref (device_props);
 	if (device != NULL)
 		g_object_unref (device);
 	if (edid != NULL)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]