]> 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 e6823344e57b01aa1862ea340694a37d4f07ed86..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 <telepathy-glib/util.h>
 #include <libmissioncontrol/mission-control.h>
 
-#include <libempathy/empathy-contact-factory.h>
 #include <libempathy/empathy-contact.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>
@@ -50,6 +50,7 @@
 #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"
@@ -76,8 +77,8 @@ typedef struct {
        /* Menu items. */
        GtkUIManager *ui_manager;
        GtkAction   *menu_conv_insert_smiley;
-       GtkAction   *menu_conv_contact;
        GtkAction   *menu_conv_favorite;
+       GtkAction   *menu_conv_toggle_contacts;
 
        GtkAction   *menu_edit_cut;
        GtkAction   *menu_edit_copy;
@@ -162,21 +163,39 @@ chat_window_close_clicked_cb (GtkAction   *action,
 }
 
 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;
+
+       button = g_object_get_data (G_OBJECT (user_data),
+               "chat-window-tab-close-button");
+       context = gtk_widget_get_pango_context (hbox);
+
+       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);
 
        gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
                                           GTK_ICON_SIZE_MENU, &w, &h);
 
+       /* 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);
+
        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;
@@ -198,7 +217,8 @@ chat_window_create_label (EmpathyChatWindow *window,
        gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
 
        name_label = gtk_label_new (NULL);
-       gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
+       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);
@@ -210,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 ();
 
@@ -220,42 +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);
-       g_object_set_data (G_OBJECT (chat), "chat-window-tab-close-button", close_button);
+       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);
+
+               /* 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);
 
@@ -279,6 +306,8 @@ chat_window_update (EmpathyChatWindow *window)
        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));
@@ -299,6 +328,13 @@ chat_window_update (EmpathyChatWindow *window)
        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), name);
@@ -347,6 +383,23 @@ chat_window_update (EmpathyChatWindow *window)
        }
 }
 
+static void
+append_markup_printf (GString    *string,
+                     const char *format,
+                     ...)
+{
+       gchar *tmp;
+       va_list args;
+
+       va_start (args, format);
+
+       tmp = g_markup_vprintf_escaped (format, args);
+       g_string_append (string, tmp);
+       g_free (tmp);
+
+       va_end (args);
+}
+
 static void
 chat_window_update_chat_tab (EmpathyChat *chat)
 {
@@ -354,8 +407,10 @@ chat_window_update_chat_tab (EmpathyChat *chat)
        EmpathyChatWindowPriv *priv;
        EmpathyContact        *remote_contact;
        const gchar           *name;
-       McAccount             *account;
+       const gchar           *id;
+       EmpathyAccount        *account;
        const gchar           *subject;
+       const gchar           *status = NULL;
        GtkWidget             *widget;
        GString               *tooltip;
        gchar                 *markup;
@@ -374,7 +429,7 @@ chat_window_update_chat_tab (EmpathyChat *chat)
        remote_contact = empathy_chat_get_remote_contact (chat);
 
        DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
-               name, mc_account_get_unique_name (account), subject, remote_contact);
+               name, empathy_account_get_unique_name (account), subject, remote_contact);
 
        /* Update tab image */
        if (g_list_find (priv->chats_new_msg, chat)) {
@@ -390,44 +445,49 @@ chat_window_update_chat_tab (EmpathyChat *chat)
        }
        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);
 
        /* Update tab tooltip */
        tooltip = g_string_new (NULL);
 
        if (remote_contact) {
-               markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
-                                                 empathy_contact_get_id (remote_contact),
-                                                 mc_account_get_display_name (account),
-                                                 empathy_contact_get_status (remote_contact));
-               g_string_append (tooltip, markup);
-               g_free (markup);
+               id = empathy_contact_get_id (remote_contact);
+               status = empathy_contact_get_presence_message (remote_contact);
+       } else {
+               id = name;
        }
