/soc/2013/ankitkv/gobjectification: 89f3e5748a68: Changed signat...

Ankit Vani a at nevitus.org
Wed Aug 21 15:35:33 EDT 2013


Changeset: 89f3e5748a6899b3b90288acacc37a60db3de032
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-22 00:29 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/89f3e5748a68

Description:

Changed signature of purple_protocols_add() take a GType and return the PurpleProtocol

diffstat:

 libpurple/protocols.c |  22 ++++++++++++++--------
 libpurple/protocols.h |   6 +++---
 2 files changed, 17 insertions(+), 11 deletions(-)

diffs (65 lines):

diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -687,6 +687,8 @@ purple_protocol_destroy(PurpleProtocol *
 	purple_signals_unregister_by_instance(protocol);
 
 	purple_prefs_disconnect_by_handle(protocol);
+
+	g_object_unref(protocol);
 }
 
 PurpleProtocol *
@@ -695,22 +697,26 @@ purple_find_protocol_info(const char *id
 	return g_hash_table_lookup(protocols, id);
 }
 
-gboolean
-purple_protocols_add(PurpleProtocol *protocol)
+PurpleProtocol *
+purple_protocols_add(GType protocol_type)
 {
-	if (purple_find_protocol_info(protocol->id))
-		return FALSE;
+	PurpleProtocol *protocol = g_object_new(protocol_type, NULL);
+	if (purple_find_protocol_info(purple_protocol_get_id(protocol))) {
+		g_object_unref(protocol);
+		return NULL;
+	}
 
-	g_hash_table_insert(protocols, g_strdup(protocol->id), protocol);
-	return TRUE;
+	g_hash_table_insert(protocols, g_strdup(purple_protocol_get_id(protocol)),
+	                    protocol);
+	return protocol;
 }
 
 gboolean purple_protocols_remove(PurpleProtocol *protocol)
 {
-	if (purple_find_protocol_info(protocol->id) == NULL)
+	if (purple_find_protocol_info(purple_protocol_get_id(protocol)) == NULL)
 		return FALSE;
 
-	g_hash_table_remove(protocols, protocol->id);
+	g_hash_table_remove(protocols, purple_protocol_get_id(protocol));
 	purple_protocol_destroy(protocol);
 
 	return TRUE;
diff --git a/libpurple/protocols.h b/libpurple/protocols.h
--- a/libpurple/protocols.h
+++ b/libpurple/protocols.h
@@ -410,11 +410,11 @@ PurpleProtocol *purple_find_protocol_inf
 /** TODO A sanity check is needed
  * Adds a protocol to the list of protocols.
  *
- * @param protocol  The protocol to add.
+ * @param protocol_type  The type of the protocol to add.
  *
- * @return TRUE if the protocol was added, else FALSE.
+ * @return The protocol instance if the protocol was added, else @c NULL.
  */
-gboolean purple_protocols_add(PurpleProtocol *protocol);
+PurpleProtocol *purple_protocols_add(GType protocol_type);
 
 /** TODO A sanity check is needed
  * Removes a protocol from the list of protocols. This will disconnect all



More information about the Commits mailing list