gnome-control-center r8647 - in trunk/capplets/appearance: . data



Author: jensg
Date: Sun Apr 13 15:19:45 2008
New Revision: 8647
URL: http://svn.gnome.org/viewvc/gnome-control-center?rev=8647&view=rev

Log:
2008-04-13  Jens Granseuer  <jensgr gmx net>

	* appearance-desktop.c: (wp_option_menu_set),
	(wp_scale_type_changed), (wp_shade_type_changed),
	(wp_options_changed), (wp_shading_changed), (wp_props_wp_set),
	(wp_load_stuffs):
	* data/appearance.glade:
	* gnome-wp-item.c: (wp_item_option_to_string),
	(wp_item_shading_to_string), (wp_item_string_to_option),
	(wp_item_string_to_shading), (set_bg_properties),
	(gnome_wp_item_update), (gnome_wp_item_free):
	* gnome-wp-item.h:
	* gnome-wp-xml.c: (gnome_wp_xml_load_xml),
	(gnome_wp_xml_save_list): use the GnomeBG enum types instead of
	strings to handle options internally and only convert when needed


Modified:
   trunk/capplets/appearance/ChangeLog
   trunk/capplets/appearance/appearance-desktop.c
   trunk/capplets/appearance/data/appearance.glade
   trunk/capplets/appearance/gnome-wp-item.c
   trunk/capplets/appearance/gnome-wp-item.h
   trunk/capplets/appearance/gnome-wp-xml.c

Modified: trunk/capplets/appearance/appearance-desktop.c
==============================================================================
--- trunk/capplets/appearance/appearance-desktop.c	(original)
+++ trunk/capplets/appearance/appearance-desktop.c	Sun Apr 13 15:19:45 2008
@@ -31,27 +31,13 @@
 #define GNOME_DESKTOP_USE_UNSTABLE_API
 #include <libgnomeui/gnome-bg.h>
 
-typedef enum {
-  GNOME_WP_SHADE_TYPE_SOLID,
-  GNOME_WP_SHADE_TYPE_HORIZ,
-  GNOME_WP_SHADE_TYPE_VERT
-} GnomeWPShadeType;
-
-typedef enum {
-  GNOME_WP_SCALE_TYPE_CENTERED,
-  GNOME_WP_SCALE_TYPE_STRETCHED,
-  GNOME_WP_SCALE_TYPE_SCALED,
-  GNOME_WP_SCALE_TYPE_ZOOM,
-  GNOME_WP_SCALE_TYPE_TILED
-} GnomeWPScaleType;
-
 enum {
   TARGET_URI_LIST,
   TARGET_BGIMAGE
 };
 
 static const GtkTargetEntry drop_types[] = {
-  {"text/uri-list", 0, TARGET_URI_LIST},
+  { "text/uri-list", 0, TARGET_URI_LIST },
   { "property/bgimage", 0, TARGET_BGIMAGE }
 };
 
@@ -248,47 +234,23 @@
 
 static void
 wp_option_menu_set (AppearanceData *data,
-                    const gchar *value,
+                    int value,
                     gboolean shade_type)
 {
   if (shade_type)
   {
-    if (!strcmp (value, "horizontal-gradient"))
-    {
-      gtk_combo_box_set_active (GTK_COMBO_BOX (data->wp_color_menu),
-                                GNOME_WP_SHADE_TYPE_HORIZ);
-      gtk_widget_show (data->wp_scpicker);
-    }
-    else if (!strcmp (value, "vertical-gradient"))
-    {
-      gtk_combo_box_set_active (GTK_COMBO_BOX (data->wp_color_menu),
-                                GNOME_WP_SHADE_TYPE_VERT);
-      gtk_widget_show (data->wp_scpicker);
-    }
-    else
-    {
-      gtk_combo_box_set_active (GTK_COMBO_BOX (data->wp_color_menu),
-                                GNOME_WP_SHADE_TYPE_SOLID);
+    gtk_combo_box_set_active (GTK_COMBO_BOX (data->wp_color_menu),
+                              value);
+
+    if (value == GNOME_BG_COLOR_SOLID)
       gtk_widget_hide (data->wp_scpicker);
-    }
+    else
+      gtk_widget_show (data->wp_scpicker);
   }
   else
   {
-    gint style;
-
-    if (!strcmp (value, "centered"))
-      style = GNOME_WP_SCALE_TYPE_CENTERED;
-    else if (!strcmp (value, "stretched"))
-      style = GNOME_WP_SCALE_TYPE_STRETCHED;
-    else if (!strcmp (value, "scaled"))
-      style = GNOME_WP_SCALE_TYPE_SCALED;
-    else if (!strcmp (value, "zoom"))
-      style = GNOME_WP_SCALE_TYPE_ZOOM;
-    else
-      style = GNOME_WP_SCALE_TYPE_TILED;
-
     gtk_combo_box_set_active (GTK_COMBO_BOX (data->wp_style_menu),
-                              style);
+                              value);
   }
 }
 
