aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-07-31 01:13:19 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-07-31 01:14:42 +0200
commitfec64d559512b2f2aae7b6041ece578c7d47f252 (patch)
tree127907ff8eb61cde805314f0985c883e4be9d5a2
parentfefb4c16ac1b48ba5a5b9278b1060e84a4566812 (diff)
downloadfiv-fec64d559512b2f2aae7b6041ece578c7d47f252.tar.gz
fiv-fec64d559512b2f2aae7b6041ece578c7d47f252.tar.xz
fiv-fec64d559512b2f2aae7b6041ece578c7d47f252.zip
Support file information for non-local files
-rw-r--r--fiv-view.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/fiv-view.c b/fiv-view.c
index f1708a4..4da10d3 100644
--- a/fiv-view.c
+++ b/fiv-view.c
@@ -1209,33 +1209,33 @@ info(FivView *self)
GtkWindow *window = get_toplevel(GTK_WIDGET(self));
int flags = G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE;
+ // TODO(p): Make this all cancellable, especially considering downloading.
+ // Do this by showing the dialog window immediately.
GFile *file = g_file_new_for_uri(self->uri);
gchar *path = g_file_get_path(file);
- g_object_unref(file);
- if (!path) {
- // TODO(p): Support piping to exiftool (use "-" as path).
- show_error_dialog(window,
- g_error_new_literal(G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- "files without a local path aren't supported"));
- return;
- }
GError *error = NULL;
+ GBytes *inbytes = NULL, *outbytes = NULL, *errbytes = NULL;
+ gchar *file_data = NULL;
+ gsize file_len = 0;
+ if (!path &&
+ g_file_load_contents(file, NULL, &file_data, &file_len, NULL, &error)) {
+ flags |= G_SUBPROCESS_FLAGS_STDIN_PIPE;
+ path = g_strdup("-");
+ inbytes = g_bytes_new_take(file_data, file_len);
+ }
+
+ g_object_unref(file);
+ if (error)
+ goto out;
+
GSubprocess *subprocess = g_subprocess_new(flags, &error, "exiftool",
"-tab", "-groupNames", "-duplicates", "-extractEmbedded", "--binary",
"-quiet", "--", path, NULL);
g_free(path);
- if (error) {
- show_error_dialog(window, error);
- return;
- }
-
- gchar *out = NULL, *err = NULL;
- if (!g_subprocess_communicate_utf8(
- subprocess, NULL, NULL, &out, &err, &error)) {
- show_error_dialog(window, error);
- return;
- }
+ if (error || !g_subprocess_communicate(
+ subprocess, inbytes, NULL, &outbytes, &errbytes, &error))
+ goto out;
GtkWidget *dialog = gtk_widget_new(GTK_TYPE_DIALOG,
"use-header-bar", TRUE,
@@ -1243,6 +1243,13 @@ info(FivView *self)
"transient-for", window,
"destroy-with-parent", TRUE, NULL);
+ gchar *out = g_utf8_make_valid(
+ g_bytes_get_data(outbytes, NULL), g_bytes_get_size(outbytes));
+ gchar *err = g_utf8_make_valid(
+ g_bytes_get_data(errbytes, NULL), g_bytes_get_size(errbytes));
+ g_bytes_unref(outbytes);
+ g_bytes_unref(errbytes);
+
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
if (*err) {
GtkWidget *info = gtk_info_bar_new();
@@ -1275,6 +1282,12 @@ info(FivView *self)
g_free(err);
g_object_unref(subprocess);
gtk_widget_show_all(dialog);
+
+out:
+ if (error)
+ show_error_dialog(window, error);
+ if (inbytes)
+ g_bytes_unref(inbytes);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -