]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
Editing mode on click
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index b0f3f8e511546214b203ee732a79f1aeaf6ccd49..74eefee2ab70061fecad059a493fbbff24cfb8ae 100644 (file)
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2005-2007 Imendio AB
+ * Copyright (C) 2009 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -20,6 +21,7 @@
  * Authors: Richard Hult <richard@imendio.com>
  *          Martyn Russell <martyn@imendio.com>
  *          Xavier Claessens <xclaesse@gmail.com>
+ *          Davyd Madeley <davyd.madeley@collabora.co.uk>
  */
 
 #include "config.h"
@@ -30,6 +32,7 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 #include <glade/glade.h>
+#include <gdk/gdkkeysyms.h>
 
 #include <telepathy-glib/util.h>
 #include <libmissioncontrol/mc-enum-types.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-status-presets.h>
 
+// FIXME - what's the correct debug flag?
+#define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
+#include <libempathy/empathy-debug.h>
+
 #include "empathy-ui-utils.h"
 #include "empathy-images.h"
 #include "empathy-presence-chooser.h"
 typedef struct {
        EmpathyIdle *idle;
 
-       GtkWidget   *hbox;
-       GtkWidget   *image;
-       GtkWidget   *label;
-       GtkWidget   *menu;
+       gboolean     editing_status;
+       int          block_set_editing;
+       int          block_changed;
 
-       McPresence   last_state;
+       McPresence   state;
+       int          previous_type;
 
        McPresence   flash_state_1;
        McPresence   flash_state_2;
        guint        flash_timeout_id;
-
-       /* The handle the kind of unnessecary scroll support. */
-       guint        scroll_timeout_id;
-       McPresence   scroll_state;
-       gchar       *scroll_status;
 } EmpathyPresenceChooserPriv;
 
 typedef struct {
@@ -82,11 +84,6 @@ enum {
        COL_COUNT
 };
 
-typedef struct {
-       McPresence   state;
-       const gchar *status;
-} StateAndStatus;
-
 static CustomMessageDialog *message_dialog = NULL;
 /* States to be listed in the menu.
  * Each state has a boolean telling if it can have custom message */
@@ -98,38 +95,12 @@ static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
 
 static void            presence_chooser_finalize               (GObject                    *object);
 static void            presence_chooser_presence_changed_cb    (EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_reset_scroll_timeout   (EmpathyPresenceChooser      *chooser);
-static gboolean        presence_chooser_scroll_timeout_cb      (EmpathyPresenceChooser      *chooser);
-static gboolean        presence_chooser_scroll_event_cb        (EmpathyPresenceChooser      *chooser,
-                                                               GdkEventScroll             *event,
-                                                               gpointer                    user_data);
-static GList *         presence_chooser_get_presets            (EmpathyPresenceChooser      *chooser);
-static StateAndStatus *presence_chooser_state_and_status_new   (McPresence                  state,
-                                                               const gchar                *status);
 static gboolean        presence_chooser_flash_timeout_cb       (EmpathyPresenceChooser      *chooser);
 static void            presence_chooser_flash_start            (EmpathyPresenceChooser      *chooser,
                                                                McPresence                  state_1,
                                                                McPresence                  state_2);
 static void            presence_chooser_flash_stop             (EmpathyPresenceChooser      *chooser,
                                                                McPresence                  state);
-static gboolean        presence_chooser_button_press_event_cb  (GtkWidget                  *chooser,
-                                                               GdkEventButton             *event,
-                                                               gpointer                    user_data);
-static void            presence_chooser_toggled_cb             (GtkWidget                  *chooser,
-                                                               gpointer                    user_data);
-static void            presence_chooser_menu_popup             (EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_menu_popdown           (EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_menu_selection_done_cb (GtkMenuShell               *menushell,
-                                                               EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_menu_destroy_cb        (GtkWidget                  *menu,
-                                                               EmpathyPresenceChooser      *chooser);
-static void            presence_chooser_menu_detach            (GtkWidget                  *attach_widget,
-                                                               GtkMenu                    *menu);
-static void            presence_chooser_menu_align_func        (GtkMenu                    *menu,
-                                                               gint                       *x,
-                                                               gint                       *y,
-                                                               gboolean                   *push_in,
-                                                               GtkWidget                  *widget);
 static void            presence_chooser_menu_add_item          (GtkWidget                  *menu,
                                                                const gchar                *str,
                                                                McPresence                  state);
@@ -139,7 +110,7 @@ static void            presence_chooser_set_state              (McPresence
                                                                const gchar                *status);
 static void            presence_chooser_custom_activate_cb     (GtkWidget                  *item,
                                                                gpointer                    user_data);
-static void            presence_chooser_dialog_show            (void);
+static void            presence_chooser_dialog_show            (GtkWindow                  *parent);
 
 G_DEFINE_TYPE (EmpathyPresenceChooser, empathy_presence_chooser, GTK_TYPE_COMBO_BOX_ENTRY);
 
@@ -159,6 +130,7 @@ enum
        COL_STATE,
        COL_STATUS_TEXT,
        COL_DISPLAY_MARKUP,
+       COL_STATUS_CUSTOMISABLE,
        COL_TYPE,
        N_COLUMNS
 };
@@ -168,6 +140,8 @@ enum
        ENTRY_TYPE_BUILTIN,
        ENTRY_TYPE_SAVED,
        ENTRY_TYPE_CUSTOM,
+       ENTRY_TYPE_SEPARATOR,
+       ENTRY_TYPE_EDIT_CUSTOM,
 };
 
 static GtkTreeModel *
@@ -178,6 +152,7 @@ create_model (void)
                        MC_TYPE_PRESENCE,       /* 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 */
        
        GtkTreeIter iter;
@@ -195,6 +170,7 @@ create_model (void)
                                COL_STATE, states[i],
                                COL_STATUS_TEXT, status,
                                COL_DISPLAY_MARKUP, status,
+                               COL_STATUS_CUSTOMISABLE, states[i+1],
                                COL_TYPE, ENTRY_TYPE_BUILTIN,
                                -1);
 
@@ -208,6 +184,7 @@ create_model (void)
                                                COL_STATE, states[i],
                                                COL_STATUS_TEXT, l->data,
                                                COL_DISPLAY_MARKUP, l->data,
+                                               COL_STATUS_CUSTOMISABLE, TRUE,
                                                COL_TYPE, ENTRY_TYPE_SAVED,
                                                -1);
                        }
