/*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
* Author: John Ellis
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "ui_fileops.h"
#include "ui_utildlg.h" /* for locale warning dialog */
+#include "md5-util.h"
+
+#include "filefilter.h"
+#include "layout.h"
+#include "utilops.h"
+#include "secure_save.h"
/*
*-----------------------------------------------------------------------------
-void print_term(const gchar *text_utf8)
+void print_term(gboolean err, const gchar *text_utf8)
{
gchar *text_l;
text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
- fputs((text_l) ? text_l : text_utf8, stdout);
+ if (err)
+ {
+ fputs((text_l) ? text_l : text_utf8, stderr);
+ }
+ else
+ {
+ fputs((text_l) ? text_l : text_utf8, stdout);
+ }
+ if(command_line && command_line->ssi)
+ secure_fputs(command_line->ssi, (text_l) ? text_l : text_utf8);
g_free(text_l);
}
-static void encoding_dialog(const gchar *path);
-
-static gint encoding_dialog_idle(gpointer data)
-{
- gchar *path = data;
-
- encoding_dialog(path);
- g_free(path);
-
- return FALSE;
-}
-
-static gint encoding_dialog_delay(gpointer data)
-{
- g_idle_add(encoding_dialog_idle, data);
-
- return 0;
-}
-
static void encoding_dialog(const gchar *path)
{
- static gint warned_user = FALSE;
+ static gboolean warned_user = FALSE;
GenericDialog *gd;
GString *string;
const gchar *lc;
const gchar *bf;
- /* check that gtk is initialized (loop is level > 0) */
- if (gtk_main_level() == 0)
- {
- /* gtk not initialized */
- gtk_init_add(encoding_dialog_delay, g_strdup(path));
- return;
- }
-
if (warned_user) return;
warned_user = TRUE;
name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
string = g_string_append(string, _("\nPreferred encoding appears to be UTF-8, however the file:\n"));
g_string_append_printf(string, "\"%s\"\n", (name) ? name : _("[name not displayable]"));
-
+
if (g_utf8_validate(path, -1, NULL))
g_string_append_printf(string, _("\"%s\" is encoded in valid UTF-8."), (name) ? name : _("[name not displayable]"));
else
generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
- _("Filename encoding locale mismatch"), string->str);
+ _("Filename encoding locale mismatch"), string->str, TRUE);
gtk_widget_show(gd->dialog);
g_string_free(string, TRUE);
}
+#if GQ_DEBUG_PATH_UTF8
+gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line)
+#else
gchar *path_to_utf8(const gchar *path)
+#endif
{
gchar *utf8;
GError *error = NULL;
utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
if (error)
{
+#if GQ_DEBUG_PATH_UTF8
+ log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message);
+#else
log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
+#endif
g_error_free(error);
encoding_dialog(path);
}
return utf8;
}
+#if GQ_DEBUG_PATH_UTF8
+gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line)
+#else
gchar *path_from_utf8(const gchar *utf8)
+#endif
{
gchar *path;
GError *error = NULL;
path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
if (error)
{
+#if GQ_DEBUG_PATH_UTF8
+ log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message);
+#else
log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
+#endif
g_error_free(error);
}
if (!path)
{
- /* if invalid UTF-8, text probaby still in original form, so just copy it */
+ /* if invalid UTF-8, text probably still in original form, so just copy it */
path = g_strdup(utf8);
}
if (!home)
home = path_to_utf8(getenv("HOME"));
-
+
if (!home)
home = path_to_utf8(g_get_home_dir());
+ DEBUG_1("Home directory: %s", home);
+
return home;
}
{
return g_build_filename(homedir(), fallback, NULL);
}
-
+
+ DEBUG_1("Got xdg %s: %s", key, dir);
+
return path_to_utf8(dir);
}
static const gchar *xdg_data_home = NULL;
if (xdg_data_home) return xdg_data_home;
-
+
xdg_data_home = xdg_dir_get("XDG_DATA_HOME", ".local/share");
return xdg_data_home;
static const gchar *xdg_config_home = NULL;
if (xdg_config_home) return xdg_config_home;
-
+
xdg_config_home = xdg_dir_get("XDG_CONFIG_HOME", ".config");
return xdg_config_home;
static const gchar *xdg_cache_home = NULL;
if (xdg_cache_home) return xdg_cache_home;
-
+
xdg_cache_home = xdg_dir_get("XDG_CACHE_HOME", ".cache");
return xdg_cache_home;
const gchar *get_rc_dir(void)
{
static gchar *rc_dir = NULL;
-
+
if (rc_dir) return rc_dir;
if (USE_XDG)
static gchar *trash_dir = NULL;
if (trash_dir) return trash_dir;
-
+
if (USE_XDG)
{
trash_dir = g_build_filename(xdg_data_home_get(), GQ_APPNAME_LC, GQ_TRASH_DIR, NULL);
return trash_dir;
}
-gint stat_utf8(const gchar *s, struct stat *st)
+const gchar *get_window_layouts_dir(void)
{
- gchar *sl;
- gint ret;
+ static gchar *window_layouts_dir = NULL;
- if (!s) return FALSE;
- sl = path_from_utf8(s);
- ret = (stat(sl, st) == 0);
- g_free(sl);
+ if (window_layouts_dir) return window_layouts_dir;
- return ret;
+ if (USE_XDG)
+ {
+ window_layouts_dir = g_build_filename(xdg_config_home_get(), GQ_APPNAME_LC, GQ_WINDOW_LAYOUTS_DIR, NULL);
+ }
+ else
+ {
+ window_layouts_dir = g_build_filename(get_rc_dir(), GQ_WINDOW_LAYOUTS_DIR, NULL);
+ }
+
+ return window_layouts_dir;
}
-gint lstat_utf8(const gchar *s, struct stat *st)
+gboolean stat_utf8(const gchar *s, struct stat *st)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
sl = path_from_utf8(s);
- ret = (lstat(sl, st) == 0);
+ ret = (stat(sl, st) == 0);
g_free(sl);
return ret;
}
-/* extension must contain only ASCII characters */
-gint stat_utf8_case_insensitive_ext(GString *base, const gchar *ext, struct stat *st)
+gboolean lstat_utf8(const gchar *s, struct stat *st)
{
gchar *sl;
- gchar *extl;
- gint ret = 0;
- gint ext_len;
- gint base_len = strlen(base->str);
-
- g_string_append(base, ext);
- sl = path_from_utf8(base->str);
-
- extl = strrchr(sl, '.');
- if (extl)
- {
- gint i, j;
- extl++; /* the first char after . */
- ext_len = strlen(extl);
-
- for (i = 0; i < (1 << ext_len); i++)
- {
- for (j = 0; j < ext_len; j++)
- {
- if (i & (1 << j))
- extl[j] = g_ascii_toupper(extl[j]);
- else
- extl[j] = g_ascii_tolower(extl[j]);
- }
- ret = (stat(sl, st) == 0);
- if (ret) break;
- }
-
- if (ret)
- {
- /* append the found extension to base */
- base = g_string_truncate(base, base_len);
- extl--;
- g_string_append(base, extl);
- }
- }
+ gboolean ret;
+
+ if (!s) return FALSE;
+ sl = path_from_utf8(s);
+ ret = (lstat(sl, st) == 0);
g_free(sl);
return ret;
}
-gint isname(const gchar *s)
+gboolean isname(const gchar *s)
{
struct stat st;
return stat_utf8(s, &st);
}
-gint isfile(const gchar *s)
+gboolean isfile(const gchar *s)
{
struct stat st;
return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
}
-gint isdir(const gchar *s)
+gboolean isdir(const gchar *s)
{
struct stat st;
return (stat_utf8(s, &st) && S_ISDIR(st.st_mode));
}
-gint islink(const gchar *s)
+gboolean islink(const gchar *s)
{
struct stat st;
return st.st_mtime;
}
-gint filetime_set(const gchar *s, time_t tval)
+gboolean filetime_set(const gchar *s, time_t tval)
{
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (tval > 0)
{
return ret;
}
-gint access_file(const gchar *s, gint mode)
+gboolean is_readable_file(const gchar *s)
+{
+ if (!s || !s[0] || !isfile(s)) return FALSE;
+ return access_file(s, R_OK);
+}
+
+gboolean access_file(const gchar *s, gint mode)
{
gchar *sl;
gint ret;
- if (!s) return FALSE;
+ if (!s || !s[0]) return FALSE;
sl = path_from_utf8(s);
ret = (access(sl, mode) == 0);
return ret;
}
-gint unlink_file(const gchar *s)
+gboolean unlink_file(const gchar *s)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint symlink_utf8(const gchar *source, const gchar *target)
+gboolean symlink_utf8(const gchar *source, const gchar *target)
{
gchar *sl;
gchar *tl;
- gint ret;
+ gboolean ret;
if (!source || !target) return FALSE;
return ret;
}
-gint mkdir_utf8(const gchar *s, gint mode)
+gboolean mkdir_utf8(const gchar *s, gint mode)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint rmdir_utf8(const gchar *s)
+gboolean rmdir_utf8(const gchar *s)
{
gchar *sl;
- gint ret;
+ gboolean ret;
if (!s) return FALSE;
return ret;
}
-gint copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
+gboolean copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
{
struct stat st;
gchar *sl, *tl;
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (!s || !t) return FALSE;
/* set the dest file attributes to that of source (ignoring errors) */
- if (perms && chown(tl, st.st_uid, st.st_gid) < 0) ret = FALSE;
- if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE;
+ if (perms)
+ {
+ ret = chown(tl, st.st_uid, st.st_gid);
+ /* Ignores chown errors, while still doing chown
+ (so root still can copy files preserving ownership) */
+ ret = TRUE;
+ if (chmod(tl, st.st_mode) < 0) {
+ struct stat st2;
+ if (stat(tl, &st2) != 0 || st2.st_mode != st.st_mode) {
+ ret = FALSE;
+ }
+ }
+ }
tb.actime = st.st_atime;
tb.modtime = st.st_mtime;
}
/* paths are in filesystem encoding */
-static gint hard_linked(const gchar *a, const gchar *b)
+static gboolean hard_linked(const gchar *a, const gchar *b)
{
struct stat sta;
struct stat stb;
sta.st_ino == stb.st_ino);
}
-gint copy_file(const gchar *s, const gchar *t)
+gboolean copy_file(const gchar *s, const gchar *t)
{
FILE *fi = NULL;
FILE *fo = NULL;
- gchar *sl, *tl;
- gchar buf[4096];
+ gchar *sl = NULL;
+ gchar *tl = NULL;
+ gchar *randname = NULL;
+ gchar buf[16384];
size_t b;
+ gint ret = FALSE;
+ gint fd = -1;
sl = path_from_utf8(s);
tl = path_from_utf8(t);
if (hard_linked(sl, tl))
{
- g_free(sl);
- g_free(tl);
- return TRUE;
+ ret = TRUE;
+ goto end;
}
- fi = fopen(sl, "rb");
- if (fi)
+ /* Do not dereference absolute symlinks, but copy them "as is".
+ * For a relative symlink, we don't know how to properly change it when
+ * copied/moved to another dir to keep pointing it to same target as
+ * a relative symlink, so we turn it into absolute symlink using
+ * realpath() instead. */
+ struct stat st;
+ if (lstat_utf8(sl, &st) && S_ISLNK(st.st_mode))
{
- fo = fopen(tl, "wb");
- if (!fo)
+ gchar *link_target;
+ ssize_t i;
+
+ link_target = g_malloc(st.st_size + 1);
+ i = readlink(sl, link_target, st.st_size);
+ if (i<0)
{
- fclose(fi);
- fi = NULL;
+ g_free(link_target);
+ goto orig_copy; // try a "normal" copy
}
- }
+ link_target[st.st_size] = '\0';
- g_free(sl);
- g_free(tl);
+ if (link_target[0] != G_DIR_SEPARATOR) // if it is a relative symlink
+ {
+ gchar *absolute;
+
+ gchar *lastslash = strrchr(sl, G_DIR_SEPARATOR);
+ gint len = lastslash - sl + 1;
+
+ absolute = g_malloc(len + st.st_size + 1);
+ strncpy(absolute, sl, len);
+ strcpy(absolute + len, link_target);
+ g_free(link_target);
+ link_target = absolute;
+
+ gchar *realPath;
+ realPath = realpath(link_target, NULL);
+
+ if (realPath != NULL) // successfully resolved into an absolute path
+ {
+ g_free(link_target);
+ link_target = g_strdup(realPath);
+ g_free(realPath);
+ }
+ else // could not get absolute path, got some error instead
+ {
+ g_free(link_target);
+ goto orig_copy; // so try a "normal" copy
+ }
+ }
+
+ if (stat_utf8(tl, &st)) unlink(tl); // first try to remove directory entry in destination directory if such entry exists
+
+ gint success = (symlink(link_target, tl) == 0);
+ g_free(link_target);
- if (!fi || !fo) return FALSE;
+ if (success)
+ {
+ ret = TRUE;
+ goto end;
+ }
+ } // if symlink did not succeed, continue on to try a copy procedure
+ orig_copy:
+
+ fi = fopen(sl, "rb");
+ if (!fi) goto end;
+
+ /* First we write to a temporary file, then we rename it on success,
+ and attributes from original file are copied */
+ randname = g_strconcat(tl, ".tmp_XXXXXX", NULL);
+ if (!randname) goto end;
+
+ fd = g_mkstemp(randname);
+ if (fd == -1) goto end;
+
+ fo = fdopen(fd, "wb");
+ if (!fo) {
+ close(fd);
+ goto end;
+ }
while ((b = fread(buf, sizeof(gchar), sizeof(buf), fi)) && b != 0)
{
if (fwrite(buf, sizeof(gchar), b, fo) != b)
{
- fclose(fi);
- fclose(fo);
- return FALSE;
+ unlink(randname);
+ goto end;
}
}
- fclose(fi);
- fclose(fo);
+ fclose(fi); fi = NULL;
+ fclose(fo); fo = NULL;
- copy_file_attributes(s, t, TRUE, TRUE);
+ if (rename(randname, tl) < 0) {
+ unlink(randname);
+ goto end;
+ }
- return TRUE;
+ ret = copy_file_attributes(s, t, TRUE, TRUE);
+
+end:
+ if (fi) fclose(fi);
+ if (fo) fclose(fo);
+ if (sl) g_free(sl);
+ if (tl) g_free(tl);
+ if (randname) g_free(randname);
+ return ret;
}
-gint move_file(const gchar *s, const gchar *t)
+gboolean move_file(const gchar *s, const gchar *t)
{
gchar *sl, *tl;
- gint ret = TRUE;
+ gboolean ret = TRUE;
if (!s || !t) return FALSE;
return ret;
}
-gint rename_file(const gchar *s, const gchar *t)
+gboolean rename_file(const gchar *s, const gchar *t)
{
gchar *sl, *tl;
- gint ret;
+ gboolean ret;
if (!s || !t) return FALSE;
return path8;
}
+void list_free_wrapper(void *data, void *userdata)
+{
+ g_free(data);
+}
+
void string_list_free(GList *list)
{
- g_list_foreach(list, (GFunc)g_free, NULL);
+ g_list_foreach(list, (GFunc)list_free_wrapper, NULL);
g_list_free(list);
}
return g_list_reverse(new_list);
}
-gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gint pad)
+gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gboolean pad)
{
gchar *unique;
gint n = 1;
name = filename_from_path(path);
if (!name) return NULL;
- ext = extension_from_path(name);
+ ext = registered_extension_from_path(name);
if (!ext)
{
gchar *remove_level_from_path(const gchar *path)
{
- gint p = 0, n = -1;
-
- if (!path) return NULL;
+ const gchar *base;
- while (path[p])
- {
- if (path[p] == G_DIR_SEPARATOR) n = p;
- p++;
- }
- if (n <= 0) n++;
+ if (!path) return g_strdup("");
- return g_strndup(path, (gsize) n);
-}
+ base = strrchr(path, G_DIR_SEPARATOR);
+ /* Take account of a file being in the root ( / ) folder - ensure the returned value
+ * is at least one character long */
+ if (base) return g_strndup(path, (strlen(path)-strlen(base)) == 0 ? 1 : (strlen(path)-strlen(base)));
-const gchar *extension_from_path(const gchar *path)
-{
- if (!path) return NULL;
- return strrchr(path, '.');
+ return g_strdup("");
}
-gint file_extension_match(const gchar *path, const gchar *ext)
+gboolean file_extension_match(const gchar *path, const gchar *ext)
{
gint p;
gint e;
p = strlen(path);
e = strlen(ext);
- /* FIXME: utf8 */
- return (p > e && strncasecmp(path + p - e, ext, e) == 0);
+ /** @FIXME utf8 */
+ return (p > e && g_ascii_strncasecmp(path + p - e, ext, e) == 0);
}
gchar *remove_extension_from_path(const gchar *path)
{
- gint p = 0, n = -1;
+ const gchar *reg_ext;
if (!path) return NULL;
- while (path[p])
- {
- if (path[p] == '.') n = p;
- p++;
- }
- if (n < 0) n = p;
+ reg_ext = registered_extension_from_path(path);
- return g_strndup(path, (gsize) n);
+ return g_strndup(path, strlen(path) - (reg_ext == NULL ? 0 : strlen(reg_ext)));
}
void parse_out_relatives(gchar *path)
{
if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
{
- /* /. occurence, let's see more */
+ /* /. occurrence, let's see more */
gint p = s + 2;
if (path[p] == G_DIR_SEPARATOR || path[p] == '\0')
continue;
}
}
-
+
if (s != t) path[t] = path[s];
t++;
s++;
path[t] = '\0';
}
-gint file_in_path(const gchar *name)
+gboolean file_in_path(const gchar *name)
{
gchar *path;
gchar *namel;
gint p, l;
- gint ret = FALSE;
+ gboolean ret = FALSE;
if (!name) return FALSE;
path = g_strdup(getenv("PATH"));
p++;
if (p[0] == G_DIR_SEPARATOR || p[0] == '\0')
{
- gint end = TRUE;
+ gboolean end = TRUE;
if (p[0] != '\0')
{
p[0] = '\0';
end = FALSE;
}
-
+
if (!isdir(npath))
{
DEBUG_1("creating sub dir:%s", npath);
return FALSE;
}
}
-
+
if (!end) p[0] = G_DIR_SEPARATOR;
}
}
return TRUE;
}
+/* does filename utf8 to filesystem encoding first */
+gboolean md5_get_digest_from_file_utf8(const gchar *path, guchar digest[16])
+{
+ gboolean success;
+ gchar *pathl;
+
+ pathl = path_from_utf8(path);
+ success = md5_get_digest_from_file(pathl, digest);
+ g_free(pathl);
+
+ return success;
+}
+
+
+gchar *md5_text_from_file_utf8(const gchar *path, const gchar *error_text)
+{
+ guchar digest[16];
+
+ if (!md5_get_digest_from_file_utf8(path, digest)) return g_strdup(error_text);
+
+ return md5_digest_to_text(digest);
+}
+
+/* Download web file
+ */
+typedef struct _WebData WebData;
+struct _WebData
+{
+ GenericDialog *gd;
+ GCancellable *cancellable;
+ LayoutWindow *lw;
+
+ GtkWidget *progress;
+ GFile *tmp_g_file;
+ GFile *web_file;
+};
+
+static void web_file_async_ready_cb(GObject *source_object, GAsyncResult *res, gpointer data)
+{
+ GError *error = NULL;
+ WebData* web = data;
+ gchar *tmp_filename;
+
+ if (!g_cancellable_is_cancelled(web->cancellable))
+ {
+ generic_dialog_close(web->gd);
+ }
+
+ if (g_file_copy_finish(G_FILE(source_object), res, &error))
+ {
+ tmp_filename = g_file_get_parse_name(web->tmp_g_file);
+ g_free(tmp_filename);
+ layout_set_path(web->lw, g_file_get_path(web->tmp_g_file));
+ }
+ else
+ {
+ file_util_warning_dialog(_("Web file download failed"), error->message, GTK_STOCK_DIALOG_ERROR, NULL);
+ }
+
+ g_object_unref(web->tmp_g_file);
+ web->tmp_g_file = NULL;
+ g_object_unref(web->cancellable);
+ g_object_unref(web->web_file);
+}
+
+static void web_file_progress_cb(goffset current_num_bytes, goffset total_num_bytes, gpointer data)
+{
+ WebData* web = data;
+
+ if (!g_cancellable_is_cancelled(web->cancellable))
+ {
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(web->progress), (gdouble)current_num_bytes / total_num_bytes);
+ }
+}
+
+static void download_web_file_cancel_button_cb(GenericDialog *gd, gpointer data)
+{
+ WebData* web = data;
+ g_cancellable_cancel(web->cancellable);
+}
+gboolean download_web_file(const gchar *text, gboolean minimized, gpointer data)
+{
+ gchar *scheme;
+ LayoutWindow *lw = data;
+ gchar *tmp_dir;
+ GError *error = NULL;
+ WebData *web;
+ gchar *base;
+ gboolean ret;
+ gchar *message;
+ FileFormatClass format_class;
+
+ scheme = g_uri_parse_scheme(text);
+ if (g_strcmp0("http", scheme) == 0 || g_strcmp0("https", scheme) == 0)
+ {
+ format_class = filter_file_get_class(text);
+
+ if (format_class == FORMAT_CLASS_IMAGE || format_class == FORMAT_CLASS_RAWIMAGE || format_class == FORMAT_CLASS_VIDEO || format_class == FORMAT_CLASS_DOCUMENT)
+ {
+ tmp_dir = g_dir_make_tmp("geeqie_XXXXXX", &error);
+ if (error)
+ {
+ log_printf("Error: could not create temporary file n%s\n", error->message);
+ g_error_free(error);
+ error = NULL;
+ ret = TRUE;
+ }
+ else
+ {
+ web = g_new0(WebData, 1);
+ web->lw = lw;
+
+ web->web_file = g_file_new_for_uri(text);
+
+ base = g_strdup(g_file_get_basename(web->web_file));
+ web->tmp_g_file = g_file_new_for_path(g_build_filename(tmp_dir, base, NULL));
+
+ web->gd = generic_dialog_new(_("Download web file"), "download_web_file", NULL, TRUE, download_web_file_cancel_button_cb, web);
+
+ message = g_strconcat(_("Downloading "), base, NULL);
+ generic_dialog_add_message(web->gd, GTK_STOCK_DIALOG_INFO, message, NULL, FALSE);
+
+ web->progress = gtk_progress_bar_new();
+ gtk_box_pack_start(GTK_BOX(web->gd->vbox), web->progress, FALSE, FALSE, 0);
+ gtk_widget_show(web->progress);
+ if (minimized)
+ {
+ gtk_window_iconify(GTK_WINDOW(web->gd->dialog));
+ }
+
+ gtk_widget_show(web->gd->dialog);
+ web->cancellable = g_cancellable_new();
+ g_file_copy_async(web->web_file, web->tmp_g_file, G_FILE_COPY_OVERWRITE, G_PRIORITY_LOW, web->cancellable, web_file_progress_cb, web, web_file_async_ready_cb, web);
+
+ g_free(base);
+ g_free(message);
+ ret = TRUE;
+ }
+ }
+ }
+ else
+ {
+ ret = FALSE;
+ }
+
+ g_free(scheme);
+ return ret;
+
+}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */