Mercurial > pidgin.yaz
changeset 17441:cc1b4d2e5a9b
if there are multiple resources available, ask the user which resource to
send to
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 29 May 2007 04:32:19 +0000 |
parents | d42de194a364 |
children | 2284a8aad9ef |
files | libpurple/protocols/jabber/si.c |
diffstat | 1 files changed, 85 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/si.c Mon May 28 21:38:36 2007 +0000 +++ b/libpurple/protocols/jabber/si.c Tue May 29 04:32:19 2007 +0000 @@ -26,6 +26,7 @@ #include "cipher.h" #include "debug.h" #include "ft.h" +#include "request.h" #include "network.h" #include "notify.h" @@ -769,6 +770,36 @@ } } +static void resource_select_cancel_cb(PurpleXfer *xfer, PurpleRequestFields *fields) +{ + purple_xfer_cancel_local(xfer); +} + +static void do_transfer_send(PurpleXfer *xfer, const char *resource) +{ + JabberSIXfer *jsx = xfer->data; + char **who_v = g_strsplit(xfer->who, "/", 2); + char *who; + + who = g_strdup_printf("%s/%s", who_v[0], resource); + g_strfreev(who_v); + g_free(xfer->who); + xfer->who = who; + jabber_disco_info_do(jsx->js, who, + jabber_si_xfer_send_disco_cb, xfer); +} + +static void resource_select_ok_cb(PurpleXfer *xfer, PurpleRequestFields *fields) +{ + PurpleRequestField *field = purple_request_fields_get_field(fields, "resource"); + int selected_id = purple_request_field_choice_get_value(field); + GList *labels = purple_request_field_choice_get_labels(field); + + const char *selected_label = g_list_nth_data(labels, selected_id); + + do_transfer_send(xfer, selected_label); +} + static void jabber_si_xfer_init(PurpleXfer *xfer) { JabberSIXfer *jsx = xfer->data; @@ -776,26 +807,65 @@ if(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND) { JabberBuddy *jb; JabberBuddyResource *jbr = NULL; + char *resource; + + if(NULL != (resource = jabber_get_resource(xfer->who))) { + /* they've specified a resource, no need to ask or + * default or anything, just do it */ + + do_transfer_send(xfer, resource); + g_free(resource); + } jb = jabber_buddy_find(jsx->js, xfer->who, TRUE); - /* XXX */ - if(!jb) - return; + + if(!jb || !jb->resources) { + /* no resources online, we're trying to send to someone + * whose presence we're not subscribed to, or + * someone who is offline. Let's inform the user */ + char *msg; - /* XXX: for now, send to the first resource available */ - if(jb->resources != NULL) { - char **who_v = g_strsplit(xfer->who, "/", 2); - char *who; + if(!jb) { + msg = g_strdup_printf(_("Unable to send file to %s, invalid JID"), xfer->who); + } else if(jb->subscription & JABBER_SUB_TO) { + msg = g_strdup_printf(_("Unable to send file to %s, user is not online"), xfer->who); + } else { + msg = g_strdup_printf(_("Unable to send file to %s, not subscribed to user presence"), xfer->who); + } + + purple_notify_error(jsx->js->gc, _("File Send Failed"), _("File Send Failed"), msg); + g_free(msg); + } else if(g_list_length(jb->resources) == 1) { + /* only 1 resource online (probably our most common case) + * so no need to ask who to send to */ + jbr = jb->resources->data; + + do_transfer_send(xfer, jbr->name); - jbr = jabber_buddy_find_resource(jb, NULL); - who = g_strdup_printf("%s/%s", who_v[0], jbr->name); - g_strfreev(who_v); - g_free(xfer->who); - xfer->who = who; - jabber_disco_info_do(jsx->js, who, - jabber_si_xfer_send_disco_cb, xfer); } else { - return; /* XXX: ick */ + /* we've got multiple resources, we need to pick one to send to */ + GList *l; + char *msg = g_strdup_printf(_("Please select which resource of %s you would like to send a file to"), xfer->who); + PurpleRequestFields *fields = purple_request_fields_new(); + PurpleRequestField *field = purple_request_field_choice_new("resource", _("Resource"), 0); + PurpleRequestFieldGroup *group = purple_request_field_group_new(NULL); + + for(l = jb->resources; l; l = l->next) + { + jbr = l->data; + + purple_request_field_choice_add(field, jbr->name); + } + + purple_request_field_group_add_field(group, field); + + purple_request_fields_add_group(fields, group); + + purple_request_fields(jsx->js->gc, _("Select a Resource"), msg, NULL, fields, + _("Send File"), G_CALLBACK(resource_select_ok_cb), _("Cancel"), G_CALLBACK(resource_select_cancel_cb), + jsx->js->gc->account, xfer->who, NULL, xfer); + + g_free(msg); } } else { xmlnode *si, *feature, *x, *field, *value;