Patch to hide KDE trash directory on desktop



This Nautilus patch makes nautilus automatically hide the trash
directory that KDE makes in ~/Desktop. I'd like to commit this so we
interoperate better with KDE wrt ~/Desktop.

How does this code freeze review thing work?

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a superhumanly strong gay househusband who hangs with the wrong crowd. 
She's a provocative African-American cab driver with a knack for trouble. They 
fight crime! 
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.201
diff -u -p -r1.201 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	8 Jul 2003 15:48:12 -0000	1.201
+++ libnautilus-private/nautilus-directory-async.c	26 Aug 2003 15:01:14 -0000
@@ -103,6 +103,9 @@ static GHashTable *waiting_directories;
 static GHashTable *async_jobs;
 #endif
 
+/* Hide kde trashcan directory */
+static char *kde_trash_dir_name = NULL;
+
 /* Forward declarations for functions that need them. */
 static void     deep_count_load             (NautilusDirectory      *directory,
 					     const char             *uri);
@@ -125,6 +128,12 @@ static void     move_file_to_low_priorit
 						    NautilusFile      *file);
 
 
+void
+nautilus_set_kde_trash_name (const char *trash_dir)
+{
+	g_free (kde_trash_dir_name);
+	kde_trash_dir_name = g_strdup (trash_dir);
+}
 
 /* Some helpers for case-insensitive strings.
  * Move to nautilus-glib-extensions?
@@ -2044,6 +2053,15 @@ start_monitoring_file_list (NautilusDire
 	directory->details->load_mime_list_hash = istr_set_new ();
 
 	read_dot_hidden_file (directory);
+	
+	/* Hack to work around kde trash dir */
+	if (kde_trash_dir_name != NULL && nautilus_directory_is_desktop_directory (directory)) {
+		char *escaped;
+		escaped = gnome_vfs_escape_string (kde_trash_dir_name);
+		g_hash_table_insert (directory->details->hidden_file_hash,
+				     escaped, escaped);
+	}
+
 	
 #ifdef DEBUG_LOAD_DIRECTORY
 	g_message ("load_directory called to monitor file list of %s", directory->details->uri);
Index: libnautilus-private/nautilus-directory-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-private.h,v
retrieving revision 1.90
diff -u -p -r1.90 nautilus-directory-private.h
--- libnautilus-private/nautilus-directory-private.h	27 Jun 2003 18:33:58 -0000	1.90
+++ libnautilus-private/nautilus-directory-private.h	26 Aug 2003 15:01:14 -0000
@@ -219,5 +219,9 @@ void               nautilus_directory_ad
 void               nautilus_directory_remove_file_from_work_queue     (NautilusDirectory *directory,
 								       NautilusFile *file);
 
+/* KDE compatibility hacks */
+
+void               nautilus_set_kde_trash_name                        (const char *trash_dir);
+
 /* debugging functions */
 int                nautilus_directory_number_outstanding              (void);
Index: libnautilus-private/nautilus-directory.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory.c,v
retrieving revision 1.248
diff -u -p -r1.248 nautilus-directory.c
--- libnautilus-private/nautilus-directory.c	27 Jun 2003 18:33:58 -0000	1.248
+++ libnautilus-private/nautilus-directory.c	26 Aug 2003 15:01:14 -0000
@@ -1704,6 +1704,21 @@ nautilus_directory_list_sort_by_uri (GLi
 	return g_list_sort (list, compare_by_uri_cover);
 }
 
+gboolean
+nautilus_directory_is_desktop_directory (NautilusDirectory   *directory)
+{
+	GnomeVFSURI *dir_vfs_uri;
+
+	dir_vfs_uri = directory->details->vfs_uri;
+
+	if (dir_vfs_uri == NULL ||
+	    strcmp (dir_vfs_uri->method_string, "file") != 0) {
+		return FALSE;
+	}
+
+	return nautilus_is_desktop_directory_escaped (dir_vfs_uri->text);
+}
+
 #if !defined (NAUTILUS_OMIT_SELF_CHECK)
 
 #include <eel/eel-debug.h>
Index: libnautilus-private/nautilus-directory.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory.h,v
retrieving revision 1.64
diff -u -p -r1.64 nautilus-directory.h
--- libnautilus-private/nautilus-directory.h	2 Apr 2003 11:50:53 -0000	1.64
+++ libnautilus-private/nautilus-directory.h	26 Aug 2003 15:01:14 -0000
@@ -212,4 +212,8 @@ void               nautilus_directory_li
 GList *            nautilus_directory_list_copy                (GList                     *directory_list);
 GList *            nautilus_directory_list_sort_by_uri         (GList                     *directory_list);
 
