]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
individual-menu: stop creating single_individual
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index 4fd524e64c0d9299fe41f1b9d0a33c91eec5028e..6ff113d2d605e57a9687185d7be25899fa452c7d 100644 (file)
  * Authors: Richard Hult <richard@imendio.com>
  *          Martyn Russell <martyn@imendio.com>
  *          Xavier Claessens <xclaesse@gmail.com>
- *          Davyd Madeley <davyd.madeley@collabora.co.uk>
+ *          Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
 #include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
+#include "empathy-presence-chooser.h"
 
 #include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
+#include <tp-account-widgets/tpaw-utils.h>
 
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-idle.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-status-presets.h>
+#include "empathy-presence-manager.h"
+#include "empathy-status-presets.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #include "empathy-ui-utils.h"
-#include "empathy-images.h"
 #include "empathy-presence-chooser.h"
 #include "empathy-status-preset-dialog.h"
 
@@ -64,9 +58,6 @@
  * Widget which extends #GtkComboBoxEntry to change presence.
  */
 
-/* Flashing delay for icons (milliseconds). */
-#define FLASH_TIMEOUT 500
-
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyPresenceChooser)
 
 /* For custom message dialog */
@@ -79,9 +70,9 @@ enum {
 
 /* For combobox's model */
 enum {
+       COL_STATUS_TEXT,
        COL_STATE_ICON_NAME,
        COL_STATE,
-       COL_STATUS_TEXT,
        COL_DISPLAY_MARKUP,
        COL_STATUS_CUSTOMISABLE,
        COL_TYPE,
@@ -97,7 +88,8 @@ typedef enum  {
 } PresenceChooserEntryType;
 
 typedef struct {
-       EmpathyIdle *idle;
+       EmpathyPresenceManager *presence_mgr;
+       GNetworkMonitor *connectivity;
 
        gboolean     editing_status;
        int          block_set_editing;
@@ -107,9 +99,7 @@ typedef struct {
        TpConnectionPresenceType state;
        PresenceChooserEntryType previous_type;
 
-       TpConnectionPresenceType   flash_state_1;
-       TpConnectionPresenceType   flash_state_2;
-       guint        flash_timeout_id;
+       TpAccountManager *account_manager;
 } EmpathyPresenceChooserPriv;
 
 /* States to be listed in the menu.
@@ -124,14 +114,9 @@ static struct { TpConnectionPresenceType state;
                         { TP_CONNECTION_PRESENCE_TYPE_UNSET, },
                        };
 
+static void            presence_chooser_constructed            (GObject                    *object);
 static void            presence_chooser_finalize               (GObject                    *object);
 static void            presence_chooser_presence_changed_cb    (EmpathyPresenceChooser      *chooser);
-static gboolean        presence_chooser_flash_timeout_cb       (EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_flash_start            (EmpathyPresenceChooser      *chooser,
-                                                               TpConnectionPresenceType                  state_1,
-                                                               TpConnectionPresenceType                  state_2);
-static void            presence_chooser_flash_stop             (EmpathyPresenceChooser      *chooser,
-                                                               TpConnectionPresenceType                  state);
 static void            presence_chooser_menu_add_item          (GtkWidget                  *menu,
                                                                const gchar                *str,
                                                                TpConnectionPresenceType                  state);
@@ -142,13 +127,14 @@ static void            presence_chooser_set_state              (TpConnectionPres
 static void            presence_chooser_custom_activate_cb     (GtkWidget                  *item,
                                                                gpointer                    user_data);
 
-G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
+G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX);
 
 static void
 empathy_presence_chooser_class_init (EmpathyPresenceChooserClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+       object_class->constructed = presence_chooser_constructed;
        object_class->finalize = presence_chooser_finalize;
 
        g_type_class_add_private (object_class, sizeof (EmpathyPresenceChooserPriv));
@@ -162,14 +148,14 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
        int i;
 
        store = gtk_list_store_new (N_COLUMNS,
+                                   G_TYPE_STRING,    /* COL_STATUS_TEXT */
                                    G_TYPE_STRING,    /* COL_STATE_ICON_NAME */
                                    G_TYPE_UINT,      /* COL_STATE */
-                                   G_TYPE_STRING,    /* COL_STATUS_TEXT */
                                    G_TYPE_STRING,    /* COL_DISPLAY_MARKUP */
                                    G_TYPE_BOOLEAN,   /* COL_STATUS_CUSTOMISABLE */
                                    G_TYPE_INT);      /* COL_TYPE */
 
-       custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message..."));
+       custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message"));
 
        for (i = 0; states[i].state != TP_CONNECTION_PRESENCE_TYPE_UNSET; i++) {
                GList       *list, *l;
@@ -179,9 +165,9 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                icon_name = empathy_icon_name_for_presence (states[i].state);
 
                gtk_list_store_insert_with_values (store, NULL, -1,
+                       COL_STATUS_TEXT, status,
                        COL_STATE_ICON_NAME, icon_name,
                        COL_STATE, states[i].state,
-                       COL_STATUS_TEXT, status,
                        COL_DISPLAY_MARKUP, status,
                        COL_STATUS_CUSTOMISABLE, states[i].customisable,
                        COL_TYPE, ENTRY_TYPE_BUILTIN,
@@ -194,9 +180,9 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                        for (l = list; l; l = l->next) {
                                gtk_list_store_insert_with_values (store,
                                        NULL, -1,
-                                       COL_STATE_ICON_NAME, icon_name,
-                                       COL_STATE, states[i],
                                        COL_STATUS_TEXT, l->data,
+                                       COL_STATE_ICON_NAME, icon_name,
+                                       COL_STATE, states[i].state,
                                        COL_DISPLAY_MARKUP, l->data,
                                        COL_STATUS_CUSTOMISABLE, TRUE,
                                        COL_TYPE, ENTRY_TYPE_SAVED,
@@ -205,9 +191,9 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                        g_list_free (list);
 
                        gtk_list_store_insert_with_values (store, NULL, -1,
+                               COL_STATUS_TEXT, _("Custom Message…"),
                                COL_STATE_ICON_NAME, icon_name,
-                               COL_STATE, states[i],
-                               COL_STATUS_TEXT, "",
+                               COL_STATE, states[i].state,
                                COL_DISPLAY_MARKUP, custom_message,
                                COL_STATUS_CUSTOMISABLE, TRUE,
                                COL_TYPE, ENTRY_TYPE_CUSTOM,
@@ -222,9 +208,9 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                        -1);
 
        gtk_list_store_insert_with_values (store, NULL, -1,
+               COL_STATUS_TEXT, _("Edit Custom Messages…"),
                COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
-               COL_STATUS_TEXT, "",
-               COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
+               COL_DISPLAY_MARKUP, _("Edit Custom Messages…"),
                COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
                -1);
 
@@ -277,23 +263,45 @@ presence_chooser_get_entry_type (EmpathyPresenceChooser *self)
        return type;
 }
 
+static TpConnectionPresenceType
+get_state_and_status (EmpathyPresenceChooser *self,
+       gchar **status)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+       TpConnectionPresenceType state;
+       gchar *tmp;
+
+       state = tp_account_manager_get_most_available_presence (
+               priv->account_manager, NULL, &tmp);
+       if (TPAW_STR_EMPTY (tmp)) {
+               /* no message, use the default message */
+               g_free (tmp);
+               tmp = g_strdup (empathy_presence_get_default_message (state));
+       }
+
+       if (status != NULL)
+               *status = tmp;
+       else
+               g_free (tmp);
+
+       return state;
+}
+
 static gboolean
 presence_chooser_is_preset (EmpathyPresenceChooser *self)
 {
-       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
        TpConnectionPresenceType state;
-       const char *status;
+       char *status;
        GList *presets, *l;
        gboolean match = FALSE;
 
-       state = empathy_idle_get_state (priv->idle);
-       status = empathy_idle_get_status (priv->idle);
+       state = get_state_and_status (self, &status);
 
        presets = empathy_status_presets_get (state, -1);
        for (l = presets; l; l = l->next) {
                char *preset = (char *) l->data;
 
-               if (!strcmp (status, preset)) {
+               if (!tp_strdiff (status, preset)) {
                        match = TRUE;
                        break;
                }
@@ -301,8 +309,9 @@ presence_chooser_is_preset (EmpathyPresenceChooser *self)
 
        g_list_free (presets);
 
-       DEBUG ("is_preset(%i, %s) = %i\n", state, status, match);
+       DEBUG ("is_preset(%i, %s) = %i", state, status, match);
 
+       g_free (status);
        return match;
 }
 
@@ -320,7 +329,7 @@ presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
                        /* saved entries can be removed from the list */
                        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
                                           GTK_ENTRY_ICON_SECONDARY,
-                                          "empathy-starred");
+                                          "starred-symbolic");
                        gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
                                         GTK_ENTRY_ICON_SECONDARY,
                                         _("Click to remove this status as a favorite"));
@@ -329,7 +338,7 @@ presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
                        /* custom entries can be favorited */
                        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
                                           GTK_ENTRY_ICON_SECONDARY,
-                                          "empathy-unstarred");
+                                          "non-starred-symbolic");
                        gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
                                         GTK_ENTRY_ICON_SECONDARY,
                                         _("Click to make this status a favorite"));
