]> git.0d.be Git - empathy.git/commitdiff
Optionally use libnm-glib for NetworkManager integration
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 30 Jun 2009 14:57:06 +0000 (15:57 +0100)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>
Tue, 30 Jun 2009 17:20:49 +0000 (18:20 +0100)
Previously Empathy use the NM D-Bus interface directly. Unfortunately the d-bus
calls used were deprecated and somewhat buggy (if NM wasn't running on empathy
startup, it would never detect network changes).

Given that NetworkManager isn't a blessed gnome dependency the code has been
made optional, but it's expected that every distribution will build with
NetworkManager integration anyway.

Based on a patch by Tambet Ingo <tambet@novell.com>. Fixes #587446

configure.ac
libempathy/Makefile.am
libempathy/empathy-idle.c

index df6ec7ec0e49f8764fbe4a04cad0bab76584f436..0dab5e4fc97441c23172d3c4548fe5029340b204 100644 (file)
@@ -40,6 +40,7 @@ LIBCHAMPLAIN_GTK_REQUIRED=0.3.3
 CLUTTER_GTK_REQUIRED=0.8.2
 GEOCLUE_REQUIRED=0.11
 WEBKIT_REQUIRED=1.1.7
+NETWORK_MANAGER_REQUIRED=0.7.0
 
 # Use --enable-maintainer-mode to disabled deprecated symbols
 GNOME_MAINTAINER_MODE_DEFINES
@@ -155,6 +156,32 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[Gettext package name])
 
 AM_GLIB_GNU_GETTEXT
 
