/soc/2013/ankitkv/gobjectification: d971efd6f8bd: Refactored mai...

Ankit Vani a at nevitus.org
Thu Sep 19 07:09:33 EDT 2013


Changeset: d971efd6f8bda66c0553ef2806f85c97af936bab
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-19 16:38 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d971efd6f8bd

Description:

Refactored mailchk, pidgininc, raw pidgin plugins to use the new plugin API

diffstat:

 pidgin/plugins/mailchk.c   |  75 +++++++++++++++++++-----------------------
 pidgin/plugins/pidgininc.c |  82 +++++++++++++++++++--------------------------
 pidgin/plugins/raw.c       |  78 ++++++++++++++++++++-----------------------
 3 files changed, 105 insertions(+), 130 deletions(-)

diffs (truncated from 377 to 300 lines):

diff --git a/pidgin/plugins/mailchk.c b/pidgin/plugins/mailchk.c
--- a/pidgin/plugins/mailchk.c
+++ b/pidgin/plugins/mailchk.c
@@ -7,7 +7,8 @@
 #include "gtkblist.h"
 #include "gtkplugin.h"
 
-#define MAILCHK_PLUGIN_ID "gtk-mailchk"
+#define MAILCHK_PLUGIN_ID      "gtk-mailchk"
+#define MAILCHK_PLUGIN_DOMAIN  (g_quark_from_static_string(MAILCHK_PLUGIN_ID))
 
 #define ANY_MAIL    0x01
 #define UNREAD_MAIL 0x02
@@ -60,7 +61,7 @@ check_timeout(gpointer data)
 	if (count == -1)
 		return FALSE;
 