@@ -343,29 +305,7 @@
   if (item == NULL)
     return;
 
-  g_free (item->options);
-
-  switch (gtk_combo_box_get_active (GTK_COMBO_BOX (data->wp_style_menu)))
-  {
-  case GNOME_WP_SCALE_TYPE_CENTERED:
-    item->options = g_strdup ("centered");
-    break;
-  case GNOME_WP_SCALE_TYPE_STRETCHED:
-    item->options = g_strdup ("stretched");
-    break;
-  case GNOME_WP_SCALE_TYPE_SCALED:
-    item->options = g_strdup ("scaled");
-    break;
-  case GNOME_WP_SCALE_TYPE_ZOOM:
-    item->options = g_strdup ("zoom");
-    break;
-  case GNOME_WP_SCALE_TYPE_TILED:
-    item->options = g_strdup ("wallpaper");
-    break;
-  default:
-    item->options = g_strdup ("none");
-    break;
-  }
+  item->options = gtk_combo_box_get_active (GTK_COMBO_BOX (data->wp_style_menu));
 
   pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
   gtk_list_store_set (GTK_LIST_STORE (data->wp_model),
@@ -376,7 +316,8 @@
     g_object_unref (pixbuf);
 
   if (gconf_client_key_is_writable (data->client, WP_OPTIONS_KEY, NULL))
-    gconf_client_set_string (data->client, WP_OPTIONS_KEY, item->options, NULL);
+    gconf_client_set_string (data->client, WP_OPTIONS_KEY,
+                             wp_item_option_to_string (item->options), NULL);
 }
 
 static void
@@ -392,24 +333,7 @@
   if (item == NULL)
     return;
 
-  g_free (item->shade_type);
-
-  switch (gtk_combo_box_get_active (GTK_COMBO_BOX (data->wp_color_menu)))
-  {
-  case GNOME_WP_SHADE_TYPE_HORIZ:
-    item->shade_type = g_strdup ("horizontal-gradient");
-    gtk_widget_show (data->wp_scpicker);
-    break;
-  case GNOME_WP_SHADE_TYPE_VERT:
-    item->shade_type = g_strdup ("vertical-gradient");
-    gtk_widget_show (data->wp_scpicker);
-    break;
-  case GNOME_WP_SHADE_TYPE_SOLID:
-  default:
-    item->shade_type = g_strdup ("solid");
-    gtk_widget_hide (data->wp_scpicker);
-    break;
-  }
+  item->shade_type = gtk_combo_box_get_active (GTK_COMBO_BOX (data->wp_color_menu));
 
   pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
   gtk_list_store_set (GTK_LIST_STORE (data->wp_model), &iter,
@@ -420,7 +344,7 @@
 
   if (gconf_client_key_is_writable (data->client, WP_SHADING_KEY, NULL))
     gconf_client_set_string (data->client, WP_SHADING_KEY,
-                             item->shade_type, NULL);
+                             wp_item_shading_to_string (item->shade_type), NULL);
 }
 
 static void
@@ -546,8 +470,7 @@
 
   if (item != NULL)
   {
-    g_free (item->options);
-    item->options = g_strdup (option);
+    item->options = wp_item_string_to_option (option);
     wp_option_menu_set (data, item->options, FALSE);
   }
 }
@@ -565,8 +488,7 @@
 
   if (item != NULL)
   {
-    g_free (item->shade_type);
-    item->shade_type = g_strdup (gconf_value_get_string (entry->value));
+    item->shade_type = wp_item_string_to_shading (gconf_value_get_string (entry->value));
     wp_option_menu_set (data, item->shade_type, TRUE);
   }
 }
@@ -630,16 +552,18 @@
       uri = g_filename_to_utf8 (item->filename, -1, NULL, NULL, NULL);
 
     if (uri == NULL) {
-      g_warning ("Failed to convert filename to UTF-8: %s\n", item->filename);
+      g_warning ("Failed to convert filename to UTF-8: %s", item->filename);
     } else {
       gconf_change_set_set_string (cs, WP_FILE_KEY, uri);
       g_free (uri);
     }
 
-    gconf_change_set_set_string (cs, WP_OPTIONS_KEY, item->options);
+    gconf_change_set_set_string (cs, WP_OPTIONS_KEY,
+                                 wp_item_option_to_string (item->options));
   }
 
-  gconf_change_set_set_string (cs, WP_SHADING_KEY, item->shade_type);
+  gconf_change_set_set_string (cs, WP_SHADING_KEY,
+                               wp_item_shading_to_string (item->shade_type));
 
   pcolor = gdk_color_to_string (item->pcolor);
   scolor = gdk_color_to_string (item->scolor);
@@ -868,7 +792,7 @@
 wp_load_stuffs (void *user_data)
 {
   AppearanceData *data;
-  gchar *imagepath, *style, *uri;
+  gchar *imagepath, *uri, *style;
   GnomeWPItem *item;
 
   data = (AppearanceData *) user_data;
@@ -940,7 +864,7 @@
     if (!strcmp (style, "none"))
     {
       select_item (data, item, FALSE);
-      wp_option_menu_set (data, style, FALSE);
+      wp_option_menu_set (data, GNOME_BG_PLACEMENT_SCALED, FALSE);
     }
   }
   g_free (imagepath);

Modified: trunk/capplets/appearance/data/appearance.glade
==============================================================================
--- trunk/capplets/appearance/data/appearance.glade	(original)
+++ trunk/capplets/appearance/data/appearance.glade	Sun Apr 13 15:19:45 2008
@@ -865,11 +865,11 @@
                             <child>
                               <widget class="GtkComboBox" id="wp_style_menu">
                                 <property name="visible">True</property>
-                                <property name="items" translatable="yes">Centered
-Fill screen
-Scaled
+                                <property name="items" translatable="yes">Tiled
 Zoom
-Tiled</property>
+Centered
+Scaled
+Fill screen</property>
                               </widget>
                               <packing>
                                 <property name="expand">False</property>

Modified: trunk/capplets/appearance/gnome-wp-item.c
==============================================================================
--- trunk/capplets/appearance/gnome-wp-item.c	(original)
+++ trunk/capplets/appearance/gnome-wp-item.c	Sun Apr 13 15:19:45 2008
@@ -25,44 +25,55 @@
 #include <gnome.h>
 #include <string.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#define GNOME_DESKTOP_USE_UNSTABLE_API
-#include <libgnomeui/gnome-bg.h>
 #include "gnome-wp-item.h"
 
-static void set_bg_properties (GnomeWPItem *item)
-{
-  GnomeBGColorType color;
-  GnomeBGPlacement placement;
+static GConfEnumStringPair options_lookup[] = {
+  { GNOME_BG_PLACEMENT_CENTERED, "centered" },
+  { GNOME_BG_PLACEMENT_FILL_SCREEN, "stretched" },
+  { GNOME_BG_PLACEMENT_SCALED, "scaled" },
+  { GNOME_BG_PLACEMENT_ZOOMED, "zoomed" },
+  { GNOME_BG_PLACEMENT_TILED, "wallpaper" },
+  { 0, NULL }
+};
+
+static GConfEnumStringPair shade_lookup[] = {
+  { GNOME_BG_COLOR_SOLID, "solid" },
+  { GNOME_BG_COLOR_H_GRADIENT, "horizontal-gradient" },
+  { GNOME_BG_COLOR_V_GRADIENT, "vertical-gradient" },
+  { 0, NULL }
+};
 
-  color = GNOME_BG_COLOR_SOLID;
+const gchar *wp_item_option_to_string (GnomeBGPlacement type)
+{
+  return gconf_enum_to_string (options_lookup, type);
+}
 
-  if (item->shade_type) {
-    if (!strcmp (item->shade_type, "horizontal-gradient")) {
-      color = GNOME_BG_COLOR_H_GRADIENT;
-    } else if (!strcmp (item->shade_type, "vertical-gradient")) {
-      color = GNOME_BG_COLOR_V_GRADIENT;
-    }
-  }
+const gchar *wp_item_shading_to_string (GnomeBGColorType type)
+{
+  return gconf_enum_to_string (shade_lookup, type);
+}
 
-  placement = GNOME_BG_PLACEMENT_TILED;
+GnomeBGPlacement wp_item_string_to_option (const gchar *option)
+{
+  int i = GNOME_BG_PLACEMENT_SCALED;
+  gconf_string_to_enum (options_lookup, option, &i);
+  return i;
+}
 
-  if (item->options) {
-    if (!strcmp (item->options, "centered")) {
-      placement = GNOME_BG_PLACEMENT_CENTERED;
-    } else if (!strcmp (item->options, "stretched")) {
-      placement = GNOME_BG_PLACEMENT_FILL_SCREEN;
-    } else if (!strcmp (item->options, "scaled")) {
-      placement = GNOME_BG_PLACEMENT_SCALED;
-    } else if (!strcmp (item->options, "zoom")) {
-      placement = GNOME_BG_PLACEMENT_ZOOMED;
-    }
-  }
+GnomeBGColorType wp_item_string_to_shading (const gchar *shade_type)
+{
+  int i = GNOME_BG_COLOR_SOLID;
+  gconf_string_to_enum (shade_lookup, shade_type, &i);
+  return i;
+}
 
+static void set_bg_properties (GnomeWPItem *item)
+{
   if (item->filename)
     gnome_bg_set_uri (item->bg, item->filename);
 
-  gnome_bg_set_color (item->bg, color, item->pcolor, item->scolor);
-  gnome_bg_set_placement (item->bg, placement);
+  gnome_bg_set_color (item->bg, item->shade_type, item->pcolor, item->scolor);
+  gnome_bg_set_placement (item->bg, item->options);
 }
 
 void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item)
