diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | libempathy-gtk/empathy-status-icon.c | 81 | ||||
-rw-r--r-- | libempathy-gtk/gossip-presence-chooser.c | 165 | ||||
-rw-r--r-- | libempathy-gtk/gossip-presence-chooser.h | 6 | ||||
-rw-r--r-- | libempathy/empathy-idle.c | 53 | ||||
-rw-r--r-- | libempathy/empathy-idle.h | 9 |
6 files changed, 169 insertions, 154 deletions
@@ -1,3 +1,12 @@ +2007-06-15 Xavier Claessens <xclaesse@gmail.com> + + * libempathy-gtk/empathy-status-icon.c: + * libempathy-gtk/gossip-presence-chooser.c: + * libempathy-gtk/gossip-presence-chooser.h: + * libempathy/empathy-idle.c: + * libempathy/empathy-idle.h: Prepare for slack time when coming back + from auto away. Not yet fully implemented. + 2007-06-14 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/empathy-images.h: diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c index f8753820a..17d274ee6 100644 --- a/libempathy-gtk/empathy-status-icon.c +++ b/libempathy-gtk/empathy-status-icon.c @@ -54,24 +54,24 @@ /* Number of ms to wait when blinking */ #define BLINK_TIMEOUT 500 +typedef struct _StatusIconEvent StatusIconEvent; + struct _EmpathyStatusIconPriv { GtkStatusIcon *icon; EmpathyContactManager *manager; EmpathyIdle *idle; GList *events; + GList *current_event; + StatusIconEvent *flash_state_event; guint blink_timeout; - gboolean showing_state_icon; GtkWindow *window; - GtkWidget *popup_menu; GtkWidget *show_window_item; GtkWidget *message_item; GtkWidget *status_item; }; -typedef struct _StatusIconEvent StatusIconEvent; - typedef void (*EventActivatedFunc) (StatusIconEvent *event); struct _StatusIconEvent { @@ -85,9 +85,7 @@ struct _StatusIconEvent { static void empathy_status_icon_class_init (EmpathyStatusIconClass *klass); static void empathy_status_icon_init (EmpathyStatusIcon *icon); static void status_icon_finalize (GObject *object); -static void status_icon_idle_notify_cb (EmpathyIdle *idle, - GParamSpec *param, - EmpathyStatusIcon *icon); +static void status_icon_idle_notify_cb (EmpathyStatusIcon *icon); static void status_icon_update_tooltip (EmpathyStatusIcon *icon); static void status_icon_set_from_state (EmpathyStatusIcon *icon); static void status_icon_toggle_visibility (EmpathyStatusIcon *icon); @@ -112,6 +110,7 @@ static void status_icon_local_pending_cb (EmpathyContactManager *manag gchar *message, EmpathyStatusIcon *icon); static void status_icon_event_subscribe_cb (StatusIconEvent *event); +static void status_icon_event_flash_state_cb (StatusIconEvent *event); static StatusIconEvent * status_icon_event_new (EmpathyStatusIcon *icon, const gchar *icon_name, const gchar *message); @@ -143,15 +142,13 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) priv->icon = gtk_status_icon_new (); priv->idle = empathy_idle_new (); priv->manager = empathy_contact_manager_new (); - priv->showing_state_icon = TRUE; status_icon_create_menu (icon); - status_icon_set_from_state (icon); - status_icon_update_tooltip (icon); + status_icon_idle_notify_cb (icon); - g_signal_connect (priv->idle, "notify", - G_CALLBACK (status_icon_idle_notify_cb), - icon); + g_signal_connect_swapped (priv->idle, "notify", + G_CALLBACK (status_icon_idle_notify_cb), + icon); g_signal_connect (priv->icon, "activate", G_CALLBACK (status_icon_activate_cb), icon); @@ -227,15 +224,37 @@ empathy_status_icon_new (GtkWindow *window) } static void -status_icon_idle_notify_cb (EmpathyIdle *idle, - GParamSpec *param, - EmpathyStatusIcon *icon) +status_icon_idle_notify_cb (EmpathyStatusIcon *icon) { EmpathyStatusIconPriv *priv; + McPresence flash_state; priv = GET_PRIV (icon); - if (priv->showing_state_icon) { + flash_state = empathy_idle_get_flash_state (priv->idle); + if (flash_state != MC_PRESENCE_UNSET) { + const gchar *icon_name; + + icon_name = gossip_icon_name_for_presence_state (flash_state); + if (!priv->flash_state_event) { + /* We are now flashing */ + priv->flash_state_event = status_icon_event_new (icon, icon_name, NULL); + priv->flash_state_event->user_data = icon; + priv->flash_state_event->func = status_icon_event_flash_state_cb; + + } else { + /* We are still flashing but with another state */ + g_free (priv->flash_state_event->icon_name); + priv->flash_state_event->icon_name = g_strdup (icon_name); + } + } + else if (priv->flash_state_event) { + /* We are no more flashing */ + status_icon_event_remove (icon, priv->flash_state_event); + priv->flash_state_event = NULL; + } + + if (!priv->current_event) { status_icon_set_from_state (icon); } @@ -469,6 +488,17 @@ status_icon_event_subscribe_cb (StatusIconEvent *event) g_object_unref (contact); } +static void +status_icon_event_flash_state_cb (StatusIconEvent *event) +{ + EmpathyStatusIconPriv *priv; + + priv = GET_PRIV (event->user_data); + + empathy_idle_set_flash_state (priv->idle, MC_PRESENCE_UNSET); +} + + static StatusIconEvent * status_icon_event_new (EmpathyStatusIcon *icon, const gchar *icon_name, @@ -485,6 +515,7 @@ status_icon_event_new (EmpathyStatusIcon *icon, priv->events = g_list_append (priv->events, event); if (!priv->blink_timeout) { + priv->current_event = NULL; priv->blink_timeout = g_timeout_add (BLINK_TIMEOUT, (GSourceFunc) status_icon_event_timeout_cb, icon); @@ -507,19 +538,17 @@ status_icon_event_remove (EmpathyStatusIcon *icon, } priv->events = g_list_remove (priv->events, event); status_icon_event_free (event); + priv->current_event = NULL; status_icon_update_tooltip (icon); + status_icon_set_from_state (icon); if (priv->events) { return; } - status_icon_set_from_state (icon); - priv->showing_state_icon = TRUE; - if (priv->blink_timeout) { g_source_remove (priv->blink_timeout); priv->blink_timeout = 0; - } } @@ -530,14 +559,18 @@ status_icon_event_timeout_cb (EmpathyStatusIcon *icon) priv = GET_PRIV (icon); - priv->showing_state_icon = !priv->showing_state_icon; + if (priv->current_event) { + priv->current_event = priv->current_event->next; + } else { + priv->current_event = priv->events; + } - if (priv->showing_state_icon) { + if (!priv->current_event) { status_icon_set_from_state (icon); } else { StatusIconEvent *event; - event = priv->events->data; + event = priv->current_event->data; gtk_status_icon_set_from_icon_name (priv->icon, event->icon_name); } status_icon_update_tooltip (icon); diff --git a/libempathy-gtk/gossip-presence-chooser.c b/libempathy-gtk/gossip-presence-chooser.c index e92de9efa..74c56e7a4 100644 --- a/libempathy-gtk/gossip-presence-chooser.c +++ b/libempathy-gtk/gossip-presence-chooser.c @@ -30,8 +30,7 @@ #include <gtk/gtk.h> #include <glade/glade.h> -#include <libmissioncontrol/mission-control.h> - +#include <libempathy/empathy-idle.h> #include <libempathy/gossip-utils.h> #include <libempathy/gossip-debug.h> #include <libempathy/empathy-marshal.h> @@ -49,23 +48,23 @@ #define FLASH_TIMEOUT 500 typedef struct { - MissionControl *mc; + EmpathyIdle *idle; - GtkWidget *hbox; - GtkWidget *image; - GtkWidget *label; - GtkWidget *menu; + GtkWidget *hbox; + GtkWidget *image; + GtkWidget *label; + GtkWidget *menu; - McPresence last_state; + McPresence last_state; - McPresence flash_state_1; - McPresence flash_state_2; - guint flash_timeout_id; + McPresence flash_state_1; + McPresence flash_state_2; + guint flash_timeout_id; /* The handle the kind of unnessecary scroll support. */ - guint scroll_timeout_id; - McPresence scroll_state; - gchar *scroll_status; + guint scroll_timeout_id; + McPresence scroll_state; + gchar *scroll_status; } GossipPresenceChooserPriv; typedef struct { @@ -81,9 +80,7 @@ static McPresence states[] = {MC_PRESENCE_AVAILABLE, static void gossip_presence_chooser_class_init (GossipPresenceChooserClass *klass); static void gossip_presence_chooser_init (GossipPresenceChooser *chooser); static void presence_chooser_finalize (GObject *object); -static void presence_chooser_presence_changed_cb (MissionControl *mc, - McPresence state, - GossipPresenceChooser *chooser); +static void presence_chooser_presence_changed_cb (GossipPresenceChooser *chooser); static void presence_chooser_reset_scroll_timeout (GossipPresenceChooser *chooser); static gboolean presence_chooser_scroll_timeout_cb (GossipPresenceChooser *chooser); static gboolean presence_chooser_scroll_event_cb (GossipPresenceChooser *chooser, @@ -93,12 +90,11 @@ static GList * presence_chooser_get_presets (GossipPresenceCh static StateAndStatus *presence_chooser_state_and_status_new (McPresence state, const gchar *status); static gboolean presence_chooser_flash_timeout_cb (GossipPresenceChooser *chooser); -void gossip_presence_chooser_flash_start (GossipPresenceChooser *chooser, +static void presence_chooser_flash_start (GossipPresenceChooser *chooser, McPresence state_1, McPresence state_2); -void gossip_presence_chooser_flash_stop (GossipPresenceChooser *chooser, +static void presence_chooser_flash_stop (GossipPresenceChooser *chooser, McPresence state); -gboolean gossip_presence_chooser_is_flashing (GossipPresenceChooser *chooser); static gboolean presence_chooser_button_press_event_cb (GtkWidget *chooser, GdkEventButton *event, gpointer user_data); @@ -156,7 +152,6 @@ gossip_presence_chooser_init (GossipPresenceChooser *chooser) GossipPresenceChooserPriv *priv; GtkWidget *arrow; GtkWidget *alignment; - McPresence state; priv = GET_PRIV (chooser); @@ -201,13 +196,11 @@ gossip_presence_chooser_init (GossipPresenceChooser *chooser) G_CALLBACK (presence_chooser_scroll_event_cb), NULL); - priv->mc = gossip_mission_control_new (); - state = mission_control_get_presence_actual (priv->mc, NULL); - presence_chooser_presence_changed_cb (priv->mc, state, chooser); - dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), - "PresenceStatusActual", - G_CALLBACK (presence_chooser_presence_changed_cb), - chooser, NULL); + priv->idle = empathy_idle_new (); + presence_chooser_presence_changed_cb (chooser); + g_signal_connect_swapped (priv->idle, "notify", + G_CALLBACK (presence_chooser_presence_changed_cb), + chooser); } static void @@ -225,11 +218,10 @@ presence_chooser_finalize (GObject *object) g_source_remove (priv->scroll_timeout_id); } - dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), - "PresenceStatusActual", - G_CALLBACK (presence_chooser_presence_changed_cb), - object); - g_object_unref (priv->mc); + g_signal_handlers_disconnect_by_func (priv->idle, + presence_chooser_presence_changed_cb, + object); + g_object_unref (priv->idle); G_OBJECT_CLASS (gossip_presence_chooser_parent_class)->finalize (object); } @@ -245,29 +237,27 @@ gossip_presence_chooser_new (void) } static void -presence_chooser_presence_changed_cb (MissionControl *mc, - McPresence state, - GossipPresenceChooser *chooser) +presence_chooser_presence_changed_cb (GossipPresenceChooser *chooser) { GossipPresenceChooserPriv *priv; - gchar *status; + McPresence state; + McPresence flash_state; + const gchar *status; priv = GET_PRIV (chooser); - status = mission_control_get_presence_message_actual (priv->mc, NULL); - if (G_STR_EMPTY (status)) { - g_free (status); - status = g_strdup (gossip_presence_state_get_default_status (state)); - } - - gossip_debug (DEBUG_DOMAIN, "Presence changed to %s (%d)", - status, state); + state = empathy_idle_get_state (priv->idle); + status = empathy_idle_get_status (priv->idle); + flash_state = empathy_idle_get_flash_state (priv->idle); presence_chooser_reset_scroll_timeout (chooser); - gossip_presence_chooser_flash_stop (chooser, state); gtk_label_set_text (GTK_LABEL (priv->label), status); - g_free (status); + if (flash_state != MC_PRESENCE_UNSET) { + presence_chooser_flash_start (chooser, state, flash_state); + } else { + presence_chooser_flash_stop (chooser, state); + } } static void @@ -295,13 +285,9 @@ presence_chooser_scroll_timeout_cb (GossipPresenceChooser *chooser) priv->scroll_timeout_id = 0; - gossip_debug (DEBUG_DOMAIN, "Setting presence to %s (%d)", - priv->scroll_status, priv->scroll_state); - - mission_control_set_presence (priv->mc, - priv->scroll_state, - priv->scroll_status, - NULL, NULL); + empathy_idle_set_presence (priv->idle, + priv->scroll_state, + priv->scroll_status); g_free (priv->scroll_status); priv->scroll_status = NULL; @@ -373,7 +359,7 @@ presence_chooser_scroll_event_cb (GossipPresenceChooser *chooser, (GSourceFunc) presence_chooser_scroll_timeout_cb, chooser); - gossip_presence_chooser_flash_stop (chooser, sas->state); + presence_chooser_flash_stop (chooser, sas->state); gtk_label_set_text (GTK_LABEL (priv->label), sas->status); } else if (!match) { @@ -383,14 +369,8 @@ presence_chooser_scroll_event_cb (GossipPresenceChooser *chooser, */ status = gossip_presence_state_get_default_status (states[0]); - gossip_debug (DEBUG_DOMAIN, "Setting presence to %s (%d)", - status, states[0]); - presence_chooser_reset_scroll_timeout (chooser); - mission_control_set_presence (priv->mc, - states[0], - status, - NULL, NULL); + empathy_idle_set_presence (priv->idle, states[0], status); } g_list_foreach (list, (GFunc) g_free, NULL); @@ -463,10 +443,10 @@ presence_chooser_flash_timeout_cb (GossipPresenceChooser *chooser) return TRUE; } -void -gossip_presence_chooser_flash_start (GossipPresenceChooser *chooser, - McPresence state_1, - McPresence state_2) +static void +presence_chooser_flash_start (GossipPresenceChooser *chooser, + McPresence state_1, + McPresence state_2) { GossipPresenceChooserPriv *priv; @@ -474,21 +454,19 @@ gossip_presence_chooser_flash_start (GossipPresenceChooser *chooser, priv = GET_PRIV (chooser); - if (priv->flash_timeout_id != 0) { - return; - } - priv->flash_state_1 = state_1; priv->flash_state_2 = state_2; - priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT, - (GSourceFunc) presence_chooser_flash_timeout_cb, - chooser); + if (!priv->flash_timeout_id) { + priv->flash_timeout_id = g_timeout_add (FLASH_TIMEOUT, + (GSourceFunc) presence_chooser_flash_timeout_cb, + chooser); + } } -void -gossip_presence_chooser_flash_stop (GossipPresenceChooser *chooser, - McPresence state) +static void +presence_chooser_flash_stop (GossipPresenceChooser *chooser, + McPresence state) { GossipPresenceChooserPriv *priv; @@ -508,22 +486,6 @@ gossip_presence_chooser_flash_stop (GossipPresenceChooser *chooser, priv->last_state = state; } -gboolean -gossip_presence_chooser_is_flashing (GossipPresenceChooser *chooser) -{ - GossipPresenceChooserPriv *priv; - - g_return_val_if_fail (GOSSIP_IS_PRESENCE_CHOOSER (chooser), FALSE); - - priv = GET_PRIV (chooser); - - if (priv->flash_timeout_id) { - return TRUE; - } - - return FALSE; -} - static gboolean presence_chooser_button_press_event_cb (GtkWidget *chooser, GdkEventButton *event, @@ -851,26 +813,21 @@ presence_chooser_set_state (McPresence state, const gchar *status, gboolean save) { - const gchar *default_status; - MissionControl *mc; + EmpathyIdle *idle; - default_status = gossip_presence_state_get_default_status (state); + if (!G_STR_EMPTY (status)) { + const gchar *default_status; - if (G_STR_EMPTY (status)) { - status = default_status; - } else { /* Only store the value if it differs from the default ones. */ + default_status = gossip_presence_state_get_default_status (state); if (save && strcmp (status, default_status) != 0) { gossip_status_presets_set_last (state, status); } } - gossip_debug (DEBUG_DOMAIN, "Setting presence to %s (%d)", - status, state); - - mc = gossip_mission_control_new (); - mission_control_set_presence (mc, state, status, NULL, NULL); - g_object_unref (mc); + idle = empathy_idle_new (); + empathy_idle_set_presence (idle, state, status); + g_object_unref (idle); } static void diff --git a/libempathy-gtk/gossip-presence-chooser.h b/libempathy-gtk/gossip-presence-chooser.h index f78c96c19..7175126ea 100644 --- a/libempathy-gtk/gossip-presence-chooser.h +++ b/libempathy-gtk/gossip-presence-chooser.h @@ -51,12 +51,6 @@ struct _GossipPresenceChooserClass { GType gossip_presence_chooser_get_type (void) G_GNUC_CONST; GtkWidget *gossip_presence_chooser_new (void); GtkWidget *gossip_presence_chooser_create_menu (void); -void gossip_presence_chooser_flash_start (GossipPresenceChooser *chooser, - McPresence state_1, - McPresence state_2); -void gossip_presence_chooser_flash_stop (GossipPresenceChooser *chooser, - McPresence state); -gboolean gossip_presence_chooser_is_flashing (GossipPresenceChooser *chooser); G_END_DECLS diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index f9b50bd40..b0984b077 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -48,7 +48,7 @@ struct _EmpathyIdlePriv { DBusGProxy *gs_proxy; gboolean is_idle; McPresence state; - McPresence slack_state; + McPresence flash_state; gchar *status; McPresence saved_state; gchar *saved_status; @@ -80,7 +80,7 @@ enum { PROP_0, PROP_STATE, PROP_STATUS, - PROP_SLACK_STATE + PROP_FLASH_STATE }; G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT) @@ -111,10 +111,10 @@ empathy_idle_class_init (EmpathyIdleClass *klass) NULL, G_PARAM_READWRITE)); g_object_class_install_property (object_class, - PROP_SLACK_STATE, - g_param_spec_uint ("slack-state", - "slack-state", - "slack-state", + PROP_FLASH_STATE, + g_param_spec_uint ("flash-state", + "flash-state", + "flash-state", MC_PRESENCE_UNSET, LAST_MC_PRESENCE, MC_PRESENCE_UNSET, @@ -133,7 +133,8 @@ empathy_idle_init (EmpathyIdle *idle) priv->is_idle = FALSE; priv->mc = gossip_mission_control_new (); priv->state = mission_control_get_presence_actual (priv->mc, NULL); - priv->status = mission_control_get_presence_message_actual (priv->mc, NULL); + idle_presence_changed_cb (priv->mc, priv->state, idle); + priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (), "org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", @@ -192,8 +193,8 @@ idle_get_property (GObject *object, case PROP_STATUS: g_value_set_string (value, empathy_idle_get_status (idle)); break; - case PROP_SLACK_STATE: - g_value_set_uint (value, empathy_idle_get_slack_state (idle)); + case PROP_FLASH_STATE: + g_value_set_uint (value, empathy_idle_get_flash_state (idle)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -220,8 +221,8 @@ idle_set_property (GObject *object, case PROP_STATUS: empathy_idle_set_status (idle, g_value_get_string (value)); break; - case PROP_SLACK_STATE: - empathy_idle_set_slack_state (idle, g_value_get_uint (value)); + case PROP_FLASH_STATE: + empathy_idle_set_flash_state (idle, g_value_get_uint (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); @@ -293,26 +294,44 @@ empathy_idle_set_status (EmpathyIdle *idle, } McPresence -empathy_idle_get_slack_state (EmpathyIdle *idle) +empathy_idle_get_flash_state (EmpathyIdle *idle) { EmpathyIdlePriv *priv; priv = GET_PRIV (idle); - return priv->slack_state; + return priv->flash_state; } void -empathy_idle_set_slack_state (EmpathyIdle *idle, +empathy_idle_set_flash_state (EmpathyIdle *idle, McPresence state) { EmpathyIdlePriv *priv; priv = GET_PRIV (idle); - priv->slack_state = state; + priv->flash_state = state; + + if (state == MC_PRESENCE_UNSET) { + } + + g_object_notify (G_OBJECT (idle), "flash-state"); +} + +void +empathy_idle_set_presence (EmpathyIdle *idle, + McPresence state, + const gchar *status) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); - g_object_notify (G_OBJECT (idle), "slack-state"); + mission_control_set_presence (priv->mc, + state, + status, + NULL, NULL); } static void @@ -352,7 +371,7 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy, if (is_idle && !priv->is_idle) { McPresence new_state; - /* We are now idle, set state to away */ + /* We are now idle */ if (priv->state <= MC_PRESENCE_OFFLINE || priv->state == MC_PRESENCE_HIDDEN) { diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h index 13c5dd293..011d2494a 100644 --- a/libempathy/empathy-idle.h +++ b/libempathy/empathy-idle.h @@ -55,10 +55,13 @@ void empathy_idle_set_state (EmpathyIdle *idle, McPresence state); const gchar *empathy_idle_get_status (EmpathyIdle *idle); void empathy_idle_set_status (EmpathyIdle *idle, - const gchar *message); -McPresence empathy_idle_get_slack_state (EmpathyIdle *idle); -void empathy_idle_set_slack_state (EmpathyIdle *idle, + const gchar *status); +McPresence empathy_idle_get_flash_state (EmpathyIdle *idle); +void empathy_idle_set_flash_state (EmpathyIdle *idle, McPresence state); +void empathy_idle_set_presence (EmpathyIdle *idle, + McPresence state, + const gchar *status); G_END_DECLS |