]> git.0d.be Git - empathy.git/blobdiff - src/empathy-chat-window.c
Chat window's tab label changes the font color when got an incoming msg. (Fixes ...
[empathy.git] / src / empathy-chat-window.c
index eef8911822037c2d3eaadc673974569375e0cd45..8dcb68d2f62ea70799eb03ac9ae142b8515271ae 100644 (file)
@@ -15,9 +15,9 @@
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- * 
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
  * Authors: Mikael Hallendal <micke@imendio.com>
  *          Richard Hult <richard@imendio.com>
  *          Martyn Russell <martyn@imendio.com>
 
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
-#include <glade/glade.h>
 #include <glib/gi18n.h>
+#include <libnotify/notification.h>
 
+#include <telepathy-glib/util.h>
 #include <libmissioncontrol/mission-control.h>
 
-#include <libempathy/empathy-contact-factory.h>
-#include <libempathy/empathy-log-manager.h>
-#include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-debug.h>
 #include <libempathy/empathy-message.h>
+#include <libempathy/empathy-dispatcher.h>
+#include <libempathy/empathy-chatroom-manager.h>
+#include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-utils.h>
 
 #include <libempathy-gtk/empathy-images.h>
 #include <libempathy-gtk/empathy-conf.h>
 #include <libempathy-gtk/empathy-contact-dialogs.h>
 #include <libempathy-gtk/empathy-log-window.h>
+#include <libempathy-gtk/empathy-geometry.h>
+#include <libempathy-gtk/empathy-smiley-manager.h>
+#include <libempathy-gtk/empathy-sound.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 
 #include "empathy-chat-window.h"
-#include "empathy-new-chatroom-dialog.h"
-#include "empathy-preferences.h"
 #include "empathy-about-dialog.h"
+#include "empathy-misc.h"
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv))
-
-#define DEBUG_DOMAIN "ChatWindow"
+#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
+#include <libempathy/empathy-debug.h>
 
-struct _EmpathyChatWindowPriv {
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatWindow)
+typedef struct {
+       EmpathyChat *current_chat;
+       GList       *chats;
+       GList       *chats_new_msg;
+       GList       *chats_composing;
+       gboolean     page_added;
+       gboolean     dnd_same_window;
+       guint        save_geometry_id;
        EmpathyChatroomManager *chatroom_manager;
-       GList                  *chats;
-       GList                  *chats_new_msg;
-       GList                  *chats_composing;
-       EmpathyChat            *current_chat;
-       gboolean                page_added;
-       gboolean                dnd_same_window;
-       guint                   save_geometry_id;
-       GtkWidget              *dialog;
-       GtkWidget              *notebook;
+       GtkWidget   *dialog;
+       GtkWidget   *notebook;
+       NotifyNotification *notification;
 
        /* Menu items. */
-       GtkWidget             *menu_conv_clear;
-       GtkWidget             *menu_conv_insert_smiley;
-       GtkWidget             *menu_conv_call;
-       GtkWidget             *menu_conv_call_separator;
-       GtkWidget             *menu_conv_log;
-       GtkWidget             *menu_conv_separator;
-       GtkWidget             *menu_conv_add_contact;
-       GtkWidget             *menu_conv_info;
-       GtkWidget             *menu_conv_close;
-
-       GtkWidget             *menu_room;
-       GtkWidget             *menu_room_set_topic;
-       GtkWidget             *menu_room_join_new;
-       GtkWidget             *menu_room_invite;
-       GtkWidget             *menu_room_add;
-       GtkWidget             *menu_room_show_contacts;
-
-       GtkWidget             *menu_edit_cut;
-       GtkWidget             *menu_edit_copy;
-       GtkWidget             *menu_edit_paste;
-
-       GtkWidget             *menu_tabs_next;
-       GtkWidget             *menu_tabs_prev;
-       GtkWidget             *menu_tabs_left;
-       GtkWidget             *menu_tabs_right;
-       GtkWidget             *menu_tabs_detach;
-       
-       GtkWidget             *menu_help_contents;
-       GtkWidget             *menu_help_about;
-};
-
-static void       empathy_chat_window_class_init (EmpathyChatWindowClass *klass);
-static void       empathy_chat_window_init       (EmpathyChatWindow      *window);
-static void       chat_window_finalize           (GObject                *object);
+       GtkUIManager *ui_manager;
+       GtkAction   *menu_conv_insert_smiley;
+       GtkAction   *menu_conv_favorite;
+       GtkAction   *menu_conv_toggle_contacts;
+
+       GtkAction   *menu_edit_cut;
+       GtkAction   *menu_edit_copy;
+       GtkAction   *menu_edit_paste;
+
+       GtkAction   *menu_tabs_next;
+       GtkAction   *menu_tabs_prev;
+       GtkAction   *menu_tabs_left;
+       GtkAction   *menu_tabs_right;
+       GtkAction   *menu_tabs_detach;
+} EmpathyChatWindowPriv;
 
 static GList *chat_windows = NULL;
 
@@ -169,7 +153,7 @@ chat_window_find_chat (EmpathyChat *chat)
 }
 
 static void
-chat_window_close_clicked_cb (GtkWidget  *button,
+chat_window_close_clicked_cb (GtkAction   *action,
                              EmpathyChat *chat)
 {
        EmpathyChatWindow *window;
@@ -179,45 +163,39 @@ chat_window_close_clicked_cb (GtkWidget  *button,
 }
 
 static void
-chat_window_close_button_style_set_cb (GtkWidget *button,
+chat_tab_style_set_cb (GtkWidget *hbox,
                                       GtkStyle  *previous_style,
                                       gpointer   user_data)
 {
-       gint h, w;
+       GtkWidget *button;
+       int char_width, h, w;
+       PangoContext *context;
+       PangoFontMetrics *metrics;
 
-       gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
-                                          GTK_ICON_SIZE_MENU, &w, &h);
+       button = g_object_get_data (G_OBJECT (user_data),
+               "chat-window-tab-close-button");
+       context = gtk_widget_get_pango_context (hbox);
 
-       gtk_widget_set_size_request (button, w, h);
-}
+       metrics = pango_context_get_metrics (context, gtk_widget_get_style (hbox)->font_desc,
+               pango_context_get_language (context));
+       char_width = pango_font_metrics_get_approximate_char_width (metrics);
+       pango_font_metrics_unref (metrics);
 
-static void
-chat_window_update_tooltip (EmpathyChatWindow *window,
-                           EmpathyChat       *chat)
-{
-       EmpathyChatWindowPriv *priv;
-       GtkWidget             *widget;
-       const gchar           *tooltip;
-       gchar                 *str = NULL;
-
-       priv = GET_PRIV (window);
-
-       tooltip = empathy_chat_get_tooltip (chat);
-
-       if (g_list_find (priv->chats_composing, chat)) {
-               str = g_strconcat (tooltip, "\n", _("Typing a message."), NULL);
-               tooltip = str;
-       }
+       gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
+                                          GTK_ICON_SIZE_MENU, &w, &h);
 
-       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
-       gtk_widget_set_tooltip_text (widget, tooltip);
+       /* Request at least about 12 chars width plus at least space for the status
+        * image and the close button */
+       gtk_widget_set_size_request (hbox,
+               12 * PANGO_PIXELS (char_width) + 2 * w, -1);
 
-       g_free (str);
+       gtk_widget_set_size_request (button, w, h);
 }
 
 static GtkWidget *
 chat_window_create_label (EmpathyChatWindow *window,
-                         EmpathyChat       *chat)
+                         EmpathyChat       *chat,
+                         gboolean           is_tab_label)
 {
        EmpathyChatWindowPriv *priv;
        GtkWidget            *hbox;
@@ -238,8 +216,9 @@ chat_window_create_label (EmpathyChatWindow *window,
        event_box = gtk_event_box_new ();
        gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
 
-       name_label = gtk_label_new (empathy_chat_get_name (chat));
-       gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
+       name_label = gtk_label_new (NULL);
+       if (is_tab_label)
+               gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
 
        attr_list = pango_attr_list_new ();
        attr = pango_attr_scale_new (1/1.2);
@@ -251,7 +230,9 @@ chat_window_create_label (EmpathyChatWindow *window,
 
        gtk_misc_set_padding (GTK_MISC (name_label), 2, 0);
        gtk_misc_set_alignment (GTK_MISC (name_label), 0.0, 0.5);
-       g_object_set_data (G_OBJECT (chat), "chat-window-tab-label", name_label);
+       g_object_set_data (G_OBJECT (chat),
+               is_tab_label ? "chat-window-tab-label" : "chat-window-menu-label",
+               name_label);
 
        status_image = gtk_image_new ();
 
@@ -261,44 +242,47 @@ chat_window_create_label (EmpathyChatWindow *window,
        gtk_box_pack_start (GTK_BOX (event_box_hbox), status_image, FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (event_box_hbox), name_label, TRUE, TRUE, 0);
 
-       g_object_set_data (G_OBJECT (chat), "chat-window-tab-image", status_image);
-       g_object_set_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget", event_box);
+       g_object_set_data (G_OBJECT (chat),
+               is_tab_label ? "chat-window-tab-image" : "chat-window-menu-image",
+               status_image);
+       g_object_set_data (G_OBJECT (chat),
+               is_tab_label ? "chat-window-tab-tooltip-widget" : "chat-window-menu-tooltip-widget",
+               event_box);
 
-       close_button = gtk_button_new ();
-       gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+       gtk_container_add (GTK_CONTAINER (event_box), event_box_hbox);
+       gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
 
-       /* We don't want focus/keynav for the button to avoid clutter, and
-        * Ctrl-W works anyway.
-        */
-       GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_FOCUS);
-       GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_DEFAULT);
+       if (is_tab_label) {
+               close_button = gtk_button_new ();
+               gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+               g_object_set_data (G_OBJECT (chat), "chat-window-tab-close-button", close_button);
 
-       /* Set the name to make the special rc style match. */
-       gtk_widget_set_name (close_button, "empathy-close-button");
+               /* We don't want focus/keynav for the button to avoid clutter, and
+                * Ctrl-W works anyway.
+                */
+               GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_FOCUS);
+               GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_DEFAULT);
 
-       close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+               /* Set the name to make the special rc style match. */
+               gtk_widget_set_name (close_button, "empathy-close-button");
 
-       gtk_container_add (GTK_CONTAINER (close_button), close_image);
+               close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
 
-       gtk_container_add (GTK_CONTAINER (event_box), event_box_hbox);
-       gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
-       gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+               gtk_container_add (GTK_CONTAINER (close_button), close_image);
 
-       /* React to theme changes and also used to setup the initial size
-        * correctly.
-        */
-       g_signal_connect (close_button,
-                         "style-set",
-                         G_CALLBACK (chat_window_close_button_style_set_cb),
-                         chat);
+               gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
 
-       g_signal_connect (close_button,
-                         "clicked",
-                         G_CALLBACK (chat_window_close_clicked_cb),
-                         chat);
+               g_signal_connect (close_button,
+                                 "clicked",
+                                 G_CALLBACK (chat_window_close_clicked_cb),
+                                 chat);
 
-       /* Set up tooltip */
-       chat_window_update_tooltip (window, chat);
+               /* React to theme changes and also setup the size correctly.  */
+               g_signal_connect (hbox,
+                                 "style-set",
+                                 G_CALLBACK (chat_tab_style_set_cb),
+                                 chat);
+       }
 
        gtk_widget_show_all (hbox);
 
