]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-chat.c
Merge remote-tracking branch 'pochu/error-dialog'
[empathy.git] / libempathy-gtk / empathy-chat.c
index cf3336bdf70061bbe3c375eae0aad4d2787950c6..b1d469f3f2c8d7ae3ccad16077d1598ff16b5c1c 100644 (file)
@@ -38,6 +38,7 @@
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/util.h>
 #include <telepathy-logger/log-manager.h>
+#include <telepathy-logger/text-event.h>
 #include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-gsettings.h>
 #include <libempathy/empathy-keyring.h>
 #include "empathy-contact-list-store.h"
 #include "empathy-contact-list-view.h"
 #include "empathy-contact-menu.h"
-#include "empathy-gtk-marshal.h"
 #include "empathy-input-text-view.h"
 #include "empathy-search-bar.h"
 #include "empathy-theme-manager.h"
+#include "empathy-theme-adium.h"
 #include "empathy-smiley-manager.h"
 #include "empathy-ui-utils.h"
 #include "empathy-string-parser.h"
@@ -105,6 +106,8 @@ struct _EmpathyChatPriv {
        guint              update_misspelled_words_id;
        /* Source func ID for save_paned_pos_timeout () */
        guint              save_paned_pos_id;
+       /* Source func ID for chat_contacts_visible_timeout_cb () */
+       guint              contacts_visible_id;
 
        GtkWidget         *widget;
        GtkWidget         *hpaned;
@@ -120,6 +123,7 @@ struct _EmpathyChatPriv {
        GtkWidget         *search_bar;
 
        guint              unread_messages;
+       guint              unread_messages_when_offline;
        /* TRUE if the pending messages can be displayed. This is to avoid to show
         * pending messages *before* messages from logs. (#603980) */
        gboolean           can_show_pending;
@@ -147,6 +151,11 @@ struct _EmpathyChatPriv {
         * messages in tab will be properly shown */
        gboolean           retrieving_backlogs;
        gboolean           sms_channel;
+
+       /* we need to know whether populate-popup happened in response to
+        * the keyboard or the mouse. We can't ask GTK for the most recent
+        * event, because it will be a notify event. Instead we track it here */
+       GdkEventType       most_recent_event_type;
 };
 
 typedef struct {
@@ -179,7 +188,7 @@ enum {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
+G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BOX);
 
 static gboolean update_misspelled_words (gpointer data);
 
@@ -268,11 +277,13 @@ account_reconnected (EmpathyChat *chat,
                        if (priv->sms_channel)
                                empathy_sms_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        else
                                empathy_chat_with_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        break;
                case TP_HANDLE_TYPE_ROOM:
                        empathy_join_muc (account, priv->id,
@@ -326,6 +337,34 @@ chat_composing_remove_timeout (EmpathyChat *chat)
        }
 }
 
+static void
+set_chate_state_cb (GObject *source,
+                   GAsyncResult *result,
+                   gpointer user_data)
+{
+       GError *error = NULL;
+
+       if (!tp_text_channel_set_chat_state_finish (TP_TEXT_CHANNEL (source), result,
+               &error)) {
+               DEBUG ("Failed to set chat state: %s", error->message);
+               g_error_free (error);
+       }
+}
+
+static void
+set_chat_state (EmpathyChat *self,
+               TpChannelChatState state)
+{
+       EmpathyChatPriv *priv = GET_PRIV (self);
+
+       if (!tp_proxy_has_interface_by_id (priv->tp_chat,
+               TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE))
+               return;
+
+       tp_text_channel_set_chat_state_async (TP_TEXT_CHANNEL (priv->tp_chat), state,
+               set_chate_state_cb, self);
+}
+
 static gboolean
 chat_composing_stop_timeout_cb (EmpathyChat *chat)
 {
@@ -334,8 +373,7 @@ chat_composing_stop_timeout_cb (EmpathyChat *chat)
        priv = GET_PRIV (chat);
 
        priv->composing_stop_timeout_id = 0;
-       empathy_tp_chat_set_state (priv->tp_chat,
-                                  TP_CHANNEL_CHAT_STATE_PAUSED);
+       set_chat_state (chat, TP_CHANNEL_CHAT_STATE_PAUSED);
 
        return FALSE;
 }
@@ -351,8 +389,7 @@ chat_composing_start (EmpathyChat *chat)
                /* Just restart the timeout */
                chat_composing_remove_timeout (chat);
        } else {
-               empathy_tp_chat_set_state (priv->tp_chat,
-                                          TP_CHANNEL_CHAT_STATE_COMPOSING);
+               set_chat_state (chat, TP_CHANNEL_CHAT_STATE_COMPOSING);
        }
 
        priv->composing_stop_timeout_id = g_timeout_add_seconds (
@@ -364,13 +401,8 @@ chat_composing_start (EmpathyChat *chat)
 static void
 chat_composing_stop (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
-
-       priv = GET_PRIV (chat);
-
        chat_composing_remove_timeout (chat);
-       empathy_tp_chat_set_state (priv->tp_chat,
-                                  TP_CHANNEL_CHAT_STATE_ACTIVE);
+       set_chat_state (chat, TP_CHANNEL_CHAT_STATE_ACTIVE);
 }
 
 static gint
@@ -984,6 +1016,44 @@ chat_command_whois (EmpathyChat *chat,
                whois_got_contact_cb, NULL, NULL, G_OBJECT (chat));
 }
 
+static void
+chat_command_whale (EmpathyChat *chat,
+                   GStrv        strv)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpMessage *message;
+
+       message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+               "\n\n\n"
+               "•_______________•");
+       empathy_tp_chat_send (priv->tp_chat, message);
+       g_object_unref (message);
+}
+
+static void
+chat_command_babywhale (EmpathyChat *chat,
+                       GStrv        strv)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpMessage *message;
+
+       message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+               "\n"
+               "•_____•");
+       empathy_tp_chat_send (priv->tp_chat, message);
+       g_object_unref (message);
+}
+
+static void
+chat_command_inspector (EmpathyChat *chat,
+                   GStrv        strv)
+{
+       if (EMPATHY_IS_THEME_ADIUM (chat->view)) {
+               empathy_theme_adium_show_inspector (
+                       EMPATHY_THEME_ADIUM (chat->view));
+       }
+}
+
 static void chat_command_help (EmpathyChat *chat, GStrv strv);
 
 typedef void (*ChatCommandFunc) (EmpathyChat *chat, GStrv strv);