@@ -219,11 +196,26 @@ create_model (void)
                                        COL_STATE, states[i],
                                        COL_STATUS_TEXT, "",
                                        COL_DISPLAY_MARKUP, "<i>Custom Message...</i>",
+                                       COL_STATUS_CUSTOMISABLE, TRUE,
                                        COL_TYPE, ENTRY_TYPE_CUSTOM,
                                        -1);
                }
 
        }
+       
+       /* add a separator */
+       gtk_list_store_append (store, &iter);
+       gtk_list_store_set (store, &iter,
+                       COL_TYPE, ENTRY_TYPE_SEPARATOR,
+                       -1);
+       
+       gtk_list_store_append (store, &iter);
+       gtk_list_store_set (store, &iter,
+                       COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
+                       COL_STATUS_TEXT, "",
+                       COL_DISPLAY_MARKUP, "Edit Custom Messages...",
+                       COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
+                       -1);
 
        return GTK_TREE_MODEL (store);
 }
@@ -236,8 +228,6 @@ popup_shown_cb (GObject *self, GParamSpec *pspec, gpointer user_data)
 
        if (!shown) return;
 
-       g_print ("popup shown\n");
-
        GtkTreeModel *model = create_model ();
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (self), GTK_TREE_MODEL (model));
@@ -248,17 +238,20 @@ popup_shown_cb (GObject *self, GParamSpec *pspec, gpointer user_data)
 static void
 set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
 {
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
        GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
 
+       if (priv->block_set_editing) return;
+
        if (editing)
        {
+               priv->editing_status = TRUE;
                gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_SECONDARY,
                                GTK_STOCK_OK);
                gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_SECONDARY,
-                               "Set status");
-               // FIXME - is this nice?
+                               _("Set status"));
                gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_PRIMARY,
                                FALSE);
