Support file information for non-local files
This commit is contained in:
parent
fefb4c16ac
commit
fec64d5595
51
fiv-view.c
51
fiv-view.c
|
@ -1209,33 +1209,33 @@ info(FivView *self)
|
||||||
GtkWindow *window = get_toplevel(GTK_WIDGET(self));
|
GtkWindow *window = get_toplevel(GTK_WIDGET(self));
|
||||||
int flags = G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE;
|
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);
|
GFile *file = g_file_new_for_uri(self->uri);
|
||||||
gchar *path = g_file_get_path(file);
|
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;
|
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",
|
GSubprocess *subprocess = g_subprocess_new(flags, &error, "exiftool",
|
||||||
"-tab", "-groupNames", "-duplicates", "-extractEmbedded", "--binary",
|
"-tab", "-groupNames", "-duplicates", "-extractEmbedded", "--binary",
|
||||||
"-quiet", "--", path, NULL);
|
"-quiet", "--", path, NULL);
|
||||||
g_free(path);
|
g_free(path);
|
||||||
if (error) {
|
if (error || !g_subprocess_communicate(
|
||||||
show_error_dialog(window, error);
|
subprocess, inbytes, NULL, &outbytes, &errbytes, &error))
|
||||||
return;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
gchar *out = NULL, *err = NULL;
|
|
||||||
if (!g_subprocess_communicate_utf8(
|
|
||||||
subprocess, NULL, NULL, &out, &err, &error)) {
|
|
||||||
show_error_dialog(window, error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *dialog = gtk_widget_new(GTK_TYPE_DIALOG,
|
GtkWidget *dialog = gtk_widget_new(GTK_TYPE_DIALOG,
|
||||||
"use-header-bar", TRUE,
|
"use-header-bar", TRUE,
|
||||||
|
@ -1243,6 +1243,13 @@ info(FivView *self)
|
||||||
"transient-for", window,
|
"transient-for", window,
|
||||||
"destroy-with-parent", TRUE, NULL);
|
"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));
|
GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
|
||||||
if (*err) {
|
if (*err) {
|
||||||
GtkWidget *info = gtk_info_bar_new();
|
GtkWidget *info = gtk_info_bar_new();
|
||||||
|
@ -1275,6 +1282,12 @@ info(FivView *self)
|
||||||
g_free(err);
|
g_free(err);
|
||||||
g_object_unref(subprocess);
|
g_object_unref(subprocess);
|
||||||
gtk_widget_show_all(dialog);
|
gtk_widget_show_all(dialog);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (error)
|
||||||
|
show_error_dialog(window, error);
|
||||||
|
if (inbytes)
|
||||||
|
g_bytes_unref(inbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
Loading…
Reference in New Issue