cpw.malu.xmpp.jingle_ft: b8f11d58: Moved the resource selector from si.c to...
malu at pidgin.im
malu at pidgin.im
Mon Apr 27 17:11:09 EDT 2009
-----------------------------------------------------------------
Revision: b8f11d5868aace81a93f0e83596d988725042fdd
Ancestor: cb595deac9a6e3dc0213304db09b5e9410dd7616
Author: malu at pidgin.im
Date: 2009-04-27T21:08:40
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/b8f11d5868aace81a93f0e83596d988725042fdd
Modified files:
libpurple/protocols/jabber/si.c
libpurple/protocols/jabber/xfer.c
ChangeLog:
Moved the resource selector from si.c to xfer.c
So now you should be able to select resource to send to, even if the top
resource supports jingle ft :)
I hope I didn't break some stuff...
-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/si.c 0b9cb2b7d0ed245cb6ba7a1389cc76e0a0bf9e9f
+++ libpurple/protocols/jabber/si.c 23fb920eba2a6db495fb41ee59ac577cb187472b
@@ -1393,11 +1393,6 @@ static void jabber_si_xfer_send_disco_cb
}
}
-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;
@@ -1412,85 +1407,12 @@ static void do_transfer_send(PurpleXfer
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;
JabberIq *iq;
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);
- return;
- }
-
- jb = jabber_buddy_find(jsx->js, xfer->who, TRUE);
-
- 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;
-
- 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(!jb->resources->next) {
- /* 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);
-
- } else {
- /* we've got multiple resources, we need to pick one to send to */
- GList *l;
- char *msg = g_strdup_printf(_("Please select the resource of %s to which you would like to send a file"), 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);
- }
+ do_transfer_send(xfer, xfer->who);
} else {
xmlnode *si, *feature, *x, *field, *value;
============================================================
--- libpurple/protocols/jabber/xfer.c 073e8f138964b4b810a610216ab832b4ec009a3a
+++ libpurple/protocols/jabber/xfer.c b8410f49ab5492c5a76fe0fb9a2b061dd65653b5
@@ -16,6 +16,7 @@
#include "xfer.h"
#include "debug.h"
+#include "request.h"
#include "buddy.h"
#include "jingle/jingle.h"
#include "jingle/file-transfer.h"
@@ -54,9 +55,17 @@ jabber_xfer_new(PurpleConnection *gc, co
}
}
-void
-jabber_xfer_send(PurpleConnection *gc, const char *who, const char *file)
+typedef struct {
+ PurpleConnection *gc;
+ const gchar *who;
+ const gchar *file;
+} JabberXferData;
+
+static void
+jabber_xfer_send_to_resource(PurpleConnection *gc, const gchar *who,
+ const gchar *file)
{
+ purple_debug_info("jabber", "jabber_xfer_send_to_resource: %s\n", who);
if (jabber_xfer_support_jingle_ft(gc, who)) {
/* call jingle... */
jingle_file_transfer_send(gc, who, file);
@@ -64,6 +73,107 @@ jabber_xfer_send(PurpleConnection *gc, c
jabber_si_xfer_send(gc, who, file);
}
}
+
+static void
+jabber_xfer_resource_select_cancel_cb(JabberXferData *data,
+ PurpleRequestFields *fields)
+{
+ g_free(data);
+}
+
+static void
+jabber_xfer_resource_select_ok_cb(JabberXferData *data,
+ PurpleRequestFields *fields)
+{
+ PurpleConnection *gc = data->gc;
+ const gchar *who = data->who;
+ const gchar *file = data->file;
+ 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);
+ gchar *jid = g_strdup_printf("%s/%s", who, selected_label);
+
+ g_free(data);
+ jabber_xfer_send_to_resource(gc, jid, file);
+ g_free(jid);
+}
+
+void
+jabber_xfer_send(PurpleConnection *gc, const char *who, const char *file)
+{
+ JabberStream *js = (JabberStream *) purple_connection_get_protocol_data(gc);
+ JabberBuddy *jb = jabber_buddy_find(js, who, TRUE);
+ JabberBuddyResource *jbr = NULL;
+ gchar *resource = jabber_get_resource(who);
+
+ /* Let the user select a resource, unless "who" already contains one */
+ /* or there's only one resource online */
+ if (resource) {
+ /* who already contains a resource */
+ jabber_xfer_send_to_resource(gc, who, file);
+ g_free(resource);
+ } else 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;
+
+ if(!jb) {
+ msg = g_strdup_printf(_("Unable to send file to %s, invalid JID"),
+ who);
+ } else if(jb->subscription & JABBER_SUB_TO) {
+ msg = g_strdup_printf(_("Unable to send file to %s, user is not online"),
+ who);
+ } else {
+ msg = g_strdup_printf(_("Unable to send file to %s, not subscribed to user presence"),
+ who);
+ }
+
+ purple_notify_error(js->gc, _("File Send Failed"), _("File Send Failed"), msg);
+ g_free(msg);
+ } else if(!jb->resources->next) {
+ /* only 1 resource online (probably our most common case)
+ * so no need to ask who to send to */
+ gchar *jid = NULL;
+
+ jbr = jb->resources->data;
+ jid = g_strdup_printf("%s/%s", who, jbr->name);
+ jabber_xfer_send_to_resource(gc, jid, file);
+ g_free(jid);
+ } else {
+ /* we've got multiple resources, we need to pick one to send to */
+ GList *l;
+ char *msg = g_strdup_printf(_("Please select the resource of %s to which you would like to send a file"),
+ 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);
+ JabberXferData *data = g_new0(JabberXferData, 1);
+
+ data->gc = gc;
+ data->who = who;
+ data->file = g_strdup(file);
+
+ 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(js->gc, _("Select a Resource"), msg, NULL,
+ fields, _("Send File"), G_CALLBACK(jabber_xfer_resource_select_ok_cb),
+ _("Cancel"), G_CALLBACK(jabber_xfer_resource_select_cancel_cb),
+ js->gc->account, who, NULL, data);
+
+ g_free(msg);
+ }
+}
xmlnode *
jabber_xfer_create_file_element(const PurpleXfer *xfer)
More information about the Commits
mailing list