@@ -1038,6 +1108,11 @@ static ChatCommandItem commands[] = {
        {"help", 1, 2, chat_command_help, NULL,
         N_("/help [<command>]: show all supported commands. "
            "If <command> is defined, show its usage.")},
+
+       {"inspector", 1, 1, chat_command_inspector, NULL, NULL},
+
+       {"whale", 1, 1, chat_command_whale, NULL, NULL},
+       {"babywhale", 1, 1, chat_command_babywhale, NULL, NULL},
 };
 
 static void
@@ -1046,6 +1121,10 @@ chat_command_show_help (EmpathyChat     *chat,
 {
        gchar *str;
 
+       if (item->help == NULL) {
+               return;
+       }
+
        str = g_strdup_printf (_("Usage: %s"), _(item->help));
        empathy_chat_view_append_event (chat->view, str);
        g_free (str);
@@ -1066,8 +1145,11 @@ chat_command_help (EmpathyChat *chat,
                                        continue;
                                }
                        }
-                   empathy_chat_view_append_event (chat->view,
-                           _(commands[i].help));
+                       if (commands[i].help == NULL) {
+                               continue;
+                       }
+                       empathy_chat_view_append_event (chat->view,
+                               _(commands[i].help));
                }
                return;
        }
@@ -1079,6 +1161,9 @@ chat_command_help (EmpathyChat *chat,
                                        break;
                                }
                        }
+                       if (commands[i].help == NULL) {
+                               break;
+                       }
                        chat_command_show_help (chat, &commands[i]);
                        return;
                }
