[gnome-color-manager] Use the GSetting enum functionality



commit c651dfb86a00329b4790b1542b28acf16f705d4e
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jun 19 22:58:08 2010 +0100

    Use the GSetting enum functionality

 data/org.gnome.color-manager.gschema.xml |   26 ++++++++++++++++---
 src/gcm-calibrate.c                      |   27 ++-----------------
 src/gcm-prefs.c                          |   41 ++++++++----------------------
 src/org.gnome.ColorManager.xml           |    4 +-
 4 files changed, 38 insertions(+), 60 deletions(-)
---
diff --git a/data/org.gnome.color-manager.gschema.xml b/data/org.gnome.color-manager.gschema.xml
index e3b31ef..8bdec98 100644
--- a/data/org.gnome.color-manager.gschema.xml
+++ b/data/org.gnome.color-manager.gschema.xml
@@ -1,4 +1,22 @@
 <schemalist>
+  <enum id="org.gnome.color-manager.RenderingType">
+    <value nick="perceptual" value="1"/>
+    <value nick="relative-colormetric" value="2"/>
+    <value nick="saturation" value="3"/>
+    <value nick="absolute-colormetric" value="4"/>
+  </enum>
+  <enum id="org.gnome.color-manager.CalibrationLength">
+    <value nick="short" value="0"/>
+    <value nick="normal" value="1"/>
+    <value nick="long" value="2"/>
+    <value nick="ask" value="3"/>
+  </enum>
+  <enum id="org.gnome.color-manager.GraphType">
+    <value nick="none" value="0"/>
+    <value nick="cie-1931-xy" value="1"/>
+    <value nick="trc" value="2"/>
+    <value nick="vcgt" value="3"/>
+  </enum>
   <schema id="org.gnome.color-manager" path="/apps/gnome-color-manager/">
     <key name="default-gamma" type="d">
       <default>1.0</default>
@@ -30,12 +48,12 @@
       <summary>Show the fine tuning controls for display devices</summary>
       <description>If set to TRUE then the fine tuning controls are visible. This allows the user to change the display profile outside of what the ICC profile suggests and is only recommended for advanced users.</description>
     </key>
-    <key name="rendering-intent-display" type="s">
+    <key name="rendering-intent-display" enum="org.gnome.color-manager.RenderingType">
       <default>'perceptual'</default>
       <summary>The rendering intent to use for the display, e.g. 'perceptual'</summary>
       <description>The rendering intent to use for the display, e.g. 'perceptual'.</description>
     </key>
-    <key name="rendering-intent-softproof" type="s">
+    <key name="rendering-intent-softproof" enum="org.gnome.color-manager.RenderingType">
       <default>'perceptual'</default>
       <summary>The rendering intent to use for softproofs, e.g. 'perceptual'</summary>
       <description>The rendering intent to use for softproofs, e.g. 'perceptual'.</description>
@@ -50,7 +68,7 @@
       <summary>The default CMYK profile</summary>
       <description>The CMYK profile filename to be used by applications by default.</description>
     </key>
-    <key name="calibration-length" type="s">
+    <key name="calibration-length" enum="org.gnome.color-manager.CalibrationLength">
       <default>'ask'</default>
       <summary>The default calibration length</summary>
       <description>The length of calibration, as this is proportional to the accuracy. The option 'short' creates a quick profile, 'normal' a regular one, and 'long' takes a really long time, but is more precise and creates a better profile. Use 'ask' if you want the user to choose.</description>
@@ -80,7 +98,7 @@
       <summary>If CUPS support is enabled</summary>
       <description>This allows the user to disable printer support if attached devices fail when probed.</description>
     </key>