-	if (!list || !PURPLE_IS_GTK_BLIST(list) || !(PIDGIN_BLIST(list)->vbox))
+	if (!list || !(PIDGIN_BLIST(list)->vbox))
 		return TRUE;
 
 	if (!mail) {
@@ -91,7 +92,7 @@ static void
 signon_cb(PurpleConnection *gc)
 {
 	PurpleBuddyList *list = purple_blist_get_buddy_list();
-	if (list && PURPLE_IS_GTK_BLIST(list) && !timer) {
+	if (list && !timer) {
 		check_timeout(NULL); /* we want the box to be drawn immediately */
 		timer = purple_timeout_add_seconds(2, check_timeout, NULL);
 	}
@@ -101,7 +102,7 @@ static void
 signoff_cb(PurpleConnection *gc)
 {
 	PurpleBuddyList *list = purple_blist_get_buddy_list();
-	if ((!list || !PURPLE_IS_GTK_BLIST(list) || !PIDGIN_BLIST(list)->vbox) && timer) {
+	if ((!list || !PIDGIN_BLIST(list)->vbox) && timer) {
 		purple_timeout_remove(timer);
 		timer = 0;
 	}
@@ -111,18 +112,42 @@ signoff_cb(PurpleConnection *gc)
  *  EXPORTED FUNCTIONS
  */
 
+static PidginPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Eric Warmenhoven <eric at warmenhoven.org>",
+		NULL
+	};
+
+	return pidgin_plugin_info_new(
+		"id",           MAILCHK_PLUGIN_ID,
+		"name",         N_("Mail Checker"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("Utility"),
+		"summary",      N_("Checks for new local mail."),
+		"description",  N_("Adds a small box to the buddy list that shows if "
+		                   "you have new mail."),
+		"authors",      authors,
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	PurpleBuddyList *list = purple_blist_get_buddy_list();
 	void *conn_handle = purple_connections_get_handle();
 
 	if (!check_timeout(NULL)) {
-		purple_debug_warning("mailchk", "Could not read $MAIL or /var/spool/mail/$USER\n");
+		g_set_error(error, MAILCHK_PLUGIN_DOMAIN, 0, _("Could not read $MAIL "
+				"or /var/spool/mail/$USER\n"));
 		return FALSE;
 	}
 
-	if (list && PURPLE_IS_GTK_BLIST(list) && PIDGIN_BLIST(list)->vbox)
+	if (list && PIDGIN_BLIST(list)->vbox)
 		timer = purple_timeout_add_seconds(2, check_timeout, NULL);
 
 	purple_signal_connect(conn_handle, "signed-on",
@@ -134,7 +159,7 @@ plugin_load(PurplePlugin *plugin)
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	if (timer)
 		purple_timeout_remove(timer);
@@ -146,36 +171,4 @@ plugin_unload(PurplePlugin *plugin)
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,
-	PIDGIN_PLUGIN_TYPE,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	MAILCHK_PLUGIN_ID,
-	N_("Mail Checker"),
-	DISPLAY_VERSION,
-	N_("Checks for new local mail."),
-	N_("Adds a small box to the buddy list that"
-	   " shows if you have new mail."),
-	"Eric Warmenhoven <eric at warmenhoven.org>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	plugin_unload,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
-}
-
-PURPLE_INIT_PLUGIN(mailchk, init_plugin, info)
+PURPLE_PLUGIN_INIT(mailchk, plugin_query, plugin_load, plugin_unload);
diff --git a/pidgin/plugins/pidgininc.c b/pidgin/plugins/pidgininc.c
--- a/pidgin/plugins/pidgininc.c
+++ b/pidgin/plugins/pidgininc.c
@@ -48,18 +48,45 @@ reverse(PurpleAccount *account, char **w
 static void
 bud(PurpleBuddy *who)
 {
-	PurpleAccount *acct = who->account;
-	PurpleConversation *conv = purple_im_conversation_new(acct, who->name);
+	PurpleAccount *acct = purple_buddy_get_account(who);
+	PurpleIMConversation *im = purple_im_conversation_new(acct,
+			purple_buddy_get_name(who));
 
-	purple_im_conversation_send(PURPLE_CONV_IM(conv), "Hello!");
+	purple_conversation_send(PURPLE_CONVERSATION(im), "Hello!");
 }
 
 /*
  *  EXPORTED FUNCTIONS
  */
 
+static PidginPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Eric Warmenhoven <eric at warmenhoven.org>",
+		NULL
+	};
+
+	return pidgin_plugin_info_new(
+		"id",           PURPLEINC_PLUGIN_ID,
+		"name",         N_("Pidgin Demonstration Plugin"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("Example"),
+		"summary",      N_("An example plugin that does stuff - see the description."),
+		"description",  N_("This is a really cool plugin that does a lot of stuff:\n"
+		                   "- It tells you who wrote the program when you log in\n"
+		                   "- It reverses all incoming text\n"
+		                   "- It sends a message to people on your list immediately"
+		                   " when they sign on"),
+		"authors",      authors,
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	/* this is for doing something fun when we sign on */
 	purple_signal_connect(purple_connections_get_handle(), "signed-on",
@@ -76,49 +103,10 @@ plugin_load(PurplePlugin *plugin)
 	return TRUE;
 }
 
-static PurplePluginInfo info =
+static gboolean
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,                             /**< type           */
-	NULL,                                             /**< ui_requirement */
-	0,                                                /**< flags          */
-	NULL,                                             /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
-
-	PURPLEINC_PLUGIN_ID,                                /**< id             */
-	N_("Pidgin Demonstration Plugin"),                  /**< name           */
-	DISPLAY_VERSION,                                  /**< version        */
-	                                                  /**  summary        */
-	N_("An example plugin that does stuff - see the description."),
-	                                                  /**  description    */
-	N_("This is a really cool plugin that does a lot of stuff:\n"
-	   "- It tells you who wrote the program when you log in\n"
-	   "- It reverses all incoming text\n"
-	   "- It sends a message to people on your list immediately"
-	   " when they sign on"),
-	"Eric Warmenhoven <eric at warmenhoven.org>",        /**< author         */
-	PURPLE_WEBSITE,                                     /**< homepage       */
-
-	plugin_load,                                      /**< load           */
-	NULL,                                             /**< unload         */
-	NULL,                                             /**< destroy        */
-
-	NULL,                                             /**< ui_info        */
-	NULL,                                             /**< extra_info     */
-	NULL,                                             /**< prefs_info     */
-	NULL,                                             /**< actions        */
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
+	return TRUE;
 }
 
-PURPLE_INIT_PLUGIN(purpleinc, init_plugin, info)
+PURPLE_PLUGIN_INIT(purpleinc, plugin_query, plugin_load, plugin_unload);
diff --git a/pidgin/plugins/raw.c b/pidgin/plugins/raw.c
--- a/pidgin/plugins/raw.c
+++ b/pidgin/plugins/raw.c
@@ -49,7 +49,7 @@ static PurplePlugin *my_plugin = NULL;
 static int
 window_closed_cb()
 {
-	purple_plugin_unload(my_plugin);
+	purple_plugin_unload(my_plugin, NULL);
 
 	return FALSE;
 }
@@ -73,7 +73,7 @@ text_sent_cb(GtkEntry *entry)
 	purple_debug_misc("raw", "protocol_id = %s\n", protocol_id);
 
 	if (strcmp(protocol_id, "toc") == 0) {
-		int *a = (int *)gc->proto_data;
+		int *a = (int *)purple_connection_get_protocol_data(gc);
 		unsigned short seqno = htons(a[1]++ & 0xffff);
 		unsigned short len = htons(strlen(txt) + 1);
 		write(*a, "*\002", 2);
@@ -83,19 +83,19 @@ text_sent_cb(GtkEntry *entry)
 		purple_debug(PURPLE_DEBUG_MISC, "raw", "TOC C: %s\n", txt);
 
 	} else if (strcmp(protocol_id, "msn") == 0) {
-		MsnSession *session = gc->proto_data;
+		MsnSession *session = purple_connection_get_protocol_data(gc);
 		char buf[strlen(txt) + 3];
 
 		g_snprintf(buf, sizeof(buf), "%s\r\n", txt);
 		msn_servconn_write(session->notification->servconn, buf, strlen(buf));
 
 	} else if (strcmp(protocol_id, "irc") == 0) {
-		write(*(int *)gc->proto_data, txt, strlen(txt));
-		write(*(int *)gc->proto_data, "\r\n", 2);
+		write(*(int *)purple_connection_get_protocol_data(gc), txt, strlen(txt));
+		write(*(int *)purple_connection_get_protocol_data(gc), "\r\n", 2);
 		purple_debug(PURPLE_DEBUG_MISC, "raw", "IRC C: %s\n", txt);
 
 	} else if (strcmp(protocol_id, "jabber") == 0) {
-		jabber_send_raw((JabberStream *)gc->proto_data, txt, -1);
+		jabber_send_raw((JabberStream *)purple_connection_get_protocol_data(gc), txt, -1);
 
 	} else {
 		purple_debug_error("raw", "Unknown protocol ID %s\n", protocol_id);
@@ -111,13 +111,39 @@ account_changed_cb(GtkWidget *dropdown, 
 	account = new_account;
 }
 
+static PidginPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Eric Warmenhoven <eric at warmenhoven.org>",
+		NULL
+	};
+
+	return pidgin_plugin_info_new(
+		"id",           RAW_PLUGIN_ID,
+		"name",         N_("Raw"),



More information about the Commits mailing list