2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Authors: John Ellis, Vladimir Nadvornik, Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "uri_utils.h"
25 #include "ui_fileops.h"
26 #include "ui_utildlg.h"
28 void warning_dialog_dnd_uri_error(GList *uri_error_list)
30 GList *work = uri_error_list;
31 guint count = g_list_length(work);
32 gchar *msg = g_strdup_printf("Failed to convert %d dropped item(s) to files\n", count);
38 msg = g_strdup_printf("%s\n%s", prev, (gchar *)work->data);
43 warning_dialog(_("Drag and Drop failed"), msg, GTK_STOCK_DIALOG_WARNING, NULL);
47 gchar **uris_from_pathlist(GList *list)
51 guint num = g_list_length(list);
52 gchar **uris = g_new0(gchar *, num + 1);
57 const gchar *path = work->data;
58 gchar *local_path = path_from_utf8(path);
59 uris[i] = g_filename_to_uri(local_path, NULL, NULL);
70 gchar **uris_from_filelist(GList *list)
72 GList *path_list = filelist_to_path_list(list);
73 gchar **ret = uris_from_pathlist(path_list);
74 string_list_free(path_list);
78 gboolean uri_selection_data_set_uris_from_filelist(GtkSelectionData *selection_data, GList *list)
80 gchar **uris = uris_from_filelist(list);
81 gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
84 char *str = g_strjoinv("\r\n", uris);
85 ret = gtk_selection_data_set_text(selection_data, str, -1);
93 GList *uri_pathlist_from_uris(gchar **uris, GList **uri_error_list)
101 gchar *local_path = g_filename_from_uri(uris[i], NULL, &error);
104 DEBUG_1("g_filename_from_uri failed on uri \"%s\"", uris[i]);
105 DEBUG_1(" error %d: %s", error->code, error->message);
106 if (error->code == G_CONVERT_ERROR_BAD_URI)
108 GError *retry_error = NULL;
109 gchar *escaped = g_uri_escape_string(uris[i], ":/", TRUE);
110 local_path = g_filename_from_uri(escaped, NULL, &retry_error);
113 DEBUG_1("manually escaped uri \"%s\" also failed g_filename_from_uri", escaped);
114 DEBUG_1(" error %d: %s", retry_error->code, retry_error->message);
115 g_error_free(retry_error);
123 *uri_error_list = g_list_prepend(*uri_error_list, g_strdup(uris[i]));
128 gchar *path = path_to_utf8(local_path);
130 list = g_list_prepend(list, path);
134 *uri_error_list = g_list_reverse(*uri_error_list);
135 return g_list_reverse(list);
138 GList *uri_filelist_from_uris(gchar **uris, GList **uri_error_list)
140 GList *path_list = uri_pathlist_from_uris(uris, uri_error_list);
141 GList *filelist = filelist_from_path_list(path_list);
142 string_list_free(path_list);
146 GList *uri_filelist_from_gtk_selection_data(GtkSelectionData *selection_data)
148 GList *errors = NULL;
149 gchar **uris = gtk_selection_data_get_uris(selection_data);
150 GList *ret = uri_filelist_from_uris(uris, &errors);
153 warning_dialog_dnd_uri_error(errors);
154 string_list_free(errors);
162 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */