Background Properties UI patch



This (committed) patch adds an "Enable wallpaper image" checkbox to the
Background capplet. Additionally it sets the sensitivity of the color
options frame based on whether any colors will actually be visible.



? wallpaper-enable.patch
? background-enabled.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/ChangeLog,v
retrieving revision 1.41
diff -u -r1.41 ChangeLog
--- ChangeLog	2001/08/28 13:45:20	1.41
+++ ChangeLog	2001/09/08 00:38:20
@@ -1,3 +1,25 @@
+2001-09-07  Richard Hestilow  <hestilow ximian com>
+
+	* background-properties.glade: Redid UI a bit to add new enabled
+	checkbox.
+	
+	* background-properties.xml: Add default for "wallpaper_enabled".
+	
+	* preferences.[ch]: New function preferences_need_color_opts.
+	(preferences_load_from_bonobo_db): Load wallpaper_enabled from
+	bonobo-conf.
+	(preferences_load_from_bonobo_pbag): Ditto.
+
+	* applier.[ch]: New function applier_get_wallpaper_pixbuf
+	(needed by preferences_need_color_opts, else pixbuf gets created
+	twice).
+
+	* background-properties-capplet.c (real_realize_cb): Set
+	color frame sensitivity based on preferences_need_color_opts.
+	(property_change_cb): Ditto.
+	(setup_dialog): Add peditor/guard for wallpaper_enabled. Also,
+	set glade object data on the preferences structure as well.
+	
 2001-08-28  Bradford Hovinen  <hovinen ximian com>
 
 	* background-properties-capplet.c (get_legacy_settings): Retrieve
Index: applier.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/applier.c,v
retrieving revision 1.35
diff -u -r1.35 applier.c
--- applier.c	2001/08/28 13:42:49	1.35
+++ applier.c	2001/09/08 00:38:28
@@ -30,7 +30,6 @@
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdkprivate.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gdk-pixbuf/gdk-pixbuf-xlib.h>
 
 #include <X11/Xlib.h>
@@ -1413,4 +1412,12 @@
 	gnome_config_set_int ("/Background/Default/opacity", prefs->opacity);
 
 	gnome_config_sync ();
+}
+
+GdkPixbuf *
+applier_get_wallpaper_pixbuf (Applier *applier)
+{
+	g_return_val_if_fail (applier != NULL, NULL);
+
+	return applier->private->wallpaper_pixbuf;
 }
Index: applier.h
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/applier.h,v
retrieving revision 1.6
diff -u -r1.6 applier.h
--- applier.h	2001/08/28 13:01:42	1.6
+++ applier.h	2001/09/08 00:38:28
@@ -25,6 +25,7 @@
 #define __APPLIER_H
 
 #include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include <X11/Xlib.h>
 #include <pthread.h>
@@ -60,5 +61,7 @@
 				  gboolean do_root, gboolean do_preview);
 
 GtkWidget   *applier_get_preview_widget (Applier *applier);
+
+GdkPixbuf   *applier_get_wallpaper_pixbuf (Applier *applier);
 
 #endif /* __APPLIER_H */
Index: background-properties-capplet.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/background-properties-capplet.c,v
retrieving revision 1.12
diff -u -r1.12 background-properties-capplet.c
--- background-properties-capplet.c	2001/08/28 13:45:20	1.12
+++ background-properties-capplet.c	2001/09/08 00:38:35
@@ -192,27 +192,52 @@
 		    CORBA_Environment  *ev,
 		    Preferences        *prefs)
 {
+	GladeXML *dialog;
+	
 	g_return_if_fail (prefs != NULL);
 	g_return_if_fail (IS_PREFERENCES (prefs));
 
 	if (GTK_OBJECT_DESTROYED (prefs))
 		return;
-	
+
+	dialog = gtk_object_get_data (GTK_OBJECT (prefs), "glade-data");
+
 	preferences_apply_event (prefs, event_name, any);
 	applier_apply_prefs (applier, prefs, FALSE, TRUE);
+
+	if (!strcmp (event_name, "Bonobo/Property:change:wallpaper_type")
+	    || !strcmp (event_name, "Bonobo/Property:change:wallpaper_filename")
+	    || !strcmp (event_name, "Bonobo/Property:change:wallpaper_enabled"))
+	{
+		gtk_widget_set_sensitive (
+			WID ("color_frame"),
+			preferences_need_color_opts (
+				prefs,
+				applier_get_wallpaper_pixbuf (applier)));
+	}
 }
 
 static gboolean
 real_realize_cb (Preferences *prefs) 
 {
+	GladeXML *dialog;
+
 	g_return_val_if_fail (prefs != NULL, TRUE);
 	g_return_val_if_fail (IS_PREFERENCES (prefs), TRUE);
 
 	if (GTK_OBJECT_DESTROYED (prefs))
 		return FALSE;
 
+	dialog = gtk_object_get_data (GTK_OBJECT (prefs), "glade-data");
+
 	applier_apply_prefs (applier, prefs, FALSE, TRUE);
 
+	gtk_widget_set_sensitive (
+		WID ("color_frame"),
+		preferences_need_color_opts (
+			prefs,
+			applier_get_wallpaper_pixbuf (applier)));
+
 	return FALSE;
 }
 