@@ -306,18 +290,54 @@ chat_window_create_label (EmpathyChatWindow *window,
 }
 
 static void
-chat_window_update_title (EmpathyChatWindow *window,
-                         EmpathyChat       *chat)
+chat_window_update (EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
-       gint                   n_chats;
-       
-       priv = GET_PRIV (window);
-       
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               first_page;
+       gboolean               last_page;
+       gboolean               is_connected;
+       gint                   num_pages;
+       gint                   page_num;
+       gint                   i;
+       const gchar           *name;
+       guint                  n_chats;
+       GdkPixbuf             *icon;
+       EmpathyContact        *remote_contact;
+       gboolean               avatar_in_icon;
+       GtkWidget             *chat;
+       GtkWidget             *chat_close_button;
+       GtkWidget             *submenu;
+       GtkWidget             *menu;
+
+       /* Get information */
+       page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
+       num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
+       first_page = (page_num == 0);
+       last_page = (page_num == (num_pages - 1));
+       is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
+       name = empathy_chat_get_name (priv->current_chat);
        n_chats = g_list_length (priv->chats);
+
+       DEBUG ("Update window");
+
+       /* Update menu */
+       gtk_action_set_sensitive (priv->menu_tabs_next, !last_page);
+       gtk_action_set_sensitive (priv->menu_tabs_prev, !first_page);
+       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);
+
+       /* Update Contact menu */
+       menu = gtk_ui_manager_get_widget (priv->ui_manager,
+               "/chats_menubar/menu_contact");
+       submenu = empathy_chat_get_contact_menu (priv->current_chat);
+       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
+       gtk_widget_show (menu);
+
+       /* Update window title */
        if (n_chats == 1) {
-               gtk_window_set_title (GTK_WINDOW (priv->dialog),
-                                     empathy_chat_get_name (priv->current_chat));
+               gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
        } else {
                gchar *title;
 
@@ -326,236 +346,315 @@ chat_window_update_title (EmpathyChatWindow *window,
                g_free (title);
        }
 
+       /* Update window icon */
        if (priv->chats_new_msg) {
                gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
                                          EMPATHY_IMAGE_MESSAGE);
        } else {
-               gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
+               empathy_conf_get_bool (empathy_conf_get (),
+                                      EMPATHY_PREFS_CHAT_AVATAR_IN_ICON,
+                                      &avatar_in_icon);
+
+               if (n_chats == 1 && avatar_in_icon) {
+                       remote_contact = empathy_chat_get_remote_contact (priv->current_chat);
+                       icon = empathy_pixbuf_avatar_from_contact_scaled (remote_contact, 0, 0);
+                       gtk_window_set_icon (GTK_WINDOW (priv->dialog), icon);
+
+                       if (icon != NULL) {
+                               g_object_unref (icon);
+                       }
+               } else {
+                       gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
+               }
+       }
+
+       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),
+                               "chat-window-tab-close-button");
+               gtk_widget_hide (chat_close_button);
+       } else {
+               for (i=0; i<num_pages; i++) {
+                       chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
+                       chat_close_button = g_object_get_data (G_OBJECT (chat),
+                                       "chat-window-tab-close-button");
+                       gtk_widget_show (chat_close_button);
+               }
        }
 }
 
 static void
-chat_window_update_status (EmpathyChatWindow *window,
-                          EmpathyChat       *chat)
+append_markup_printf (GString    *string,
+                     const char *format,
+                     ...)
 {
-       EmpathyChatWindowPriv *priv;
-       GtkImage             *image;
-       const gchar          *icon_name = NULL;
+       gchar *tmp;
+       va_list args;
 
-       priv = GET_PRIV (window);
+       va_start (args, format);
 
-       if (g_list_find (priv->chats_new_msg, chat)) {
-               icon_name = EMPATHY_IMAGE_MESSAGE;
-       }
-       else if (g_list_find (priv->chats_composing, chat)) {
-               icon_name = EMPATHY_IMAGE_TYPING;
-       }
-       else {
-               icon_name = empathy_chat_get_status_icon_name (chat);
-       }
-       image = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
-       gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU);
+       tmp = g_markup_vprintf_escaped (format, args);
+       g_string_append (string, tmp);
+       g_free (tmp);
 
-       chat_window_update_title (window, chat);
-       chat_window_update_tooltip (window, chat);
+       va_end (args);
 }
 
 static void
-chat_window_update_menu (EmpathyChatWindow *window)
+chat_window_update_chat_tab (EmpathyChat *chat)
 {
+       EmpathyChatWindow     *window;
        EmpathyChatWindowPriv *priv;
-       gboolean              first_page;
-       gboolean              last_page;
-       gboolean              is_connected;
-       gint                  num_pages;
-       gint                  page_num;
+       EmpathyContact        *remote_contact;
+       const gchar           *name;
+       const gchar           *id;
+       EmpathyAccount        *account;
+       const gchar           *subject;
+       const gchar           *status = NULL;
+       GtkWidget             *widget;
+       GString               *tooltip;
+       gchar                 *markup;
+       const gchar           *icon_name;
 
+       window = chat_window_find_chat (chat);
+       if (!window) {
+               return;
+       }
        priv = GET_PRIV (window);
 
-       /* Notebook pages */
-       page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
-       num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
-       first_page = (page_num == 0);
-       last_page = (page_num == (num_pages - 1));
+       /* Get information */
+       name = empathy_chat_get_name (chat);
+       account = empathy_chat_get_account (chat);
+       subject = empathy_chat_get_subject (chat);
+       remote_contact = empathy_chat_get_remote_contact (chat);
 
-       gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
-       gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
-       gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
+       DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
+               name, empathy_account_get_unique_name (account), subject, remote_contact);
 
-       is_connected = empathy_chat_is_connected (priv->current_chat);
+       /* Update tab image */
+       if (g_list_find (priv->chats_new_msg, chat)) {
+               icon_name = EMPATHY_IMAGE_MESSAGE;
+       }
+       else if (g_list_find (priv->chats_composing, chat)) {
+               icon_name = EMPATHY_IMAGE_TYPING;
+       }
+       else if (remote_contact) {
+               icon_name = empathy_icon_name_for_contact (remote_contact);
+       } else {
+               icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
+       }
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
+       gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-image");
+       gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
 