@@ -271,15 +264,67 @@ set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
                gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_SECONDARY,
                                NULL);
-               // FIXME - also this
                gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_PRIMARY,
                                TRUE);
 
-               // FIXME - move the focus somewhere
+               /* attempt to get the toplevel for this widget */
+               GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
+               if (GTK_WIDGET_TOPLEVEL (window) && GTK_IS_WINDOW (window))
+               {
+                       /* unset the focus */
+                       gtk_window_set_focus (GTK_WINDOW (window), NULL);
+               }
+               gtk_editable_set_position (GTK_EDITABLE (entry), 0);
+
+               priv->editing_status = FALSE;
        }
 }
 
+static void
+mc_set_custom_state (EmpathyPresenceChooser *self)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+       GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+
+       /* update the status with MC */
+       const char *status = gtk_entry_get_text (GTK_ENTRY (entry));
+       DEBUG ("Sending state to MC-> %s (%s)\n",
+                       g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
+                               priv->state)->value_name,
+                       status);
+       empathy_idle_set_presence (priv->idle, priv->state, status);
+}
+
+static void
+ui_set_custom_state (EmpathyPresenceChooser *self,
+                          McPresence state,
+                          const char *status)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+       GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
+       const char *icon_name;
+
+       priv->block_set_editing++;
+       priv->block_changed++;
+
+       icon_name = empathy_icon_name_for_presence (state);
+       gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+                       GTK_ENTRY_ICON_PRIMARY,
+                       icon_name);
+       gtk_entry_set_text (GTK_ENTRY (entry), status);
+
+       priv->block_changed--;
+       priv->block_set_editing--;
+}
+
+static void
+reset_status (EmpathyPresenceChooser *self)
+{
+       /* recover the status that was unset */
+       presence_chooser_presence_changed_cb (self);
+}
+
 static void
 entry_icon_release_cb (EmpathyPresenceChooser  *self,
                       GtkEntryIconPosition      icon_pos,
@@ -287,75 +332,205 @@ entry_icon_release_cb (EmpathyPresenceChooser    *self,
                       GtkEntry         *entry)
 {
        set_status_editing (self, FALSE);
+       mc_set_custom_state (self);
 }
 
 static void
 entry_activate_cb (EmpathyPresenceChooser      *self,
                   GtkEntry                     *entry)
 {
-       g_print ("ACTIVATE! (form of a dragon)\n");
-       
        set_status_editing (self, FALSE);
+       mc_set_custom_state (self);
+}
+
+static gboolean
+entry_key_press_event_cb (EmpathyPresenceChooser       *self,
+                         GdkEventKey                   *event,
+                         GtkWidget                     *entry)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+       if (priv->editing_status && event->keyval == GDK_Escape)
+       {
+               /* the user pressed Escape, undo the editing */
+               set_status_editing (self, FALSE);
+               reset_status (self);
+
+               return TRUE;
+       }
+
+       return FALSE; /* send this event elsewhere */
+}
+
+static gboolean
+entry_button_press_event_cb (EmpathyPresenceChooser *self,
+                             GdkEventButton         *event,
+                            GtkWidget              *entry)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+       if (!priv->editing_status && event->button == 1)
+       {
+               set_status_editing (self, TRUE);
+               gtk_widget_grab_focus (entry);
+               gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static void
+text_changed_cb (EmpathyPresenceChooser *self, gpointer user_data)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+       if (priv->block_changed) return;
+
+       /* the combo is being edited to a custom entry */
+       if (!priv->editing_status)
+       {
+               set_status_editing (self, TRUE);
+       }
 }
 
 static void
 changed_cb (GtkComboBox *self, gpointer user_data)
 {
-       g_print ("Changed\n");
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+       if (priv->block_changed) return;
 
        GtkTreeIter iter;
        char *icon_name;
+       McPresence new_state;
+       gboolean customisable = TRUE;
        int type = -1;
 
        GtkTreeModel *model = gtk_combo_box_get_model (self);
        if (!gtk_combo_box_get_active_iter (self, &iter))
        {
-               /* the combo is being edited to a custom entry */
-               set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
                return;
        }
 
        gtk_tree_model_get (model, &iter,
                        COL_STATE_ICON_NAME, &icon_name,
+                       COL_STATE, &new_state,
+                       COL_STATUS_CUSTOMISABLE, &customisable,
                        COL_TYPE, &type,
                        -1);
 
        GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
-       gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
-                       GTK_ENTRY_ICON_PRIMARY,
-                       icon_name);
 
-       if (type == ENTRY_TYPE_CUSTOM)
+       /* some types of status aren't editable, set the editability of the
+        * entry appropriately. Unless we're just about to reset it anyway,
+        * in which case, don't fiddle with it */
+       if (type != ENTRY_TYPE_EDIT_CUSTOM)
+       {
+               gtk_editable_set_editable (GTK_EDITABLE (entry), customisable);
+               priv->state = new_state;
+       }
+
+       if (type == ENTRY_TYPE_EDIT_CUSTOM)
        {
+               reset_status (EMPATHY_PRESENCE_CHOOSER (self));
+
+               /* attempt to get the toplevel for this widget */
+               GtkWidget *window = gtk_widget_get_toplevel (GTK_WIDGET (self));
+               if (!GTK_WIDGET_TOPLEVEL (window) || !GTK_IS_WINDOW (window))
+               {
+                       window = NULL;
+               }
+
+               presence_chooser_dialog_show (GTK_WINDOW (window));
+       }
+       else if (type == ENTRY_TYPE_CUSTOM)
+       {
+               gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+                               GTK_ENTRY_ICON_PRIMARY,
+                               icon_name);
+
+               /* preseed the status */
+               if (priv->previous_type == ENTRY_TYPE_BUILTIN)
+               {
+                       gtk_entry_set_text (GTK_ENTRY (entry), "");
+               }
+               else
+               {
+                       const char *status = empathy_idle_get_status (priv->idle);
+                       gtk_entry_set_text (GTK_ENTRY (entry), status);
+               }
+
                /* grab the focus */
                gtk_widget_grab_focus (entry);
-               set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
        }
        else
        {
+               char *status;
                /* just in case we were setting a new status when
                 * things were changed */
                set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), FALSE);
+
+               gtk_tree_model_get (model, &iter,
+                               COL_STATUS_TEXT, &status,
+                               -1);
+
+               empathy_idle_set_presence (priv->idle, priv->state, status);
+
+               g_free (status);
        }
 
+       if (type != ENTRY_TYPE_EDIT_CUSTOM)
+       {
+               priv->previous_type = type;
+       }
        g_free (icon_name);
 }
 
+static gboolean
+combo_row_separator_func (GtkTreeModel *model,
+                         GtkTreeIter   *iter,
+                         gpointer       data)
+{
+       int type;
+       gtk_tree_model_get (model, iter,
+                       COL_TYPE, &type,
+                       -1);
+
+       return (type == ENTRY_TYPE_SEPARATOR);
+}
+
+static gboolean
+focus_out_cb (EmpathyPresenceChooser *chooser, GdkEventFocus *event,
+              GtkEntry *entry)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
+
+       if (priv->editing_status)
+       {
+               // entry_activate_cb (chooser, entry);
+       }
+
+       return FALSE;
+}
+
 static void
 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
 {
-       //GtkWidget                  *arrow;
-       //GtkWidget                  *alignment;
        EmpathyPresenceChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
                EMPATHY_TYPE_PRESENCE_CHOOSER, EmpathyPresenceChooserPriv);
 
-
        chooser->priv = priv;
        
        GtkTreeModel *model = create_model ();
 
        gtk_combo_box_set_model (GTK_COMBO_BOX (chooser), GTK_TREE_MODEL (model));