-    <key name="profile-graph-type" type="s">
+    <key name="profile-graph-type" enum="org.gnome.color-manager.GraphType">
       <default>'cie-1931-xy'</default>
       <summary>The graph type to show in the properties page</summary>
       <description>The graph type in the properties page. This should not be changed manually as this is set from the UI.</description>
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 90bfd32..e2af3b0 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -104,24 +104,6 @@ enum {
 G_DEFINE_TYPE (GcmCalibrate, gcm_calibrate, G_TYPE_OBJECT)
 
 /**
- * gcm_calibrate_precision_from_string:
- **/
-static GcmCalibratePrecision
-gcm_calibrate_precision_from_string (const gchar *string)
-{
-	if (g_strcmp0 (string, "short") == 0)
-		return GCM_CALIBRATE_PRECISION_SHORT;
-	if (g_strcmp0 (string, "normal") == 0)
-		return GCM_CALIBRATE_PRECISION_NORMAL;
-	if (g_strcmp0 (string, "long") == 0)
-		return GCM_CALIBRATE_PRECISION_LONG;
-	if (g_strcmp0 (string, "ask") == 0)
-		return GCM_CALIBRATE_PRECISION_UNKNOWN;
-	egg_warning ("failed to convert to precision: %s", string);
-	return GCM_CALIBRATE_PRECISION_UNKNOWN;
-}
-
-/**
  * gcm_calibrate_get_model_fallback:
  **/
 const gchar *
@@ -610,8 +592,7 @@ gcm_calibrate_display (GcmCalibrate *calibrate, GtkWindow *window, GError **erro
 	}
 
 	/* get default precision */
-	precision = g_settings_get_string (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
-	priv->precision = gcm_calibrate_precision_from_string (precision);
+	priv->precision = g_settings_get_enum (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
 	if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
 		priv->precision = gcm_calibrate_get_precision (calibrate, error);
 		if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
@@ -928,8 +909,7 @@ gcm_calibrate_printer (GcmCalibrate *calibrate, GtkWindow *window, GError **erro
 	}
 
 	/* get default precision */
-	precision = g_settings_get_string (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
-	priv->precision = gcm_calibrate_precision_from_string (precision);
+	priv->precision = g_settings_get_enum (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
 	if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
 		priv->precision = gcm_calibrate_get_precision (calibrate, error);
 		if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
@@ -1101,8 +1081,7 @@ gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error
 	g_object_get (priv->calibrate_dialog, "reference-kind", &priv->reference_kind, NULL);
 
 	/* get default precision */
-	precision = g_settings_get_string (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
-	priv->precision = gcm_calibrate_precision_from_string (precision);
+	priv->precision = g_settings_get_enum (priv->settings, GCM_SETTINGS_CALIBRATION_LENGTH);
 	if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
 		priv->precision = gcm_calibrate_get_precision (calibrate, error);
 		if (priv->precision == GCM_CALIBRATE_PRECISION_UNKNOWN) {
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index b822d17..ccaaef1 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -2822,7 +2822,6 @@ gcm_prefs_renderer_combo_changed_cb (GtkWidget *widget, gpointer data)
 {
 	gint active;
 	const gchar *key = GCM_SETTINGS_RENDERING_INTENT_DISPLAY;
-	const gchar *value;
 
 	/* no selection */
 	active = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
@@ -2833,21 +2832,19 @@ gcm_prefs_renderer_combo_changed_cb (GtkWidget *widget, gpointer data)
 		key = GCM_SETTINGS_RENDERING_INTENT_SOFTPROOF;
 
 	/* save to GSettings */
-	value = gcm_intent_to_string (active+1);
-	egg_debug ("changed rendering intent to %s", value);
-	g_settings_set_string (settings, key, value);
+	egg_debug ("changed rendering intent to %s", gcm_intent_to_string (active+1));
+	g_settings_set_enum (settings, key, active+1);
 }
 
 /**
  * gcm_prefs_setup_rendering_combobox:
  **/
 static void
-gcm_prefs_setup_rendering_combobox (GtkWidget *widget, const gchar *intent)
+gcm_prefs_setup_rendering_combobox (GtkWidget *widget, GcmIntent intent)
 {
 	guint i;
 	gboolean ret = FALSE;
 	gchar *label;
-	const gchar *text;
 
 	for (i=1; i<GCM_INTENT_LAST; i++) {
 		label = g_strdup_printf ("%s - %s",
@@ -2855,8 +2852,7 @@ gcm_prefs_setup_rendering_combobox (GtkWidget *widget, const gchar *intent)
 					 gcm_intent_to_localized_description (i));
 		gtk_combo_box_append_text (GTK_COMBO_BOX (widget), label);
 		g_free (label);
-		text = gcm_intent_to_string (i);
-		if (g_strcmp0 (text, intent) == 0) {
+		if (i == intent) {
 			ret = TRUE;
 			gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i-1);
 		}
@@ -2877,8 +2873,8 @@ gcm_prefs_startup_phase1_idle_cb (gpointer user_data)
 	GError *error = NULL;
 	gchar *colorspace_rgb;
 	gchar *colorspace_cmyk;
-	gchar *intent_display;
-	gchar *intent_softproof;
+	gint intent_display;
+	gint intent_softproof;
 
 	/* search the disk for profiles */
 	gcm_profile_store_search_default (profile_store);
@@ -2903,14 +2899,14 @@ gcm_prefs_startup_phase1_idle_cb (gpointer user_data)
 	/* setup rendering lists */
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_rendering_display"));
 	gcm_prefs_set_combo_simple_text (widget);
-	intent_display = g_settings_get_string (settings, GCM_SETTINGS_RENDERING_INTENT_DISPLAY);
+	intent_display = g_settings_get_enum (settings, GCM_SETTINGS_RENDERING_INTENT_DISPLAY);
 	gcm_prefs_setup_rendering_combobox (widget, intent_display);
 	g_signal_connect (G_OBJECT (widget), "changed",
 			  G_CALLBACK (gcm_prefs_renderer_combo_changed_cb), NULL);
 
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_rendering_softproof"));
 	gcm_prefs_set_combo_simple_text (widget);
-	intent_softproof = g_settings_get_string (settings, GCM_SETTINGS_RENDERING_INTENT_SOFTPROOF);
+	intent_softproof = g_settings_get_enum (settings, GCM_SETTINGS_RENDERING_INTENT_SOFTPROOF);
 	gcm_prefs_setup_rendering_combobox (widget, intent_softproof);
 	g_signal_connect (G_OBJECT (widget), "changed",
 			  G_CALLBACK (gcm_prefs_renderer_combo_changed_cb), (gpointer) "softproof");
@@ -2930,8 +2926,6 @@ gcm_prefs_startup_phase1_idle_cb (gpointer user_data)
 	g_idle_add ((GSourceFunc) gcm_prefs_startup_phase2_idle_cb, NULL);
 
 out:
-	g_free (intent_display);
-	g_free (intent_softproof);
 	g_free (colorspace_rgb);
 	g_free (colorspace_cmyk);
 	return FALSE;
@@ -3148,14 +3142,8 @@ gcm_prefs_graph_combo_changed_cb (GtkWidget *widget, gpointer data)
 	gtk_widget_set_visible (widget, active == 3);
 
 	/* save to GSettings */
-	if (active == 1)
-		value = "cie-1931-xy";
-	else if (active == 2)
-		value = "trc";
-	else if (active == 3)
-		value = "vcgt";
 	egg_debug ("changed profile-graph-type to %s", value);
-	g_settings_set_string (settings, GCM_SETTINGS_PROFILE_GRAPH_TYPE, value);
+	g_settings_set_enum (settings, GCM_SETTINGS_PROFILE_GRAPH_TYPE, active);
 }
 
 /**
@@ -3164,8 +3152,7 @@ gcm_prefs_graph_combo_changed_cb (GtkWidget *widget, gpointer data)
 static void
 gcm_prefs_setup_graph_combobox (GtkWidget *widget)
 {
-	gchar *graph_type;
-	guint active = 0;
+	gint active;
 
 	/* TRANSLATORS: combo-entry, no graph selected to be shown */
 	gtk_combo_box_append_text (GTK_COMBO_BOX(widget), _("None"));
@@ -3180,13 +3167,7 @@ gcm_prefs_setup_graph_combobox (GtkWidget *widget)
 	gtk_combo_box_append_text (GTK_COMBO_BOX(widget), _("Video card gamma table"));
 
 	/* get from settings */
-	graph_type = g_settings_get_string (settings, GCM_SETTINGS_PROFILE_GRAPH_TYPE);
-	if (g_strcmp0 (graph_type, "cie-1931-xy") == 0)
-		active = 1;
-	if (g_strcmp0 (graph_type, "trc") == 0)
-		active = 2;
-	if (g_strcmp0 (graph_type, "vcgt") == 0)
-		active = 3;
+	active = g_settings_get_enum (settings, GCM_SETTINGS_PROFILE_GRAPH_TYPE);
 	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active);
 }
 
diff --git a/src/org.gnome.ColorManager.xml b/src/org.gnome.ColorManager.xml
index 1e65eed..7af0b90 100644
--- a/src/org.gnome.ColorManager.xml
+++ b/src/org.gnome.ColorManager.xml
@@ -12,7 +12,7 @@
     </doc:doc>
 
     <!--*****************************************************************************************-->
-    <property name='RenderingIntentDisplay' type='s' access='read'>
+    <property name='RenderingIntentDisplay' type='i' access='read'>
       <doc:doc>
         <doc:description>
           <doc:para>
@@ -37,7 +37,7 @@
     </property>
 
     <!--*****************************************************************************************-->
-    <property name='RenderingIntentSoftproof' type='s' access='read'>
+    <property name='RenderingIntentSoftproof' type='i' access='read'>
       <doc:doc>
         <doc:description>
           <doc:para>



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