[epiphany] Use a gdbus-codegen generated GDBusProxy to monitor NM state



commit 3af15cdbcd31a7ac4eda748ae83180a228d30a80
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Thu Jun 23 23:18:37 2011 +0300

    Use a gdbus-codegen generated GDBusProxy to monitor NM state
    
    Get rid of the EphyNetMonitor code and instead generate a GDBusProxy
    subclass that monitors the StateChanged signal and State property in
    org.gnome.NetworkManager. This proxy exports these features as
    standard GObject signal and property, respectively, so we can use it
    directly through the relevant accessors.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=622903

 configure.ac                  |    1 +
 data/Makefile.am              |    1 +
 data/ephy-network-manager.xml |    9 +
 src/Makefile.am               |   28 ++-
 src/ephy-net-monitor.c        |  374 -----------------------------------------
 src/ephy-net-monitor.h        |   66 -------
 src/ephy-shell.c              |   36 +++--
 7 files changed, 52 insertions(+), 463 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0b16ea8..bace397 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,6 +323,7 @@ if test "$enable_network_manager" != "no"; then
 fi
 
 if test "$enable_network_manager" = "yes"; then
+	AC_PATH_PROG([GDBUS_CODEGEN], [gdbus-codegen])
 	AC_DEFINE([ENABLE_NETWORK_MANAGER],[1],[Define for NetworkManager support])
 fi
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 6fcfa81..4d9cf6a 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -72,6 +72,7 @@ EXTRA_DIST = \
 	$(gsettings_files)		\
 	$(convert_DATA)			\
 	epiphany-service.xml		\
+	ephy-network-manager.xml	\
 	check-mime.py
 
 DISTCLEANFILES = \
diff --git a/data/ephy-network-manager.xml b/data/ephy-network-manager.xml
new file mode 100644
index 0000000..90fcd70
--- /dev/null
+++ b/data/ephy-network-manager.xml
@@ -0,0 +1,9 @@
+<node>
+  <interface name='org.freedesktop.NetworkManager'>
+    <signal name='StateChanged'>
+      <arg name='state' type='u' />
+    </signal>
+    <property name='State' type='u' access='read'/>
+    <property name='Version' type='s' access='read'/>
+  </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index f399505..9c2e87e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -116,10 +116,26 @@ libephymain_la_CFLAGS = \
 	$(WEBKIT_CFLAGS)	\
 	$(AM_CFLAGS)
 
+BUILT_SOURCES =		\
+	$(TYPES_SOURCE)			\
+	ephy-dbus-client-bindings.h	\
+	ephy-dbus-server-bindings.h
+
 if ENABLE_NETWORK_MANAGER
-libephymain_la_SOURCES += \
-	ephy-net-monitor.c	\
-	ephy-net-monitor.h
+nodist_libephymain_la_SOURCES += \
+	ephy-network-manager.c	 \
+	ephy-network-manager.h
+
+BUILT_SOURCES +=		\
+	ephy-network-manager.h	\
+	ephy-network-manager.c
+
+ephy-network-manager.c ephy-network-manager.h: $(top_srcdir)/data/ephy-network-manager.xml
+	$(AM_V_GEN) $(GDBUS_CODEGEN) 			\
+		--c-namespace Ephy			\
+		--generate-c-code ephy-network-manager  \
+		--interface-prefix org.freedesktop. 	\
+		$<
 
 libephymain_la_CFLAGS += $(NETWORK_MANAGER_CFLAGS)
 endif
@@ -184,12 +200,6 @@ epiphany_LDADD += \
 	$(NETWORK_MANAGER_LIBS)
 endif
 
-BUILT_SOURCES =	\
-	$(TYPES_SOURCE)			\
-	ephy-dbus-client-bindings.h	\
-	ephy-dbus-server-bindings.h
-
-
 TYPES_SOURCE = \
 	ephy-type-builtins.c	\
 	ephy-type-builtins.h
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index ef45fb4..6a246ee 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -58,7 +58,8 @@
 #include "ephy-web-view.h"
 
 #ifdef ENABLE_NETWORK_MANAGER
