mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 23:05:59 +01:00
Merge branch 'carrotIndustries/zathura-features/gio-download' into develop
This commit is contained in:
commit
bf73069d14
1 changed files with 49 additions and 1 deletions
|
@ -518,6 +518,41 @@ prepare_document_open_from_stdin(zathura_t* zathura, const char* path)
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
prepare_document_open_from_gfile(zathura_t* zathura, GFile* source)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(zathura, NULL);
|
||||||
|
gchar* file = NULL;
|
||||||
|
GFileIOStream *iostream;
|
||||||
|
GError* error = NULL;
|
||||||
|
|
||||||
|
GFile *tmpfile = g_file_new_tmp("zathura.gio.XXXXXX", &iostream, &error);
|
||||||
|
if(tmpfile == NULL) {
|
||||||
|
if (error != NULL) {
|
||||||
|
girara_error("Can not create temporary file: %s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean rc = g_file_copy(source, tmpfile, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
|
||||||
|
if(rc == FALSE) {
|
||||||
|
if (error != NULL) {
|
||||||
|
girara_error("Can not copy to temporary file: %s", error->message);
|
||||||
|
g_error_free(error);
|
||||||
|
}
|
||||||
|
g_object_unref(iostream);
|
||||||
|
g_object_unref(tmpfile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = g_file_get_path(tmpfile);
|
||||||
|
g_object_unref(iostream);
|
||||||
|
g_object_unref(tmpfile);
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
document_info_open(gpointer data)
|
document_info_open(gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -536,7 +571,20 @@ document_info_open(gpointer data)
|
||||||
document_info->zathura->stdin_support.file = g_strdup(file);
|
document_info->zathura->stdin_support.file = g_strdup(file);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file = g_strdup(document_info->path);
|
GFile *gf = g_file_new_for_commandline_arg(document_info->path);
|
||||||
|
if(g_file_is_native(gf)) {
|
||||||
|
file = g_strdup(document_info->path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
file = prepare_document_open_from_gfile(document_info->zathura, gf);
|
||||||
|
if (file == NULL) {
|
||||||
|
girara_notify(document_info->zathura->ui.session, GIRARA_ERROR,
|
||||||
|
_("Could not read file from GIO and copy it to a temporary file."));
|
||||||
|
} else {
|
||||||
|
document_info->zathura->stdin_support.file = g_strdup(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_object_unref(gf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file != NULL) {
|
if (file != NULL) {
|
||||||
|
|
Loading…
Reference in a new issue