Re: [Nautilus-list] Integration of gmc and nautilus desktop directories.



Patch, Take 2.

> Nautilus coding style requires braces for even one-line if statements.

Fixed all of these

> Nautilus coding style requires a space between the ")" and the "{".

And all of these.

> There's a coding mistake here. You meant to call nautilus_file_is_local on
> file. I think nautilus_file_is_local is probably not right anyway.

You are right.  Fixed.

> It's a coding mistake to assume that nautilus_file_is_local is only true for
> "real" files in the local file system. "is_local" can be returned true from
> any gnome-vfs module, and can be used to indicate other more-subtle forms of
> "being local". Instead, the correct check is to do
> gnome_vfs_get_local_path_from_uri, and reject files where the result is
> NULL.

I am just trying to speed up the path by avoiding doing expensive
operations.  It does not really matter correctness wise, as the only
case where these things will happen is the ~/.gnome-desktop directory,
and I am not expecting people to have thousands of files there.

> Nautilus coding style requires all declarations at the top of the function.

Fixed all of these as well.  I am not sure this is a great policy, it
seems like it might lead to bugs.

> Nautilus comment style matches GTK, so there should not be a first line with
> a "/*" by itself..

Fixed all of these as well.

> This should use DESKTOP_DIRECTORY_NAME. Perhaps it could also be changed so
> that it doesn't get fooled by files whose name are prefixed with
> ".gnome-desktop", but maybe that's not a real issue?

Did not fix this, as it is a private define in
nautilus-file-utilities.c

I can move it to a header if you think thats ok

> As discussed above, nautilus_file_is_local is probably the wrong check here.
> Instead, a check for NULL in the result of gnome_vfs_get_local_path_from_uri
> is probably the better choice.

It is not that important, it is a test used to not impact performance
on the most common case.  Ie, it will turn out always ok and not use
any expensive operations in its process.

> Nautilus coding style requires braces for even one-line if statements and
> "path != NULL" rather than "path".

Fixed all of these as well.

> > +        if (res == 0 && caption)
> 
> I'm surprised this compiles without warnings, because res is uninitialized
> if path is NULL. You need to set res to 0 in the path == NULL case.

Good catch.  Fixed.

> This function worries me. What will prevent people from naming their files
> with the letters "url" at the start, and putting them onto the desktop? Is
> there a reason this is OK?

Not really, but I can not think of other ways of testing this
(actually, for correctness, the gmc-url handler should not depend on
the contents of the file for fetching the URL, the data was always
stored on the metadata.db).  

> Please remove this empty unused function.

Done.

> Not sure what to do about the changes to the druid. At the very least, the
> patch should either remove everything cleanly, or use an ifdef on some
> symbol. The current patch has both a change or two and #if 0 blocks.

