aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-idle.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-06 17:10:23 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-06 17:10:23 +0800
commit976d656a08ded1864324b6060ef035ffcb0b833b (patch)
treec852357f8832fc6acb3a355e2c9a3335195a3a09 /libempathy/empathy-idle.c
parentc982f4d2eb903359a5083e9466669413d5eaf938 (diff)
downloadgsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar.gz
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar.bz2
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar.lz
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar.xz
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.tar.zst
gsoc2013-empathy-976d656a08ded1864324b6060ef035ffcb0b833b.zip
Add support for blinking when there is an event. Make use of EmpathyIdle
2007-06-06 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/empathy-status-icon.c: Add support for blinking when there is an event. Make use of EmpathyIdle for presence handling. Add an event when a contact requets subscription. * libempathy-gtk/gossip-contact-list-store.c: * libempathy-gtk/gossip-contact-list-view.c: * libempathy/empathy-contact-manager.c: * libempathy/empathy-tp-contact-list.c: * libempathy/empathy-tp-chatroom.c: * libempathy/empathy-contact-list.c: * libempathy/empathy-contact-list.h: get_contacts() is renamed to get_members(). Adding a signal and a method for local-pending with contacts with the message. Rework completely the contact-list handling in EmpathyTpContactList to follow tp spec. * libempathy/empathy-idle.c: * libempathy/empathy-idle.h: Add properties for the state and the status message. EmpathyIdle is now a singleton to manager self presence. * TODO: Updated. svn path=/trunk/; revision=123
Diffstat (limited to 'libempathy/empathy-idle.c')
-rw-r--r--libempathy/empathy-idle.c233
1 files changed, 217 insertions, 16 deletions
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c
index 6b9cfb3b9..f9b50bd40 100644
--- a/libempathy/empathy-idle.c
+++ b/libempathy/empathy-idle.c
@@ -27,8 +27,6 @@
#include <libtelepathy/tp-helpers.h>
-#include <libmissioncontrol/mission-control.h>
-
#include "empathy-idle.h"
#include "gossip-utils.h"
#include "gossip-debug.h"
@@ -49,6 +47,9 @@ struct _EmpathyIdlePriv {
MissionControl *mc;
DBusGProxy *gs_proxy;
gboolean is_idle;
+ McPresence state;
+ McPresence slack_state;
+ gchar *status;
McPresence saved_state;
gchar *saved_status;
guint ext_away_timeout;
@@ -57,6 +58,17 @@ struct _EmpathyIdlePriv {
static void empathy_idle_class_init (EmpathyIdleClass *klass);
static void empathy_idle_init (EmpathyIdle *idle);
static void idle_finalize (GObject *object);
+static void idle_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void idle_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void idle_presence_changed_cb (MissionControl *mc,
+ McPresence state,
+ EmpathyIdle *idle);
static void idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
gboolean is_idle,
EmpathyIdle *idle);
@@ -64,7 +76,12 @@ static void idle_ext_away_start (EmpathyIdle *idle);
static void idle_ext_away_stop (EmpathyIdle *idle);
static gboolean idle_ext_away_cb (EmpathyIdle *idle);
-//static guint signals[LAST_SIGNAL];
+enum {
+ PROP_0,
+ PROP_STATE,
+ PROP_STATUS,
+ PROP_SLACK_STATE
+};
G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT)
@@ -74,6 +91,34 @@ empathy_idle_class_init (EmpathyIdleClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = idle_finalize;
+ object_class->get_property = idle_get_property;
+ object_class->set_property = idle_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_STATE,
+ g_param_spec_uint ("state",
+ "state",
+ "state",
+ MC_PRESENCE_UNSET,
+ LAST_MC_PRESENCE,
+ MC_PRESENCE_AVAILABLE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_STATUS,
+ g_param_spec_string ("status",
+ "status",
+ "status",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SLACK_STATE,
+ g_param_spec_uint ("slack-state",
+ "slack-state",
+ "slack-state",
+ MC_PRESENCE_UNSET,
+ LAST_MC_PRESENCE,
+ MC_PRESENCE_UNSET,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
}
@@ -87,6 +132,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);
priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
"org.gnome.ScreenSaver",
"/org/gnome/ScreenSaver",
@@ -102,6 +149,10 @@ empathy_idle_init (EmpathyIdle *idle)
dbus_g_proxy_connect_signal (priv->gs_proxy, "SessionIdleChanged",
G_CALLBACK (idle_session_idle_changed_cb),
idle, NULL);
+ dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
+ "PresenceStatusActual",
+ G_CALLBACK (idle_presence_changed_cb),
+ idle, NULL);
}
static void
@@ -111,6 +162,7 @@ idle_finalize (GObject *object)
priv = GET_PRIV (object);
+ g_free (priv->status);
g_free (priv->saved_status);
g_object_unref (priv->mc);
@@ -121,6 +173,62 @@ idle_finalize (GObject *object)
idle_ext_away_stop (EMPATHY_IDLE (object));
}
+static void
+idle_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIdlePriv *priv;
+ EmpathyIdle *idle;
+
+ priv = GET_PRIV (object);
+ idle = EMPATHY_IDLE (object);
+
+ switch (param_id) {
+ case PROP_STATE:
+ g_value_set_uint (value, empathy_idle_get_state (idle));
+ break;
+ 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));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+idle_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIdlePriv *priv;
+ EmpathyIdle *idle;
+
+ priv = GET_PRIV (object);
+ idle = EMPATHY_IDLE (object);
+
+ switch (param_id) {
+ case PROP_STATE:
+ empathy_idle_set_state (idle, g_value_get_uint (value));
+ break;
+ 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));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
EmpathyIdle *
empathy_idle_new (void)
{
@@ -136,6 +244,99 @@ empathy_idle_new (void)
return idle;
}
+McPresence
+empathy_idle_get_state (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ return priv->state;
+}
+
+void
+empathy_idle_set_state (EmpathyIdle *idle,
+ McPresence state)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ mission_control_set_presence (priv->mc,
+ state,
+ priv->status,
+ NULL, NULL);
+}
+
+const gchar *
+empathy_idle_get_status (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ return priv->status;
+}
+
+void
+empathy_idle_set_status (EmpathyIdle *idle,
+ const gchar *status)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ mission_control_set_presence (priv->mc,
+ priv->state,
+ status,
+ NULL, NULL);
+}
+
+McPresence
+empathy_idle_get_slack_state (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ return priv->slack_state;
+}
+
+void
+empathy_idle_set_slack_state (EmpathyIdle *idle,
+ McPresence state)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ priv->slack_state = state;
+
+ g_object_notify (G_OBJECT (idle), "slack-state");
+}
+
+static void
+idle_presence_changed_cb (MissionControl *mc,
+ McPresence state,
+ EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ g_free (priv->status);
+ priv->state = state;
+ priv->status = mission_control_get_presence_message_actual (priv->mc, NULL);
+
+ if (G_STR_EMPTY (priv->status)) {
+ g_free (priv->status);
+ priv->status = g_strdup (gossip_presence_state_get_default_status (state));
+ }
+
+ g_object_notify (G_OBJECT (idle), "state");
+ g_object_notify (G_OBJECT (idle), "status");
+}
+
static void
idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
gboolean is_idle,
@@ -150,30 +351,29 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
is_idle ? "yes" : "no");
if (is_idle && !priv->is_idle) {
- McPresence new_state = MC_PRESENCE_AWAY;
+ McPresence new_state;
/* We are now idle, set state to away */
- priv->saved_state = mission_control_get_presence_actual (priv->mc, NULL);
- priv->saved_status = mission_control_get_presence_message_actual (priv->mc, NULL);
-
- if (priv->saved_state <= MC_PRESENCE_OFFLINE ||
- priv->saved_state == MC_PRESENCE_HIDDEN) {
+ if (priv->state <= MC_PRESENCE_OFFLINE ||
+ priv->state == MC_PRESENCE_HIDDEN) {
/* We are not online so nothing to do here */
return;
- } else if (priv->saved_state == MC_PRESENCE_AWAY ||
- priv->saved_state == MC_PRESENCE_EXTENDED_AWAY) {
+ } else if (priv->state == MC_PRESENCE_AWAY ||
+ priv->state == MC_PRESENCE_EXTENDED_AWAY) {
/* User set away manually, when coming back we restore
* default presence. */
- new_state = priv->saved_state;
+ new_state = priv->state;
priv->saved_state = MC_PRESENCE_AVAILABLE;
priv->saved_status = NULL;
+ } else {
+ new_state = MC_PRESENCE_AWAY;
+ priv->saved_state = priv->state;
+ priv->saved_status = g_strdup (priv->status);
}
gossip_debug (DEBUG_DOMAIN, "Going to autoaway");
- mission_control_set_presence (priv->mc,
- new_state,
- priv->saved_status,
- NULL, NULL);
+ empathy_idle_set_state (idle, new_state);
+
idle_ext_away_start (idle);
} else if (!is_idle && priv->is_idle) {
/* We are no more idle, restore state */
@@ -187,6 +387,7 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
priv->saved_state,
priv->saved_status,
NULL, NULL);
+
g_free (priv->saved_status);
priv->saved_status = NULL;
}