-       if (empathy_chat_is_group_chat (priv->current_chat)) {
-               EmpathyGroupChat *group_chat;
-               EmpathyChatroom  *chatroom;
-               gboolean         show_contacts;
+       /* Update tab tooltip */
+       tooltip = g_string_new (NULL);
 
-               group_chat = EMPATHY_GROUP_CHAT (priv->current_chat);
+       if (remote_contact) {
+               id = empathy_contact_get_id (remote_contact);
+               status = empathy_contact_get_presence_message (remote_contact);
+       } else {
+               id = name;
+       }
 
-               /* Show / Hide widgets */
-               gtk_widget_show (priv->menu_room);
+       append_markup_printf (tooltip,
+                             "<b>%s</b><small> (%s)</small>",
+                             id,
+                             empathy_account_get_display_name (account));
 
-               gtk_widget_hide (priv->menu_conv_add_contact);
-               gtk_widget_hide (priv->menu_conv_info);
-               gtk_widget_hide (priv->menu_conv_separator);
+       if (!EMP_STR_EMPTY (status)) {
+               append_markup_printf (tooltip, "\n<i>%s</i>", status);
+       }
 
-               /* Can we add this room to our favourites and are we
-                * connected to the room?
-                */
-               chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
-                                                         empathy_chat_get_account (priv->current_chat),
-                                                         empathy_chat_get_id (priv->current_chat));
-
-               gtk_widget_set_sensitive (priv->menu_room_add, chatroom == NULL);
-               gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
-               gtk_widget_set_sensitive (priv->menu_room_join_new, is_connected);
-               gtk_widget_set_sensitive (priv->menu_room_invite, is_connected);
-
-               /* We need to block the signal here because all we are
-                * really trying to do is check or uncheck the menu
-                * item. If we don't do this we get funny behaviour
-                * with 2 or more group chat windows where showing
-                * contacts doesn't do anything.
-                */
-               show_contacts = empathy_group_chat_get_show_contacts (group_chat);
+       if (subject) {
+               append_markup_printf (tooltip, "\n<b>%s</b> %s",
+                                     _("Topic:"), subject);
+       }
 
-               g_signal_handlers_block_by_func (priv->menu_room_show_contacts,
-                                                chat_window_show_contacts_toggled_cb,
-                                                window);
+       if (g_list_find (priv->chats_composing, chat)) {
+               append_markup_printf (tooltip, "\n%s", _("Typing a message."));
+       }
 
-               g_object_set (priv->menu_room_show_contacts,
-                             "active", show_contacts,
-                             NULL);
+       markup = g_string_free (tooltip, FALSE);
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
+       gtk_widget_set_tooltip_markup (widget, markup);
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-tooltip-widget");
+       gtk_widget_set_tooltip_markup (widget, markup);
+       g_free (markup);
+
+       /* Update tab and menu label */
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+       gtk_label_set_text (GTK_LABEL (widget), name);
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-menu-label");
+       gtk_label_set_text (GTK_LABEL (widget), name);
+
+       /* Update the window if it's the current chat */
+       if (priv->current_chat == chat) {
+               chat_window_update (window);
+       }
+}
 
-               g_signal_handlers_unblock_by_func (priv->menu_room_show_contacts,
-                                                  chat_window_show_contacts_toggled_cb,
-                                                  window);
-       } else {
-               EmpathyPrivateChat *chat;
-               EmpathyContact     *contact;
-               McPresence          presence;
-
-               chat = EMPATHY_PRIVATE_CHAT (priv->current_chat);
-
-               /* Show / Hide widgets */
-               gtk_widget_hide (priv->menu_room);
-
-               /* Unset presence means this contact refuses to send us his
-                * presence. By adding the contact we ask the contact to accept
-                * to send his presence. */
-               contact = empathy_private_chat_get_contact (chat);
-               presence = empathy_contact_get_presence (contact);
-               if (presence == MC_PRESENCE_UNSET) {
-                       gtk_widget_show (priv->menu_conv_add_contact);
-               } else {
-                       gtk_widget_hide (priv->menu_conv_add_contact);
+static void
+chat_window_chat_notify_cb (EmpathyChat *chat)
+{
+       EmpathyContact *old_remote_contact;
+       EmpathyContact *remote_contact = NULL;
+
+       old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
+       remote_contact = empathy_chat_get_remote_contact (chat);
+
+       if (old_remote_contact != remote_contact) {
+               /* The remote-contact associated with the chat changed, we need
+                * to keep track of any change of that contact and update the
+                * window each time. */
+               if (remote_contact) {
+                       g_signal_connect_swapped (remote_contact, "notify",
+                                                 G_CALLBACK (chat_window_update_chat_tab),
+                                                 chat);
+               }
+               if (old_remote_contact) {
+                       g_signal_handlers_disconnect_by_func (old_remote_contact,
+                                                             chat_window_update_chat_tab,
+                                                             chat);
                }
 
-               gtk_widget_show (priv->menu_conv_separator);
-               gtk_widget_show (priv->menu_conv_info);
-
-               /* Are we connected? */
-               gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
-               gtk_widget_set_sensitive (priv->menu_conv_add_contact, is_connected);
-               gtk_widget_set_sensitive (priv->menu_conv_info, is_connected);
+               g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
+                                  remote_contact);
        }
+
+       chat_window_update_chat_tab (chat);
 }
 
 static void
-chat_window_insert_smiley_activate_cb (GtkWidget         *menuitem,
-                                      EmpathyChatWindow *window)
+chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
+                                      EmpathySmiley        *smiley,
+                                      gpointer              window)
 {
-       EmpathyChatWindowPriv *priv;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
        EmpathyChat           *chat;
-       GtkTextBuffer        *buffer;
-       GtkTextIter           iter;
-       const gchar          *smiley;
-
-       priv = GET_PRIV (window);
+       GtkTextBuffer         *buffer;
+       GtkTextIter            iter;
 
        chat = priv->current_chat;
 
-       smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
-
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
        gtk_text_buffer_get_end_iter (buffer, &iter);
-       gtk_text_buffer_insert (buffer, &iter,
-                               smiley, -1);
+       gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
 }
 
 static void
-chat_window_clear_activate_cb (GtkWidget        *menuitem,
-                              EmpathyChatWindow *window)
+chat_window_conv_activate_cb (GtkAction         *action,
+                             EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
-
-       priv = GET_PRIV (window);
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               is_room;
+       gboolean               active;
+       EmpathyContact        *remote_contact = NULL;
+
+       /* Favorite room menu */
+       is_room = empathy_chat_is_room (priv->current_chat);
+       if (is_room) {
+               const gchar *room;
+               EmpathyAccount   *account;
+               gboolean     found = FALSE;
+               EmpathyChatroom *chatroom;
+
+               room = empathy_chat_get_id (priv->current_chat);
+               account = empathy_chat_get_account (priv->current_chat);
+               chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
+                                                      account, room);
+               if (chatroom != NULL)
+                       found = empathy_chatroom_is_favorite (chatroom);
 
-       empathy_chat_clear (priv->current_chat);
+               DEBUG ("This room %s favorite", found ? "is" : "is not");
+               gtk_toggle_action_set_active (
+                       GTK_TOGGLE_ACTION (priv->menu_conv_favorite), found);
+       }
+       gtk_action_set_visible (priv->menu_conv_favorite, is_room);
+
+       /* Show contacts menu */
+       g_object_get (priv->current_chat,
+                     "remote-contact", &remote_contact,
+                     "show-contacts", &active,
+                     NULL);
+       if (remote_contact == NULL) {
+               gtk_toggle_action_set_active (
+                       GTK_TOGGLE_ACTION (priv->menu_conv_toggle_contacts),
+                                          active);
+       }
+       gtk_action_set_visible (priv->menu_conv_toggle_contacts,
+                               (remote_contact == NULL));
+       if (remote_contact != NULL) {
+               g_object_unref (remote_contact);
+       }
 }
 
 static void
-chat_window_add_contact_activate_cb (GtkWidget        *menuitem,
-                                    EmpathyChatWindow *window)
+chat_window_clear_activate_cb (GtkAction         *action,
+                              EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
-       //EmpathyContact        *contact;
-
-       priv = GET_PRIV (window);
-
-       //contact = empathy_chat_get_contact (priv->current_chat);
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
 
-       // FIXME: empathy_add_contact_dialog_show (NULL, contact);
+       empathy_chat_clear (priv->current_chat);
 }
 
 static void
-chat_window_call_activate_cb (GtkWidget         *menuitem,
-                             EmpathyChatWindow *window)
+chat_window_favorite_toggled_cb (GtkToggleAction   *toggle_action,
+                                EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               active;
+       EmpathyAccount        *account;
+       const gchar           *room;
+       EmpathyChatroom       *chatroom;
 
-       priv = GET_PRIV (window);
+       active = gtk_toggle_action_get_active (toggle_action);
+       account = empathy_chat_get_account (priv->current_chat);
+       room = empathy_chat_get_id (priv->current_chat);
 
-       if (!empathy_chat_is_group_chat (priv->current_chat)) {
-               EmpathyPrivateChat *chat;
-               EmpathyContact     *contact;
+       chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
+                                                 account, room);
 
-               chat = EMPATHY_PRIVATE_CHAT (priv->current_chat);
-               contact = empathy_private_chat_get_contact (chat);
+       if (chatroom == NULL) {
+               const gchar *name;
 
-               empathy_call_with_contact (contact);
-       }
+               name = empathy_chat_get_name (priv->current_chat);
+               chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
+               empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
+               g_object_unref (chatroom);
+  }
+
+       empathy_chatroom_set_favorite (chatroom, active);
 }
 
 static void
