[libsocialweb/lr/libnm] sw-online: port to libnm
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsocialweb/lr/libnm] sw-online: port to libnm
- Date: Tue, 19 Dec 2017 17:12:15 +0000 (UTC)
commit e3d22e947ff28d8a8af06555c4718dd0365ba2c2
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Tue Dec 19 18:04:06 2017 +0100
sw-online: port to libnm
libnm-glib has been deprecated for three years and is eventually going
to disappear.
configure.ac | 2 +-
libsocialweb/sw-online.c | 35 ++++++++++-------------------------
2 files changed, 11 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7eecb80..b5608a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,7 +99,7 @@ AS_CASE(["$with_online"],
["networkmanager"],
[
AC_MSG_RESULT([Network Manager])
- PKG_CHECK_MODULES(NM, libnm-glib >= 0.7)
+ PKG_CHECK_MODULES(NM, libnm >= 1.0)
AC_DEFINE([WITH_ONLINE_NM], 1, [NM online detection])
],
diff --git a/libsocialweb/sw-online.c b/libsocialweb/sw-online.c
index 6b82b02..56b796e 100644
--- a/libsocialweb/sw-online.c
+++ b/libsocialweb/sw-online.c
@@ -103,11 +103,7 @@ sw_is_online (void)
#endif
#if WITH_ONLINE_NM
-#include <libnm-glib/nm-client.h>
-
-#if !defined(NM_CHECK_VERSION)
-#define NM_CHECK_VERSION(x,y,z) 0
-#endif
+#include <NetworkManager.h>
/*
* Use NMClient since it correctly handles the NetworkManager service
@@ -139,8 +135,15 @@ state_changed (NMClient *client,
static gboolean
online_init (void)
{
+ GError *error = NULL;
+
if (!client) {
- client = nm_client_new();
+ client = nm_client_new (NULL, &error);
+ if (!client) {
+ g_printerr ("Cannot create a NetworkManager client: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
g_signal_connect (client,
"notify::" NM_CLIENT_STATE,
G_CALLBACK (state_changed),
@@ -155,25 +158,7 @@ sw_is_online (void)
if (!online_init ())
return TRUE;
- switch (nm_client_get_state (client)) {
-#if NM_CHECK_VERSION(0,8,992)
- case NM_STATE_CONNECTED_LOCAL:
- case NM_STATE_CONNECTED_SITE:
- case NM_STATE_CONNECTED_GLOBAL:
-#else
- case NM_STATE_CONNECTED:
-#endif
- return TRUE;
- case NM_STATE_CONNECTING:
- case NM_STATE_ASLEEP:
- case NM_STATE_DISCONNECTED:
-#if NM_CHECK_VERSION(0,8,992)
- case NM_STATE_DISCONNECTING:
-#endif
- case NM_STATE_UNKNOWN:
- default:
- return FALSE;
- }
+ return nm_client_get_state (client) >= NM_STATE_CONNECTED_LOCAL;
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]