changeset 18920:2a9d60d7af82

Implemented a callback for unregistering, mirroring the registration callback. Since this is a new API, I can do it properly by passing it right in the unregister function call, instead of having a separate function for setting it.
author Andreas Monitzer <pidgin@monitzer.com>
date Tue, 31 Jul 2007 03:50:41 +0000
parents 177552010f1d
children ba3b22cd280b
files libpurple/account.c libpurple/account.h libpurple/connection.c libpurple/connection.h libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/prpl.h
diffstat 7 files changed, 24 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/account.c	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/account.c	Tue Jul 31 03:50:41 2007 +0000
@@ -933,14 +933,14 @@
 }
 
 void
-purple_account_unregister(PurpleAccount *account)
+purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data)
 {
 	g_return_if_fail(account != NULL);
 	
 	purple_debug_info("account", "Unregistering account %s\n",
 					  purple_account_get_username(account));
 	
-	purple_connection_new_unregister(account, purple_account_get_password(account));
+	purple_connection_new_unregister(account, purple_account_get_password(account), cb, user_data);
 }
 
 static void
--- a/libpurple/account.h	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/account.h	Tue Jul 31 03:50:41 2007 +0000
@@ -37,6 +37,7 @@
 typedef gboolean (*PurpleFilterAccountFunc)(PurpleAccount *account);
 typedef void (*PurpleAccountRequestAuthorizationCb)(void *);
 typedef void (*PurpleAccountRegistrationCb)(PurpleAccount *account, gboolean succeeded, void *user_data);
+typedef void (*PurpleAccountUnregistrationCb)(PurpleAccount *account, gboolean succeeded, void *user_data);
 
 #include "connection.h"
 #include "log.h"
@@ -164,8 +165,10 @@
  * Unregisters an account (deleting it from the server).
  *
  * @param account The account to unregister.
+ * @param cb Optional callback to be called when unregistration is complete
+ * @param user_data user data to pass to the callback
  */
-void purple_account_unregister(PurpleAccount *account);
+void purple_account_unregister(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data);
 
 /**
  * Disconnects from an account.
--- a/libpurple/connection.c	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/connection.c	Tue Jul 31 03:50:41 2007 +0000
@@ -158,7 +158,7 @@
 }
 
 void
-purple_connection_new_unregister(PurpleAccount *account, const char *password)
+purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data)
 {
 	/* Lots of copy/pasted code to avoid API changes. You might want to integrate that into the previous function when posssible. */
 	PurpleConnection *gc;
@@ -182,7 +182,7 @@
 	}
 
 	if (!purple_account_is_disconnected(account)) {
-		prpl_info->unregister_user(account);
+		prpl_info->unregister_user(account, cb, user_data);
 		return;
 	}
 	
@@ -210,7 +210,7 @@
 	
 	purple_debug_info("connection", "Unregistering.  gc = %p\n", gc);
 	
-	prpl_info->unregister_user(account);
+	prpl_info->unregister_user(account, cb, user_data);
 }
 
 void
--- a/libpurple/connection.h	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/connection.h	Tue Jul 31 03:50:41 2007 +0000
@@ -143,7 +143,7 @@
  * @param account  The account to unregister
  * @param password The password to use.
  */
-void purple_connection_new_unregister(PurpleAccount *account, const char *password);
+void purple_connection_new_unregister(PurpleAccount *account, const char *password, PurpleAccountUnregistrationCb cb, void *user_data);
 
 /**
  * Disconnects and destroys a PurpleConnection.
--- a/libpurple/protocols/jabber/jabber.c	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Tue Jul 31 03:50:41 2007 +0000
@@ -1120,6 +1120,7 @@
 }
 
 static void jabber_unregister_account_iq_cb(JabberStream *js, xmlnode *packet, gpointer data) {
+	PurpleAccount *account = purple_connection_get_account(js->gc);
 	const char *type = xmlnode_get_attrib(packet,"type");
 	if(!strcmp(type,"error")) {
 		char *msg = jabber_parse_error(js, packet);
@@ -1127,9 +1128,13 @@
 		purple_notify_error(js->gc, _("Error unregistering account"),
 							_("Error unregistering account"), msg);
 		g_free(msg);
+		if(js->unregistration_cb)
+			js->unregistration_cb(account, TRUE, js->unregistration_user_data);
 	} else if(!strcmp(type,"result")) {
 		purple_notify_info(js->gc, _("Account successfully unregistered"),
 						   _("Account successfully unregistered"), NULL);
+		if(js->unregistration_cb)
+			js->unregistration_cb(account, FALSE, js->unregistration_user_data);
 	}
 }
 
@@ -1150,7 +1155,7 @@
 	jabber_iq_send(iq);
 }
 
-void jabber_unregister_account(PurpleAccount *account) {
+void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data) {
 	PurpleConnection *gc = purple_account_get_connection(account);
 	JabberStream *js;
 	
@@ -1159,12 +1164,16 @@
 			jabber_login(account);
 		js = gc->proto_data;
 		js->unregistration = TRUE;
+		js->unregistration_cb = cb;
+		js->unregistration_user_data = user_data;
 		return;
 	}
 	
 	js = gc->proto_data;
 	assert(!js->unregistration); /* don't allow multiple calls */
 	js->unregistration = TRUE;
+	js->unregistration_cb = cb;
+	js->unregistration_user_data = user_data;
 	
 	jabber_unregister_account_cb(js);
 }
--- a/libpurple/protocols/jabber/jabber.h	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Tue Jul 31 03:50:41 2007 +0000
@@ -160,6 +160,8 @@
 	char *serverFQDN;
 	
 	gboolean unregistration;
+	PurpleAccountUnregistrationCb unregistration_cb;
+	void *unregistration_user_data;
 	
 	gboolean vcard_fetched;
 	
@@ -227,7 +229,7 @@
 void jabber_keepalive(PurpleConnection *gc);
 void jabber_register_gateway(JabberStream *js, const char *gateway);
 void jabber_register_account(PurpleAccount *account);
-void jabber_unregister_account(PurpleAccount *account);
+void jabber_unregister_account(PurpleAccount *account, PurpleAccountUnregistrationCb cb, void *user_data);
 void jabber_convo_closed(PurpleConnection *gc, const char *who);
 PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name);
 gboolean jabber_offline_message(const PurpleBuddy *buddy);
--- a/libpurple/prpl.h	Mon Jul 30 00:05:02 2007 +0000
+++ b/libpurple/prpl.h	Tue Jul 31 03:50:41 2007 +0000
@@ -328,7 +328,7 @@
 	 * The account can either be connected or disconnected. After the removal is finished,
 	 * the connection will stay open and has to be closed!
 	 */
-	void (*unregister_user)(PurpleAccount *);
+	void (*unregister_user)(PurpleAccount *, PurpleAccountUnregistrationCb cb, void *user_data);
 	
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);