Used `ifdef TRANSITIONAL_NAUTILUS'

> This should be removed from the patch!

Done.

> Nautilus coding style says use int, not gint, but these should be guint
> anyway!

Good catch.  Changed to guint.

> Nautilus coding style prohibits initializing local variables in the
> declaration.

Done.

> Nautilus coding style says that defined constants go at the top of the file.

Done.

> Also, the nautilus_file_is_local check isn't needed and should be removed.
> gnome_vfs_get_local_path_from_uri will return NULL and everything will be
> all right for the non-local case.

It is just a quick way of separating the good from the bad.  A more
accurate test follows for false positives.  It wont hurt, it is just
faster. 

Miguel.

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.4180.2.48.2.1
diff -u -r1.4180.2.48.2.1 ChangeLog
--- ChangeLog	2001/04/06 20:07:34	1.4180.2.48.2.1
+++ ChangeLog	2001/04/12 19:45:45
@@ -1,3 +1,56 @@
+2001-04-11  Miguel de Icaza  <miguel ximian com>
+
+	* src/file-manager/fm-icon-view.c
+	(get_stored_icon_position_callback): Try to load position
+	information from GNOME metadata as well.
+	(icon_position_changed_callback): Store metadata changes to the
+	desktop as well.
+
+	* src/nautilus-first-time-druid.c
+	(nautilus_first_time_druid_show): Disable GMC transition page, as
+	we now share the desktop directory and the data files.
+	(druid_finished): Remove desktop link to Eazel services.
+
+	* libnautilus-extensions/nautilus-file.c
+	(nautilus_file_can_rename): Do not allow to rename x-gnome-apps. 
+	(nautilus_file_get_name): Return the translated name of a desktop
+	file instead of the file name.  
+	Handle URL files in .gnome-desktop directories. 
+	(is_special_desktop_gmc_file): New function: Returns true if a
+	file should be hidden from the desktop-directory display (for
+	sharing the directory with gmc).
+	(filter_hidden_and_backup_partition_callback): If we are scanning
+	the desktop directory, hide gmc metadata files or legacy files.
+
+	* libnautilus-extensions/nautilus-directory-async.c
+	(activation_uri_gmc_link_read_callback): Handle GMC link files
+	correctly (skip the prefix "URL: ")
+
+	* libnautilus-extensions/nautilus-icon-factory.c
+	(nautilus_icon_factory_get_icon_for_file): Load icons from the
+	gnome-metadata for files on the ~/.gnome-desktop directory.
+	(nautilus_icon_factory_get_icon_for_file): Load icons for GNOME
+	.desktop files.
+
+2001-04-10  Miguel de Icaza  <miguel ximian com>
+
+	* libnautilus-extensions/nautilus-file-utilities.c
+	(DESKTOP_DIRECTORY_NAME): Make it .gnome-desktop.
+	(nautilus_get_desktop_directory): Modified to make the nautilus
+	home directory be the normal one.
+
+2001-04-09  Miguel de Icaza  <miguel ximian com>
+
+	* src/file-manager/fm-desktop-icon-view.c: Eliminated all over the
+	place the loading of the desktop_directory directory from the
+	nautilus api call, and instead just load this value once.
+
+2001-04-11  Miguel de Icaza  <miguel ximian com>
+
+	* libnautilus-extensions/nautilus-directory-async.c
+	(activation_uri_gmc_link_read_callback): Handle correctly gmc URL
+	links. 
+
 2001-04-06  Robin * Slomkowski  <rslomkow eazel com>
 
 	* components/music/Makefile.am: added non-x86 files to EXTRA_DISTS
Index: libnautilus-extensions/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-directory-async.c,v
retrieving revision 1.145
diff -u -r1.145 nautilus-directory-async.c
--- libnautilus-extensions/nautilus-directory-async.c	2001/03/02 18:18:13	1.145
+++ libnautilus-extensions/nautilus-directory-async.c	2001/04/12 19:45:48
@@ -3159,7 +3159,7 @@
 	}
 
 	g_free (file_contents);
-	activation_uri_read_done (directory, uri);
+	activation_uri_read_done (directory, uri ? uri + 5 : NULL);
 	g_free (uri);
 }
 
Index: libnautilus-extensions/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-file-utilities.c,v
retrieving revision 1.90.2.1
diff -u -r1.90.2.1 nautilus-file-utilities.c
--- libnautilus-extensions/nautilus-file-utilities.c	2001/03/10 02:24:15	1.90.2.1
+++ libnautilus-extensions/nautilus-file-utilities.c	2001/04/12 19:45:49
@@ -50,7 +50,7 @@
 #define NAUTILUS_USER_DIRECTORY_NAME ".nautilus"
 #define DEFAULT_NAUTILUS_DIRECTORY_MODE (0755)
 
-#define DESKTOP_DIRECTORY_NAME "desktop"
+#define DESKTOP_DIRECTORY_NAME ".gnome-desktop"
 #define DEFAULT_DESKTOP_DIRECTORY_MODE (0755)
 
 #define NAUTILUS_USER_MAIN_DIRECTORY_NAME "Nautilus"
@@ -930,7 +930,7 @@
 	char *desktop_directory, *user_directory;
 
 	user_directory = nautilus_get_user_directory ();
-	desktop_directory = nautilus_make_path (user_directory, DESKTOP_DIRECTORY_NAME);
+	desktop_directory = nautilus_make_path (g_get_home_dir (), DESKTOP_DIRECTORY_NAME);
 	g_free (user_directory);
 
 	if (!g_file_exists (desktop_directory)) {
Index: libnautilus-extensions/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-file.c,v
retrieving revision 1.229
diff -u -r1.229 nautilus-file.c
--- libnautilus-extensions/nautilus-file.c	2001/03/03 01:46:59	1.229
+++ libnautilus-extensions/nautilus-file.c	2001/04/12 19:45:51
@@ -40,6 +40,7 @@
 #include "nautilus-trash-directory.h"
 #include "nautilus-trash-file.h"
 #include "nautilus-vfs-file.h"
+#include "nautilus-metadata.h"
 #include <ctype.h>
 #include <gnome-xml/parser.h>
 #include <grp.h>
@@ -48,6 +49,7 @@
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-mime-info.h>
 #include <libgnome/gnome-mime.h>
+#include <libgnome/gnome-dentry.h>
 #include <libgnomevfs/gnome-vfs-file-info.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
 #include <libgnomevfs/gnome-vfs-mime-info.h>
@@ -75,6 +77,7 @@
 
 
 typedef struct {
+
 	NautilusFile *file;
 	GnomeVFSAsyncHandle *handle;
 	NautilusFileOperationCallback callback;
@@ -732,6 +735,10 @@
 		return FALSE;
 	}
 
+	if (nautilus_file_is_mime_type (file, "application/x-gnome-app-info")) {
+		return FALSE;
+	}
+	
 	can_rename = TRUE;
 	uri = nautilus_file_get_uri (file);
 	path = gnome_vfs_get_local_path_from_uri (uri);
@@ -936,11 +943,30 @@
 	Operation *op;
 	GnomeVFSFileInfo *partial_file_info;
 	GnomeVFSURI *vfs_uri;
+	char *uri, *path;
 
 	g_return_if_fail (NAUTILUS_IS_FILE (file));
 	g_return_if_fail (new_name != NULL);
 	g_return_if_fail (callback != NULL);
 
+	if (nautilus_file_is_local (file) && nautilus_file_is_gmc_url (file)) {
+		uri = nautilus_file_get_uri (file);
+		path = gnome_vfs_get_local_path_from_uri (uri);
+
+		if (path) {
+			gnome_metadata_set (path, "icon-caption", strlen (new_name)+1, new_name);
+		}
+
+		g_free (path);
+		g_free (uri);
+
+		(*callback) (file, GNOME_VFS_OK, callback_data);
+			
+		nautilus_file_changed (file);
+		
+		return;
+	}
+	
 	 /* Make return an error for incoming names containing path separators. */
 	 if (strstr (new_name, "/") != NULL) {
 		(* callback) (file, GNOME_VFS_ERROR_NOT_PERMITTED, callback_data);
@@ -1848,6 +1874,70 @@
 } NautilusFileFilterOptions;
 
 static gboolean
+is_special_desktop_gmc_file (NautilusFile *file)
+{
+	static char *home_dir;
+	static int home_dir_len;
+	char buffer [1024];
+	char *uri, *path;
+	int s;
+
+	if (!nautilus_file_is_local (file))
+		return FALSE;
+	
+	if (strcmp (file->details->relative_uri, "Trash.gmc") == 0)
+		return TRUE;
+
+	if (nautilus_file_is_symbolic_link (file)) {
+		/* You would think that
+		 * nautilus_file_get_symbolic_link_target_path would
+		 * be useful here, but you would be wrong.  The
+		 * information kept around by NautilusFile is not
+		 * available right now, and I I have no clue how to
+		 * fix this.  On top of that, inode/device are not
+		 * stored, so it is not possible to see if a link is a
+		 * symlink to the home directory.  sigh.
+		 */
+		uri = nautilus_file_get_uri (file);
+		path = gnome_vfs_get_local_path_from_uri (uri);
+		s = readlink (path, buffer, sizeof (buffer)-1);
+		g_free (path);
+		g_free (uri);
+
+		if (s == -1) {
+			return FALSE;
+		}
+
+		buffer [s] = 0;
+		
+		if (!home_dir) {
+			home_dir = g_strdup (g_get_home_dir ());
+			home_dir_len = strlen (home_dir);
+			
+			if (home_dir && home_dir [home_dir_len-1] == '/') {
+				home_dir [home_dir_len-1] = 0;
+				home_dir_len--;
+			}
+			
+		}
+		if (home_dir) {
+			if (strncmp (home_dir, buffer, home_dir_len) == 0)
+				return TRUE;
+		}
+	}
+	return FALSE;
+}
+
+gboolean
+nautilus_file_is_in_desktop (NautilusFile *file)
+{
+	/* This handles visiting other people's desktops, but it can arguably
+	 * be said that this might break and that we should lookup the passwd table.
+	 */
+	return strstr (file->details->directory->details->uri, "/.gnome-desktop") != NULL;
+}
+
+static gboolean
 filter_hidden_and_backup_partition_callback (gpointer data,
 					     gpointer callback_data)
 {
@@ -1857,6 +1947,10 @@
 	file = NAUTILUS_FILE (data);
 	options = (NautilusFileFilterOptions) callback_data;
 
+	if (nautilus_file_is_in_desktop (file) && is_special_desktop_gmc_file (file)) {
+			return FALSE;
+	}
+	
 	return nautilus_file_should_show (file, 
 					  options & SHOW_HIDDEN,
 					  options & SHOW_BACKUP);
@@ -1947,10 +2041,30 @@
 			    const char *default_metadata,
 			    const char *metadata)
 {
+	char *icon_path;
+	char *local_path;
+	char *local_uri;
+	
 	g_return_if_fail (NAUTILUS_IS_FILE (file));
 	g_return_if_fail (key != NULL);
 	g_return_if_fail (key[0] != '\0');
 
+	if (strcmp (key, NAUTILUS_METADATA_KEY_CUSTOM_ICON) == 0) {
+		if (nautilus_file_is_in_desktop (file) &&
+		    nautilus_file_is_local (file)) {
+
+			local_uri = nautilus_file_get_uri (file);
+			local_path = gnome_vfs_get_local_path_from_uri (local_uri);
+			icon_path = gnome_vfs_get_local_path_from_uri (metadata);
+
+			gnome_metadata_set (local_path, "icon-filename", strlen (icon_path)+1, icon_path);
+
+			g_free (icon_path);
+			g_free (local_path);
+			g_free (local_uri);
+		}
+	}
+	
 	nautilus_directory_set_file_metadata
 		(file->details->directory,
 		 get_metadata_name (file),
@@ -2062,11 +2176,55 @@
 nautilus_file_get_name (NautilusFile *file)
 {
 	char *name;
+	GnomeDesktopEntry *entry;
+	char *path, *uri;
+	char *caption;
+	int size, res;
 	
 	if (file == NULL) {
 		return NULL;
 	}
 	g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+
+	if (nautilus_file_is_mime_type (file, "application/x-gnome-app-info")) {
+		uri = nautilus_file_get_uri (file);
+		path = gnome_vfs_get_local_path_from_uri (uri);
+
+		if (path) {
+			entry = gnome_desktop_entry_load (path);
+			if (entry != NULL) {
+				name = g_strdup (entry->name);
+				gnome_desktop_entry_free (entry);
+			}
+		}
+		
+		g_free (path);
+		g_free (uri);
+
+		return name;
+	}
+
+	/* Desktop directories contain special "URL" files, handle those by using
+	 * the gnome metadata caption
+	 */
+	if (nautilus_file_is_gmc_url (file)) {
+
+		uri = nautilus_file_get_uri (file);
+		path = gnome_vfs_get_local_path_from_uri (uri);
+
+		if (path) {
+			res = gnome_metadata_get (path, "icon-caption", &size, &caption);
+		} else {
+			res = -1;
+		}
+		
+		g_free (path);
+		g_free (uri);
+
+		if (res == 0 && caption != NULL)
+			return caption;
+	}
+
 	name = gnome_vfs_unescape_string (file->details->relative_uri, "/");
 	if (name != NULL) {
 		return name;
@@ -4070,6 +4228,25 @@
 nautilus_file_is_nautilus_link (NautilusFile *file)
 {
 	return nautilus_file_is_mime_type (file, "application/x-nautilus-link");
+}
+
+/**
+ * nautilus_file_is_gmc_url
+ * 
+ * Check if this file is a gmc url
+ * @file: NautilusFile representing the file in question.
+ * 
+ * Returns: True if the file is a gmc url
+ * 
+ **/
+gboolean
+nautilus_file_is_gmc_url (NautilusFile *file)
+{
+	if ((strncmp (file->details->relative_uri, "url", 3) == 0) &&
+	    nautilus_file_is_in_desktop (file)) {
+		return TRUE;
+	}
+	return FALSE;
 }
 
 /**
Index: libnautilus-extensions/nautilus-file.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-file.h,v
retrieving revision 1.75
diff -u -r1.75 nautilus-file.h
--- libnautilus-extensions/nautilus-file.h	2001/02/24 01:45:10	1.75
+++ libnautilus-extensions/nautilus-file.h	2001/04/12 19:45:51
@@ -131,6 +131,7 @@
 char *                  nautilus_file_get_symbolic_link_target_path     (NautilusFile                   *file);
 gboolean                nautilus_file_is_broken_symbolic_link           (NautilusFile                   *file);
 gboolean                nautilus_file_is_nautilus_link                  (NautilusFile                   *file);
+gboolean                nautilus_file_is_gmc_url                        (NautilusFile                   *file);
 gboolean                nautilus_file_is_executable                     (NautilusFile                   *file);
 gboolean                nautilus_file_is_directory                      (NautilusFile                   *file);
 gboolean                nautilus_file_is_in_trash                       (NautilusFile                   *file);
Index: libnautilus-extensions/nautilus-icon-factory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-icon-factory.c,v
retrieving revision 1.199.2.1
diff -u -r1.199.2.1 nautilus-icon-factory.c
--- libnautilus-extensions/nautilus-icon-factory.c	2001/03/08 20:29:44	1.199.2.1
+++ libnautilus-extensions/nautilus-icon-factory.c	2001/04/12 19:45:52
@@ -52,6 +52,7 @@
 #include <gtk/gtksignal.h>
 #include <libgnome/gnome-i18n.h>
 #include <libgnome/gnome-util.h>
+#include <libgnome/gnome-dentry.h>
 #include <libgnomevfs/gnome-vfs-file-info.h>
 #include <libgnomevfs/gnome-vfs-mime-info.h>
 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
@@ -1371,11 +1372,22 @@
  	gboolean is_local;
  	int file_size;
  	NautilusScalableIcon *scalable_icon;
-	
+	gboolean try_gnome_metadata = FALSE;
+	static char *desktop_directory;
+	char *directory, *directory_uri;
+	GnomeDesktopEntry *entry;
+	char *buf;
+	int size, res;
+			
+
 	if (file == NULL) {
 		return NULL;
 	}
 
+	if (!desktop_directory)
+		desktop_directory = nautilus_get_desktop_directory ();
+	
+
 	/* if there is a custom image in the metadata, use that. */
 	uri = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
 	file_uri = nautilus_file_get_uri (file);
@@ -1386,6 +1398,36 @@
 	   If a thumbnail is required, but does not yet exist,  put an entry on the thumbnail queue so we
 	   eventually make one */
 
+	if (uri == NULL) {
+		/* Do we have to check the gnome metadata?
+		 *
+		 * Do this only for the ~/.gnome-desktop directory, as it was
+		 * the only place where GMC used it (since everywhere else we could
+		 * not do it because of the imlib leaks).
+		 */
+		directory_uri = nautilus_file_get_parent_uri (file);
+		directory = gnome_vfs_get_local_path_from_uri (directory_uri);
+		if (directory && strcmp (directory, desktop_directory) == 0) {
+			file_path = gnome_vfs_get_local_path_from_uri (file_uri);
+
+			if (file_path) {
+				res = gnome_metadata_get (file_path, "icon-filename", &size, &buf);
+			} else {
+				res = -1;
+			}
+
+			if (res == 0 && buf != NULL) {
+				uri = gnome_vfs_get_uri_from_local_path (buf);
+				g_free (buf);
+			}
+			
+			g_free (file_path);
+			file_path = NULL;
+		}
+		g_free (directory);
+		
+	}
+	
 	/* also, dont make thumbnails for images in the thumbnails directory */  
 	if (uri == NULL) {		
 		mime_type = nautilus_file_get_mime_type (file);
@@ -1429,7 +1471,20 @@
 				}
 			}
 			g_free (file_path);
+			file_path = NULL;
+		}
+	}
+
+	if (uri == NULL && nautilus_file_is_mime_type (file, "application/x-gnome-app-info")) {
+		entry = gnome_desktop_entry_load (file_path);
+		if (entry != NULL) {
+			if (entry->icon != NULL) {
+				uri = gnome_vfs_get_uri_from_local_path (entry->icon);
+			}
+			gnome_desktop_entry_free (entry);
 		}
+		g_free (file_path);
+		file_path = NULL;
 	}
 	
 	/* handle SVG files */
Index: src/nautilus-application.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.c,v
retrieving revision 1.134
diff -u -r1.134 nautilus-application.c
--- src/nautilus-application.c	2001/03/01 21:01:02	1.134
+++ src/nautilus-application.c	2001/04/12 19:45:52
@@ -333,6 +333,29 @@
 	return uri_list;
 }
 
+/* Find ~/.gnome-desktop/Trash and rename it to ~/.gnome-desktop/Trash-gmc
+ * Only if it is a directory
+ */
+static void
+migrate_trashcan (void)
+{
+	char *dp, *trash_dir, *dest;
+	struct stat buf;
+
+	dp = nautilus_get_desktop_directory ();
+	trash_dir = g_strconcat (dp, "/", "Trash", NULL);
+	dest = g_strconcat (dp, "/", "Trash.gmc", NULL);
+	
+	if (stat (trash_dir, &buf) == 0 && S_ISDIR (buf.st_mode)) {
+		rename (trash_dir, dest);
+		gnome_metadata_rename (trash_dir, dest);
+	}
+	
+	g_free (dp);
+	g_free (trash_dir);
+	g_free (dest);
+}
+
 void
 nautilus_application_startup (NautilusApplication *application,
 			      gboolean kill_shell,
@@ -373,6 +396,7 @@
 		nautilus_first_time_druid_show (application, start_desktop, urls);
 		return;
 	}
+	migrate_trashcan ();
 	
 	/* initialize the sound machinery */
 	nautilus_sound_initialize ();
Index: src/nautilus-first-time-druid.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-first-time-druid.c,v
retrieving revision 1.87.2.5.2.1
diff -u -r1.87.2.5.2.1 nautilus-first-time-druid.c
--- src/nautilus-first-time-druid.c	2001/04/06 20:07:43	1.87.2.5.2.1
+++ src/nautilus-first-time-druid.c	2001/04/12 19:45:53
@@ -66,7 +66,9 @@
 /* Druid page number enumeration */
 enum {
 	USER_LEVEL_PAGE = 0,
+#ifdef TRANSITIONAL_NAUTILUS
 	GMC_TRANSITION_PAGE,
+#endif
 	LAUNCH_MEDUSA_PAGE,
 	START_CRON_INFORMATION_PAGE,
 	OFFER_UPDATE_PAGE,
@@ -139,10 +141,11 @@
 
 /* GMC transition tool globals */
 static gboolean draw_desktop = TRUE;
+#if TRANSITIONAL_NAUTILUS
 static gboolean add_to_session = TRUE;
 static gboolean transfer_gmc_icons = TRUE;
 static GtkWidget *draw_desktop_checkbox_widget;
-
+#endif
 /* `Launch Medusa' globals */
 static gboolean medusa_is_blocked;
 static NautilusCronStatus cron_status;