@@ -242,6 +267,7 @@
 	GladeXML          *dialog;
 	Applier           *applier;
 	GtkObject         *prefs;
+	
 	CORBA_Environment  ev;
 
 	CORBA_exception_init (&ev);
@@ -256,6 +282,10 @@
 	CUSTOM_CREATE_PEDITOR (option_menu, ulong, "wallpaper_type", "image_option");	
 	CUSTOM_CREATE_PEDITOR (int_range, long, "opacity", "opacity_spin");
 
+	CREATE_PEDITOR (boolean, "wallpaper_enabled", "picture_enabled_check");
+
+	bonobo_peditor_set_guard (WID ("picture_frame"), bag, "wallpaper_enabled");
+			
 	/* Disable opacity controls */
 	gtk_widget_hide (WID ("opacity_spin"));
 	gtk_widget_hide (WID ("opacity_label"));
@@ -263,6 +293,7 @@
 	bonobo_property_bag_client_set_value_gboolean (bag, "enabled", TRUE, NULL);
 
 	prefs = preferences_new_from_bonobo_pbag (bag, &ev);
+	gtk_object_set_data (GTK_OBJECT (prefs), "glade-data", dialog);
 	bonobo_event_source_client_add_listener (bag, (BonoboListenerCallbackFn) property_change_cb,
 						 NULL, NULL, prefs);
 
@@ -296,7 +327,9 @@
 			    TRUE, TRUE, 0);
 	gtk_widget_show_all (holder);
 
+#if 0
 	gnome_entry_append_history (GNOME_ENTRY (gnome_file_entry_gnome_entry (GNOME_FILE_ENTRY (WID ("image_fileentry")))), 0, "(none)");