+# -----------------------------------------------------------
+# NM integration
+# -----------------------------------------------------------
+AC_ARG_ENABLE(network-manager,
+              AS_HELP_STRING([--enable-network-manager=@<:@no/yes/auto@:>@],
+                             [build with network-manager support]), ,
+                             enable_webkit=auto)
+
+if test "x$enable_network_manager" != "xno"; then
+   PKG_CHECK_MODULES(NETWORK_MANAGER,
+   [
+      libnm_glib >= $NETWORK_MANAGER_REQUIRED
+   ], have_nm="yes", have_nm="no")
+
+   if test "x$have_nm" = "xyes"; then
+      AC_DEFINE(HAVE_NM, 1, [Define if you have libnm-glib])
+   fi
+else
+   have_nm=no
+fi
+
+if test "x$enable_network_manager" = "xyes" -a "x$have_nm" != "xyes"; then
+   AC_MSG_ERROR([Couldn't find libnm-glib dependencies.])
+fi
+AM_CONDITIONAL(HAVE_NM, test "x$have_NM" = "xyes")
+
 # -----------------------------------------------------------
 # Webkit
 # -----------------------------------------------------------
@@ -179,7 +206,6 @@ fi
 if test "x$enable_webkit" = "xyes" -a "x$have_webkit" != "xyes"; then
    AC_MSG_ERROR([Couldn't find webkit dependencies.])
 fi
-
 AM_CONDITIONAL(HAVE_WEBKIT, test "x$have_webkit" = "xyes")
 
 # -----------------------------------------------------------
@@ -453,6 +479,7 @@ Configure summary:
        Display maps (libchamplain).:  ${have_libchamplain}
        Location awareness (Geoclue):  ${have_geoclue}
        Adium themes (Webkit).......:  ${have_webkit}
+       NetworkManager integration..:  ${have_nm}
 
     Extras:
        Documentation...............:  ${enable_gtk_doc}
index 87b7284643ebe58a4531569c58c45fcbf24461cd..2877dc6ae6a401b64a9a00bf6410d371267d511f 100644 (file)
@@ -10,6 +10,7 @@ AM_CPPFLAGS =                                           \
        -DG_LOG_DOMAIN=\"empathy\"                      \
        $(LIBEMPATHY_CFLAGS)                            \
        $(GEOCLUE_CFLAGS)                               \
+       $(NETWORK_MANAGER_CFLAGS) \
        $(WARN_CFLAGS)                                  \
        $(DISABLE_DEPRECATED)
 
@@ -65,7 +66,8 @@ nodist_libempathy_la_SOURCES =\
 libempathy_la_LIBADD =         \
        $(top_builddir)/extensions/libemp-extensions.la \
        $(LIBEMPATHY_LIBS) \
-       $(GEOCLUE_LIBS)
+       $(GEOCLUE_LIBS) \
+       $(NETWORK_MANAGER_LIBS)
 
 libempathy_la_LDFLAGS =                \
        -version-info ${LIBEMPATHY_CURRENT}:${LIBEMPATHY_REVISION}:${LIBEMPATHY_AGE} \
index 2ed1440fc8690d04584a8317a6256cb904e5b144..78366e02177034f490d53428cd92a77e46bdaba8 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <glib/gi18n-lib.h>
 #include <dbus/dbus-glib.h>
+#ifdef HAVE_NM
+#include <nm-client.h>
+#endif
 
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/util.h>
@@ -43,7 +46,9 @@
 typedef struct {
        MissionControl *mc;
        DBusGProxy     *gs_proxy;
-       DBusGProxy     *nm_proxy;
+#ifdef HAVE_NM
+       NMClient       *nm_client;
+#endif
 
        TpConnectionPresenceType      state;
        gchar          *status;
@@ -60,14 +65,6 @@ typedef struct {
        guint           ext_away_timeout;
 } EmpathyIdlePriv;
 
-typedef enum {
-       NM_STATE_UNKNOWN,
-       NM_STATE_ASLEEP,
-       NM_STATE_CONNECTING,
-       NM_STATE_CONNECTED,
-       NM_STATE_DISCONNECTED
-} NMState;
-
 typedef enum {
        SESSION_STATUS_AVAILABLE,
        SESSION_STATUS_INVISIBLE,
@@ -234,14 +231,16 @@ idle_session_status_changed_cb (DBusGProxy    *gs_proxy,
        priv->is_idle = is_idle;
 }
 
+#ifdef HAVE_NM
 static void
-idle_nm_state_change_cb (DBusGProxy  *proxy,
-                        guint        state,
-                        EmpathyIdle *idle)
+idle_nm_state_change_cb (NMClient         *client,
+                        const GParamSpec *pspec,
+                        EmpathyIdle      *idle)
 {
        EmpathyIdlePriv *priv;
        gboolean         old_nm_connected;
        gboolean         new_nm_connected;
+       NMState          state;
 
        priv = GET_PRIV (idle);
 
@@ -250,6 +249,7 @@ idle_nm_state_change_cb (DBusGProxy  *proxy,
                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);
@@ -280,6 +280,7 @@ idle_nm_state_change_cb (DBusGProxy  *proxy,
 
        priv->nm_connected = new_nm_connected;
 }
+#endif
 
 static void
 idle_finalize (GObject *object)
@@ -295,6 +296,12 @@ idle_finalize (GObject *object)
                g_object_unref (priv->gs_proxy);
        }
 
+#ifdef HAVE_NM
+       if (priv->nm_client) {
+               g_object_unref (priv->nm_client);
+       }
+#endif
+
        idle_ext_away_stop (EMPATHY_IDLE (object));
 }
 
@@ -468,7 +475,6 @@ empathy_idle_get_actual_presence (EmpathyIdle *idle, GError **error)
 static void
 empathy_idle_init (EmpathyIdle *idle)
 {
-       DBusGConnection *system_bus;
        GError          *error = NULL;
        EmpathyIdlePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (idle,
                EMPATHY_TYPE_IDLE, EmpathyIdlePriv);
@@ -516,28 +522,18 @@ empathy_idle_init (EmpathyIdle *idle)
                DEBUG ("Failed to get gs proxy");
        }
 
-
-       system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
-       if (!system_bus) {
-               DEBUG ("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);
+#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");
        }
 
        priv->nm_connected = TRUE;
+#endif
 }
 
 EmpathyIdle *
@@ -722,29 +718,20 @@ empathy_idle_set_use_nm (EmpathyIdle *idle,
 {
        EmpathyIdlePriv *priv = GET_PRIV (idle);
 
-       if (!priv->nm_proxy || use_nm == priv->use_nm) {
+#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) {
-               guint   nm_status;
-               GError *error = NULL;
-
-               dbus_g_proxy_call (priv->nm_proxy, "state",
-                                  &error,
-                                  G_TYPE_INVALID,
-                                  G_TYPE_UINT, &nm_status,
-                                  G_TYPE_INVALID);
-
-               if (error) {
-                       DEBUG ("Couldn't get NM state: %s", error->message);
-                       g_clear_error (&error);
-                       nm_status = NM_STATE_ASLEEP;
-               }
-
-               idle_nm_state_change_cb (priv->nm_proxy, nm_status, idle);
+               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) {