nautilus r13674 - in trunk: . libnautilus-private src



Author: alexl
Date: Wed Jan 30 15:52:03 2008
New Revision: 13674
URL: http://svn.gnome.org/viewvc/nautilus?rev=13674&view=rev

Log:
2008-01-30  Alexander Larsson  <alexl redhat com>

        * libnautilus-private/nautilus-autorun.[ch]:
	Add functions to inhibit autorun for a volume
	or for the volume of a file.
	
        * src/nautilus-application.c:
	Convert automount code to new way to inhibit autorun.
	
        * libnautilus-private/nautilus-file-operations.c:
        * libnautilus-private/nautilus-mime-actions.c:
        * libnautilus-private/nautilus-vfs-file.c:
        * src/nautilus-window-manage-views.c:
	Inhibit autorun if we manually mount stuff.



Modified:
   trunk/ChangeLog
   trunk/libnautilus-private/nautilus-autorun.c
   trunk/libnautilus-private/nautilus-autorun.h
   trunk/libnautilus-private/nautilus-file-operations.c
   trunk/libnautilus-private/nautilus-mime-actions.c
   trunk/libnautilus-private/nautilus-vfs-file.c
   trunk/src/nautilus-application.c
   trunk/src/nautilus-window-manage-views.c

Modified: trunk/libnautilus-private/nautilus-autorun.c
==============================================================================
--- trunk/libnautilus-private/nautilus-autorun.c	(original)
+++ trunk/libnautilus-private/nautilus-autorun.c	Wed Jan 30 15:52:03 2008
@@ -60,6 +60,8 @@
 	COLUMN_AUTORUN_ITEM_TYPE,	
 };
 
+static gboolean should_autorun_mount (GMount *mount);
+
 void
 nautilus_autorun_get_preferences (const char *x_content_type, 
 				  gboolean *pref_ask, 
@@ -1233,7 +1235,8 @@
 {
 	AutorunData *data;
 
-	if (eel_preferences_get_boolean (NAUTILUS_PREFERENCES_MEDIA_AUTORUN_NEVER))
+	if (!should_autorun_mount (mount) ||
+	    eel_preferences_get_boolean (NAUTILUS_PREFERENCES_MEDIA_AUTORUN_NEVER))
 		return;
 		
 	/* TODO: only do this for local mounts */
@@ -1270,3 +1273,94 @@
 	 */
 	return _g_mount_guess_content_type (mount, force_rescan, NULL);
 }
+
+
+static GList *inhibit_mount_handling_for = NULL;
+
+
+static gboolean
+remove_inhibit_file_cb (gpointer data)
+{
+	GFile *file = data;
+	GList *l;
+
+	l = g_list_find (inhibit_mount_handling_for, file);
+	if (l != NULL) {
+		inhibit_mount_handling_for = g_list_delete_link (inhibit_mount_handling_for, l);
+		g_object_unref (file);
+	}
+	
+	return FALSE;
+}
+
+void
+nautilus_inhibit_autorun_for_file (GFile *file)
+{
+	inhibit_mount_handling_for = g_list_prepend (inhibit_mount_handling_for, g_object_ref (file));
+	g_timeout_add_full (0,
+			    5000,
+			    remove_inhibit_file_cb,
+			    g_object_ref (file),
+			    g_object_unref);
+}
+
+static gboolean
+remove_inhibit_volume (gpointer data)
+{
+	GVolume *volume = data;
+
+	g_object_set_data (G_OBJECT (volume), "nautilus-inhibit-autorun", NULL);
+	return FALSE;
+}
+
+void
+nautilus_inhibit_autorun_for_volume (GVolume *volume)
+{
+	g_object_set_data (G_OBJECT (volume), "nautilus-inhibit-autorun", GINT_TO_POINTER (1));
+	g_timeout_add_full (0,
+			    5000,
+			    remove_inhibit_volume,
+			    g_object_ref (volume),
+			    g_object_unref);
+}
+
+static gboolean
+should_autorun_mount (GMount *mount)
+{
+	GFile *root, *file;
+	GList *l;
+	GVolume *enclosing_volume;
+	gboolean ignore_autorun;
+
+	ignore_autorun = FALSE;
+	enclosing_volume = g_mount_get_volume (mount);
+	if (enclosing_volume != NULL) {
+		if (g_object_get_data (G_OBJECT (enclosing_volume), "nautilus-inhibit-autorun") != NULL) {
+			ignore_autorun = TRUE;
+			g_object_set_data (G_OBJECT (enclosing_volume), "nautilus-inhibit-autorun", NULL);
+		}
+		g_object_unref (enclosing_volume);
+	}
+
+	if (ignore_autorun) {
+		return FALSE;
+	}
+	
+	root = g_mount_get_root (mount);
+
+	for (l = inhibit_mount_handling_for; l != NULL; l = l->next) {
+		file = l->data;
+		if (g_file_contains_file (root, file)) {
+			ignore_autorun = TRUE;
+			
+			inhibit_mount_handling_for = g_list_delete_link (inhibit_mount_handling_for, l);
+			g_object_unref (file);
+			
+			break;
+		}
+	}
+	
+	g_object_unref (root);
+
+	return !ignore_autorun;
+}

Modified: trunk/libnautilus-private/nautilus-autorun.h
==============================================================================
--- trunk/libnautilus-private/nautilus-autorun.h	(original)
+++ trunk/libnautilus-private/nautilus-autorun.h	Wed Jan 30 15:52:03 2008
@@ -84,4 +84,7 @@
 
 void nautilus_autorun_launch_for_mount (GMount *mount, GAppInfo *app_info);
 
+void nautilus_inhibit_autorun_for_volume (GVolume *volume);
+void nautilus_inhibit_autorun_for_file (GFile *file);
+
 #endif /* NAUTILUS_AUTORUN_H */

Modified: trunk/libnautilus-private/nautilus-file-operations.c
==============================================================================
--- trunk/libnautilus-private/nautilus-file-operations.c	(original)
+++ trunk/libnautilus-private/nautilus-file-operations.c	Wed Jan 30 15:52:03 2008
@@ -71,6 +71,7 @@
 #include "nautilus-desktop-link-monitor.h"
 #include "nautilus-global-preferences.h"
 #include "nautilus-link.h"
+#include "nautilus-autorun.h"
 #include "nautilus-trash-monitor.h"
 #include "nautilus-file-utilities.h"
 
@@ -1991,6 +1992,7 @@
 	GMountOperation *mount_op;
 	
 	mount_op = eel_mount_operation_new (parent_window);
+	nautilus_inhibit_autorun_for_volume (volume);
 	g_volume_mount (volume, mount_op, NULL, volume_mount_cb, mount_op);
 }
 

