aboutsummaryrefslogtreecommitdiff
path: root/fiv-browser.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-browser.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-browser.c')
-rw-r--r--fiv-browser.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/fiv-browser.c b/fiv-browser.c
index 3edcf4a..c4475a7 100644
--- a/fiv-browser.c
+++ b/fiv-browser.c
@@ -29,6 +29,7 @@
#endif // GDK_WINDOWING_QUARTZ
#include "fiv-browser.h"
+#include "fiv-collection.h"
#include "fiv-context-menu.h"
#include "fiv-io.h"
#include "fiv-thumbnail.h"
@@ -102,6 +103,7 @@ static cairo_user_data_key_t fiv_browser_key_mtime_msec;
struct entry {
gchar *uri; ///< GIO URI
+ gchar *target_uri; ///< GIO URI for any target
gint64 mtime_msec; ///< Modification time in milliseconds
cairo_surface_t *thumbnail; ///< Prescaled thumbnail
GIcon *icon; ///< If no thumbnail, use this icon
@@ -111,6 +113,7 @@ static void
entry_free(Entry *self)
{
g_free(self->uri);
+ g_free(self->target_uri);
g_clear_pointer(&self->thumbnail, cairo_surface_destroy);
g_clear_object(&self->icon);
}
@@ -437,6 +440,17 @@ rescale_thumbnail(cairo_surface_t *thumbnail, double row_height)
return scaled;
}
+static char *
+entry_system_wide_uri(const Entry *self)
+{
+ // "recent" and "trash", e.g., also have "standard::target-uri" set,
+ // but we'd like to avoid saving their thumbnails.
+ if (self->target_uri && fiv_collection_uri_matches(self->uri))
+ return self->target_uri;
+
+ return self->uri;
+}
+
static void
entry_add_thumbnail(gpointer data, gpointer user_data)
{
@@ -456,7 +470,7 @@ entry_add_thumbnail(gpointer data, gpointer user_data)
// unnecessarily; we might also shift the concern there).
} else {
cairo_surface_t *found = fiv_thumbnail_lookup(
- self->uri, self->mtime_msec, browser->item_size);
+ entry_system_wide_uri(self), self->mtime_msec, browser->item_size);
self->thumbnail = rescale_thumbnail(found, browser->item_height);
}
@@ -589,7 +603,8 @@ thumbnailer_reprocess_entry(FivBrowser *self, GBytes *output, Entry *entry)
g_list_append(self->thumbnailers_queue, entry);
}
- // This choice of mtime favours unnecessary thumbnail reloading.
+ // This choice of mtime favours unnecessary thumbnail reloading
+ // over retaining stale data.
cairo_surface_set_user_data(entry->thumbnail,
&fiv_browser_key_mtime_msec, (void *) (intptr_t) entry->mtime_msec,
NULL);
@@ -663,12 +678,13 @@ thumbnailer_next(Thumbnailer *t)
// - We've found one, but we're not quite happy with it:
// always run the full process for a high-quality wide thumbnail.
// - We can't end up here in any other cases.
+ const char *uri = entry_system_wide_uri(t->target);
const char *argv_faster[] = {PROJECT_NAME, "--extract-thumbnail",
"--thumbnail", fiv_thumbnail_sizes[self->item_size].thumbnail_spec_name,
- "--", t->target->uri, NULL};
+ "--", uri, NULL};
const char *argv_slower[] = {PROJECT_NAME,
"--thumbnail", fiv_thumbnail_sizes[self->item_size].thumbnail_spec_name,
- "--", t->target->uri, NULL};
+ "--", uri, NULL};
GError *error = NULL;
t->minion = g_subprocess_newv(t->target->icon ? argv_faster : argv_slower,
@@ -1259,7 +1275,7 @@ fiv_browser_drag_data_get(GtkWidget *widget,
FivBrowser *self = FIV_BROWSER(widget);
if (self->selected) {
(void) gtk_selection_data_set_uris(
- data, (gchar *[]){self->selected->uri, NULL});
+ data, (gchar *[]) {entry_system_wide_uri(self->selected), NULL});
}
}
@@ -1466,10 +1482,9 @@ fiv_browser_query_tooltip(GtkWidget *widget, gint x, gint y,
return FALSE;
GFile *file = g_file_new_for_uri(entry->uri);
- GFileInfo *info = g_file_query_info(file,
- G_FILE_ATTRIBUTE_STANDARD_NAME
- "," G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ GFileInfo *info =
+ g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE, NULL, NULL);
g_object_unref(file);
if (!info)
return FALSE;
@@ -1740,8 +1755,11 @@ on_model_files_changed(FivIoModel *model, FivBrowser *self)
gsize len = 0;
const FivIoModelEntry *files = fiv_io_model_get_files(self->model, &len);
for (gsize i = 0; i < len; i++) {
- g_array_append_val(self->entries, ((Entry) {.thumbnail = NULL,
- .uri = g_strdup(files[i].uri), .mtime_msec = files[i].mtime_msec}));
+ Entry e = {.thumbnail = NULL,
+ .uri = g_strdup(files[i].uri),
+ .target_uri = g_strdup(files[i].target_uri),
+ .mtime_msec = files[i].mtime_msec};
+ g_array_append_val(self->entries, e);
}
fiv_browser_select(self, selected_uri);