-chat_window_log_activate_cb (GtkWidget        *menuitem,
-                            EmpathyChatWindow *window)
+chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
+                                EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               active;
 
-       priv = GET_PRIV (window);
+       active = gtk_toggle_action_get_active (toggle_action);
 
-       empathy_log_window_show (empathy_chat_get_account (priv->current_chat),
-                                empathy_chat_get_id (priv->current_chat),
-                                empathy_chat_is_group_chat (priv->current_chat),
-                                GTK_WINDOW (priv->dialog));
+       empathy_chat_set_show_contacts (priv->current_chat, active);
 }
 
-static void
-chat_window_info_activate_cb (GtkWidget        *menuitem,
-                             EmpathyChatWindow *window)
+static const gchar *
+chat_get_window_id_for_geometry (EmpathyChat *chat)
 {
-       EmpathyChatWindowPriv *priv;
-       EmpathyContact        *contact;
+       const gchar *res = NULL;
+       gboolean     separate_windows;
 
-       priv = GET_PRIV (window);
+       empathy_conf_get_bool (empathy_conf_get (),
+                              EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
+                              &separate_windows);
 
-       contact = empathy_private_chat_get_contact (EMPATHY_PRIVATE_CHAT (priv->current_chat));
+       if (separate_windows) {
+               res = empathy_chat_get_id (chat);
+       }
 
-       empathy_contact_information_dialog_show (contact,
-                                                GTK_WINDOW (priv->dialog),
-                                                FALSE, FALSE);
+       return res ? res : "chat-window";
 }
 
 static gboolean
@@ -569,7 +668,8 @@ chat_window_save_geometry_timeout_cb (EmpathyChatWindow *window)
        gtk_window_get_size (GTK_WINDOW (priv->dialog), &w, &h);
        gtk_window_get_position (GTK_WINDOW (priv->dialog), &x, &y);
 
-       empathy_chat_save_geometry (priv->current_chat, x, y, w, h);
+       empathy_geometry_save (chat_get_window_id_for_geometry (priv->current_chat),
+                              x, y, w, h);
 
        priv->save_geometry_id = 0;
 
@@ -598,58 +698,7 @@ chat_window_configure_event_cb (GtkWidget         *widget,
 }
 
 static void
