]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
Add Custom Messages dialog back in (this dialog needs some work ASAP)
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index 9359199ebb24e598689a2d4c27a39df5b38cf43a..32f32acb07b95935c8b37f72c761296a414a38db 100644 (file)
@@ -107,7 +107,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);
 
@@ -136,6 +136,8 @@ enum
        ENTRY_TYPE_BUILTIN,
        ENTRY_TYPE_SAVED,
        ENTRY_TYPE_CUSTOM,
+       ENTRY_TYPE_SEPARATOR,
+       ENTRY_TYPE_EDIT_CUSTOM,
 };
 
 static GtkTreeModel *
@@ -192,6 +194,20 @@ create_model (void)
                }
 
        }
+       
+       /* 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);
 }
@@ -227,7 +243,7 @@ set_status_editing (EmpathyPresenceChooser *self, gboolean editing)
                                GTK_STOCK_OK);
                gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_SECONDARY,
-                               "Set status");
+                               _("Set status"));
                gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
                                GTK_ENTRY_ICON_PRIMARY,
                                FALSE);
@@ -353,14 +369,36 @@ changed_cb (GtkComboBox *self, gpointer user_data)
                        -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)
+       if (type == ENTRY_TYPE_EDIT_CUSTOM)
        {
+               /* recover the status that was unset because COL_STATUS_TEXT
+                * is "". Unfortunately if you try and set COL_STATUS_TEXT to
+                * NULL, it generates a g_critical. I wonder if there is a
+                * better way around this. */
+               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--;
+
+               /* 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);
+
                /* grab the focus */
                gtk_widget_grab_focus (entry);
+
                set_status_editing (EMPATHY_PRESENCE_CHOOSER (self), TRUE);
        }
        else
@@ -382,6 +420,19 @@ changed_cb (GtkComboBox *self, gpointer user_data)
        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 void
 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
 {
@@ -393,7 +444,11 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
        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),
@@ -437,6 +492,11 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
        g_signal_connect_swapped (priv->idle, "notify",
                                  G_CALLBACK (presence_chooser_presence_changed_cb),
                                  chooser);
+
+       g_object_set (chooser,
+                       // FIXME: this string sucks
+                       "tooltip-text", _("Set your presence and current status"),
+                       NULL);
 }
 
 static void
@@ -729,7 +789,7 @@ static void
 presence_chooser_custom_activate_cb (GtkWidget *item,
                                     gpointer   user_data)
 {
-       presence_chooser_dialog_show ();
+       presence_chooser_dialog_show (NULL);
 }
 
 static McPresence
@@ -894,7 +954,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;
@@ -940,7 +1000,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);
 }