@@ -359,8 +368,17 @@ presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
 
        entry = gtk_bin_get_child (GTK_BIN (self));
        if (editing) {
+               gchar *tooltip_text;
+               gchar *status;
+
                priv->editing_status = TRUE;
 
+               get_state_and_status (self, &status);
+               /* Translators: %s is a status message like 'At the pub' for example */
+               tooltip_text = g_strdup_printf (_("<b>Current message: %s</b>\n"
+                       "<small><i>Press Enter to set the new message or Esc to cancel.</i></small>"),
+                   status);
+               gtk_widget_set_tooltip_markup (entry, tooltip_text);
                gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
                                               GTK_ENTRY_ICON_SECONDARY,
                                               GTK_STOCK_OK);
@@ -370,6 +388,8 @@ presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
                gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
                                              GTK_ENTRY_ICON_PRIMARY,
                                              FALSE);
+               g_free (status);
+               g_free (tooltip_text);
        } else {
                GtkWidget *window;
 
@@ -380,7 +400,7 @@ presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
 
                /* attempt to get the toplevel for this widget */
                window = gtk_widget_get_toplevel (GTK_WIDGET (self));
-               if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window)) {
+               if (gtk_widget_is_toplevel (window) && GTK_IS_WINDOW (window)) {
                        /* unset the focus */
                        gtk_window_set_focus (GTK_WINDOW (window), NULL);
                }
@@ -409,9 +429,9 @@ mc_set_custom_state (EmpathyPresenceChooser *self)
        /* update the status with MC */
        status = gtk_entry_get_text (GTK_ENTRY (entry));
 
-       DEBUG ("Sending state to MC-> %d (%s)\n", priv->state, status);
+       DEBUG ("Sending state to MC-> %d (%s)", priv->state, status);
 
-       empathy_idle_set_presence (priv->idle, priv->state, status);
+       empathy_presence_manager_set_presence (priv->presence_mgr, priv->state, status);
 }
 
 static void
