Adding support for OnlyShowIn



Hi,

I want to add support for the "OnlyShowIn" key in .desktop files, so
that Nautilus will not show desktop items which have "OnlyShowIn=KDE",
for example.

I started with the attached patch, but it doesn't work.  Some advice
would be appreciated :)

Basically, my is_foreign_desktop_file() gets called with a URI that is
incorrect.  Say I'm viewing /home/federico and I double-click on the
icon for /home/federico/Desktop.  In it I have a test.desktop, which has
"OnlyShowIn=KDE".

My is_foreign_desktop_file() function gets called with a URI of
"file:///home/federico/test.desktop", instead of
"file:///home/federico/Desktop/test.desktop".

Why does the async machinery (i.e. mime_list_one() and friends) get
callbacks for URIs that are *not* direct children of the current
directory?  I.e. a directory /home/federico will ask to read the MIME
types of /home/federico/Desktop/*, and then I can't know what the
original request was.

Thanks,

  Federico
--- nautilus-2.12.2.orig/libnautilus-private/nautilus-directory-async.c	2006-04-05 17:17:10.000000000 -0500
+++ nautilus-2.12.2.onlyshowin/libnautilus-private/nautilus-directory-async.c	2006-03-31 14:27:46.000000000 -0600
@@ -707,7 +707,39 @@ is_dot_or_dot_dot (const char *name)
 }
 
 static gboolean
-should_skip_file (NautilusDirectory *directory, GnomeVFSFileInfo *info)
+is_foreign_desktop_file (NautilusDirectory *directory, const char *uri, GnomeVFSFileInfo *info)
+{
+	const char *mime_type;
+	GnomeDesktopItem *ditem;
+	gboolean retval;
+
+	mime_type = gnome_vfs_file_info_get_mime_type (info);
+	if (g_ascii_strcasecmp (mime_type, "application/x-desktop") != 0) {
+		return FALSE;
+	}
+
+	/* NULL GError */
+	ditem = gnome_desktop_item_new_from_uri (uri, 0, NULL);
+
+	retval = FALSE;
+
+	if (ditem) {
+		const char *only_show_in;
+
+		only_show_in = gnome_desktop_item_get_string (ditem, GNOME_DESKTOP_ITEM_ONLY_SHOW_IN);
+
+		if (only_show_in && g_ascii_strcasecmp (only_show_in, "GNOME") != 0) {
+			retval = TRUE;
+		}
+
+		gnome_desktop_item_unref (ditem);
+	}
+
+	return retval;
+}
+
+static gboolean
+should_skip_file (NautilusDirectory *directory, const char *uri, GnomeVFSFileInfo *info)
 {
 	static gboolean show_hidden_files_changed_callback_installed = FALSE;
 	static gboolean show_backup_files_changed_callback_installed = FALSE;
@@ -742,6 +774,10 @@ should_skip_file (NautilusDirectory *dir
 		return TRUE;
 	}
 
+	if (is_foreign_desktop_file (directory, uri, info)) {
+		return TRUE;
+	}
+
 	if (!show_hidden_files && (nautilus_file_name_matches_hidden_pattern (info->name) ||
 				   (directory != NULL &&
 				    g_hash_table_lookup (directory->details->hidden_file_hash, info->name) != NULL))) {
@@ -815,6 +851,7 @@ dequeue_pending_idle_callback (gpointer 
 
 	/* Build a list of NautilusFile objects. */
 	for (node = pending_file_info; node != NULL; node = node->next) {
+		char *uri;
 		file_info = node->data;
 
 		/* Update the file count. */
@@ -824,7 +861,8 @@ dequeue_pending_idle_callback (gpointer 
 		 * moving this into the actual callback instead of
 		 * waiting for the idle function.
 		 */
-		if (!should_skip_file (directory, file_info)) {
+		uri = nautilus_directory_get_file_uri (directory, file_info->name);
+		if (!should_skip_file (directory, uri, file_info)) {
 			directory->details->load_file_count += 1;
 
 			/* Add the MIME type to the set. */
@@ -834,6 +872,7 @@ dequeue_pending_idle_callback (gpointer 
 						 file_info->mime_type);
 			}
 		}
+		g_free (uri);
 		
 		/* check if the file already exists */
 		file = nautilus_directory_find_file_by_name (directory, file_info->name);
@@ -1374,16 +1413,22 @@ nautilus_directory_cancel_callback_inter
 }
 
 static guint
-count_non_skipped_files (GList *list)
+count_non_skipped_files (NautilusDirectory *directory, GList *list)
 {
 	guint count;
 	GList *node;
 
 	count = 0;
 	for (node = list; node != NULL; node = node->next) {
-		if (!should_skip_file (NULL, node->data)) {
+		GnomeVFSFileInfo *file_info;
+		char *uri;
+
+		file_info = node->data;
+		uri = nautilus_directory_get_file_uri (directory, file_info->name);
+		if (!should_skip_file (NULL, uri, file_info)) {
 			count += 1;
 		}
+		g_free (uri);
 	}
 	return count;
 }
@@ -1420,7 +1465,7 @@ directory_count_callback (GnomeVFSAsyncH
 	} else {
 		count_file->details->directory_count_failed = FALSE;
 		count_file->details->got_directory_count = TRUE;
-		count_file->details->directory_count = count_non_skipped_files (list);
+		count_file->details->directory_count = count_non_skipped_files (directory, list);
 	}
 	directory->details->count_file = NULL;
 	directory->details->count_in_progress = NULL;
@@ -2228,9 +2273,14 @@ deep_count_one (NautilusDirectory *direc
 {
 	NautilusFile *file;
 	char *escaped_name, *uri;
-	
-	if (should_skip_file (NULL, info))
+	gboolean skip;
+
+	uri = nautilus_directory_get_file_uri (directory, info->name);
+	skip = should_skip_file (NULL, uri, info);
+	g_free (uri);
+	if (skip) {
 		return;
+	}
 
 	file = directory->details->deep_count_file;
 
@@ -2398,7 +2448,13 @@ static void
 mime_list_one (NautilusDirectory *directory,
 	       GnomeVFSFileInfo *info)
 {
-	if (should_skip_file (NULL, info)) {
+	char *uri;
+	gboolean skip;
+
+	uri = nautilus_directory_get_file_uri (directory, info->name);
+	skip = should_skip_file (NULL, uri, info);
+	g_free (uri);
+	if (skip) {
 		return;
 	}
 


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