[Nautilus-list] Nautlius GConf preliminary patch



Hello,

I've been trying to remove (the deprecated) gnome_config from Nautlius
and replace it with GConf.

I've started on getting and updating desktop settings, and have
attatched a patch. This patch is in no way ready for the tree yet, but I
need some advice on the general direction and some spesifics.


The patch does the following:

 * Set only the primary color for desktop background, ignoring all
   other settings (but this should be easy to fix).

 * Leak a GConfClient object

 * Probably wreak havoc on Nautilus as a whole

Can someone take a look at it and tell me if I'm heading in the right
direction. Is it something obvious that I've missed?

Also, what would be the correct place to attach a GConfClinet to the
view, and the proper place to destroy it? (And am I right in the
assumption that if I unref the client in nautilus_desktop_set_background
the callback won't work)?

Please be gentle with me, as this is my first Nautilus effort, and I'm
not very familiar with the Gnome platform as a whole.
-- 
    tia, Håvard

havardw stud ntnu no||http://www.stud.ntnu.no/~havardw||+47 93 84 64 68
All it takes to start an avalanche is one snowflake||Or a snowboarder
     Oh! Un Fraggle! Regarde, maman! J'ai attrapé un Fraggle!
? gconf-1st.patch
? nautilus-gconf_preliminary.patch
? libnautilus-private/nautilus-directory-background.c.new
Index: libnautilus-private/nautilus-directory-background.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-background.c,v
retrieving revision 1.69
diff -c -u -r1.69 nautilus-directory-background.c
--- libnautilus-private/nautilus-directory-background.c	2002/01/18 15:10:34	1.69
+++ libnautilus-private/nautilus-directory-background.c	2002/01/23 12:04:24
@@ -63,6 +63,11 @@
 			const char* image, const char* default_image,
 			EelBackgroundImagePlacement placement, EelBackgroundImagePlacement default_placement);
 
+void nautilus_desktop_color1_callback(GConfClient* client,
+                                      guint cnxn_id,
+                                      GConfEntry *entry,
+                                      gpointer user_data);
+
 static void
 desktop_background_realized (NautilusIconContainer *icon_container, void *disconnect_signal)
 {
@@ -1003,4 +1008,151 @@
         file = nautilus_file_get (uri);
         nautilus_connect_background_to_file_metadata (widget, file);
         nautilus_file_unref (file);
+}
+
+void
+nautilus_desktop_color1_callback(GConfClient* client,
+                                 guint cnxn_id,
+                                 GConfEntry *entry,
+                                 gpointer user_data) {
+
+        const gchar *color;
+        EelBackground* background;
+
+        g_message("color1 callback\n");
+        g_assert(NAUTILUS_IS_ICON_CONTAINER(user_data));
+        background = eel_get_widget_background (GTK_WIDGET (user_data));
+
+        // FIXME: Need to check for valid string
+        color = gconf_value_get_string(entry->value);
+        g_message("Color value is '%s'\n", color);
+        eel_background_set_color (background, gconf_value_get_string(entry->value));
+}
+        
+
+
+void
+nautilus_desktop_set_background (NautilusIconContainer *icon_container,
+                                 NautilusFile *file)
+{
+	EelBackground *background;
+        GConfClient *client;
+        GError *gerror;
+        gpointer old_file;
+        char *color;
+        char *image;
+        EelBackgroundImagePlacement placement;
+
+	background = eel_get_widget_background (GTK_WIDGET (icon_container));
+        color = NULL;
+
+        // Get old file value. Can this have a value other than when changing the
+        // value for which directory is the desktop?
+	old_file = g_object_get_data (G_OBJECT (background), "eel_background_file");
+        if (old_file != NULL) {                
+                g_error("'old_file' was set, we need to handle this situation.\n");
+        }
+	if (old_file == file) {
+                g_error("Trying to set desktop directory to existing directory. (file==old_file)\n");
+		return;
+	}
+
+        // Make sure this is recognized as the desktop view
+        g_object_set_data (G_OBJECT (background), "theme_source", (gpointer) desktop_theme_source);
+
+
+        // Set up callbacks for EelBackground, so that the background is painted when we change
+        // settings later
+        if (file != NULL) {
+                g_message("Installing signal handlers\n");
+                g_signal_connect (background,
+                                  "settings_changed",
+                                  G_CALLBACK (background_changed_callback),
+                                  file);
+                g_signal_connect (background,
+                                  "destroy",
+                                  G_CALLBACK (background_destroyed_callback),
+                                  file);
+                g_signal_connect (background,
+                                  "reset",
+                                  G_CALLBACK (background_reset_callback),
+                                  file);
+        }
+        else {
+                g_error("'file' was NULL, what now?");
+        }
+
+        /* Load settings from GConf */
+        // FIXME: Should be done in initialization for view?
+        // This will leak a client reference
+        client = gconf_client_get_default();
+
+        color = gconf_client_get_string (client, 
+                                         "/desktop/gnome/background/color1",
+                                         &gerror);
+        // FIXME: Is this a valid color
+        if (gerror != NULL) {
+                // FIXME: Handle this error
+                g_error ("Error getting background color, setting to default.\n");
+                // FIXME: GConf is probably broken, set color to default widget background or something
+                color = "#FFFFFF";
+        }
+        else {
+                g_message ("Color from GConf is '%s'\n", color);
+        }
+
+
+        // IN PROGRESS: Use default values to see if this works
+
+        image = NULL;
+        placement = WALLPAPER_CENTERED;
+
+        /* Attach the new directory. */
+        nautilus_file_ref (file);
+        g_object_set_data_full (G_OBJECT (background),
+                                "eel_background_file",
+                                file,
+                                (GtkDestroyNotify) nautilus_file_unref);
+
+
+        /* Block signals for synchronized update */
+        gtk_signal_handler_block_by_func (GTK_OBJECT (background),
+                                          G_CALLBACK (background_changed_callback),
+                                          file);
+
+	eel_background_set_color (background, color);     
+        // FIXME: Should I free 'color'?
+
+        eel_background_set_image_uri_sync (background, image);
+
+        eel_background_set_image_placement (background, placement);
+	
+	/* Unblock the handler. */
+	gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
+                                            G_CALLBACK (background_changed_callback),
+                                            file);
+	
+
+        /** Set up callbacks for GConf changes. */
+        gconf_client_add_dir (client,
+                              "/desktop/gnome/background",
+                              GCONF_CLIENT_PRELOAD_NONE,
+                              NULL);
+
+        gconf_client_notify_add (client, 
+                                 "/desktop/gnome/background/color1",
+                                 nautilus_desktop_color1_callback,
+                                 icon_container, 
+                                 NULL, NULL);
+    
+
+
+	if (GTK_WIDGET_REALIZED (icon_container)) {
+		desktop_background_realized (icon_container, GINT_TO_POINTER (FALSE));
+	} else {
+		g_signal_connect (icon_container, "realize", G_CALLBACK (desktop_background_realized), GINT_TO_POINTER (TRUE));
+	}
+
+        // FIXME: What does this do?
+	nautilus_file_background_receive_root_window_changes (background); 
 }
