3 * Copyright (C) 2008 - 2012 The Geeqie Team
5 * Authors: John Ellis, Vladimir Nadvornik, Laurent Monin
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
14 #include "uri_utils.h"
17 #include "ui_fileops.h"
18 #include "ui_utildlg.h"
20 void warning_dialog_dnd_uri_error(GList *uri_error_list)
22 GList *work = uri_error_list;
23 guint count = g_list_length(work);
24 gchar *msg = g_strdup_printf("Failed to convert %d dropped item(s) to files\n", count);
30 msg = g_strdup_printf("%s\n%s", prev, (gchar *)work->data);
35 warning_dialog(_("Drag and Drop failed"), msg, GTK_STOCK_DIALOG_WARNING, NULL);
39 gchar **uris_from_pathlist(GList *list)
43 guint num = g_list_length(list);
44 gchar **uris = g_new0(gchar *, num + 1);
49 const gchar *path = work->data;
50 gchar *local_path = path_from_utf8(path);
51 uris[i] = g_filename_to_uri(local_path, NULL, NULL);
62 gchar **uris_from_filelist(GList *list)
64 GList *path_list = filelist_to_path_list(list);
65 gchar **ret = uris_from_pathlist(path_list);
66 string_list_free(path_list);
70 gboolean uri_selection_data_set_uris_from_filelist(GtkSelectionData *selection_data, GList *list)
72 gchar **uris = uris_from_filelist(list);
73 gboolean ret = gtk_selection_data_set_uris(selection_data, uris);
76 char *str = g_strjoinv("\r\n", uris);
77 ret = gtk_selection_data_set_text(selection_data, str, -1);
85 GList *uri_pathlist_from_uris(gchar **uris, GList **uri_error_list)
93 gchar *local_path = g_filename_from_uri(uris[i], NULL, &error);
96 DEBUG_1("g_filename_from_uri failed on uri \"%s\"", uris[i]);
97 DEBUG_1(" error %d: %s", error->code, error->message);
98 if (error->code == G_CONVERT_ERROR_BAD_URI)
100 GError *retry_error = NULL;
101 gchar *escaped = g_uri_escape_string(uris[i], ":/", TRUE);
102 local_path = g_filename_from_uri(escaped, NULL, &retry_error);
105 DEBUG_1("manually escaped uri \"%s\" also failed g_filename_from_uri", escaped);
106 DEBUG_1(" error %d: %s", retry_error->code, retry_error->message);
107 g_error_free(retry_error);
115 *uri_error_list = g_list_prepend(*uri_error_list, g_strdup(uris[i]));
120 gchar *path = path_to_utf8(local_path);
122 list = g_list_prepend(list, path);
126 *uri_error_list = g_list_reverse(*uri_error_list);
127 return g_list_reverse(list);
130 GList *uri_filelist_from_uris(gchar **uris, GList **uri_error_list)
132 GList *path_list = uri_pathlist_from_uris(uris, uri_error_list);
133 GList *filelist = filelist_from_path_list(path_list);
134 string_list_free(path_list);
138 GList *uri_filelist_from_gtk_selection_data(GtkSelectionData *selection_data)
140 GList *errors = NULL;
141 gchar **uris = gtk_selection_data_get_uris(selection_data);
142 GList *ret = uri_filelist_from_uris(uris, &errors);
145 warning_dialog_dnd_uri_error(errors);
146 string_list_free(errors);
154 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */