[gnome-panel] panel: Finish porting all background handling to GSettings



commit 2dc604c01ee22f3f53432dbda144f2ad53ccf315
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Mar 25 12:13:16 2011 +0100

    panel: Finish porting all background handling to GSettings
    
    There were still some code needed for drag and drop.

 gnome-panel/panel-profile.c |  140 -------------------------------------------
 gnome-panel/panel.c         |   94 +++++++++++++++++++++++------
 2 files changed, 76 insertions(+), 158 deletions(-)
---
diff --git a/gnome-panel/panel-profile.c b/gnome-panel/panel-profile.c
index 24402bf..f803c4e 100644
--- a/gnome-panel/panel-profile.c
+++ b/gnome-panel/panel-profile.c
@@ -56,13 +56,6 @@ static GConfEnumStringPair panel_orientation_map [] = {
 	{ 0,                        NULL     }
 };
 
-static GConfEnumStringPair panel_background_type_map [] = {
-	{ PANEL_BACK_NONE,  "gtk"   },
-	{ PANEL_BACK_COLOR, "color" },
-	{ PANEL_BACK_IMAGE, "image" },
-	{ 0,                NULL    }
-};
-
 static GConfEnumStringPair panel_object_type_map [] = {
 	{ PANEL_OBJECT_MENU,      "menu-object" },
 	{ PANEL_OBJECT_LAUNCHER,  "launcher-object" },
@@ -104,12 +97,6 @@ panel_profile_map_orientation (PanelOrientation orientation)
 	return gconf_enum_to_string (panel_orientation_map, orientation);
 }
 
-const char *
-panel_profile_map_background_type (PanelBackgroundType  background_type)
-{
-	return gconf_enum_to_string (panel_background_type_map, background_type);
-}
-
 gboolean
 panel_profile_map_object_type_string (const char       *str,
 				      PanelObjectType  *object_type)
@@ -206,133 +193,6 @@ panel_profile_get_toplevel_key (PanelToplevel *toplevel,
 		return gconf_client_key_is_writable (client, key, NULL); \
 	}
 
-void
-panel_profile_set_background_type (PanelToplevel       *toplevel,
-				   PanelBackgroundType  background_type)
-{
-	GConfClient *client;
-	const char  *key;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_profile_get_toplevel_key (toplevel, "background/type");
-	gconf_client_set_string (client,
-				 key,
-				 panel_profile_map_background_type (background_type),
-			         NULL);
-}
-
-
-TOPLEVEL_IS_WRITABLE_FUNC ("background/type", background, type)
-
-static void
-panel_profile_set_background_opacity (PanelToplevel *toplevel,
-				      gdouble        opacity)
-{
-	GConfClient *client;
-	const char  *key;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
-	gconf_client_set_int (client, key, (guint16) ((opacity * 65535.) + 0.5), NULL);
-}
-
-static gdouble
-panel_profile_get_background_opacity (PanelToplevel *toplevel)
-{
-	GConfClient *client;
-	const char  *key;
-	guint16      opacity;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_profile_get_toplevel_key (toplevel, "background/opacity");
-	opacity = gconf_client_get_int (client, key, NULL);
-
-	return opacity / 65535.;
-}
-
-TOPLEVEL_IS_WRITABLE_FUNC ("background/opacity", background, opacity)
-
-void
-panel_profile_set_background_color (PanelToplevel *toplevel,
-				    const GdkRGBA *color)
-{
-        GConfClient *client;
-        const char  *key;
-        char        *color_str;
-
-        client = panel_gconf_get_client ();
-
-        color_str = gdk_rgba_to_string (color);
-        key = panel_profile_get_toplevel_key (toplevel, "background/color");
-        gconf_client_set_string (client, key, color_str, NULL);
-
-        panel_profile_set_background_opacity (toplevel, color->alpha);
-
-        g_free (color_str);
-}
-
-void
-panel_profile_get_background_color (PanelToplevel *toplevel,
-				    GdkRGBA       *color)
-{
-        GConfClient *client;
-        const char  *key;
-        char        *color_str;
-
-        client = panel_gconf_get_client ();
-
-        key = panel_profile_get_toplevel_key (toplevel, "background/color");
-        color_str = gconf_client_get_string (client, key, NULL);
-        if (!color_str || !gdk_rgba_parse (color, color_str)) {
-                color->red   = 0.;
-                color->green = 0.;
-                color->blue  = 0.;
-                color->alpha = 1.;
-        }
-        color->alpha = panel_profile_get_background_opacity (toplevel);
-
-        g_free (color_str);
-}
-
-TOPLEVEL_IS_WRITABLE_FUNC ("background/color", background, color)
-
-void
-panel_profile_set_background_image (PanelToplevel *toplevel,
-				    const char    *image)
-{
-	GConfClient *client;
-	const char  *key;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_profile_get_toplevel_key (toplevel, "background/image");
-
-	if (image && image [0])
-		gconf_client_set_string (client, key, image, NULL);
-	else
-		gconf_client_unset (client, key, NULL);
-}
-
-char *
-panel_profile_get_background_image (PanelToplevel *toplevel)
-{
-	GConfClient *client;
-	const char  *key;
-	char        *retval;
-
-	client = panel_gconf_get_client ();
-
-	key = panel_profile_get_toplevel_key (toplevel, "background/image");
-	retval = gconf_client_get_string (client, key, NULL);
-
-	return retval;
-}
-
-TOPLEVEL_IS_WRITABLE_FUNC ("background/image", background, image)
-
 PanelOrientation
 panel_profile_get_toplevel_orientation (PanelToplevel *toplevel)
 {
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index b3a5ea7..07f95ee 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -388,23 +388,53 @@ panel_key_press_event (PanelToplevel *toplevel,
 	return FALSE;
 }
 
+static GSettings *
+get_settings_background_for_toplevel (PanelToplevel *toplevel)
+{
+	char      *toplevel_settings_path;
+	GSettings *settings;
+	GSettings *settings_background;
+
+	g_object_get (toplevel, "settings-path", &toplevel_settings_path, NULL);
+	settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA,
+					     toplevel_settings_path);
+	settings_background = g_settings_get_child (settings,
+						    PANEL_BACKGROUND_SCHEMA_CHILD);
+
+	g_object_unref (settings);
+	g_free (toplevel_settings_path);
+
+	return settings_background;
+}
+
 static gboolean
 set_background_image_from_uri (PanelToplevel *toplevel,
 			       const char    *uri)
 {
-	char *image;
+	GFile     *file;
+	GSettings *settings;
 
-	if ( ! panel_profile_is_writable_background_type (toplevel) ||
-	     ! panel_profile_is_writable_background_image (toplevel))
+	file = g_file_new_for_uri (uri);
+	if (!g_file_is_native (file)) {
+		g_object_unref (file);
 		return FALSE;
+	}
+	g_object_unref (file);
+
+	settings = get_settings_background_for_toplevel (toplevel);
 
-	if (!(image = g_filename_from_uri (uri, NULL, NULL)))
+	if (!g_settings_is_writable (settings,
+				     PANEL_BACKGROUND_TYPE_KEY) ||
+	    !g_settings_is_writable (settings,
+				     PANEL_BACKGROUND_IMAGE_URI_KEY)) {
+		g_object_unref (settings);
 		return FALSE;
+	}
 
-	panel_profile_set_background_image (toplevel, image);
-	panel_profile_set_background_type (toplevel, PANEL_BACK_IMAGE);
+	g_settings_set_string (settings, PANEL_BACKGROUND_IMAGE_URI_KEY, uri);
+	g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_IMAGE);
 