@@ -1315,23 +1400,33 @@ chat_message_received (EmpathyChat *chat,
 
        sender = empathy_message_get_sender (message);
 
-       DEBUG ("Appending new message from %s (%d)",
-               empathy_contact_get_alias (sender),
-               empathy_contact_get_handle (sender));
+       if (empathy_message_is_edit (message)) {
+               DEBUG ("Editing message '%s' to '%s'",
+                       empathy_message_get_supersedes (message),
+                       empathy_message_get_body (message));
 
-       empathy_chat_view_append_message (chat->view, message);
+               empathy_chat_view_edit_message (chat->view, message);
+       } else {
+               DEBUG ("Appending new message '%s' from %s (%d)",
+                       empathy_message_get_token (message),
+                       empathy_contact_get_alias (sender),
+                       empathy_contact_get_handle (sender));
 
-       /* We received a message so the contact is no longer composing */
-       chat_state_changed_cb (priv->tp_chat, sender,
-                              TP_CHANNEL_CHAT_STATE_ACTIVE,
-                              chat);
+               empathy_chat_view_append_message (chat->view, message);
 
-       if (empathy_message_is_incoming (message)) {
-               priv->unread_messages++;
-               g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+               if (empathy_message_is_incoming (message)) {
+                       priv->unread_messages++;
+                       g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+               }
+
+               g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
        }
 
-       g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
+       /* We received a message so the contact is no longer
+        * composing */
+       chat_state_changed_cb (priv->tp_chat, sender,
+                              TP_CHANNEL_CHAT_STATE_ACTIVE,
+                              chat);
 }
 
 static void
@@ -1352,8 +1447,55 @@ chat_message_acknowledged_cb (EmpathyTpChat  *tp_chat,
        empathy_chat_view_message_acknowledged (chat->view,
            message);
 
-       priv->unread_messages--;
-       g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+       if (!empathy_message_is_edit (message)) {
+               priv->unread_messages--;
+               g_object_notify (G_OBJECT (chat), "nb-unread-messages");
+       }
+}
+
+static void
+append_balance_error (EmpathyChat *chat,
+                     const gchar *message_body)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+       const gchar *uri = tp_connection_get_balance_uri (conn);
+       const gchar *error = _("insufficient balance to send message");
+       gchar *str, *str_markup = NULL;
+
+       if (message_body != NULL) {
+               str = g_strdup_printf (_("Error sending message '%s': %s"), message_body, error);
+       } else {
+               str = g_strdup_printf (_("Error sending message: %s"), error);
+       }
+
+       if (!tp_str_empty (uri)) {
+               /* translators: error used when user doesn't have enough credit on his
+                * account to send the message. */
+               gchar *markup_error = g_strdup_printf (_("insufficient balance to send message."
+                                                        " <a href='%s'>Top up</a>."), uri);
+
+               if (message_body != NULL) {
+                       gchar *escaped_body = g_markup_escape_text (message_body, -1);
+
+                       str_markup = g_strdup_printf (_("Error sending message '%s': %s"),
+                               escaped_body, markup_error);
+
+                       g_free (escaped_body);
+               } else {
+                       str_markup = g_strdup_printf (_("Error sending message: %s"), markup_error);
+               }
+
+               g_free (markup_error);
+       }
+
+       if (str_markup != NULL)
+               empathy_chat_view_append_event_markup (chat->view, str_markup, str);
+       else
+               empathy_chat_view_append_event (chat->view, str);
+
+       g_free (str);
+       g_free (str_markup);
 }
 
 static void
