/soc/2013/ankitkv/gobjectification: d5014e354e8f: Refactored res...

Ankit Vani a at nevitus.org
Sat Sep 14 12:47:15 EDT 2013


Changeset: d5014e354e8f3ad54bacfbfd4a721dfdce93cae9
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-14 22:16 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/d5014e354e8f

Description:

Refactored rest of libpurple to use the new protocol API

diffstat:

 libpurple/dbus-analyze-functions.py |   2 +-
 libpurple/protocols.c               |  20 +++++++-------------
 libpurple/server.c                  |  10 +++++-----
 libpurple/util.c                    |   2 +-
 4 files changed, 14 insertions(+), 20 deletions(-)

diffs (132 lines):

diff --git a/libpurple/dbus-analyze-functions.py b/libpurple/dbus-analyze-functions.py
--- a/libpurple/dbus-analyze-functions.py
+++ b/libpurple/dbus-analyze-functions.py
@@ -32,7 +32,7 @@ excluded = [\
     "purple_account_unregister",
 
     # Similar to the above:
-    "purple_protocol_iface_unregister_user",
+    "purple_protocol_server_iface_unregister_user",
 
     # Similar to the above, again
     "purple_menu_action_new",
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -507,7 +507,7 @@ purple_protocol_send_attention(PurpleCon
 	g_return_if_fail(who != NULL);
 
 	protocol = purple_protocols_find(purple_account_get_protocol_id(purple_connection_get_account(gc)));
-	g_return_if_fail(PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_attention));
+	g_return_if_fail(PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, send));
 
 	mtime = time(NULL);
 
@@ -776,6 +776,7 @@ PurpleProtocol *
 purple_protocols_add(GType protocol_type, GError **error)
 {
 	PurpleProtocol *protocol;
+	PurpleProtocolClass *klass;
 
 	if (protocol_type == G_TYPE_INVALID) {
 		g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
@@ -789,12 +790,6 @@ purple_protocols_add(GType protocol_type
 		return NULL;
 	}
 
-	if (!g_type_is_a(protocol_type, PURPLE_TYPE_PROTOCOL_INTERFACE)) {
-		g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
-		            _("Protocol does not implement PurpleProtocolInterface"));
-		return NULL;
-	}
-
 	if (G_TYPE_IS_ABSTRACT(protocol_type)) {
 		g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
 		            _("Protocol type is abstract"));
@@ -802,6 +797,7 @@ purple_protocols_add(GType protocol_type
 	}
 
 	protocol = g_object_new(protocol_type, NULL);
+	klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
 
 	if (!protocol) {
 		g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
@@ -827,14 +823,12 @@ purple_protocols_add(GType protocol_type
 	}
 
 	/* Make sure the protocol implements the required functions */
-	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, list_icon) ||
-	    !PURPLE_PROTOCOL_IMPLEMENTS(protocol, login)     ||
-	    !PURPLE_PROTOCOL_IMPLEMENTS(protocol, close))
+	if (!klass->login        || !klass->close_connection ||
+	    !klass->status_types || !klass->list_icon)
 	{
 		g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
-		            _("Protocol %s does not implement all the required "
-		            "functions (list_icon, login and close)"),
-		            purple_protocol_get_id(protocol));
+		            _("Protocol %s does not implement all the functions in "
+		            "PurpleProtocolClass"), purple_protocol_get_id(protocol));
 
 		g_object_unref(protocol);
 		return NULL;
diff --git a/libpurple/server.c b/libpurple/server.c
--- a/libpurple/server.c
+++ b/libpurple/server.c
@@ -133,7 +133,7 @@ int serv_send_im(PurpleConnection *gc, c
 
 	im = purple_conversations_find_im_with_account(name, account);
 
-	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_im))
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, IM_IFACE, send))
 		val = purple_protocol_im_iface_send(protocol, gc, name, message, flags);
 
 	/*
@@ -174,7 +174,7 @@ void serv_set_info(PurpleConnection *gc,
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
 
-		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, set_info)) {
+		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, SERVER_IFACE, set_info)) {
 			account = purple_connection_get_account(gc);
 
 			if (purple_signal_emit_return_1(purple_accounts_get_handle(),
@@ -293,7 +293,7 @@ PurpleAttentionType *purple_get_attentio
 	protocol = purple_protocols_find(purple_account_get_protocol_id(account));
 
 	/* Lookup the attention type in the protocol's attention_types list, if any. */
-	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_attention_types)) {
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, ATTENTION_IFACE, get_types)) {
 		GList *attention_types;
 
 		attention_types = purple_protocol_attention_iface_get_types(protocol, account);
@@ -467,7 +467,7 @@ int serv_chat_send(PurpleConnection *gc,
 
 	protocol = purple_connection_get_protocol(gc);
 
-	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, chat_send))
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, CHAT_IFACE, send))
 		return purple_protocol_chat_iface_send(protocol, gc, id, message, flags);
 
 	return -EINVAL;
@@ -866,7 +866,7 @@ void serv_send_file(PurpleConnection *gc
 	if (gc) {
 		protocol = purple_connection_get_protocol(gc);
 
-		if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, can_receive_file) ||
+		if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, XFER_IFACE, can_receive) ||
 				purple_protocol_xfer_iface_can_receive(protocol, gc, who))
 
 			purple_protocol_xfer_iface_send(protocol, gc, who, file);
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -3443,7 +3443,7 @@ purple_validate(const PurpleProtocol *pr
 	if (str[0] == '\0')
 		return FALSE;
 
-	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, normalize))
+	if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, CLIENT_IFACE, normalize))
 		return TRUE;
 
 	normalized = purple_protocol_client_iface_normalize(PURPLE_PROTOCOL(protocol),



More information about the Commits mailing list