@@ -422,6 +442,7 @@ ui_set_custom_state (EmpathyPresenceChooser *self,
        EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
        GtkWidget *entry;
        const char *icon_name;
+       const gchar *status_tooltip;
 
        entry = gtk_bin_get_child (GTK_BIN (self));
 
@@ -432,7 +453,9 @@ ui_set_custom_state (EmpathyPresenceChooser *self,
        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
                                           GTK_ENTRY_ICON_PRIMARY,
                                           icon_name);
-       gtk_entry_set_text (GTK_ENTRY (entry), status);
+       status_tooltip = status == NULL ? "" : status;
+       gtk_entry_set_text (GTK_ENTRY (entry), status_tooltip);
+       gtk_widget_set_tooltip_text (GTK_WIDGET (entry), status_tooltip);
        presence_chooser_set_favorite_icon (self);
 
        priv->block_changed--;
@@ -460,27 +483,31 @@ presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
                mc_set_custom_state (self);
        }
        else {
-               PresenceChooserEntryType type;
                TpConnectionPresenceType state;
-               const char *status;
+               char *status;
 
-               type = presence_chooser_get_entry_type (self);
-               state = empathy_idle_get_state (priv->idle);
-               status = empathy_idle_get_status (priv->idle);
+               state = get_state_and_status (self, &status);
+
+               if (!empathy_status_presets_is_valid (state)) {
+                       /* It doesn't make sense to add such presence as favorite */
+                       g_free (status);
+                       return;
+               }
 
                if (presence_chooser_is_preset (self)) {
                        /* remove the entry */
-                       DEBUG ("REMOVING PRESET (%i, %s)\n", state, status);
+                       DEBUG ("REMOVING PRESET (%i, %s)", state, status);
                        empathy_status_presets_remove (state, status);
                }
                else {
                        /* save the entry */
-                       DEBUG ("SAVING PRESET (%i, %s)\n", state, status);
+                       DEBUG ("SAVING PRESET (%i, %s)", state, status);
                        empathy_status_presets_set_last (state, status);
                }
 
                /* update the icon */
                presence_chooser_set_favorite_icon (self);
+               g_free (status);
        }
 }
 
@@ -499,12 +526,12 @@ presence_chooser_entry_key_press_event_cb (EmpathyPresenceChooser *self,
 {
        EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
 
-       if (priv->editing_status && event->keyval == GDK_Escape) {
+       if (priv->editing_status && event->keyval == GDK_KEY_Escape) {
                /* the user pressed Escape, undo the editing */
                presence_chooser_reset_status (self);
                return TRUE;
        }
-       else if (event->keyval == GDK_Up || event->keyval == GDK_Down) {
+       else if (event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down) {
                /* ignore */
                return TRUE;
        }
@@ -521,7 +548,7 @@ presence_chooser_entry_button_press_event_cb (EmpathyPresenceChooser *self,
 
        if (!priv->editing_status &&
            event->button == 1 &&
-           !GTK_WIDGET_HAS_FOCUS (entry)) {
+           !gtk_widget_has_focus (entry)) {
                gtk_widget_grab_focus (entry);
                gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
 
@@ -589,7 +616,7 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
 
                /* attempt to get the toplevel for this widget */
                window = gtk_widget_get_toplevel (GTK_WIDGET (self));
-               if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window)) {
+               if (!gtk_widget_is_toplevel (window) || !GTK_IS_WINDOW (window)) {
                        window = NULL;
                }
 
@@ -610,10 +637,12 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
                } else {
                        /* else preseed the text of their currently entered
                         * status message */
-                       const char *status;
+                       char *status;
 
-                       status = empathy_idle_get_status (priv->idle);
+                       get_state_and_status (EMPATHY_PRESENCE_CHOOSER (self),
+                               &status);
                        gtk_entry_set_text (GTK_ENTRY (entry), status);
+                       g_free (status);
                }
 
                /* grab the focus */
@@ -634,7 +663,7 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
                                    COL_STATUS_TEXT, &status,
                                    -1);
 
-               empathy_idle_set_presence (priv->idle, priv->state, status);
+               empathy_presence_manager_set_presence (priv->presence_mgr, priv->state, status);
 
                g_free (status);
        }
@@ -665,7 +694,7 @@ presence_chooser_entry_focus_out_idle_cb (gpointer user_data)
        EmpathyPresenceChooser *chooser;
        GtkWidget *entry;
 
-       DEBUG ("Autocommiting status message\n");
+       DEBUG ("Autocommiting status message");
 
        chooser = EMPATHY_PRESENCE_CHOOSER (user_data);
        entry = gtk_bin_get_child (GTK_BIN (chooser));
@@ -705,19 +734,103 @@ presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser,
        return FALSE;
 }
 
+static void
+update_sensitivity_am_prepared_cb (GObject *source_object,
+                                  GAsyncResult *result,
+                                  gpointer user_data)
+{
+       TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
+       EmpathyPresenceChooser *chooser = user_data;
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
+       gboolean sensitive = FALSE;
+       GList *accounts, *l;
+       GError *error = NULL;
+
+       if (!tp_proxy_prepare_finish (manager, result, &error)) {
+               DEBUG ("Failed to prepare account manager: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+       accounts = tp_account_manager_dup_valid_accounts (manager);
+
+       for (l = accounts ; l != NULL ; l = g_list_next (l)) {
+               TpAccount *a = TP_ACCOUNT (l->data);
+
+               if (tp_account_is_enabled (a)) {
+                       sensitive = TRUE;
+                       break;
+               }
+       }
+
+       g_list_free_full (accounts, g_object_unref);
+
+       if (!g_network_monitor_get_network_available (priv->connectivity))
+               sensitive = FALSE;
+
+       gtk_widget_set_sensitive (GTK_WIDGET (chooser), sensitive);
+
+       presence_chooser_presence_changed_cb (chooser);
+}
+
+static void
+presence_chooser_update_sensitivity (EmpathyPresenceChooser *chooser)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
+
+       tp_proxy_prepare_async (priv->account_manager, NULL,
+                                         update_sensitivity_am_prepared_cb,
+                                         chooser);
+}
+
+static void
+presence_chooser_account_manager_account_validity_changed_cb (
+       TpAccountManager *manager,
+       TpAccount *account,
+       gboolean valid,
+       EmpathyPresenceChooser *chooser)
+{
+       presence_chooser_update_sensitivity (chooser);
+}
+
+static void
+presence_chooser_account_manager_account_changed_cb (
+       TpAccountManager *manager,
+       TpAccount *account,
+       EmpathyPresenceChooser *chooser)
+{
+       presence_chooser_update_sensitivity (chooser);
+}
+
+static void
+presence_chooser_network_change (GNetworkMonitor *connectivity,
+                                           gboolean new_online,
+                                           EmpathyPresenceChooser *chooser)
+{
+       presence_chooser_update_sensitivity (chooser);
+}
+
 static void
 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
 {
        EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
                EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
-       GtkWidget *entry;
-       GtkCellRenderer *renderer;
 
        chooser->priv = priv;
+}
+
+static void
+presence_chooser_constructed (GObject *object)
+{
+       EmpathyPresenceChooser *chooser = EMPATHY_PRESENCE_CHOOSER (object);
+       EmpathyPresenceChooserPriv *priv = chooser->priv;
+       GtkWidget *entry;
+       GtkCellRenderer *renderer;
+       const gchar *status_tooltip;
 
        presence_chooser_create_model (chooser);
 
-       gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
+       gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (chooser),
                                             COL_STATUS_TEXT);
        gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
                                              combo_row_separator_func,
@@ -755,6 +868,7 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (chooser), renderer,
                                        "markup", COL_DISPLAY_MARKUP,
                                        NULL);
+       g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
 
        g_signal_connect (chooser, "notify::popup-shown",
                        G_CALLBACK (presence_chooser_popup_shown_cb), NULL);
@@ -767,15 +881,39 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
                        G_CALLBACK (presence_chooser_entry_focus_out_cb),
                        chooser);
 