@@ -241,24 +244,28 @@
 		signup_uris[1] = NULL;
 	}
 
-
+#ifdef TRANSITIONAL_NAUTILUS
 	/* Do the GMC to Nautilus Transition */
 	nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP, draw_desktop);	
 	nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_ADD_TO_SESSION, add_to_session);	
 	if (transfer_gmc_icons) {
 		convert_gmc_desktop_icons ();
 	}
+#endif
 
 	/* Do the Medusa config */
 	nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_USE_FAST_SEARCH, launch_medusa);
 	nautilus_medusa_enable_services (launch_medusa);
 	
 	/* Create default services icon on the desktop */
 	desktop_path = nautilus_get_desktop_directory ();
 	nautilus_link_local_create (desktop_path, _("Eazel Services"), "hand.png", 
 				    "eazel:", NULL, NAUTILUS_LINK_GENERIC);
 	g_free (desktop_path);
	
 	/* Time to start. Hooray! */
 	nautilus_application_startup (save_application, FALSE, FALSE, draw_desktop, 
 				      FALSE, FALSE, NULL, (signup_uris[0] != NULL) ? signup_uris : NULL);
@@ -267,6 +274,7 @@
 	gtk_widget_destroy (gtk_widget_get_toplevel (druid_page));
 }
 
