Mercurial > pidgin
changeset 9670:ed3bbf36de75
[gaim-migrate @ 10522]
(10:17:53) datallah:
http://www.butfer.com/gaim-patches/dnd_robustness+multiple_file_fix.patch
should fix 1003589 and also make us support DND of multiple files to
transfer - also makes us not try to transfer directories
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 05 Aug 2004 14:17:03 +0000 |
parents | 287d900e2c03 |
children | 783d579859eb |
files | src/gtkblist.c src/gtkconv.c src/util.c src/util.h |
diffstat | 4 files changed, 119 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gtkblist.c Thu Aug 05 04:01:41 2004 +0000 +++ b/src/gtkblist.c Thu Aug 05 14:17:03 2004 +0000 @@ -2012,21 +2012,18 @@ if (GAIM_BLIST_NODE_IS_BUDDY(node) || GAIM_BLIST_NODE_IS_CONTACT(node)) { GaimBuddy *b = GAIM_BLIST_NODE_IS_BUDDY(node) ? (GaimBuddy*)node : gaim_contact_get_priority_buddy((GaimContact*)node); - if (!g_ascii_strncasecmp(sd->data, "file://", 7)) { - GError *converr = NULL; - gchar *file; - if(!(file = g_filename_from_uri(sd->data, NULL, &converr))) { - gaim_debug(GAIM_DEBUG_ERROR, "conv dnd", "%s\n", - (converr ? converr->message : - "g_filename_from_uri error")); - g_error_free(converr); - return; + GList *tmp; + GList *files = gaim_uri_list_extract_filenames(sd->data); + for(tmp = files; tmp != NULL ; tmp = g_list_next(tmp)) { + gchar *filename = tmp->data; + /* XXX - Make ft API support creating a transfer with more than one file */ + if (g_file_test(filename, G_FILE_TEST_EXISTS) + && !g_file_test(filename, G_FILE_TEST_IS_DIR)) { + serv_send_file(gaim_account_get_connection(b->account), b->name, filename); } - file = g_strchomp(file); - /* XXX - Handle dragging more than one file. Make ft API support creating a transfer with more than one file */ - serv_send_file(gaim_account_get_connection(b->account), b->name, file); - g_free(file); - } + g_free(filename); + } + g_list_free(files); } } }
--- a/src/gtkconv.c Thu Aug 05 04:01:41 2004 +0000 +++ b/src/gtkconv.c Thu Aug 05 14:17:03 2004 +0000 @@ -4420,21 +4420,23 @@ else if (sd->target == gdk_atom_intern("text/uri-list", FALSE)) { if (!g_ascii_strncasecmp(sd->data, "file://", 7)) { GError *converr = NULL; + GList *tmp; + GList *files = gaim_uri_list_extract_filenames(sd->data); + for(tmp = files; tmp != NULL ; tmp = g_list_next(tmp)) { + gchar *filename = tmp->data; + /* XXX - Make ft API support creating a transfer with more than one file */ + if (g_file_test(filename, G_FILE_TEST_EXISTS) + && !g_file_test(filename, G_FILE_TEST_IS_DIR) + && gaim_conversation_get_type(conv) == GAIM_CONV_IM) { + serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), filename); + } + g_free(filename); + } + g_list_free(files); gchar *file; - if(!(file = g_filename_from_uri(sd->data, NULL, &converr))) { - gaim_debug(GAIM_DEBUG_ERROR, "conv dnd", "%s\n", - (converr ? converr->message : - "g_filename_from_uri error")); - g_error_free(converr); - return; - } - file = g_strchomp(file); - /* XXX - Handle dragging more than one file. Make ft API support creating a transfer with more than one file */ /* XXX - Attempt to load this file into gdk_pixbuf, or otherwise determine if it is an image. If it is, offer * the choice of a) sending this file b) inserting this file as an IM image or c) setting this file as a custom * buddy icon for this buddy */ - if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) - serv_send_file(gaim_conversation_get_gc(conv), gaim_conversation_get_name(conv), file); g_free(file); } }
--- a/src/util.c Thu Aug 05 04:01:41 2004 +0000 +++ b/src/util.c Thu Aug 05 14:17:03 2004 +0000 @@ -2944,6 +2944,78 @@ return ((c - domain) > 3 ? TRUE : FALSE); } +/** Stolen from gnome_uri_list_extract_uris **/ +GList* gaim_uri_list_extract_uris (const gchar* uri_list) { + const gchar *p, *q; + gchar *retval; + GList *result = NULL; + + g_return_val_if_fail (uri_list != NULL, NULL); + + p = uri_list; + + /* We don't actually try to validate the URI according to RFC + * 2396, or even check for allowed characters - we just ignore + * comments and trim whitespace off the ends. We also + * allow LF delimination as well as the specified CRLF. + */ + while (p) { + if (*p != '#') { + while (isspace(*p)) + p++; + + q = p; + while (*q && (*q != '\n') && (*q != '\r')) + q++; + + if (q > p) { + q--; + while (q > p && isspace(*q)) + q--; + + retval = (gchar*)g_malloc (q - p + 2); + strncpy (retval, p, q - p + 1); + retval[q - p + 1] = '\0'; + + result = g_list_prepend (result, retval); + } + } + p = strchr (p, '\n'); + if (p) + p++; + } + + return g_list_reverse (result); +} + + +/** Stolen from gaim_uri_list_extract_filenames **/ +GList* gaim_uri_list_extract_filenames (const gchar* uri_list) { + GList *tmp_list, *node, *result; + + g_return_val_if_fail (uri_list != NULL, NULL); + + result = gaim_uri_list_extract_uris (uri_list); + + tmp_list = result; + while (tmp_list) { + gchar *s = (gchar*)tmp_list->data; + + node = tmp_list; + tmp_list = tmp_list->next; + + if (!strncmp (s, "file:", 5)) { + node->data = g_filename_from_uri (s, NULL, NULL); + /* not sure if this fallback is useful at all */ + if (!node->data) node->data = g_strdup (s+5); + } else { + result = g_list_remove_link(result, node); + g_list_free_1 (node); + } + g_free (s); + } + return result; +} /************************************************************************** * UTF8 String Functions
--- a/src/util.h Thu Aug 05 04:01:41 2004 +0000 +++ b/src/util.h Thu Aug 05 14:17:03 2004 +0000 @@ -650,6 +650,29 @@ */ gboolean gaim_email_is_valid(const char *address); +/** + * This function extracts a list of URIs from the a "text/uri-list" string + * It was "borrowed" from gnome_uri_list_extract_uris + * + * @param uri_list an uri-list in the standard format. + * + * @return a GList containing strings allocated with g_malloc that have been + * splitted from uri-list. + */ +GList* gaim_uri_list_extract_uris (const gchar* uri_list); + +/** + * This function extracts a list of filenames from the a "text/uri-list" string + * It was "borrowed" from gnome_uri_list_extract_filenames + * + * @param uri_list an uri-list in the standard format. + * + * @return a GList containing strings allocated with g_malloc that contain the + * filenames in the uri-list. Note that unlike gaim_uri_list_extract_uris() + * function, this will discard any non-file uri from the result value. + */ +GList* gaim_uri_list_extract_filenames (const gchar* uri_list); + /*@}*/ /**************************************************************************