-       priv->idle = empathy_idle_dup_singleton ();
-       presence_chooser_presence_changed_cb (chooser);
-       g_signal_connect_swapped (priv->idle, "notify",
+       priv->presence_mgr = empathy_presence_manager_dup_singleton ();
+
+       priv->account_manager = tp_account_manager_dup ();
+       g_signal_connect_swapped (priv->account_manager,
+               "most-available-presence-changed",
                G_CALLBACK (presence_chooser_presence_changed_cb),
                chooser);
 
-       /* FIXME: this string sucks */
-       gtk_widget_set_tooltip_text (GTK_WIDGET (chooser),
-               _("Set your presence and current status"));
+       tp_g_signal_connect_object (priv->account_manager, "account-validity-changed",
+               G_CALLBACK (presence_chooser_account_manager_account_validity_changed_cb),
+               chooser, 0);
+       tp_g_signal_connect_object (priv->account_manager, "account-removed",
+               G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
+               chooser, 0);
+       tp_g_signal_connect_object (priv->account_manager, "account-enabled",
+               G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
+               chooser, 0);
+       tp_g_signal_connect_object (priv->account_manager, "account-disabled",
+               G_CALLBACK (presence_chooser_account_manager_account_changed_cb),
+               chooser, 0);
+
+       status_tooltip = gtk_entry_get_text (GTK_ENTRY (entry));
+       gtk_widget_set_tooltip_text (GTK_WIDGET (chooser), status_tooltip);
+
+       priv->connectivity = g_network_monitor_get_default ();
+       g_object_ref (priv->connectivity);
+
+       tp_g_signal_connect_object (priv->connectivity,
+               "network-changed",
+               G_CALLBACK (presence_chooser_network_change),
+               chooser, 0);
+
+       presence_chooser_update_sensitivity (chooser);
 }
 
 static void