-       else {
-               markup = g_markup_printf_escaped ("<b>%s</b><small>  (%s)</small>", name,
-                                                 mc_account_get_display_name (account));
-               g_string_append (tooltip, markup);
-               g_free (markup);
+
+       append_markup_printf (tooltip,
+                             "<b>%s</b><small> (%s)</small>",
+                             id,
+                             empathy_account_get_display_name (account));
+
+       if (!EMP_STR_EMPTY (status)) {
+               append_markup_printf (tooltip, "\n<i>%s</i>", status);
        }
 
        if (subject) {
-               markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
-               g_string_append (tooltip, markup);
-               g_free (markup);
+               append_markup_printf (tooltip, "\n<b>%s</b> %s",
+                                     _("Topic:"), subject);
        }
+
        if (g_list_find (priv->chats_composing, chat)) {
-               markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
-               g_string_append (tooltip, markup);
-               g_free (markup);
+               append_markup_printf (tooltip, "\n%s", _("Typing a message."));
        }
 
        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 label */
+       /* 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) {
@@ -488,37 +548,46 @@ chat_window_conv_activate_cb (GtkAction         *action,
                              EmpathyChatWindow *window)
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
-       GtkWidget             *menu = NULL;
-       GtkWidget             *submenu = NULL;
        gboolean               is_room;
-
-       /* Contact submenu */
-       submenu = empathy_chat_get_contact_menu (priv->current_chat);
-       if (submenu) {
-               menu = gtk_ui_manager_get_widget (priv->ui_manager,
-                       "/chats_menubar/menu_conv/menu_conv_contact");
-               gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
-               gtk_widget_show (submenu);
-       }
-       gtk_action_set_visible (priv->menu_conv_contact, submenu != NULL);
+       gboolean               active;
+       EmpathyContact        *remote_contact = NULL;
 
        /* Favorite room menu */
        is_room = empathy_chat_is_room (priv->current_chat);
        if (is_room) {
                const gchar *room;
-               McAccount   *account;
-               gboolean     found;
+               EmpathyAccount   *account;
+               gboolean     found = FALSE;
+               EmpathyChatroom *chatroom;
 
                room = empathy_chat_get_id (priv->current_chat);
                account = empathy_chat_get_account (priv->current_chat);
-               found = empathy_chatroom_manager_find (priv->chatroom_manager,
-                                                      account, room) != NULL;
+               chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
+                                                      account, room);
+               if (chatroom != NULL)
+                       found = empathy_chatroom_is_favorite (chatroom);
 
                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
@@ -536,7 +605,7 @@ chat_window_favorite_toggled_cb (GtkToggleAction   *toggle_action,
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
        gboolean               active;
-       McAccount             *account;
+       EmpathyAccount        *account;
        const gchar           *room;
        EmpathyChatroom       *chatroom;
 
@@ -547,19 +616,28 @@ chat_window_favorite_toggled_cb (GtkToggleAction   *toggle_action,
        chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
                                                  account, room);
 
-       if (active && !chatroom) {
+       if (chatroom == NULL) {
                const gchar *name;
 
                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);
-               return;
-       }
-       
-       if (!active && chatroom) {
-               empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
-       }
+  }
+
+       empathy_chatroom_set_favorite (chatroom, active);
+}
+
+static void
+chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
+                                EmpathyChatWindow *window)
+{
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
+       gboolean               active;
+
+       active = gtk_toggle_action_get_active (toggle_action);
+
+       empathy_chat_set_show_contacts (priv->current_chat, active);
 }
 
 static const gchar *
