[empathy] Reliably set favourite-star
- From: Davyd Madeley <davyd src gnome org>
- To: svn-commits-list gnome org
- Subject: [empathy] Reliably set favourite-star
- Date: Tue, 21 Apr 2009 04:24:38 -0400 (EDT)
commit 225661fe0ac22a4d8daa7f4e9f33b5fd3c5660c9
Author: Davyd Madeley <davyd madeley id au>
Date: Tue Apr 21 09:50:45 2009 +0800
Reliably set favourite-star
---
libempathy-gtk/empathy-presence-chooser.c | 78 ++++++++++++++++++----------
src/empathy-main-window.c | 6 +-
2 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/libempathy-gtk/empathy-presence-chooser.c b/libempathy-gtk/empathy-presence-chooser.c
index d5dc188..39d4e06 100644
--- a/libempathy-gtk/empathy-presence-chooser.c
+++ b/libempathy-gtk/empathy-presence-chooser.c
@@ -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);
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c
index 0f09a2a..6c5f1fa 100644
--- a/src/empathy-main-window.c
+++ b/src/empathy-main-window.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]