[gnome-panel/wip/3.0-freeze-break] panel: Change background image to an uri in gsettings



commit c1b60b3aa36d388c14f3f9d7221cab4101def16d
Author: Vincent Untz <vuntz gnome org>
Date:   Fri Mar 25 11:38:43 2011 +0100

    panel: Change background image to an uri in gsettings
    
    We rename the key to make this clear, and we also rename the rotate key
    to image-rotate to clearly show it applies to the image only.

 data/org.gnome.gnome-panel.toplevel.gschema.xml |    4 +-
 gnome-panel/panel-background.c                  |   51 ++++++++++++++++-------
 gnome-panel/panel-properties-dialog.c           |   32 +++++++-------
 gnome-panel/panel-schemas.h                     |   16 ++++----
 4 files changed, 62 insertions(+), 41 deletions(-)
---
diff --git a/data/org.gnome.gnome-panel.toplevel.gschema.xml b/data/org.gnome.gnome-panel.toplevel.gschema.xml
index 432c5d6..a97f445 100644
--- a/data/org.gnome.gnome-panel.toplevel.gschema.xml
+++ b/data/org.gnome.gnome-panel.toplevel.gschema.xml
@@ -108,7 +108,7 @@
       <summary>Background color</summary>
       <description>Specifies the background color for the panel in #RGB format.</description>
     </key>
-    <key name="image" type="s">
+    <key name="image-uri" type="s">
       <default>''</default>
       <summary>Background image</summary>
       <description>Specifies the file to be used for the background image. If the image contains an alpha channel it will be composited onto the desktop background image.</description>
@@ -123,7 +123,7 @@
       <summary>Stretch image to panel</summary>
       <description>If true, the image will be scaled to the panel dimensions. The aspect ratio of the image will not be maintained.</description>
     </key>
-    <key name="rotate" type="b">
+    <key name="image-rotate" type="b">
       <default>false</default>
       <summary>Rotate image on vertical panels</summary>
       <description>If true, the background image will be rotated when the panel is oriented vertically.</description>
diff --git a/gnome-panel/panel-background.c b/gnome-panel/panel-background.c
index 441f656..09f0697 100644
--- a/gnome-panel/panel-background.c
+++ b/gnome-panel/panel-background.c
@@ -32,6 +32,8 @@
 #include <cairo.h>
 #include <cairo-xlib.h>
 
+#include <libpanel-util/panel-glib.h>
+
 #include "panel-background-monitor.h"
 #include "panel-schemas.h"
 #include "panel-util.h"
@@ -551,8 +553,8 @@ panel_background_set_color (PanelBackground *background,
 }
 
 static void
-panel_background_set_image_no_update (PanelBackground *background,
-				      const char      *image)
+panel_background_set_image_uri_no_update (PanelBackground *background,
+					  const char      *uri)
 {
 	if (background->loaded_image)
 		g_object_unref (background->loaded_image);
@@ -562,24 +564,43 @@ panel_background_set_image_no_update (PanelBackground *background,
 		g_free (background->image);
 	background->image = NULL;
 
-	if (image && image [0])
-		background->image = g_strdup (image);
+	if (!PANEL_GLIB_STR_EMPTY (uri)) {
+		GFile *file;
+		file = g_file_new_for_uri (uri);
+
+		if (g_file_is_native (file))
+			background->image = g_file_get_path (file);
+
+		g_object_unref (file);
+	}
 
 	panel_background_update_has_alpha (background);
 }
 
 static void
-panel_background_set_image (PanelBackground *background,
-			    const char      *image)
+panel_background_set_image_uri (PanelBackground *background,
+				const char      *uri)
 {
-	if (!background->image && !image)
+	GFile *file;
+	char  *current_uri = NULL;
+
+	if (!background->image && !uri)
 		return;
 
-	if (background->image && image && !strcmp (background->image, image))
+	if (background->image) {
+		file = g_file_new_for_path (background->image);
+		current_uri = g_file_get_uri (file);
+		g_object_unref (file);
+	}
+
+	if (g_strcmp0 (current_uri, uri) == 0) {
+		g_free (current_uri);
 		return;
+	}
+	g_free (current_uri);
 
 	free_transformed_resources (background);
-	panel_background_set_image_no_update (background, image);
+	panel_background_set_image_uri_no_update (background, uri);
 	panel_background_transform (background);
 }
 
@@ -664,9 +685,9 @@ panel_background_settings_changed (GSettings       *settings,
 		if (gdk_rgba_parse (&color, value_str))
 			panel_background_set_color (background, &color);
 		g_free (value_str);
-	} else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_KEY) == 0) {
+	} else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_URI_KEY) == 0) {
 		value_str = g_settings_get_string (settings, key);
-		panel_background_set_image (background, value_str);
+		panel_background_set_image_uri (background, value_str);
 		g_free (value_str);
 	} else if (g_strcmp0 (key, PANEL_BACKGROUND_FIT_KEY) == 0) {
 		value_boolean = g_settings_get_boolean (settings, key);
@@ -674,7 +695,7 @@ panel_background_settings_changed (GSettings       *settings,
 	} else if (g_strcmp0 (key, PANEL_BACKGROUND_STRETCH_KEY) == 0) {
 		value_boolean = g_settings_get_boolean (settings, key);
 		panel_background_set_stretch (background, value_boolean);
-	} else if (g_strcmp0 (key, PANEL_BACKGROUND_ROTATE_KEY) == 0) {
+	} else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_ROTATE_KEY) == 0) {
 		value_boolean = g_settings_get_boolean (settings, key);
 		panel_background_set_rotate (background, value_boolean);
 	} else {
@@ -709,8 +730,8 @@ panel_background_settings_init (PanelBackground *background,
 	g_free (color_str);
 
 	image = g_settings_get_string (background->settings,
-				       PANEL_BACKGROUND_IMAGE_KEY);
-	panel_background_set_image_no_update (background, image);
+				       PANEL_BACKGROUND_IMAGE_URI_KEY);
+	panel_background_set_image_uri_no_update (background, image);
 	g_free (image);
 
 	fit_image = g_settings_get_boolean (background->settings,
@@ -722,7 +743,7 @@ panel_background_settings_init (PanelBackground *background,
 	panel_background_set_stretch_no_update (background, stretch_image);
 
 	rotate_image = g_settings_get_boolean (background->settings,
-					       PANEL_BACKGROUND_ROTATE_KEY);
+					       PANEL_BACKGROUND_IMAGE_ROTATE_KEY);
 	panel_background_set_rotate_no_update (background, rotate_image);
 
 	type = g_settings_get_enum (background->settings,
diff --git a/gnome-panel/panel-properties-dialog.c b/gnome-panel/panel-properties-dialog.c
index 4e7ed59..3193ba1 100644
--- a/gnome-panel/panel-properties-dialog.c
+++ b/gnome-panel/panel-properties-dialog.c
@@ -354,32 +354,32 @@ panel_properties_dialog_arrows_toggle_setup (PanelPropertiesDialog *dialog,
 static void
 panel_properties_dialog_background_image_update (PanelPropertiesDialog *dialog)
 {
-	char *filename;
+	char *uri;
 
-	filename = g_settings_get_string (dialog->settings_background,
-					  PANEL_BACKGROUND_IMAGE_KEY);
+	uri = g_settings_get_string (dialog->settings_background,
+				     PANEL_BACKGROUND_IMAGE_URI_KEY);
 
-	if (PANEL_GLIB_STR_EMPTY (filename))
+	if (PANEL_GLIB_STR_EMPTY (uri))
 		gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser));
 	else
-		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->image_chooser),
-					       filename);
+		gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog->image_chooser),
+					  uri);
 