@@ -77,32 +88,28 @@
 void gnome_wp_item_update (GnomeWPItem *item) {
   GConfClient *client;
   GdkColor color1 = { 0, 0, 0, 0 }, color2 = { 0, 0, 0, 0 };
-  gchar *col_str;
+  gchar *s;
 
   client = gconf_client_get_default ();
 
-  g_free (item->options);
-  item->options = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
-  if (item->options == NULL || !strcmp (item->options, "none")) {
-    g_free (item->options);
-    item->options = g_strdup ("scaled");
-  }
-
-  g_free (item->shade_type);
-  item->shade_type = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
-  if (item->shade_type == NULL)
-    item->shade_type = g_strdup ("solid");
-
-  col_str = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
-  if (col_str != NULL) {
-    gdk_color_parse (col_str, &color1);
-    g_free (col_str);
-  }
-
-  col_str = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
-  if (col_str != NULL) {
-    gdk_color_parse (col_str, &color2);
-    g_free (col_str);
+  s = gconf_client_get_string (client, WP_OPTIONS_KEY, NULL);
+  item->options = wp_item_string_to_option (s);
+  g_free (s);
+
+  s = gconf_client_get_string (client, WP_SHADING_KEY, NULL);
+  item->shade_type = wp_item_string_to_shading (s);
+  g_free (s);
+
+  s = gconf_client_get_string (client, WP_PCOLOR_KEY, NULL);
+  if (s != NULL) {
+    gdk_color_parse (s, &color1);
+    g_free (s);
+  }
+
+  s = gconf_client_get_string (client, WP_SCOLOR_KEY, NULL);
+  if (s != NULL) {
+    gdk_color_parse (s, &color2);
+    g_free (s);
   }
 
   g_object_unref (client);
@@ -158,8 +165,6 @@
   g_free (item->name);
   g_free (item->filename);
   g_free (item->description);
-  g_free (item->options);
-  g_free (item->shade_type);
 
   if (item->pcolor != NULL)
     gdk_color_free (item->pcolor);

Modified: trunk/capplets/appearance/gnome-wp-item.h
==============================================================================
--- trunk/capplets/appearance/gnome-wp-item.h	(original)
+++ trunk/capplets/appearance/gnome-wp-item.h	Sun Apr 13 15:19:45 2008
@@ -47,8 +47,8 @@
   gchar * name;
   gchar * filename;
   gchar * description;
-  gchar * options;
-  gchar * shade_type;
+  GnomeBGPlacement options;
+  GnomeBGColorType shade_type;
 
   /* Where the Item is in the List */
   GtkTreeRowReference * rowref;
@@ -67,15 +67,20 @@
   gint height;
 };
 
-GnomeWPItem * gnome_wp_item_new (const gchar * filename,
-				 GHashTable * wallpapers,
-				 GnomeThumbnailFactory * thumbnails);
-void gnome_wp_item_free (GnomeWPItem * item);
-GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item,
-					 GnomeThumbnailFactory * thumbs);
-void gnome_wp_item_update (GnomeWPItem * item);
-void gnome_wp_item_update_description (GnomeWPItem * item);
+GnomeWPItem * gnome_wp_item_new (const gchar *filename,
+				 GHashTable *wallpapers,
+				 GnomeThumbnailFactory *thumbnails);
+
+void gnome_wp_item_free (GnomeWPItem *item);
+GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem *item,
+					 GnomeThumbnailFactory *thumbs);
+void gnome_wp_item_update (GnomeWPItem *item);
+void gnome_wp_item_update_description (GnomeWPItem *item);
 void gnome_wp_item_ensure_gnome_bg (GnomeWPItem *item);
 
