# HG changeset patch # User Sean Egan # Date 1164762801 0 # Node ID f227feab8c782ad3d17434251fe9a302a618c31c # Parent e8ba9f4a3a7dfdad715774dc4ed21f1ac34b1631 [gaim-migrate @ 17841] Ok... let's throw this to the wild. Support for "So-and-so want's authorization" in the core. It creates a new mini-dialog in the blist for this with an Authorize and Deny button, which do as you might imagine. Clicking Authorize will also spawn an "Add buddy" dialog if that person isn't already a buddy. I'm not sure I like this, since I never add buddies that I authorize, but it seems the best option. I considered a checkbox in the dialog (but it only applies when you hit "Authorize," which could be weird), and a third "Authorize and Add" button (but that was too big for the blist). I'll come back to the UI later, I'm sure. I'd like to see that the prpl changes all work. Yahoo, especially, looked confusing, and had the most changes. I'm mostly happy with this. committer: Tailor Script diff -r e8ba9f4a3a7d -r f227feab8c78 gtk/gtkaccount.c --- a/gtk/gtkaccount.c Tue Nov 28 21:29:12 2006 +0000 +++ b/gtk/gtkaccount.c Wed Nov 29 01:13:21 2006 +0000 @@ -2358,20 +2358,104 @@ data->alias = g_strdup(alias); buffer = make_info(account, gc, remote_user, id, alias, msg); - alert = gaim_gtk_make_mini_dialog(gc, GAIM_STOCK_DIALOG_INFO, + alert = gaim_gtk_make_mini_dialog(gc, GAIM_STOCK_DIALOG_QUESTION, _("Add buddy to your list?"), buffer, data, - _("Cancel"), G_CALLBACK(free_add_user_data), - _("Add"), G_CALLBACK(add_user_cb), NULL); + _("Add"), G_CALLBACK(add_user_cb), + _("Cancel"), G_CALLBACK(free_add_user_data), NULL); gaim_gtk_blist_add_alert(alert); g_free(buffer); } +struct auth_and_add { + void(*auth_cb)(void*); + void(*deny_cb)(void*); + void *data; + char *username; + char *alias; + GaimAccount *account; +}; + +static void +authorize_and_add_cb(struct auth_and_add *aa) +{ + aa->auth_cb(aa->data); + gaim_blist_request_add_buddy(aa->account, aa->username, + NULL, aa->alias); + + g_free(aa->username); + g_free(aa->alias); + g_free(aa); +} + +static void +deny_no_add_cb(struct auth_and_add *aa) +{ + aa->deny_cb(aa->data); + + g_free(aa->username); + g_free(aa->alias); + g_free(aa); +} + +static void +gaim_gtk_accounts_request_authorization(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, const char *message, + GCallback auth_cb, GCallback deny_cb, void *user_data) +{ + char *buffer; + GaimConnection *gc; + GtkWidget *alert; + + gc = gaim_account_get_connection(account); + if (message != NULL && *message == '\0') + message = NULL; + + buffer = g_strdup_printf(_("%s%s%s%s wants to add %s to his or her buddy list%s%s"), + remote_user, + (alias != NULL ? " (" : ""), + (alias != NULL ? alias : ""), + (alias != NULL ? ")" : ""), + (id != NULL + ? id + : (gaim_connection_get_display_name(gc) != NULL + ? gaim_connection_get_display_name(gc) + : gaim_account_get_username(account))), + (message != NULL ? ": " : "."), + (message != NULL ? message : "")); + + + if (!gaim_find_buddy(account, remote_user)) { + struct auth_and_add *aa = g_new0(struct auth_and_add, 1); + aa->auth_cb = auth_cb; + aa->deny_cb = deny_cb; + aa->data = user_data; + aa->username = g_strdup(remote_user); + aa->alias = g_strdup(alias); + aa->account = account; + alert = gaim_gtk_make_mini_dialog(gc, GAIM_STOCK_DIALOG_QUESTION, + _("Authorize buddy?"), buffer, aa, + _("Authorize"), authorize_and_add_cb, + _("Deny"), deny_no_add_cb, + NULL); + } else { + alert = gaim_gtk_make_mini_dialog(gc, GAIM_STOCK_DIALOG_QUESTION, + _("Authorize buddy?"), buffer, user_data, + _("Authorize"), auth_cb, + _("Deny"), deny_cb, + NULL); + } + gaim_gtk_blist_add_alert(alert); + + g_free(buffer); +} + static GaimAccountUiOps ui_ops = { gaim_gtk_accounts_notify_added, NULL, - gaim_gtk_accounts_request_add + gaim_gtk_accounts_request_add, + gaim_gtk_accounts_request_authorization }; GaimAccountUiOps * diff -r e8ba9f4a3a7d -r f227feab8c78 gtk/gtkscrollbook.c --- a/gtk/gtkscrollbook.c Tue Nov 28 21:29:12 2006 +0000 +++ b/gtk/gtkscrollbook.c Wed Nov 29 01:13:21 2006 +0000 @@ -114,7 +114,7 @@ static void -page_count_change_cb(GtkNotebook *notebook, GtkGaimScrollBook *scroll_book) +page_count_change_cb(GtkGaimScrollBook *scroll_book) { int index = gtk_notebook_get_current_page(GTK_NOTEBOOK(scroll_book->notebook)); #if GTK_CHECK_VERSION(2,2,0) @@ -183,7 +183,7 @@ gtk_box_pack_start(GTK_BOX(scroll_book), scroll_book->notebook, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT(scroll_book->notebook), "add", G_CALLBACK(page_count_change_cb), scroll_book); + g_signal_connect_swapped(G_OBJECT(scroll_book->notebook), "add", G_CALLBACK(page_count_change_cb), scroll_book); g_signal_connect(G_OBJECT(scroll_book->notebook), "remove", G_CALLBACK(page_count_change_cb), scroll_book); g_signal_connect(G_OBJECT(scroll_book->notebook), "switch-page", G_CALLBACK(switch_page_cb), scroll_book); gtk_widget_hide(scroll_book->hbox); diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/account.c --- a/libgaim/account.c Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/account.c Wed Nov 29 01:13:21 2006 +0000 @@ -1051,6 +1051,23 @@ ui_ops->request_add(account, remote_user, id, alias, message); } +void +gaim_account_request_authorization(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, const char *message, + GCallback auth_cb, GCallback deny_cb, void *user_data) +{ + GaimAccountUiOps *ui_ops; + + g_return_if_fail(account != NULL); + g_return_if_fail(remote_user != NULL); + + ui_ops = gaim_accounts_get_ui_ops(); + + if (ui_ops != NULL && ui_ops->request_authorize != NULL) + ui_ops->request_authorize(account, remote_user, id, alias, message, auth_cb, deny_cb, user_data); + +} + static void change_password_cb(GaimAccount *account, GaimRequestFields *fields) { diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/account.h --- a/libgaim/account.h Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/account.h Wed Nov 29 01:13:21 2006 +0000 @@ -27,6 +27,7 @@ #ifndef _GAIM_ACCOUNT_H_ #define _GAIM_ACCOUNT_H_ +#include #include typedef struct _GaimAccountUiOps GaimAccountUiOps; @@ -51,6 +52,9 @@ void (*request_add)(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message); + void (*request_authorize)(GaimAccount *account, const char *remote_user, const char *id, + const char *alias, const char *message, + GCallback authorize_cb, GCallback deny_cb, void *user_data); }; struct _GaimAccount @@ -170,6 +174,27 @@ void gaim_account_request_add(GaimAccount *account, const char *remote_user, const char *id, const char *alias, const char *message); + +/** + * Notifies the user that a remote user has wants to add the local user + * to his or her buddy list and requires authorization to d oso. + * + * This will present a dialog informing the usre of this and ask if the + * user authorizes or denies the remote user from adding him. + * + * @param account The account that was added + * @param remote_user The name of the usre that added this account. + * @param id The optional ID of the local account. Rarely used. + * @param alias The optional alias of the remote user. + * @param message The optional message sent from the uer requesting you + * @param auth_cb The callback called when the local user accepts + * @param deny_cb The callback called when the local user rejects + * @param user_data Data to be passed back to the above callbacks + */ +void gaim_account_request_authorization(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, const char *message, + GCallback auth_cb, GCallback deny_cb, void *user_data); + /** * Requests information from the user to change the account's password. * diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/protocols/jabber/presence.c --- a/libgaim/protocols/jabber/presence.c Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/protocols/jabber/presence.c Wed Nov 29 01:13:21 2006 +0000 @@ -181,32 +181,8 @@ static void authorize_add_cb(struct _jabber_add_permit *jap) { - GaimBuddy *buddy = NULL; - jabber_presence_subscription_set(jap->gc->proto_data, jap->who, "subscribed"); -#if 0 - buddy = gaim_find_buddy(jap->gc->account, jap->who); - - if (buddy) { - JabberBuddy *jb = NULL; - - jb = jabber_buddy_find(jap->js, jap->who, TRUE); - - if ((jb->subscription & JABBER_SUB_TO) == 0) { - gaim_account_request_add(jap->gc->account, - jap->who, NULL, - NULL, NULL); - } else { - gaim_account_notify_added(jap->gc->account, - jap->who, NULL, - NULL, NULL); - } - } else { - gaim_account_request_add(jap->gc->account, jap->who, - NULL, NULL, NULL); - } -#endif g_free(jap->who); g_free(jap); } @@ -304,20 +280,13 @@ jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence")); } else if(type && !strcmp(type, "subscribe")) { struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1); - char *msg; - msg = g_strdup_printf(_("The user %s wants to add %s to his or " - "her buddy list."), - from, gaim_account_get_username(js->gc->account)); jap->gc = js->gc; jap->who = g_strdup(from); jap->js = js; - gaim_request_action(js->gc, NULL, msg, NULL, GAIM_DEFAULT_ACTION_NONE, - jap, 2, - _("_Authorize"), G_CALLBACK(authorize_add_cb), - _("_Deny"), G_CALLBACK(deny_add_cb)); - g_free(msg); + gaim_account_request_authorization(gaim_connection_get_account(js->gc), from, NULL, NULL, NULL, + G_CALLBACK(authorize_add_cb), G_CALLBACK(deny_add_cb), jap); jabber_id_free(jid); return; } else if(type && !strcmp(type, "subscribed")) { diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/protocols/msn/userlist.c --- a/libgaim/protocols/msn/userlist.c Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/protocols/msn/userlist.c Wed Nov 29 01:13:21 2006 +0000 @@ -42,19 +42,9 @@ { MsnSession *session = pa->gc->proto_data; MsnUserList *userlist = session->userlist; - GaimBuddy *buddy; msn_userlist_add_buddy(userlist, pa->who, MSN_LIST_AL, NULL); - buddy = gaim_find_buddy(pa->gc->account, pa->who); - - if (buddy != NULL) - gaim_account_notify_added(pa->gc->account, pa->who, - NULL, pa->friendly, NULL); - else - gaim_account_request_add(pa->gc->account, pa->who, - NULL, pa->friendly, NULL); - g_free(pa->who); g_free(pa->friendly); g_free(pa); @@ -77,35 +67,14 @@ got_new_entry(GaimConnection *gc, const char *passport, const char *friendly) { MsnPermitAdd *pa; - char *msg; pa = g_new0(MsnPermitAdd, 1); pa->who = g_strdup(passport); pa->friendly = g_strdup(friendly); pa->gc = gc; - - if (friendly != NULL) - { - msg = g_strdup_printf( - _("The user %s (%s) wants to add %s to his or her " - "buddy list."), - passport, friendly, - gaim_account_get_username(gc->account)); - } - else - { - msg = g_strdup_printf( - _("The user %s wants to add %s to his or " - "her buddy list."), - passport, gaim_account_get_username(gc->account)); - } - - gaim_request_action(gc, NULL, msg, NULL, - GAIM_DEFAULT_ACTION_NONE, pa, 2, - _("Authorize"), G_CALLBACK(msn_accept_add_cb), - _("Deny"), G_CALLBACK(msn_cancel_add_cb)); - - g_free(msg); + + gaim_account_request_authorization(gaim_connection_get_account(gc), passport, NULL, friendly, NULL, + msn_accept_add_cb, msn_cancel_add_cb, pa); } /************************************************************************** diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/protocols/oscar/oscar.c --- a/libgaim/protocols/oscar/oscar.c Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/protocols/oscar/oscar.c Wed Nov 29 01:13:21 2006 +0000 @@ -2317,30 +2317,22 @@ struct name_data *data = g_new(struct name_data, 1); gchar *sn = g_strdup_printf("%u", args->uin); gchar *reason; - gchar *dialog_msg; if (msg2[5] != NULL) reason = gaim_plugin_oscar_decode_im_part(account, sn, AIM_CHARSET_CUSTOM, 0x0000, msg2[5], strlen(msg2[5])); else - reason = g_strdup(_("No reason given.")); - - dialog_msg = g_strdup_printf(_("The user %u wants to add %s to their buddy list for the following reason:\n%s"), - args->uin, gaim_account_get_username(gc->account), reason); - g_free(reason); + reason = NULL; + gaim_debug_info("oscar", "Received an authorization request from UIN %u\n", args->uin); data->gc = gc; data->name = sn; data->nick = NULL; - - gaim_request_action(gc, NULL, _("Authorization Request"), - dialog_msg, GAIM_DEFAULT_ACTION_NONE, data, - 2, _("_Authorize"), - G_CALLBACK(gaim_auth_grant), - _("_Deny"), - G_CALLBACK(gaim_auth_dontgrant_msgprompt)); - g_free(dialog_msg); + + gaim_account_request_authorization(gaim_connection_get_account(gc), sn, NULL, NULL, reason, + G_CALLBACK(gaim_auth_grant), G_CALLBACK(gaim_auth_dontgrant_msgprompt), data); + g_free(reason); } } break; @@ -5014,7 +5006,6 @@ GaimAccount *account = gaim_connection_get_account(gc); gchar *nombre; gchar *reason = NULL; - gchar *dialog_msg; struct name_data *data; GaimBuddy *buddy; @@ -5035,26 +5026,15 @@ if (msg != NULL) reason = gaim_plugin_oscar_decode_im_part(account, sn, AIM_CHARSET_CUSTOM, 0x0000, msg, strlen(msg)); - if (reason == NULL) - reason = g_strdup(_("No reason given.")); - - dialog_msg = g_strdup_printf( - _("The user %s wants to add %s to their buddy list for the following reason:\n%s"), - nombre, gaim_account_get_username(account), reason); - g_free(reason); - data = g_new(struct name_data, 1); data->gc = gc; data->name = g_strdup(sn); data->nick = NULL; - gaim_request_action(gc, NULL, _("Authorization Request"), dialog_msg, - GAIM_DEFAULT_ACTION_NONE, data, 2, - _("_Authorize"), G_CALLBACK(gaim_auth_grant), - _("_Deny"), G_CALLBACK(gaim_auth_dontgrant_msgprompt)); - - g_free(dialog_msg); + gaim_account_request_authorization(gaim_connection_get_account(gc), nombre, NULL, NULL, reason, + G_CALLBACK(gaim_auth_grant), G_CALLBACK(gaim_auth_dontgrant_msgprompt), data); g_free(nombre); + g_free(reason); return 1; } diff -r e8ba9f4a3a7d -r f227feab8c78 libgaim/protocols/yahoo/yahoo.c --- a/libgaim/protocols/yahoo/yahoo.c Tue Nov 28 21:29:12 2006 +0000 +++ b/libgaim/protocols/yahoo/yahoo.c Wed Nov 29 01:13:21 2006 +0000 @@ -910,16 +910,7 @@ }; static void -yahoo_buddy_add_authorize_cb(struct yahoo_add_request *add_req, const char *msg) { - GaimBuddy *buddy = gaim_find_buddy(add_req->gc->account, add_req->who); - - if (buddy != NULL) - gaim_account_notify_added(add_req->gc->account, add_req->who, - add_req->id, NULL, add_req->msg); - else - gaim_account_request_add(add_req->gc->account, add_req->who, - add_req->id, NULL, add_req->msg); - +yahoo_buddy_add_authorize_cb(struct yahoo_add_request *add_req) { g_free(add_req->id); g_free(add_req->who); g_free(add_req->msg); @@ -956,6 +947,20 @@ g_free(add_req); } +static void +yahoo_buddy_add_deny_noreason_cb(struct yahoo_add_request *add_req, const char*msg) +{ + yahoo_buddy_add_deny_cb(add_req, NULL); +} + +static void +yahoo_buddy_add_deny_reason_cb(struct yahoo_add_request *add_req) { + gaim_request_input(add_req->gc, NULL, _("Authorization denied message:"), + NULL, _("No reason given."), TRUE, FALSE, NULL, + _("OK"), G_CALLBACK(yahoo_buddy_add_deny_cb), + _("Cancel"), G_CALLBACK(yahoo_buddy_add_deny_noreason_cb), add_req); +} + static void yahoo_buddy_added_us(GaimConnection *gc, struct yahoo_packet *pkt) { struct yahoo_add_request *add_req; char *msg = NULL; @@ -984,27 +989,16 @@ } if (add_req->id) { - char *prompt_msg; if (msg) add_req->msg = yahoo_string_decode(gc, msg, FALSE); - /* TODO: this is almost exactly the same as what MSN does, + /* DONE! this is almost exactly the same as what MSN does, * this should probably be moved to the core. */ - prompt_msg = g_strdup_printf(_("The user %s wants to add %s to " - "his or her buddy list%s%s."), - add_req->who, add_req->id, - add_req->msg ? ": " : "", - add_req->msg ? add_req->msg : ""); - gaim_request_input(gc, NULL, prompt_msg, - _("Message (optional) :"), - NULL, TRUE, FALSE, NULL, - _("Authorize"), G_CALLBACK( - yahoo_buddy_add_authorize_cb), - _("Deny"), G_CALLBACK( - yahoo_buddy_add_deny_cb), - add_req); - g_free(prompt_msg); + gaim_account_request_authorization(gaim_connection_get_account(gc), add_req->who, add_req->id, + NULL, add_req->msg, G_CALLBACK(yahoo_buddy_add_authorize_cb), + G_CALLBACK(yahoo_buddy_add_deny_reason_cb), + add_req); } else { g_free(add_req->id); g_free(add_req->who);