aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-15 21:02:53 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-15 21:02:53 +0800
commitae50c870740145dbb89560b69477acca0566d12f (patch)
treebf8d1f341e47a261fbec55348e19d7ee885b0f0c /libempathy-gtk
parent01621c62802d1cbf1afa3e857cf072d29b1ca0c7 (diff)
downloadgsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar.gz
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar.bz2
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar.lz
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar.xz
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.tar.zst
gsoc2013-empathy-ae50c870740145dbb89560b69477acca0566d12f.zip
Prepare for slack time when coming back from auto away. Not yet fully
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. svn path=/trunk/; revision=159
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-status-icon.c81
-rw-r--r--libempathy-gtk/gossip-presence-chooser.c165
-rw-r--r--libempathy-gtk/gossip-presence-chooser.h6
3 files changed, 118 insertions, 134 deletions
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