]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Merge branch 'undo-close-tab'
[empathy.git] / src / empathy-chat-window.c
index bea85c648fc075bf7d7f0ba39f902322639e1661..e18ae2583437869caac8fc82db6ce4dd1bcf381a 100644 (file)
 
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-message.h>
-#include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-tp-contact-factory.h>
+#include <libempathy/empathy-contact-list.h>
 
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-conf.h>
@@ -53,8 +54,7 @@
 #include <libempathy-gtk/empathy-ui-utils.h>
 #include <libempathy-gtk/empathy-notify-manager.h>
 
-#include <extensions/extensions.h>
-
+#include "empathy-chat-manager.h"
 #include "empathy-chat-window.h"
 #include "empathy-about-dialog.h"
 #include "empathy-invite-participant-dialog.h"
@@ -85,6 +85,9 @@ typedef struct {
        GtkTargetList *contact_targets;
        GtkTargetList *file_targets;
 
+       EmpathyChatManager *chat_manager;
+       gulong chat_manager_chats_changed_id;
+
        /* Menu items. */
        GtkUIManager *ui_manager;
        GtkAction   *menu_conv_insert_smiley;
@@ -94,9 +97,11 @@ typedef struct {
        GtkAction   *menu_edit_cut;
        GtkAction   *menu_edit_copy;
        GtkAction   *menu_edit_paste;
+       GtkAction   *menu_edit_find;
 
        GtkAction   *menu_tabs_next;
        GtkAction   *menu_tabs_prev;
+       GtkAction   *menu_tabs_undo_close_tab;
        GtkAction   *menu_tabs_left;
        GtkAction   *menu_tabs_right;
        GtkAction   *menu_tabs_detach;
@@ -119,6 +124,7 @@ static const GtkTargetEntry drag_types_dest[] = {
        { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
        { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB },
        { "text/uri-list", 0, DND_DRAG_TYPE_URI_LIST },
+       { "text/path-list", 0, DND_DRAG_TYPE_URI_LIST },
 };
 
 static const GtkTargetEntry drag_types_dest_contact[] = {
@@ -126,6 +132,9 @@ static const GtkTargetEntry drag_types_dest_contact[] = {
 };
 
 static const GtkTargetEntry drag_types_dest_file[] = {
+       /* must be first to be prioritized, in order to receive the
+        * note's file path from Tomboy instead of an URI */
+       { "text/path-list", 0, DND_DRAG_TYPE_URI_LIST },
        { "text/uri-list", 0, DND_DRAG_TYPE_URI_LIST },
 };
 
@@ -329,24 +338,53 @@ chat_window_menu_context_update (EmpathyChatWindowPriv *priv,
 {
        gboolean first_page;
        gboolean last_page;
+       gboolean wrap_around;
        gboolean is_connected;
        gint     page_num;
 
        page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
        first_page = (page_num == 0);
        last_page = (page_num == (num_pages - 1));
+       g_object_get (gtk_settings_get_default (), "gtk-keynav-wrap-around",
+                     &wrap_around, NULL);
        is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
 
-       DEBUG ("Update window : Menu Contexts (Tabs & Conv)");
-
-       gtk_action_set_sensitive (priv->menu_tabs_next, TRUE);
-       gtk_action_set_sensitive (priv->menu_tabs_prev, TRUE);
+       gtk_action_set_sensitive (priv->menu_tabs_next, (!last_page ||
+                                                        wrap_around));
+       gtk_action_set_sensitive (priv->menu_tabs_prev, (!first_page ||
+                                                        wrap_around));
        gtk_action_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
        gtk_action_set_sensitive (priv->menu_tabs_left, !first_page);
        gtk_action_set_sensitive (priv->menu_tabs_right, !last_page);
        gtk_action_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
 }
 
+static void
+chat_window_conversation_menu_update (EmpathyChatWindowPriv *priv,
+                                      EmpathyChatWindow     *self)
+{
+       EmpathyTpChat *tp_chat;
+       TpConnection *connection;
+       GtkAction *action;
+       gboolean sensitive = FALSE;
+
+       g_return_if_fail (priv->current_chat != NULL);
+
+       action = gtk_ui_manager_get_action (priv->ui_manager,
+               "/chats_menubar/menu_conv/menu_conv_invite_participant");
+       tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
+
+       if (tp_chat != NULL) {
+               connection = empathy_tp_chat_get_connection (tp_chat);
+
+               sensitive = empathy_tp_chat_can_add_contact (tp_chat) &&
+                       (tp_connection_get_status (connection, NULL) ==
+                        TP_CONNECTION_STATUS_CONNECTED);
+       }
+
+       gtk_action_set_sensitive (action, sensitive);
+}
+
 static void
 chat_window_contact_menu_update (EmpathyChatWindowPriv *priv,
                                 EmpathyChatWindow     *window)
@@ -357,8 +395,6 @@ chat_window_contact_menu_update (EmpathyChatWindowPriv *priv,
                "/chats_menubar/menu_contact");
        orig_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
 
-       DEBUG ("Update window : Contact Menu");
-
        if (orig_submenu == NULL || !GTK_WIDGET_VISIBLE (orig_submenu)) {
                submenu = empathy_chat_get_contact_menu (priv->current_chat);
                gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
@@ -457,8 +493,6 @@ chat_window_title_update (EmpathyChatWindowPriv *priv)
 {
        gchar *name;
 
-       DEBUG ("Update window : Title");
-
        name = get_window_title_name (priv);
        gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
        g_free (name);
@@ -474,8 +508,6 @@ chat_window_icon_update (EmpathyChatWindowPriv *priv)
 
        n_chats = g_list_length (priv->chats);
 
-       DEBUG ("Update window : Icon");
-
        /* Update window icon */
        if (priv->chats_new_msg) {
                gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
@@ -507,8 +539,6 @@ chat_window_close_button_update (EmpathyChatWindowPriv *priv,
        GtkWidget *chat_close_button;
        gint       i;
 
-       DEBUG ("Update window : Close Button");
-
        if (num_pages == 1) {
                chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 0);
                chat_close_button = g_object_get_data (G_OBJECT (chat),
@@ -532,12 +562,12 @@ chat_window_update (EmpathyChatWindow *window)
 
        num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
 
-       DEBUG ("Update window");
-
        /* Update Tab menu */
        chat_window_menu_context_update (priv,
                                         num_pages);
 
+       chat_window_conversation_menu_update (priv, window);
+
        chat_window_contact_menu_update (priv,
                                         window);
 
@@ -821,48 +851,21 @@ chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
 }
 
 static void
-chat_window_upgrade_to_muc (EmpathyChat    *chat,
-                            EmpathyContact *invitee)
+got_contact_cb (EmpathyTpContactFactory *factory,
+                EmpathyContact          *contact,
+                const GError            *error,
+                gpointer                 user_data,
+                GObject                 *object)
 {
-       EmpathyDispatcher     *dispatcher = empathy_dispatcher_dup_singleton ();
-       EmpathyTpChat         *tp_chat;
-       TpConnection          *connection;
-       TpChannel             *channel;
-       GHashTable            *props;
-       GPtrArray             *channels;
-       char                  *invitees[3] = { NULL, };
-
-       tp_chat = empathy_chat_get_tp_chat (chat);
-       connection = empathy_tp_chat_get_connection (tp_chat);
-       channel = empathy_tp_chat_get_channel (tp_chat);
-
-       /* Ensure a MUC channel */
-       channels = g_ptr_array_sized_new (1);
-       g_ptr_array_add (channels, (char *) tp_proxy_get_object_path (channel));
-
-       invitees[0] = (char *) tp_channel_get_identifier (channel);
-       invitees[1] = (char *) empathy_contact_get_id (invitee);
-
-       props = tp_asv_new (
-           TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
-               TP_IFACE_CHANNEL_TYPE_TEXT,
-           TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT,
-               TP_HANDLE_TYPE_NONE,
-           EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialChannels",
-               TP_ARRAY_TYPE_OBJECT_PATH_LIST, channels,
-           EMP_IFACE_CHANNEL_INTERFACE_CONFERENCE ".InitialInviteeIDs",
-               G_TYPE_STRV, invitees,
-           /* FIXME: InvitationMessage ? */
-           NULL);
+       EmpathyTpChat *tp_chat = EMPATHY_TP_CHAT (user_data);
 
-       /* Although this is a MUC, it's anonymous, so CreateChannel is valid */
-       empathy_dispatcher_create_channel (dispatcher, connection,
-                       props, NULL, NULL);
-
-       g_hash_table_destroy (props);
-       g_ptr_array_free (channels, TRUE);
-
-       g_object_unref (dispatcher);
+       if (error != NULL) {
+               DEBUG ("Failed: %s", error->message);
+               return;
+       } else {
+               empathy_contact_list_add (EMPATHY_CONTACT_LIST (tp_chat),
+                               contact, _("Inviting you to this room"));
+       }
 }
 
 static void
@@ -874,6 +877,7 @@ chat_window_invite_participant_activate_cb (GtkAction         *action,
        EmpathyTpChat         *tp_chat;
        TpChannel             *channel;
        int                    response;
+       TpAccount             *account;
 
        priv = GET_PRIV (window);
 
@@ -881,42 +885,33 @@ chat_window_invite_participant_activate_cb (GtkAction         *action,
 
        tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
        channel = empathy_tp_chat_get_channel (tp_chat);
+       account = empathy_chat_get_account (priv->current_chat);
 
-       /* FIXME: should filter out the existing participants from the
-        * list */
        dialog = empathy_invite_participant_dialog_new (
-                       GTK_WINDOW (priv->dialog));
+                       GTK_WINDOW (priv->dialog), account);
        gtk_widget_show (dialog);
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
 
-       if (response == GTK_RESPONSE_OK)
-       {
-               EmpathyContact *contact;
-               TpHandleType handle_type;
+       if (response == GTK_RESPONSE_ACCEPT) {
+               TpConnection *connection;
+               EmpathyTpContactFactory *factory;
+               const char *id;
 
-               contact = empathy_invite_participant_dialog_dup_selected_contact (EMPATHY_INVITE_PARTICIPANT_DIALOG (dialog));
-               tp_channel_get_handle (channel, &handle_type);
+               id = empathy_contact_selector_dialog_get_selected (
+                               EMPATHY_CONTACT_SELECTOR_DIALOG (dialog), NULL);
+               if (EMP_STR_EMPTY (id)) goto out;
 
-               if (handle_type == TP_HANDLE_TYPE_CONTACT)
-               {
-                       chat_window_upgrade_to_muc (priv->current_chat,
-                                       contact);
-               }
-               else
-               {
-                       TpHandle handle = empathy_contact_get_handle (contact);
-                       GArray handles = {(gchar *) &handle, 1};
-
-                       tp_cli_channel_interface_group_call_add_members (
-                                       channel, -1, &handles,
-                                       _("Inviting to this room"),
-                                       NULL, NULL, NULL, NULL);
-               }
+               connection = tp_channel_borrow_connection (channel);
+               factory = empathy_tp_contact_factory_dup_singleton (connection);
 
-               g_object_unref (contact);
+               empathy_tp_contact_factory_get_from_id (factory, id,
+                       got_contact_cb, tp_chat,  NULL, NULL);
+
+               g_object_unref (factory);
        }
 
+out:
        gtk_widget_destroy (dialog);
 }
 
@@ -1010,6 +1005,19 @@ chat_window_paste_activate_cb (GtkAction         *action,
        empathy_chat_paste (priv->current_chat);
 }
 
+static void
+chat_window_find_activate_cb (GtkAction         *action,
+                             EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv;
+
+       g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
+
+       priv = GET_PRIV (window);
+
+       empathy_chat_find (priv->current_chat);
+}
+
 static void
 chat_window_tabs_next_activate_cb (GtkAction         *action,
                                   EmpathyChatWindow *window)
@@ -1017,14 +1025,18 @@ chat_window_tabs_next_activate_cb (GtkAction         *action,
        EmpathyChatWindowPriv *priv;
        EmpathyChat           *chat;
        gint                  index_, numPages;
+       gboolean              wrap_around;
 
        priv = GET_PRIV (window);
 
+       g_object_get (gtk_settings_get_default (), "gtk-keynav-wrap-around",
+                      &wrap_around, NULL);
+
        chat = priv->current_chat;
        index_ = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
        numPages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
 
-       if (index_ == (numPages - 1)) {
+       if (index_ == (numPages - 1) && wrap_around) {
                gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0);
                return;
        }
@@ -1039,14 +1051,18 @@ chat_window_tabs_previous_activate_cb (GtkAction         *action,
        EmpathyChatWindowPriv *priv;
        EmpathyChat           *chat;
        gint                  index_, numPages;
+       gboolean              wrap_around;
 
        priv = GET_PRIV (window);
 
+       g_object_get (gtk_settings_get_default (), "gtk-keynav-wrap-around",
+                      &wrap_around, NULL);
+
        chat = priv->current_chat;
        index_ = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
        numPages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
 
-       if (index_ <= 0) {
+       if (index_ <= 0 && wrap_around) {
                gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), numPages - 1);
                return;
        }
@@ -1054,6 +1070,14 @@ chat_window_tabs_previous_activate_cb (GtkAction         *action,
        gtk_notebook_prev_page (GTK_NOTEBOOK (priv->notebook));
 }
 
+static void
+chat_window_tabs_undo_close_tab_activate_cb (GtkAction         *action,
+                                            EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       empathy_chat_manager_undo_closed_chat (priv->chat_manager);
+}
+
 static void
 chat_window_tabs_left_activate_cb (GtkAction         *action,
                                   EmpathyChatWindow *window)
@@ -1174,7 +1198,6 @@ chat_window_set_urgency_hint (EmpathyChatWindow *window,
 
        priv = GET_PRIV (window);
 
-       DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
        gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
 }
 
@@ -1311,6 +1334,8 @@ chat_window_new_message_cb (EmpathyChat       *chat,
 
        if (has_focus && priv->current_chat == chat) {
                /* window and tab are focused so consider the message to be read */
+
+               /* FIXME: see Bug#610994 and coments about it in EmpathyChatPriv */
                empathy_chat_messages_read (chat);
                return;
        }
@@ -1510,8 +1535,6 @@ chat_window_focus_in_event_cb (GtkWidget        *widget,
 {
        EmpathyChatWindowPriv *priv;
 
-       DEBUG ("Focus in event, updating title");
-
        priv = GET_PRIV (window);
 
        priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
@@ -1526,7 +1549,7 @@ chat_window_focus_in_event_cb (GtkWidget        *widget,
 }
 
 static gboolean
-chat_window_drag_motion (GtkWidget        *widget,
+chat_window_drag_drop (GtkWidget        *widget,
                         GdkDragContext   *context,
                         int               x,
                         int               y,
@@ -1535,14 +1558,36 @@ chat_window_drag_motion (GtkWidget        *widget,
 {
        GdkAtom target;
        EmpathyChatWindowPriv *priv;
-       GdkAtom dest_target;
 
        priv = GET_PRIV (window);
 
-       target = gtk_drag_dest_find_target (widget, context, NULL);
+       target = gtk_drag_dest_find_target (widget, context, priv->file_targets);
+       if (target == GDK_NONE)
+               target = gtk_drag_dest_find_target (widget, context, priv->contact_targets);
 
-       dest_target = gdk_atom_intern_static_string ("text/uri-list");
-       if (target == dest_target) {
+       if (target != GDK_NONE) {
+               gtk_drag_get_data (widget, context, target, time_);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static gboolean
+chat_window_drag_motion (GtkWidget        *widget,
+                        GdkDragContext   *context,
+                        int               x,
+                        int               y,
+                        guint             time_,
+                        EmpathyChatWindow *window)
+{
+       GdkAtom target;
+       EmpathyChatWindowPriv *priv;
+
+       priv = GET_PRIV (window);
+
+       target = gtk_drag_dest_find_target (widget, context, priv->file_targets);
+       if (target != GDK_NONE) {
                /* This is a file drag.  Ensure the contact is online and set the
                   drag type to COPY.  Note that it's possible that the tab will
                   be switched by GTK+ after a timeout from drag_motion without
@@ -1571,8 +1616,8 @@ chat_window_drag_motion (GtkWidget        *widget,
                return TRUE;
        }
 
-       dest_target = gdk_atom_intern_static_string ("text/contact-id");
-       if (target == dest_target) {
+       target = gtk_drag_dest_find_target (widget, context, priv->contact_targets);
+       if (target != GDK_NONE) {
                /* This is a drag of a contact from a contact list.  Set to COPY.
                   FIXME: If this drag is to a MUC window, it invites the user.
                   Otherwise, it opens a chat.  Should we use a different drag
@@ -1582,9 +1627,7 @@ chat_window_drag_motion (GtkWidget        *widget,
                return TRUE;
        }
 
-       /* Otherwise, it must be a notebook tab drag.  Set to MOVE. */
-       gdk_drag_status (context, GDK_ACTION_MOVE, time_);
-       return TRUE;
+       return FALSE;
 }
 
 static void
@@ -1703,29 +1746,27 @@ chat_window_drag_data_received (GtkWidget        *widget,
                        EmpathyChatWindowPriv *priv;
 
                        priv = GET_PRIV (window);
-
-                       if (old_window == window) {
-                               DEBUG ("DND tab (within same window)");
-                               priv->dnd_same_window = TRUE;
-                               gtk_drag_finish (context, TRUE, FALSE, time_);
-                               return;
-                       }
-
-                       priv->dnd_same_window = FALSE;
+                       priv->dnd_same_window = (old_window == window);
+                       DEBUG ("DND tab (within same window: %s)",
+                               priv->dnd_same_window ? "Yes" : "No");
                }
-
-               /* We should return TRUE to remove the data when doing
-                * GDK_ACTION_MOVE, but we don't here otherwise it has
-                * weird consequences, and we handle that internally
-                * anyway with add_chat () and remove_chat ().
-                */
-               gtk_drag_finish (context, TRUE, FALSE, time_);
        } else {
                DEBUG ("DND from unknown source");
                gtk_drag_finish (context, FALSE, FALSE, time_);
        }
 }
 
+static void
+chat_window_chat_manager_chats_changed_cb (EmpathyChatManager *chat_manager,
+                                          guint num_chats_in_manager,
+                                          EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+
+       gtk_action_set_sensitive (priv->menu_tabs_undo_close_tab,
+                                 num_chats_in_manager > 0);
+}
+
 static void
 chat_window_finalize (GObject *object)
 {
@@ -1759,6 +1800,13 @@ chat_window_finalize (GObject *object)
                gtk_target_list_unref (priv->file_targets);
        }
 
+       if (priv->chat_manager) {
+               g_signal_handler_disconnect (priv->chat_manager,
+                                            priv->chat_manager_chats_changed_id);
+               g_object_unref (priv->chat_manager);
+               priv->chat_manager = NULL;
+       }
+
        chat_windows = g_list_remove (chat_windows, window);
        gtk_widget_destroy (priv->dialog);
 
@@ -1814,8 +1862,10 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                       "menu_edit_cut", &priv->menu_edit_cut,
                                       "menu_edit_copy", &priv->menu_edit_copy,
                                       "menu_edit_paste", &priv->menu_edit_paste,
+                                      "menu_edit_find", &priv->menu_edit_find,
                                       "menu_tabs_next", &priv->menu_tabs_next,
                                       "menu_tabs_prev", &priv->menu_tabs_prev,
+                                      "menu_tabs_undo_close_tab", &priv->menu_tabs_undo_close_tab,
                                       "menu_tabs_left", &priv->menu_tabs_left,
                                       "menu_tabs_right", &priv->menu_tabs_right,
                                       "menu_tabs_detach", &priv->menu_tabs_detach,
@@ -1833,8 +1883,10 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                              "menu_edit_cut", "activate", chat_window_cut_activate_cb,
                              "menu_edit_copy", "activate", chat_window_copy_activate_cb,
                              "menu_edit_paste", "activate", chat_window_paste_activate_cb,
+                             "menu_edit_find", "activate", chat_window_find_activate_cb,
                              "menu_tabs_next", "activate", chat_window_tabs_next_activate_cb,
                              "menu_tabs_prev", "activate", chat_window_tabs_previous_activate_cb,
+                             "menu_tabs_undo_close_tab", "activate", chat_window_tabs_undo_close_tab_activate_cb,
                              "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
                              "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
                              "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
@@ -1914,7 +1966,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
 
        /* Set up drag and drop */
        gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
-                          GTK_DEST_DEFAULT_ALL,
+                          GTK_DEST_DEFAULT_HIGHLIGHT,
                           drag_types_dest,
                           G_N_ELEMENTS (drag_types_dest),
                           GDK_ACTION_MOVE | GDK_ACTION_COPY);
@@ -1928,6 +1980,10 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                          "drag-data-received",
                          G_CALLBACK (chat_window_drag_data_received),
                          window);
+       g_signal_connect (priv->notebook,
+                         "drag-drop",
+                         G_CALLBACK (chat_window_drag_drop),
+                         window);
 
        chat_windows = g_list_prepend (chat_windows, window);
 
@@ -1938,6 +1994,16 @@ empathy_chat_window_init (EmpathyChatWindow *window)
        priv->current_chat = NULL;
 
        priv->notify_mgr = empathy_notify_manager_dup_singleton ();
+
+       priv->chat_manager = empathy_chat_manager_dup_singleton ();
+       priv->chat_manager_chats_changed_id =
+               g_signal_connect (priv->chat_manager, "chats-changed",
+                                 G_CALLBACK (chat_window_chat_manager_chats_changed_cb),
+                                 window);
+
+       chat_window_chat_manager_chats_changed_cb (priv->chat_manager,
+                                                  empathy_chat_manager_get_num_chats (priv->chat_manager),
+                                                  window);
 }
 
 EmpathyChatWindow *
@@ -2014,6 +2080,7 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        GtkWidget             *label;
        GtkWidget             *popup_label;
        GtkWidget             *child;
+       GValue                value = { 0, };
 
        g_return_if_fail (window != NULL);
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
@@ -2061,8 +2128,13 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        gtk_notebook_append_page_menu (GTK_NOTEBOOK (priv->notebook), child, label, popup_label);
        gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
        gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
-       gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
-                                           TRUE, TRUE, GTK_PACK_START);
+       g_value_init (&value, G_TYPE_BOOLEAN);
+       g_value_set_boolean (&value, TRUE);
+       gtk_container_child_set_property (GTK_CONTAINER (priv->notebook),
+                                         child, "tab-expand" , &value);
+       gtk_container_child_set_property (GTK_CONTAINER (priv->notebook),
+                                         child,  "tab-fill" , &value);
+       g_value_unset (&value);
 
        DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
 }
@@ -2074,6 +2146,7 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
        EmpathyChatWindowPriv *priv;
        gint                   position;
        EmpathyContact        *remote_contact;
+       EmpathyChatManager    *chat_manager;
 
        g_return_if_fail (window != NULL);
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
@@ -2091,6 +2164,10 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
                                                      chat);
        }
 
+       chat_manager = empathy_chat_manager_dup_singleton ();
+       empathy_chat_manager_closed_chat (chat_manager, chat);
+       g_object_unref (chat_manager);
+
        position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
                                          GTK_WIDGET (chat));
        gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
@@ -2215,7 +2292,7 @@ empathy_chat_window_present_chat (EmpathyChat *chat)
 
        priv = GET_PRIV (window);
        empathy_chat_window_switch_to_chat (window, chat);
-       empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
+       empathy_window_present (GTK_WINDOW (priv->dialog));
 
        gtk_widget_grab_focus (chat->input_text_view);
 }