@@ -1367,9 +1509,8 @@ chat_send_error_cb (EmpathyTpChat          *tp_chat,
        gchar       *str;
 
        if (!tp_strdiff (dbus_error, TP_ERROR_STR_INSUFFICIENT_BALANCE)) {
-               /* translators: error used when user doesn't have enough credit on his
-                * account to send the message. */
-               error = _("insufficient balance to send message");
+               append_balance_error (chat, message_body);
+               return;
        } else if (!tp_strdiff (dbus_error, TP_ERROR_STR_NOT_CAPABLE)) {
                error = _("not capable");
        }
@@ -1667,6 +1808,8 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
 
        priv = GET_PRIV (chat);
 
+       priv->most_recent_event_type = event->type;
+
        /* Catch ctrl+up/down so we can traverse messages we sent */
        if ((event->state & GDK_CONTROL_MASK) &&
            (event->keyval == GDK_KEY_Up ||
@@ -2122,11 +2265,24 @@ chat_text_send_cb (GtkMenuItem *menuitem,
        chat_input_text_view_send (chat);
 }
 
+static gboolean
+chat_input_button_press_event_cb (GtkTextView    *view,
+                                 GdkEventButton *event,
+                                 EmpathyChat    *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       priv->most_recent_event_type = event->type;
+
+       return FALSE;
+}
+
 static void
 chat_input_populate_popup_cb (GtkTextView *view,
                              GtkMenu     *menu,
                              EmpathyChat *chat)
 {
+       EmpathyChatPriv      *priv = GET_PRIV (chat);
        GtkTextBuffer        *buffer;
        GtkTextTagTable      *table;
        GtkTextTag           *tag;
@@ -2177,12 +2333,31 @@ chat_input_populate_popup_cb (GtkTextView *view,
        /* Add the spell check menu item. */
        table = gtk_text_buffer_get_tag_table (buffer);
        tag = gtk_text_tag_table_lookup (table, "misspelled");
-       gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
-       gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
-                                              GTK_TEXT_WINDOW_WIDGET,
-                                              x, y,
-                                              &x, &y);
-       gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
+
+       switch (priv->most_recent_event_type) {
+           case GDK_BUTTON_PRESS:
+               /* get the location from the pointer */
+               gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+               gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
+                                                      GTK_TEXT_WINDOW_WIDGET,
+                                                      x, y,
+                                                      &x, &y);
+               gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view),
+                                                   &iter, x, y);
+               break;
+
+           default:
+               g_warn_if_reached ();
+               /* assume the KEY_PRESS case */
+
+           case GDK_KEY_PRESS:
+               /* get the location from the cursor */
+               gtk_text_buffer_get_iter_at_mark (buffer, &iter,
+                               gtk_text_buffer_get_insert (buffer));
+               break;
+
+       }
+
        start = end = iter;
        if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
            gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
@@ -2227,7 +2402,7 @@ chat_input_populate_popup_cb (GtkTextView *view,
 
 
 static gboolean
-chat_log_filter (TplEvent *log,
+chat_log_filter (TplEvent *event,
                 gpointer user_data)
 {
        EmpathyChat *chat = user_data;
@@ -2235,11 +2410,11 @@ chat_log_filter (TplEvent *log,
        EmpathyChatPriv *priv = GET_PRIV (chat);
        const GList *pending;
 
-       g_return_val_if_fail (TPL_IS_EVENT (log), FALSE);
+       g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
        g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
 
        pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
-       message = empathy_message_from_tpl_log_event (log);
+       message = empathy_message_from_tpl_log_event (event);
 
        for (; pending; pending = g_list_next (pending)) {
                if (empathy_message_equal (message, pending->data)) {
@@ -2297,12 +2472,38 @@ got_filtered_messages_cb (GObject *manager,
 
        for (l = messages; l; l = g_list_next (l)) {
                EmpathyMessage *message;
+
                g_assert (TPL_IS_EVENT (l->data));
 
                message = empathy_message_from_tpl_log_event (l->data);
                g_object_unref (l->data);
 
-               empathy_chat_view_append_message (chat->view, message);
+               if (empathy_message_is_edit (message)) {
+                       /* this is an edited message, create a synthetic event
+                        * using the supersedes token and
+                        * original-message-sent timestamp, that we can then
+                        * replace */
+                       EmpathyMessage *syn_msg = g_object_new (
+                               EMPATHY_TYPE_MESSAGE,
+                               "body", "",
+                               "token", empathy_message_get_supersedes (message),
+                               "type", empathy_message_get_tptype (message),
+                               "timestamp", empathy_message_get_original_timestamp (message),
+                               "incoming", empathy_message_is_incoming (message),
+                               "is-backlog", TRUE,
+                               "receiver", empathy_message_get_receiver (message),
+                               "sender", empathy_message_get_sender (message),
+                               NULL);
+
+                       empathy_chat_view_append_message (chat->view, syn_msg);
+                       empathy_chat_view_edit_message (chat->view, message);
+
+                       g_object_unref (syn_msg);
+               } else {
+                       /* append the latest message */
+                       empathy_chat_view_append_message (chat->view, message);
+               }
+
                g_object_unref (message);
        }
        g_list_free (messages);
@@ -2495,9 +2696,22 @@ chat_member_renamed_cb (EmpathyTpChat  *tp_chat,
 }
 
 static gboolean
-chat_reset_size_request (gpointer widget)
+chat_contacts_visible_timeout_cb (gpointer chat)
 {
-       gtk_widget_set_size_request (widget, -1, -1);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       /* Relax the size request */
+       gtk_widget_set_size_request (priv->vbox_left, -1, -1);
+
+       /* Set the position of the slider. This must be done here because
+        * GtkPaned need to know its size allocation and it will be settled only
+        * after the gtk_window_resize () tough effect. */
+       if (priv->contacts_width > 0) {
+               gtk_paned_set_position (GTK_PANED (priv->hpaned),
+                                       priv->contacts_width);
+       }
+
+       priv->contacts_visible_id = 0;
 
        return FALSE;
 }
@@ -2507,7 +2721,6 @@ chat_update_contacts_visibility (EmpathyChat *chat,
                         gboolean show)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       GtkAllocation allocation;
 
        if (!priv->scrolled_window_contacts) {
                return;
@@ -2520,6 +2733,7 @@ chat_update_contacts_visibility (EmpathyChat *chat,
        if (show && priv->contact_list_view == NULL) {
                EmpathyContactListStore *store;
                gint                     min_width;
+               GtkAllocation            allocation;
 
                /* We are adding the contact list to the chat, we don't want the
                 * chat view to become too small. If the chat view is already
@@ -2530,12 +2744,13 @@ chat_update_contacts_visibility (EmpathyChat *chat,
                gtk_widget_get_allocation (priv->vbox_left, &allocation);
                min_width = MIN (allocation.width, 250);
                gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
-               g_idle_add (chat_reset_size_request, priv->vbox_left);
 
-               if (priv->contacts_width > 0) {
-                       gtk_paned_set_position (GTK_PANED (priv->hpaned),
-                                               priv->contacts_width);
-               }
+               /* There is no way to know when the window resize will happen
+                * since it is WM's decision. Let's hope it won't be longer. */
+               if (priv->contacts_visible_id != 0)
+                       g_source_remove (priv->contacts_visible_id);
+               priv->contacts_visible_id = g_timeout_add (500,
+                       chat_contacts_visible_timeout_cb, chat);
 
                store = empathy_contact_list_store_new (
                                EMPATHY_CONTACT_LIST (priv->tp_chat));
@@ -2605,7 +2820,10 @@ chat_remote_contact_changed_cb (EmpathyChat *chat)
 }
 
 static void
-chat_destroy_cb (EmpathyTpChat *tp_chat,
+chat_invalidated_cb (EmpathyTpChat *tp_chat,
+                guint domain,
+                gint code,
+                gchar *message,
                 EmpathyChat   *chat)
 {
        EmpathyChatPriv *priv;
@@ -2625,6 +2843,8 @@ chat_destroy_cb (EmpathyTpChat *tp_chat,
        gtk_widget_set_sensitive (chat->input_text_view, FALSE);
 
        chat_update_contacts_visibility (chat, FALSE);
+
+       priv->unread_messages_when_offline = priv->unread_messages;
 }
 
 static gboolean
@@ -2772,7 +2992,6 @@ chat_create_ui (EmpathyChat *chat)
        GList           *list = NULL;
        gchar           *filename;
        GtkTextBuffer   *buffer;
-       gint              paned_pos;
        EmpathyThemeManager *theme_mgr;
 
        filename = empathy_file_lookup ("empathy-chat.ui",
@@ -2825,6 +3044,9 @@ chat_create_ui (EmpathyChat *chat)
        g_signal_connect (chat->input_text_view, "realize",
                          G_CALLBACK (chat_input_realize_cb),
                          chat);
+       g_signal_connect (chat->input_text_view, "button-press-event",
+                         G_CALLBACK (chat_input_button_press_event_cb),
+                         chat);
        g_signal_connect (chat->input_text_view, "populate-popup",
                          G_CALLBACK (chat_input_populate_popup_cb),
                          chat);
@@ -2855,12 +3077,6 @@ chat_create_ui (EmpathyChat *chat)
                          G_CALLBACK (chat_hpaned_pos_changed_cb),
                          chat);
 
-        /* Load the paned position */
-       paned_pos = g_settings_get_int (priv->gsettings_ui,
-                       EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
-       if (paned_pos != 0)
-               gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
-
        /* Set widget focus order */
        list = g_list_append (NULL, priv->search_bar);
        list = g_list_append (list, priv->scrolled_window_input);
@@ -2878,33 +3094,10 @@ chat_create_ui (EmpathyChat *chat)
        g_list_free (list);
 
        /* Add the main widget in the chat widget */
-       gtk_container_add (GTK_CONTAINER (chat), priv->widget);
+       gtk_box_pack_start (GTK_BOX (chat), priv->widget, TRUE, TRUE, 0);
        g_object_unref (gui);
 }
 
-static void
-chat_size_allocate (GtkWidget     *widget,
-                   GtkAllocation *allocation)
-{
-  GtkBin *bin = GTK_BIN (widget);
-  GtkAllocation child_allocation;
-  GtkWidget *child;
-
-  gtk_widget_set_allocation (widget, allocation);
-
-  child = gtk_bin_get_child (bin);
-
-  if (child && gtk_widget_get_visible (child))
-    {
-      child_allocation.x = allocation->x + gtk_container_get_border_width (GTK_CONTAINER (widget));
-      child_allocation.y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (widget));
-      child_allocation.width = MAX (allocation->width - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
-      child_allocation.height = MAX (allocation->height - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
-
-      gtk_widget_size_allocate (child, &child_allocation);
-    }
-}
-
 static void
 chat_finalize (GObject *object)
 {
@@ -2922,6 +3115,9 @@ chat_finalize (GObject *object)
        if (priv->save_paned_pos_id != 0)
                g_source_remove (priv->save_paned_pos_id);
 
+       if (priv->contacts_visible_id != 0)
+               g_source_remove (priv->contacts_visible_id);
+
        g_object_unref (priv->gsettings_chat);
        g_object_unref (priv->gsettings_ui);
 
@@ -2938,7 +3134,7 @@ chat_finalize (GObject *object)
 
        if (priv->tp_chat) {
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
-                       chat_destroy_cb, chat);
+                       chat_invalidated_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_message_received_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
@@ -2995,7 +3191,6 @@ chat_constructed (GObject *object)
 static void
 empathy_chat_class_init (EmpathyChatClass *klass)
 {
-       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
        object_class->finalize = chat_finalize;
@@ -3003,8 +3198,6 @@ empathy_chat_class_init (EmpathyChatClass *klass)
        object_class->set_property = chat_set_property;
        object_class->constructed = chat_constructed;
 
-       widget_class->size_allocate = chat_size_allocate;
-
        g_object_class_install_property (object_class,
                                         PROP_TP_CHAT,
                                         g_param_spec_object ("tp-chat",
@@ -3093,7 +3286,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             g_cclosure_marshal_VOID__BOOLEAN,
+                             g_cclosure_marshal_generic,
                              G_TYPE_NONE,
                              1, G_TYPE_BOOLEAN);
 
@@ -3103,7 +3296,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                              G_SIGNAL_RUN_LAST,
                              0,
                              NULL, NULL,
-                             _empathy_gtk_marshal_VOID__OBJECT_BOOLEAN,
+                             g_cclosure_marshal_generic,
                              G_TYPE_NONE,
                              2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
 
@@ -3113,7 +3306,7 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                                  G_SIGNAL_RUN_LAST,
                                  0,
                                  NULL, NULL,
-                                 g_cclosure_marshal_VOID__POINTER,
+                                 g_cclosure_marshal_generic,
                                  G_TYPE_NONE,
                                  1, G_TYPE_STRV);
 
@@ -3140,7 +3333,7 @@ account_manager_prepared_cb (GObject *source_object,
        EmpathyChat *chat = user_data;
        GError *error = NULL;
 
-       if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
+       if (!tp_proxy_prepare_finish (account_manager, result, &error)) {
                DEBUG ("Failed to prepare the account manager: %s", error->message);
                g_error_free (error);
                return;
@@ -3169,12 +3362,13 @@ empathy_chat_init (EmpathyChat *chat)
        priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
        priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
 
-       priv->contacts_width = -1;
+       priv->contacts_width = g_settings_get_int (priv->gsettings_ui,
+               EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
        priv->input_history = NULL;
        priv->input_history_current = NULL;
        priv->account_manager = tp_account_manager_dup ();
 
-       tp_account_manager_prepare_async (priv->account_manager, NULL,
+       tp_proxy_prepare_async (priv->account_manager, NULL,
                                          account_manager_prepared_cb, chat);
 
        priv->show_contacts = g_settings_get_boolean (priv->gsettings_chat,
@@ -3330,7 +3524,7 @@ provide_password_cb (GObject *tp_chat,
        EmpathyChatPriv *priv = GET_PRIV (self);
        GError *error = NULL;
 
-       if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+       if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
                                                      &error)) {
                DEBUG ("error: %s", error->message);
                /* FIXME: what should we do if that's another error? Close the channel?
@@ -3374,6 +3568,7 @@ provide_password_cb (GObject *tp_chat,
 
        /* Room joined */
        gtk_widget_set_sensitive (priv->hpaned, TRUE);
+       gtk_widget_set_sensitive (self->input_text_view, TRUE);
        gtk_widget_grab_focus (self->input_text_view);
 }
 
@@ -3393,7 +3588,7 @@ password_infobar_response_cb (GtkWidget *info_bar,
 
        password = gtk_entry_get_text (GTK_ENTRY (data->entry));
 
-       empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+       tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
                                                provide_password_cb, data);
 
        gtk_widget_set_sensitive (data->button, FALSE);
@@ -3439,7 +3634,7 @@ password_entry_changed_cb (GtkEditable *entry,
 }
 
 static void
-chat_invalidated_cb (TpProxy       *proxy,
+infobar_chat_invalidated_cb (TpProxy       *proxy,
                           guint          domain,
                           gint           code,
                           gchar         *message,
@@ -3533,7 +3728,7 @@ display_password_info_bar (EmpathyChat *self)
        gtk_widget_show_all (hbox);
 
        tp_g_signal_connect_object (priv->tp_chat,
-                                 "invalidated", G_CALLBACK (chat_invalidated_cb),
+                                 "invalidated", G_CALLBACK (infobar_chat_invalidated_cb),
                                  info_bar, 0);
 
        data->response_id = g_signal_connect (info_bar, "response",
@@ -3556,7 +3751,7 @@ provide_saved_password_cb (GObject *tp_chat,
        EmpathyChatPriv *priv = GET_PRIV (self);
        GError *error = NULL;
 
-       if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+       if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
                                                      &error)) {
                DEBUG ("error: %s", error->message);
                /* FIXME: what should we do if that's another error? Close the channel?
@@ -3596,7 +3791,7 @@ chat_room_got_password_cb (GObject *source,
                return;
        }
 
-       empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+       tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
                                                provide_saved_password_cb, self);
 }
 
@@ -3605,7 +3800,7 @@ chat_password_needed_changed_cb (EmpathyChat *self)
 {
        EmpathyChatPriv *priv = GET_PRIV (self);
 
-       if (empathy_tp_chat_password_needed (priv->tp_chat)) {
+       if (tp_channel_password_needed (TP_CHANNEL (priv->tp_chat))) {
                empathy_keyring_get_room_password_async (priv->account,
                                                         empathy_tp_chat_get_id (priv->tp_chat),
                                                         chat_room_got_password_cb, self);
@@ -3617,7 +3812,8 @@ chat_sms_channel_changed_cb (EmpathyChat *self)
 {
        EmpathyChatPriv *priv = GET_PRIV (self);
 
-       priv->sms_channel = empathy_tp_chat_is_sms_channel (priv->tp_chat);
+       priv->sms_channel = tp_text_channel_is_sms_channel (
+               (TpTextChannel *) priv->tp_chat);
        g_object_notify (G_OBJECT (self), "sms-channel");
 }
 
@@ -3648,8 +3844,8 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        priv->tp_chat = g_object_ref (tp_chat);
        priv->account = g_object_ref (empathy_tp_chat_get_account (priv->tp_chat));
 
-       g_signal_connect (tp_chat, "destroy",
-                         G_CALLBACK (chat_destroy_cb),
+       g_signal_connect (tp_chat, "invalidated",
+                         G_CALLBACK (chat_invalidated_cb),
                          chat);
        g_signal_connect (tp_chat, "message-received-empathy",
                          G_CALLBACK (chat_message_received_cb),
@@ -3678,7 +3874,7 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        g_signal_connect_swapped (tp_chat, "notify::password-needed",
                                  G_CALLBACK (chat_password_needed_changed_cb),
                                  chat);
-       g_signal_connect_swapped (tp_chat, "notify::sms-channel",
+       g_signal_connect_swapped (tp_chat, "notify::is-sms-channel",
                                  G_CALLBACK (chat_sms_channel_changed_cb),
                                  chat);
        g_signal_connect_swapped (tp_chat, "notify::n-messages-sending",
@@ -3985,7 +4181,16 @@ empathy_chat_messages_read (EmpathyChat *self)
                return;
 
        if (priv->tp_chat != NULL) {
-               empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
+               tp_text_channel_ack_all_pending_messages_async (
+                       TP_TEXT_CHANNEL (priv->tp_chat), NULL, NULL);
+       }
+
+       if (priv->unread_messages_when_offline > 0) {
+               /* We can't ack those as the connection has gone away so just consider
+               * them as read. */
+               priv->unread_messages -= priv->unread_messages_when_offline;
+               g_object_notify (G_OBJECT (self), "nb-unread-messages");
+               priv->unread_messages_when_offline = 0;
        }
 }