[gnome-color-manager] Store the output name in GcmDevice::native-device-xrandr, not the output pointer



commit b00a74b0b5838566f044025efb5f5172c53abfbd
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 6 13:58:32 2009 +0000

    Store the output name in GcmDevice::native-device-xrandr, not the output pointer

 src/gcm-client.c |    4 +++-
 src/gcm-device.c |   13 ++++++++-----
 src/gcm-prefs.c  |    9 ++++-----
 src/gcm-utils.c  |   15 +++++++++++----
 4 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/src/gcm-client.c b/src/gcm-client.c
index b79ace5..a3c5fc1 100644
--- a/src/gcm-client.c
+++ b/src/gcm-client.c
@@ -364,6 +364,7 @@ gcm_client_xrandr_add (GcmClient *client, GnomeRROutput *output)
 	gboolean ret;
 	GcmDevice *device = NULL;
 	GError *error = NULL;
+	const gchar *output_name;
 	GcmClientPrivate *priv = client->priv;
 
 	/* get details */
@@ -387,11 +388,12 @@ gcm_client_xrandr_add (GcmClient *client, GnomeRROutput *output)
 	/* add new device */
 	device = gcm_device_new ();
 	title = gcm_utils_get_output_name (output);
+	output_name = gnome_rr_output_get_name (output);
 	g_object_set (device,
 		      "type", GCM_DEVICE_TYPE_DISPLAY,
 		      "id", id,
 		      "title", title,
-		      "native-device-xrandr", output,
+		      "native-device-xrandr", output_name,
 		      NULL);
 
 	/* load the device */
diff --git a/src/gcm-device.c b/src/gcm-device.c
index db48ca9..f6bcf6d 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -61,7 +61,7 @@ struct _GcmDevicePrivate
 	gchar				*copyright;
 	gchar				*vendor;
 	GConfClient			*gconf_client;
-	GnomeRROutput			*native_device_xrandr;
+	gchar				*native_device_xrandr;
 	gchar				*native_device_sysfs;
 };
 
@@ -374,7 +374,7 @@ gcm_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
 		g_value_set_string (value, priv->title);
 		break;
 	case PROP_NATIVE_DEVICE_XRANDR:
-		g_value_set_pointer (value, priv->native_device_xrandr);
+		g_value_set_string (value, priv->native_device_xrandr);
 		break;
 	case PROP_NATIVE_DEVICE_SYSFS:
 		g_value_set_string (value, priv->native_device_sysfs);
@@ -420,7 +420,8 @@ gcm_device_set_property (GObject *object, guint prop_id, const GValue *value, GP
 		priv->contrast = g_value_get_float (value);
 		break;
 	case PROP_NATIVE_DEVICE_XRANDR:
-		priv->native_device_xrandr = g_value_get_pointer (value);
+		g_free (priv->native_device_xrandr);
+		priv->native_device_xrandr = g_strdup (g_value_get_string (value));
 		break;
 	case PROP_NATIVE_DEVICE_SYSFS:
 		g_free (priv->native_device_sysfs);
@@ -527,8 +528,9 @@ gcm_device_class_init (GcmDeviceClass *klass)
 	/**
 	 * GcmDevice:native-device-xrandr:
 	 */
-	pspec = g_param_spec_pointer ("native-device-xrandr", NULL, NULL,
-				      G_PARAM_READWRITE);
+	pspec = g_param_spec_string ("native-device-xrandr", NULL, NULL,
+				     NULL,
+				     G_PARAM_READWRITE);
 	g_object_class_install_property (object_class, PROP_NATIVE_DEVICE_XRANDR, pspec);
 
 	/**
@@ -576,6 +578,7 @@ gcm_device_finalize (GObject *object)
 	g_free (priv->vendor);
 	g_free (priv->title);
 	g_free (priv->id);
+	g_free (priv->native_device_xrandr);
 	g_free (priv->native_device_sysfs);
 	g_object_unref (priv->gconf_client);
 
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 180056c..ef80022 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -91,8 +91,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	gboolean ret;
 	GError *error = NULL;
 	GtkWindow *window;
-	GnomeRROutput *output;
-	const gchar *output_name;
+	gchar *output_name = NULL;
 	const gchar *name;
 	gchar *filename = NULL;
 	gchar *destination = NULL;
@@ -101,9 +100,9 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 
 	/* get the device */
 	g_object_get (current_device,
-		      "native-device-xrandr", &output,
+		      "native-device-xrandr", &output_name,
 		      NULL);
-	if (output == NULL) {
+	if (output_name == NULL) {
 		egg_warning ("failed to get output");
 		goto out;
 	}
@@ -113,7 +112,6 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	brightness = gcm_brightness_new ();
 
 	/* set the proper output name */
-	output_name = gnome_rr_output_get_name (output);
 	g_object_set (calib,
 		      "output-name", output_name,
 		      NULL);
@@ -248,6 +246,7 @@ out:
 	}
 	g_free (filename);
 	g_free (destination);
+	g_free (output_name);
 }
 
 /**
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 401dd01..aab7fa2 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -222,10 +222,11 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
 	gfloat gamma;
 	gfloat brightness;
 	gfloat contrast;
-	const gchar *output_name;
+	gchar *output_name;
 	gchar *id = NULL;
 	guint size;
 	GcmDeviceType type;
+	GnomeRRScreen *rr_screen = NULL;
 
 	/* get details about the device */
 	g_object_get (device,
@@ -235,7 +236,7 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
 		      "gamma", &gamma,
 		      "brightness", &brightness,
 		      "contrast", &contrast,
-		      "native-device-xrandr", &output,
+		      "native-device-xrandr", &output_name,
 		      NULL);
 
 	/* do no set the gamma for non-display types */
@@ -246,9 +247,13 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
 	}
 
 	/* check we have an output */
+	rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), NULL, NULL, error);
+	if (rr_screen == NULL)
+		goto out;
+	output = gnome_rr_screen_get_output_by_name (rr_screen, output_name);
 	if (output == NULL) {
 		if (error != NULL)
-			*error = g_error_new (1, 0, "no output for device: %s", id);
+			*error = g_error_new (1, 0, "no output for device: %s [%s]", id, output_name);
 		goto out;
 	}
 
@@ -290,7 +295,6 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
 
 	/* set the per-output profile atoms */
 	xserver = gcm_xserver_new ();
-	output_name = gnome_rr_output_get_name (output);
 	ret = gcm_xserver_set_output_profile (xserver, output_name, profile, error);
 	if (!ret)
 		goto out;
@@ -305,6 +309,9 @@ gcm_utils_set_gamma_for_device (GcmDevice *device, GError **error)
 out:
 	g_free (id);
 	g_free (profile);
+	g_free (output_name);
+	if (rr_screen != NULL)
+		gnome_rr_screen_destroy (rr_screen);
 	if (clut != NULL)
 		g_object_unref (clut);
 	if (xserver != NULL)



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