-	g_free (filename);
+	g_free (uri);
 }
 
 static void
 panel_properties_dialog_image_chooser_changed (PanelPropertiesDialog *dialog)
 {
-	char *image;
+	char *uri;
 
-	image = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->image_chooser));
-	if (!image)
-		image = g_strdup ("");
+	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog->image_chooser));
+	if (!uri)
+		uri = g_strdup ("");
 
 	g_settings_set_string (dialog->settings_background,
-			       PANEL_BACKGROUND_IMAGE_KEY, image);
-	g_free (image);
+			       PANEL_BACKGROUND_IMAGE_URI_KEY, uri);
+	g_free (uri);
 }
 
 static void
@@ -396,11 +396,11 @@ panel_properties_dialog_image_chooser_setup (PanelPropertiesDialog *dialog,
 				  dialog);
 
 	g_settings_bind_writable (dialog->settings_background,
-				  PANEL_BACKGROUND_IMAGE_KEY,
+				  PANEL_BACKGROUND_IMAGE_URI_KEY,
 				  dialog->image_chooser, "sensitive", FALSE);
 
 	if (!g_settings_is_writable (dialog->settings_background,
-				     PANEL_BACKGROUND_IMAGE_KEY))
+				     PANEL_BACKGROUND_IMAGE_URI_KEY))
 		gtk_widget_show (dialog->writability_warn_background);
 }
 
@@ -672,7 +672,7 @@ panel_properties_dialog_background_changed (GSettings             *settings,
 {
 	if (g_strcmp0 (key, PANEL_BACKGROUND_TYPE_KEY) == 0)
 		panel_properties_dialog_background_type_update (dialog);
-	else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_KEY) == 0)
+	else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_URI_KEY) == 0)
 		panel_properties_dialog_background_image_update (dialog);
 	else if (g_strcmp0 (key, PANEL_BACKGROUND_COLOR_KEY) == 0)
 		panel_properties_dialog_background_color_update (dialog);
diff --git a/gnome-panel/panel-schemas.h b/gnome-panel/panel-schemas.h
index ea968d2..d40000e 100644
--- a/gnome-panel/panel-schemas.h
+++ b/gnome-panel/panel-schemas.h
@@ -52,14 +52,14 @@
 #define PANEL_TOPLEVEL_AUTO_HIDE_SIZE_KEY   "auto-hide-size"
 #define PANEL_TOPLEVEL_ANIMATION_SPEED_KEY  "animation-speed"
 
-#define PANEL_BACKGROUND_SCHEMA_CHILD   "background"
-#define PANEL_BACKGROUND_TYPE_KEY       "type"
-#define PANEL_BACKGROUND_COLOR_KEY      "color"
-#define PANEL_BACKGROUND_IMAGE_KEY      "image"
-#define PANEL_BACKGROUND_FIT_KEY        "fit"
-#define PANEL_BACKGROUND_STRETCH_KEY    "stretch"
-#define PANEL_BACKGROUND_ROTATE_KEY     "rotate"
-#define PANEL_BACKGROUND_COLOR_DEFAULT  "rgba(255,255,255,.2)"
+#define PANEL_BACKGROUND_SCHEMA_CHILD     "background"
+#define PANEL_BACKGROUND_TYPE_KEY         "type"
+#define PANEL_BACKGROUND_COLOR_KEY        "color"
+#define PANEL_BACKGROUND_IMAGE_URI_KEY    "image-uri"
+#define PANEL_BACKGROUND_FIT_KEY          "fit"
+#define PANEL_BACKGROUND_STRETCH_KEY      "stretch"
+#define PANEL_BACKGROUND_IMAGE_ROTATE_KEY "image-rotate"
+#define PANEL_BACKGROUND_COLOR_DEFAULT    "rgba(255,255,255,.2)"
 
 #define PANEL_OBJECT_SCHEMA             "org.gnome.gnome-panel.object"
 #define PANEL_OBJECT_IID_KEY            "object-iid"



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