changeset 15764:0869f00ca178

Add request_authorize to gaim-text's account ui ops
author Richard Nelson <wabz@pidgin.im>
date Sat, 03 Mar 2007 23:12:11 +0000
parents d318c6672011
children c7a7ea7c07a8 c6ad254c1b89
files console/gntaccount.c
diffstat 1 files changed, 89 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/console/gntaccount.c	Sat Mar 03 04:06:19 2007 +0000
+++ b/console/gntaccount.c	Sat Mar 03 23:12:11 2007 +0000
@@ -835,11 +835,98 @@
 	g_free(buffer);
 }
 
-static GaimAccountUiOps ui_ops = 
+/* Copied from gtkaccount.c */
+typedef struct {
+	GaimAccountRequestAuthorizationCb auth_cb;
+	GaimAccountRequestAuthorizationCb deny_cb;
+	void *data;
+	char *username;
+	char *alias;
+	GaimAccount *account;
+} auth_and_add;
+
+static void
+authorize_and_add_cb(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(auth_and_add *aa)
+{
+	aa->deny_cb(aa->data);
+
+	g_free(aa->username);
+	g_free(aa->alias);
+	g_free(aa);
+}
+
+static void *
+gg_request_authorize(GaimAccount *account, const char *remote_user,
+					const char *id, const char *alias, const char *message, gboolean on_list,
+					GCallback auth_cb, GCallback deny_cb, void *user_data)
+{
+	char *buffer;
+	GaimConnection *gc;
+	void *uihandle;
+
+	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 (!on_list) {
+		auth_and_add *aa = g_new(auth_and_add, 1);
+		aa->auth_cb = (GaimAccountRequestAuthorizationCb)auth_cb;
+		aa->deny_cb = (GaimAccountRequestAuthorizationCb)deny_cb;
+		aa->data = user_data;
+		aa->username = g_strdup(remote_user);
+		aa->alias = g_strdup(alias);
+		aa->account = account;
+		uihandle = gaim_request_action(NULL, _("Authorize buddy?"), buffer, NULL,
+			GAIM_DEFAULT_ACTION_NONE, aa, 2,
+			_("Authorize"), authorize_and_add_cb,
+			_("Deny"), deny_no_add_cb);
+	} else {
+		uihandle = gaim_request_action(NULL, _("Authorize buddy?"), buffer, NULL,
+			GAIM_DEFAULT_ACTION_NONE, user_data, 2,
+			_("Authorize"), auth_cb,
+			_("Deny"), deny_cb);
+	}
+	g_free(buffer);
+	return uihandle;
+}
+
+static void
+gg_request_close(void *uihandle)
+{
+	gaim_request_close(GAIM_REQUEST_ACTION, uihandle);
+}
+
+static GaimAccountUiOps ui_ops =
 {
 	.notify_added = notify_added,
 	.status_changed = NULL,
-	.request_add  = request_add
+	.request_add  = request_add,
+	.request_authorize = gg_request_authorize,
+	.close_account_request = gg_request_close
 };
 
 GaimAccountUiOps *gg_accounts_get_ui_ops()