+
 /* set up an event box to serve as the background */
 
 static GtkWidget *
@@ -290,11 +298,13 @@
 static void
 update_draw_desktop_checkbox_state ()
 {
+#ifdef TRANSITIONAL_NAUTILUS
 	if (current_user_level == NAUTILUS_USER_LEVEL_NOVICE) {
 		gtk_widget_hide (draw_desktop_checkbox_widget);
 	} else {
 		gtk_widget_show (draw_desktop_checkbox_widget);
 	}
+#endif
 }
 
 /* handler for user level buttons changing */
@@ -773,7 +783,7 @@
 		gnome_druid_set_page (druid, GNOME_DRUID_PAGE (pages[START_CRON_INFORMATION_PAGE]));
 	}
 #else
-	gnome_druid_set_page (druid, GNOME_DRUID_PAGE (pages[GMC_TRANSITION_PAGE]));
+	gnome_druid_set_page (druid, GNOME_DRUID_PAGE (pages[USER_LEVEL_PAGE]));
 #endif
 
 	return TRUE;
@@ -885,6 +895,7 @@
 	return TRUE;
 }
 
+#ifdef TRANSITIONAL_NAUTILUS
 /* set up the "GMC to Nautilus Transition" page */
 static void
 set_up_gmc_transition_page (NautilusDruidPageEazel *page)
