aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-21 03:46:29 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-21 03:46:29 +0800
commitdf31bb8cc736b500215a52b27d14f13acb8ecf6e (patch)
tree61a97eaa1add6dc5cef0ea30e13890b186a4f175
parent6ce393073158d07d797f189fe5b4e34c683c2049 (diff)
downloadgsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar.gz
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar.bz2
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar.lz
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar.xz
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.tar.zst
gsoc2013-empathy-df31bb8cc736b500215a52b27d14f13acb8ecf6e.zip
Adding NetworkManager support.
2007-06-15 Xavier Claessens <xclaesse@gmail.com> * src/empathy.c: * libempathy/empathy-idle.c: Adding NetworkManager support. svn path=/trunk/; revision=162
-rw-r--r--ChangeLog5
-rw-r--r--libempathy/empathy-idle.c154
-rw-r--r--src/empathy.c38
3 files changed, 133 insertions, 64 deletions
diff --git a/ChangeLog b/ChangeLog
index 92580a5ad..b7ef27693 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2007-06-15 Xavier Claessens <xclaesse@gmail.com>
+ * src/empathy.c:
+ * libempathy/empathy-idle.c: Adding NetworkManager support.
+
+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:
diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c
index b0984b077..8150effd3 100644
--- a/libempathy/empathy-idle.c
+++ b/libempathy/empathy-idle.c
@@ -22,6 +22,8 @@
#include <config.h>
+#include <string.h>
+
#include <glib/gi18n.h>
#include <dbus/dbus-glib.h>
@@ -39,19 +41,25 @@
/* Number of seconds before entering extended autoaway. */
#define EXT_AWAY_TIME (30*60)
-enum {
- LAST_SIGNAL
-};
+typedef enum {
+ NM_STATE_UNKNOWN = 0,
+ NM_STATE_ASLEEP,
+ NM_STATE_CONNECTING,
+ NM_STATE_CONNECTED,
+ NM_STATE_DISCONNECTED
+} NMState;
struct _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 nm_connected;
guint ext_away_timeout;
};
@@ -72,6 +80,9 @@ static void idle_presence_changed_cb (MissionControl *mc,
static void idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
gboolean is_idle,
EmpathyIdle *idle);
+static void idle_nm_state_change_cb (DBusGProxy *proxy,
+ guint state,
+ 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);
@@ -127,6 +138,8 @@ static void
empathy_idle_init (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
+ DBusGConnection *system_bus;
+ GError *error = NULL;
priv = GET_PRIV (idle);
@@ -135,25 +148,48 @@ empathy_idle_init (EmpathyIdle *idle)
priv->state = mission_control_get_presence_actual (priv->mc, NULL);
idle_presence_changed_cb (priv->mc, priv->state, idle);
+ dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
+ "PresenceStatusActual",
+ G_CALLBACK (idle_presence_changed_cb),
+ idle, 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) {
+ if (priv->gs_proxy) {
+ 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);
+ } else {
gossip_debug (DEBUG_DOMAIN, "Failed to get gs proxy");
- return;
}
- 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);
+
+ system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (!system_bus) {
+ gossip_debug (DEBUG_DOMAIN, "Failed to get system bus: %s",
+ error ? error->message : "No error given");
+ } else {
+ priv->nm_proxy = dbus_g_proxy_new_for_name (system_bus,
+ "org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager",
+ "org.freedesktop.NetworkManager");
+ }
+ if (priv->nm_proxy) {
+ dbus_g_proxy_add_signal (priv->nm_proxy, "StateChange",
+ G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (priv->nm_proxy, "StateChange",
+ G_CALLBACK (idle_nm_state_change_cb),
+ idle, NULL);
+ } else {
+ gossip_debug (DEBUG_DOMAIN, "Failed to get nm proxy");
+ }
+ /* FIXME: get value */
+ priv->nm_connected = TRUE;
}
static void
@@ -263,10 +299,7 @@ empathy_idle_set_state (EmpathyIdle *idle,
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 *
@@ -276,6 +309,10 @@ empathy_idle_get_status (EmpathyIdle *idle)
priv = GET_PRIV (idle);
+ if (!priv->status) {
+ return gossip_presence_state_get_default_status (priv->state);
+ }
+
return priv->status;
}
@@ -287,10 +324,7 @@ empathy_idle_set_status (EmpathyIdle *idle,
priv = GET_PRIV (idle);
- mission_control_set_presence (priv->mc,
- priv->state,
- status,
- NULL, NULL);
+ empathy_idle_set_presence (idle, priv->state, status);
}
McPresence
@@ -325,9 +359,23 @@ empathy_idle_set_presence (EmpathyIdle *idle,
const gchar *status)
{
EmpathyIdlePriv *priv;
+ const gchar *default_status;
priv = GET_PRIV (idle);
+ if (!priv->nm_connected) {
+ g_free (priv->saved_status);
+ priv->saved_state = state;
+ priv->saved_status = g_strdup (status);
+ return;
+ }
+
+ /* Do not set translated default messages */
+ default_status = gossip_presence_state_get_default_status (state);
+ if (status && strcmp (status, default_status) == 0) {
+ status = NULL;
+ }
+
mission_control_set_presence (priv->mc,
state,
status,
@@ -349,7 +397,7 @@ idle_presence_changed_cb (MissionControl *mc,
if (G_STR_EMPTY (priv->status)) {
g_free (priv->status);
- priv->status = g_strdup (gossip_presence_state_get_default_status (state));
+ priv->status = NULL;
}
g_object_notify (G_OBJECT (idle), "state");
@@ -369,15 +417,18 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
priv->is_idle ? "yes" : "no",
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->is_idle = is_idle;
+ return;
+ }
+
if (is_idle && !priv->is_idle) {
McPresence new_state;
/* We are now idle */
- 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 ||
+ if (priv->state == MC_PRESENCE_AWAY ||
priv->state == MC_PRESENCE_EXTENDED_AWAY) {
/* User set away manually, when coming back we restore
* default presence. */
@@ -402,10 +453,9 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
priv->saved_state,
priv->saved_status);
- mission_control_set_presence (priv->mc,
- priv->saved_state,
- priv->saved_status,
- NULL, NULL);
+ empathy_idle_set_presence (idle,
+ priv->saved_state,
+ priv->saved_status);
g_free (priv->saved_status);
priv->saved_status = NULL;
@@ -415,6 +465,38 @@ idle_session_idle_changed_cb (DBusGProxy *gs_proxy,
}
static void
+idle_nm_state_change_cb (DBusGProxy *proxy,
+ guint state,
+ EmpathyIdle *idle)
+{
+ EmpathyIdlePriv *priv;
+
+ priv = GET_PRIV (idle);
+
+ gossip_debug (DEBUG_DOMAIN, "New network state (%d)", state);
+
+ if (state != NM_STATE_CONNECTED &&
+ priv->state > MC_PRESENCE_OFFLINE) {
+ /* We are no more connected */
+ idle_ext_away_stop (idle);
+ g_free (priv->saved_status);
+ priv->saved_state = priv->state;
+ priv->saved_status = g_strdup (priv->status);
+
+ empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
+ priv->nm_connected = FALSE;
+ }
+ else if (priv->state <= MC_PRESENCE_OFFLINE &&
+ state == NM_STATE_CONNECTED) {
+ /* We are now connected */
+ priv->nm_connected = TRUE;
+ empathy_idle_set_presence (idle,
+ priv->saved_state,
+ priv->saved_status);
+ }
+}
+
+static void
idle_ext_away_start (EmpathyIdle *idle)
{
EmpathyIdlePriv *priv;
@@ -448,11 +530,7 @@ idle_ext_away_cb (EmpathyIdle *idle)
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);
-
+ empathy_idle_set_state (idle, MC_PRESENCE_EXTENDED_AWAY);
priv->ext_away_timeout = 0;
return FALSE;
diff --git a/src/empathy.c b/src/empathy.c
index 51fa25937..91152daa2 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -43,6 +43,7 @@
#include <libempathy/gossip-contact.h>
#include <libempathy/empathy-chandler.h>
#include <libempathy/empathy-tp-chat.h>
+#include <libempathy/empathy-idle.h>
#include <libempathy-gtk/empathy-main-window.h>
#include <libempathy-gtk/empathy-status-icon.h>
#include <libempathy-gtk/gossip-private-chat.h>
@@ -54,16 +55,6 @@
#define OBJECT_PATH "/org/freedesktop/Telepathy/ChannelHandler"
static void
-error_cb (MissionControl *mc,
- GError *error,
- gpointer data)
-{
- if (error) {
- gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
- }
-}
-
-static void
service_ended_cb (MissionControl *mc,
gpointer user_data)
{
@@ -82,33 +73,27 @@ operation_error_cb (MissionControl *mc,
}
static void
-start_mission_control (MissionControl *mc)
+start_mission_control (EmpathyIdle *idle)
{
McPresence presence;
- presence = mission_control_get_presence_actual (mc, NULL);
+ presence = empathy_idle_get_state (idle);
if (presence > MC_PRESENCE_OFFLINE) {
/* MC is already running and online, nothing to do */
return;
}
- gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
-
- mission_control_set_presence (mc,
- MC_PRESENCE_AVAILABLE,
- NULL,
- (McCallback) error_cb,
- NULL);
+ empathy_idle_set_state (idle, MC_PRESENCE_AVAILABLE);
}
static void
account_enabled_cb (McAccountMonitor *monitor,
gchar *unique_name,
- MissionControl *mc)
+ EmpathyIdle *idle)
{
gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
- start_mission_control (mc);
+ start_mission_control (idle);
}
static void
@@ -164,6 +149,7 @@ main (int argc, char *argv[])
GtkWidget *window;
MissionControl *mc;
McAccountMonitor *monitor;
+ EmpathyIdle *idle;
EmpathyChandler *chandler;
GnomeProgram *program;
gboolean no_connect = FALSE;
@@ -201,9 +187,10 @@ main (int argc, char *argv[])
/* Setting up MC */
monitor = mc_account_monitor_new ();
mc = gossip_mission_control_new ();
+ idle = empathy_idle_new ();
g_signal_connect (monitor, "account-enabled",
G_CALLBACK (account_enabled_cb),
- mc);
+ idle);
g_signal_connect (mc, "ServiceEnded",
G_CALLBACK (service_ended_cb),
NULL);
@@ -212,7 +199,7 @@ main (int argc, char *argv[])
NULL);
if (!no_connect) {
- start_mission_control (mc);
+ start_mission_control (idle);
}
/* Setting up UI */
@@ -227,13 +214,12 @@ main (int argc, char *argv[])
gtk_main ();
- mission_control_set_presence (mc,
- MC_PRESENCE_OFFLINE,
- NULL, NULL, NULL);
+ empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
g_object_unref (chandler);
g_object_unref (monitor);
g_object_unref (mc);
+ g_object_unref (idle);
g_object_unref (icon);
g_object_unref (program);