]> git.0d.be Git - empathy.git/commitdiff
Fix reviewer comments
authorXavier Claessens <xclaesse@src.gnome.org>
Tue, 15 Jul 2008 13:23:05 +0000 (13:23 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 15 Jul 2008 13:23:05 +0000 (13:23 +0000)
svn path=/trunk/; revision=1237

libempathy/empathy-chatroom.c
libempathy/empathy-chatroom.h
libempathy/empathy-tp-roomlist.c

index 17be191e593023c4107cc1a5af9783dae1b0ccba..91f86d04e976072ba2b5a202d5d52baba78cfb3a 100644 (file)
@@ -188,15 +188,12 @@ chatroom_set_property (GObject      *object,
 }
 
 EmpathyChatroom *
-empathy_chatroom_new (McAccount   *account,
-                    const gchar *room)
+empathy_chatroom_new (McAccount *account)
 {
        g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-       g_return_val_if_fail (room != NULL, NULL);
 
        return g_object_new (EMPATHY_TYPE_CHATROOM,
                             "account", account,
-                            "room", room,
                             NULL);
 }
 
index 58e2e53d784f1c83d85920d45fd24848f13f6853..a4eecc04a92a8cc59ea65ba7819c4e7706cb30e7 100644 (file)
@@ -50,9 +50,8 @@ struct _EmpathyChatroomClass {
 };
 
 GType            empathy_chatroom_get_type        (void) G_GNUC_CONST;
-EmpathyChatroom *empathy_chatroom_new             (McAccount       *account,
-                                                  const gchar     *room);
-EmpathyChatroom *empathy_chatroom_new_full         (McAccount      *account,
+EmpathyChatroom *empathy_chatroom_new             (McAccount       *account);
+EmpathyChatroom *empathy_chatroom_new_full        (McAccount       *account,
                                                   const gchar     *room,
                                                   const gchar     *name,
                                                   gboolean         auto_connect);
index 04984096d98451d830a5464da00a752488aa2092..b54aec82408cb81051f7c69a94c1ff01a6d2b550 100644 (file)
@@ -73,6 +73,35 @@ tp_roomlist_listing_cb (TpChannel *channel,
        g_object_notify (list, "is-listing");
 }
 
+static void
+tp_roomlist_chatrooms_free (gpointer data)
+{
+       GSList *chatrooms = data;
+
+       g_slist_foreach (chatrooms, (GFunc) g_object_unref, NULL);
+       g_slist_free (chatrooms);
+}
+
+static void
+tp_roomlist_inspect_handles_cb (TpConnection *connection,
+                               const gchar **names,
+                               const GError *error,
+                               gpointer      user_data,
+                               GObject      *list)
+{
+       GSList *chatrooms = user_data;
+
+       while (*names) {
+               EmpathyChatroom *chatroom = chatrooms->data;
+
+               empathy_chatroom_set_room (chatroom, *names);
+               g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
+
+               names++;
+               chatrooms = chatrooms->next;
+       }
+}
+
 static void
 tp_roomlist_got_rooms_cb (TpChannel       *channel,
                          const GPtrArray *rooms,
@@ -82,10 +111,8 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
        EmpathyTpRoomlistPriv *priv = GET_PRIV (list);
        EmpathyChatroom       *chatroom;
        guint                  i;
-       gchar                **room_ids;
        GArray                *handles = NULL;
-       GSList                *chatrooms = NULL, *l;
-       const gchar           *str;
+       GSList                *chatrooms = NULL;
 
        for (i = 0; i < rooms->len; i++) {
                const GValue *room_name_value;
@@ -107,25 +134,24 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
                        continue;
                }
 
-               chatroom = g_object_new (EMPATHY_TYPE_CHATROOM,
-                                        "account", priv->account,
-                                        NULL);
+               chatroom = empathy_chatroom_new (priv->account);
 
-               if (room_name_value) {
-                       str = g_value_get_string (room_name_value);
-                       empathy_chatroom_set_name (chatroom, str);
+               if (room_name_value != NULL) {
+                       empathy_chatroom_set_name (chatroom,
+                                                  g_value_get_string (room_name_value));
                }
 
-               if (handle_name_value) {
-                       str = g_value_get_string (handle_name_value);
-                       empathy_chatroom_set_room (chatroom, str);
+               if (handle_name_value != NULL) {
+                       empathy_chatroom_set_room (chatroom,
+                                                  g_value_get_string (handle_name_value));
 
-                       /* Room is ready, emit it */
+                       /* We have the room ID, we can directly emit it */
                        g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
                        g_object_unref (chatroom);
                } else {
-                       /* We first need to inspect the handle */
-                       if (!handles) {
+                       /* We don't have the room ID, we'll inspect all handles
+                        * at once and then emit rooms */
+                       if (handles == NULL) {
                                handles = g_array_new (FALSE, FALSE, sizeof (guint));
                        }
 
@@ -134,31 +160,18 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
                }
        }
 
-       if (!handles) {
-               /* All rooms were ready, we are done */
-               return;
+       if (handles != NULL) {
+               chatrooms = g_slist_reverse (chatrooms);
+               tp_cli_connection_call_inspect_handles (priv->connection, -1,
+                                                      TP_HANDLE_TYPE_ROOM,
+                                                      handles,
+                                                      tp_roomlist_inspect_handles_cb,
+                                                      chatrooms,
+                                                      tp_roomlist_chatrooms_free,
+                                                      list);
        }
 
-       tp_cli_connection_run_inspect_handles (priv->connection, -1,
-                                              TP_HANDLE_TYPE_ROOM,
-                                              handles,
-                                              &room_ids,
-                                              NULL, NULL);
-
-       l = chatrooms = g_slist_reverse (chatrooms);
-       for (i = 0; i < handles->len; i++) {
-               EmpathyChatroom *chatroom = l->data;
-
-               empathy_chatroom_set_room (chatroom, room_ids[i]);
-               g_signal_emit (list, signals[NEW_ROOM], 0, chatroom);
-
-               g_object_unref (chatroom);
-               g_free (room_ids[i]);
-       }
-
-       g_free (room_ids);
        g_array_free (handles, TRUE);
-       g_slist_free (chatrooms);
 }
 
 static void