aboutsummaryrefslogtreecommitdiff
path: root/fiv-browser.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-30 21:47:28 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-30 22:32:29 +0100
commit380ddd540bd93850e4df254200cba5b1fdf05cc6 (patch)
tree3730d9cc0b3150b9084b612014554ab39ace8b15 /fiv-browser.c
parent8b232dc44464a70b53c3b6e1616de21b52e13e67 (diff)
downloadfiv-380ddd540bd93850e4df254200cba5b1fdf05cc6.tar.gz
fiv-380ddd540bd93850e4df254200cba5b1fdf05cc6.tar.xz
fiv-380ddd540bd93850e4df254200cba5b1fdf05cc6.zip
Convert all loading to use GFile
Now we're able to make use of GVfs, with some caveats.
Diffstat (limited to 'fiv-browser.c')
-rw-r--r--fiv-browser.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/fiv-browser.c b/fiv-browser.c
index 8296e67..39e2528 100644
--- a/fiv-browser.c
+++ b/fiv-browser.c
@@ -48,7 +48,7 @@ struct _FivBrowser {
int item_height; ///< Thumbnail height in pixels
int item_spacing; ///< Space between items in pixels
- char *path; ///< Current path
+ char *uri; ///< Current URI
GArray *entries; ///< []Entry
GArray *layouted_rows; ///< []Row
int selected;
@@ -502,9 +502,9 @@ thumbnailer_next(FivBrowser *self)
const Entry *entry = link->data;
GFile *file = g_file_new_for_uri(entry->uri);
- gchar *path = g_file_get_path(file);
+ gchar *uri = g_file_get_uri(file);
g_object_unref(file);
- if (!path) {
+ if (!uri) {
// TODO(p): Support thumbnailing non-local URIs in some manner.
self->thumbnail_queue = g_list_delete_link(self->thumbnail_queue, link);
return;
@@ -513,9 +513,9 @@ thumbnailer_next(FivBrowser *self)
GError *error = NULL;
self->thumbnailer = g_subprocess_new(G_SUBPROCESS_FLAGS_NONE, &error,
PROJECT_NAME, "--thumbnail",
- fiv_thumbnail_sizes[self->item_size].thumbnail_spec_name, "--", path,
+ fiv_thumbnail_sizes[self->item_size].thumbnail_spec_name, "--", uri,
NULL);
- g_free(path);
+ g_free(uri);
if (error) {
g_warning("%s", error->message);
g_error_free(error);
@@ -550,7 +550,7 @@ thumbnailer_start(FivBrowser *self)
gchar *thumbnails_dir = fiv_thumbnail_get_root();
GFile *thumbnails = g_file_new_for_path(thumbnails_dir);
g_free(thumbnails_dir);
- GFile *current = g_file_new_for_path(self->path);
+ GFile *current = g_file_new_for_uri(self->uri);
gboolean is_a_thumbnail = g_file_has_prefix(current, thumbnails);
g_object_unref(current);
g_object_unref(thumbnails);
@@ -759,7 +759,7 @@ fiv_browser_finalize(GObject *gobject)
{
FivBrowser *self = FIV_BROWSER(gobject);
thumbnailer_abort(self);
- g_free(self->path);
+ g_free(self->uri);
g_array_free(self->entries, TRUE);
g_array_free(self->layouted_rows, TRUE);
cairo_surface_destroy(self->glow);
@@ -940,9 +940,7 @@ fiv_browser_button_press_event(GtkWidget *widget, GdkEventButton *event)
const Entry *entry = entry_at(self, event->x, event->y);
if (!entry && event->button == GDK_BUTTON_SECONDARY) {
- gchar *uri = g_filename_to_uri(self->path, NULL, NULL);
- show_context_menu(widget, uri);
- g_free(uri);
+ show_context_menu(widget, self->uri);
return TRUE;
}
if (!entry)
@@ -1175,22 +1173,27 @@ entry_compare(gconstpointer a, gconstpointer b)
void
fiv_browser_load(
- FivBrowser *self, FivBrowserFilterCallback cb, const char *path)
+ FivBrowser *self, FivBrowserFilterCallback cb, const char *uri)
{
g_return_if_fail(FIV_IS_BROWSER(self));
thumbnailer_abort(self);
g_array_set_size(self->entries, 0);
g_array_set_size(self->layouted_rows, 0);
- g_clear_pointer(&self->path, g_free);
+ g_clear_pointer(&self->uri, g_free);
+
+ GFile *file = g_file_new_for_uri((self->uri = g_strdup(uri)));
- GFile *file = g_file_new_for_path((self->path = g_strdup(path)));
+ GError *error = NULL;
GFileEnumerator *enumerator = g_file_enumerate_children(file,
G_FILE_ATTRIBUTE_STANDARD_NAME "," G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
g_object_unref(file);
- if (!enumerator)
+ if (!enumerator) {
+ // Note that this has had a side-effect of clearing all entries.
+ g_error_free(error);
return;
+ }
while (TRUE) {
GFileInfo *info = NULL;