+#endif
 
 	gtk_signal_connect_object (GTK_OBJECT (widget), "destroy",
 				   GTK_SIGNAL_FUNC (gtk_object_destroy),
Index: background-properties.glade
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/background-properties.glade,v
retrieving revision 1.16
diff -u -r1.16 background-properties.glade
--- background-properties.glade	2001/07/27 01:33:19	1.16
+++ background-properties.glade	2001/09/08 00:38:35
@@ -59,91 +59,22 @@
     </widget>
 
     <widget>
-      <class>GtkFrame</class>
-      <name>frame4</name>
-      <border_width>4</border_width>
-      <label>Background colors</label>
-      <label_xalign>0</label_xalign>
-      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <class>GtkCheckButton</class>
+      <name>picture_enabled_check</name>
+      <can_focus>True</can_focus>
+      <label>Use a picture for the background</label>
+      <active>False</active>
+      <draw_indicator>True</draw_indicator>
       <child>
 	<padding>0</padding>
 	<expand>False</expand>
 	<fill>False</fill>
       </child>
-
-      <widget>
-	<class>GtkHBox</class>
-	<name>hbox4</name>
-	<border_width>10</border_width>
-	<homogeneous>False</homogeneous>
-	<spacing>8</spacing>
-
-	<widget>
-	  <class>GtkLabel</class>
-	  <name>label19</name>
-	  <label>Style:</label>
-	  <justify>GTK_JUSTIFY_CENTER</justify>
-	  <wrap>False</wrap>
-	  <xalign>0.5</xalign>
-	  <yalign>0.5</yalign>
-	  <xpad>0</xpad>
-	  <ypad>0</ypad>
-	  <child>
-	    <padding>0</padding>
-	    <expand>False</expand>
-	    <fill>False</fill>
-	  </child>
-	</widget>
-
-	<widget>
-	  <class>GtkOptionMenu</class>
-	  <name>color_option</name>
-	  <can_focus>True</can_focus>
-	  <items>Solid color
-Horizontal gradient
-Vertical gradient
-</items>
-	  <initial_choice>0</initial_choice>
-	  <child>
-	    <padding>0</padding>
-	    <expand>False</expand>
-	    <fill>False</fill>
-	  </child>
-	</widget>
-
-	<widget>
-	  <class>GnomeColorPicker</class>
-	  <name>colorpicker1</name>
-	  <can_focus>True</can_focus>
-	  <dither>True</dither>
-	  <use_alpha>False</use_alpha>
-	  <title>Pick a color</title>
-	  <child>
-	    <padding>0</padding>
-	    <expand>False</expand>
-	    <fill>False</fill>
-	  </child>
-	</widget>
-
-	<widget>
-	  <class>GnomeColorPicker</class>
-	  <name>colorpicker2</name>
-	  <can_focus>True</can_focus>
-	  <dither>True</dither>
-	  <use_alpha>False</use_alpha>
-	  <title>Pick a color</title>
-	  <child>
-	    <padding>0</padding>
-	    <expand>False</expand>
-	    <fill>False</fill>
-	  </child>
-	</widget>
-      </widget>
     </widget>
 
     <widget>
       <class>GtkFrame</class>
-      <name>frame3</name>
+      <name>picture_frame</name>
       <border_width>4</border_width>
       <label>Background picture</label>
       <label_xalign>0</label_xalign>
@@ -374,6 +305,89 @@
 	    <yshrink>False</yshrink>
 	    <xfill>True</xfill>
 	    <yfill>False</yfill>
+	  </child>
+	</widget>
+      </widget>
+    </widget>
+
+    <widget>
+      <class>GtkFrame</class>
+      <name>color_frame</name>
+      <border_width>4</border_width>
+      <label>Background colors</label>
+      <label_xalign>0</label_xalign>
+      <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+      <child>
+	<padding>0</padding>
+	<expand>False</expand>
+	<fill>False</fill>
+      </child>
+
+      <widget>
+	<class>GtkHBox</class>
+	<name>hbox4</name>
+	<border_width>10</border_width>
+	<homogeneous>False</homogeneous>
+	<spacing>8</spacing>
+
+	<widget>
+	  <class>GtkLabel</class>
+	  <name>label19</name>
+	  <label>Style:</label>
+	  <justify>GTK_JUSTIFY_CENTER</justify>
+	  <wrap>False</wrap>
+	  <xalign>0.5</xalign>
+	  <yalign>0.5</yalign>
+	  <xpad>0</xpad>
+	  <ypad>0</ypad>
+	  <child>
+	    <padding>0</padding>
+	    <expand>False</expand>
+	    <fill>False</fill>
+	  </child>
+	</widget>
+
+	<widget>
+	  <class>GtkOptionMenu</class>
+	  <name>color_option</name>
+	  <can_focus>True</can_focus>
+	  <items>Solid color
+Horizontal gradient
+Vertical gradient
+</items>
+	  <initial_choice>0</initial_choice>
+	  <child>
+	    <padding>0</padding>
+	    <expand>False</expand>
+	    <fill>False</fill>
+	  </child>
+	</widget>
+
+	<widget>
+	  <class>GnomeColorPicker</class>
+	  <name>colorpicker1</name>
+	  <can_focus>True</can_focus>
+	  <dither>True</dither>
+	  <use_alpha>False</use_alpha>
+	  <title>Pick a color</title>
+	  <child>
+	    <padding>0</padding>
+	    <expand>False</expand>
+	    <fill>False</fill>
+	  </child>
+	</widget>
+
+	<widget>
+	  <class>GnomeColorPicker</class>
+	  <name>colorpicker2</name>
+	  <can_focus>True</can_focus>
+	  <dither>True</dither>
+	  <use_alpha>False</use_alpha>
+	  <title>Pick a color</title>
+	  <child>
+	    <padding>0</padding>
+	    <expand>False</expand>
+	    <fill>False</fill>
 	  </child>
 	</widget>
       </widget>
Index: background-properties.xml
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/background-properties.xml,v
retrieving revision 1.4
diff -u -r1.4 background-properties.xml
--- background-properties.xml	2001/08/13 18:39:08	1.4
+++ background-properties.xml	2001/09/08 00:38:36
@@ -65,5 +65,6 @@
     </entry>
     <entry name="opacity" type="long" value="100"/>
     <entry name="enabled" type="boolean" value="true"/>
+    <entry name="wallpaper_enabled" type="boolean" value="true"/>
   </section>
 </bonobo-config>
Index: preferences.c
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/preferences.c,v
retrieving revision 1.22
diff -u -r1.22 preferences.c
--- preferences.c	2001/08/28 13:32:01	1.22
+++ preferences.c	2001/09/08 00:38:37
@@ -236,12 +236,7 @@
 	prefs->wallpaper_type = bonobo_property_bag_client_get_value_gulong (pb, "wallpaper_type", ev);
 	prefs->wallpaper_filename = g_strdup (*((CORBA_char **)(PB_GET_VALUE ("wallpaper_filename"))->_value));
 
-	if (prefs->wallpaper_filename != NULL &&
-	    strcmp (prefs->wallpaper_filename, "") != 0 &&
-	    strcmp (prefs->wallpaper_filename, "(none)") != 0)
-		prefs->wallpaper_enabled = TRUE;
-	else
-		prefs->wallpaper_enabled = FALSE;
+	prefs->wallpaper_enabled = bonobo_property_bag_client_get_value_gboolean (pb, "wallpaper_enabled", ev);
 	
 	prefs->color1 = bonobo_color_to_gdk ((Bonobo_Config_Color *)(PB_GET_VALUE ("color1"))->_value);
 	prefs->color2 = bonobo_color_to_gdk ((Bonobo_Config_Color *)(PB_GET_VALUE ("color2"))->_value);
@@ -294,13 +289,9 @@
 
 	prefs->wallpaper_type = bonobo_config_get_ulong (db, "/main/wallpaper_type", NULL);
 	prefs->wallpaper_filename = g_strdup (*((CORBA_char **)(DB_GET_VALUE ("/main/wallpaper_filename"))->_value));
-	if (prefs->wallpaper_filename && 
-	    strcmp (prefs->wallpaper_filename, "") != 0 &&
-	    strcmp (prefs->wallpaper_filename, "(none)") != 0)
-		prefs->wallpaper_enabled = TRUE;
-	else
-		prefs->wallpaper_enabled = FALSE;
 	
+	prefs->wallpaper_enabled = BONOBO_ARG_GET_BOOLEAN (DB_GET_VALUE ("/main/wallpaper_enabled"));
+
 	prefs->color1 = bonobo_color_to_gdk ((Bonobo_Config_Color *)(DB_GET_VALUE ("/main/color1"))->_value);
 	prefs->color2 = bonobo_color_to_gdk ((Bonobo_Config_Color *)(DB_GET_VALUE ("/main/color2"))->_value);
 
@@ -362,6 +353,9 @@
 			prefs->gradient_enabled = FALSE;
 		else
 			prefs->gradient_enabled = TRUE;
+	}
+	else if (!strcmp (name, "wallpaper_enabled")) {
+		prefs->wallpaper_enabled = BONOBO_ARG_GET_BOOLEAN (value);
 	} else {
 		g_warning ("%s: Unknown property: %s", __FUNCTION__, name);
 	}