+/* Fast way to check if a directory is the desktop directory */
+gboolean           nautilus_directory_is_desktop_directory     (NautilusDirectory         *directory);
+
+
 #endif /* NAUTILUS_DIRECTORY_H */
Index: libnautilus-private/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.c,v
retrieving revision 1.112
diff -u -p -r1.112 nautilus-file-utilities.c
--- libnautilus-private/nautilus-file-utilities.c	8 Jul 2003 15:48:12 -0000	1.112
+++ libnautilus-private/nautilus-file-utilities.c	26 Aug 2003 15:01:14 -0000
@@ -169,25 +169,64 @@ nautilus_get_desktop_directory_uri_no_cr
 
 /* These need to be reset to NULL when desktop_is_home_dir changes */
 static char *escaped_desktop_dir = NULL;
-static char *escaped_desktop_file = NULL;
+static char *escaped_desktop_dir_dirname = NULL;
+static char *escaped_desktop_dir_filename = NULL;
 static gboolean desktop_dir_changed_callback_installed = FALSE;
 
 static void
 desktop_dir_changed_callback (gpointer callback_data)
 {
 	g_free (escaped_desktop_dir);
-	g_free (escaped_desktop_file);
+	g_free (escaped_desktop_dir_filename);
+	g_free (escaped_desktop_dir_dirname);
 	escaped_desktop_dir = NULL;
-	escaped_desktop_file = NULL;
+	escaped_desktop_dir_dirname = NULL;
+	escaped_desktop_dir_filename = NULL;
 }
 
-gboolean
-nautilus_is_desktop_directory_escaped (char *escaped_dir,
-				       char *escaped_file)
+static void
+update_desktop_dir (void)
 {
 	char *uri, *path;
 	GnomeVFSURI *vfs_uri;
 
+	path = get_desktop_path ();
+	uri = gnome_vfs_get_uri_from_local_path (path);
+	vfs_uri = gnome_vfs_uri_new (uri);
+	g_free (path);
+	g_free (uri);
+	
+	escaped_desktop_dir = g_strdup (vfs_uri->text);
+	escaped_desktop_dir_filename = gnome_vfs_uri_extract_short_path_name (vfs_uri);
+	escaped_desktop_dir_dirname = gnome_vfs_uri_extract_dirname (vfs_uri);
+	
+	gnome_vfs_uri_unref (vfs_uri);
+}
+
+gboolean
+nautilus_is_desktop_directory_file_escaped (char *escaped_dirname,
+					    char *escaped_file)
+{
+
+	if (!desktop_dir_changed_callback_installed) {
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
+					      desktop_dir_changed_callback,
+					      NULL);
+		desktop_dir_changed_callback_installed = TRUE;
+	}
+		
+	if (escaped_desktop_dir == NULL) {
+		update_desktop_dir ();
+	}
+
+	return (strcmp (escaped_dirname, escaped_desktop_dir_dirname) == 0 &&
+		strcmp (escaped_file, escaped_desktop_dir_filename) == 0);
+}
+
+gboolean
+nautilus_is_desktop_directory_escaped (char *escaped_dir)
+{
+
 	if (!desktop_dir_changed_callback_installed) {
 		eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
 					      desktop_dir_changed_callback,
@@ -196,18 +235,10 @@ nautilus_is_desktop_directory_escaped (c
 	}
 		
 	if (escaped_desktop_dir == NULL) {
-		path = get_desktop_path ();
-		uri = gnome_vfs_get_uri_from_local_path (path);
-		vfs_uri = gnome_vfs_uri_new (uri);
-		g_free (path);
-		g_free (uri);
-		escaped_desktop_file = gnome_vfs_uri_extract_short_path_name (vfs_uri);
-		escaped_desktop_dir = gnome_vfs_uri_extract_dirname (vfs_uri);
-		gnome_vfs_uri_unref (vfs_uri);
+		update_desktop_dir ();
 	}
 
-	return (strcmp (escaped_dir, escaped_desktop_dir) == 0 &&
-		strcmp (escaped_file, escaped_desktop_file) == 0);
+	return strcmp (escaped_dir, escaped_desktop_dir) == 0;
 }
 
 
Index: libnautilus-private/nautilus-file-utilities.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.h,v
retrieving revision 1.49
diff -u -p -r1.49 nautilus-file-utilities.h
--- libnautilus-private/nautilus-file-utilities.h	8 Jul 2003 15:48:12 -0000	1.49
+++ libnautilus-private/nautilus-file-utilities.h	26 Aug 2003 15:01:14 -0000
@@ -37,8 +37,9 @@ gboolean nautilus_file_name_matches_back
 char *   nautilus_get_user_directory                 (void);
 char *   nautilus_get_desktop_directory              (void);
 char *   nautilus_get_desktop_directory_uri          (void);
-gboolean nautilus_is_desktop_directory_escaped       (char *escaped_dir,
+gboolean nautilus_is_desktop_directory_file_escaped  (char *escaped_dirname,
 						      char *escaped_filename);
+gboolean nautilus_is_desktop_directory_escaped       (char *escaped_dir);
 char *   nautilus_get_gmc_desktop_directory          (void);
 char *   nautilus_get_pixmap_directory               (void);
 
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.324
diff -u -p -r1.324 nautilus-file.c
--- libnautilus-private/nautilus-file.c	8 Jul 2003 15:48:12 -0000	1.324
+++ libnautilus-private/nautilus-file.c	26 Aug 2003 15:01:15 -0000
@@ -1724,8 +1724,8 @@ file_is_desktop (NautilusFile *file)
 		return FALSE;
 	}
 
-	return nautilus_is_desktop_directory_escaped (dir_vfs_uri->text,
-						      file->details->relative_uri);
+	return nautilus_is_desktop_directory_file_escaped (dir_vfs_uri->text,
+							   file->details->relative_uri);
 }
 
 static int
