]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
Don't make Hidden/Offline have customisable text
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index 32f32acb07b95935c8b37f72c761296a414a38db..0bb2ce0dea2e50beb56523f4c938270a28c5bbb2 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"
@@ -127,6 +129,7 @@ enum
        COL_STATE,
        COL_STATUS_TEXT,
        COL_DISPLAY_MARKUP,
+       COL_STATUS_CUSTOMISABLE,
        COL_TYPE,
        N_COLUMNS
 };
@@ -148,6 +151,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;
@@ -165,6 +169,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);
 
@@ -178,6 +183,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);
                        }
@@ -189,6 +195,7 @@ 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);
                }
@@ -260,7 +267,14 @@ set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
                                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;
        }
@@ -349,6 +363,7 @@ changed_cb (GtkComboBox *self, gpointer user_data)
 
        GtkTreeIter iter;
        char *icon_name;
+       gboolean customisable = TRUE;
        int type = -1;
 
        GtkTreeModel *model = gtk_combo_box_get_model (self);
@@ -365,11 +380,22 @@ changed_cb (GtkComboBox *self, gpointer user_data)
        gtk_tree_model_get (model, &iter,
                        COL_STATE_ICON_NAME, &icon_name,
                        COL_STATE, &priv->state,
+                       COL_STATUS_CUSTOMISABLE, &customisable,
                        COL_TYPE, &type,
                        -1);
 
        GtkWidget *entry = gtk_bin_get_child (GTK_BIN (self));
 
+       /* 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 */
+       /* FIXME: there is a bug here, if we start in the Hidden state, it
+        * will be editable. It's not something that often occurs though. */
+       if (type != ENTRY_TYPE_EDIT_CUSTOM)
+       {
+               gtk_editable_set_editable (GTK_EDITABLE (entry), customisable);
+       }
+
        if (type == ENTRY_TYPE_EDIT_CUSTOM)
        {
                /* recover the status that was unset because COL_STATUS_TEXT
@@ -396,6 +422,12 @@ changed_cb (GtkComboBox *self, gpointer user_data)
                                GTK_ENTRY_ICON_PRIMARY,
                                icon_name);
 
+               /* preseed the status */
+               const char *status = empathy_idle_get_status (priv->idle);
+               priv->block_set_editing++;
+               gtk_entry_set_text (GTK_ENTRY (entry), status);
+               priv->block_set_editing--;
+
                /* grab the focus */
                gtk_widget_grab_focus (entry);
 
@@ -486,6 +518,8 @@ 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 (changed_cb), chooser);
 
        priv->idle = empathy_idle_dup_singleton ();
        presence_chooser_presence_changed_cb (chooser);
@@ -559,7 +593,9 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                                COL_TYPE, &m_type,
                                -1);
 
-               if (m_type == ENTRY_TYPE_CUSTOM)
+               if (m_type == ENTRY_TYPE_CUSTOM ||
+                   m_type == ENTRY_TYPE_SEPARATOR ||
+                   m_type == ENTRY_TYPE_EDIT_CUSTOM)
                {
                        continue;
                }