Beispiel #1
0
static void
vfs_file_set_metadata_as_list (NautilusFile  *file,
                               const char    *key,
                               char         **value)
{
    GFile *location;
    GFileInfo *info;
    char *gio_key;

    info = g_file_info_new ();

    gio_key = g_strconcat ("metadata::", key, NULL);
    g_file_info_set_attribute_stringv (info, gio_key, value);
    g_free (gio_key);

    location = nautilus_file_get_location (file);
    g_file_set_attributes_async (location,
                                 info,
                                 0,
                                 G_PRIORITY_DEFAULT,
                                 NULL,
                                 set_metadata_callback,
                                 nautilus_file_ref (file));
    g_object_unref (info);
    g_object_unref (location);
}
Beispiel #2
0
static void
vfs_file_stop (NautilusFile                  *file,
               GMountOperation               *mount_op,
               GCancellable                  *cancellable,
               NautilusFileOperationCallback  callback,
               gpointer                       callback_data)
{
    NautilusFileOperation *op;
    GFile *location;

    op = nautilus_file_operation_new (file, callback, callback_data);
    if (cancellable)
    {
        g_object_unref (op->cancellable);
        op->cancellable = g_object_ref (cancellable);
    }

    location = nautilus_file_get_location (file);
    g_file_stop_mountable (location,
                           G_MOUNT_UNMOUNT_NONE,
                           mount_op,
                           op->cancellable,
                           vfs_file_stop_callback,
                           op);
    g_object_unref (location);
}
static void
ensure_dirs_task_ready_cb (GObject *_source,
			   GAsyncResult *res,
			   gpointer user_data)
{
	NautilusFile *original_dir;
	GFile *original_dir_location;
	GList *original_dirs, *files, *locations, *l;
	RestoreFilesData *data = user_data;

	original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
	for (l = original_dirs; l != NULL; l = l->next) {
		original_dir = NAUTILUS_FILE (l->data);
		original_dir_location = nautilus_file_get_location (original_dir);

		files = g_hash_table_lookup (data->original_dirs_hash, original_dir);
		locations = locations_from_file_list (files);

		nautilus_file_operations_move
			(locations, NULL,
			 original_dir_location,
			 data->parent_window,
			 NULL, NULL);

		g_list_free_full (locations, g_object_unref);
		g_object_unref (original_dir_location);
	}

	g_list_free (original_dirs);

	g_hash_table_unref (data->original_dirs_hash);
	g_slice_free (RestoreFilesData, data);
}
gboolean
nautilus_file_selection_equal (GList *selection_a,
			       GList *selection_b)
{
	GList *al, *bl;
	gboolean selection_matches;

	if (selection_a == NULL || selection_b == NULL) {
		return (selection_a == selection_b);
	}

	if (g_list_length (selection_a) != g_list_length (selection_b)) {
		return FALSE;
	}

	selection_matches = TRUE;

	for (al = selection_a; al; al = al->next) {
		GFile *a_location = nautilus_file_get_location (NAUTILUS_FILE (al->data));
		gboolean found = FALSE;

		for (bl = selection_b; bl; bl = bl->next) {
			GFile *b_location = nautilus_file_get_location (NAUTILUS_FILE (bl->data));
			found = g_file_equal (b_location, a_location);
			g_object_unref (b_location);

			if (found) {
				break;
			}
		}

		selection_matches = found;
		g_object_unref (a_location);

		if (!selection_matches) {
			break;
		}
	}

	return selection_matches;
}
void
nautilus_restore_files_from_trash (GList *files,
                                   GtkWindow *parent_window)
{
    NautilusFile *file, *original_dir;
    GHashTable *original_dirs_hash;
    GList *original_dirs, *unhandled_files;
    GFile *original_dir_location;
    GList *locations, *l;
    char *message, *file_name;

    original_dirs_hash = nautilus_trashed_files_get_original_directories (files, &unhandled_files);

    for (l = unhandled_files; l != NULL; l = l->next) {
        file = NAUTILUS_FILE (l->data);
        file_name = nautilus_file_get_display_name (file);
        message = g_strdup_printf (_("Could not determine original location of \"%s\" "), file_name);
        g_free (file_name);

        eel_show_warning_dialog (message,
                                 _("The item cannot be restored from trash"),
                                 parent_window);
        g_free (message);
    }

    if (original_dirs_hash != NULL) {
        original_dirs = g_hash_table_get_keys (original_dirs_hash);
        for (l = original_dirs; l != NULL; l = l->next) {
            original_dir = NAUTILUS_FILE (l->data);
            original_dir_location = nautilus_file_get_location (original_dir);

            files = g_hash_table_lookup (original_dirs_hash, original_dir);
            locations = locations_from_file_list (files);

            nautilus_file_operations_move
            (locations, NULL,
             original_dir_location,
             parent_window,
             NULL, NULL);

            g_list_free_full (locations, g_object_unref);
            g_object_unref (original_dir_location);
        }

        g_list_free (original_dirs);
        g_hash_table_destroy (original_dirs_hash);
    }

    nautilus_file_list_unref (unhandled_files);
}
static GList *
locations_from_file_list (GList *file_list)
{
    NautilusFile *file;
    GList *l, *ret;

    ret = NULL;

    for (l = file_list; l != NULL; l = l->next) {
        file = NAUTILUS_FILE (l->data);
        ret = g_list_prepend (ret, nautilus_file_get_location (file));
    }

    return g_list_reverse (ret);
}
Beispiel #7
0
static void
vfs_file_poll_for_media (NautilusFile *file)
{
    NautilusFileOperation *op;
    GFile *location;

    op = nautilus_file_operation_new (file, NULL, NULL);

    location = nautilus_file_get_location (file);
    g_file_poll_mountable (location,
                           op->cancellable,
                           vfs_file_poll_callback,
                           op);
    g_object_unref (location);
}
static void
xdg_dir_changed (NautilusFile *file,
                 XdgDirEntry *dir)
{
    GFile *location, *dir_location;
    char *path;

    location = nautilus_file_get_location (file);
    dir_location = g_file_new_for_path (dir->path);
    if (!g_file_equal (location, dir_location)) {
        path = g_file_get_path (location);

        if (path) {
            char *argv[5];
            int i;

            g_free (dir->path);
            dir->path = path;

            i = 0;
            argv[i++] = "xdg-user-dirs-update";
            argv[i++] = "--set";
            argv[i++] = dir->type;
            argv[i++] = dir->path;
            argv[i++] = NULL;

            /* We do this sync, to avoid possible race-conditions
               if multiple dirs change at the same time. Its
               blocking the main thread, but these updates should
               be very rare and very fast. */
            g_spawn_sync (NULL,
                          argv, NULL,
                          G_SPAWN_SEARCH_PATH |
                          G_SPAWN_STDOUT_TO_DEV_NULL |
                          G_SPAWN_STDERR_TO_DEV_NULL,
                          NULL, NULL,
                          NULL, NULL, NULL, NULL);
            g_reload_user_special_dirs_cache ();
            schedule_user_dirs_changed ();
            desktop_dir_changed ();
            /* Icon might have changed */
            nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_INFO);
        }
    }
    g_object_unref (location);
    g_object_unref (dir_location);
}
static void
bookmark_file_changed_callback (NautilusFile *file,
				NautilusBookmark *bookmark)
{
	GFile *location;

	g_assert (file == bookmark->details->file);

	DEBUG ("%s: file changed", nautilus_bookmark_get_name (bookmark));

	location = nautilus_file_get_location (file);

	if (!g_file_equal (bookmark->details->location, location) &&
	    !nautilus_file_is_in_trash (file)) {
		DEBUG ("%s: file got moved", nautilus_bookmark_get_name (bookmark));

		g_object_unref (bookmark->details->location);
		bookmark->details->location = g_object_ref (location);

		g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]);
		g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
	}

	g_object_unref (location);

	if (nautilus_file_is_gone (file) ||
	    nautilus_file_is_in_trash (file)) {
		/* The file we were monitoring has been trashed, deleted,
		 * or moved in a way that we didn't notice. We should make 
		 * a spanking new NautilusFile object for this 
		 * location so if a new file appears in this place 
		 * we will notice. However, we can't immediately do so
		 * because creating a new NautilusFile directly as a result
		 * of noticing a file goes away may trigger i/o on that file
		 * again, noticeing it is gone, leading to a loop.
		 * So, the new NautilusFile is created when the bookmark
		 * is used again. However, this is not really a problem, as
		 * we don't want to change the icon or anything about the
		 * bookmark just because its not there anymore.
		 */
		DEBUG ("%s: trashed", nautilus_bookmark_get_name (bookmark));
		nautilus_bookmark_disconnect_file (bookmark);
	} else {
		bookmark_set_name_from_ready_file (bookmark, file);
	}
}
static void
switch_location (NautilusDragSlotProxyInfo *drag_info)
{
    GFile *location;
    GtkWidget *window;

    if (drag_info->target_file == NULL) {
        return;
    }

    window = gtk_widget_get_toplevel (drag_info->widget);
    g_assert (NAUTILUS_IS_WINDOW (window));

    location = nautilus_file_get_location (drag_info->target_file);
    nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
            location, NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
            NULL, NAUTILUS_WINDOW (window), NULL);
    g_object_unref (location);
}
Beispiel #11
0
static void
vfs_file_start (NautilusFile                  *file,
                GMountOperation               *mount_op,
                GCancellable                  *cancellable,
                NautilusFileOperationCallback  callback,
                gpointer                       callback_data)
{
    NautilusFileOperation *op;
    GError *error;
    GFile *location;

    if (file->details->type != G_FILE_TYPE_MOUNTABLE)
    {
        if (callback)
        {
            error = NULL;
            g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                 _("This file cannot be started"));
            callback (file, NULL, error, callback_data);
            g_error_free (error);
        }
        return;
    }

    op = nautilus_file_operation_new (file, callback, callback_data);
    if (cancellable)
    {
        g_object_unref (op->cancellable);
        op->cancellable = g_object_ref (cancellable);
    }

    location = nautilus_file_get_location (file);
    g_file_start_mountable (location,
                            0,
                            mount_op,
                            op->cancellable,
                            vfs_file_start_callback,
                            op);
    g_object_unref (location);
}
static void
ensure_dirs_task_thread_func (GTask *task,
			      gpointer source,
			      gpointer task_data,
			      GCancellable *cancellable)
{
	RestoreFilesData *data = task_data;
	NautilusFile *original_dir;
	GFile *original_dir_location;
	GList *original_dirs, *l;

	original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
	for (l = original_dirs; l != NULL; l = l->next) {
		original_dir = NAUTILUS_FILE (l->data);
		original_dir_location = nautilus_file_get_location (original_dir);

		g_file_make_directory_with_parents (original_dir_location, cancellable, NULL);
		g_object_unref (original_dir_location);
	}

	g_task_return_pointer (task, NULL, NULL);
}
Beispiel #13
0
static void
vfs_file_set_metadata (NautilusFile *file,
                       const char   *key,
                       const char   *value)
{
    GFileInfo *info;
    GFile *location;
    char *gio_key;

    info = g_file_info_new ();

    gio_key = g_strconcat ("metadata::", key, NULL);
    if (value != NULL)
    {
        g_file_info_set_attribute_string (info, gio_key, value);
    }
    else
    {
        /* Unset the key */
        g_file_info_set_attribute (info, gio_key,
                                   G_FILE_ATTRIBUTE_TYPE_INVALID,
                                   NULL);
    }
    g_free (gio_key);

    location = nautilus_file_get_location (file);
    g_file_set_attributes_async (location,
                                 info,
                                 0,
                                 G_PRIORITY_DEFAULT,
                                 NULL,
                                 set_metadata_callback,
                                 nautilus_file_ref (file));
    g_object_unref (location);
    g_object_unref (info);
}