Commit 00e59a6b authored by David Zeuthen's avatar David Zeuthen Committed by Alexander Larsson
Browse files

Use g_volume_should_automount() to determine if we should autorun programs

2008-02-21  David Zeuthen  <davidz@redhat.com>

	* libnautilus-private/nautilus-autorun.c: (should_autorun_mount):
	Use g_volume_should_automount() to determine if we should autorun
	programs on a mount.

	* libnautilus-private/nautilus-directory-async.c:
	(nautilus_directory_set_up_request),
	(nautilus_async_destroying_file), (lacks_filesystem_info),
	(wants_filesystem_info), (request_is_satisfied),
	(directory_count_start), (mime_list_start),
	(filesystem_info_cancel), (filesystem_info_stop),
	(filesystem_info_state_free), (got_filesystem_info),
	(query_filesystem_info_callback), (filesystem_info_start),
	(start_or_stop_io), (nautilus_directory_cancel),
	(cancel_filesystem_info_for_file), (cancel_loading_attributes),
	(nautilus_directory_cancel_loading_file_attributes):
	* libnautilus-private/nautilus-directory-private.h:
	* libnautilus-private/nautilus-file-attributes.h: Add new
	filesystem info attribute; right now two bits in NautilusFile's
	private structure are set; the filesystem::use-preview and
	filesystem:readonly.

	* libnautilus-private/nautilus-file-operations.c:
	(nautilus_file_operations_mount_volume):
	* src/nautilus-places-sidebar.c: (open_selected_bookmark),
	(mount_shortcut_cb): Don't inhibit automount from
	nautilus_file_operations_mount_volume() because then everything
	will be inhibited as the mount_added callback use it as
	well. Rather, move the call to inhibit out to the proper call
	sites.

	* libnautilus-private/nautilus-file-private.h:
	* libnautilus-private/nautilus-file.c:
	(nautilus_file_get_filesystem_use_preview),
	(nautilus_file_should_show_thumbnail),
	(get_speed_tradeoff_preference_for_file),
	(nautilus_file_get_mount):
	* libnautilus-private/nautilus-file.h:
	* src/file-manager/fm-directory-view.c: (load_directory):
	* src/file-manager/fm-icon-view.c: (should_preview_sound):
	* src/nautilus-window-manage-views.c: (update_for_new_location):
	Use the new filesystem::use-preview hint to determine if we should
	preview non-native files (such as gphoto2:// and cdda://
	mounts). 


