Refactored finch plugins to use the new plugin API soc.2013.gobjectification.plugins

Mon, 16 Sep 2013 22:34:22 +0530

author
Ankit Vani <a@nevitus.org>
date
Mon, 16 Sep 2013 22:34:22 +0530
branch
soc.2013.gobjectification.plugins
changeset 36751
a9f6ae7c308e
parent 36750
b860bdf364a1
child 36752
c726e758c59b

Refactored finch plugins to use the new plugin API

finch/plugins/gntclipboard.c file | annotate | diff | comparison | revisions
finch/plugins/gntgf.c file | annotate | diff | comparison | revisions
finch/plugins/gnthistory.c file | annotate | diff | comparison | revisions
finch/plugins/gnttinyurl.c file | annotate | diff | comparison | revisions
finch/plugins/lastlog.c file | annotate | diff | comparison | revisions
--- a/finch/plugins/gntclipboard.c	Mon Sep 16 21:06:32 2013 +0530
+++ b/finch/plugins/gntclipboard.c	Mon Sep 16 22:34:22 2013 +0530
@@ -22,6 +22,8 @@
 #include "internal.h"
 #include <glib.h>
 
+#define PLUGIN_ID           "gntclipboard"
+#define PLUGIN_DOMAIN       (g_quark_from_static_string(PLUGIN_ID))
 #define PLUGIN_STATIC_NAME	GntClipboard
 
 #ifdef HAVE_X11
@@ -106,8 +108,31 @@
 }
 #endif
 
+static FinchPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Richard Nelson <wabz@whatsbeef.net>",
+		NULL
+	};
+
+	return finch_plugin_info_new(
+		"id",           PLUGIN_ID,
+		"name",         N_("GntClipboard"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("Utility"),
+		"summary",      N_("Clipboard plugin"),
+		"description",  N_("When the gnt clipboard contents change, the "
+		                   "contents are made available to X, if possible."),
+		"authors",      authors,
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 #ifdef HAVE_X11
 	if (!XOpenDisplay(NULL)) {
@@ -125,14 +150,14 @@
 	sig_handle = g_signal_connect(G_OBJECT(gnt_get_clipboard()), "clipboard_changed", G_CALLBACK(clipboard_changed), NULL);
 	return TRUE;
 #else
-	purple_notify_error(NULL, _("Error"), _("Error loading the plugin."),
-			_("This plugin cannot be loaded because it was not built with X11 support."));
+	g_set_error(error, PLUGIN_DOMAIN, 0, _("This plugin cannot be loaded "
+			"because it was not built with X11 support."));
 	return FALSE;
 #endif
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 #ifdef HAVE_X11
 	if (child) {
@@ -144,42 +169,4 @@
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,
-	FINCH_PLUGIN_TYPE,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	"gntclipboard",
-	N_("GntClipboard"),
-	DISPLAY_VERSION,
-	N_("Clipboard plugin"),
-	N_("When the gnt clipboard contents change, "
-		"the contents are made available to X, if possible."),
-	"Richard Nelson <wabz@whatsbeef.net>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	plugin_unload,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
-}
-
-PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
+PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload);
--- a/finch/plugins/gntgf.c	Mon Sep 16 21:06:32 2013 +0530
+++ b/finch/plugins/gntgf.c	Mon Sep 16 22:34:22 2013 +0530
@@ -269,35 +269,6 @@
 		notify(conv, _("%s sent a message in %s"), sender, purple_conversation_get_name(conv));
 }
 
-static gboolean
-plugin_load(PurplePlugin *plugin)
-{
-	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", plugin,
-			PURPLE_CALLBACK(buddy_signed_on), NULL);
-	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", plugin,
-			PURPLE_CALLBACK(buddy_signed_off), NULL);
-	purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin,
-			PURPLE_CALLBACK(received_im_msg), NULL);
-	purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", plugin,
-			PURPLE_CALLBACK(received_chat_msg), NULL);
-
-	memset(&gpsy, 0, sizeof(gpsy));
-	memset(&gpsw, 0, sizeof(gpsw));
-
-	return TRUE;
-}
-
-static gboolean
-plugin_unload(PurplePlugin *plugin)
-{
-	while (toasters)
-	{
-		GntToast *toast = toasters->data;
-		destroy_toaster(toast);
-	}
-	return TRUE;
-}
-
 static struct
 {
 	char *pref;
@@ -365,40 +336,31 @@
 	return window;
 }
 
-static PurplePluginInfo info =
+static FinchPluginInfo *
+plugin_query(GError **error)
 {
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,
-	FINCH_PLUGIN_TYPE,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	"gntgf",
-	N_("GntGf"),
-	DISPLAY_VERSION,
-	N_("Toaster plugin"),
-	N_("Toaster plugin"),
-	"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	plugin_unload,
-	NULL,
-	config_frame,
-	NULL,
-	NULL,
-	NULL,
+	const gchar * const authors[] = {
+		"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
+		NULL
+	};
 
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
+	return finch_plugin_info_new(
+		"id",                      "gntgf",
+		"name",                    N_("GntGf"),
+		"version",                 DISPLAY_VERSION,
+		"category",                N_("Notification"),
+		"summary",                 N_("Toaster plugin"),
+		"description",             N_("Toaster plugin"),
+		"authors",                 authors,
+		"website",                 PURPLE_WEBSITE,
+		"abi-version",             PURPLE_ABI_VERSION,
+		"finch-preferences-frame", config_frame,
+		NULL
+	);
+}
 
-static void
-init_plugin(PurplePlugin *plugin)
+static gboolean
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	purple_prefs_add_none("/plugins");
 	purple_prefs_add_none("/plugins/gnt");
@@ -415,6 +377,31 @@
 #ifdef HAVE_X11
 	purple_prefs_add_bool(PREFS_URGENT, FALSE);
 #endif
+
+	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-on", plugin,
+			PURPLE_CALLBACK(buddy_signed_on), NULL);
+	purple_signal_connect(purple_blist_get_handle(), "buddy-signed-off", plugin,
+			PURPLE_CALLBACK(buddy_signed_off), NULL);
+	purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin,
+			PURPLE_CALLBACK(received_im_msg), NULL);
+	purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", plugin,
+			PURPLE_CALLBACK(received_chat_msg), NULL);
+
+	memset(&gpsy, 0, sizeof(gpsy));
+	memset(&gpsw, 0, sizeof(gpsw));
+
+	return TRUE;
 }
 
-PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
+static gboolean
+plugin_unload(PurplePlugin *plugin, GError **error)
+{
+	while (toasters)
+	{
+		GntToast *toast = toasters->data;
+		destroy_toaster(toast);
+	}
+	return TRUE;
+}
+
+PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload);
--- a/finch/plugins/gnthistory.c	Mon Sep 16 21:06:32 2013 +0530
+++ b/finch/plugins/gnthistory.c	Mon Sep 16 22:34:22 2013 +0530
@@ -188,8 +188,34 @@
 	history_prefs_check((PurplePlugin *)data);
 }
 
