diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-05-17 00:26:31 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-05-17 00:26:31 +0800 |
commit | 372008f78e3ea94a322e29cbdfe2b9c72b2433ae (patch) | |
tree | 9dc5cc42e6d3ce360ac7be635a7c3b0b59419d9e | |
parent | 979baa2249ea5918b1892b142fb5f5c4d8773bdc (diff) | |
download | gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar.gz gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar.bz2 gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar.lz gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar.xz gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.tar.zst gsoc2013-empathy-372008f78e3ea94a322e29cbdfe2b9c72b2433ae.zip |
New object EmpathyIdle to manage autoaway and extended autoaway states.
2006-05-16 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/empathy-status-icon.c:
* libempathy/empathy-idle.c:
* libempathy/empathy-idle.h:
* libempathy/Makefile.am:
* po/POTFILES.in: New object EmpathyIdle to manage autoaway and
extended autoaway states.
svn path=/trunk/; revision=70
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | data/salut.profile | 2 | ||||
-rw-r--r-- | libempathy-gtk/empathy-status-icon.c | 7 | ||||
-rw-r--r-- | libempathy/Makefile.am | 1 | ||||
-rw-r--r-- | libempathy/empathy-idle.c | 226 | ||||
-rw-r--r-- | libempathy/empathy-idle.h | 54 | ||||
-rw-r--r-- | po/POTFILES.in | 1 |
7 files changed, 298 insertions, 2 deletions
@@ -1,3 +1,12 @@ +2006-05-16 Xavier Claessens <xclaesse@gmail.com> + + * libempathy-gtk/empathy-status-icon.c: + * libempathy/empathy-idle.c: + * libempathy/empathy-idle.h: + * libempathy/Makefile.am: + * po/POTFILES.in: New object EmpathyIdle to manage autoaway and + extended autoaway states. + 2006-05-15 Xavier Claessens <xclaesse@gmail.com> * configure.ac: diff --git a/data/salut.profile b/data/salut.profile index 22c9c1867..2082881ee 100644 --- a/data/salut.profile +++ b/data/salut.profile @@ -2,6 +2,6 @@ Manager=salut Protocol=salut DisplayName=Salut -IconName = im-jabber +IconName = empathy-proto-jabber ConfigurationUI = salut diff --git a/libempathy-gtk/empathy-status-icon.c b/libempathy-gtk/empathy-status-icon.c index 5b764c6cf..21082276a 100644 --- a/libempathy-gtk/empathy-status-icon.c +++ b/libempathy-gtk/empathy-status-icon.c @@ -24,7 +24,6 @@ #include <string.h> -#include <glib/gi18n.h> #include <gtk/gtk.h> #include <glade/glade.h> @@ -33,6 +32,7 @@ #include <libempathy/gossip-debug.h> #include <libempathy/gossip-utils.h> #include <libempathy/gossip-conf.h> +#include <libempathy/empathy-idle.h> #include "empathy-status-icon.h" #include "gossip-presence-chooser.h" @@ -40,6 +40,7 @@ #include "gossip-ui-utils.h" #include "gossip-accounts-dialog.h" + #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ EMPATHY_TYPE_STATUS_ICON, EmpathyStatusIconPriv)) @@ -48,6 +49,8 @@ struct _EmpathyStatusIconPriv { MissionControl *mc; GtkStatusIcon *icon; + EmpathyIdle *idle; + GtkWindow *window; GtkWidget *popup_menu; @@ -102,6 +105,7 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) priv->icon = gtk_status_icon_new (); priv->mc = gossip_mission_control_new (); + priv->idle = empathy_idle_new (); status_icon_create_menu (icon); @@ -135,6 +139,7 @@ status_icon_finalize (GObject *object) g_object_unref (priv->mc); g_object_unref (priv->icon); g_object_unref (priv->window); + g_object_unref (priv->idle); } EmpathyStatusIcon * diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 9ce202733..4f1f1aadc 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -28,6 +28,7 @@ libempathy_la_SOURCES = \ empathy-contact-manager.c empathy-contact-manager.h \ empathy-tp-chat.c empathy-tp-chat.h \ empathy-chandler.c empathy-chandler.h \ + empathy-idle.c empathy-idle.h \ empathy-marshal-main.c libempathy_la_LIBADD = \ diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c new file mode 100644 index 000000000..80d75740a --- /dev/null +++ b/libempathy/empathy-idle.c @@ -0,0 +1,226 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 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 program 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. + * + * 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 <dbus/dbus-glib.h> + +#include <libtelepathy/tp-helpers.h> + +#include <libmissioncontrol/mission-control.h> + +#include "empathy-idle.h" +#include "gossip-utils.h" +#include "gossip-debug.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + EMPATHY_TYPE_IDLE, EmpathyIdlePriv)) + +#define DEBUG_DOMAIN "Idle" + +/* Number of seconds before entering extended autoaway. */ +#define EXT_AWAY_TIME (30*60) + +enum { + LAST_SIGNAL +}; + +struct _EmpathyIdlePriv { + MissionControl *mc; + DBusGProxy *gs_proxy; + gboolean is_active; + McPresence last_state; + gchar *last_status; + 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_active_changed_cb (DBusGProxy *gs_proxy, + gboolean is_active, + 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); + +//static guint signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT) + +static void +empathy_idle_class_init (EmpathyIdleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = idle_finalize; + + g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv)); +} + +static void +empathy_idle_init (EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); + + priv->is_active = FALSE; + priv->mc = gossip_mission_control_new (); + 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"); + return; + } + + dbus_g_proxy_add_signal (priv->gs_proxy, "ActiveChanged", + G_TYPE_BOOLEAN, + G_TYPE_INVALID); + dbus_g_proxy_connect_signal (priv->gs_proxy, "ActiveChanged", + G_CALLBACK (idle_active_changed_cb), + idle, NULL); +} + +static void +idle_finalize (GObject *object) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (object); + + g_free (priv->last_status); + g_object_unref (priv->mc); + + if (priv->gs_proxy) { + g_object_unref (priv->gs_proxy); + } + + idle_ext_away_stop (EMPATHY_IDLE (object)); +} + +EmpathyIdle * +empathy_idle_new (void) +{ + static EmpathyIdle *idle = NULL; + + if (!idle) { + idle = g_object_new (EMPATHY_TYPE_IDLE, NULL); + g_object_add_weak_pointer (G_OBJECT (idle), (gpointer) &idle); + } else { + g_object_ref (idle); + } + + return idle; +} + +static void +idle_active_changed_cb (DBusGProxy *gs_proxy, + gboolean is_active, + EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); + + gossip_debug (DEBUG_DOMAIN, "Screensaver state changed, %s -> %s", + priv->is_active ? "yes" : "no", + is_active ? "yes" : "no"); + + if (is_active && !priv->is_active) { + /* The screensaver is now running */ + g_free (priv->last_status); + idle_ext_away_stop (idle); + + priv->last_state = mission_control_get_presence_actual (priv->mc, NULL); + priv->last_status = mission_control_get_presence_message_actual (priv->mc, NULL); + + gossip_debug (DEBUG_DOMAIN, "Going to autoaway"); + mission_control_set_presence (priv->mc, + MC_PRESENCE_AWAY, + _("Autoaway"), + NULL, NULL); + idle_ext_away_start (idle); + } else if (!is_active && priv->is_active) { + /* The screensaver stoped */ + idle_ext_away_stop (idle); + + gossip_debug (DEBUG_DOMAIN, "Restoring state to %d %s", + priv->last_state, + priv->last_status); + + mission_control_set_presence (priv->mc, + priv->last_state, + priv->last_status, + NULL, NULL); + } + + priv->is_active = is_active; +} + +static void +idle_ext_away_start (EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); + + idle_ext_away_stop (idle); + priv->ext_away_timeout = g_timeout_add (EXT_AWAY_TIME * 1000, + (GSourceFunc) idle_ext_away_cb, + idle); +} + +static void +idle_ext_away_stop (EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); + + if (priv->ext_away_timeout) { + g_source_remove (priv->ext_away_timeout); + priv->ext_away_timeout = 0; + } +} + +static gboolean +idle_ext_away_cb (EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv; + + priv = GET_PRIV (idle); + + gossip_debug (DEBUG_DOMAIN, "Going to extended autoaway"); + mission_control_set_presence (priv->mc, + MC_PRESENCE_EXTENDED_AWAY, + _("Extended autoaway"), + NULL, NULL); + + priv->ext_away_timeout = 0; + + return FALSE; +} + diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h new file mode 100644 index 000000000..df8846b9b --- /dev/null +++ b/libempathy/empathy-idle.h @@ -0,0 +1,54 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 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 program 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. + * + * 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> + */ + +#ifndef __EMPATHY_IDLE_H__ +#define __EMPATHY_IDLE_H__ + +#include <glib.h> + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_IDLE (empathy_idle_get_type ()) +#define EMPATHY_IDLE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_IDLE, EmpathyIdle)) +#define EMPATHY_IDLE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_IDLE, EmpathyIdleClass)) +#define EMPATHY_IS_IDLE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_IDLE)) +#define EMPATHY_IS_IDLE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_IDLE)) +#define EMPATHY_IDLE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IDLE, EmpathyIdleClass)) + +typedef struct _EmpathyIdle EmpathyIdle; +typedef struct _EmpathyIdleClass EmpathyIdleClass; +typedef struct _EmpathyIdlePriv EmpathyIdlePriv; + +struct _EmpathyIdle { + GObject parent; +}; + +struct _EmpathyIdleClass { + GObjectClass parent_class; +}; + +GType empathy_idle_get_type (void) G_GNUC_CONST; +EmpathyIdle *empathy_idle_new (void); + +G_END_DECLS + +#endif /* __EMPATHY_IDLE_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index 7079f4cb3..5ca5eb807 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -4,6 +4,7 @@ data/empathy.desktop.in data/empathy.schemas.in +libempathy/empathy-idle.c libempathy/gossip-contact.c libempathy/gossip-presence.c |