@@ -785,18 +923,19 @@ presence_chooser_finalize (GObject *object)
 
        priv = GET_PRIV (object);
 
-       if (priv->flash_timeout_id) {
-               g_source_remove (priv->flash_timeout_id);
-       }
-
        if (priv->focus_out_idle_source) {
                g_source_remove (priv->focus_out_idle_source);
        }
 
-       g_signal_handlers_disconnect_by_func (priv->idle,
+       if (priv->account_manager != NULL)
+               g_object_unref (priv->account_manager);
+
+       g_signal_handlers_disconnect_by_func (priv->presence_mgr,
                                              presence_chooser_presence_changed_cb,
                                              object);
-       g_object_unref (priv->idle);
+       g_object_unref (priv->presence_mgr);
+
+       g_object_unref (priv->connectivity);
 
        G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
 }
@@ -811,11 +950,10 @@ presence_chooser_finalize (GObject *object)
 GtkWidget *
 empathy_presence_chooser_new (void)
 {
-       GtkWidget *chooser;
-
-       chooser = g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER, NULL);
-
-       return chooser;
+       /* FIXME, why can't this go in init ()? */
+       return g_object_new (EMPATHY_TYPE_PRESENCE_CHOOSER,
+               "has-entry", TRUE,
+               NULL);
 }
 
 static void
@@ -823,11 +961,11 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
 {
        EmpathyPresenceChooserPriv *priv;
        TpConnectionPresenceType    state;
-       TpConnectionPresenceType    flash_state;
-       const gchar                *status;
+       gchar                      *status;
        GtkTreeModel               *model;
        GtkTreeIter                 iter;
        gboolean valid, match_state = FALSE, match = FALSE;
+       GtkWidget                  *entry;
 
        priv = GET_PRIV (chooser);
 
@@ -835,9 +973,14 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                return;
        }
 
-       priv->state = state = empathy_idle_get_state (priv->idle);
-       status = empathy_idle_get_status (priv->idle);
-       flash_state = empathy_idle_get_flash_state (priv->idle);
+       state = get_state_and_status (chooser, &status);
+       priv->state = state;
+
+       /* An unset presence here doesn't make any sense. Force it to appear as
+        * offline. */
+       if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+               state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
+       }
 
        /* look through the model and attempt to find a matching state */
        model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
