Mercurial > pidgin
changeset 7015:dece74f05509
[gaim-migrate @ 7578]
Further core/UI splittage. show_got_added() -> gaim_account_notify_added()
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 29 Sep 2003 15:28:20 +0000 |
parents | 67c4e9d39242 |
children | aa619031193b |
files | src/account.c src/account.h src/gtkaccount.c src/gtkaccount.h src/main.c src/protocols/jabber/presence.c src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/oscar/oscar.c src/protocols/yahoo/yahoo.c src/prpl.c src/prpl.h |
diffstat | 12 files changed, 182 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/src/account.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/account.c Mon Sep 29 15:28:20 2003 +0000 @@ -81,6 +81,9 @@ } AccountParserData; + +static GaimAccountUiOps *account_ui_ops = NULL; + static GList *accounts = NULL; static guint accounts_save_timer = 0; static gboolean accounts_loaded = FALSE; @@ -230,6 +233,22 @@ } void +gaim_account_notify_added(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, + const char *message) +{ + 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->notify_added != NULL) + ui_ops->notify_added(account, remote_user, id, alias, message); +} + +void gaim_account_set_username(GaimAccount *account, const char *username) { g_return_if_fail(account != NULL); @@ -1446,6 +1465,18 @@ return account; } +void +gaim_accounts_set_ui_ops(GaimAccountUiOps *ops) +{ + account_ui_ops = ops; +} + +GaimAccountUiOps * +gaim_accounts_get_ui_ops(void) +{ + return account_ui_ops; +} + void * gaim_accounts_get_handle(void) {
--- a/src/account.h Mon Sep 29 15:23:19 2003 +0000 +++ b/src/account.h Mon Sep 29 15:28:20 2003 +0000 @@ -25,7 +25,8 @@ #ifndef _GAIM_ACCOUNTS_H_ #define _GAIM_ACCOUNTS_H_ -typedef struct _GaimAccount GaimAccount; +typedef struct _GaimAccountUiOps GaimAccountUiOps; +typedef struct _GaimAccount GaimAccount; #include "connection.h" #include "proxy.h" @@ -39,6 +40,13 @@ DENY_SOME }; +struct _GaimAccountUiOps +{ + void (*notify_added)(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, + const char *message); +}; + struct _GaimAccount { char *username; /**< The username. */ @@ -119,6 +127,23 @@ void gaim_account_disconnect(GaimAccount *account); /** + * Notifies the user that the account was added to a remote user's + * buddy list. + * + * This will present a dialog so that the local user can add the buddy, + * if not already added. + * + * @param account The account that was added. + * @param remote_user The name of the user that added this account. + * @param id The optional ID of the local account. Rarely used. + * @param alias The optional alias of the user. + * @param message The optional message sent from the user adding you. + */ +void gaim_account_notify_added(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, + const char *message); + +/** * Sets the account's username. * * @param account The account. @@ -594,6 +619,20 @@ /*@{*/ /** + * Sets the UI operations structure to be used for accounts. + * + * @param ops The UI operations structure. + */ +void gaim_accounts_set_ui_ops(GaimAccountUiOps *ops); + +/** + * Returns the UI operations structure used for accounts. + * + * @return The UI operations structure in use. + */ +GaimAccountUiOps *gaim_accounts_get_ui_ops(void); + +/** * Returns the accounts subsystem handle. * * @return The accounts subsystem handle.
--- a/src/gtkaccount.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/gtkaccount.c Mon Sep 29 15:28:20 2003 +0000 @@ -26,6 +26,7 @@ #include "accountopt.h" #include "core.h" #include "debug.h" +#include "notify.h" #include "plugin.h" #include "prefs.h" #include "request.h" @@ -53,6 +54,14 @@ typedef struct { + GaimAccount *account; + char *username; + char *alias; + +} GaimGtkAccountAddUserData; + +typedef struct +{ GtkWidget *window; GtkWidget *treeview; @@ -1906,3 +1915,86 @@ gaim_core_quit(); } } + +static void +free_add_user_data(GaimGtkAccountAddUserData *data) +{ + g_free(data->username); + + if (data->alias != NULL) + g_free(data->alias); + + g_free(data); +} + +static void +add_user_cb(GaimGtkAccountAddUserData *data) +{ + GaimConnection *gc = gaim_account_get_connection(data->account); + + if (g_list_find(gaim_connections_get_all(), gc)) + show_add_buddy(gc, data->username, NULL, data->alias); + + free_add_user_data(data); +} + +static void +gaim_gtk_accounts_notify_added(GaimAccount *account, const char *remote_user, + const char *id, const char *alias, + const char *msg) +{ + char *buffer; + GaimConnection *gc; + GaimGtkAccountAddUserData *data; + GaimBuddy *buddy; + + gc = gaim_account_get_connection(account); + + buddy = gaim_find_buddy(account, remote_user); + + data = g_new0(GaimGtkAccountAddUserData, 1); + data->account = account; + data->username = g_strdup(remote_user); + data->alias = (alias != NULL ? g_strdup(alias) : NULL); + + buffer = g_strdup_printf(_("%s%s%s%s has made %s his or her buddy%s%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))), + (msg != NULL ? ": " : "."), + (msg != NULL ? msg : ""), + (buddy != NULL + ? "" + : _("\n\nDo you wish to add him or her to your buddy list?"))); + + if (buddy != NULL) + { + gaim_notify_info(NULL, NULL, _("Gaim - Information"), buffer); + } + else + { + gaim_request_action(NULL, NULL, _("Add buddy to your list?"), + buffer, 0, data, 2, + _("Add"), G_CALLBACK(add_user_cb), + _("Cancel"), G_CALLBACK(free_add_user_data)); + } + + g_free(buffer); +} + +static GaimAccountUiOps ui_ops = +{ + gaim_gtk_accounts_notify_added +}; + +GaimAccountUiOps * +gaim_gtk_accounts_get_ui_ops(void) +{ + return &ui_ops; +}
--- a/src/gtkaccount.h Mon Sep 29 15:23:19 2003 +0000 +++ b/src/gtkaccount.h Mon Sep 29 15:28:20 2003 +0000 @@ -5,7 +5,7 @@ * gaim * * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -52,5 +52,12 @@ void gaim_gtk_account_dialog_show(GaimGtkAccountDialogType type, GaimAccount *account); +/** + * Returns the GTK+ account UI ops + * + * @return The UI operations structure. + */ +GaimAccountUiOps *gaim_gtk_accounts_get_ui_ops(void); + #endif /* _GAIM_GTK_ACCOUNT_H_ */
--- a/src/main.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/main.c Mon Sep 29 15:28:20 2003 +0000 @@ -490,6 +490,7 @@ gaim_gtk_ui_init(void) { /* Set the UI operation structures. */ + gaim_accounts_set_ui_ops(gaim_gtk_accounts_get_ui_ops()); gaim_set_win_ui_ops(gaim_get_gtk_window_ui_ops()); gaim_set_xfer_ui_ops(gaim_get_gtk_xfer_ui_ops()); gaim_set_blist_ui_ops(gaim_get_gtk_blist_ui_ops());
--- a/src/protocols/jabber/presence.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/protocols/jabber/presence.c Mon Sep 29 15:28:20 2003 +0000 @@ -115,7 +115,7 @@ "subscribed"); if(!gaim_find_buddy(jap->gc->account, jap->who)) - show_got_added(jap->gc, NULL, jap->who, NULL, NULL); + gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); } g_free(jap->who); @@ -129,7 +129,7 @@ "unsubscribed"); if(!gaim_find_buddy(jap->gc->account, jap->who)) - show_got_added(jap->gc, NULL, jap->who, NULL, NULL); + gaim_account_notify_added(jap->gc->account, NULL, jap->who, NULL, NULL); } g_free(jap->who);
--- a/src/protocols/msn/msn.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/protocols/msn/msn.c Mon Sep 29 15:28:20 2003 +0000 @@ -1521,6 +1521,8 @@ { GaimAccountOption *option; + info.dependencies = g_list_append(info.dependencies, "core-ssl"); + option = gaim_account_option_string_new(_("Login server"), "server", MSN_SERVER); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
--- a/src/protocols/msn/notification.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/protocols/msn/notification.c Mon Sep 29 15:28:20 2003 +0000 @@ -182,8 +182,9 @@ gaim_privacy_permit_add(pa->gc->account, msn_user_get_passport(pa->user), TRUE); - show_got_added(pa->gc, NULL, msn_user_get_passport(pa->user), - msn_user_get_name(pa->user), NULL); + gaim_account_notify_added(pa->gc->account, NULL, + msn_user_get_passport(pa->user), + msn_user_get_name(pa->user), NULL); } msn_user_destroy(pa->user);
--- a/src/protocols/oscar/oscar.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/protocols/oscar/oscar.c Mon Sep 29 15:28:20 2003 +0000 @@ -2494,7 +2494,7 @@ message = 0; buddy = gaim_find_buddy(gc->account, data->name); aim_im_sendch4(od->sess, data->name, AIM_ICQMSG_AUTHGRANTED, &message); - show_got_added(gc, NULL, data->name, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL); + gaim_account_notify_added(gc->account, NULL, data->name, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL); #else aim_ssi_sendauthreply(od->sess, data->name, 0x01, NULL); #endif @@ -5119,7 +5119,7 @@ buddy = gaim_find_buddy(gc->account, sn); gaim_debug(GAIM_DEBUG_INFO, "oscar", "ssi: %s added you to their buddy list\n", sn); - show_got_added(gc, NULL, sn, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL); + gaim_account_notify_added(gc->account, NULL, sn, (buddy ? gaim_get_buddy_alias_only(buddy) : NULL), NULL); return 1; }
--- a/src/protocols/yahoo/yahoo.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/protocols/yahoo/yahoo.c Mon Sep 29 15:28:20 2003 +0000 @@ -722,7 +722,7 @@ } if (id) - show_got_added(gc, id, who, NULL, msg); + gaim_account_notify_added(gc->account, id, who, NULL, msg); } static void yahoo_buddy_denied_our_add(GaimConnection *gc, struct yahoo_packet *pkt)
--- a/src/prpl.c Mon Sep 29 15:23:19 2003 +0000 +++ b/src/prpl.c Mon Sep 29 15:28:20 2003 +0000 @@ -101,66 +101,3 @@ return NULL; } - -struct got_add { - GaimConnection *gc; - char *who; - char *alias; -}; - -static void dont_add(struct got_add *ga) -{ - g_free(ga->who); - if (ga->alias) - g_free(ga->alias); - g_free(ga); -} - -static void do_add(struct got_add *ga) -{ - if (g_list_find(gaim_connections_get_all(), ga->gc)) - show_add_buddy(ga->gc, ga->who, NULL, ga->alias); - dont_add(ga); -} - -void show_got_added(GaimConnection *gc, const char *id, - const char *who, const char *alias, const char *msg) -{ - GaimAccount *account; - char buf[BUF_LONG]; - struct got_add *ga; - GaimBuddy *b; - - account = gaim_connection_get_account(gc); - b = gaim_find_buddy(gc->account, who); - - ga = g_new0(struct got_add, 1); - ga->gc = gc; - ga->who = g_strdup(who); - ga->alias = (alias ? g_strdup(alias) : NULL); - - - g_snprintf(buf, sizeof(buf), _("%s%s%s%s has made %s his or her buddy%s%s%s"), - who, - alias ? " (" : "", - alias ? alias : "", - alias ? ")" : "", - (id - ? id - : (gaim_connection_get_display_name(gc) - ? gaim_connection_get_display_name(gc) - : gaim_account_get_username(account))), - msg ? ": " : ".", - msg ? msg : "", - b ? "" : _("\n\nDo you wish to add him or her to your buddy list?")); - - if (b) { - gaim_notify_info(NULL, NULL, _("Gaim - Information"), buf); - } - else - gaim_request_action(NULL, NULL, _("Add buddy to your list?"), buf, - 0, ga, 2, - _("Add"), G_CALLBACK(do_add), - _("Cancel"), G_CALLBACK(dont_add)); -} -
--- a/src/prpl.h Mon Sep 29 15:23:19 2003 +0000 +++ b/src/prpl.h Mon Sep 29 15:28:20 2003 +0000 @@ -349,19 +349,6 @@ */ GaimPlugin *gaim_find_prpl(GaimProtocol type); -/** - * Shows a message saying that somebody added you as a buddy, and asks - * if you would like to do the same. - * - * @param gc The gaim connection. - * @param id The ID of the user. - * @param who The username. - * @param alias The user's alias. - * @param msg The message to go along with the request. - */ -void show_got_added(GaimConnection *gc, const char *id, - const char *who, const char *alias, const char *msg); - #ifdef __cplusplus } #endif