From 381d68e40a9ead2b8217c4f4da856c972d5d3228 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 18 Aug 2009 15:34:41 +0100 Subject: empathy-connectivity: add initial stubs Signed-off-by: Jonny Lamb --- libempathy/Makefile.am | 2 + libempathy/empathy-connectivity.c | 129 ++++++++++++++++++++++++++++++++++++++ libempathy/empathy-connectivity.h | 65 +++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 libempathy/empathy-connectivity.c create mode 100644 libempathy/empathy-connectivity.h (limited to 'libempathy') diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 27671543a..7600ee5d4 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -31,6 +31,7 @@ libempathy_la_SOURCES = \ empathy-chatroom-manager.c \ empathy-call-factory.c \ empathy-call-handler.c \ + empathy-connectivity.c \ empathy-contact.c \ empathy-contact-groups.c \ empathy-contact-list.c \ @@ -82,6 +83,7 @@ libempathy_headers = \ empathy-chatroom-manager.h \ empathy-call-factory.h \ empathy-call-handler.h \ + empathy-connectivity.h \ empathy-contact.h \ empathy-contact-groups.h \ empathy-contact-list.h \ diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c new file mode 100644 index 000000000..264b58d06 --- /dev/null +++ b/libempathy/empathy-connectivity.c @@ -0,0 +1,129 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * 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 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 + * 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 + * + * Authors: Jonny Lamb + */ + +#include "config.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +#include + +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConnectivity) + +typedef struct { + gboolean dispose_run; +} EmpathyConnectivityPriv; + +enum { + STATE_CHANGE, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL]; +static EmpathyConnectivity *connectivity_singleton = NULL; + +G_DEFINE_TYPE (EmpathyConnectivity, empathy_connectivity, G_TYPE_OBJECT); + +static void +empathy_connectivity_init (EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (connectivity, + EMPATHY_TYPE_CONNECTIVITY, EmpathyConnectivityPriv); + + connectivity->priv = priv; + priv->dispose_run = FALSE; +} + +static void +connectivity_finalize (GObject *object) +{ + EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (obj); + EmpathyConnectivityPriv *priv = GET_PRIV (manager); + + G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (obj); +} + +static void +connectivity_dispose (GObject *object) +{ + EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (obj); + EmpathyConnectivityPriv *priv = GET_PRIV (manager); + + if (priv->dispose_run) + return; + + priv->dispose_run = TRUE; + + G_OBJECT_CLASS (empathy_connectivity_parent_class)->dispose (obj); +} + +static GObject * +connectivity_constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *retval; + + if (!manager_singleton) + { + retval = G_OBJECT_CLASS (empathy_connectivity_parent_class)->constructor + (type, n_construct_params, construct_params); + + manager_singleton = EMPATHY_CONNECTIVITY (retval); + g_object_add_weak_pointer (retval, (gpointer) &manager_singleton); + } + else + { + retval = g_object_ref (manager_singleton); + } + + return retval; +} + +static void +empathy_connectivity_class_init (EmpathyConnectivityClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS (klass); + + oclass->finalize = connectivity_finalize; + oclass->dispose = connectivity_dispose; + oclass->constructor = connectivity_constructor; + + signals[STATE_CHANGE] = + g_signal_new ("state-change", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, /* TODO */ + G_TYPE_NONE, + 0, NULL); + + g_type_class_add_private (oclass, sizeof (EmpathyConnectivityPriv)); +} + +/* public methods */ + +EmpathyConnectivity * +empathy_connectivity_dup_singleton (void) +{ + return g_object_new (EMPATHY_TYPE_CONNECTIVITY, NULL); +} diff --git a/libempathy/empathy-connectivity.h b/libempathy/empathy-connectivity.h new file mode 100644 index 000000000..391c6597f --- /dev/null +++ b/libempathy/empathy-connectivity.h @@ -0,0 +1,65 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ +/* + * Copyright (C) 2009 Collabora Ltd. + * + * 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 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 + * 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 + * + * Authors: Jonny Lamb + */ + +#ifndef __EMPATHY_CONNECTIVITY_H__ +#define __EMPATHY_CONNECTIVITY_H__ + +#include + +G_BEGIN_DECLS + +#define EMPATHY_TYPE_CONNECTIVITY (empathy_connectivity_get_type ()) +#define EMPATHY_CONNECTIVITY(o) \ + (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CONNECTIVITY, \ + EmpathyConnectivity)) +#define EMPATHY_CONNECTIVITY_CLASS(k) \ + (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_CONNECTIVITY, \ + EmpathyConnectivityClass)) +#define EMPATHY_IS_CONNECTIVITY(o) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CONNECTIVITY)) +#define EMPATHY_IS_CONNECTIVITY_CLASS(k) \ + (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CONNECTIVITY)) +#define EMPATHY_CONNECTIVITY_GET_CLASS(o) \ + (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CONNECTIVITY, \ + EmpathyConnectivityClass)) + +typedef struct _EmpathyConnectivity EmpathyConnectivity; +typedef struct _EmpathyConnectivityClass EmpathyConnectivityClass; + +struct _EmpathyConnectivity { + GObject parent; + gpointer priv; +}; + +struct _EmpathyConnectivityClass { + GObjectClass parent_class; +}; + +GType empathy_connectivity_get_type (void); + +/* public methods */ + +EmpathyConnectivity * empathy_connectivity_dup_singleton (void); + +G_END_DECLS + +#endif /* __EMPATHY_CONNECTIVITY_H__ */ + -- cgit v1.2.3 From b6385d57ac531ea4dde4e6bf5478fc47924bcb07 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 18 Aug 2009 16:56:54 +0100 Subject: empathy-debug: add connectivity debug key Signed-off-by: Jonny Lamb --- libempathy/empathy-debug.c | 1 + libempathy/empathy-debug.h | 1 + 2 files changed, 2 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-debug.c b/libempathy/empathy-debug.c index 99111deec..9d69b801c 100644 --- a/libempathy/empathy-debug.c +++ b/libempathy/empathy-debug.c @@ -49,6 +49,7 @@ static GDebugKey keys[] = { { "Ft", EMPATHY_DEBUG_FT }, { "Location", EMPATHY_DEBUG_LOCATION }, { "Other", EMPATHY_DEBUG_OTHER }, + { "Connectivity", EMPATHY_DEBUG_CONNECTIVITY }, { 0, } }; diff --git a/libempathy/empathy-debug.h b/libempathy/empathy-debug.h index 0d25f22dd..edfa05d95 100644 --- a/libempathy/empathy-debug.h +++ b/libempathy/empathy-debug.h @@ -42,6 +42,7 @@ typedef enum EMPATHY_DEBUG_LOCATION = 1 << 8, EMPATHY_DEBUG_OTHER = 1 << 9, EMPATHY_DEBUG_SHARE_DESKTOP = 1 << 10, + EMPATHY_DEBUG_CONNECTIVITY = 1 << 11, } EmpathyDebugFlags; gboolean empathy_debug_flag_is_set (EmpathyDebugFlags flag); -- cgit v1.2.3 From e3279de0b6781be33abf59a7d4efcb728765a9fc Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 18 Aug 2009 18:23:54 +0100 Subject: empathy-connectivity: add signals, properties and hook in NM Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 192 +++++++++++++++++++++++++++++++++++--- libempathy/empathy-connectivity.h | 6 ++ 2 files changed, 186 insertions(+), 12 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 264b58d06..47d02989e 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -20,13 +20,27 @@ */ #include "config.h" +#include "empathy-connectivity.h" -#define DEBUG_FLAG EMPATHY_DEBUG_OTHER -#include +#ifdef HAVE_NM +#include +#endif + +#include "empathy-utils.h" +#include "empathy-marshal.h" + +#define DEBUG_FLAG EMPATHY_DEBUG_CONNECTIVITY +#include "empathy-debug.h" #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyConnectivity) typedef struct { +#ifdef HAVE_NM + NMClient *nm_client; +#endif + + gboolean connected; + gboolean use_conn; gboolean dispose_run; } EmpathyConnectivityPriv; @@ -35,11 +49,47 @@ enum { LAST_SIGNAL }; +enum { + PROP_0, + PROP_USE_CONN, +}; + static guint signals[LAST_SIGNAL]; static EmpathyConnectivity *connectivity_singleton = NULL; G_DEFINE_TYPE (EmpathyConnectivity, empathy_connectivity, G_TYPE_OBJECT); +#ifdef HAVE_NM +static void +connectivity_nm_state_change_cb (NMClient *client, + const GParamSpec *pspec, + EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv; + gboolean old_nm_connected; + gboolean new_nm_connected; + NMState state; + + priv = GET_PRIV (connectivity); + + if (!priv->use_conn) + return; + + state = nm_client_get_state (priv->nm_client); + old_nm_connected = priv->connected; + new_nm_connected = state == NM_STATE_CONNECTED; + new_nm_connected = !(state == NM_STATE_CONNECTING + || state == NM_STATE_DISCONNECTED); + + DEBUG ("New NetworkManager network state %d", state); + + priv->connected = new_nm_connected; + + g_signal_emit (connectivity, signals[STATE_CHANGE], 0, + old_nm_connected, new_nm_connected); +} +#endif + static void empathy_connectivity_init (EmpathyConnectivity *connectivity) { @@ -50,21 +100,40 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) connectivity->priv = priv; priv->dispose_run = FALSE; + +#ifdef HAVE_NM + priv->nm_client = nm_client_new (); + if (priv->nm_client != NULL) + { + g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE, + G_CALLBACK (connectivity_nm_state_change_cb), connectivity); + } + else + { + DEBUG ("Failed to get NetworkManager proxy"); + } +#endif } static void connectivity_finalize (GObject *object) { - EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (obj); + EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (object); EmpathyConnectivityPriv *priv = GET_PRIV (manager); - G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (obj); + if (priv->nm_client != NULL) + { + g_object_unref (priv->nm_client); + priv->nm_client = NULL; + } + + G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (object); } static void connectivity_dispose (GObject *object) { - EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (obj); + EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (object); EmpathyConnectivityPriv *priv = GET_PRIV (manager); if (priv->dispose_run) @@ -72,7 +141,7 @@ connectivity_dispose (GObject *object) priv->dispose_run = TRUE; - G_OBJECT_CLASS (empathy_connectivity_parent_class)->dispose (obj); + G_OBJECT_CLASS (empathy_connectivity_parent_class)->dispose (object); } static GObject * @@ -82,22 +151,62 @@ connectivity_constructor (GType type, { GObject *retval; - if (!manager_singleton) + if (!connectivity_singleton) { retval = G_OBJECT_CLASS (empathy_connectivity_parent_class)->constructor (type, n_construct_params, construct_params); - manager_singleton = EMPATHY_CONNECTIVITY (retval); - g_object_add_weak_pointer (retval, (gpointer) &manager_singleton); + connectivity_singleton = EMPATHY_CONNECTIVITY (retval); + g_object_add_weak_pointer (retval, (gpointer) &connectivity_singleton); } else { - retval = g_object_ref (manager_singleton); + retval = g_object_ref (connectivity_singleton); } return retval; } +static void +connectivity_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); + + switch (param_id) + { + case PROP_USE_CONN: + g_value_set_boolean (value, empathy_connectivity_get_use_conn ( + connectivity)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +connectivity_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); + + switch (param_id) + { + case PROP_USE_CONN: + empathy_connectivity_set_use_conn (connectivity, + g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + static void empathy_connectivity_class_init (EmpathyConnectivityClass *klass) { @@ -106,6 +215,8 @@ empathy_connectivity_class_init (EmpathyConnectivityClass *klass) oclass->finalize = connectivity_finalize; oclass->dispose = connectivity_dispose; oclass->constructor = connectivity_constructor; + oclass->get_property = connectivity_get_property; + oclass->set_property = connectivity_set_property; signals[STATE_CHANGE] = g_signal_new ("state-change", @@ -113,9 +224,17 @@ empathy_connectivity_class_init (EmpathyConnectivityClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, /* TODO */ + _empathy_marshal_VOID__BOOLEAN_BOOLEAN, G_TYPE_NONE, - 0, NULL); + 2, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, NULL); + + g_object_class_install_property (oclass, + PROP_USE_CONN, + g_param_spec_boolean ("use-conn", + "Use connectivity managers", + "Set presence according to connectivity managers", + TRUE, + G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); g_type_class_add_private (oclass, sizeof (EmpathyConnectivityPriv)); } @@ -127,3 +246,52 @@ empathy_connectivity_dup_singleton (void) { return g_object_new (EMPATHY_TYPE_CONNECTIVITY, NULL); } + +gboolean +empathy_connectivity_is_online (EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); + + if (priv->use_conn) + { +#ifdef HAVE_NM + return priv->connected; +#else + return TRUE; +#endif + } + else + { + return TRUE; + } +} + +gboolean +empathy_connectivity_get_use_conn (EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); + + return priv->use_conn; +} + +void +empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, + gboolean use_conn) +{ + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); + + if (use_conn == priv->use_conn) + return; + + DEBUG ("use_conn gconf key changed; new value = %s", + use_conn ? "true" : "false"); + + priv->use_conn = use_conn; + +#ifdef HAVE_NM + if (use_conn) + connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); +#endif + + g_object_notify (G_OBJECT (connectivity), "use-conn"); +} diff --git a/libempathy/empathy-connectivity.h b/libempathy/empathy-connectivity.h index 391c6597f..ca507e910 100644 --- a/libempathy/empathy-connectivity.h +++ b/libempathy/empathy-connectivity.h @@ -59,6 +59,12 @@ GType empathy_connectivity_get_type (void); EmpathyConnectivity * empathy_connectivity_dup_singleton (void); +gboolean empathy_connectivity_is_online (EmpathyConnectivity *connectivity); + +gboolean empathy_connectivity_get_use_conn (EmpathyConnectivity *connectivity); +void empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, + gboolean use_conn); + G_END_DECLS #endif /* __EMPATHY_CONNECTIVITY_H__ */ -- cgit v1.2.3 From 21eba5b7a86ad221efd3738d415cd56eb0ee98b8 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Tue, 18 Aug 2009 18:24:48 +0100 Subject: empathy-idle: use EmpathyConnectivity instead of messing with NM itself Signed-off-by: Jonny Lamb --- libempathy/empathy-idle.c | 172 +++++++++++++--------------------------------- libempathy/empathy-idle.h | 3 - 2 files changed, 49 insertions(+), 126 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 5d2fa2bdc..7757b7bdf 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -25,9 +25,6 @@ #include #include -#ifdef HAVE_NM -#include -#endif #include #include @@ -35,6 +32,7 @@ #include "empathy-idle.h" #include "empathy-utils.h" +#include "empathy-connectivity.h" #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include "empathy-debug.h" @@ -46,22 +44,18 @@ typedef struct { MissionControl *mc; DBusGProxy *gs_proxy; -#ifdef HAVE_NM - NMClient *nm_client; -#endif + EmpathyConnectivity *connectivity; TpConnectionPresenceType state; gchar *status; TpConnectionPresenceType flash_state; gboolean auto_away; - gboolean use_nm; TpConnectionPresenceType away_saved_state; - TpConnectionPresenceType nm_saved_state; - gchar *nm_saved_status; + TpConnectionPresenceType saved_state; + gchar *saved_status; gboolean is_idle; - gboolean nm_connected; guint ext_away_timeout; } EmpathyIdlePriv; @@ -78,8 +72,7 @@ enum { PROP_STATE, PROP_STATUS, PROP_FLASH_STATE, - PROP_AUTO_AWAY, - PROP_USE_NM + PROP_AUTO_AWAY }; G_DEFINE_TYPE (EmpathyIdle, empathy_idle, G_TYPE_OBJECT); @@ -172,7 +165,7 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy, is_idle ? "yes" : "no"); if (!priv->auto_away || - (priv->nm_saved_state == TP_CONNECTION_PRESENCE_TYPE_UNSET && + (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 @@ -187,11 +180,11 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy, idle_ext_away_start (idle); - if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { + 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->nm_saved_state; + priv->away_saved_state = priv->saved_state; } else { priv->away_saved_state = priv->state; } @@ -231,56 +224,38 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy, priv->is_idle = is_idle; } -#ifdef HAVE_NM static void -idle_nm_state_change_cb (NMClient *client, - const GParamSpec *pspec, - EmpathyIdle *idle) +idle_state_change_cb (EmpathyConnectivity *connectivity, + gboolean old_online, + gboolean new_online, + EmpathyIdle *idle) { EmpathyIdlePriv *priv; - gboolean old_nm_connected; - gboolean new_nm_connected; - NMState state; priv = GET_PRIV (idle); - if (!priv->use_nm) { - return; - } - - state = nm_client_get_state (priv->nm_client); - old_nm_connected = priv->nm_connected; - new_nm_connected = !(state == NM_STATE_CONNECTING || - state == NM_STATE_DISCONNECTED); - priv->nm_connected = TRUE; /* To be sure _set_state will work */ - - DEBUG ("New network state %d", state); - - if (old_nm_connected && !new_nm_connected) { - /* We are no more connected */ + if (old_online && !new_online) { + /* We are no longer connected */ DEBUG ("Disconnected: Save state %d (%s)", priv->state, priv->status); - priv->nm_saved_state = priv->state; - g_free (priv->nm_saved_status); - priv->nm_saved_status = g_strdup (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 (!old_nm_connected && new_nm_connected - && priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { + else if (!old_online && new_online + && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { /* We are now connected */ DEBUG ("Reconnected: Restore state %d (%s)", - priv->nm_saved_state, priv->nm_saved_status); + priv->saved_state, priv->saved_status); empathy_idle_set_presence (idle, - priv->nm_saved_state, - priv->nm_saved_status); - priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; - g_free (priv->nm_saved_status); - priv->nm_saved_status = NULL; + priv->saved_state, + priv->saved_status); + priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; + g_free (priv->saved_status); + priv->saved_status = NULL; } - - priv->nm_connected = new_nm_connected; } -#endif static void idle_finalize (GObject *object) @@ -296,11 +271,7 @@ idle_finalize (GObject *object) g_object_unref (priv->gs_proxy); } -#ifdef HAVE_NM - if (priv->nm_client) { - g_object_unref (priv->nm_client); - } -#endif + g_object_unref (priv->connectivity); idle_ext_away_stop (EMPATHY_IDLE (object)); } @@ -350,9 +321,6 @@ idle_get_property (GObject *object, case PROP_AUTO_AWAY: g_value_set_boolean (value, empathy_idle_get_auto_away (idle)); break; - case PROP_USE_NM: - g_value_set_boolean (value, empathy_idle_get_use_nm (idle)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -384,9 +352,6 @@ idle_set_property (GObject *object, case PROP_AUTO_AWAY: empathy_idle_set_auto_away (idle, g_value_get_boolean (value)); break; - case PROP_USE_NM: - empathy_idle_set_use_nm (idle, g_value_get_boolean (value)); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; @@ -435,14 +400,6 @@ empathy_idle_class_init (EmpathyIdleClass *klass) FALSE, G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_USE_NM, - g_param_spec_boolean ("use-nm", - "Use Network Manager", - "Set presence according to Network Manager", - TRUE, - G_PARAM_CONSTRUCT | G_PARAM_READWRITE)); - g_type_class_add_private (object_class, sizeof (EmpathyIdlePriv)); } @@ -472,6 +429,22 @@ empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error) } } +static void +idle_use_conn_cb (GObject *object, + GParamSpec *pspec, + EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv = GET_PRIV (idle); + + if (!empathy_connectivity_get_use_conn (priv->connectivity)) { + if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { + empathy_idle_set_state (idle, priv->saved_state); + } + + priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; + } +} + static void empathy_idle_init (EmpathyIdle *idle) { @@ -522,16 +495,11 @@ empathy_idle_init (EmpathyIdle *idle) DEBUG ("Failed to get gs proxy"); } -#ifdef HAVE_NM - priv->nm_client = nm_client_new (); - if (priv->nm_client) { - g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE, - G_CALLBACK (idle_nm_state_change_cb), - idle); - } else { - DEBUG ("Failed to get nm proxy"); - } -#endif + priv->connectivity = empathy_connectivity_dup_singleton (); + g_signal_connect (priv->connectivity, "state-change", + G_CALLBACK (idle_state_change_cb), idle); + g_signal_connect (priv->connectivity, "notify::use-conn", + G_CALLBACK (idle_use_conn_cb), idle); } EmpathyIdle * @@ -664,10 +632,9 @@ empathy_idle_set_presence (EmpathyIdle *idle, status = NULL; } - if (!priv->nm_connected) { - DEBUG ("NM not connected"); + if (!empathy_connectivity_is_online (priv->connectivity)) { + DEBUG ("Empathy is not online"); - priv->nm_saved_state = state; if (tp_strdiff (priv->status, status)) { g_free (priv->status); priv->status = NULL; @@ -676,8 +643,6 @@ empathy_idle_set_presence (EmpathyIdle *idle, } g_object_notify (G_OBJECT (idle), "status"); } - - return; } empathy_idle_do_set_presence (idle, state, status); @@ -702,42 +667,3 @@ empathy_idle_set_auto_away (EmpathyIdle *idle, g_object_notify (G_OBJECT (idle), "auto-away"); } -gboolean -empathy_idle_get_use_nm (EmpathyIdle *idle) -{ - EmpathyIdlePriv *priv = GET_PRIV (idle); - - return priv->use_nm; -} - -void -empathy_idle_set_use_nm (EmpathyIdle *idle, - gboolean use_nm) -{ - EmpathyIdlePriv *priv = GET_PRIV (idle); - -#ifdef HAVE_NM - if (!priv->nm_client || use_nm == priv->use_nm) { - return; - } -#endif - - priv->use_nm = use_nm; - -#ifdef HAVE_NM - if (use_nm) { - idle_nm_state_change_cb (priv->nm_client, NULL, idle); -#else - if (0) { -#endif - } else { - priv->nm_connected = TRUE; - if (priv->nm_saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { - empathy_idle_set_state (idle, priv->nm_saved_state); - } - priv->nm_saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; - } - - g_object_notify (G_OBJECT (idle), "use-nm"); -} - diff --git a/libempathy/empathy-idle.h b/libempathy/empathy-idle.h index 0f7f23deb..d0b426e59 100644 --- a/libempathy/empathy-idle.h +++ b/libempathy/empathy-idle.h @@ -64,9 +64,6 @@ void empathy_idle_set_presence (EmpathyIdle *idle, gboolean empathy_idle_get_auto_away (EmpathyIdle *idle); void empathy_idle_set_auto_away (EmpathyIdle *idle, gboolean auto_away); -gboolean empathy_idle_get_use_nm (EmpathyIdle *idle); -void empathy_idle_set_use_nm (EmpathyIdle *idle, - gboolean use_nm); G_END_DECLS -- cgit v1.2.3 From 394527fe9f0394c41fcf980bba3668d84434040f Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 11:51:27 +0100 Subject: empathy-idle: disconnect from connectivity signals before unreffing Signed-off-by: Jonny Lamb --- libempathy/empathy-idle.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 7757b7bdf..5f38e941b 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -257,6 +257,22 @@ idle_state_change_cb (EmpathyConnectivity *connectivity, } } +static void +idle_use_conn_cb (GObject *object, + GParamSpec *pspec, + EmpathyIdle *idle) +{ + EmpathyIdlePriv *priv = GET_PRIV (idle); + + if (!empathy_connectivity_get_use_conn (priv->connectivity)) { + if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { + empathy_idle_set_state (idle, priv->saved_state); + } + + priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; + } +} + static void idle_finalize (GObject *object) { @@ -271,6 +287,11 @@ idle_finalize (GObject *object) g_object_unref (priv->gs_proxy); } + g_signal_handlers_disconnect_by_func (priv->connectivity, + idle_state_change_cb, object); + g_signal_handlers_disconnect_by_func (priv->connectivity, + idle_use_conn_cb, object); + g_object_unref (priv->connectivity); idle_ext_away_stop (EMPATHY_IDLE (object)); @@ -429,22 +450,6 @@ empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error) } } -static void -idle_use_conn_cb (GObject *object, - GParamSpec *pspec, - EmpathyIdle *idle) -{ - EmpathyIdlePriv *priv = GET_PRIV (idle); - - if (!empathy_connectivity_get_use_conn (priv->connectivity)) { - if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { - empathy_idle_set_state (idle, priv->saved_state); - } - - priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; - } -} - static void empathy_idle_init (EmpathyIdle *idle) { -- cgit v1.2.3 From d183b3dbbdd4bf1aea48eff08ae33ddd27f23e57 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 12:00:50 +0100 Subject: empathy-connectivity: handle changes in use_conn correctly This is so that the presence chooser can get notified if use_conn turns to false, and NM still reports us as offline, so it can become sensitive again. Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 47d02989e..b06b57cb8 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -290,8 +290,18 @@ empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, #ifdef HAVE_NM if (use_conn) - connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); + { + connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); +#else + if (FALSE) + { #endif + } + else + { + g_signal_emit (connectivity, signals[STATE_CHANGE], 0, + FALSE, TRUE); + } g_object_notify (G_OBJECT (connectivity), "use-conn"); } -- cgit v1.2.3 From d12645619d0fcf721d9edcdb8b7893e27364e17f Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 13:30:23 +0100 Subject: empathy-connectivity: only unref the NM client if we're using NM Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index b06b57cb8..a1f0383c7 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -118,6 +118,7 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) static void connectivity_finalize (GObject *object) { +#ifdef HAVE_NM EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (object); EmpathyConnectivityPriv *priv = GET_PRIV (manager); @@ -126,6 +127,7 @@ connectivity_finalize (GObject *object) g_object_unref (priv->nm_client); priv->nm_client = NULL; } +#endif G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (object); } -- cgit v1.2.3 From 0d6ea34bb155e74a5ceac71cea9c550d7baaa85a Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 13:40:13 +0100 Subject: empathy-connectivity: disconnect from NM state change signal on finalize Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index a1f0383c7..b724865ba 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -124,6 +124,8 @@ connectivity_finalize (GObject *object) if (priv->nm_client != NULL) { + g_signal_handlers_disconnect_by_func (priv->nm_client, + connectivity_nm_state_change_cb, manager); g_object_unref (priv->nm_client); priv->nm_client = NULL; } -- cgit v1.2.3 From bbe5b582755870e4e3d4865f49d8ef9bb5db0b8d Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 14:39:55 +0100 Subject: empathy-connectivity: stop using the name "manager" when I mean "connectivity" Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index b724865ba..b38ee2d5d 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -119,13 +119,13 @@ static void connectivity_finalize (GObject *object) { #ifdef HAVE_NM - EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (object); - EmpathyConnectivityPriv *priv = GET_PRIV (manager); + EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); if (priv->nm_client != NULL) { g_signal_handlers_disconnect_by_func (priv->nm_client, - connectivity_nm_state_change_cb, manager); + connectivity_nm_state_change_cb, connectivity); g_object_unref (priv->nm_client); priv->nm_client = NULL; } @@ -137,8 +137,8 @@ connectivity_finalize (GObject *object) static void connectivity_dispose (GObject *object) { - EmpathyConnectivity *manager = EMPATHY_CONNECTIVITY (object); - EmpathyConnectivityPriv *priv = GET_PRIV (manager); + EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); if (priv->dispose_run) return; -- cgit v1.2.3 From 6013dce0de5f8046d0b1318b7d01d672eac45b91 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 14:40:26 +0100 Subject: empathy-connectivity: remove useless assignment Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 1 - 1 file changed, 1 deletion(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index b38ee2d5d..4e75d7d76 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -77,7 +77,6 @@ connectivity_nm_state_change_cb (NMClient *client, state = nm_client_get_state (priv->nm_client); old_nm_connected = priv->connected; - new_nm_connected = state == NM_STATE_CONNECTED; new_nm_connected = !(state == NM_STATE_CONNECTING || state == NM_STATE_DISCONNECTED); -- cgit v1.2.3 From 1f9772288086230ec9b8ac63380ad90d413b73c0 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 15:01:16 +0100 Subject: empathy-connectivity: init priv->connected to TRUE if we're not using NM Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 4e75d7d76..e9734e5db 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -111,6 +111,8 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) { DEBUG ("Failed to get NetworkManager proxy"); } +#else + priv->connected = TRUE; #endif } @@ -257,11 +259,7 @@ empathy_connectivity_is_online (EmpathyConnectivity *connectivity) if (priv->use_conn) { -#ifdef HAVE_NM return priv->connected; -#else - return TRUE; -#endif } else { -- cgit v1.2.3 From 1b6dc82801e05a9afe5495e05e4918e19a44bdfe Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 15:08:52 +0100 Subject: empathy-connectivity: be sure to get the initial presence on init Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index e9734e5db..27f4e1f17 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -100,12 +100,16 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) connectivity->priv = priv; priv->dispose_run = FALSE; + priv->use_conn = TRUE; + #ifdef HAVE_NM priv->nm_client = nm_client_new (); if (priv->nm_client != NULL) { g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE, G_CALLBACK (connectivity_nm_state_change_cb), connectivity); + + connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); } else { -- cgit v1.2.3 From 6d55ee1e5cfce1655ed34b8e36ef23167a7d9818 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 15:15:59 +0100 Subject: empathy-connectivity: remove dispose_run Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 27f4e1f17..8c38cf2c3 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -41,7 +41,6 @@ typedef struct { gboolean connected; gboolean use_conn; - gboolean dispose_run; } EmpathyConnectivityPriv; enum { @@ -98,7 +97,6 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) EMPATHY_TYPE_CONNECTIVITY, EmpathyConnectivityPriv); connectivity->priv = priv; - priv->dispose_run = FALSE; priv->use_conn = TRUE; @@ -142,14 +140,6 @@ connectivity_finalize (GObject *object) static void connectivity_dispose (GObject *object) { - EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); - EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); - - if (priv->dispose_run) - return; - - priv->dispose_run = TRUE; - G_OBJECT_CLASS (empathy_connectivity_parent_class)->dispose (object); } -- cgit v1.2.3 From 363e6b81d004687f286fcd30322e94bd15c14e8f Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 15:22:05 +0100 Subject: empathy-idle: no need to listen to use-conn If use_conn is set to FALSE, then EmpathyConnectivity will signal status-change with a new online status of TRUE, which will do the right thing. Signed-off-by: Jonny Lamb --- libempathy/empathy-idle.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index 5f38e941b..c3e6b0177 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -257,22 +257,6 @@ idle_state_change_cb (EmpathyConnectivity *connectivity, } } -static void -idle_use_conn_cb (GObject *object, - GParamSpec *pspec, - EmpathyIdle *idle) -{ - EmpathyIdlePriv *priv = GET_PRIV (idle); - - if (!empathy_connectivity_get_use_conn (priv->connectivity)) { - if (priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { - empathy_idle_set_state (idle, priv->saved_state); - } - - priv->saved_state = TP_CONNECTION_PRESENCE_TYPE_UNSET; - } -} - static void idle_finalize (GObject *object) { @@ -289,8 +273,6 @@ idle_finalize (GObject *object) g_signal_handlers_disconnect_by_func (priv->connectivity, idle_state_change_cb, object); - g_signal_handlers_disconnect_by_func (priv->connectivity, - idle_use_conn_cb, object); g_object_unref (priv->connectivity); @@ -503,8 +485,6 @@ empathy_idle_init (EmpathyIdle *idle) priv->connectivity = empathy_connectivity_dup_singleton (); g_signal_connect (priv->connectivity, "state-change", G_CALLBACK (idle_state_change_cb), idle); - g_signal_connect (priv->connectivity, "notify::use-conn", - G_CALLBACK (idle_use_conn_cb), idle); } EmpathyIdle * -- cgit v1.2.3 From c98e85dcf635914dc66755d6a8560e2d370cfffe Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 16:50:14 +0100 Subject: empathy-connectivity: only send the new state in the state-change signal It can be assumed that the old state was always the opposite to the new state, because the signal is only ever fired if the new state differs from the old state. Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 31 +++++++++++++++++++++---------- libempathy/empathy-idle.c | 5 ++--- 2 files changed, 23 insertions(+), 13 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 8c38cf2c3..82ac9c9cb 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -58,6 +58,23 @@ static EmpathyConnectivity *connectivity_singleton = NULL; G_DEFINE_TYPE (EmpathyConnectivity, empathy_connectivity, G_TYPE_OBJECT); +static void +connectivity_change_state (EmpathyConnectivity *connectivity, + gboolean new_state) +{ + EmpathyConnectivityPriv *priv; + + priv = GET_PRIV (connectivity); + + if (priv->connected == new_state) + return; + + priv->connected = new_state; + + g_signal_emit (connectivity, signals[STATE_CHANGE], 0, + priv->connected); +} + #ifdef HAVE_NM static void connectivity_nm_state_change_cb (NMClient *client, @@ -65,7 +82,6 @@ connectivity_nm_state_change_cb (NMClient *client, EmpathyConnectivity *connectivity) { EmpathyConnectivityPriv *priv; - gboolean old_nm_connected; gboolean new_nm_connected; NMState state; @@ -75,16 +91,12 @@ connectivity_nm_state_change_cb (NMClient *client, return; state = nm_client_get_state (priv->nm_client); - old_nm_connected = priv->connected; new_nm_connected = !(state == NM_STATE_CONNECTING || state == NM_STATE_DISCONNECTED); DEBUG ("New NetworkManager network state %d", state); - priv->connected = new_nm_connected; - - g_signal_emit (connectivity, signals[STATE_CHANGE], 0, - old_nm_connected, new_nm_connected); + connectivity_change_state (connectivity, new_nm_connected); } #endif @@ -223,9 +235,9 @@ empathy_connectivity_class_init (EmpathyConnectivityClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _empathy_marshal_VOID__BOOLEAN_BOOLEAN, + _empathy_marshal_VOID__BOOLEAN, G_TYPE_NONE, - 2, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, NULL); + 1, G_TYPE_BOOLEAN, NULL); g_object_class_install_property (oclass, PROP_USE_CONN, @@ -294,8 +306,7 @@ empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, } else { - g_signal_emit (connectivity, signals[STATE_CHANGE], 0, - FALSE, TRUE); + connectivity_change_state (connectivity, TRUE); } g_object_notify (G_OBJECT (connectivity), "use-conn"); diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index c3e6b0177..f408cf69b 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -226,7 +226,6 @@ idle_session_status_changed_cb (DBusGProxy *gs_proxy, static void idle_state_change_cb (EmpathyConnectivity *connectivity, - gboolean old_online, gboolean new_online, EmpathyIdle *idle) { @@ -234,7 +233,7 @@ idle_state_change_cb (EmpathyConnectivity *connectivity, priv = GET_PRIV (idle); - if (old_online && !new_online) { + if (!new_online) { /* We are no longer connected */ DEBUG ("Disconnected: Save state %d (%s)", priv->state, priv->status); @@ -243,7 +242,7 @@ idle_state_change_cb (EmpathyConnectivity *connectivity, priv->saved_status = g_strdup (priv->status); empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_OFFLINE); } - else if (!old_online && new_online + else if (new_online && priv->saved_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) { /* We are now connected */ DEBUG ("Reconnected: Restore state %d (%s)", -- cgit v1.2.3 From 8e549e268287120c56eb2dbc25b9d70dadb895f2 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 17:07:48 +0100 Subject: all: save the signal id and use that to disconnect from the signal Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 9 ++++++--- libempathy/empathy-idle.c | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 82ac9c9cb..8cc1d26bb 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -37,6 +37,7 @@ typedef struct { #ifdef HAVE_NM NMClient *nm_client; + gulong state_change_signal_id; #endif gboolean connected; @@ -116,7 +117,8 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) priv->nm_client = nm_client_new (); if (priv->nm_client != NULL) { - g_signal_connect (priv->nm_client, "notify::" NM_CLIENT_STATE, + priv->state_change_signal_id = g_signal_connect (priv->nm_client, + "notify::" NM_CLIENT_STATE, G_CALLBACK (connectivity_nm_state_change_cb), connectivity); connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); @@ -139,8 +141,9 @@ connectivity_finalize (GObject *object) if (priv->nm_client != NULL) { - g_signal_handlers_disconnect_by_func (priv->nm_client, - connectivity_nm_state_change_cb, connectivity); + g_signal_handler_disconnect (priv->nm_client, + priv->state_change_signal_id); + priv->state_change_signal_id = 0; g_object_unref (priv->nm_client); priv->nm_client = NULL; } diff --git a/libempathy/empathy-idle.c b/libempathy/empathy-idle.c index f408cf69b..ac0ca72f6 100644 --- a/libempathy/empathy-idle.c +++ b/libempathy/empathy-idle.c @@ -45,6 +45,7 @@ typedef struct { MissionControl *mc; DBusGProxy *gs_proxy; EmpathyConnectivity *connectivity; + gulong state_change_signal_id; TpConnectionPresenceType state; gchar *status; @@ -270,8 +271,9 @@ idle_finalize (GObject *object) g_object_unref (priv->gs_proxy); } - g_signal_handlers_disconnect_by_func (priv->connectivity, - idle_state_change_cb, object); + g_signal_handler_disconnect (priv->connectivity, + priv->state_change_signal_id); + priv->state_change_signal_id = 0; g_object_unref (priv->connectivity); @@ -482,8 +484,8 @@ empathy_idle_init (EmpathyIdle *idle) } priv->connectivity = empathy_connectivity_dup_singleton (); - g_signal_connect (priv->connectivity, "state-change", - G_CALLBACK (idle_state_change_cb), idle); + priv->state_change_signal_id = g_signal_connect (priv->connectivity, + "state-change", G_CALLBACK (idle_state_change_cb), idle); } EmpathyIdle * -- cgit v1.2.3 From 4b87ece33144d35023b713d8e7d1be9262bc272a Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 17:08:49 +0100 Subject: empathy-connectivity: small style fix Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 8cc1d26bb..60d938b58 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -302,12 +302,9 @@ empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, if (use_conn) { connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); -#else - if (FALSE) - { -#endif } else +#endif { connectivity_change_state (connectivity, TRUE); } -- cgit v1.2.3 From 094a490dac0da29d685e5f1cbb06bc6caa588d3a Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 13:31:21 +0100 Subject: configure: enable connectivity building with nm, connman, auto or none Signed-off-by: Jonny Lamb --- libempathy/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libempathy') diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am index 7600ee5d4..0250a63d8 100644 --- a/libempathy/Makefile.am +++ b/libempathy/Makefile.am @@ -10,7 +10,8 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\"empathy\" \ $(LIBEMPATHY_CFLAGS) \ $(GEOCLUE_CFLAGS) \ - $(NETWORK_MANAGER_CFLAGS) \ + $(NETWORK_MANAGER_CFLAGS) \ + $(CONNMAN_CFLAGS) \ $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED) @@ -70,7 +71,8 @@ libempathy_la_LIBADD = \ $(top_builddir)/extensions/libemp-extensions.la \ $(LIBEMPATHY_LIBS) \ $(GEOCLUE_LIBS) \ - $(NETWORK_MANAGER_LIBS) + $(NETWORK_MANAGER_LIBS) \ + $(CONNMAN_LIBS) libempathy_la_LDFLAGS = \ -version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} \ -- cgit v1.2.3 From 4be054d9317f3f35c5fc799556f85f880e1761bf Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 14:45:48 +0100 Subject: empathy-connectivity: add ConnMan support Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 122 +++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index 60d938b58..f033e42e8 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -26,6 +26,12 @@ #include #endif +#ifdef HAVE_CONNMAN +#include +#endif + +#include + #include "empathy-utils.h" #include "empathy-marshal.h" @@ -40,6 +46,10 @@ typedef struct { gulong state_change_signal_id; #endif +#ifdef HAVE_CONNMAN + DBusGProxy *proxy; +#endif + gboolean connected; gboolean use_conn; } EmpathyConnectivityPriv; @@ -101,10 +111,70 @@ connectivity_nm_state_change_cb (NMClient *client, } #endif +#ifdef HAVE_CONNMAN +static void +connectivity_connman_state_changed_cb (DBusGProxy *proxy, + const gchar *new_state, + EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv; + gboolean new_connected; + + priv = GET_PRIV (connectivity); + + if (!priv->use_conn) + return; + + new_connected = !tp_strdiff (new_state, "online"); + + DEBUG ("New ConnMan network state %s", new_state); + + connectivity_change_state (connectivity, new_connected); +} + +static void +connectivity_connman_check_state_cb (DBusGProxy *proxy, + DBusGProxyCall *call_id, + gpointer user_data) +{ + EmpathyConnectivity *connectivity = (EmpathyConnectivity *) user_data; + GError *error = NULL; + gchar *state; + + if (dbus_g_proxy_end_call (proxy, call_id, &error, + G_TYPE_STRING, &state, G_TYPE_INVALID)) + { + connectivity_connman_state_changed_cb (proxy, state, + connectivity); + g_free (state); + } + else + { + DEBUG ("Failed to call GetState: %s", error->message); + } +} + +static void +connectivity_connman_check_state (EmpathyConnectivity *connectivity) +{ + EmpathyConnectivityPriv *priv; + + priv = GET_PRIV (connectivity); + + dbus_g_proxy_begin_call (priv->proxy, "GetState", + connectivity_connman_check_state_cb, connectivity, NULL, + G_TYPE_INVALID); +} +#endif + static void empathy_connectivity_init (EmpathyConnectivity *connectivity) { EmpathyConnectivityPriv *priv; +#ifdef HAVE_CONNMAN + DBusGConnection *connection; + GError *error = NULL; +#endif priv = G_TYPE_INSTANCE_GET_PRIVATE (connectivity, EMPATHY_TYPE_CONNECTIVITY, EmpathyConnectivityPriv); @@ -127,7 +197,37 @@ empathy_connectivity_init (EmpathyConnectivity *connectivity) { DEBUG ("Failed to get NetworkManager proxy"); } -#else +#endif + +#ifdef HAVE_CONNMAN + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + if (connection != NULL) + { + priv->proxy = dbus_g_proxy_new_for_name (connection, + "org.moblin.connman", "/", + "org.moblin.connman.Manager"); + + dbus_g_object_register_marshaller ( + _empathy_marshal_VOID__STRING, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID); + + dbus_g_proxy_add_signal (priv->proxy, "StateChanged", + G_TYPE_STRING, G_TYPE_INVALID); + + dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", + G_CALLBACK (connectivity_connman_state_changed_cb), + connectivity, NULL); + + connectivity_connman_check_state (connectivity); + } + else + { + DEBUG ("Failed to get system bus connection: %s", error->message); + g_error_free (error); + } +#endif + +#if !defined(HAVE_NM) || !defined(HAVE_CONNMAN) priv->connected = TRUE; #endif } @@ -149,6 +249,20 @@ connectivity_finalize (GObject *object) } #endif +#ifdef HAVE_CONNMAN + EmpathyConnectivity *connectivity = EMPATHY_CONNECTIVITY (object); + EmpathyConnectivityPriv *priv = GET_PRIV (connectivity); + + if (priv->proxy != NULL) + { + dbus_g_proxy_disconnect_signal (priv->proxy, "StateChanged", + G_CALLBACK (connectivity_connman_state_changed_cb), connectivity); + + g_object_unref (priv->proxy); + priv->proxy = NULL; + } +#endif + G_OBJECT_CLASS (empathy_connectivity_parent_class)->finalize (object); } @@ -298,10 +412,14 @@ empathy_connectivity_set_use_conn (EmpathyConnectivity *connectivity, priv->use_conn = use_conn; -#ifdef HAVE_NM +#if defined(HAVE_NM) || defined(HAVE_CONNMAN) if (use_conn) { +#if defined(HAVE_NM) connectivity_nm_state_change_cb (priv->nm_client, NULL, connectivity); +#elif defined(HAVE_CONNMAN) + connectivity_connman_check_state (connectivity); +#endif } else #endif -- cgit v1.2.3 From 98bdc25304295c21761ee6d5547273d5f077f61b Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Wed, 19 Aug 2009 16:54:10 +0100 Subject: empathy-connectivity: assume status is offline if GetState fails Signed-off-by: Jonny Lamb --- libempathy/empathy-connectivity.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libempathy') diff --git a/libempathy/empathy-connectivity.c b/libempathy/empathy-connectivity.c index f033e42e8..bbbcba467 100644 --- a/libempathy/empathy-connectivity.c +++ b/libempathy/empathy-connectivity.c @@ -151,6 +151,8 @@ connectivity_connman_check_state_cb (DBusGProxy *proxy, else { DEBUG ("Failed to call GetState: %s", error->message); + connectivity_connman_state_changed_cb (proxy, "offline", + connectivity); } } -- cgit v1.2.3