aboutsummaryrefslogtreecommitdiff
path: root/fiv-sidebar.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-07-28 00:37:36 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-08 18:06:50 +0200
commit701846ab398371de5a921b1a561bcc1601cd8297 (patch)
tree04f5a765e0783f403b90e97ac6f6edb058b61e49 /fiv-sidebar.c
parent4927c8c6923991ae68db21e66749c1fb99240b08 (diff)
downloadfiv-701846ab398371de5a921b1a561bcc1601cd8297.tar.gz
fiv-701846ab398371de5a921b1a561bcc1601cd8297.tar.xz
fiv-701846ab398371de5a921b1a561bcc1601cd8297.zip
Support opening collections of files
Implement a process-local VFS to enable grouping together arbitrary URIs passed via program arguments, DnD, or the file open dialog. This VFS contains FivCollectionFile objects, which act as "simple" proxies over arbitrary GFiles. Their true URIs may be retrieved through the "standard::target-uri" attribute, in a similar way to GVfs's "recent" and "trash" backends. (The main reason we proxy rather than just hackishly return foreign GFiles from the VFS is that loading them would switch the current directory, and break iteration as a result. We could also keep the collection outside of GVfs, but that would result in considerable special-casing, and the author wouldn't gain intimate knowledge of GIO.) There is no perceived need to keep old collections when opening new ones, so we simply change and reload the contents when needed. Similarly, there is no intention to make the VFS writeable. The process-locality of this and other URI schemes has proven to be rather annoying when passing files to other applications, however most of the resulting complexity appears to be essential rather than accidental. Note that the GTK+ file chooser widget is retarded, and doesn't recognize URIs that lack the authority part in the location bar.
Diffstat (limited to 'fiv-sidebar.c')
-rw-r--r--fiv-sidebar.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/fiv-sidebar.c b/fiv-sidebar.c
index bc83649..fc63a99 100644
--- a/fiv-sidebar.c
+++ b/fiv-sidebar.c
@@ -17,6 +17,7 @@
#include <gtk/gtk.h>
+#include "fiv-collection.h"
#include "fiv-context-menu.h"
#include "fiv-io.h"
#include "fiv-sidebar.h"
@@ -296,15 +297,48 @@ create_row(FivSidebar *self, GFile *file, const char *icon_name)
}
static void
+on_update_task(GTask *task, G_GNUC_UNUSED gpointer source_object,
+ G_GNUC_UNUSED gpointer task_data, G_GNUC_UNUSED GCancellable *cancellable)
+{
+ g_task_return_boolean(task, TRUE);
+}
+
+static void
+on_update_task_done(GObject *source_object, G_GNUC_UNUSED GAsyncResult *res,
+ G_GNUC_UNUSED gpointer user_data)
+{
+ FivSidebar *self = FIV_SIDEBAR(source_object);
+ gtk_places_sidebar_set_location(
+ self->places, fiv_io_model_get_location(self->model));
+}
+
+static void
update_location(FivSidebar *self)
{
GFile *location = fiv_io_model_get_location(self->model);
- if (!location)
- return;
+
+ GFile *collection = g_file_new_for_uri(FIV_COLLECTION_SCHEME ":/");
+ gtk_places_sidebar_remove_shortcut(self->places, collection);
+ if (location && g_file_has_uri_scheme(location, FIV_COLLECTION_SCHEME)) {
+ // add_shortcut() asynchronously requests GFileInfo, and only fills in
+ // the new row's "uri" data field once that's finished, resulting in
+ // the immediate set_location() call below failing to find it.
+ gtk_places_sidebar_add_shortcut(self->places, collection);
+
+ // Queue up a callback using the same mechanism that GFile uses.
+ GTask *task = g_task_new(self, NULL, on_update_task_done, NULL);
+ g_task_set_name(task, __func__);
+ g_task_set_priority(task, G_PRIORITY_LOW);
+ g_task_run_in_thread(task, on_update_task);
+ g_object_unref(task);
+ }
+ g_object_unref(collection);
gtk_places_sidebar_set_location(self->places, location);
gtk_container_foreach(GTK_CONTAINER(self->listbox),
(GtkCallback) gtk_widget_destroy, NULL);
+ if (!location)
+ return;
GFile *iter = g_object_ref(location);
GtkWidget *row = NULL;