-chat_window_conv_activate_cb (GtkWidget         *menuitem,
-                             EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv;
-       EmpathyLogManager     *manager;
-       gboolean              log_exists = FALSE;
-       gboolean              can_voip = FALSE;
-
-       priv = GET_PRIV (window);
-
-       manager = empathy_log_manager_new ();
-       log_exists = empathy_log_manager_exists (manager,
-                                                empathy_chat_get_account (priv->current_chat),
-                                                empathy_chat_get_id (priv->current_chat),
-                                                empathy_chat_is_group_chat (priv->current_chat));
-       g_object_unref (manager);
-
-       if (!empathy_chat_is_group_chat (priv->current_chat)) {
-               EmpathyPrivateChat *chat;
-               EmpathyContact     *contact;
-
-               chat = EMPATHY_PRIVATE_CHAT (priv->current_chat);
-               contact = empathy_private_chat_get_contact (chat);
-               can_voip = empathy_contact_can_voip (contact);
-       }
-
-       gtk_widget_set_sensitive (priv->menu_conv_log, log_exists);
-#ifdef HAVE_VOIP
-       gtk_widget_set_sensitive (priv->menu_conv_call, can_voip);
-#else 
-       g_object_set (priv->menu_conv_call, "visible", FALSE, NULL);
-       g_object_set (priv->menu_conv_call_separator, "visible", FALSE, NULL);
-#endif
-}
-
-static void
-chat_window_show_contacts_toggled_cb (GtkWidget        *menuitem,
-                                     EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv;
-       gboolean              show;
-
-       priv = GET_PRIV (window);
-
-       g_return_if_fail (priv->current_chat != NULL);
-
-       show = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (priv->menu_room_show_contacts));
-       empathy_group_chat_set_show_contacts (EMPATHY_GROUP_CHAT (priv->current_chat), show);
-}
-
-static void
-chat_window_close_activate_cb (GtkWidget        *menuitem,
+chat_window_close_activate_cb (GtkAction         *action,
                               EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -662,81 +711,7 @@ chat_window_close_activate_cb (GtkWidget        *menuitem,
 }
 
 static void
-chat_window_room_set_topic_activate_cb (GtkWidget        *menuitem,
-                                       EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv = GET_PRIV (window);
-       
-       if (empathy_chat_is_group_chat (priv->current_chat)) {
-               empathy_group_chat_set_topic (EMPATHY_GROUP_CHAT (priv->current_chat));
-       }
-}
-
-static void
-chat_window_room_join_new_activate_cb (GtkWidget        *menuitem,
-                                      EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv;
-
-       priv = GET_PRIV (window);
-
-       empathy_new_chatroom_dialog_show (GTK_WINDOW (priv->dialog));
-}
-
-static void
-chat_window_room_invite_activate_cb (GtkWidget        *menuitem,
-                                    EmpathyChatWindow *window)
-{
-/* FIXME:
-       EmpathyChatWindowPriv *priv;
-       EmpathyContact        *own_contact;
-       EmpathyChatroomId      id = 0;
-
-       priv = GET_PRIV (window);
-       own_contact = empathy_chat_get_own_contact (priv->current_chat);
-
-       if (empathy_chat_is_group_chat (priv->current_chat)) {
-               EmpathyGroupChat *group_chat;
-
-               group_chat = EMPATHY_GROUP_CHAT (priv->current_chat);
-               id = empathy_group_chat_get_chatroom_id (group_chat);
-       }
-
-       empathy_chat_invite_dialog_show (own_contact, id);
-*/
-}
-
-static void
-chat_window_room_add_activate_cb (GtkWidget        *menuitem,
-                                 EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv  *priv;
-       EmpathyChatroomManager *manager;
-       EmpathyChatroom        *chatroom;
-
-       priv = GET_PRIV (window);
-
-       g_return_if_fail (priv->current_chat != NULL);
-
-       if (!empathy_chat_is_group_chat (priv->current_chat)) {
-               return;
-       }
-
-       chatroom = empathy_chatroom_new_full (empathy_chat_get_account (priv->current_chat),
-                                             empathy_chat_get_id (priv->current_chat),
-                                             empathy_chat_get_name (priv->current_chat),
-                                             FALSE);
-
-       manager = empathy_chatroom_manager_new ();
-       empathy_chatroom_manager_add (manager, chatroom);
-       chat_window_update_menu (window);
-
-       g_object_unref (chatroom);
-       g_object_unref (manager);
-}
-
-static void
-chat_window_edit_activate_cb (GtkWidget        *menuitem,
+chat_window_edit_activate_cb (GtkAction         *action,
                              EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -748,34 +723,33 @@ chat_window_edit_activate_cb (GtkWidget        *menuitem,
 
        g_return_if_fail (priv->current_chat != NULL);
 
-       if (!empathy_chat_is_connected (priv->current_chat)) {
-               gtk_widget_set_sensitive (priv->menu_edit_copy, FALSE);
-               gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
-               gtk_widget_set_sensitive (priv->menu_edit_paste, FALSE);
+       if (!empathy_chat_get_tp_chat (priv->current_chat)) {
+               gtk_action_set_sensitive (priv->menu_edit_copy, FALSE);
+               gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
+               gtk_action_set_sensitive (priv->menu_edit_paste, FALSE);
                return;
        }
 
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_chat->input_text_view));
-       if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
-               gtk_widget_set_sensitive (priv->menu_edit_copy, TRUE);
-               gtk_widget_set_sensitive (priv->menu_edit_cut, TRUE);
+       if (gtk_text_buffer_get_has_selection (buffer)) {
+               gtk_action_set_sensitive (priv->menu_edit_copy, TRUE);
+               gtk_action_set_sensitive (priv->menu_edit_cut, TRUE);
        } else {
                gboolean selection;
 
-               selection = empathy_chat_view_get_selection_bounds (priv->current_chat->view, 
-                                                                  NULL, NULL);
+               selection = empathy_chat_view_get_has_selection (priv->current_chat->view);
 
-               gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
-               gtk_widget_set_sensitive (priv->menu_edit_copy, selection);
+               gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
+               gtk_action_set_sensitive (priv->menu_edit_copy, selection);
        }
 
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
        text_available = gtk_clipboard_wait_is_text_available (clipboard);
-       gtk_widget_set_sensitive (priv->menu_edit_paste, text_available);
+       gtk_action_set_sensitive (priv->menu_edit_paste, text_available);
 }
 
 static void
-chat_window_cut_activate_cb (GtkWidget        *menuitem,
+chat_window_cut_activate_cb (GtkAction         *action,
                             EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -788,7 +762,7 @@ chat_window_cut_activate_cb (GtkWidget        *menuitem,
 }
 
 static void
-chat_window_copy_activate_cb (GtkWidget        *menuitem,
+chat_window_copy_activate_cb (GtkAction         *action,
                              EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -801,7 +775,7 @@ chat_window_copy_activate_cb (GtkWidget        *menuitem,
 }
 
 static void
-chat_window_paste_activate_cb (GtkWidget        *menuitem,
+chat_window_paste_activate_cb (GtkAction         *action,
                               EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -814,7 +788,7 @@ chat_window_paste_activate_cb (GtkWidget        *menuitem,
 }
 
 static void
-chat_window_tabs_left_activate_cb (GtkWidget        *menuitem,
+chat_window_tabs_left_activate_cb (GtkAction         *action,
                                   EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -830,15 +804,12 @@ chat_window_tabs_left_activate_cb (GtkWidget        *menuitem,
        }
 
        gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
-                                   empathy_chat_get_widget (chat),
+                                   GTK_WIDGET (chat),
                                    index - 1);
-
-       chat_window_update_menu (window);
-       chat_window_update_status (window, chat);
 }
 
 static void
-chat_window_tabs_right_activate_cb (GtkWidget        *menuitem,
+chat_window_tabs_right_activate_cb (GtkAction         *action,
                                    EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -851,15 +822,12 @@ chat_window_tabs_right_activate_cb (GtkWidget        *menuitem,
        index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
 
        gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
-                                   empathy_chat_get_widget (chat),
+                                   GTK_WIDGET (chat),
                                    index + 1);
-
-       chat_window_update_menu (window);
-       chat_window_update_status (window, chat);
 }
 
 static void
-chat_window_detach_activate_cb (GtkWidget        *menuitem,
+chat_window_detach_activate_cb (GtkAction         *action,
                                EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
@@ -878,15 +846,17 @@ chat_window_detach_activate_cb (GtkWidget        *menuitem,
 }
 
 static void
-chat_window_help_contents_cb (GtkWidget         *menuitem,
-                             EmpathyChatWindow *window)
+chat_window_help_contents_activate_cb (GtkAction         *action,
+                                      EmpathyChatWindow *window)
 {
-       //empathy_help_show ();
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+
+       empathy_url_show (priv->dialog, "ghelp:empathy?chat");
 }
 
 static void
-chat_window_help_about_cb (GtkWidget         *menuitem,
-                          EmpathyChatWindow *window)
+chat_window_help_about_activate_cb (GtkAction         *action,
+                                   EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
 
@@ -898,90 +868,208 @@ chat_window_delete_event_cb (GtkWidget        *dialog,
                             GdkEvent         *event,
                             EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
-       GList                *list;
-       GList                *l;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
 
-       priv = GET_PRIV (window);
+       DEBUG ("Delete event received");
 
-       empathy_debug (DEBUG_DOMAIN, "Delete event received");
+       g_object_ref (window);
+       while (priv->chats) {
+               empathy_chat_window_remove_chat (window, priv->chats->data);
+       }
+       g_object_unref (window);
 
-       list = g_list_copy (priv->chats);
+       return TRUE;
+}
 
-       for (l = list; l; l = l->next) {
-               empathy_chat_window_remove_chat (window, l->data);
-       }
+static void
+chat_window_composing_cb (EmpathyChat       *chat,
+                         gboolean          is_composing,
+                         EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv;
+
+       priv = GET_PRIV (window);
 
-       g_list_free (list);
+       if (is_composing && !g_list_find (priv->chats_composing, chat)) {
+               priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
+       } else {
+               priv->chats_composing = g_list_remove (priv->chats_composing, chat);
+       }
 
-       return TRUE;
+       chat_window_update_chat_tab (chat);
 }
 
 static void
-chat_window_status_changed_cb (EmpathyChat       *chat,
-                              EmpathyChatWindow *window)
+chat_window_set_urgency_hint (EmpathyChatWindow *window,
+                             gboolean          urgent)
 {
-       chat_window_update_menu (window);
-       chat_window_update_status (window, chat);
+       EmpathyChatWindowPriv *priv;
+
+       priv = GET_PRIV (window);
+
+       DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
+       gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
 }
 
+typedef struct {
+       EmpathyChatWindow *window;
+       EmpathyChat *chat;
+} NotificationData;
+
 static void
-chat_window_name_changed_cb (EmpathyChat       *chat,
-                            const gchar      *name,
-                            EmpathyChatWindow *window)
+chat_window_notification_closed_cb (NotifyNotification *notify,
+                                   NotificationData *cb_data)
 {
-       GtkLabel *label;
+       EmpathyNotificationClosedReason reason = 0;
+       EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
 
-       label = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+#ifdef notify_notification_get_closed_reason
+       reason = notify_notification_get_closed_reason (notify);
+#endif
+       if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
+               empathy_chat_window_present_chat (cb_data->chat);
+       }
 
-       gtk_label_set_text (label, name);
+       g_object_unref (notify);
+       priv->notification = NULL;
+       g_object_unref (cb_data->chat);
+       g_slice_free (NotificationData, cb_data);
 }
 
 static void
-chat_window_composing_cb (EmpathyChat       *chat,
-                         gboolean          is_composing,
-                         EmpathyChatWindow *window)
+chat_window_show_or_update_notification (EmpathyChatWindow *window,
+                                        EmpathyMessage *message,
+                                        EmpathyChat *chat)
 {
-       EmpathyChatWindowPriv *priv;
+       EmpathyContact *sender;
+       const gchar *header;
+       char *escaped;
+       const char *body;
+       GdkPixbuf *pixbuf;
+       NotificationData *cb_data;
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean res;
 
-       priv = GET_PRIV (window);
+       if (!empathy_notification_is_enabled ()) {
+               return;
+       } else {
+               empathy_conf_get_bool (empathy_conf_get (),
+                                      EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
+               if (!res) {
+                       return;
+               }
+       }
 
-       if (is_composing && !g_list_find (priv->chats_composing, chat)) {
-               priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
+       cb_data = g_slice_new0 (NotificationData);
+       cb_data->chat = g_object_ref (chat);
+       cb_data->window = window;
+
+       sender = empathy_message_get_sender (message);
+       header = empathy_contact_get_name (sender);
+       body = empathy_message_get_body (message);
+       escaped = g_markup_escape_text (body, -1);
+
+       pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
+
+       if (priv->notification != NULL) {
+               notify_notification_update (priv->notification,
+                                           header, escaped, NULL);
+               /* if icon doesn't exist libnotify will crash */
+               if (pixbuf != NULL)
+                       notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
        } else {
-               priv->chats_composing = g_list_remove (priv->chats_composing, chat);
+               priv->notification = notify_notification_new (header, escaped, NULL, NULL);
+               notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
+               /* if icon doesn't exist libnotify will crash */
+               if (pixbuf != NULL)
+                       notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+
+               g_signal_connect (priv->notification, "closed",
+                                 G_CALLBACK (chat_window_notification_closed_cb), cb_data);
        }
 
-       chat_window_update_status (window, chat);
+       notify_notification_show (priv->notification, NULL);
+
+       g_object_unref (pixbuf);
+       g_free (escaped);
+}
+
+static void
+chat_window_set_highlight_room_tab_label (EmpathyChat *chat)
+{
+       gchar *markup;
+       GtkWidget *widget;
+
+       if (empathy_chat_is_room (chat) == FALSE)
+               return;
+
+       markup = g_markup_printf_escaped ("<span color=\"%s\">%s</span>",
+                       "red",
+                       empathy_chat_get_name (chat));
+
+       widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+       gtk_label_set_markup (GTK_LABEL (widget), markup);
+       g_free (markup);
 }
 
 static void
 chat_window_new_message_cb (EmpathyChat       *chat,
                            EmpathyMessage    *message,
-s                          EmpathyChatWindow *window)
+                           EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv;
        gboolean              has_focus;
        gboolean              needs_urgency;
+       EmpathyContact        *sender;
 
        priv = GET_PRIV (window);
 
        has_focus = empathy_chat_window_has_focus (window);
-       
-       if (has_focus && priv->current_chat == chat) {
-               return;
+
+       /* - if we're the sender, we play the sound if it's specified in the
+        *   preferences and we're not away.
+        * - if we receive a message, we play the sound if it's specified in the
+        *   preferences and the window does not have focus on the chat receiving
+        *   the message.
+        */
+
+       sender = empathy_message_get_sender (message);
+
+       if (empathy_contact_is_user (sender)) {
+               empathy_sound_play (GTK_WIDGET (priv->dialog),
+                                   EMPATHY_SOUND_MESSAGE_OUTGOING);
        }
-       
-       needs_urgency = (empathy_chat_is_group_chat (chat) &&
-                        empathy_message_should_highlight (message));
 
-       if (needs_urgency && !has_focus) {
-               chat_window_set_urgency_hint (window, TRUE);
+       if (has_focus && priv->current_chat == chat) {
+               return;
        }
 
        if (!g_list_find (priv->chats_new_msg, chat)) {
                priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
-               chat_window_update_status (window, chat);
+               chat_window_update_chat_tab (chat);
+       }
+
+       /* If empathy_chat_is_room () returns TRUE, that means it's a named MUC.
+        * If empathy_chat_get_remote_contact () returns NULL, that means it's
+        * an unamed MUC (msn-like).
+        * In case of a MUC, we set urgency only if the message contains our
+        * alias. */
+       if (empathy_chat_is_room (chat) ||
+           empathy_chat_get_remote_contact (chat) == NULL) {
+               needs_urgency = empathy_message_should_highlight (message);
+       } else {
+               needs_urgency = TRUE;
+       }
+
+       if (needs_urgency) {
+               if (!has_focus) {
+                       chat_window_set_urgency_hint (window, TRUE);
+                       chat_window_set_highlight_room_tab_label (chat);
+               }
+
+               empathy_sound_play (GTK_WIDGET (priv->dialog),
+                   EMPATHY_SOUND_MESSAGE_INCOMING);
+               chat_window_show_or_update_notification (window, message, chat);
        }
 }
 
@@ -996,13 +1084,13 @@ chat_window_detach_hook (GtkNotebook *source,
        EmpathyChatWindow     *window, *new_window;
        EmpathyChat           *chat;
 
-       chat = g_object_get_data (G_OBJECT (page), "chat");
+       chat = EMPATHY_CHAT (page);
        window = chat_window_find_chat (chat);
 
        new_window = empathy_chat_window_new ();
        priv = GET_PRIV (new_window);
 
-       empathy_debug (DEBUG_DOMAIN, "Detach hook called");
+       DEBUG ("Detach hook called");
 
        empathy_chat_window_move_chat (window, new_window, chat);
 
@@ -1022,12 +1110,12 @@ chat_window_page_switched_cb (GtkNotebook      *notebook,
        EmpathyChat           *chat;
        GtkWidget            *child;
 
-       empathy_debug (DEBUG_DOMAIN, "Page switched");
+       DEBUG ("Page switched");
 
        priv = GET_PRIV (window);
 
        child = gtk_notebook_get_nth_page (notebook, page_num);
-       chat = g_object_get_data (G_OBJECT (child), "chat");
+       chat = EMPATHY_CHAT (child);
 
        if (priv->page_added) {
                priv->page_added = FALSE;
@@ -1040,19 +1128,7 @@ chat_window_page_switched_cb (GtkNotebook      *notebook,
        priv->current_chat = chat;
        priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
 
-       chat_window_update_menu (window);
-       chat_window_update_status (window, chat);
-}
-
-static void
-chat_window_page_reordered_cb (GtkNotebook      *notebook,
-                              GtkWidget        *widget,
-                              guint             page_num,
-                              EmpathyChatWindow *window)
-{
-       empathy_debug (DEBUG_DOMAIN, "Page reordered");
-       
-       chat_window_update_menu (window);
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -1071,23 +1147,17 @@ chat_window_page_added_cb (GtkNotebook      *notebook,
         * it, so we return here and in "page-added".
         */
        if (priv->dnd_same_window) {
-               empathy_debug (DEBUG_DOMAIN, "Page added (back to the same window)");
+               DEBUG ("Page added (back to the same window)");
                priv->dnd_same_window = FALSE;
                return;
        }
 
-       empathy_debug (DEBUG_DOMAIN, "Page added");
+       DEBUG ("Page added");
 
        /* Get chat object */
-       chat = g_object_get_data (G_OBJECT (child), "chat");
+       chat = EMPATHY_CHAT (child);
 
        /* Connect chat signals for this window */
-       g_signal_connect (chat, "status-changed",
-                         G_CALLBACK (chat_window_status_changed_cb),
-                         window);
-       g_signal_connect (chat, "name-changed",
-                         G_CALLBACK (chat_window_name_changed_cb),
-                         window);
        g_signal_connect (chat, "composing",
                          G_CALLBACK (chat_window_composing_cb),
                          window);
@@ -1102,6 +1172,8 @@ chat_window_page_added_cb (GtkNotebook      *notebook,
 
        /* Get list of chats up to date */
        priv->chats = g_list_append (priv->chats, chat);
+
+       chat_window_update_chat_tab (chat);
 }
 
 static void
@@ -1120,22 +1192,16 @@ chat_window_page_removed_cb (GtkNotebook      *notebook,
         * it, so we return here and in "page-added".
         */
        if (priv->dnd_same_window) {
-               empathy_debug (DEBUG_DOMAIN, "Page removed (and will be readded to same window)");
+               DEBUG ("Page removed (and will be readded to same window)");
                return;
        }
 
-       empathy_debug (DEBUG_DOMAIN, "Page removed");
+       DEBUG ("Page removed");
 
        /* Get chat object */
-       chat = g_object_get_data (G_OBJECT (child), "chat");
+       chat = EMPATHY_CHAT (child);
 
        /* Disconnect all signal handlers for this chat and this window */
-       g_signal_handlers_disconnect_by_func (chat,
-                                             G_CALLBACK (chat_window_status_changed_cb),
-                                             window);
-       g_signal_handlers_disconnect_by_func (chat,
-                                             G_CALLBACK (chat_window_name_changed_cb),
-                                             window);
        g_signal_handlers_disconnect_by_func (chat,
                                              G_CALLBACK (chat_window_composing_cb),
                                              window);
@@ -1151,8 +1217,7 @@ chat_window_page_removed_cb (GtkNotebook      *notebook,
        if (priv->chats == NULL) {
                g_object_unref (window);
        } else {
-               chat_window_update_menu (window);
-               chat_window_update_title (window, NULL);
+               chat_window_update (window);
        }
 }
 
@@ -1163,16 +1228,16 @@ chat_window_focus_in_event_cb (GtkWidget        *widget,
 {
        EmpathyChatWindowPriv *priv;
 
-       empathy_debug (DEBUG_DOMAIN, "Focus in event, updating title");
+       DEBUG ("Focus in event, updating title");
 
        priv = GET_PRIV (window);
 
        priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
 
        chat_window_set_urgency_hint (window, FALSE);
-       
+
        /* Update the title, since we now mark all unread messages as read. */
-       chat_window_update_status (window, priv->current_chat);
+       chat_window_update_chat_tab (priv->current_chat);
 
        return FALSE;
 }
@@ -1190,107 +1255,100 @@ chat_window_drag_data_received (GtkWidget        *widget,
        if (info == DND_DRAG_TYPE_CONTACT_ID) {
                EmpathyChat           *chat;
                EmpathyChatWindow     *old_window;
-               McAccount             *account;
-               const gchar           *id = NULL;
+               EmpathyAccount        *account;
+               EmpathyAccountManager *account_manager;
+               const gchar           *id;
                gchar                **strv;
+               const gchar           *account_id;
+               const gchar           *contact_id;
 
-               if (selection) {
-                       id = (const gchar*) selection->data;
-               }
+               id = (const gchar*) gtk_selection_data_get_data (selection);
+               account_manager = empathy_account_manager_dup_singleton ();
+
+               DEBUG ("DND contact from roster with id:'%s'", id);
 
-               empathy_debug (DEBUG_DOMAIN, "DND contact from roster with id:'%s'", id);
-               
                strv = g_strsplit (id, "/", 2);
-               account = mc_account_lookup (strv[0]);
-               chat = empathy_chat_window_find_chat (account, strv[1]);
+               account_id = strv[0];
+               contact_id = strv[1];
+               account = empathy_account_manager_lookup (account_manager, account_id);
+               chat = empathy_chat_window_find_chat (account, contact_id);
 
                if (!chat) {
-                       empathy_chat_with_contact_id (account, strv[2]);
+                       TpConnection *connection;
+
+                       connection = empathy_account_get_connection (account);
+
+                       if (connection) {
+                               empathy_dispatcher_chat_with_contact_id (
+                                       connection, contact_id, NULL, NULL);
+                       }
+
                        g_object_unref (account);
                        g_strfreev (strv);
                        return;
                }
                g_object_unref (account);
+               g_object_unref (account_manager);
                g_strfreev (strv);
 
-               old_window = chat_window_find_chat (chat);              
+               old_window = chat_window_find_chat (chat);
                if (old_window) {
                        if (old_window == window) {
                                gtk_drag_finish (context, TRUE, FALSE, time);
                                return;
                        }
-                       
+
                        empathy_chat_window_move_chat (old_window, window, chat);
                } else {
                        empathy_chat_window_add_chat (window, chat);
                }
-               
+
                /* Added to take care of any outstanding chat events */
                empathy_chat_window_present_chat (chat);
 
                /* 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().
+                * anyway with add_chat () and remove_chat ().
                 */
                gtk_drag_finish (context, TRUE, FALSE, time);
        }
        else if (info == DND_DRAG_TYPE_TAB) {
-               EmpathyChat        *chat = NULL;
-               EmpathyChatWindow  *old_window;
-               GtkWidget        **child = NULL;
+               EmpathyChat        **chat;
+               EmpathyChatWindow   *old_window = NULL;
 
-               empathy_debug (DEBUG_DOMAIN, "DND tab");
+               DEBUG ("DND tab");
 
-               if (selection) {
-                       child = (void*) selection->data;
-               }
+               chat = (void *) gtk_selection_data_get_data (selection);
+               old_window = chat_window_find_chat (*chat);
 
-               if (child) {
-                       chat = g_object_get_data (G_OBJECT (*child), "chat");
-               }
-
-               old_window = chat_window_find_chat (chat);
                if (old_window) {
                        EmpathyChatWindowPriv *priv;
 
                        priv = GET_PRIV (window);
 
                        if (old_window == window) {
-                               empathy_debug (DEBUG_DOMAIN, "DND tab (within same 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;
                }
 
                /* 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().
+                * anyway with add_chat () and remove_chat ().
                 */
                gtk_drag_finish (context, TRUE, FALSE, time);
        } else {
-               empathy_debug (DEBUG_DOMAIN, "DND from unknown source");
+               DEBUG ("DND from unknown source");
                gtk_drag_finish (context, FALSE, FALSE, time);
        }
 }
 
-static void
-chat_window_set_urgency_hint (EmpathyChatWindow *window,
-                             gboolean          urgent)
-{
-       EmpathyChatWindowPriv *priv;
-
-       priv = GET_PRIV (window);
-
-       empathy_debug (DEBUG_DOMAIN, "Turning %s urgency hint",
-                      urgent ? "on" : "off");
-       gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
-}
-
 static void
 chat_window_finalize (GObject *object)
 {
@@ -1300,20 +1358,23 @@ chat_window_finalize (GObject *object)
        window = EMPATHY_CHAT_WINDOW (object);
        priv = GET_PRIV (window);
 
-       empathy_debug (DEBUG_DOMAIN, "Finalized: %p", object);
+       DEBUG ("Finalized: %p", object);
 
+       g_object_unref (priv->ui_manager);
+       g_object_unref (priv->chatroom_manager);
        if (priv->save_geometry_id != 0) {
                g_source_remove (priv->save_geometry_id);
        }
 
+       if (priv->notification != NULL) {
+               notify_notification_close (priv->notification, NULL);
+               g_object_unref (priv->notification);
+               priv->notification = NULL;
+       }
+
        chat_windows = g_list_remove (chat_windows, window);
        gtk_widget_destroy (priv->dialog);
 
-       g_signal_handlers_disconnect_by_func (priv->chatroom_manager,
-                                             chat_window_update_menu,
-                                             window);
-       g_object_unref (priv->chatroom_manager);
-
        G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
 }
 
@@ -1322,7 +1383,7 @@ empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       object_class->finalize = empathy_chat_window_finalize;
+       object_class->finalize = chat_window_finalize;
 
        g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
 
@@ -1342,41 +1403,27 @@ empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
 static void
 empathy_chat_window_init (EmpathyChatWindow *window)
 {
-       EmpathyChatWindowPriv *priv;
-       GladeXML             *glade;
-       GtkAccelGroup        *accel_group;
-       GtkWidget            *image;
-       GClosure             *closure;
-       GtkWidget            *menu_conv;
-       GtkWidget            *menu;
-       gint                  i;
-       GtkWidget            *chat_vbox;
-       gchar                *filename;
-
-       priv = GET_PRIV (window);
-
-       filename = empathy_file_lookup ("empathy-chat-window.glade", "src");
-       glade = empathy_glade_get_file (filename,
-                                      "chat_window",
-                                      NULL,
+       GtkBuilder            *gui;
+       GtkAccelGroup         *accel_group;
+       GClosure              *closure;
+       GtkWidget             *menu;
+       GtkWidget             *submenu;
+       gint                   i;
+       GtkWidget             *chat_vbox;
+       gchar                 *filename;
+       EmpathySmileyManager  *smiley_manager;
+       EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
+               EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
+
+       window->priv = priv;
+       filename = empathy_file_lookup ("empathy-chat-window.ui", "src");
+       gui = empathy_builder_get_file (filename,
                                       "chat_window", &priv->dialog,
                                       "chat_vbox", &chat_vbox,
-                                      "menu_conv", &menu_conv,
-                                      "menu_conv_clear", &priv->menu_conv_clear,
+                                      "ui_manager", &priv->ui_manager,
                                       "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
-                                      "menu_conv_call", &priv->menu_conv_call,
-                                      "menu_conv_call_separator", &priv->menu_conv_call_separator,
-                                      "menu_conv_log", &priv->menu_conv_log,
-                                      "menu_conv_separator", &priv->menu_conv_separator,
-                                      "menu_conv_add_contact", &priv->menu_conv_add_contact,
-                                      "menu_conv_info", &priv->menu_conv_info,
-                                      "menu_conv_close", &priv->menu_conv_close,
-                                      "menu_room", &priv->menu_room,
-                                      "menu_room_set_topic", &priv->menu_room_set_topic,
-                                      "menu_room_join_new", &priv->menu_room_join_new,
-                                      "menu_room_invite", &priv->menu_room_invite,
-                                      "menu_room_add", &priv->menu_room_add,
-                                      "menu_room_show_contacts", &priv->menu_room_show_contacts,
+                                      "menu_conv_favorite", &priv->menu_conv_favorite,
+                                      "menu_conv_toggle_contacts", &priv->menu_conv_toggle_contacts,
                                       "menu_edit_cut", &priv->menu_edit_cut,
                                       "menu_edit_copy", &priv->menu_edit_copy,
                                       "menu_edit_paste", &priv->menu_edit_paste,
@@ -1385,25 +1432,16 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                       "menu_tabs_left", &priv->menu_tabs_left,
                                       "menu_tabs_right", &priv->menu_tabs_right,
                                       "menu_tabs_detach", &priv->menu_tabs_detach,
-                                      "menu_help_contents", &priv->menu_help_contents,
-                                      "menu_help_about", &priv->menu_help_about,
                                       NULL);
        g_free (filename);
 
-       empathy_glade_connect (glade,
-                             window,
+       empathy_builder_connect (gui, window,
                              "chat_window", "configure-event", chat_window_configure_event_cb,
                              "menu_conv", "activate", chat_window_conv_activate_cb,
                              "menu_conv_clear", "activate", chat_window_clear_activate_cb,
-                             "menu_conv_call", "activate", chat_window_call_activate_cb,
-                             "menu_conv_log", "activate", chat_window_log_activate_cb,
-                             "menu_conv_add_contact", "activate", chat_window_add_contact_activate_cb,
-                             "menu_conv_info", "activate", chat_window_info_activate_cb,
+                             "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
+                             "menu_conv_toggle_contacts", "toggled", chat_window_contacts_toggled_cb,
                              "menu_conv_close", "activate", chat_window_close_activate_cb,
-                             "menu_room_set_topic", "activate", chat_window_room_set_topic_activate_cb,
-                             "menu_room_join_new", "activate", chat_window_room_join_new_activate_cb,
-                             "menu_room_invite", "activate", chat_window_room_invite_activate_cb,
-                             "menu_room_add", "activate", chat_window_room_add_activate_cb,
                              "menu_edit", "activate", chat_window_edit_activate_cb,
                              "menu_edit_cut", "activate", chat_window_cut_activate_cb,
                              "menu_edit_copy", "activate", chat_window_copy_activate_cb,
@@ -1411,23 +1449,19 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                              "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,
-                             "menu_help_contents", "activate", chat_window_help_contents_cb,
-                             "menu_help_about", "activate", chat_window_help_about_cb,
+                             "menu_help_contents", "activate", chat_window_help_contents_activate_cb,
+                             "menu_help_about", "activate", chat_window_help_about_activate_cb,
                              NULL);
 
-       g_object_unref (glade);
+       g_object_ref (priv->ui_manager);
+       g_object_unref (gui);
 
-       /* Set up chatroom manager */
-       priv->chatroom_manager = empathy_chatroom_manager_new ();
-       g_signal_connect_swapped (priv->chatroom_manager, "chatroom-added",
-                                 G_CALLBACK (chat_window_update_menu),
-                                 window);
-       g_signal_connect_swapped (priv->chatroom_manager, "chatroom-removed",
-                                 G_CALLBACK (chat_window_update_menu),
-                                 window);
+       priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
 
        priv->notebook = gtk_notebook_new ();
-       gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); 
+       gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
+       gtk_notebook_set_scrollable (GTK_NOTEBOOK (priv->notebook), TRUE);
+       gtk_notebook_popup_enable (GTK_NOTEBOOK (priv->notebook));
        gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
        gtk_widget_show (priv->notebook);
 
@@ -1448,21 +1482,17 @@ empathy_chat_window_init (EmpathyChatWindow *window)
 
        g_object_unref (accel_group);
 
-       /* Set the contact information menu item image to the Empathy
-        * stock image
-        */
-       image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (priv->menu_conv_info));
-       gtk_image_set_from_icon_name (GTK_IMAGE (image),
-                                     EMPATHY_IMAGE_CONTACT_INFORMATION,
-                                     GTK_ICON_SIZE_MENU);
-
        /* Set up smiley menu */
-       menu = empathy_chat_view_get_smiley_menu (
-               G_CALLBACK (chat_window_insert_smiley_activate_cb),
-               window);
-       gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley), menu);
-
-       /* Set up signals we can't do with glade since we may need to
+       smiley_manager = empathy_smiley_manager_dup_singleton ();
+       submenu = empathy_smiley_menu_new (smiley_manager,
+                                          chat_window_insert_smiley_activate_cb,
+                                          window);
+       menu = gtk_ui_manager_get_widget (priv->ui_manager,
+               "/chats_menubar/menu_conv/menu_conv_insert_smiley");
+       gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
+       g_object_unref (smiley_manager);
+
+       /* Set up signals we can't do with ui file since we may need to
         * block/unblock them at some later stage.
         */
 
@@ -1471,11 +1501,6 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                          G_CALLBACK (chat_window_delete_event_cb),
                          window);
 
-       g_signal_connect (priv->menu_room_show_contacts,
-                         "toggled",
-                         G_CALLBACK (chat_window_show_contacts_toggled_cb),
-                         window);
-
        g_signal_connect_swapped (priv->menu_tabs_prev,
                                  "activate",
                                  G_CALLBACK (gtk_notebook_prev_page),
@@ -1493,10 +1518,6 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                "switch_page",
                                G_CALLBACK (chat_window_page_switched_cb),
                                window);
-       g_signal_connect (priv->notebook,
-                         "page_reordered",
-                         G_CALLBACK (chat_window_page_reordered_cb),
-                         window);
        g_signal_connect (priv->notebook,
                          "page_added",
                          G_CALLBACK (chat_window_page_added_cb),
@@ -1559,7 +1580,7 @@ empathy_chat_window_get_default (void)
                chat_window = l->data;
 
                dialog = empathy_chat_window_get_dialog (chat_window);
-               if (empathy_window_get_is_visible (GTK_WINDOW (GTK_WINDOW (dialog)))) {
+               if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
                        /* Found a visible window on this desktop */
                        return chat_window;
                }
@@ -1586,6 +1607,7 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
 {
        EmpathyChatWindowPriv *priv;
        GtkWidget             *label;
+       GtkWidget             *popup_label;
        GtkWidget             *child;
        gint                   x, y, w, h;
 
@@ -1597,34 +1619,48 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        /* Reference the chat object */
        g_object_ref (chat);
 
-       empathy_chat_load_geometry (chat, &x, &y, &w, &h);
+       /* If this window has just been created, position it */
+       if (priv->chats == NULL) {
+               empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
 
-       if (x >= 0 && y >= 0) {
-               /* Let the window manager position it if we don't have
-                * good x, y coordinates.
-                */
-               gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
-       }
+               if (x >= 0 && y >= 0) {
+                       /* Let the window manager position it if we don't have
+                        * good x, y coordinates.
+                        */
+                       gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
+               }
 
-       if (w > 0 && h > 0) {
-               /* Use the defaults from the glade file if we don't have
-                * good w, h geometry.
-                */
-               gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
+               if (w > 0 && h > 0) {
+                       /* Use the defaults from the ui file if we don't have
+                        * good w, h geometry.
+                        */
+                       gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
+               }
        }
 
-       child = empathy_chat_get_widget (chat);
-       label = chat_window_create_label (window, chat); 
-
-       gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
+       child = GTK_WIDGET (chat);
+       label = chat_window_create_label (window, chat, TRUE);
+       popup_label = chat_window_create_label (window, chat, FALSE);
+       gtk_widget_show (child);
+
+       g_signal_connect (chat, "notify::name",
+                         G_CALLBACK (chat_window_chat_notify_cb),
+                         NULL);
+       g_signal_connect (chat, "notify::subject",
+                         G_CALLBACK (chat_window_chat_notify_cb),
+                         NULL);
+       g_signal_connect (chat, "notify::remote-contact",
+                         G_CALLBACK (chat_window_chat_notify_cb),
+                         NULL);
+       chat_window_chat_notify_cb (chat);
+
+       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); 
+                                           TRUE, TRUE, GTK_PACK_START);
 
-       empathy_debug (DEBUG_DOMAIN, 
-                     "Chat added (%d references)",
-                     G_OBJECT (chat)->ref_count);
+       DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
 }
 
 void
@@ -1632,20 +1668,30 @@ empathy_chat_window_remove_chat (EmpathyChatWindow *window,
                                 EmpathyChat       *chat)
 {
        EmpathyChatWindowPriv *priv;
-       gint                  position;
+       gint                   position;
+       EmpathyContact        *remote_contact;
 
        g_return_if_fail (window != NULL);
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
 
        priv = GET_PRIV (window);
 
+       g_signal_handlers_disconnect_by_func (chat,
+                                             chat_window_chat_notify_cb,
+                                             NULL);
+       remote_contact = g_object_get_data (G_OBJECT (chat),
+                                           "chat-window-remote-contact");
+       if (remote_contact) {
+               g_signal_handlers_disconnect_by_func (remote_contact,
+                                                     chat_window_update_chat_tab,
+                                                     chat);
+       }
+
        position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
-                                         empathy_chat_get_widget (chat));
+                                         GTK_WIDGET (chat));
        gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
 
-       empathy_debug (DEBUG_DOMAIN, 
-                     "Chat removed (%d references)", 
-                     G_OBJECT (chat)->ref_count - 1);
+       DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
 
        g_object_unref (chat);
 }
@@ -1661,12 +1707,10 @@ empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
        g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
 
-       widget = empathy_chat_get_widget (chat);
+       widget = GTK_WIDGET (chat);
 
-       empathy_debug (DEBUG_DOMAIN,
-                     "Chat moving with widget:%p (%d references)", 
-                     widget,
-                     G_OBJECT (widget)->ref_count);
+       DEBUG ("Chat moving with widget:%p (%d references)", widget,
+               G_OBJECT (widget)->ref_count);
 
        /* We reference here to make sure we don't loose the widget
         * and the EmpathyChat object during the move.
@@ -1694,7 +1738,7 @@ empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
        priv = GET_PRIV (window);
 
        page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
-                                         empathy_chat_get_widget (chat));
+                                         GTK_WIDGET (chat));
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
                                       page_num);
 }
@@ -1715,13 +1759,12 @@ empathy_chat_window_has_focus (EmpathyChatWindow *window)
 }
 
 EmpathyChat *
-empathy_chat_window_find_chat (McAccount   *account,
+empathy_chat_window_find_chat (EmpathyAccount   *account,
                               const gchar *id)
 {
        GList *l;
 
-       g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-       g_return_val_if_fail (!G_STR_EMPTY (id), NULL);
+       g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
 
        for (l = chat_windows; l; l = l->next) {
                EmpathyChatWindowPriv *priv;
@@ -1737,7 +1780,7 @@ empathy_chat_window_find_chat (McAccount   *account,
                        chat = ll->data;
 
                        if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
-                           strcmp (id, empathy_chat_get_id (chat)) == 0) {
+                           !tp_strdiff (id, empathy_chat_get_id (chat))) {
                                return chat;
                        }
                }
@@ -1770,60 +1813,6 @@ empathy_chat_window_present_chat (EmpathyChat *chat)
        empathy_chat_window_switch_to_chat (window, chat);
        empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
 
-       gtk_widget_grab_focus (chat->input_text_view); 
-}
-
-
-static gboolean
-chat_should_play_sound (EmpathyChat *chat)
-{
-       EmpathyChatPriv *priv = GET_PRIV (chat);
-       GtkWindow       *window;
-       gboolean         has_focus = FALSE;
-
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
-
-       window = empathy_get_toplevel_window (priv->widget);
-       if (window) {
-               g_object_get (window, "has-toplevel-focus", &has_focus, NULL);
-       }
-
-       return !has_focus;
-}
-static const gchar *
-chat_get_window_id_for_geometry (EmpathyChat *chat)
-{
-       gboolean separate_windows;
-
-       empathy_conf_get_bool (empathy_conf_get (),
-                              EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
-                              &separate_windows);
-
-       if (separate_windows) {
-               return empathy_chat_get_id (chat);
-       } else {
-               return "chat-window";
-       }
-}
-
-void
-empathy_chat_save_geometry (EmpathyChat *chat,
-                          gint        x,
-                          gint        y,
-                          gint        w,
-                          gint        h)
-{
-       empathy_geometry_save (chat_get_window_id_for_geometry (chat), x, y, w, h);
-}
-
-void
-empathy_chat_load_geometry (EmpathyChat *chat,
-                          gint       *x,
-                          gint       *y,
-                          gint       *w,
-                          gint       *h)
-{
-       empathy_geometry_load (chat_get_window_id_for_geometry (chat), x, y, w, h);
+       gtk_widget_grab_focus (chat->input_text_view);
 }
 
-