Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > d60bd1f35e0c82afb5f88d78afd23ee9 > files > 24

NetworkManager-0.7.0-9.el5.src.rpm

diff -up NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.c.hide-vpn NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.c
--- NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.c.hide-vpn	2009-05-21 11:14:16.589668258 -0400
+++ NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.c	2009-05-21 11:24:11.214665131 -0400
@@ -1186,7 +1186,8 @@ static void nma_menu_show_cb (GtkWidget 
 
 	n_wireless = nma_menu_add_devices (menu, applet);
 
-	nma_menu_add_vpn_submenu (menu, applet);
+	if (applet->have_vpn_plugins)
+		nma_menu_add_vpn_submenu (menu, applet);
 
 	if (n_wireless > 0 && nm_client_wireless_get_enabled (applet->nm_client)) {
 		/* Add the "Hidden wireless network..." entry */
@@ -2404,6 +2405,75 @@ system_settings_permissions_changed_cb (
 	applet->permissions = nm_dbus_settings_system_get_permissions (settings);
 }
 
+static gboolean
+have_vpn_plugins (void)
+{
+	GDir *dir;
+	const char *f;
+	gboolean have_plugins = FALSE;
+
+	dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL);
+	if (!dir) {
+		nm_warning("%s", "Couldn't read VPN .name files directory " VPN_NAME_FILES_DIR ".");
+		return FALSE;
+	}
+
+	while (!have_plugins && (f = g_dir_read_name (dir))) {
+		char *path = NULL, *service = NULL;
+		char *so_path = NULL, *so_name = NULL;
+		GKeyFile *keyfile = NULL;
+		GModule *module;
+		gpointer factory = NULL;
+
+		if (!g_str_has_suffix (f, ".name"))
+			continue;
+
+		path = g_strdup_printf ("%s/%s", VPN_NAME_FILES_DIR, f);
+
+		keyfile = g_key_file_new ();
+		if (!g_key_file_load_from_file (keyfile, path, 0, NULL))
+			goto next;
+
+		service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL);
+		if (!service)
+			goto next;
+
+		so_path = g_key_file_get_string (keyfile,  "GNOME", "properties", NULL);
+		if (!so_path)
+			goto next;
+
+		/* Remove any path and extension components, then reconstruct path
+		 * to the SO in LIBDIR
+		 */
+		so_name = g_path_get_basename (so_path);
+		g_free (so_path);
+		so_path = g_strdup_printf ("%s/NetworkManager/%s", LIBDIR, so_name);
+		g_free (so_name);
+
+		module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+		if (!module) {
+			nm_warning("Cannot load the VPN plugin which provides the "
+			             "service '%s'.", service);
+			goto next;
+		}
+
+		if (g_module_symbol (module, "nm_vpn_plugin_ui_factory", &factory)) {
+			if (factory)
+				have_plugins = TRUE;
+		}
+		g_module_close (module);
+
+	next:
+		g_free (so_path);
+		g_free (service);
+		g_key_file_free (keyfile);
+		g_free (path);
+	}
+
+	g_dir_close (dir);
+	return have_plugins;
+}
+
 static GObject *
 constructor (GType type,
              guint n_props,
@@ -2495,6 +2565,8 @@ constructor (GType type,
 
 	nm_gconf_set_pre_keyring_callback (applet_pre_keyring_callback, applet);
 
+	applet->have_vpn_plugins = have_vpn_plugins ();
+
 	return G_OBJECT (applet);
 
 error:
diff -up NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.h.hide-vpn NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.h
--- NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.h.hide-vpn	2009-05-21 11:16:22.658697608 -0400
+++ NetworkManager-0.7.0/network-manager-applet-0.7.0/src/applet.h	2009-05-21 11:17:54.655667907 -0400
@@ -102,6 +102,7 @@ typedef struct
 	/* Data model elements */
 	guint			update_icon_id;
 	gboolean		icons_loaded;
+	gboolean        have_vpn_plugins;
 
 	GtkIconTheme *	icon_theme;
 	GdkPixbuf *		no_connection_icon;
diff -up NetworkManager-0.7.0/network-manager-applet-0.7.0/src/Makefile.am.hide-vpn NetworkManager-0.7.0/network-manager-applet-0.7.0/src/Makefile.am
--- NetworkManager-0.7.0/network-manager-applet-0.7.0/src/Makefile.am.hide-vpn	2009-05-21 11:35:51.000000000 -0400
+++ NetworkManager-0.7.0/network-manager-applet-0.7.0/src/Makefile.am	2009-05-21 11:36:16.000000000 -0400
@@ -16,6 +16,7 @@ nm_applet_CPPFLAGS = \
 	-DBINDIR=\""$(bindir)"\"								\
 	-DSYSCONFDIR=\""$(sysconfdir)"\"						\
 	-DLIBEXECDIR=\""$(libexecdir)"\" \
+	-DLIBDIR=\""$(libdir)"\" \
 	-DAUTOSTARTDIR=\""$(sysconfdir)/xdg/autostart"\"			\
 	-DVPN_NAME_FILES_DIR=\""$(sysconfdir)/NetworkManager/VPN"\"	\
 	-DDBUS_API_SUBJECT_TO_CHANGE							\