@@ -925,7 +936,7 @@
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), transfer_gmc_icons);	
 	gtk_signal_connect (GTK_OBJECT (checkbox), "toggled", GTK_SIGNAL_FUNC (transition_value_changed), &transfer_gmc_icons);
 
-#if 0
+#ifdef TRANSITIONAL_NAUTILUS
 	/* This option is currently disabled, per bugzilla.eazel.com 7557 */
 
 	checkbox = gtk_check_button_new_with_label (_("Launch Nautilus when GNOME starts up."));
@@ -936,7 +947,7 @@
 	
 	gtk_widget_show_all (main_box);
 }
-
+#endif
 
 static gboolean
 medusa_value_changed (GtkWidget *checkbox, gboolean *value)
@@ -1226,14 +1237,15 @@
 	/* set up the user level page */
 	set_page_title (NAUTILUS_DRUID_PAGE_EAZEL (pages[USER_LEVEL_PAGE]), _("Choose Your User Level"));
 	set_up_user_level_page (NAUTILUS_DRUID_PAGE_EAZEL (pages[USER_LEVEL_PAGE]));
-				
+
+#ifdef TRANSITIONAL_NAUTILUS
 	/* set up the GMC transition page */
 	set_page_title (NAUTILUS_DRUID_PAGE_EAZEL (pages[GMC_TRANSITION_PAGE]), _("GMC to Nautilus Transition"));
 	set_up_gmc_transition_page (NAUTILUS_DRUID_PAGE_EAZEL (pages[GMC_TRANSITION_PAGE]));
 	gtk_signal_connect (GTK_OBJECT (pages[GMC_TRANSITION_PAGE]), "next",
 			    GTK_SIGNAL_FUNC (next_gmc_transition_page_callback),
 			    druid);