Index: libnautilus-private/nautilus-directory-background.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-background.h,v
retrieving revision 1.9
diff -c -u -r1.9 nautilus-directory-background.h
--- libnautilus-private/nautilus-directory-background.h	2001/09/15 19:17:45	1.9
+++ libnautilus-private/nautilus-directory-background.h	2002/01/23 12:04:24
@@ -33,6 +33,8 @@
                                                            NautilusFile      *file);
 void nautilus_connect_desktop_background_to_file_metadata (NautilusIconContainer *icon_container,
                                                            NautilusFile		 *file);
+void nautilus_desktop_set_background (NautilusIconContainer *icon_container,
+                                      NautilusFile *file);
 void nautilus_connect_background_to_file_metadata_by_uri  (GtkWidget         *widget,
                                                            const char        *uri);
 gboolean nautilus_file_background_is_set		  (EelBackground *background);
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.236
diff -c -u -r1.236 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	2002/01/17 21:24:12	1.236
+++ src/file-manager/fm-icon-view.c	2002/01/23 12:04:25
@@ -929,6 +929,7 @@
 
 	icon_view = FM_ICON_VIEW (view);
 	file = fm_directory_view_get_directory_as_file (view);
+	g_message("Loading view for file '%s'...\n", nautilus_file_get_display_name(file));
 	icon_container = GTK_WIDGET (get_icon_container (icon_view));
 
 	icon_view->details->loading = TRUE;
@@ -940,8 +941,11 @@
 	 * of hardcoding desktop knowledge in here.
 	 */
 	if (FM_IS_DESKTOP_ICON_VIEW (view)) {
-		nautilus_connect_desktop_background_to_file_metadata (NAUTILUS_ICON_CONTAINER (icon_container), file);
+		//nautilus_connect_desktop_background_to_file_metadata (NAUTILUS_ICON_CONTAINER (icon_container), file);
+		g_message("Setting background for IS_DESKTOP_ICON_VIEW\n");
+		nautilus_desktop_set_background(NAUTILUS_ICON_CONTAINER (icon_container), file);
 	} else {
+		g_message("Setting background for icon view\n");
 		nautilus_connect_background_to_file_metadata (icon_container, file);
 	}
 	


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