Improve support for opening HTTP URIs

While all GVfs files implement the mountable interface,
mounting may not actually achieve anything.
This commit is contained in:
Přemysl Eric Janouch 2022-08-05 03:25:31 +02:00
parent bb669743b6
commit 51dc56c9df
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 23 additions and 6 deletions

29
fiv.c
View File

@ -913,27 +913,44 @@ on_item_activated(G_GNUC_UNUSED FivBrowser *browser, GFile *location,
static void open_any_file(GFile *file, gboolean force_browser);
static void
on_mounted_enclosing(GObject *source_object, GAsyncResult *res,
G_GNUC_UNUSED gpointer user_data)
on_mounted_enclosing(
GObject *source_object, GAsyncResult *res, gpointer user_data)
{
GFile *file = G_FILE(source_object);
GError *error = NULL;
if (!g_file_mount_enclosing_volume_finish(file, res, &error))
if (g_file_mount_enclosing_volume_finish(file, res, &error))
goto retry;
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED)) {
show_error_dialog(error);
else
open_any_file(file, FALSE);
return;
}
// The "http" scheme doesn't behave nicely, make a leap of faith.
g_error_free(error);
if (g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL) ==
G_FILE_TYPE_UNKNOWN) {
gchar *uri = g_file_get_uri(file);
open_image(uri);
g_free(uri);
return;
}
retry:
open_any_file(file, (gboolean) (gintptr) user_data);
}
static void
open_any_file(GFile *file, gboolean force_browser)
{
// Various GVfs schemes may need mounting.
GFileType type = g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL);
if (type == G_FILE_TYPE_UNKNOWN &&
G_FILE_GET_IFACE(file)->mount_enclosing_volume) {
// TODO(p): At least provide some kind of indication.
GMountOperation *op = gtk_mount_operation_new(GTK_WINDOW(g.window));
g_file_mount_enclosing_volume(file, G_MOUNT_MOUNT_NONE, op, NULL,
on_mounted_enclosing, NULL);
on_mounted_enclosing, (gpointer) (gintptr) force_browser);
g_object_unref(op);
return;
}