-
+#endif
 	/* set up the `Launch Medusa' page */
 	set_page_title (NAUTILUS_DRUID_PAGE_EAZEL (pages[LAUNCH_MEDUSA_PAGE]), _("Fast Searches"));
 	set_up_medusa_page (NAUTILUS_DRUID_PAGE_EAZEL (pages[LAUNCH_MEDUSA_PAGE]));
Index: src/file-manager/fm-desktop-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-desktop-icon-view.c,v
retrieving revision 1.122
diff -u -r1.122 fm-desktop-icon-view.c
--- src/file-manager/fm-desktop-icon-view.c	2001/02/23 23:54:35	1.122
+++ src/file-manager/fm-desktop-icon-view.c	2001/04/12 19:45:53
@@ -21,6 +21,7 @@
 
    Authors: Mike Engber <engber eazel com>
    	    Gene Z. Ragan <gzr eazel com>
+	    Miguel de Icaza <miguel ximian com>
 */
 
 #include <config.h>
@@ -30,6 +31,7 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <bonobo/bonobo-ui-util.h>
+#include <gtk/gtkmain.h>
 #include <gdk/gdkx.h>
 #include <gtk/gtkcheckmenuitem.h>
 #include <libgnome/gnome-dentry.h>
@@ -70,10 +72,22 @@
 
 #define DESKTOP_BACKGROUND_POPUP_PATH_DISKS	"/popups/background/Before Zoom Items/Volume Items/Disks"
 
+/* Timeout to check the desktop directory for updates */
+#define RESCAN_TIMEOUT 4000
+
+static char *desktop_directory;
+static time_t desktop_dir_modify_time;
+
 struct FMDesktopIconViewDetails
 {
 	BonoboUIComponent *ui;
 	GList *mount_black_list;
+
+	/* For the desktop rescanning
+	 */
+	guint reload_desktop_timeout;
+	guint delayed_init_signal;
+	gboolean pending_rescan;
 };
 
 typedef struct {
@@ -134,6 +148,10 @@
 
 	icon_view = FM_DESKTOP_ICON_VIEW (object);
 
+	/* Remove desktop rescan timeout 
+	 */
+	gtk_timeout_remove (icon_view->details->reload_desktop_timeout);
+	
 	/* Delete all of the link files. */
 	delete_all_mount_links ();
 	
@@ -294,7 +312,7 @@
 create_mount_link (FMDesktopIconView *icon_view,
 		   const NautilusVolume *volume)
 {
-	char *desktop_path, *target_uri, *volume_name;
+	char *target_uri, *volume_name;
 	const char *icon_name;
 
 	if (volume_in_black_list (icon_view, volume)) {
@@ -322,15 +340,13 @@
 		break;	
 	}
 
-	desktop_path = nautilus_get_desktop_directory ();
 	target_uri =  nautilus_volume_monitor_get_target_uri (volume);
 	
-	volume_name = create_unique_volume_name (desktop_path, volume);
+	volume_name = create_unique_volume_name (desktop_directory, volume);
 	
 	/* Create link */
-	nautilus_link_local_create (desktop_path, volume_name, icon_name, target_uri, NULL, NAUTILUS_LINK_MOUNT);
+	nautilus_link_local_create (desktop_directory, volume_name, icon_name, target_uri, NULL, NAUTILUS_LINK_MOUNT);
 				    
-	g_free (desktop_path);
 	g_free (target_uri);
 	g_free (volume_name);
 }
@@ -354,7 +370,71 @@
 	update_home_link_and_delete_copies ();
 }
 