-#endif
+const gchar *wp_item_option_to_string (GnomeBGPlacement type);
+const gchar *wp_item_shading_to_string (GnomeBGColorType type);
+GnomeBGPlacement wp_item_string_to_option (const gchar *option);
+GnomeBGColorType wp_item_string_to_shading (const gchar *shade_type);
 
+#endif

Modified: trunk/capplets/appearance/gnome-wp-xml.c
==============================================================================
--- trunk/capplets/appearance/gnome-wp-xml.c	(original)
+++ trunk/capplets/appearance/gnome-wp-xml.c	Sun Apr 13 15:19:45 2008
@@ -117,6 +117,8 @@
     if (!strcmp ((gchar *)list->name, "wallpaper")) {
       GnomeWPItem * wp;
       gchar *pcolor = NULL, *scolor = NULL;
+      gchar *s;
+      gboolean have_scale = FALSE, have_shade = FALSE;
 
       wp = g_new0 (GnomeWPItem, 1);
 
@@ -128,7 +130,7 @@
 	    const char * none = "(none)";
 	    gchar *content = g_strstrip ((gchar *)wpa->last->content);
 
-	    if (!strncmp (content, none, strlen (none)))
+	    if (!strcmp (content, none))
 	      wp->filename = g_strdup (content);
 	    else if (g_utf8_validate (content, -1, NULL) &&
 		     g_file_test (content, G_FILE_TEST_EXISTS))
@@ -160,14 +162,13 @@
 	  }
 	} else if (!strcmp ((gchar *)wpa->name, "options")) {
 	  if (wpa->last != NULL) {
-	    wp->options = g_strdup (g_strstrip ((gchar *)wpa->last->content));
-	  } else {
-	    wp->options = gconf_client_get_string (data->client,
-						   WP_OPTIONS_KEY, NULL);
+	    wp->options = wp_item_string_to_option (g_strstrip ((gchar *)wpa->last->content));
+	    have_scale = TRUE;
 	  }
 	} else if (!strcmp ((gchar *)wpa->name, "shade_type")) {
 	  if (wpa->last != NULL) {
-	    wp->shade_type = g_strdup (g_strstrip ((gchar *)wpa->last->content));
+	    wp->shade_type = wp_item_string_to_shading (g_strstrip ((gchar *)wpa->last->content));
+	    have_shade = TRUE;
 	  }
 	} else if (!strcmp ((gchar *)wpa->name, "pcolor")) {
 	  if (wpa->last != NULL) {
@@ -195,10 +196,18 @@
       }
 
       /* Verify the colors and alloc some GdkColors here */
-      if (wp->shade_type == NULL) {
-	wp->shade_type = gconf_client_get_string (data->client,
-						  WP_SHADING_KEY, NULL);
+      if (!have_scale) {
+        s = gconf_client_get_string (data->client, WP_OPTIONS_KEY, NULL);
+        wp->options = wp_item_string_to_option (s);
+        g_free (s);
+      }
+
+      if (!have_shade) {
+        s = gconf_client_get_string (data->client, WP_SHADING_KEY, NULL);
+        wp->shade_type = wp_item_string_to_shading (s);
+        g_free (s);
       }
+
       if (pcolor == NULL) {
 	pcolor = gconf_client_get_string (data->client,
 					  WP_PCOLOR_KEY, NULL);
@@ -379,6 +388,7 @@
     GnomeWPItem * wpitem = list->data;
     const char * none = "(none)";
     gchar * filename;
+    const gchar * scale, * shade;
     gchar * pcolor, * scolor;
 
     if (!strcmp (wpitem->filename, none) ||
@@ -390,13 +400,15 @@
 
     pcolor = gdk_color_to_string (wpitem->pcolor);
     scolor = gdk_color_to_string (wpitem->scolor);
+    scale = wp_item_option_to_string (wpitem->options);
+    shade = wp_item_shading_to_string (wpitem->shade_type);
 
     wallpaper = xmlNewChild (root, NULL, (xmlChar *)"wallpaper", NULL);
     gnome_wp_xml_set_bool (wallpaper, (xmlChar *)"deleted", wpitem->deleted);
     item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"name", (xmlChar *)wpitem->name);
     item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"filename", (xmlChar *)filename);
-    item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)wpitem->options);
-    item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"shade_type", (xmlChar *)wpitem->shade_type);
+    item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"options", (xmlChar *)scale);
+    item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"shade_type", (xmlChar *)shade);
     item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"pcolor", (xmlChar *)pcolor);
     item = xmlNewTextChild (wallpaper, NULL, (xmlChar *)"scolor", (xmlChar *)scolor);
     g_free (pcolor);



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