[network-manager-applet] applet: move migration code into a new binary



commit e88dd5889637621b84cd6ebf3fe26d76e1e8290e
Author: Dan Winship <danw gnome org>
Date:   Tue Jun 19 12:10:16 2012 -0400

    applet: move migration code into a new binary
    
    Move the migration code from nm-applet to nm-applet-migration-tool.
    Now nm-applet does not link against libgconf-helpers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662767

 .gitignore           |    1 +
 configure.ac         |   15 ++++++++
 src/Makefile.am      |   23 ++++++++++--
 src/applet.c         |   46 ++++++++---------------
 src/migration-tool.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 150 insertions(+), 33 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index c4d11bf..5e79879 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,7 @@ src/connection-editor/nm-connection-editor-service-glue.h
 src/libnm-gtk/libnm-gtk.pc
 src/marshallers/nma-marshal.[ch]
 src/nm-applet
+src/nm-applet-migration-tool
 src/applet-dbus-bindings.h
 
 src/gconf-helpers/tests/test-upgrade
diff --git a/configure.ac b/configure.ac
index 1cce372..b3199c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,21 @@ PKG_CHECK_MODULES(NMA,
 # aren't macros for any older versions.
 NMA_CFLAGS="$NMA_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26"
 
+AC_MSG_CHECKING([whether to build nm-applet-migration-tool])
+AC_ARG_ENABLE([migration],
+	      [AS_HELP_STRING([--disable-migration], [Don't build migration tool for NM <= 0.8 settings])],
+	      [enable_migration="$enableval"],
+	      [if test "$UNDER_JHBUILD" = "true"; then
+	           enable_migration=no
+	       else
+	           enable_migration=yes
+	       fi])
+AC_MSG_RESULT([$enable_migration])
+if test "$enable_migration" = "yes"; then
+	AC_DEFINE(BUILD_MIGRATION_TOOL, 1, [Define when building nm-applet-migration-tool])
+fi
+AM_CONDITIONAL(BUILD_MIGRATION_TOOL, test "$enable_migration" = "yes")
+
 PKG_CHECK_MODULES(GCONF, [gconf-2.0])
 AC_SUBST(GCONF_CFLAGS)
 AC_SUBST(GCONF_LIBS)
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ec6416..412f2df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = marshallers utils gconf-helpers wireless-security libnm-gtk connection-editor gnome-bluetooth
+SUBDIRS = marshallers utils wireless-security libnm-gtk connection-editor gnome-bluetooth
 
 bin_PROGRAMS = nm-applet
 
@@ -20,7 +20,6 @@ nm_applet_CPPFLAGS = \
 	$(DISABLE_DEPRECATED)	\
 	-I${top_builddir}/src/marshallers \
 	-I${top_srcdir}/src/utils \
-	-I${top_srcdir}/src/gconf-helpers  \
 	-I${top_srcdir}/src/wireless-security \
 	-I${top_srcdir}/src/libnm-gtk
 
@@ -72,10 +71,28 @@ nm_applet_LDADD = \
 	$(NOTIFY_LIBS) \
 	${top_builddir}/src/marshallers/libmarshallers.la \
 	${top_builddir}/src/utils/libutils.la \
-	${top_builddir}/src/gconf-helpers/libgconf-helpers.la \
 	${top_builddir}/src/wireless-security/libwireless-security.la \
 	${top_builddir}/src/libnm-gtk/libnm-gtk.la
 
+
+if BUILD_MIGRATION_TOOL
+SUBDIRS += gconf-helpers
+
+libexec_PROGRAMS = nm-applet-migration-tool
+endif
+
+nm_applet_migration_tool_CPPFLAGS = \
+	$(nm_applet_CPPFLAGS) \
+	-I${top_srcdir}/src/gconf-helpers
+
+nm_applet_migration_tool_SOURCES = \
+	migration-tool.c
+
+nm_applet_migration_tool_LDADD = \
+	$(nm_applet_LDADD) \
+	${top_builddir}/src/gconf-helpers/libgconf-helpers.la
+
+
 uidir = $(datadir)/nm-applet
 ui_DATA = gsm-unlock.ui info.ui wired-8021x.ui keyring.png
 
diff --git a/src/applet.c b/src/applet.c
index f90b543..8cda23f 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -78,7 +78,6 @@
 #include "nm-wireless-dialog.h"
 #include "applet-vpn-request.h"
 #include "utils.h"
-#include "gconf-helpers.h"
 #include "shell-watcher.h"
 
 #define NOTIFY_CAPS_ACTIONS_KEY "actions"
@@ -3320,33 +3319,6 @@ dbus_setup (NMApplet *applet, GError **error)
 	return success;
 }
 
-static void
-add_cb (NMRemoteSettings *settings,
-        NMRemoteConnection *connection,
-        GError *error,
-        gpointer user_data)
-{
-	NMConnection *c = user_data;
-
-	if (error) {
-		g_warning ("Failed to move connection '%s' to NetworkManager system settings: %s",
-		           nm_connection_get_id (c),
-		           error->message);
-	}
-	g_object_unref (c);
-}
-
-static void
-import_cb (NMConnection *connection, gpointer user_data)
-{
-	NMApplet *applet = user_data;
-
-	if (!nm_remote_settings_add_connection (applet->settings, connection, add_cb, g_object_ref (connection))) {
-		g_warning ("Failed to move connection '%s' to NetworkManager system settings.",
-		           nm_connection_get_id (connection));
-	}
-}
-
 static GObject *
 constructor (GType type,
              guint n_props,
@@ -3393,8 +3365,22 @@ constructor (GType type,
 	}
 	applet->settings = nm_remote_settings_new (applet->bus);
 
-	/* Move user connections to the system */
-	nm_gconf_move_connections_to_system (import_cb, applet);
+#ifdef BUILD_MIGRATION_TOOL
+	{
+		char *argv[2] = { LIBEXECDIR "/nm-applet-migration-tool", NULL };
+		int status;
+
+		/* Move user connections to the system */
+		if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL,
+						   NULL, NULL, &status, &error)) {
+			g_warning ("Could not run nm-applet-migration-tool: %s",
+					   error->message);
+			g_error_free (error);
+		} else if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
+			g_warning ("nm-applet-migration-tool exited with error");
+		}
+	}
+#endif
 
 	applet->agent = applet_agent_new ();
 	g_assert (applet->agent);
diff --git a/src/migration-tool.c b/src/migration-tool.c
new file mode 100644
index 0000000..c06a533
--- /dev/null
+++ b/src/migration-tool.c
@@ -0,0 +1,98 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager applet migration tool -- migrate old GConf settings
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2005-2012 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <libintl.h>
+#include <stdlib.h>
+
+#include <nm-remote-connection.h>
+#include <nm-remote-settings.h>
+
+#include "gconf-helpers.h"
+
+gboolean success = TRUE;
+
+static void
+add_cb (NMRemoteSettings *settings,
+        NMRemoteConnection *connection,
+        GError *error,
+        gpointer user_data)
+{
+	NMConnection *c = user_data;
+
+	if (error) {
+		g_printerr ("Failed to move connection '%s' to NetworkManager system settings: %s",
+					nm_connection_get_id (c),
+					error->message);
+		success = FALSE;
+	}
+	g_object_unref (c);
+}
+
+static void
+import_cb (NMConnection *connection, gpointer user_data)
+{
+	NMRemoteSettings *settings = user_data;
+
+	if (!nm_remote_settings_add_connection (settings, connection, add_cb, g_object_ref (connection))) {
+		g_warning ("Failed to move connection '%s' to NetworkManager system settings.",
+		           nm_connection_get_id (connection));
+		g_object_unref (connection);
+		success = FALSE;
+	}
+}
+
+int
+main (int argc, char **argv)
+{
+	DBusGConnection *bus;
+	NMRemoteSettings *settings;
+	GError *error = NULL;
+
+	bindtextdomain (GETTEXT_PACKAGE, NMALOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	g_type_init ();
+
+	if (argc != 1) {
+		g_printerr ("Usage: %s\n", argv[0]);
+		exit (1);
+	}
+
+	bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (!bus) {
+		g_printerr ("Could not get system bus: %s\n", error->message);
+		g_error_free (error);
+		exit (1);
+	}
+
+	settings = nm_remote_settings_new (bus);
+	nm_gconf_move_connections_to_system (import_cb, settings);
+
+	g_object_unref (settings);
+	g_object_unref (bus);
+
+	return success ? 0 : 1;
+}
+



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