From 5f8dc88fa715563c3abb8ed0d8ae5d2736f7a1a9 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Thu, 30 Dec 2021 22:52:23 +0100 Subject: Minor URL-related fix-ups --- fastiv.c | 25 +++++++++++++------------ fiv-browser.c | 16 +++------------- fiv-sidebar.c | 1 + fiv-thumbnail.c | 5 ++++- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/fastiv.c b/fastiv.c index 88dd764..5aa183f 100644 --- a/fastiv.c +++ b/fastiv.c @@ -319,14 +319,19 @@ show_error_dialog(GError *error) } static void -switch_to_browser(void) +set_window_title(const char *uri) { - // TODO(p): Use g_file_get_parse_name() or something. - GFile *file = g_file_new_for_uri(g.directory); - const char *path = g_file_peek_path(file); - gtk_window_set_title(GTK_WINDOW(g.window), path ? path : g.directory); + GFile *file = g_file_new_for_uri(uri); + gchar *name = g_file_get_parse_name(file); + gtk_window_set_title(GTK_WINDOW(g.window), name); + g_free(name); g_object_unref(file); +} +static void +switch_to_browser(void) +{ + set_window_title(g.directory); gtk_stack_set_visible_child(GTK_STACK(g.stack), g.browser_paned); gtk_widget_grab_focus(g.browser_scroller); } @@ -334,12 +339,7 @@ switch_to_browser(void) static void switch_to_view(const char *uri) { - // TODO(p): Use g_file_get_parse_name() or something. - GFile *file = g_file_new_for_uri(uri); - const char *path = g_file_peek_path(file); - gtk_window_set_title(GTK_WINDOW(g.window), path ? path : uri); - g_object_unref(file); - + set_window_title(uri); gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view_box); gtk_widget_grab_focus(g.view); } @@ -451,8 +451,9 @@ load_directory(const gchar *uri) g_ptr_array_sort(g.files, files_compare); update_files_index(); + } else if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) { + g_error_free(error); } else { - // TODO(p): Handle "Operation not supported" silently. show_error_dialog(error); } g_object_unref(file); diff --git a/fiv-browser.c b/fiv-browser.c index 39e2528..d426454 100644 --- a/fiv-browser.c +++ b/fiv-browser.c @@ -488,7 +488,6 @@ on_thumbnailer_ready(GObject *object, GAsyncResult *res, gpointer user_data) if (succeeded) thumbnailer_reprocess_entry(self, entry); - // TODO(p): Eliminate high recursion depth with non-paths. thumbnailer_next(self); } @@ -496,26 +495,17 @@ static void thumbnailer_next(FivBrowser *self) { // TODO(p): At least launch multiple thumbnailers in parallel. + // Ideally, try to keep them alive. GList *link = self->thumbnail_queue; if (!link) return; const Entry *entry = link->data; - GFile *file = g_file_new_for_uri(entry->uri); - gchar *uri = g_file_get_uri(file); - g_object_unref(file); - if (!uri) { - // TODO(p): Support thumbnailing non-local URIs in some manner. - self->thumbnail_queue = g_list_delete_link(self->thumbnail_queue, link); - return; - } - 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, "--", uri, - NULL); - g_free(uri); + fiv_thumbnail_sizes[self->item_size].thumbnail_spec_name, "--", + entry->uri, NULL); if (error) { g_warning("%s", error->message); g_error_free(error); diff --git a/fiv-sidebar.c b/fiv-sidebar.c index 7712eb9..4c2daea 100644 --- a/fiv-sidebar.c +++ b/fiv-sidebar.c @@ -220,6 +220,7 @@ complete_path(GFile *location, GtkListStore *model) { // TODO(p): Do not enter directories unless followed by '/'. // This information has already been stripped from `location`. + // TODO(p): Try out GFileCompleter. GFile *parent = G_FILE_TYPE_DIRECTORY == g_file_query_file_type(location, G_FILE_QUERY_INFO_NONE, NULL) ? g_object_ref(location) diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c index 60df749..076a917 100644 --- a/fiv-thumbnail.c +++ b/fiv-thumbnail.c @@ -223,9 +223,12 @@ fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, GError **error) max_size <= FIV_THUMBNAIL_SIZE_MAX, FALSE); // Local files only, at least for now. + // TODO(p): Support thumbnailing the trash scheme. const gchar *path = g_file_peek_path(target); - if (!path) + if (!path) { + set_error(error, "only local files are supported"); return FALSE; + } GMappedFile *mf = g_mapped_file_new(path, FALSE, error); if (!mf) -- cgit v1.2.3-70-g09d2