-       gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser), COL_STATUS_TEXT);
+       gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (chooser),
+                       COL_STATUS_TEXT);
+       gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (chooser),
+                       combo_row_separator_func,
+                       NULL, NULL);
        
        GtkWidget *entry = gtk_bin_get_child (GTK_BIN (chooser));
        gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
@@ -366,6 +541,12 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
        g_signal_connect_object (entry, "activate",
                        G_CALLBACK (entry_activate_cb), chooser,
                        G_CONNECT_SWAPPED);
+       g_signal_connect_object (entry, "key-press-event",
+                       G_CALLBACK (entry_key_press_event_cb), chooser,
+                       G_CONNECT_SWAPPED);
+       g_signal_connect_object (entry, "button-press-event",
+                       G_CALLBACK (entry_button_press_event_cb), chooser,
+                       G_CONNECT_SWAPPED);
 
        GtkCellRenderer *renderer;
        gtk_cell_layout_clear (GTK_CELL_LAYOUT (chooser));
@@ -389,17 +570,21 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
                        G_CALLBACK (popup_shown_cb), NULL);
        g_signal_connect (chooser, "changed",
                        G_CALLBACK (changed_cb), NULL);
+       g_signal_connect_swapped (entry, "changed",
+                       G_CALLBACK (text_changed_cb), chooser);
+       g_signal_connect_swapped (entry, "focus-out-event",
+                       G_CALLBACK (focus_out_cb), chooser);
 
-       // FIXME - no!
-       gtk_combo_box_set_active (GTK_COMBO_BOX (chooser), 0);
-
-#if 0
        priv->idle = empathy_idle_dup_singleton ();
        presence_chooser_presence_changed_cb (chooser);
        g_signal_connect_swapped (priv->idle, "notify",
                                  G_CALLBACK (presence_chooser_presence_changed_cb),
                                  chooser);
-#endif
+
+       g_object_set (chooser,
+                       // FIXME: this string sucks
+                       "tooltip-text", _("Set your presence and current status"),
+                       NULL);
 }
 
 static void
@@ -413,10 +598,6 @@ presence_chooser_finalize (GObject *object)
                g_source_remove (priv->flash_timeout_id);
        }
 
-       if (priv->scroll_timeout_id) {
-               g_source_remove (priv->scroll_timeout_id);
-       }
-
        g_signal_handlers_disconnect_by_func (priv->idle,
                                              presence_chooser_presence_changed_cb,
                                              object);
@@ -438,7 +619,6 @@ empathy_presence_chooser_new (void)
 static void
 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
 {
-#if 0
        EmpathyPresenceChooserPriv *priv;
        McPresence                 state;
        McPresence                 flash_state;
@@ -446,196 +626,78 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
 
        priv = GET_PRIV (chooser);
 
-       state = empathy_idle_get_state (priv->idle);
+       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);
 