@@ -784,4 +778,48 @@
 	color->pixel = xlib_rgb_xpixel_from_rgb (rgb);
 
 	return color;
+}
+
+/* It'd be nice if we could just get the pixbuf the applier uses, for
+ * efficiency's sake */
+gboolean
+preferences_need_color_opts (Preferences *prefs, GdkPixbuf *wallpaper_pixbuf)
+{
+	int s_width, s_height;
+	int p_width, p_height;
+	
+	g_return_val_if_fail (prefs != NULL, TRUE);
+
+	if (!(prefs->wallpaper_enabled && prefs->wallpaper_filename))
+		return TRUE;
+
+	if (!wallpaper_pixbuf)
+		return TRUE;
+
+	p_width = gdk_pixbuf_get_width (wallpaper_pixbuf);
+	p_height = gdk_pixbuf_get_height (wallpaper_pixbuf);
+	
+	s_width = gdk_screen_width ();
+	s_height = gdk_screen_height ();
+
+	switch (prefs->wallpaper_type)
+	{
+		case WPTYPE_CENTERED:
+			if (p_width >= s_width && p_height >= s_height)
+				return FALSE;
+			else
+				return TRUE;
+			break;
+		case WPTYPE_SCALED_ASPECT:
+			if (s_width == p_width && s_height == p_height)
+				return FALSE;
+			else if (((double) s_width / (double) s_height)
+				 == ((double) p_width / (double) p_height))
+				return FALSE;
+			else
+				return TRUE;
+			break;
+		default:
+			return FALSE;
+	}
 }
Index: preferences.h
===================================================================
RCS file: /cvs/gnome/gnome-control-center/capplets/background/preferences.h,v
retrieving revision 1.11
diff -u -r1.11 preferences.h
--- preferences.h	2001/08/28 13:01:42	1.11
+++ preferences.h	2001/09/08 00:38:37
@@ -25,6 +25,7 @@
 #define __PREFERENCES_H
 
 #include <gtk/gtk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #ifdef BONOBO_CONF_ENABLE
 #include <bonobo-conf/bonobo-config-database.h>
@@ -85,6 +86,9 @@
 GtkObject   *preferences_clone                (const Preferences     *prefs);
 
 void         preferences_destroy              (GtkObject             *object);
+
+gboolean     preferences_need_color_opts      (Preferences           *prefs,
+					       GdkPixbuf   *wallpaper_pixbuf);
 
 #ifdef BONOBO_CONF_ENABLE
 


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