/soc/2013/ankitkv/gobjectification: 85008f2cf762: Return protoco...

Ankit Vani a at nevitus.org
Mon Sep 2 18:45:19 EDT 2013


Changeset: 85008f2cf762a1803d2d433ab0f35236ee37d9bf
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-03 04:03 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/85008f2cf762

Description:

Return protocols as a sorted list from purple_protocols_get_all()

diffstat:

 libpurple/protocols.c |  24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diffs (41 lines):

diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -734,6 +734,28 @@ purple_protocol_action_get_type(void)
 /**************************************************************************
  * Protocols API
  **************************************************************************/
+/**
+ * Negative if a before b, 0 if equal, positive if a after b.
+ */
+static gint
+compare_protocol(PurpleProtocol *a, PurpleProtocol *b)
+{
+	const gchar *aname = purple_protocol_get_name(a);
+	const gchar *bname = purple_protocol_get_name(b);
+
+	if (aname) {
+		if (bname)
+			return strcmp(aname, bname);
+		else
+			return -1;
+	} else {
+		if (bname)
+			return 1;
+		else
+			return 0;
+	}
+}
+
 PurpleProtocol *
 purple_protocols_find(const char *id)
 {
@@ -830,7 +852,7 @@ purple_protocols_get_all(void)
 
 	g_hash_table_iter_init(&iter, protocols);
 	while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&protocol))
-		ret = g_list_append(ret, protocol);
+		ret = g_list_insert_sorted(ret, protocol, (GCompareFunc)compare_protocol);
 
 	return ret;
 }



More information about the Commits mailing list