Commit 075ab7a0 authored by Alexander Larsson's avatar Alexander Larsson Committed by Alexander Larsson

Add functions to inhibit autorun for a volume or for the volume of a file.

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.


svn path=/trunk/; revision=13674
parent af54d704
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.
2008-01-29 Alexander Larsson <alexl@redhat.com>
* libnautilus-private/nautilus-file-operations.c (report_link_progress):
......
......@@ -60,6 +60,8 @@ enum
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 @@ nautilus_autorun (GMount *mount, NautilusAutorunOpenWindow open_window_func, gpo
{
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 @@ nautilus_autorun_get_x_content_types_for_mount (GMount *mount,
*/
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;
}
......@@ -84,4 +84,7 @@ char **nautilus_autorun_get_x_content_types_for_mount (GMount *mount,
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 */
......@@ -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 @@ nautilus_file_operations_mount_volume (GtkWindow *parent_window,
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);
}
......
......@@ -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 @@ activation_mount_not_mounted (ActivateParameters *parameters)
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);
......
......@@ -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 @@ vfs_file_mount_callback (GObject *source_object,
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) {
......
......@@ -207,8 +207,7 @@ automount_all_volumes (NautilusApplication *application)
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 @@ mount_added_callback (GVolumeMonitor *monitor,
{
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 @@ mount_added_callback (GVolumeMonitor *monitor,
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
......
......@@ -968,6 +968,7 @@ got_file_info_for_view_selection_callback (NautilusFile *file,
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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment