gossip r2827 - in trunk: . libgossip



Author: mr
Date: Tue Jul  8 17:57:20 2008
New Revision: 2827
URL: http://svn.gnome.org/viewvc/gossip?rev=2827&view=rev

Log:
Fixed passing NULL to gossip_jid_new() and sort chatrooms
alphabetically by default


Modified:
   trunk/ChangeLog
   trunk/libgossip/gossip-chatroom-manager.c
   trunk/libgossip/gossip-jabber-disco.c

Modified: trunk/libgossip/gossip-chatroom-manager.c
==============================================================================
--- trunk/libgossip/gossip-chatroom-manager.c	(original)
+++ trunk/libgossip/gossip-chatroom-manager.c	Tue Jul  8 17:57:20 2008
@@ -62,6 +62,9 @@
 static void     chatroom_manager_chatroom_favorite_cb (GossipChatroom           *chatroom,
 						       GParamSpec               *arg1,
 						       GossipChatroomManager    *manager);
+static void     chatroom_manager_chatroom_name_cb     (GossipChatroom           *chatroom,
+						       GParamSpec               *arg1,
+						       GossipChatroomManager    *manager);
 static gboolean chatroom_manager_get_all              (GossipChatroomManager    *manager);
 static gboolean chatroom_manager_file_parse           (GossipChatroomManager    *manager,
 						       const gchar              *filename);
@@ -200,6 +203,31 @@
 	return manager;
 }
 
+static gint
+chatroom_sort_func (gconstpointer a,
+		    gconstpointer b)
+{
+	const gchar *name_a;
+	const gchar *name_b;
+
+	name_a = gossip_chatroom_get_name (GOSSIP_CHATROOM (a));
+	name_b = gossip_chatroom_get_name (GOSSIP_CHATROOM (b));
+
+	if (name_a && !name_b) {
+		return -1;
+	}
+
+	if (name_b && !name_a) {
+		return +1;
+	}
+
+	if (!name_a && !name_b) {
+		return 0;
+	}
+
+	return strcmp (name_a, name_b);
+}
+
 gboolean
 gossip_chatroom_manager_add (GossipChatroomManager *manager,
 			     GossipChatroom        *chatroom)
@@ -240,9 +268,14 @@
 	g_signal_connect (chatroom, "notify::favorite",
 			  G_CALLBACK (chatroom_manager_chatroom_favorite_cb),
 			  manager);
+
+	g_signal_connect (chatroom, "notify::name",
+			  G_CALLBACK (chatroom_manager_chatroom_name_cb),
+			  manager);
 	
-	priv->chatrooms = g_list_append (priv->chatrooms,
-					 g_object_ref (chatroom));
+	priv->chatrooms = g_list_insert_sorted (priv->chatrooms, 
+						g_object_ref (chatroom),
+						chatroom_sort_func);
 	
 	g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);
 	
@@ -266,13 +299,17 @@
 		      gossip_chatroom_get_name (chatroom));
 
 	g_signal_handlers_disconnect_by_func (chatroom,
-					      chatroom_manager_chatroom_enabled_cb,
+					      chatroom_manager_chatroom_name_cb,
 					      manager);
 
 	g_signal_handlers_disconnect_by_func (chatroom,
 					      chatroom_manager_chatroom_favorite_cb,
 					      manager);
 
+	g_signal_handlers_disconnect_by_func (chatroom,
+					      chatroom_manager_chatroom_enabled_cb,
+					      manager);
+
 	link = g_list_find (priv->chatrooms, chatroom);
 	if (link) {
 		priv->chatrooms = g_list_delete_link (priv->chatrooms, link);
@@ -311,12 +348,38 @@
 
 static void
 chatroom_manager_chatroom_favorite_cb (GossipChatroom        *chatroom,
-					GParamSpec            *arg1,
-					GossipChatroomManager *manager)
+				       GParamSpec            *arg1,
+				       GossipChatroomManager *manager)
 {
+	GossipChatroomManagerPriv *priv;
+
+	/* We sort here so we resort the list when a chatroom is
+	 * marked as a favorite, this way, newly added favorites
+	 * appear correctly in the right order.
+	 */
+	priv = GET_PRIV (manager);
+
+	priv->chatrooms = g_list_sort (priv->chatrooms, chatroom_sort_func);
+
 	g_signal_emit (manager, signals[CHATROOM_FAVORITE_UPDATE], 0, chatroom);
 }
 
+static void
+chatroom_manager_chatroom_name_cb (GossipChatroom        *chatroom,
+				   GParamSpec            *arg1,
+				   GossipChatroomManager *manager)
+{
+	GossipChatroomManagerPriv *priv;
+
+	/* We sort here so we resort the list when a chatroom name 
+	 * changes, this way, the list in the favorites menu stays up
+	 * to date.
+	 */
+	priv = GET_PRIV (manager);
+
+	priv->chatrooms = g_list_sort (priv->chatrooms, chatroom_sort_func);
+}
+
 GList *
 gossip_chatroom_manager_get_chatrooms (GossipChatroomManager *manager,
 				       GossipAccount         *account)
@@ -333,23 +396,24 @@
 	}
 
 	chatrooms = NULL;
+
 	for (l = priv->chatrooms; l; l = l->next) {
 		GossipChatroom *chatroom;
 		GossipAccount  *this_account;
 
 		chatroom = l->data;
-
 		this_account = gossip_chatroom_get_account (chatroom);
+
 		if (!this_account) {
 			continue;
 		}
 
 		if (gossip_account_equal (account, this_account)) {
-			chatrooms = g_list_append (chatrooms, chatroom);
+			chatrooms = g_list_prepend (chatrooms, chatroom);
 		}
 	}
 
-	return chatrooms;
+	return g_list_reverse (chatrooms);
 }
 
 guint

Modified: trunk/libgossip/gossip-jabber-disco.c
==============================================================================
--- trunk/libgossip/gossip-jabber-disco.c	(original)
+++ trunk/libgossip/gossip-jabber-disco.c	Tue Jul  8 17:57:20 2008
@@ -347,29 +347,30 @@
 			      LmMessage        *m,
 			      gpointer          user_data)
 {
-	GossipJabberDisco *disco;
-	GossipJID         *from_jid;
+	GossipJabberDisco *disco = NULL;
 	const gchar       *from;
 	LmMessageNode     *node;
 	const char        *xmlns;
 
 	from = lm_message_node_get_attribute (m->node, "from");
-	from_jid = gossip_jid_new (from);
+	if (from) {
+		GossipJID *from_jid;
+
+		from_jid = gossip_jid_new (from);
 
-	/* used for info look ups */
-	disco = g_hash_table_lookup (discos, from_jid);
+		/* Used for info look ups */
+		disco = g_hash_table_lookup (discos, from_jid);
+		g_object_unref (from_jid);
+	}
 
-	/* if not listed under the from jid, try the user data */
+	/* If not listed under the from jid, try the user data */
 	if (!disco) {
 		disco = (GossipJabberDisco *) user_data;
 	}
 
 	if (lm_message_get_sub_type (m) != LM_MESSAGE_SUB_TYPE_RESULT &&
 	    lm_message_get_sub_type (m) != LM_MESSAGE_SUB_TYPE_ERROR) {
-		g_object_unref (from_jid);
-
 		return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
-
 	}
 
 	node = lm_message_node_get_child (m->node, "query");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]