svn path=/trunk/; revision=13795
parent 7f77d09d
2008-02-21 David Zeuthen <davidz@redhat.com>
* libnautilus-private/nautilus-autorun.c: (should_autorun_mount):
Use g_volume_should_automount() to determine if we should autorun
programs on a mount.
* libnautilus-private/nautilus-directory-async.c:
(nautilus_directory_set_up_request),
(nautilus_async_destroying_file), (lacks_filesystem_info),
(wants_filesystem_info), (request_is_satisfied),
(directory_count_start), (mime_list_start),
(filesystem_info_cancel), (filesystem_info_stop),
(filesystem_info_state_free), (got_filesystem_info),
(query_filesystem_info_callback), (filesystem_info_start),
(start_or_stop_io), (nautilus_directory_cancel),
(cancel_filesystem_info_for_file), (cancel_loading_attributes),
(nautilus_directory_cancel_loading_file_attributes):
* libnautilus-private/nautilus-directory-private.h:
* libnautilus-private/nautilus-file-attributes.h: Add new
filesystem info attribute; right now two bits in NautilusFile's
private structure are set; the filesystem::use-preview and
filesystem:readonly.
* libnautilus-private/nautilus-file-operations.c:
(nautilus_file_operations_mount_volume):
* src/nautilus-places-sidebar.c: (open_selected_bookmark),
(mount_shortcut_cb): Don't inhibit automount from
nautilus_file_operations_mount_volume() because then everything
will be inhibited as the mount_added callback use it as
well. Rather, move the call to inhibit out to the proper call
sites.
* libnautilus-private/nautilus-file-private.h:
* libnautilus-private/nautilus-file.c:
(nautilus_file_get_filesystem_use_preview),
(nautilus_file_should_show_thumbnail),
(get_speed_tradeoff_preference_for_file),
(nautilus_file_get_mount):
* libnautilus-private/nautilus-file.h:
* src/file-manager/fm-directory-view.c: (load_directory):
* src/file-manager/fm-icon-view.c: (should_preview_sound):
* src/nautilus-window-manage-views.c: (update_for_new_location):
Use the new filesystem::use-preview hint to determine if we should
preview non-native files (such as gphoto2:// and cdda://
mounts).
2008-02-21 Cosimo Cecchi <cosimoc@gnome.org>
* src/nautilus-application.c: (find_parent_spatial_window):
......
......@@ -1339,10 +1339,12 @@ should_autorun_mount (GMount *mount)
ignore_autorun = TRUE;
g_object_set_data (G_OBJECT (enclosing_volume), "nautilus-inhibit-autorun", NULL);
}
g_object_unref (enclosing_volume);
}
if (ignore_autorun) {
if (enclosing_volume != NULL) {
g_object_unref (enclosing_volume);
}
return FALSE;
}
......@@ -1350,7 +1352,7 @@ should_autorun_mount (GMount *mount)
for (l = inhibit_mount_handling_for; l != NULL; l = l->next) {
file = l->data;
if (g_file_contains_file (root, file)) {
if (g_file_has_prefix (file, root)) {
ignore_autorun = TRUE;
inhibit_mount_handling_for = g_list_delete_link (inhibit_mount_handling_for, l);
......@@ -1360,10 +1362,14 @@ should_autorun_mount (GMount *mount)
}
}
if (!g_file_is_native (root)) {
/* only do autorun on local files */
/* TODO: Maybe we should do this on some gvfs mounts? like gphoto: ? */
ignore_autorun = TRUE;
/* only do autorun on local files or files where g_volume_should_automount() returns TRUE */
ignore_autorun = TRUE;
if (g_file_is_native (root) ||
(enclosing_volume != NULL && g_volume_should_automount (enclosing_volume))) {
ignore_autorun = FALSE;
}
if (enclosing_volume != NULL) {
g_object_unref (enclosing_volume);
}
g_object_unref (root);
......
......@@ -89,6 +89,12 @@ struct MountState {
NautilusFile *file;
};
struct FilesystemInfoState {
NautilusDirectory *directory;
GCancellable *cancellable;
NautilusFile *file;
};
struct DirectoryLoadState {
NautilusDirectory *directory;
GCancellable *cancellable;
......@@ -628,6 +634,10 @@ nautilus_directory_set_up_request (Request *request,
request->mount = TRUE;
request->file_info = TRUE;
}
if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO) {
request->filesystem_info = TRUE;
}
}
static void
......@@ -1581,6 +1591,12 @@ nautilus_async_destroying_file (NautilusFile *file)
directory->details->mount_state->file = NULL;
changed = TRUE;
}
if (directory->details->filesystem_info_state != NULL &&
directory->details->filesystem_info_state->file == file) {
directory->details->filesystem_info_state->file = NULL;
changed = TRUE;
}
/* Let the directory take care of the rest. */
if (changed) {
......@@ -1644,12 +1660,24 @@ lacks_info (NautilusFile *file)
&& !file->details->is_gone;
}
static gboolean
lacks_filesystem_info (NautilusFile *file)
{
return !file->details->filesystem_info_is_up_to_date;
}
static gboolean
wants_info (const Request *request)
{
return request->file_info;
}
static gboolean
wants_filesystem_info (const Request *request)
{
return request->filesystem_info;
}
static gboolean
lacks_deep_count (NautilusFile *file)
{
......@@ -1798,6 +1826,12 @@ request_is_satisfied (NautilusDirectory *directory,
}
}
if (request->filesystem_info) {
if (has_problem (directory, file, lacks_filesystem_info)) {
return FALSE;
}
}
if (request->top_left_text) {
if (has_problem (directory, file, lacks_top_left)) {
return FALSE;
......@@ -2606,10 +2640,15 @@ directory_count_start (NautilusDirectory *directory,
directory->details->count_in_progress = state;
location = nautilus_file_get_location (file);
#ifdef DEBUG_LOAD_DIRECTORY
g_message ("load_directory called to get shallow file count for %s", uri);
{
char *uri;
uri = g_file_get_uri (location);
g_message ("load_directory called to get shallow file count for %s", uri);
g_free (uri);
}
#endif
location = nautilus_file_get_location (file);
g_file_enumerate_children_async (location,
G_FILE_ATTRIBUTE_STANDARD_NAME ","
......@@ -3137,11 +3176,16 @@ mime_list_start (NautilusDirectory *directory,
directory->details->mime_list_in_progress = state;
location = nautilus_file_get_location (file);
#ifdef DEBUG_LOAD_DIRECTORY
g_message ("load_directory called to get MIME list of %s", uri);
{
char *uri;
uri = g_file_get_uri (location);
g_message ("load_directory called to get MIME list of %s", uri);
g_free (uri);
}
#endif
location = nautilus_file_get_location (file);
g_file_enumerate_children_async (location,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
0, /* flags */
......@@ -4079,6 +4123,147 @@ mount_start (NautilusDirectory *directory,
g_object_unref (location);
}
static void
filesystem_info_cancel (NautilusDirectory *directory)
{
if (directory->details->filesystem_info_state != NULL) {
g_cancellable_cancel (directory->details->filesystem_info_state->cancellable);
directory->details->filesystem_info_state->directory = NULL;
directory->details->filesystem_info_state = NULL;
async_job_end (directory, "filesystem info");
}
}
static void
filesystem_info_stop (NautilusDirectory *directory)
{
NautilusFile *file;
if (directory->details->filesystem_info_state != NULL) {
file = directory->details->filesystem_info_state->file;
if (file != NULL) {
g_assert (NAUTILUS_IS_FILE (file));
g_assert (file->details->directory == directory);
if (is_needy (file,
lacks_filesystem_info,
wants_filesystem_info)) {
return;
}
}
/* The filesystem info is not wanted, so stop it. */
filesystem_info_cancel (directory);
}
}
static void
filesystem_info_state_free (FilesystemInfoState *state)
{
g_object_unref (state->cancellable);
g_free (state);
}
static void
got_filesystem_info (FilesystemInfoState *state, GFileInfo *info)
{
NautilusDirectory *directory;
NautilusFile *file;
/* careful here, info may be NULL */
directory = nautilus_directory_ref (state->directory);
state->directory->details->filesystem_info_state = NULL;
async_job_end (state->directory, "filesystem info");
file = nautilus_file_ref (state->file);
file->details->filesystem_info_is_up_to_date = TRUE;
if (info != NULL) {
file->details->filesystem_use_preview =
g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW);
file->details->filesystem_readonly =
g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
}
nautilus_directory_async_state_changed (directory);
nautilus_file_changed (file);
nautilus_file_unref (file);
nautilus_directory_unref (directory);
filesystem_info_state_free (state);
}
static void
query_filesystem_info_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GFileInfo *info;
FilesystemInfoState *state;
state = user_data;
if (state->directory == NULL) {
/* Operation was cancelled. Bail out */
filesystem_info_state_free (state);
return;
}
info = g_file_query_filesystem_info_finish (G_FILE (source_object), res, NULL);
got_filesystem_info (state, info);
if (info != NULL) {
g_object_unref (info);
}
}
static void
filesystem_info_start (NautilusDirectory *directory,
NautilusFile *file,
gboolean *doing_io)
{
GFile *location;
FilesystemInfoState *state;
if (directory->details->filesystem_info_state != NULL) {
*doing_io = TRUE;
return;
}
if (!is_needy (file,
lacks_filesystem_info,
wants_filesystem_info)) {
return;
}
*doing_io = TRUE;
if (!async_job_start (directory, "filesystem info")) {
return;
}
state = g_new0 (FilesystemInfoState, 1);
state->directory = directory;
state->file = file;
state->cancellable = g_cancellable_new ();
location = nautilus_file_get_location (file);
directory->details->filesystem_info_state = state;
g_file_query_filesystem_info_async (location,
G_FILE_ATTRIBUTE_FILESYSTEM_READONLY ","
G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW,
G_PRIORITY_DEFAULT,
state->cancellable,
query_filesystem_info_callback,
state);
g_object_unref (location);
}
static void
extension_info_cancel (NautilusDirectory *directory)
{
......@@ -4257,6 +4442,7 @@ start_or_stop_io (NautilusDirectory *directory)
extension_info_stop (directory);
mount_stop (directory);
thumbnail_stop (directory);
filesystem_info_stop (directory);
doing_io = FALSE;
/* Take files that are all done off the queue. */
......@@ -4285,6 +4471,7 @@ start_or_stop_io (NautilusDirectory *directory)
mime_list_start (directory, file, &doing_io);
top_left_start (directory, file, &doing_io);
thumbnail_start (directory, file, &doing_io);
filesystem_info_start (directory, file, &doing_io);
if (doing_io) {
return;
......@@ -4356,6 +4543,7 @@ nautilus_directory_cancel (NautilusDirectory *directory)
extension_info_cancel (directory);
thumbnail_cancel (directory);
mount_cancel (directory);
filesystem_info_cancel (directory);
/* We aren't waiting for anything any more. */
if (waiting_directories != NULL) {
......@@ -4434,6 +4622,16 @@ cancel_mount_for_file (NautilusDirectory *directory,
}
}
static void
cancel_filesystem_info_for_file (NautilusDirectory *directory,
NautilusFile *file)
{
if (directory->details->filesystem_info_state != NULL &&
directory->details->filesystem_info_state->file == file) {
filesystem_info_cancel (directory);
}
}
static void
cancel_link_info_for_file (NautilusDirectory *directory,
NautilusFile *file)
......@@ -4469,6 +4667,9 @@ cancel_loading_attributes (NautilusDirectory *directory,
if (request.file_info) {
file_info_cancel (directory);
}
if (request.filesystem_info) {
filesystem_info_cancel (directory);
}
if (request.link_info) {
link_info_cancel (directory);
}
......@@ -4518,6 +4719,9 @@ nautilus_directory_cancel_loading_file_attributes (NautilusDirectory *direc
if (request.file_info) {
cancel_file_info_for_file (directory, file);
}
if (request.filesystem_info) {
cancel_filesystem_info_for_file (directory, file);
}
if (request.link_info) {
cancel_link_info_for_file (directory, file);
}
......
......@@ -44,6 +44,7 @@ typedef struct NewFilesState NewFilesState;
typedef struct MimeListState MimeListState;
typedef struct ThumbnailState ThumbnailState;
typedef struct MountState MountState;
typedef struct FilesystemInfoState FilesystemInfoState;
struct NautilusDirectoryDetails
{
......@@ -106,6 +107,8 @@ struct NautilusDirectoryDetails
ThumbnailState *thumbnail_state;
MountState *mount_state;
FilesystemInfoState *filesystem_info_state;
TopLeftTextReadState *top_left_read_state;
......@@ -130,6 +133,7 @@ typedef struct {
gboolean extension_info;
gboolean thumbnail;
gboolean mount;
gboolean filesystem_info;
} Request;
NautilusDirectory *nautilus_directory_get_existing (GFile *location);
......
......@@ -1240,7 +1240,7 @@ collect_directories_by_container (gpointer key, gpointer value, gpointer callbac
directory = NAUTILUS_DIRECTORY (value);
collect_data = (CollectData *) callback_data;
if (g_file_contains_file (collect_data->container, location) ||
if (g_file_has_prefix (location, collect_data->container) ||
g_file_equal (collect_data->container, location)) {
nautilus_directory_ref (directory);
collect_data->directories =
......
......@@ -431,7 +431,7 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
/* Compare the first dropped uri with the target uri for same fs match. */
dropped = g_file_new_for_uri (dropped_uri);
same_fs = check_same_fs (target, dropped);
target_is_source_parent = g_file_contains_file (target, dropped);
target_is_source_parent = g_file_has_prefix (dropped, target);
if (same_fs || target_is_source_parent ||
g_file_has_uri_scheme (dropped, "trash")) {
......
......@@ -41,6 +41,7 @@ typedef enum {
NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO = 1 << 8,
NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL = 1 << 9,
NAUTILUS_FILE_ATTRIBUTE_MOUNT = 1 << 10,
NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO = 1 << 11,
} NautilusFileAttributes;
#endif /* NAUTILUS_FILE_ATTRIBUTES_H */
......@@ -2040,7 +2040,6 @@ 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, 0, mount_op, NULL, volume_mount_cb, mount_op);
}
......
......@@ -206,6 +206,10 @@ struct NautilusFileDetails
eel_boolean_bit can_mount : 1;
eel_boolean_bit can_unmount : 1;
eel_boolean_bit can_eject : 1;
eel_boolean_bit filesystem_readonly : 1;
eel_boolean_bit filesystem_use_preview : 2; /* GFilesystemPreviewType */
eel_boolean_bit filesystem_info_is_up_to_date : 1;
};
typedef struct {
......
......@@ -3199,10 +3199,30 @@ mimetype_limited_by_size (const char *mime_type)
return FALSE;
}
GFilesystemPreviewType
nautilus_file_get_filesystem_use_preview (NautilusFile *file)
{
GFilesystemPreviewType use_preview;
NautilusFile *parent;
parent = nautilus_file_get_parent (file);
if (parent != NULL) {
use_preview = parent->details->filesystem_use_preview;
g_object_unref (parent);
} else {
use_preview = 0;
}
return use_preview;
}
gboolean
nautilus_file_should_show_thumbnail (NautilusFile *file)
{
const char *mime_type;
GFilesystemPreviewType use_preview;
use_preview = nautilus_file_get_filesystem_use_preview (file);
mime_type = eel_ref_str_peek (file->details->mime_type);
if (mime_type == NULL) {
......@@ -3213,14 +3233,26 @@ nautilus_file_should_show_thumbnail (NautilusFile *file)
nautilus_file_get_size (file) > (unsigned int)cached_thumbnail_limit) {
return FALSE;
}
if (show_image_thumbs == NAUTILUS_SPEED_TRADEOFF_ALWAYS) {
return TRUE;
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
return FALSE;
} else {
return TRUE;
}
} else if (show_image_thumbs == NAUTILUS_SPEED_TRADEOFF_NEVER) {
return FALSE;
} else {
/* only local files */
return nautilus_file_is_local (file);
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
/* file system says to never thumbnail anything */
return FALSE;
} else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL) {
/* file system says we should treat file as if it's local */
return TRUE;
} else {
/* only local files */
return nautilus_file_is_local (file);
}
}
return FALSE;
......@@ -3715,10 +3747,18 @@ show_directory_item_count_changed_callback (gpointer callback_data)
static gboolean
get_speed_tradeoff_preference_for_file (NautilusFile *file, NautilusSpeedTradeoffValue value)
{
GFilesystemPreviewType use_preview;
g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
use_preview = nautilus_file_get_filesystem_use_preview (file);
if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) {
return TRUE;
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
return FALSE;
} else {
return TRUE;
}
}
if (value == NAUTILUS_SPEED_TRADEOFF_NEVER) {
......@@ -3726,7 +3766,17 @@ get_speed_tradeoff_preference_for_file (NautilusFile *file, NautilusSpeedTradeof
}
g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
return nautilus_file_is_local (file);
if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
/* file system says to never preview anything */
return FALSE;
} else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL) {
/* file system says we should treat file as if it's local */
return TRUE;
} else {
/* only local files */
return nautilus_file_is_local (file);
}
}
gboolean
......
......@@ -218,6 +218,7 @@ void nautilus_file_set_attributes (Nautilu
GFileInfo *attributes,
NautilusFileOperationCallback callback,
gpointer callback_data);
GFilesystemPreviewType nautilus_file_get_filesystem_use_preview (NautilusFile *file);
/* Permissions. */
gboolean nautilus_file_can_get_permissions (NautilusFile *file);
......
......@@ -7552,7 +7552,9 @@ load_directory (FMDirectoryView *view,
* well as doing a call when ready), in case external forces
* change the directory's file metadata.
*/
attributes = NAUTILUS_FILE_ATTRIBUTE_METADATA;
attributes =
NAUTILUS_FILE_ATTRIBUTE_METADATA |
NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
view->details->metadata_for_directory_as_file_pending = TRUE;
view->details->metadata_for_files_in_directory_pending = TRUE;
nautilus_file_call_when_ready
......@@ -7568,7 +7570,9 @@ load_directory (FMDirectoryView *view,
/* If capabilities change, then we need to update the menus
* because of New Folder, and relative emblems.
*/
attributes = NAUTILUS_FILE_ATTRIBUTE_INFO;
attributes =
NAUTILUS_FILE_ATTRIBUTE_INFO |
NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
nautilus_file_monitor_add (view->details->directory_as_file,