/soc/2013/ankitkv/gobjectification: 219de60342be: Refactored gg ...

Ankit Vani a at nevitus.org
Mon Aug 26 11:36:09 EDT 2013


Changeset: 219de60342bebe8c7cc3d77666d8cc28b8893d3b
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-26 21:05 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/219de60342be

Description:

Refactored gg to use the new protocol API

diffstat:

 libpurple/protocols/gg/gg.c |  205 ++++++++++++++++++++-----------------------
 libpurple/protocols/gg/gg.h |   25 +++++
 2 files changed, 121 insertions(+), 109 deletions(-)

diffs (truncated from 307 to 300 lines):

diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -54,6 +54,9 @@
 #include "pubdir-prpl.h"
 
 /* ---------------------------------------------------------------------- */
+static PurpleProtocol *my_protocol = NULL;
+
+/* ---------------------------------------------------------------------- */
 
 ggp_buddy_data * ggp_buddy_get_data(PurpleBuddy *buddy)
 {
@@ -1367,84 +1370,6 @@ static GHashTable * ggp_get_account_text
 	return table;
 }
 
-static PurpleProtocol protocol =
-{
-	"prpl-gg",			/* id */
-	"Gadu-Gadu",			/* name */
-	sizeof(PurpleProtocol),       /* struct_size */
-	OPT_PROTO_REGISTER_NOSCREENNAME | OPT_PROTO_IM_IMAGE,
-	NULL,				/* user_splits */
-	NULL,				/* protocol_options */
-	{"png", 1, 1, 200, 200, 0, PURPLE_ICON_SCALE_DISPLAY | PURPLE_ICON_SCALE_SEND},	/* icon_spec */
-	ggp_get_actions,		/* get_actions */
-	ggp_list_icon,			/* list_icon */
-	ggp_list_emblem,		/* list_emblem */
-	ggp_status_buddy_text,		/* status_text */
-	ggp_tooltip_text,		/* tooltip_text */
-	ggp_status_types,		/* status_types */
-	ggp_blist_node_menu,		/* blist_node_menu */
-	ggp_chat_info,			/* chat_info */
-	NULL,				/* chat_info_defaults */
-	ggp_login,			/* login */
-	ggp_close,			/* close */
-	ggp_send_im,			/* send_im */
-	NULL,				/* set_info */
-	ggp_send_typing,		/* send_typing */
-	ggp_pubdir_get_info_protocol,	/* get_info */
-	ggp_status_set_purplestatus,	/* set_away */
-	NULL,				/* set_idle */
-	NULL,				/* change_passwd */
-	ggp_add_buddy,			/* add_buddy */
-	NULL,				/* add_buddies */
-	ggp_remove_buddy,		/* remove_buddy */
-	NULL,				/* remove_buddies */
-	NULL,				/* add_permit */
-	ggp_add_deny,			/* add_deny */
-	NULL,				/* rem_permit */
-	ggp_rem_deny,			/* rem_deny */
-	NULL,				/* set_permit_deny */
-	ggp_join_chat,			/* join_chat */
-	NULL,				/* reject_chat */
-	ggp_get_chat_name,		/* get_chat_name */
-	NULL,				/* chat_invite */
-	NULL,				/* chat_leave */
-	NULL,				/* chat_whisper */
-	ggp_chat_send,			/* chat_send */
-	ggp_keepalive,			/* keepalive */
-	ggp_account_register,		/* register_user */
-	NULL,				/* get_cb_info */
-	ggp_roster_alias_buddy,		/* alias_buddy */
-	ggp_roster_group_buddy,		/* group_buddy */
-	ggp_roster_rename_group,	/* rename_group */
-	ggp_buddy_free,			/* buddy_free */
-	NULL,				/* convo_closed */
-	ggp_normalize,			/* normalize */
-	ggp_avatar_own_set,		/* set_buddy_icon */
-	NULL,				/* remove_group */
-	NULL,				/* get_cb_real_name */
-	NULL,				/* set_chat_topic */
-	NULL,				/* find_blist_chat */
-	NULL,				/* roomlist_get_list */
-	NULL,				/* roomlist_cancel */
-	NULL,				/* roomlist_expand_category */
-	NULL,				/* can_receive_file */
-	NULL,				/* send_file */
-	NULL,				/* new_xfer */
-	ggp_offline_message,		/* offline_message */
-	NULL,				/* whiteboard_protocol_ops */
-	NULL,				/* send_raw */
-	NULL,				/* roomlist_room_serialize */
-	NULL,				/* unregister_user */
-	NULL,				/* send_attention */
-	NULL,				/* get_attention_types */
-	ggp_get_account_text_table,	/* get_account_text_table */
-	NULL,				/* initiate_media */
-	NULL,				/* can_do_media */
-	NULL,				/* get_moods */
-	NULL,				/* set_public_alias */
-	NULL				/* get_public_alias */
-};
-
 static void purple_gg_debug_handler(int level, const char * format, va_list args) {
 	PurpleDebugLevel purple_level;
 	char *msg = g_strdup_vprintf(format, args);
@@ -1468,38 +1393,27 @@ static void purple_gg_debug_handler(int 
 	g_free(msg);
 }
 
-static PurplePluginInfo *
-plugin_query(GError **error)
+static void
+ggp_protocol_base_init(GaduGaduProtocolClass *klass)
 {
-	return purple_plugin_info_new(
-		"id",           "prpl-gg",
-		"name",         "Gadu-Gadu",
-		"version",      DISPLAY_VERSION,
-		"category",     N_("Protocol"),
-		"summary",      N_("Gadu-Gadu Protocol Plugin"),
-		"description",  N_("Polish popular IM"),
-		"author",       "boler at sourceforge.net",
-		"website",      PURPLE_WEBSITE,
-		"abi-version",  PURPLE_ABI_VERSION,
-		"flags",        GPLUGIN_PLUGIN_INFO_FLAGS_INTERNAL |
-		                GPLUGIN_PLUGIN_INFO_FLAGS_LOAD_ON_QUERY,
-		NULL
-	);
-}
+	PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
+	PurpleAccountOption *option;
+	PurpleAccountOption *ggp_server_option;
+	GList *encryption_options = NULL;
 
-static PurpleAccountOption *ggp_server_option;
-
-static gboolean
-plugin_load(PurplePlugin *plugin, GError **error)
-{
-	PurpleAccountOption *option;
-	GList *encryption_options = NULL;
+	proto_class->id        = GGP_ID;
+	proto_class->name      = GGP_NAME;
+	proto_class->options   = OPT_PROTO_REGISTER_NOSCREENNAME |
+	                         OPT_PROTO_IM_IMAGE;
+	proto_class->icon_spec = (PurpleBuddyIconSpec) {"png", 1, 1, 200, 200, 0,
+	                                                PURPLE_ICON_SCALE_DISPLAY |
+	                                                PURPLE_ICON_SCALE_SEND};
 
 	purple_prefs_add_none("/plugins/prpl/gg");
 
 	option = purple_account_option_string_new(_("GG server"),
 			"gg_server", "");
-	protocol.protocol_options = g_list_append(protocol.protocol_options,
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options,
 			option);
 	ggp_server_option = option;
 
@@ -1517,12 +1431,12 @@ plugin_load(PurplePlugin *plugin, GError
 
 	option = purple_account_option_list_new(_("Connection security"),
 		"encryption", encryption_options);
-	protocol.protocol_options = g_list_append(protocol.protocol_options,
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options,
 		option);
 
 	option = purple_account_option_bool_new(_("Show links from strangers"),
 		"show_links_from_strangers", 1);
-	protocol.protocol_options = g_list_append(protocol.protocol_options,
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options,
 		option);
 
 	gg_debug_handler = purple_gg_debug_handler;
@@ -1532,8 +1446,78 @@ plugin_load(PurplePlugin *plugin, GError
 
 	ggp_resolver_purple_setup();
 	ggp_servconn_setup(ggp_server_option);
+}
 
-	purple_protocols_add(&protocol);
+static void
+ggp_protocol_base_finalize(GaduGaduProtocolClass *klass)
+{
+	ggp_servconn_cleanup();
+}
+
+static void
+ggp_protocol_interface_init(PurpleProtocolInterface *iface)
+{
+	iface->get_actions            = ggp_get_actions;
+	iface->list_icon              = ggp_list_icon;
+	iface->list_emblem            = ggp_list_emblem;
+	iface->status_text            = ggp_status_buddy_text;
+	iface->tooltip_text           = ggp_tooltip_text;
+	iface->status_types           = ggp_status_types;
+	iface->blist_node_menu        = ggp_blist_node_menu;
+	iface->chat_info              = ggp_chat_info;
+	iface->login                  = ggp_login;
+	iface->close                  = ggp_close;
+	iface->send_im                = ggp_send_im;
+	iface->send_typing            = ggp_send_typing;
+	iface->get_info               = ggp_pubdir_get_info_protocol;
+	iface->set_status             = ggp_status_set_purplestatus;
+	iface->add_buddy              = ggp_add_buddy;
+	iface->remove_buddy           = ggp_remove_buddy;
+	iface->add_deny               = ggp_add_deny;
+	iface->rem_deny               = ggp_rem_deny;
+	iface->join_chat              = ggp_join_chat;
+	iface->get_chat_name          = ggp_get_chat_name;
+	iface->chat_send              = ggp_chat_send;
+	iface->keepalive              = ggp_keepalive;
+	iface->register_user          = ggp_account_register;
+	iface->alias_buddy            = ggp_roster_alias_buddy;
+	iface->group_buddy            = ggp_roster_group_buddy;
+	iface->rename_group           = ggp_roster_rename_group;
+	iface->buddy_free             = ggp_buddy_free;
+	iface->normalize              = ggp_normalize;
+	iface->set_buddy_icon         = ggp_avatar_own_set;
+	iface->offline_message        = ggp_offline_message;
+	iface->get_account_text_table = ggp_get_account_text_table;
+}
+
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+	return purple_plugin_info_new(
+		"id",           GGP_ID,
+		"name",         GGP_NAME,
+		"version",      DISPLAY_VERSION,
+		"category",     N_("Protocol"),
+		"summary",      N_("Gadu-Gadu Protocol Plugin"),
+		"description",  N_("Polish popular IM"),
+		"author",       "boler at sourceforge.net",
+		"website",      PURPLE_WEBSITE,
+		"abi-version",  PURPLE_ABI_VERSION,
+		"flags",        GPLUGIN_PLUGIN_INFO_FLAGS_INTERNAL |
+		                GPLUGIN_PLUGIN_INFO_FLAGS_LOAD_ON_QUERY,
+		NULL
+	);
+}
+
+static gboolean
+plugin_load(PurplePlugin *plugin, GError **error)
+{
+	my_protocol = purple_protocols_add(GGP_TYPE_PROTOCOL);
+
+	if (!my_protocol) {
+		g_set_error(error, GGP_DOMAIN, 0, _("Failed to add gg protocol"));
+		return FALSE;
+	}
 
 	return TRUE;
 }
@@ -1541,12 +1525,15 @@ plugin_load(PurplePlugin *plugin, GError
 static gboolean
 plugin_unload(PurplePlugin *plugin, GError **error)
 {
-	ggp_servconn_cleanup();
-	purple_protocols_remove(&protocol);
+	if (!purple_protocols_remove(my_protocol)) {
+		g_set_error(error, GGP_DOMAIN, 0, _("Failed to remove gg protocol"));
+		return FALSE;
+	}
 
 	return TRUE;
 }
 
-PURPLE_PLUGIN_INIT(gg, plugin_query, plugin_load, plugin_unload);
+PURPLE_PROTOCOL_DEFINE (GaduGaduProtocol, ggp_protocol);
+PURPLE_PLUGIN_INIT     (gg, plugin_query, plugin_load, plugin_unload);
 
 /* vim: set ts=8 sts=0 sw=8 noet: */
diff --git a/libpurple/protocols/gg/gg.h b/libpurple/protocols/gg/gg.h
--- a/libpurple/protocols/gg/gg.h
+++ b/libpurple/protocols/gg/gg.h
@@ -40,6 +40,26 @@
 
 #define GGP_UIN_LEN_MAX 10
 
+#define GGP_ID     "prpl-gg"
+#define GGP_NAME   "Gadu-Gadu"
+#define GGP_DOMAIN (g_quark_from_static_string(GGP_ID))
+
+#define GGP_TYPE_PROTOCOL             (ggp_protocol_get_type())
+#define GGP_PROTOCOL(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), GGP_TYPE_PROTOCOL, GaduGaduProtocol))
+#define GGP_PROTOCOL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), GGP_TYPE_PROTOCOL, GaduGaduProtocolClass))
+#define GGP_IS_PROTOCOL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), GGP_TYPE_PROTOCOL))
+#define GGP_IS_PROTOCOL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), GGP_TYPE_PROTOCOL))
+#define GGP_PROTOCOL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), GGP_TYPE_PROTOCOL, GaduGaduProtocolClass))
+
+typedef struct _GaduGaduProtocol
+{
+	PurpleProtocol parent;
+} GaduGaduProtocol;
+
+typedef struct _GaduGaduProtocolClass
+{
+	PurpleProtocolClass parent_class;
+} GaduGaduProtocolClass;
 
 typedef struct
 {
@@ -67,6 +87,11 @@ typedef struct
 	gboolean blocked;
 } ggp_buddy_data;
 
+/**



More information about the Commits mailing list