Modified: trunk/libnautilus-private/nautilus-mime-actions.c
==============================================================================
--- trunk/libnautilus-private/nautilus-mime-actions.c	(original)
+++ trunk/libnautilus-private/nautilus-mime-actions.c	Wed Jan 30 15:52:03 2008
@@ -35,6 +35,7 @@
 
 #include "nautilus-file-attributes.h"
 #include "nautilus-file.h"
+#include "nautilus-autorun.h"
 #include "nautilus-file-operations.h"
 #include "nautilus-metadata.h"
 #include "nautilus-program-choosing.h"
@@ -1265,6 +1266,7 @@
 		mount_op = eel_mount_operation_new (parameters->parent_window);
 		g_signal_connect (mount_op, "active_changed", (GCallback)activate_mount_op_active, parameters);
 		location = nautilus_file_get_location (file);
+		nautilus_inhibit_autorun_for_file (location);
 		g_file_mount_enclosing_volume (location, mount_op, parameters->cancellable,
 					       activation_mount_not_mounted_callback, parameters);
 		g_object_unref (location);

Modified: trunk/libnautilus-private/nautilus-vfs-file.c
==============================================================================
--- trunk/libnautilus-private/nautilus-vfs-file.c	(original)
+++ trunk/libnautilus-private/nautilus-vfs-file.c	Wed Jan 30 15:52:03 2008
@@ -28,6 +28,7 @@
 
 #include "nautilus-directory-private.h"
 #include "nautilus-file-private.h"
+#include "nautilus-autorun.h"
 #include <eel/eel-gtk-macros.h>
 #include <eel/eel-mount-operation.h>
 #include <glib/gi18n.h>
@@ -236,9 +237,9 @@
 	error = NULL;
 	mounted_on = g_file_mount_mountable_finish (G_FILE (source_object),
 						    res, &error);
-	
 	nautilus_file_operation_complete (op, mounted_on, error);
 	if (mounted_on) {
+		nautilus_inhibit_autorun_for_file (mounted_on);
 		g_object_unref (mounted_on);
 	}
 	if (error) {

Modified: trunk/src/nautilus-application.c
==============================================================================
--- trunk/src/nautilus-application.c	(original)
+++ trunk/src/nautilus-application.c	Wed Jan 30 15:52:03 2008
@@ -207,8 +207,7 @@
 				continue;
 			}
 			
-			/* Set this so we don't autorun stuff from it */
-			g_object_set_data (G_OBJECT (volume), "nautilus-automounted", GINT_TO_POINTER (1));
+			nautilus_inhibit_autorun_for_volume (volume);
 
 			/* pass NULL as GMountOperation to avoid user interaction */
 			g_volume_mount (volume, NULL, NULL, startup_volume_mount_cb, NULL);
@@ -1418,8 +1417,6 @@
 {
 	NautilusDirectory *directory;
 	GFile *root;
-	GVolume *enclosing_volume;
-	gboolean ignore_autorun;
 		
 	root = g_mount_get_root (mount);
 	directory = nautilus_directory_get_existing (root);
@@ -1429,21 +1426,7 @@
 		nautilus_directory_unref (directory);
 	}
 
-	ignore_autorun = FALSE;
-
-	enclosing_volume = g_mount_get_volume (mount);
-	if (enclosing_volume != NULL) {
-		if (g_object_get_data (G_OBJECT (enclosing_volume), "nautilus-automounted") != NULL) {
-			ignore_autorun = TRUE;
-			/* Autorun if the user unmounts and then mounts */
-			g_object_set_data (G_OBJECT (enclosing_volume), "nautilus-automounted", NULL);
-		}
-		g_object_unref (enclosing_volume);
-	}
-
-	if (!ignore_autorun) {
-		nautilus_autorun (mount, autorun_show_window, application);
-	}
+	nautilus_autorun (mount, autorun_show_window, application);
 }
 
 /* Called whenever a mount is unmounted. Check and see if there are

Modified: trunk/src/nautilus-window-manage-views.c
==============================================================================
--- trunk/src/nautilus-window-manage-views.c	(original)
+++ trunk/src/nautilus-window-manage-views.c	Wed Jan 30 15:52:03 2008
@@ -968,6 +968,7 @@
 		data->cancellable = g_cancellable_new ();
 		data->window = window;
 		window->details->mount_cancellable = data->cancellable;
+		nautilus_inhibit_autorun_for_file (location);
 		g_file_mount_enclosing_volume (location, mount_op, window->details->mount_cancellable,
 					       mount_not_mounted_callback, data);
 		g_object_unref (location);



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