+static FinchPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Sean Egan <seanegan@gmail.com>",
+		"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
+		NULL
+	};
+
+	return finch_plugin_info_new(
+		"id",           HISTORY_PLUGIN_ID,
+		"name",         N_("GntHistory"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("User interface"),
+		"summary",      N_("Shows recently logged conversations in new "
+		                   "conversations."),
+		"description",  N_("When a new conversation is opened this plugin will "
+		                   "insert the last conversation into the current "
+		                   "conversation."),
+		"authors",      authors,
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	purple_signal_connect(purple_conversations_get_handle(),
 						"conversation-created",
@@ -205,44 +231,10 @@
 	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,
-	NULL,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	HISTORY_PLUGIN_ID,
-	N_("GntHistory"),
-	DISPLAY_VERSION,
-	N_("Shows recently logged conversations in new conversations."),
-	N_("When a new conversation is opened this plugin will insert "
-	   "the last conversation into the current conversation."),
-	"Sean Egan <seanegan@gmail.com>\n"
-	"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
+	return TRUE;
 }
 
-PURPLE_INIT_PLUGIN(gnthistory, init_plugin, info)
-
+PURPLE_PLUGIN_INIT(gnthistory, plugin_query, plugin_load, plugin_unload);
--- a/finch/plugins/gnttinyurl.c	Mon Sep 16 21:06:32 2013 +0530
+++ b/finch/plugins/gnttinyurl.c	Mon Sep 16 22:34:22 2013 +0530
@@ -409,11 +409,59 @@
 	return win;
 }
 
+static PurplePluginPrefFrame *
+get_plugin_pref_frame(PurplePlugin *plugin) {
+
+  PurplePluginPrefFrame *frame;
+  PurplePluginPref *pref;
+
+  frame = purple_plugin_pref_frame_new();
+
+  pref = purple_plugin_pref_new_with_name(PREF_LENGTH);
+  purple_plugin_pref_set_label(pref, _("Only create TinyURL for URLs"
+				     " of this length or greater"));
+  purple_plugin_pref_frame_add(frame, pref);
+  pref = purple_plugin_pref_new_with_name(PREF_URL);
+  purple_plugin_pref_set_label(pref, _("TinyURL (or other) address prefix"));
+  purple_plugin_pref_frame_add(frame, pref);
+
+  return frame;
+}
+
+static FinchPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Richard Nelson <wabz@whatsbeef.net>",
+		NULL
+	};
+
+	return finch_plugin_info_new(
+		"id",                 "TinyURL",
+		"name",               N_("TinyURL"),
+		"version",            DISPLAY_VERSION,
+		"category",           N_("Utility"),
+		"summary",            N_("TinyURL plugin"),
+		"description",        N_("When receiving a message with URL(s), "
+		                         "use TinyURL for easier copying"),
+		"authors",            authors,
+		"website",            PURPLE_WEBSITE,
+		"abi-version",        PURPLE_ABI_VERSION,
+		"preferences-frame",  get_plugin_pref_frame,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	PurpleNotifyUiOps *ops = purple_notify_get_ui_ops();
-	plugin->extra = ops->notify_uri;
+
+	purple_prefs_add_none(PREFS_BASE);
+	purple_prefs_add_int(PREF_LENGTH, 30);
+	purple_prefs_add_string(PREF_URL, "http://tinyurl.com/api-create.php?url=");
+
+	g_object_set_data(G_OBJECT(plugin), "notify-uri", ops->notify_uri);
 	ops->notify_uri = tinyurl_notify_uri;
 
 	purple_signal_connect(purple_conversations_get_handle(),
@@ -436,82 +484,12 @@
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	PurpleNotifyUiOps *ops = purple_notify_get_ui_ops();
 	if (ops->notify_uri == tinyurl_notify_uri)
-		ops->notify_uri = plugin->extra;
+		ops->notify_uri = g_object_get_data(G_OBJECT(plugin), "notify-uri");
 	return TRUE;
 }
 
-static PurplePluginPrefFrame *
-get_plugin_pref_frame(PurplePlugin *plugin) {
-
-  PurplePluginPrefFrame *frame;
-  PurplePluginPref *pref;
-
-  frame = purple_plugin_pref_frame_new();
-
-  pref = purple_plugin_pref_new_with_name(PREF_LENGTH);
-  purple_plugin_pref_set_label(pref, _("Only create TinyURL for URLs"
-				     " of this length or greater"));
-  purple_plugin_pref_frame_add(frame, pref);
-  pref = purple_plugin_pref_new_with_name(PREF_URL);
-  purple_plugin_pref_set_label(pref, _("TinyURL (or other) address prefix"));
-  purple_plugin_pref_frame_add(frame, pref);
-
-  return frame;
-}
-
-static PurplePluginUiInfo prefs_info = {
-  get_plugin_pref_frame,
-  0,    /* page_num (Reserved) */
-  NULL, /* frame (Reserved) */
-
-  /* padding */
-  NULL,
-  NULL,
-  NULL,
-  NULL
-};
-
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,
-	FINCH_PLUGIN_TYPE,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	"TinyURL",
-	N_("TinyURL"),
-	DISPLAY_VERSION,
-	N_("TinyURL plugin"),
-	N_("When receiving a message with URL(s), use TinyURL for easier copying"),
-	"Richard Nelson <wabz@whatsbeef.net>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	plugin_unload,
-	NULL,
-	NULL,
-	NULL,
-	&prefs_info,            /**< prefs_info */
-	NULL,
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin) {
-  purple_prefs_add_none(PREFS_BASE);
-  purple_prefs_add_int(PREF_LENGTH, 30);
-  purple_prefs_add_string(PREF_URL, "http://tinyurl.com/api-create.php?url=");
-}
-
-PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
+PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload);
--- a/finch/plugins/lastlog.c	Mon Sep 16 21:06:32 2013 +0530
+++ b/finch/plugins/lastlog.c	Mon Sep 16 22:34:22 2013 +0530
@@ -91,8 +91,30 @@
 	return PURPLE_CMD_STATUS_OK;
 }
 
+static FinchPluginInfo *
+plugin_query(GError **error)
+{
+	const gchar * const authors[] = {
+		"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
+		NULL
+	};
+
+	return finch_plugin_info_new(
+		"id",           "gntlastlog",
+		"name",         N_("GntLastlog"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("Utility"),
+		"summary",      N_("Lastlog plugin."),
+		"description",  N_("Lastlog plugin."),
+		"authors",      authors,
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	cmd = purple_cmd_register("lastlog", "s", PURPLE_CMD_P_DEFAULT,
 			PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM, NULL,
@@ -102,48 +124,10 @@
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	purple_cmd_unregister(cmd);
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,
-	FINCH_PLUGIN_TYPE,
-	0,
-	NULL,
-	PURPLE_PRIORITY_DEFAULT,
-	"gntlastlog",
-	N_("GntLastlog"),
-	DISPLAY_VERSION,
-	N_("Lastlog plugin."),
-	N_("Lastlog plugin."),
-	"Sadrul H Chowdhury <sadrul@users.sourceforge.net>",
-	PURPLE_WEBSITE,
-	plugin_load,
-	plugin_unload,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
-}
-
-PURPLE_INIT_PLUGIN(PLUGIN_STATIC_NAME, init_plugin, info)
-
+PURPLE_PLUGIN_INIT(PLUGIN_STATIC_NAME, plugin_query, plugin_load, plugin_unload);

mercurial