@@ -864,7 +942,8 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
                                         EmpathyChat *chat)
 {
        EmpathyContact *sender;
-       char *header, *escaped;
+       const gchar *header;
+       char *escaped;
        const char *body;
        GdkPixbuf *pixbuf;
        NotificationData *cb_data;
@@ -886,8 +965,7 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        cb_data->window = window;
 
        sender = empathy_message_get_sender (message);
-       header = g_strdup_printf (_("New message from %s"),
-                                 empathy_contact_get_name (sender));
+       header = empathy_contact_get_name (sender);
        body = empathy_message_get_body (message);
        escaped = g_markup_escape_text (body, -1);
 
@@ -896,11 +974,15 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        if (priv->notification != NULL) {
                notify_notification_update (priv->notification,
                                            header, escaped, NULL);
-               notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+               /* if icon doesn't exist libnotify will crash */
+               if (pixbuf != NULL)
+                       notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
        } else {
                priv->notification = notify_notification_new (header, escaped, NULL, NULL);
                notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
-               notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+               /* 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);
@@ -909,10 +991,27 @@ chat_window_show_or_update_notification (EmpathyChatWindow *window,
        notify_notification_show (priv->notification, NULL);
 
        g_object_unref (pixbuf);
-       g_free (header);
        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,
@@ -930,43 +1029,47 @@ chat_window_new_message_cb (EmpathyChat       *chat,
        /* - 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
-        *   prefereces and the window does not have focus on the chat receiving
+        *   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) != FALSE) {
+       if (empathy_contact_is_user (sender)) {
                empathy_sound_play (GTK_WIDGET (priv->dialog),
                                    EMPATHY_SOUND_MESSAGE_OUTGOING);
-       } else {
-               if ((!has_focus || priv->current_chat != chat)) {
-                       empathy_sound_play (GTK_WIDGET (priv->dialog),
-                                           EMPATHY_SOUND_MESSAGE_INCOMING);
-               }
-       }
-
-       if (!has_focus) {
-               chat_window_show_or_update_notification (window, message, chat);
        }
 
        if (has_focus && priv->current_chat == chat) {
                return;
        }
-       
-       if (empathy_chat_get_members_count (chat) > 2) {
+
+       if (!g_list_find (priv->chats_new_msg, chat)) {
+               priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, 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 && !has_focus) {
-               chat_window_set_urgency_hint (window, TRUE);
-       }
+       if (needs_urgency) {
+               if (!has_focus) {
+                       chat_window_set_urgency_hint (window, TRUE);
+                       chat_window_set_highlight_room_tab_label (chat);
+               }
 
-       if (!g_list_find (priv->chats_new_msg, chat)) {
-               priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
-               chat_window_update_chat_tab (chat);
+               empathy_sound_play (GTK_WIDGET (priv->dialog),
+                   EMPATHY_SOUND_MESSAGE_INCOMING);
+               chat_window_show_or_update_notification (window, message, chat);
        }
 }
 
@@ -1132,7 +1235,7 @@ chat_window_focus_in_event_cb (GtkWidget        *widget,
        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_chat_tab (priv->current_chat);
 
@@ -1152,46 +1255,61 @@ chat_window_drag_data_received (GtkWidget        *widget,
        if (info == DND_DRAG_TYPE_CONTACT_ID) {
                EmpathyChat           *chat;
                EmpathyChatWindow     *old_window;
-               McAccount             *account;
+               EmpathyAccount        *account;
+               EmpathyAccountManager *account_manager;
                const gchar           *id;
                gchar                **strv;
+               const gchar           *account_id;
+               const gchar           *contact_id;
 
-               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);
-               
+
                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_dispatcher_chat_with_contact_id (account, strv[2], NULL, NULL);
+                       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);
        }
@@ -1201,7 +1319,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                DEBUG ("DND tab");
 
-               chat = (void*) selection->data;
+               chat = (void *) gtk_selection_data_get_data (selection);
                old_window = chat_window_find_chat (*chat);
 
                if (old_window) {
@@ -1215,14 +1333,14 @@ chat_window_drag_data_received (GtkWidget        *widget,
                                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 {
@@ -1304,8 +1422,8 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                                       "chat_vbox", &chat_vbox,
                                       "ui_manager", &priv->ui_manager,
                                       "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
-                                      "menu_conv_contact", &priv->menu_conv_contact,
                                       "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,
@@ -1322,6 +1440,7 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                              "menu_conv", "activate", chat_window_conv_activate_cb,
                              "menu_conv_clear", "activate", chat_window_clear_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_edit", "activate", chat_window_edit_activate_cb,
                              "menu_edit_cut", "activate", chat_window_cut_activate_cb,
@@ -1340,7 +1459,9 @@ empathy_chat_window_init (EmpathyChatWindow *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);
 
@@ -1486,6 +1607,7 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
 {
        EmpathyChatWindowPriv *priv;
        GtkWidget             *label;
+       GtkWidget             *popup_label;
        GtkWidget             *child;
        gint                   x, y, w, h;
 
@@ -1500,14 +1622,14 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        /* 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 (w > 0 && h > 0) {
                        /* Use the defaults from the ui file if we don't have
                         * good w, h geometry.
@@ -1517,7 +1639,8 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
        }
 
        child = GTK_WIDGET (chat);
-       label = chat_window_create_label (window, 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",
@@ -1531,11 +1654,11 @@ empathy_chat_window_add_chat (EmpathyChatWindow *window,
                          NULL);
        chat_window_chat_notify_cb (chat);
 
-       gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
+       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);
 
        DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
 }
@@ -1636,12 +1759,11 @@ 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 (!EMP_STR_EMPTY (id), NULL);
 
        for (l = chat_windows; l; l = l->next) {
@@ -1691,20 +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); 
+       gtk_widget_grab_focus (chat->input_text_view);
 }
 
-#if 0
-static gboolean
-chat_window_should_play_sound (EmpathyChatWindow *window)
-{
-       EmpathyChatWindowPriv *priv = GET_PRIV (window);
-       gboolean               has_focus = FALSE;
-
-       g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
-
-       g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
-
-       return !has_focus;
-}
-#endif