/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include <config.h>
-#include <glib/gi18n.h>
+#include <string.h>
+
+#include <glib/gi18n-lib.h>
#include <dbus/dbus-glib.h>
-#include <libtelepathy/tp-helpers.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/util.h>
+#include "empathy-account-manager.h"
#include "empathy-idle.h"
-#include "gossip-utils.h"
-#include "gossip-debug.h"
+#include "empathy-utils.h"
+#include "empathy-connectivity.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- EMPATHY_TYPE_IDLE, EmpathyIdlePriv))
-
-#define DEBUG_DOMAIN "Idle"
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include "empathy-debug.h"
/* Number of seconds before entering extended autoaway. */
#define EXT_AWAY_TIME (30*60)
-enum {
- LAST_SIGNAL
-};
-
-struct _EmpathyIdlePriv {
- MissionControl *mc;
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIdle)
+typedef struct {
DBusGProxy *gs_proxy;
- gboolean is_idle;
- McPresence state;
- McPresence slack_state;
+ EmpathyConnectivity *connectivity;
+ gulong state_change_signal_id;
+
+ TpConnectionPresenceType state;
gchar *status;
- McPresence saved_state;
+ TpConnectionPresenceType flash_state;
+ gboolean auto_away;
+
+ TpConnectionPresenceType away_saved_state;
+ TpConnectionPresenceType saved_state;
gchar *saved_status;
+
+ gboolean is_idle;
guint ext_away_timeout;
-};
-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);
-static void idle_ext_away_start (EmpathyIdle *idle);
-static void idle_ext_away_stop (EmpathyIdle *idle);
-static gboolean idle_ext_away_cb (EmpathyIdle *idle);
+ EmpathyAccountManager *manager;
+} EmpathyIdlePriv;
+
+typedef enum {
+ SESSION_STATUS_AVAILABLE,
+ SESSION_STATUS_INVISIBLE,
+ SESSION_STATUS_BUSY,
+ SESSION_STATUS_IDLE,
+ SESSION_STATUS_UNKNOWN
+} SessionStatus;
enum {
PROP_0,
PROP_STATE,
PROP_STATUS,
- PROP_SLACK_STATE
+ PROP_FLASH_STATE,
+ PROP_AUTO_AWAY
};
-G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT)
+G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT);
+
+static EmpathyIdle * idle_singleton = NULL;
static void
-empathy_idle_class_init (EmpathyIdleClass *klass)
+idle_presence_changed_cb (EmpathyAccountManager *manager,
+ TpConnectionPresenceType state,
+ gchar *status,
+ gchar *status_message,
+ EmpathyIdle *idle)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ EmpathyIdlePriv *priv;
- object_class->finalize = idle_finalize;
- object_class->get_property = idle_get_property;
- object_class->set_property = idle_set_property;
+ priv = GET_PRIV (idle);
- 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));
+ if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET)
+ /* Assume our presence is offline if MC reports UNSET */
+ state = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
- g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
+ DEBUG ("Presence changed to '%s' (%d) \"%s\"", status, state,
+ status_message);
+
+ g_free (priv->status);
+ priv->state = state;
+ if (EMP_STR_EMPTY (status_message))
+ priv->status = NULL;
+ else
+ priv->status = g_strdup (status_message);
+
+ g_object_notify (G_OBJECT (idle), "state");
+ g_object_notify (G_OBJECT (idle), "status");
+}
+
+static gboolean
+idle_ext_away_cb (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ DEBUG ("Going to extended autoaway");
+ empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY);
+ priv->ext_away_timeout = 0;
+
+ return FALSE;
}
static void
-empathy_idle_init (EmpathyIdle *idle)
+idle_ext_away_stop (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
priv = GET_PRIV (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",
- "org.gnome.ScreenSaver");
- if (!priv->gs_proxy) {
- gossip_debug (DEBUG_DOMAIN, "Failed to get gs proxy");
+ if (priv->ext_away_timeout) {
+ g_source_remove (priv->ext_away_timeout);
+ priv->ext_away_timeout = 0;
+ }
+}
+
+static void
+idle_ext_away_start (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ if (priv->ext_away_timeout != 0) {
return;
}
+ priv->ext_away_timeout = g_timeout_add_seconds (EXT_AWAY_TIME,
+ (GSourceFunc) idle_ext_away_cb,
+ idle);
+}
+
+static void
+idle_session_status_changed_cb (DBusGProxy *gs_proxy,
+ SessionStatus status,
+ EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+ gboolean is_idle;
+
+ priv = GET_PRIV (idle);
+
+ is_idle = (status == SESSION_STATUS_IDLE);
+
+ DEBUG ("Session idle state changed, %s -> %s",
+ priv->is_idle ? "yes" : "no",
+ is_idle ? "yes" : "no");
+
+ if (!priv->auto_away ||
+ (priv->saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET &&
+ (priv->state <= TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
+ priv->state == TP_CONNECTION_PRESENCE_TYPE_HIDDEN))) {
+ /* We don't want to go auto away OR we explicitely asked to be
+ * offline, nothing to do here */
+ priv->is_idle = is_idle;
+ return;
+ }
+
+ if (is_idle && !priv->is_idle) {
+ TpConnectionPresenceType new_state;
+ /* We are now idle */
+
+ idle_ext_away_start (idle);
+
+ if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+ /* We are disconnected, when coming back from away
+ * we want to restore the presence before the
+ * disconnection. */
+ priv->away_saved_state = priv->saved_state;
+ } else {
+ priv->away_saved_state = priv->state;
+ }
+
+ new_state = TP_CONNECTION_PRESENCE_TYPE_AWAY;
+ if (priv->state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
+ new_state = TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY;
+ }
+
+ DEBUG ("Going to autoaway. Saved state=%d, new state=%d",
+ priv->away_saved_state, new_state);
+ empathy_idle_set_state (idle, new_state);
+ } else if (!is_idle && priv->is_idle) {
+ const gchar *new_status;
+ /* We are no more idle, restore state */
+
+ idle_ext_away_stop (idle);
+
+ if (priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_AWAY ||
+ priv->away_saved_state == TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY) {
+ priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
+ new_status = NULL;
+ } else {
+ new_status = priv->status;
+ }
+
+ DEBUG ("Restoring state to %d, reset status to %s",
+ priv->away_saved_state, new_status);
+
+ empathy_idle_set_presence (idle,
+ priv->away_saved_state,
+ new_status);
+
+ priv->away_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
+ }
+
+ priv->is_idle = is_idle;
+}
- dbus_g_proxy_add_signal (priv->gs_proxy, "SessionIdleChanged",
- G_TYPE_BOOLEAN,
- G_TYPE_INVALID);
- 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
+idle_state_change_cb (EmpathyConnectivity *connectivity,
+ gboolean new_online,
+ EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ if (!new_online) {
+ /* We are no longer connected */
+ DEBUG ("Disconnected: Save state %d (%s)",
+ priv->state, priv->status);
+ priv->saved_state = priv->state;
+ g_free (priv->saved_status);
+ priv->saved_status = g_strdup (priv->status);
+ empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+ }
+ else if (new_online
+ && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+ /* We are now connected */
+ DEBUG ("Reconnected: Restore state %d (%s)",
+ priv->saved_state, priv->saved_status);
+ empathy_idle_set_presence (idle,
+ priv->saved_state,
+ priv->saved_status);
+ priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET;
+ g_free (priv->saved_status);
+ priv->saved_status = NULL;
+ }
}
static void
priv = GET_PRIV (object);
g_free (priv->status);
- g_free (priv->saved_status);
- g_object_unref (priv->mc);
if (priv->gs_proxy) {
g_object_unref (priv->gs_proxy);
}
+ g_signal_handler_disconnect (priv->connectivity,
+ priv->state_change_signal_id);
+ priv->state_change_signal_id = 0;
+
+ g_object_unref (priv->connectivity);
+
idle_ext_away_stop (EMPATHY_IDLE (object));
}
+static GObject *
+idle_constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
+{
+ GObject *retval;
+
+ if (idle_singleton) {
+ retval = g_object_ref (idle_singleton);
+ } else {
+ retval = G_OBJECT_CLASS (empathy_idle_parent_class)->constructor
+ (type, n_props, props);
+
+ idle_singleton = EMPATHY_IDLE (retval);
+ g_object_add_weak_pointer (retval, (gpointer) &idle_singleton);
+ }
+
+ return retval;
+}
+
static void
idle_get_property (GObject *object,
guint param_id,
switch (param_id) {
case PROP_STATE:
- g_value_set_uint (value, empathy_idle_get_state (idle));
+ g_value_set_enum (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));
+ case PROP_FLASH_STATE:
+ g_value_set_enum (value, empathy_idle_get_flash_state (idle));
+ break;
+ case PROP_AUTO_AWAY:
+ g_value_set_boolean (value, empathy_idle_get_auto_away (idle));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
switch (param_id) {
case PROP_STATE:
- empathy_idle_set_state (idle, g_value_get_uint (value));
+ empathy_idle_set_state (idle, g_value_get_enum (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));
+ case PROP_FLASH_STATE:
+ empathy_idle_set_flash_state (idle, g_value_get_enum (value));
+ break;
+ case PROP_AUTO_AWAY:
+ empathy_idle_set_auto_away (idle, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
};
}
-EmpathyIdle *
-empathy_idle_new (void)
+static void
+empathy_idle_class_init (EmpathyIdleClass *klass)
{
- static EmpathyIdle *idle = NULL;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- if (!idle) {
- idle = g_object_new (EMPATHY_TYPE_IDLE, NULL);
- g_object_add_weak_pointer (G_OBJECT (idle), (gpointer) &idle);
+ object_class->finalize = idle_finalize;
+ object_class->constructor = idle_constructor;
+ 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",
+ 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
+ TP_CONNECTION_PRESENCE_TYPE_UNSET,
+ 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_FLASH_STATE,
+ g_param_spec_uint ("flash-state",
+ "flash-state",
+ "flash-state",
+ 0, NUM_TP_CONNECTION_PRESENCE_TYPES,
+ TP_CONNECTION_PRESENCE_TYPE_UNSET,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_AUTO_AWAY,
+ g_param_spec_boolean ("auto-away",
+ "Automatic set presence to away",
+ "Should it set presence to away if inactive",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
+}
+
+static void
+empathy_idle_init (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
+ EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
+
+ idle->priv = priv;
+ priv->is_idle = FALSE;
+
+ priv->manager = empathy_account_manager_dup_singleton ();
+ priv->state = empathy_account_manager_get_global_presence (priv->manager,
+ NULL, &priv->status);
+
+
+ g_signal_connect (priv->manager, "global-presence-changed",
+ G_CALLBACK (idle_presence_changed_cb), idle);
+
+ priv->gs_proxy = dbus_g_proxy_new_for_name (tp_get_bus (),
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager/Presence",
+ "org.gnome.SessionManager.Presence");
+ if (priv->gs_proxy) {
+ dbus_g_proxy_add_signal (priv->gs_proxy, "StatusChanged",
+ G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (priv->gs_proxy, "StatusChanged",
+ G_CALLBACK (idle_session_status_changed_cb),
+ idle, NULL);
} else {
- g_object_ref (idle);
+ DEBUG ("Failed to get gs proxy");
}
- return idle;
+ priv->connectivity = empathy_connectivity_dup_singleton ();
+ priv->state_change_signal_id = g_signal_connect (priv->connectivity,
+ "state-change", G_CALLBACK (idle_state_change_cb), idle);
+}
+
+EmpathyIdle *
+empathy_idle_dup_singleton (void)
+{
+ return g_object_new (EMPATHY_TYPE_IDLE, NULL);
}
-McPresence
+TpConnectionPresenceType
empathy_idle_get_state (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
void
empathy_idle_set_state (EmpathyIdle *idle,
- McPresence state)
+ TpConnectionPresenceType state)
{
EmpathyIdlePriv *priv;
priv = GET_PRIV (idle);
- mission_control_set_presence (priv->mc,
- state,
- priv->status,
- NULL, NULL);
+ empathy_idle_set_presence (idle, state, priv->status);
}
const gchar *
priv = GET_PRIV (idle);
+ if (!priv->status) {
+ return empathy_presence_get_default_message (priv->state);
+ }
+
return priv->status;
}
priv = GET_PRIV (idle);
- mission_control_set_presence (priv->mc,
- priv->state,
- status,
- NULL, NULL);
+ empathy_idle_set_presence (idle, priv->state, status);
}
-McPresence
-empathy_idle_get_slack_state (EmpathyIdle *idle)
+TpConnectionPresenceType
+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,
- McPresence state)
+empathy_idle_set_flash_state (EmpathyIdle *idle,
+ TpConnectionPresenceType state)
{
EmpathyIdlePriv *priv;
priv = GET_PRIV (idle);
- priv->slack_state = state;
+ priv->flash_state = state;
+
+ if (state == TP_CONNECTION_PRESENCE_TYPE_UNSET) {
+ }
- g_object_notify (G_OBJECT (idle), "slack-state");
+ g_object_notify (G_OBJECT (idle), "flash-state");
}
static void
-idle_presence_changed_cb (MissionControl *mc,
- McPresence state,
- EmpathyIdle *idle)
+empathy_idle_do_set_presence (EmpathyIdle *idle,
+ TpConnectionPresenceType status_type,
+ const gchar *status_message)
{
- EmpathyIdlePriv *priv;
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+ const gchar *statuses[NUM_TP_CONNECTION_PRESENCE_TYPES] = {
+ NULL,
+ "offline",
+ "available",
+ "away",
+ "xa",
+ "hidden",
+ "busy",
+ NULL,
+ NULL,
+ };
+ const gchar *status;
- priv = GET_PRIV (idle);
+ g_assert (status_type > 0 && status_type < NUM_TP_CONNECTION_PRESENCE_TYPES);
- g_free (priv->status);
- priv->state = state;
- priv->status = mission_control_get_presence_message_actual (priv->mc, NULL);
+ status = statuses[status_type];
- if (G_STR_EMPTY (priv->status)) {
- g_free (priv->status);
- priv->status = g_strdup (gossip_presence_state_get_default_status (state));
- }
+ g_return_if_fail (status != NULL);
- g_object_notify (G_OBJECT (idle), "state");
- g_object_notify (G_OBJECT (idle), "status");
+ empathy_account_manager_request_global_presence (priv->manager,
+ status_type, status, status_message);
}
-static void
-idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
- gboolean is_idle,
- EmpathyIdle *idle)
+void
+empathy_idle_set_presence (EmpathyIdle *idle,
+ TpConnectionPresenceType state,
+ const gchar *status)
{
EmpathyIdlePriv *priv;
+ const gchar *default_status;
priv = GET_PRIV (idle);
- gossip_debug (DEBUG_DOMAIN, "Session idle state changed, %s -> %s",
- priv->is_idle ? "yes" : "no",
- is_idle ? "yes" : "no");
+ DEBUG ("Changing presence to %s (%d)", status, state);
- if (is_idle && !priv->is_idle) {
- McPresence new_state;
- /* We are now idle, set state to away */
-
- if (priv->state <= MC_PRESENCE_OFFLINE ||
- priv->state == MC_PRESENCE_HIDDEN) {
- /* We are not online so nothing to do here */
- return;
- } 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->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");
- 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 */
- idle_ext_away_stop (idle);
-
- gossip_debug (DEBUG_DOMAIN, "Restoring state to %d %s",
- priv->saved_state,
- priv->saved_status);
-
- mission_control_set_presence (priv->mc,
- priv->saved_state,
- priv->saved_status,
- NULL, NULL);
-
- g_free (priv->saved_status);
- priv->saved_status = NULL;
+ /* Do not set translated default messages */
+ default_status = empathy_presence_get_default_message (state);
+ if (!tp_strdiff (status, default_status)) {
+ status = NULL;
}
- priv->is_idle = is_idle;
-}
-
-static void
-idle_ext_away_start (EmpathyIdle *idle)
-{
- EmpathyIdlePriv *priv;
+ if (!empathy_connectivity_is_online (priv->connectivity)) {
+ DEBUG ("Empathy is not online");
- priv = GET_PRIV (idle);
+ if (tp_strdiff (priv->status, status)) {
+ g_free (priv->status);
+ priv->status = NULL;
+ if (!EMP_STR_EMPTY (status)) {
+ priv->status = g_strdup (status);
+ }
+ g_object_notify (G_OBJECT (idle), "status");
+ }
+ }
- idle_ext_away_stop (idle);
- priv->ext_away_timeout = g_timeout_add (EXT_AWAY_TIME * 1000,
- (GSourceFunc) idle_ext_away_cb,
- idle);
+ empathy_idle_do_set_presence (idle, state, status);
}
-static void
-idle_ext_away_stop (EmpathyIdle *idle)
+gboolean
+empathy_idle_get_auto_away (EmpathyIdle *idle)
{
- EmpathyIdlePriv *priv;
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
- priv = GET_PRIV (idle);
-
- if (priv->ext_away_timeout) {
- g_source_remove (priv->ext_away_timeout);
- priv->ext_away_timeout = 0;
- }
+ return priv->auto_away;
}
-static gboolean
-idle_ext_away_cb (EmpathyIdle *idle)
+void
+empathy_idle_set_auto_away (EmpathyIdle *idle,
+ gboolean auto_away)
{
- EmpathyIdlePriv *priv;
-
- priv = GET_PRIV (idle);
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
- gossip_debug (DEBUG_DOMAIN, "Going to extended autoaway");
- mission_control_set_presence (priv->mc,
- MC_PRESENCE_EXTENDED_AWAY,
- priv->saved_status,
- NULL, NULL);
+ priv->auto_away = auto_away;
- priv->ext_away_timeout = 0;
-
- return FALSE;
+ g_object_notify (G_OBJECT (idle), "auto-away");
}