-	g_free (image);
+	g_object_unref (settings);
 
 	return FALSE;
 }
@@ -413,22 +443,55 @@ static gboolean
 set_background_color (PanelToplevel *toplevel,
 		      guint16       *dropped)
 {
-	GdkRGBA color;
+	GSettings *settings;
+	GdkRGBA    color;
+	char      *color_str;
 
 	if (!dropped)
 		return FALSE;
 
-	if ( ! panel_profile_is_writable_background_type (toplevel) ||
-	     ! panel_profile_is_writable_background_color (toplevel))
+	settings = get_settings_background_for_toplevel (toplevel);
+
+	if (!g_settings_is_writable (settings,
+				     PANEL_BACKGROUND_TYPE_KEY) ||
+	    !g_settings_is_writable (settings,
+				     PANEL_BACKGROUND_COLOR_KEY)) {
+		g_object_unref (settings);
 		return FALSE;
+	}
 
 	color.red   = dropped [0] / 65535.;
 	color.green = dropped [1] / 65535.;
 	color.blue  = dropped [2] / 65535.;
 	color.alpha = 1.;
 
-	panel_profile_set_background_color (toplevel, &color);
-	panel_profile_set_background_type (toplevel, PANEL_BACK_COLOR);
+	color_str = gdk_rgba_to_string (&color);
+
+	g_settings_set_string (settings, PANEL_BACKGROUND_COLOR_KEY, color_str);
+	g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_COLOR);
+
+	g_free (color_str);
+	g_object_unref (settings);
+
+	return TRUE;
+}
+
+static gboolean
+reset_background (PanelToplevel *toplevel)
+{
+	GSettings *settings;
+
+	settings = get_settings_background_for_toplevel (toplevel);
+
+	if (!g_settings_is_writable (settings,
+				     PANEL_BACKGROUND_TYPE_KEY)) {
+		g_object_unref (settings);
+		return FALSE;
+	}
+
+	g_settings_set_enum (settings, PANEL_BACKGROUND_TYPE_KEY, PANEL_BACK_NONE);
+
+	g_object_unref (settings);
 
 	return TRUE;
 }
@@ -1102,12 +1165,7 @@ panel_receive_dnd_data (PanelWidget      *panel,
 		success = set_background_image_from_uri (panel->toplevel, (char *) data);
 		break;
 	case TARGET_BACKGROUND_RESET:
-		if (panel_profile_is_writable_background_type (panel->toplevel)) {
-			panel_profile_set_background_type (panel->toplevel, PANEL_BACK_NONE);
-			success = TRUE;
-		} else {
-			success = FALSE;
-		}
+		success = reset_background (panel->toplevel);
 		break;
 	case TARGET_DIRECTORY:
 		success = drop_uri (panel, pos, (char *)data,



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