-#include "ephy-net-monitor.h"
+#include <NetworkManager.h>
+#include "ephy-network-manager.h"
 #endif
 
 #define EPHY_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_SHELL, EphyShellPrivate))
@@ -72,7 +73,7 @@ struct _EphyShellPrivate
 	EggToolbarsModel *fs_toolbars_model;
 	EphyExtensionsManager *extensions_manager;
 #ifdef ENABLE_NETWORK_MANAGER
-	EphyNetMonitor *net_monitor;
+	EphyNetworkManager *nm_proxy;
 #endif
 	GtkWidget *bme;
 	GtkWidget *history_window;
@@ -151,8 +152,8 @@ ephy_shell_new_window_cb (EphyEmbedSingle *single,
 #ifdef ENABLE_NETWORK_MANAGER
 
 static void
-ephy_shell_sync_network_status (EphyNetMonitor *net_monitor,
-				GParamSpec *pspec,
+ephy_shell_sync_network_status (EphyNetworkManager *nm_proxy,
+				NMState state,
 				EphyShell *shell)
 {
 	EphyShellPrivate *priv = shell->priv;
@@ -163,7 +164,7 @@ ephy_shell_sync_network_status (EphyNetMonitor *net_monitor,
 
 	single = EPHY_EMBED_SINGLE (ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (shell)));
 
-	net_status = ephy_net_monitor_get_net_status (net_monitor);
+	net_status = state == NM_STATE_CONNECTED;
 	ephy_embed_single_set_network_status (single, net_status);
 }
 
@@ -190,7 +191,9 @@ impl_get_embed_single (EphyEmbedShell *embed_shell)
 #ifdef ENABLE_NETWORK_MANAGER
 		/* Now we need the net monitor */
 		ephy_shell_get_net_monitor (shell);
-		ephy_shell_sync_network_status (priv->net_monitor, NULL, shell);
+		ephy_shell_sync_network_status (priv->nm_proxy,
+						ephy_network_manager_get_state (priv->nm_proxy),
+						shell);
 #endif
 	}
 	
@@ -291,13 +294,13 @@ ephy_shell_dispose (GObject *object)
 	}
 
 #ifdef ENABLE_NETWORK_MANAGER
-	if (priv->net_monitor != NULL)
+	if (priv->nm_proxy != NULL)
 	{
 		LOG ("Unref net monitor");
 		g_signal_handlers_disconnect_by_func
-			(priv->net_monitor, G_CALLBACK (ephy_shell_sync_network_status), shell);
-		g_object_unref (priv->net_monitor);
-		priv->net_monitor = NULL;
+			(priv->nm_proxy, G_CALLBACK (ephy_shell_sync_network_status), shell);
+		g_object_unref (priv->nm_proxy);
+		priv->nm_proxy = NULL;
 	}
 #endif /* ENABLE_NETWORK_MANAGER */
 
@@ -669,14 +672,19 @@ ephy_shell_get_net_monitor (EphyShell *shell)
 #ifdef ENABLE_NETWORK_MANAGER
 	EphyShellPrivate *priv = shell->priv;
 
-	if (priv->net_monitor == NULL)
+	if (priv->nm_proxy == NULL)
 	{
-		priv->net_monitor = ephy_net_monitor_new ();
-		g_signal_connect (priv->net_monitor, "notify::network-status",
+		priv->nm_proxy = ephy_network_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+									      G_DBUS_PROXY_FLAGS_NONE,
+									      NM_DBUS_SERVICE,
+									      NM_DBUS_PATH,
+									      NULL,
+									      NULL);
+		g_signal_connect (priv->nm_proxy, "state-changed",
 				  G_CALLBACK (ephy_shell_sync_network_status), shell);
 	}
 
-	return G_OBJECT (priv->net_monitor);
+	return G_OBJECT (priv->nm_proxy);
 #else
 	return NULL;
 #endif /* ENABLE_NETWORK_MANAGER */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]