-       presence_chooser_reset_scroll_timeout (chooser);
-       gtk_label_set_text (GTK_LABEL (priv->label), status);
-
-       if (flash_state != MC_PRESENCE_UNSET) {
-               presence_chooser_flash_start (chooser, state, flash_state);
-       } else {
-               presence_chooser_flash_stop (chooser, state);
-       }
-#endif
-}
-
-#if 0
-static void
-presence_chooser_reset_scroll_timeout (EmpathyPresenceChooser *chooser)
-{
-       EmpathyPresenceChooserPriv *priv;
-
-       priv = GET_PRIV (chooser);
-
-       if (priv->scroll_timeout_id) {
-               g_source_remove (priv->scroll_timeout_id);
-               priv->scroll_timeout_id = 0;
-       }
-
-       g_free (priv->scroll_status);
-       priv->scroll_status = NULL;
-}
-#endif
-
-#if 0
-static gboolean
-presence_chooser_scroll_timeout_cb (EmpathyPresenceChooser *chooser)
-{
-       EmpathyPresenceChooserPriv *priv;
-
-       priv = GET_PRIV (chooser);
-
-       priv->scroll_timeout_id = 0;
-
-       empathy_idle_set_presence (priv->idle,
-                                  priv->scroll_state,
-                                  priv->scroll_status);
-
-       g_free (priv->scroll_status);
-       priv->scroll_status = NULL;
-
-       return FALSE;
-}
-#endif
-
-static gboolean
-presence_chooser_scroll_event_cb (EmpathyPresenceChooser *chooser,
-                                 GdkEventScroll        *event,
-                                 gpointer               user_data)
-{
-#if 0
-       EmpathyPresenceChooserPriv *priv;
-       GList                     *list, *l;
-       const gchar               *current_status;
-       StateAndStatus            *sas;
-       gboolean                   match;
-
-       priv = GET_PRIV (chooser);
+       /* look through the model and attempt to find a matching state */
+       GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (chooser));
+       GtkTreeIter iter;
+       gboolean valid, match_state = FALSE, match = FALSE;
+       for (valid = gtk_tree_model_get_iter_first (model, &iter);
+            valid;
+            valid = gtk_tree_model_iter_next (model, &iter))
+       {
+               int m_type;
+               McPresence m_state;
+               char *m_status;
 
-       switch (event->direction) {
-       case GDK_SCROLL_UP:
-               break;
-       case GDK_SCROLL_DOWN:
-               break;
-       default:
-               return FALSE;
-       }
+               gtk_tree_model_get (model, &iter,
+                               COL_STATE, &m_state,
+                               COL_TYPE, &m_type,
+                               -1);
 
-       current_status = gtk_label_get_text (GTK_LABEL (priv->label));
-
-       /* Get the list of presets, which in this context means all the items
-        * without a trailing "...".
-        */
-       list = presence_chooser_get_presets (chooser);
-       sas = NULL;
-       match = FALSE;
-       for (l = list; l; l = l->next) {
-               sas = l->data;
-
-               if (sas->state == priv->last_state &&
-                   strcmp (sas->status, current_status) == 0) {
-                       sas = NULL;
-                       match = TRUE;
-                       if (event->direction == GDK_SCROLL_UP) {
-                               if (l->prev) {
-                                       sas = l->prev->data;
-                               }
-                       }
-                       else if (event->direction == GDK_SCROLL_DOWN) {
-                               if (l->next) {
-                                       sas = l->next->data;
-                               }
-                       }
+               if (m_type == ENTRY_TYPE_CUSTOM ||
+                   m_type == ENTRY_TYPE_SEPARATOR ||
+                   m_type == ENTRY_TYPE_EDIT_CUSTOM)
+               {
+                       continue;
+               }
+               else if (!match_state && state == m_state)
+               {
+                       /* we are now in the section that can contain our
+                        * match */
+                       match_state = TRUE;
+               }
+               else if (match_state && state != m_state)
+               {
+                       /* we have passed the section that can contain our
+                        * match */
                        break;
                }
 
-               sas = NULL;
-       }
+               gtk_tree_model_get (model, &iter,
+                               COL_STATUS_TEXT, &m_status,
+                               -1);
 
-       if (sas) {
-               presence_chooser_reset_scroll_timeout (chooser);
+               match = !strcmp (status, m_status);
 
-               priv->scroll_status = g_strdup (sas->status);
-               priv->scroll_state = sas->state;
+               g_free (m_status);
 
-               priv->scroll_timeout_id =
-                       g_timeout_add_seconds (1,
-                                              (GSourceFunc) presence_chooser_scroll_timeout_cb,
-                                              chooser);
+               if (match) break;
 
-               presence_chooser_flash_stop (chooser, sas->state);
-               gtk_label_set_text (GTK_LABEL (priv->label), sas->status);      
        }
-       else if (!match) {
-               const gchar *status;
-               /* If we didn't get any match at all, it means the last state
-                * was a custom one. Just switch to the first one.
-                */
-               status = empathy_presence_get_default_message (states[0]);
-
-               presence_chooser_reset_scroll_timeout (chooser);
-               empathy_idle_set_presence (priv->idle, states[0], status);
-       }
-
-       g_list_foreach (list, (GFunc) g_free, NULL);
-       g_list_free (list);
-
-#endif
-       return TRUE;
-}
-
-static GList *
-presence_chooser_get_presets (EmpathyPresenceChooser *chooser)
-{
-       GList      *list = NULL;
-       guint       i;
 
-       for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
-               GList          *presets, *p;
-               StateAndStatus *sas;
-               const gchar    *status;
-
-               status = empathy_presence_get_default_message (states[i]);
-               sas = presence_chooser_state_and_status_new (states[i], status);
-               list = g_list_prepend (list, sas);
-
-               /* Go to next state if we don't want messages for that state */
-               if (!states[i+1]) {
-                       continue;
-               }
-
-               presets = empathy_status_presets_get (states[i], 5);
-               for (p = presets; p; p = p->next) {
-                       sas = presence_chooser_state_and_status_new (states[i], p->data);
-                       list = g_list_prepend (list, sas);
-               }
-               g_list_free (presets);
+       if (match)
+       {
+               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
+       }
+       else
+       {
+               // FIXME - do we insert the match into the menu?
+               ui_set_custom_state (chooser, state, status);
        }
-       list = g_list_reverse (list);
-
-       return list;
-}
-
-static StateAndStatus *
-presence_chooser_state_and_status_new (McPresence   state,
-                                      const gchar *status)
-{
-       StateAndStatus *sas;
-
-       sas = g_new0 (StateAndStatus, 1);
-
-       sas->state = state;
-       sas->status = status;
 
-       return sas;
+       if (flash_state != MC_PRESENCE_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)
 {
-#if 0
        EmpathyPresenceChooserPriv *priv;
        McPresence                 state;
        static gboolean            on = FALSE;
@@ -648,12 +710,13 @@ presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
                state = priv->flash_state_2;
        }
 
-       gtk_image_set_from_icon_name (GTK_IMAGE (priv->image),
-                                     empathy_icon_name_for_presence (state),
-                                     GTK_ICON_SIZE_MENU);
+       GtkWidget *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;
-#endif
+
        return TRUE;
 }
 
@@ -662,7 +725,6 @@ presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
                              McPresence             state_1,
                              McPresence             state_2)
 {
-#if 0
        EmpathyPresenceChooserPriv *priv;
 
        g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
@@ -677,14 +739,12 @@ presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
                                                        (GSourceFunc) presence_chooser_flash_timeout_cb,
                                                        chooser);
        }