@@ -873,7 +1016,7 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                                COL_STATUS_TEXT, &m_status,
                                -1);
 
-               match = !strcmp (status, m_status);
+               match = !tp_strdiff (status, m_status);
 
                g_free (m_status);
 
@@ -891,78 +1034,17 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                ui_set_custom_state (chooser, state, status);
        }
 
-       if (flash_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
-               presence_chooser_flash_start (chooser, state, flash_state);
-       }
-       else {
-               presence_chooser_flash_stop (chooser, state);
-       }
-}
-
-static gboolean
-presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
-{
-       EmpathyPresenceChooserPriv *priv;
-       TpConnectionPresenceType    state;
-       static gboolean             on = FALSE;
-       GtkWidget                  *entry;
-
-       priv = GET_PRIV (chooser);
-
-       if (on) {
-               state = priv->flash_state_1;
-       }
-       else {
-               state = priv->flash_state_2;
-       }
-
        entry = gtk_bin_get_child (GTK_BIN (chooser));
        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
-                                          GTK_ENTRY_ICON_PRIMARY,
-                                          empathy_icon_name_for_presence (state));
-
-       on = !on;
-
-       return TRUE;
-}
-
-static void
-presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
-                             TpConnectionPresenceType state_1,
-                             TpConnectionPresenceType state_2)
-{
-       EmpathyPresenceChooserPriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
-
-       priv = GET_PRIV (chooser);
-
-       priv->flash_state_1 = state_1;
-       priv->flash_state_2 = state_2;
-
-       if (!priv->flash_timeout_id) {
-               priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT,
-                       (GSourceFunc) presence_chooser_flash_timeout_cb,
-                       chooser);
-       }
-}
-
-static void
-presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
-                            TpConnectionPresenceType state)
-{
-       EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
-       GtkWidget *entry;
-
-       if (priv->flash_timeout_id) {
-               g_source_remove (priv->flash_timeout_id);
-               priv->flash_timeout_id = 0;
-       }
+             GTK_ENTRY_ICON_PRIMARY,
+             empathy_icon_name_for_presence (state));
+       gtk_widget_set_tooltip_text (GTK_WIDGET (entry), status);
 
        entry = gtk_bin_get_child (GTK_BIN (chooser));
-       gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
-                                          GTK_ENTRY_ICON_PRIMARY,
-                                          empathy_icon_name_for_presence (state));
+       gtk_editable_set_editable (GTK_EDITABLE (entry),
+           state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+
+       g_free (status);
 }
 
 /**
@@ -1010,7 +1092,7 @@ empathy_presence_chooser_create_menu (void)
        gtk_widget_show (item);
 
        /* Custom messages */
-       item = gtk_image_menu_item_new_with_label (_("Custom messages..."));
+       item = gtk_image_menu_item_new_with_label (_("Custom messages"));
        image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
@@ -1045,6 +1127,7 @@ presence_chooser_menu_add_item (GtkWidget   *menu,
        gtk_widget_show (image);
 
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
        gtk_widget_show (item);
 
        g_object_set_data_full (G_OBJECT (item),
@@ -1073,11 +1156,11 @@ static void
 presence_chooser_set_state (TpConnectionPresenceType state,
                            const gchar *status)
 {
-       EmpathyIdle *idle;
+       EmpathyPresenceManager *presence_mgr;
 
-       idle = empathy_idle_dup_singleton ();
-       empathy_idle_set_presence (idle, state, status);
-       g_object_unref (idle);
+       presence_mgr = empathy_presence_manager_dup_singleton ();
+       empathy_presence_manager_set_presence (presence_mgr, state, status);
+       g_object_unref (presence_mgr);
 }
 
 static void