+static gint
+do_desktop_rescan (gpointer data)
+{
+	FMDesktopIconView *desktop_icon_view;
+	struct stat buf;
+
+	desktop_icon_view = FM_DESKTOP_ICON_VIEW (data);
+	if (desktop_icon_view->details->pending_rescan) {
+		return TRUE;
+	}
+	
+	if (stat (desktop_directory, &buf) == -1) {
+		return TRUE;
+	}
+
+	if (buf.st_ctime == desktop_dir_modify_time) {
+		return TRUE;
+	}
+
+	desktop_icon_view->details->pending_rescan = TRUE;
+
+	nautilus_directory_force_reload (
+		fm_directory_view_get_model (
+			FM_DIRECTORY_VIEW (desktop_icon_view)));
+	return TRUE;
+}
+
 static void
+done_loading (GtkObject *DirectoryView, FMDesktopIconView *desktop_icon_view)
+{
+	struct stat buf;
+
+	desktop_icon_view->details->pending_rescan = FALSE;
+	if (stat (desktop_directory, &buf) == -1)
+		return;
+
+	desktop_dir_modify_time = buf.st_ctime;
+}
+
+/* This function is used because the NautilusDirectory
+ * model does not exist always in the desktop_icon_view,
+ * so we want until it has been instantiated
+ */
+static void
+delayed_init (FMDesktopIconView *desktop_icon_view)
+{
+	/* Keep track of the load time
+	 */
+	gtk_signal_connect (
+		GTK_OBJECT (fm_directory_view_get_model (
+			FM_DIRECTORY_VIEW (desktop_icon_view))),
+		"done_loading",
+		GTK_SIGNAL_FUNC (done_loading), desktop_icon_view);
+
+	/* Monitor desktop directory */
+	desktop_icon_view->details->reload_desktop_timeout =
+		gtk_timeout_add (RESCAN_TIMEOUT, do_desktop_rescan, desktop_icon_view);
+
+	gtk_signal_disconnect (
+		GTK_OBJECT (desktop_icon_view),
+		desktop_icon_view->details->delayed_init_signal);
+	desktop_icon_view->details->delayed_init_signal = -1;
+}
+
+static void
 fm_desktop_icon_view_initialize (FMDesktopIconView *desktop_icon_view)
 {
 	GList *list;
@@ -362,11 +442,20 @@
 	GtkAllocation *allocation;
 	GtkAdjustment *hadj, *vadj;
 
+	if (!desktop_directory) {
+		desktop_directory = nautilus_get_desktop_directory ();
+	}
+
 	icon_container = get_icon_container (desktop_icon_view);
 
 	/* Set up details */
 	desktop_icon_view->details = g_new0 (FMDesktopIconViewDetails, 1);	
 
+	desktop_icon_view->details->delayed_init_signal = gtk_signal_connect (
+		GTK_OBJECT (desktop_icon_view),
+		"begin_loading",
+		GTK_SIGNAL_FUNC (delayed_init), desktop_icon_view);
+	
 	nautilus_icon_container_set_is_fixed_size (icon_container, TRUE);
 	
 	/* Set up default mount black list */
@@ -581,16 +670,14 @@
 						   gboolean state,
 						   gpointer callback_data)
 {
-	char *desktop_path, *path;
+	char *path;
 
-	desktop_path = nautilus_get_desktop_directory ();
-	path = nautilus_make_path (desktop_path, TRASH_LINK_NAME);
+	path = nautilus_make_path (desktop_directory, TRASH_LINK_NAME);
 
 	/* Change the XML file to have a new icon. */
 	nautilus_link_local_set_icon (path, state ? "trash-empty.png" : "trash-full.png");
 
 	g_free (path);
-	g_free (desktop_path);
 }
 
 static void
@@ -625,7 +712,7 @@
 			   NautilusVolume *volume, 
 			   FMDesktopIconView *icon_view)
 {
-	char *link_path, *desktop_path, *volume_name;
+	char *link_path, *volume_name;
 
 	g_assert (volume != NULL);
 	
@@ -634,12 +721,10 @@
 		return;
 	}
 	
-	desktop_path = nautilus_get_desktop_directory ();
-	link_path = nautilus_make_path (desktop_path, volume_name);
+	link_path = nautilus_make_path (desktop_directory, volume_name);
 	unlink_and_notify (link_path);
 
 	g_free (volume_name);
-	g_free (desktop_path);
 	g_free (link_path);
 }
 
@@ -648,7 +733,6 @@
 			   	 int x, int y, FMDirectoryView *view)
 {
 	const GList *element;
-	char *desktop_path;	
 	GnomeDesktopEntry *entry;
 	int index;
 	GdkPoint point;
@@ -657,18 +741,15 @@
 		return;
 	}
 	
-	desktop_path = nautilus_get_desktop_directory ();
 	point.x = x;
 	point.y = y;
 	
 	/* Iterate through all of the URIs in the list */
 	for (element = item_uris, index = 0; element != NULL; element = element->next, index++) {
 		entry = gnome_desktop_entry_load ((char *)element->data);
-		nautilus_link_local_create_from_gnome_entry (entry, desktop_path, &point);
+		nautilus_link_local_create_from_gnome_entry (entry, desktop_directory, &point);
 		gnome_desktop_entry_free (entry);
 	}
-	
-	g_free (desktop_path);
 }
 
 static gboolean
