]> git.0d.be Git - empathy.git/commitdiff
Reliably set favourite-star
authorDavyd Madeley <davyd@madeley.id.au>
Tue, 21 Apr 2009 01:50:45 +0000 (09:50 +0800)
committerDavyd Madeley <davyd@madeley.id.au>
Tue, 21 Apr 2009 01:50:45 +0000 (09:50 +0800)
libempathy-gtk/empathy-presence-chooser.c
src/empathy-main-window.c

index d5dc1880f18d71e9675f7ecec96e25ec24ba733d..39d4e0676f79bff5c596062a242f6b5d5cb9566a 100644 (file)
@@ -267,41 +267,63 @@ presence_chooser_get_entry_type (EmpathyPresenceChooser *self)
        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_favourite_icon (EmpathyPresenceChooser *self)
 {
-       EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
        GtkWidget *entry;
        PresenceChooserEntryType type;
 
        entry = gtk_bin_get_child (GTK_BIN (self));
        type = presence_chooser_get_entry_type (self);
 
-       /* debug */
-       g_print ("type = %i\n", type);
-       const char *status = empathy_idle_get_status (priv->idle);
-       g_print ("STATUS = '%s'", status);
-       if (type == ENTRY_TYPE_CUSTOM) g_print ("(Custom)");
-       g_print ("\n");
-       /* - */
-
-       if (type == ENTRY_TYPE_CUSTOM) {
-               /* custom entries can be favourited */
-               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 favourite"));
-       }
-       else if (type == ENTRY_TYPE_SAVED) {
-               /* saved entries can be removed from the list */
-               gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+       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_set_icon_tooltip_text (GTK_ENTRY (entry),
                                         GTK_ENTRY_ICON_SECONDARY,
                                         _("Click to remove this status as a favourite"));
+               }
+               else {
+                       /* custom entries can be favourited */
+                       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 favourite"));
+               }
        }
        else {
                /* built-in entries cannot be favourited */
@@ -440,16 +462,16 @@ presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
                state = empathy_idle_get_state (priv->idle);
                status = empathy_idle_get_status (priv->idle);
 
-               if (type == ENTRY_TYPE_CUSTOM) {
-                       /* save the entry */
-                       DEBUG ("SAVING PRESET (%i, %s)\n", state, status);
-                       empathy_status_presets_set_last (state, status);
-               }
-               else if (type == ENTRY_TYPE_SAVED) {
+               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_favourite_icon (self);
index 0f09a2a36900df47353c15da7dfaf6c260865307..6c5f1fa2c0f1e094caf133af60d0b79b05a6890f 100644 (file)
@@ -1186,6 +1186,9 @@ empathy_main_window_show (void)
        gtk_widget_hide (window->edit_context);
        gtk_widget_hide (window->edit_context_separator);
 
+       /* Set up contact list. */
+       empathy_status_presets_get_all ();
+
        /* Set up presence chooser */
        window->presence_chooser = empathy_presence_chooser_new ();
        gtk_widget_show (window->presence_chooser);
@@ -1216,9 +1219,6 @@ empathy_main_window_show (void)
        gtk_toolbar_insert (GTK_TOOLBAR (window->presence_toolbar), item, -1);
        gtk_widget_show (GTK_WIDGET (item));
 
-       /* Set up contact list. */
-       empathy_status_presets_get_all ();
-
        list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
        monitor = empathy_contact_list_get_monitor (list_iface);
        window->list_store = empathy_contact_list_store_new (list_iface);