-#endif
 }
 
 static void
 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
                             McPresence             state)
 {
-#if 0
        EmpathyPresenceChooserPriv *priv;
 
        g_return_if_fail (EMPATHY_IS_PRESENCE_CHOOSER (chooser));
@@ -695,13 +755,14 @@ presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
                g_source_remove (priv->flash_timeout_id);
                priv->flash_timeout_id = 0;
        }
+       GtkWidget *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_image_set_from_icon_name (GTK_IMAGE (priv->image),
-                                     empathy_icon_name_for_presence (state),
-                                     GTK_ICON_SIZE_MENU);
-
-       priv->last_state = state;
-#endif
+       // FIXME - what does this do?
+       // priv->last_state = state;
 }
 
 GtkWidget *
@@ -816,7 +877,7 @@ static void
 presence_chooser_custom_activate_cb (GtkWidget *item,
                                     gpointer   user_data)
 {
-       presence_chooser_dialog_show ();
+       presence_chooser_dialog_show (NULL);
 }
 
 static McPresence
@@ -981,7 +1042,7 @@ presence_chooser_dialog_destroy_cb (GtkWidget           *widget,
 }
 
 static void
-presence_chooser_dialog_show (void)
+presence_chooser_dialog_show (GtkWindow *parent)
 {
        GladeXML *glade;
        gchar    *filename;
@@ -1027,7 +1088,12 @@ presence_chooser_dialog_show (void)
 
        gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (message_dialog->comboboxentry_message), 0);
 
-       /* FIXME: Set transian for a window ? */
+       if (parent)
+       {
+               gtk_window_set_transient_for (
+                               GTK_WINDOW (message_dialog->dialog),
+                               parent);
+       }
 
        gtk_widget_show_all (message_dialog->dialog);
 }