]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
Don't forget to show the contact widget in some places
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index 4806dc5c3a88b98c2402c5127dc52f5750b79494..8e9574bc533c10798a195510079395458831785e 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 #include <gdk/gdkkeysyms.h>
 
 #include <telepathy-glib/util.h>
@@ -247,6 +246,96 @@ presence_chooser_popup_shown_cb (GObject *self,
        presence_chooser_create_model (EMPATHY_PRESENCE_CHOOSER (self));
 }
 
+static PresenceChooserEntryType
+presence_chooser_get_entry_type (EmpathyPresenceChooser *self)
+{
+       GtkTreeIter iter;
+       PresenceChooserEntryType type = -1;
+
+       if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter)) {
+               type = ENTRY_TYPE_CUSTOM;
+       }
+       else {
+               GtkTreeModel *model;
+
+               model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+               gtk_tree_model_get (model, &iter,
+                                   COL_TYPE, &type,
+                                   -1);
+       }
+
+       return type;
+}
+
+static gboolean
+presence_chooser_is_preset (EmpathyPresenceChooser *self)
+{
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+       McPresence state;
+       const char *status;
+       GList *presets, *l;
+       gboolean match = FALSE;
+
+       state = empathy_idle_get_state (priv->idle);
+       status = empathy_idle_get_status (priv->idle);
+
+       presets = empathy_status_presets_get (state, -1);
+       for (l = presets; l; l = l->next) {
+               char *preset = (char *) l->data;
+
+               if (!strcmp (status, preset)) {
+                       match = TRUE;
+                       break;
+               }
+       }
+
+       g_list_free (presets);
+
+       DEBUG ("is_preset(%i, %s) = %i\n", state, status, match);
+
+       return match;
+}
+
+static void
+presence_chooser_set_favorite_icon (EmpathyPresenceChooser *self)
+{
+       GtkWidget *entry;
+       PresenceChooserEntryType type;
+
+       entry = gtk_bin_get_child (GTK_BIN (self));
+       type = presence_chooser_get_entry_type (self);
+
+       if (type == ENTRY_TYPE_CUSTOM || type == ENTRY_TYPE_SAVED) {
+               if (presence_chooser_is_preset (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");
+                       gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
+                                        GTK_ENTRY_ICON_SECONDARY,
+                                        _("Click to remove this status as a favorite"));
+               }
+               else {
+                       /* custom entries can be favorited */
+                       gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+                                          GTK_ENTRY_ICON_SECONDARY,
+                                          "empathy-unstarred");
+                       gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
+                                        GTK_ENTRY_ICON_SECONDARY,
+                                        _("Click to make this status a favorite"));
+               }
+       }
+       else {
+               /* built-in entries cannot be favorited */
+               gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
+                                          GTK_ENTRY_ICON_SECONDARY,
+                                          NULL);
+               gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
+                                        GTK_ENTRY_ICON_SECONDARY,
+                                        NULL);
+       }
+}
+
 static void
 presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
                                      gboolean editing)
@@ -274,12 +363,7 @@ presence_chooser_set_status_editing (EmpathyPresenceChooser *self,
        } else {
                GtkWidget *window;
 
-               gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
-                                              GTK_ENTRY_ICON_SECONDARY,
-                                              NULL);
-               gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
-                                                GTK_ENTRY_ICON_SECONDARY,
-                                                NULL);
+               presence_chooser_set_favorite_icon (self);
                gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
                                              GTK_ENTRY_ICON_PRIMARY,
                                              TRUE);
@@ -342,6 +426,7 @@ ui_set_custom_state (EmpathyPresenceChooser *self,
                                           GTK_ENTRY_ICON_PRIMARY,
                                           icon_name);
        gtk_entry_set_text (GTK_ENTRY (entry), status);
+       presence_chooser_set_favorite_icon (self);
 
        priv->block_changed--;
        priv->block_set_editing--;
@@ -361,8 +446,35 @@ presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
                                         GdkEvent               *event,
                                        GtkEntry               *entry)
 {
-       presence_chooser_set_status_editing (self, FALSE);
-       mc_set_custom_state (self);
+       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
+
+       if (priv->editing_status) {
+               presence_chooser_set_status_editing (self, FALSE);
+               mc_set_custom_state (self);
+       }
+       else {
+               PresenceChooserEntryType type;
+               McPresence state;
+               const char *status;
+
+               type = presence_chooser_get_entry_type (self);
+               state = empathy_idle_get_state (priv->idle);
+               status = empathy_idle_get_status (priv->idle);
+
+               if (presence_chooser_is_preset (self)) {
+                       /* remove the entry */
+                       DEBUG ("REMOVING PRESET (%i, %s)\n", state, status);
+                       empathy_status_presets_remove (state, status);
+               }
+               else {
+                       /* save the entry */
+                       DEBUG ("SAVING PRESET (%i, %s)\n", state, status);
+                       empathy_status_presets_set_last (state, status);
+               }
+
+               /* update the icon */
+               presence_chooser_set_favorite_icon (self);
+       }
 }
 
 static void
@@ -753,6 +865,7 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
        if (match) {
                priv->block_changed++;
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (chooser), &iter);
+               presence_chooser_set_favorite_icon (chooser);
                priv->block_changed--;
        }
        else {
@@ -1112,8 +1225,8 @@ presence_chooser_dialog_destroy_cb (GtkWidget           *widget,
 static void
 presence_chooser_dialog_show (GtkWindow *parent)
 {
-       GladeXML *glade;
-       gchar    *filename;
+       GtkBuilder *gui;
+       gchar      *filename;
 
        if (message_dialog) {
                gtk_window_present (GTK_WINDOW (message_dialog->dialog));
@@ -1122,11 +1235,9 @@ presence_chooser_dialog_show (GtkWindow *parent)
 
        message_dialog = g_new0 (CustomMessageDialog, 1);
 
-       filename = empathy_file_lookup ("empathy-presence-chooser.glade",
+       filename = empathy_file_lookup ("empathy-presence-chooser.ui",
                                        "libempathy-gtk");
-       glade = empathy_glade_get_file (filename,
-                                      "custom_message_dialog",
-                                      NULL,
+       gui = empathy_builder_get_file (filename,
                                       "custom_message_dialog", &message_dialog->dialog,
                                       "checkbutton_save", &message_dialog->checkbutton_save,
                                       "comboboxentry_message", &message_dialog->comboboxentry_message,
@@ -1134,15 +1245,14 @@ presence_chooser_dialog_show (GtkWindow *parent)
                                       NULL);
        g_free (filename);
 
-       empathy_glade_connect (glade,
-                              message_dialog,
+       empathy_builder_connect (gui, message_dialog,
                               "custom_message_dialog", "destroy", presence_chooser_dialog_destroy_cb,
                               "custom_message_dialog", "response", presence_chooser_dialog_response_cb,
                               "combobox_status", "changed", presence_chooser_dialog_status_changed_cb,
                               "checkbutton_save", "toggled", presence_chooser_dialog_save_toggled_cb,
                               NULL);
 
-       g_object_unref (glade);
+       g_object_unref (gui);
 
        /* Setup the message combobox */
        message_dialog->entry_message = GTK_BIN (message_dialog->comboboxentry_message)->child;