@@ -678,22 +759,19 @@
 {
 	DIR *dir;
 	gboolean found_link;
-	char *desktop_path;
 	struct dirent *dir_entry;
 	char *link_path;
 
-	desktop_path = nautilus_get_desktop_directory ();
-
-	dir = opendir (desktop_path);
+	dir = opendir (desktop_directory);
 	if (dir == NULL) {
-		g_free (desktop_path);
+		g_free (desktop_directory);
 		return FALSE;
 	}
 
 	found_link = FALSE;
 
 	while ((dir_entry = readdir (dir)) != NULL) {
-		link_path = nautilus_make_path (desktop_path, dir_entry->d_name);
+		link_path = nautilus_make_path (desktop_directory, dir_entry->d_name);
 		if ((* is_link_function) (link_path)) {
 			if (strcmp (dir_entry->d_name, link_name) == 0) {
 				nautilus_link_local_set_link_uri (link_path, link_target_uri);
@@ -707,8 +785,6 @@
 	
 	closedir (dir);
 
-	g_free (desktop_path);
-	
 	return found_link;
 }
 
@@ -720,10 +796,8 @@
 static void
 update_home_link_and_delete_copies (void)
 {
-	char *desktop_path, *home_link_name, *home_uri;
+	char *home_link_name, *home_uri;
 
-	desktop_path = nautilus_get_desktop_directory ();
-
 	/* Note to translators: If it's hard to compose a good home
 	 * icon name from the user name, you can use a string without
 	 * an "%s" here, in which case the home icon name will not
@@ -739,7 +813,7 @@
 	if (!update_link_and_delete_copies (nautilus_link_local_is_home_link,
 					    home_link_name,
 					    home_uri)) {
-		nautilus_link_local_create (desktop_path,
+		nautilus_link_local_create (desktop_directory,
 					    home_link_name,
 					    "temp-home.png", 
 					    home_uri,
@@ -747,7 +821,6 @@
 					    NAUTILUS_LINK_HOME);
 	}
 	
-	g_free (desktop_path);
 	g_free (home_link_name);
 	g_free (home_uri);
 }
@@ -755,7 +828,6 @@
 static void
 update_trash_link_and_delete_copies (void)
 {
-	char *desktop_path;
 
 	/* Check for trash link */
 	if (update_link_and_delete_copies (nautilus_link_local_is_trash_link,
@@ -764,15 +836,12 @@
 		return;
 	}
 
-	desktop_path = nautilus_get_desktop_directory ();
-	nautilus_link_local_create (desktop_path,
+	nautilus_link_local_create (desktop_directory,
 				    TRASH_LINK_NAME,
 				    "trash-empty.png", 
 				    NAUTILUS_TRASH_URI,
 				    NULL,
 				    NAUTILUS_LINK_TRASH);				    				    
-	g_free (desktop_path);
-	
 	/* Make sure link represents current trash state */
 	fm_desktop_icon_view_trash_state_changed_callback (nautilus_trash_monitor_get (),
 						   	   nautilus_trash_monitor_is_empty (),
Index: src/file-manager/fm-icon-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-icon-view.c,v
retrieving revision 1.186
diff -u -r1.186 fm-icon-view.c
--- src/file-manager/fm-icon-view.c	2001/03/05 08:14:59	1.186
+++ src/file-manager/fm-icon-view.c	2001/04/12 19:45:54
@@ -254,6 +254,9 @@
 	char *position_string, *scale_string;
 	gboolean position_good, scale_good;
 	char *locale;
+	char *path, *uri;
+	int res, size;
+	char *buf;
 
 	g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
 	g_assert (NAUTILUS_IS_FILE (file));
@@ -276,6 +279,28 @@
 		 &position->x, &position->y) == 2;
 	g_free (position_string);
 
+	/* If it is the desktop directory, maybe the gnome-libs metadata has information about it */
+
+	if (!position_good) {
+		if (nautilus_file_is_local (file) && nautilus_file_is_in_desktop (file)) {
+			uri = nautilus_file_get_uri (file);
+			path = gnome_vfs_get_local_path_from_uri (uri);
+
+			if (path != NULL) {
+				res = gnome_metadata_get (path, "icon-position", &size, &buf);
+
+				if (res == 0) {
+					if (sscanf (buf, "%d%d", &position->x, &position->y) == 2) {
+						position_good = TRUE;
+					}
+					g_free (buf);
+				}
+			}
+			g_free (path);
+			g_free (uri);
+		}
+	}
+	
 	/* Get the scale of the icon from the metadata. */
 	scale_string = nautilus_file_get_metadata
 		(file, NAUTILUS_METADATA_KEY_ICON_SCALE, "1");
@@ -1576,6 +1601,8 @@
 	char *position_string;
 	char *scale_string, *scale_string_x, *scale_string_y;
 	char *locale;
+	char *uri, *path;
+	char buf [128];
 
 	g_assert (FM_IS_ICON_VIEW (icon_view));
 	g_assert (container == get_icon_container (icon_view));
@@ -1610,6 +1637,20 @@
 			(file, NAUTILUS_METADATA_KEY_ICON_POSITION, 
 			 NULL, position_string);
 		g_free (position_string);
+
+		if (nautilus_file_is_local (file) && nautilus_file_is_in_desktop (file)) {
+			uri = nautilus_file_get_uri (file);
+			path = gnome_vfs_get_local_path_from_uri (uri);
+
+			if (path) {
+				g_snprintf (buf, sizeof (buf), "%d %d", position->x, position->y);
+
+				gnome_metadata_set (path, "icon-position", strlen (buf)+1, buf);
+			}
+
+			g_free (uri);
+			g_free (path);
+		}
 	}
 
 	/* FIXME bugzilla.eazel.com 662: 




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