/*
* 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 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 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.
+ * 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
*
* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include <dbus/dbus-glib.h>
#include <libtelepathy/tp-helpers.h>
+#include <libmissioncontrol/mc-enum-types.h>
#include "empathy-idle.h"
#include "empathy-utils.h"
#include "empathy-debug.h"
-/* FIXME mission-control does not install libmissioncontrol/mc-enum-types.h so
- * we have to define MC_TYPE_PRESENCE here. See sf.net bug #1768235,
- * https://sf.net/tracker/?func=detail&atid=932444&aid=1768235&group_id=190214 */
-#ifndef MC_TYPE_PRESENCE
-GType mc_presence_get_type (void) G_GNUC_CONST;
-#define MC_TYPE_PRESENCE (mc_presence_get_type())
-#endif
-
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
EMPATHY_TYPE_IDLE, EmpathyIdlePriv))
MissionControl *mc;
DBusGProxy *gs_proxy;
DBusGProxy *nm_proxy;
- gboolean is_idle;
McPresence state;
McPresence flash_state;
gchar *status;
McPresence saved_state;
gchar *saved_status;
+ gboolean is_idle;
gboolean nm_connected;
+ gboolean auto_away;
+ gboolean auto_disconnect;
guint ext_away_timeout;
};
PROP_0,
PROP_STATE,
PROP_STATUS,
- PROP_FLASH_STATE
+ PROP_FLASH_STATE,
+ PROP_AUTO_AWAY,
+ PROP_AUTO_DISCONNECT
};
G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT)
MC_PRESENCE_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_object_class_install_property (object_class,
+ PROP_AUTO_DISCONNECT,
+ g_param_spec_boolean ("auto-disconnect",
+ "Automatic set presence to offline",
+ "Should it set presence to offline if NM is disconnected",
+ FALSE,
+ G_PARAM_READWRITE));
+
g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv));
}
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;
+ case PROP_AUTO_DISCONNECT:
+ g_value_set_boolean (value, empathy_idle_get_auto_disconnect (idle));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
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);
break;
NULL, NULL);
}
+gboolean
+empathy_idle_get_auto_away (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ return priv->auto_away;
+}
+
+void
+empathy_idle_set_auto_away (EmpathyIdle *idle,
+ gboolean auto_away)
+{
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ priv->auto_away = auto_away;
+
+ g_object_notify (G_OBJECT (idle), "auto-away");
+}
+
+gboolean
+empathy_idle_get_auto_disconnect (EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ return priv->auto_disconnect;
+}
+
+void
+empathy_idle_set_auto_disconnect (EmpathyIdle *idle,
+ gboolean auto_disconnect)
+{
+ EmpathyIdlePriv *priv = GET_PRIV (idle);
+
+ priv->auto_disconnect = auto_disconnect;
+
+ g_object_notify (G_OBJECT (idle), "auto-disconnect");
+}
+
static void
idle_presence_changed_cb (MissionControl *mc,
McPresence state,
is_idle ? "yes" : "no");
if (priv->state <= MC_PRESENCE_OFFLINE ||
- priv->state == MC_PRESENCE_HIDDEN) {
- /* We are not online so nothing to do here */
+ priv->state == MC_PRESENCE_HIDDEN ||
+ !priv->auto_away) {
+ /* We are not online or we don't want to go auto away,
+ * nothing to do here */
priv->is_idle = is_idle;
return;
}
empathy_debug (DEBUG_DOMAIN, "New network state (%d)", state);
+ if (!priv->auto_disconnect) {
+ return;
+ }
+
if (state != NM_STATE_CONNECTED && priv->nm_connected) {
/* We are no more connected */
idle_ext_away_stop (idle);
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);
+ priv->ext_away_timeout = g_timeout_add_seconds (EXT_AWAY_TIME,
+ (GSourceFunc) idle_ext_away_cb,
+ idle);
}
static void