libpurple/protocols/oscar/libaim.c

branch
soc.2013.gobjectification.plugins
changeset 36590
e77919ff5e74
parent 36583
0582190c9382
child 36613
0e96218aa13a
--- a/libpurple/protocols/oscar/libaim.c	Wed Aug 28 00:13:52 2013 +0530
+++ b/libpurple/protocols/oscar/libaim.c	Wed Aug 28 03:37:22 2013 +0530
@@ -24,96 +24,46 @@
  * which contains all the shared implementation code with libicq
  */
 
+#include "core.h"
 #include "plugins.h"
+#include "signals.h"
 
+#include "libaim.h"
 #include "oscarcommon.h"
-#include "oscar.h"
+
+static PurpleProtocol *my_protocol = NULL;
 
-static PurpleProtocol protocol =
+static void
+aim_protocol_base_init(AIMProtocolClass *klass)
 {
-	"prpl-aim",				/* id */
-	"AIM",					/* name */
-	sizeof(PurpleProtocol),       /* struct_size */
-	OPT_PROTO_MAIL_CHECK | OPT_PROTO_IM_IMAGE | OPT_PROTO_INVITE_MESSAGE | OPT_PROTO_AUTHORIZATION_DENIED_MESSAGE,
-	NULL,					/* user_splits */
-	NULL,					/* protocol_options */
-	{"gif,jpeg,bmp,ico", 0, 0, 64, 64, 7168, PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */
-	oscar_get_actions,		/* get_actions */
-	oscar_list_icon_aim,	/* list_icon */
-	oscar_list_emblem,		/* list_emblems */
-	oscar_status_text,		/* status_text */
-	oscar_tooltip_text,		/* tooltip_text */
-	oscar_status_types,		/* status_types */
-	oscar_blist_node_menu,	/* blist_node_menu */
-	oscar_chat_info,		/* chat_info */
-	oscar_chat_info_defaults, /* chat_info_defaults */
-	oscar_login,			/* login */
-	oscar_close,			/* close */
-	oscar_send_im,			/* send_im */
-	oscar_set_info,			/* set_info */
-	oscar_send_typing,		/* send_typing */
-	oscar_get_info,			/* get_info */
-	oscar_set_status,		/* set_status */
-	oscar_set_idle,			/* set_idle */
-	oscar_change_passwd,	/* change_passwd */
-	oscar_add_buddy,		/* add_buddy */
-	NULL,					/* add_buddies */
-	oscar_remove_buddy,		/* remove_buddy */
-	NULL,					/* remove_buddies */
-	oscar_add_permit,		/* add_permit */
-	oscar_add_deny,			/* add_deny */
-	oscar_rem_permit,		/* rem_permit */
-	oscar_rem_deny,			/* rem_deny */
-	oscar_set_aim_permdeny,	/* set_permit_deny */
-	oscar_join_chat,		/* join_chat */
-	NULL,					/* reject_chat */
-	oscar_get_chat_name,	/* get_chat_name */
-	oscar_chat_invite,		/* chat_invite */
-	oscar_chat_leave,		/* chat_leave */
-	NULL,					/* chat_whisper */
-	oscar_send_chat,		/* chat_send */
-	oscar_keepalive,		/* keepalive */
-	NULL,					/* register_user */
-	NULL,					/* get_cb_info */
-	oscar_alias_buddy,		/* alias_buddy */
-	oscar_move_buddy,		/* group_buddy */
-	oscar_rename_group,		/* rename_group */
-	NULL,					/* buddy_free */
-	oscar_convo_closed,		/* convo_closed */
-	oscar_normalize,		/* normalize */
-	oscar_set_icon,			/* set_buddy_icon */
-	oscar_remove_group,		/* 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 */
-	oscar_can_receive_file,	/* can_receive_file */
-	oscar_send_file,		/* send_file */
-	oscar_new_xfer,			/* new_xfer */
-	oscar_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 */
-	NULL,					/* get_account_text_table */
-	NULL,					/* initiate_media */
-	NULL,					/* get_media_caps */
-	NULL,					/* get_moods */
-	NULL,					/* set_public_alias */
-	NULL,					/* get_public_alias */
-	oscar_get_max_message_size		/* get_max_message_size */
-};
+	PurpleProtocolClass *proto_class = PURPLE_PROTOCOL_CLASS(klass);
+	PurpleAccountOption *option;
+
+	proto_class->id        = AIM_ID;
+	proto_class->name      = AIM_NAME;
+
+	option = purple_account_option_string_new(_("Server"), "server", oscar_get_login_server(FALSE, TRUE));
+	proto_class->protocol_options = g_list_append(proto_class->protocol_options, option);
+}
+
+static void
+aim_protocol_interface_init(PurpleProtocolInterface *iface)
+{
+	iface->list_icon            = oscar_list_icon_aim;
+	iface->add_permit           = oscar_add_permit;
+	iface->rem_permit           = oscar_rem_permit;
+	iface->set_permit_deny      = oscar_set_aim_permdeny;
+	iface->get_max_message_size = oscar_get_max_message_size;
+}
+
+static void aim_protocol_base_finalize(AIMProtocolClass *klass) { }
 
 static PurplePluginInfo *
 plugin_query(GError **error)
 {
 	return purple_plugin_info_new(
-		"id",           "prpl-aim",
-		"name",         "AIM",
+		"id",           AIM_ID,
+		"name",         AIM_NAME,
 		"version",      DISPLAY_VERSION,
 		"category",     N_("Protocol"),
 		"summary",      N_("AIM Protocol Plugin"),
@@ -129,8 +79,14 @@
 static gboolean
 plugin_load(PurplePlugin *plugin, GError **error)
 {
-	oscar_init(&protocol, FALSE);
-	purple_protocols_add(&protocol);
+	my_protocol = purple_protocols_add(AIM_TYPE_PROTOCOL);
+	if (!my_protocol) {
+		g_set_error(error, AIM_DOMAIN, 0, _("Failed to add aim protocol"));
+		return FALSE;
+	}
+
+	purple_signal_connect(purple_get_core(), "uri-handler", my_protocol,
+		PURPLE_CALLBACK(oscar_uri_handler), NULL);
 
 	return TRUE;
 }
@@ -138,9 +94,15 @@
 static gboolean
 plugin_unload(PurplePlugin *plugin, GError **error)
 {
-	purple_protocols_remove(&protocol);
+	if (!purple_protocols_remove(my_protocol)) {
+		g_set_error(error, AIM_DOMAIN, 0, _("Failed to remove aim protocol"));
+		return FALSE;
+	}
 
 	return TRUE;
 }
 
+PURPLE_PROTOCOL_DEFINE_EXTENDED(AIMProtocol, aim_protocol,
+                                OSCAR_TYPE_PROTOCOL, 0);
+
 PURPLE_PLUGIN_INIT(aim, plugin_query, plugin_load, plugin_unload);

mercurial