Index: src/nautilus-application.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.c,v
retrieving revision 1.203
diff -u -p -r1.203 nautilus-application.c
--- src/nautilus-application.c	5 Jul 2003 15:53:36 -0000	1.203
+++ src/nautilus-application.c	26 Aug 2003 15:02:19 -0000
@@ -71,6 +71,7 @@
 #include <libnautilus-private/nautilus-undo-manager.h>
 #include <libnautilus-private/nautilus-volume-monitor.h>
 #include <libnautilus-private/nautilus-desktop-link-monitor.h>
+#include <libnautilus-private/nautilus-directory-private.h>
 #include <bonobo-activation/bonobo-activation.h>
 
 /* Needed for the is_kdesktop_present check */
@@ -366,6 +367,53 @@ finish_startup (NautilusApplication *app
 	nautilus_desktop_link_monitor_get ();
 }
 
+static void
+initialize_kde_trash_hack (void)
+{
+	char *trash_dir;
+	char *desktop_dir, *desktop_uri, *kde_trash_dir;
+	char *dir, *basename;
+	char *kde_conf_file;
+	char *key;
+	gboolean def;
+	
+	trash_dir = NULL;
+
+	desktop_uri = nautilus_get_desktop_directory_uri_no_create ();
+	desktop_dir = gnome_vfs_get_local_path_from_uri (desktop_uri);
+	g_free (desktop_uri);
+	
+	if (g_file_test (desktop_dir, G_FILE_TEST_EXISTS)) {
+		/* Look for trash directory */
+		kde_conf_file = g_build_filename (g_get_home_dir(), ".kde/share/config/kdeglobals", NULL);
+		key = g_strconcat ("=", kde_conf_file, "=/Paths/Trash", NULL);
+		kde_trash_dir = gnome_config_get_string_with_default (key, &def);
+		gnome_config_drop_file (kde_conf_file);
+		g_free (kde_conf_file);
+		g_free (key);
+
+		if (kde_trash_dir != NULL) {
+			basename = g_path_get_basename (kde_trash_dir);
+			g_free (kde_trash_dir);
+			
+			dir = g_build_filename (desktop_dir, basename, NULL);
+
+			if (g_file_test (dir, G_FILE_TEST_IS_DIR)) {
+				trash_dir = g_strdup (basename);
+			} 
+			g_free (basename);
+			g_free (dir);
+		} 
+
+		if (trash_dir != NULL) {
+			nautilus_set_kde_trash_name (trash_dir);
+		}
+
+		g_free (trash_dir);
+	}
+	g_free (desktop_dir);
+}
+
 void
 nautilus_application_startup (NautilusApplication *application,
 			      gboolean kill_shell,
@@ -403,6 +451,8 @@ nautilus_application_startup (NautilusAp
 		g_idle_add (create_starthere_link_callback, NULL);
 		nautilus_set_first_time_file_flag ();
 	}
+
+	initialize_kde_trash_hack ();
 
 	CORBA_exception_init (&ev);
 


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