network-manager-applet r461 - in trunk: . src src/utils



Author: dcbw
Date: Fri Jan 18 17:20:42 2008
New Revision: 461
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=461&view=rev

Log:
2008-01-18  Dan Williams  <dcbw redhat com>

	* src/utils/utils.c
	  src/utils/utils.h
		- (utils_check_ap_compatible): make static; only used from utils.c now
		- (connection_valid_for_wireless): if an AP is provided, check
			compability of that first before doing device capability comparisons

	* src/applet-dbus-settings.c
	  src/applet-dbus-settings.h
		- Rename applet_dbus_settings_get_by_dbus_path() -> 
			applet_dbus_settings_user_get_by_dbus_path()
		- (applet_dbus_settings_system_get_dbus_path): new function; return
			a system NMConnection object from it's D-Bus path
		- Rename applet_dbus_settings_get_by_connection() ->
			applet_dbus_settings_user_get_by_connection()
		- Rename applet_dbus_settings_add_connection() ->
			applet_dbus_settings_user_add_connection()

	* src/applet.c
	  src/applet.h
		- Remove the connection_filter() virtual function from NMADeviceClass,
			it's no longer needed
		- (applet_menu_item_activate_helper): take an NMConnection argument
			for the connection to activate.  If this argument is NULL, then
			create a new default connection for the object.  Handle system
			connections too when calling nm_client_activate_device()

	* src/applet-device-wired.c
		- (wired_connection_filter): remove
		- (wired_menu_item_activate): pass connection to
			applet_menu_item_activate_helper()
		- (wired_add_menu_item): get all connections valid for the device,
			and construct the connection sub-menu if there are more than one.
			Each menu item now keeps its applicable connection object around
			to pass to applet_menu_item_activate_helper().

	* src/applet-device-gsm.c
		- (gsm_connection_filter): remove
		- (gsm_menu_item_activate): pass connection to
			applet_menu_item_activate_helper()
		- (gsm_add_menu_item): get all connections valid for the device,
			and construct the connection sub-menu if there are more than one.
			Each menu item now keeps its applicable connection object around
			to pass to applet_menu_item_activate_helper().

	* src/applet-device-wireless.c
		- (wireless_connection_filter): remove
		- (wireless_menu_item_activate): pass connection to
			applet_menu_item_activate_helper()
		- (wireless_add_menu_item): filter all connections for the ones that
			apply to this device and pass that on to the real menu construction
			functions
		- (add_one_ap_menu_item): do new menu item construction elsewhere
		- (add_new_ap_item): get all connections valid for the device and the
			access point tied to this menu item, and construct the connection
			sub-menu if there are more than one. Each menu item now keeps its
			applicable connection object around to pass to
			applet_menu_item_activate_helper()



Modified:
   trunk/ChangeLog
   trunk/src/applet-dbus-settings.c
   trunk/src/applet-dbus-settings.h
   trunk/src/applet-device-gsm.c
   trunk/src/applet-device-wired.c
   trunk/src/applet-device-wireless.c
   trunk/src/applet.c
   trunk/src/applet.h
   trunk/src/utils/utils.c
   trunk/src/utils/utils.h

Modified: trunk/src/applet-dbus-settings.c
==============================================================================
--- trunk/src/applet-dbus-settings.c	(original)
+++ trunk/src/applet-dbus-settings.c	Fri Jan 18 17:20:42 2008
@@ -523,8 +523,8 @@
 }
 
 AppletDbusConnectionSettings *
-applet_dbus_settings_get_by_dbus_path (AppletDbusSettings *applet_settings,
-                                       const char *path)
+applet_dbus_settings_user_get_by_dbus_path (AppletDbusSettings *applet_settings,
+                                            const char *path)
 {
 	GSList *elt;
 
@@ -540,9 +540,40 @@
 	return NULL;
 }
 
+struct FindSystemInfo {
+	NMConnection *connection;
+	const char *path;
+};
+
+static void
+find_system_by_path (gpointer key, gpointer data, gpointer user_data)
+{
+	struct FindSystemInfo *info = (struct FindSystemInfo *) user_data;
+	NMConnection *connection = NM_CONNECTION (data);
+
+	if (!info->path && (info->connection == connection))
+		info->path = (const char *) key;
+}
+
+const char *
+applet_dbus_settings_system_get_dbus_path (AppletDbusSettings *settings,
+                                           NMConnection *connection)
+{
+	struct FindSystemInfo info;
+
+	g_return_val_if_fail (APPLET_IS_DBUS_SETTINGS (settings), NULL);
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+	info.connection = connection;
+	info.path = NULL;
+
+	g_hash_table_foreach (settings->system_connections, find_system_by_path, &info);
+	return info.path;
+}
+
 AppletDbusConnectionSettings *
-applet_dbus_settings_get_by_connection (AppletDbusSettings *applet_settings,
-                                        NMConnection *connection)
+applet_dbus_settings_user_get_by_connection (AppletDbusSettings *applet_settings,
+                                             NMConnection *connection)
 {
 	GSList *elt;
 
@@ -686,8 +717,8 @@
 }
 
 AppletDbusConnectionSettings *
-applet_dbus_settings_add_connection (AppletDbusSettings *applet_settings,
-                                     NMConnection *connection)
+applet_dbus_settings_user_add_connection (AppletDbusSettings *applet_settings,
+                                          NMConnection *connection)
 {
 	NMConnectionSettings *exported;
 	guint32 i = 0;

Modified: trunk/src/applet-dbus-settings.h
==============================================================================
--- trunk/src/applet-dbus-settings.h	(original)
+++ trunk/src/applet-dbus-settings.h	Fri Jan 18 17:20:42 2008
@@ -92,14 +92,17 @@
 GType       applet_dbus_settings_get_type (void);
 NMSettings *applet_dbus_settings_new (void);
 
-AppletDbusConnectionSettings * applet_dbus_settings_add_connection (AppletDbusSettings *settings,
-                                                                    NMConnection *connection);
+AppletDbusConnectionSettings * applet_dbus_settings_user_add_connection (AppletDbusSettings *settings,
+                                                                         NMConnection *connection);
 
-AppletDbusConnectionSettings * applet_dbus_settings_get_by_dbus_path (AppletDbusSettings *settings,
-                                                                      const char *path);
+AppletDbusConnectionSettings * applet_dbus_settings_user_get_by_dbus_path (AppletDbusSettings *settings,
+                                                                           const char *path);
 
-AppletDbusConnectionSettings * applet_dbus_settings_get_by_connection (AppletDbusSettings *settings,
-                                                                       NMConnection *connection);
+AppletDbusConnectionSettings * applet_dbus_settings_user_get_by_connection (AppletDbusSettings *settings,
+                                                                            NMConnection *connection);
+
+const char * applet_dbus_settings_system_get_dbus_path (AppletDbusSettings *settings,
+                                                        NMConnection *connection);
 
 /* Returns a list of NMConnectionSettings objects */
 GSList * applet_dbus_settings_list_connections (AppletDbusSettings *settings);

Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c	(original)
+++ trunk/src/applet-device-gsm.c	Fri Jan 18 17:20:42 2008
@@ -43,6 +43,7 @@
 typedef struct {
 	NMApplet *applet;
 	NMDevice *device;
+	NMConnection *connection;
 } GSMMenuItemInfo;
 
 static void
@@ -88,32 +89,15 @@
 	return connection;
 }
 
-
-static gboolean
-gsm_connection_filter (NMConnection *connection,
-                       NMDevice *device,
-                       NMApplet *applet,
-                       gpointer user_data)
-{
-	NMSettingConnection *s_con;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
-
-	// FIXME: check MAC address of connection too
-	if (!strcmp (s_con->type, NM_SETTING_GSM_SETTING_NAME))
-		return TRUE;
-
-	return FALSE;
-}
-
 static void
 gsm_menu_item_activate (GtkMenuItem *item, gpointer user_data)
 {
 	GSMMenuItemInfo *info = (GSMMenuItemInfo *) user_data;
 
 	applet_menu_item_activate_helper (info->device,
-	                                  info->applet,
+	                                  info->connection,
 	                                  "/",
+	                                  info->applet,
 	                                  user_data);
 }
 
@@ -126,6 +110,7 @@
 	GSMMenuItemInfo *info;
 	char *text;
 	GtkCheckMenuItem *item;
+	GSList *connections, *all, *iter;
 
 	if (n_devices > 1) {
 		const char *desc;
@@ -145,6 +130,57 @@
 	item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_mnemonic (text));
 	g_free (text);
 
+	all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+	connections = utils_filter_connections_for_device (device, all);
+	g_slist_free (all);
+
+	/* If there's only one connection, don't show the submenu */
+	if (g_slist_length (connections) > 1) {
+		GtkWidget *submenu;
+
+		submenu = gtk_menu_new ();
+
+		for (iter = connections; iter; iter = g_slist_next (iter)) {
+			NMConnection *connection = NM_CONNECTION (iter->data);
+			NMSettingConnection *s_con;
+			GtkWidget *subitem;
+
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+			subitem = gtk_menu_item_new_with_label (s_con->id);
+
+			info = g_slice_new0 (GSMMenuItemInfo);
+			info->applet = applet;
+			info->device = g_object_ref (G_OBJECT (device));
+			info->connection = g_object_ref (connection);
+
+			g_signal_connect_data (subitem, "activate",
+			                       G_CALLBACK (gsm_menu_item_activate),
+			                       info,
+			                       (GClosureNotify) gsm_menu_item_info_destroy, 0);
+
+			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
+		}
+
+		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+	} else {
+		NMConnection *connection;
+
+		info = g_slice_new0 (GSMMenuItemInfo);
+		info->applet = applet;
+		info->device = g_object_ref (G_OBJECT (device));
+
+		if (g_slist_length (connections) == 1) {
+			connection = NM_CONNECTION (g_slist_nth_data (connections, 0));
+			info->connection = g_object_ref (G_OBJECT (connection));
+		}
+
+		g_signal_connect_data (item, "activate",
+		                       G_CALLBACK (gsm_menu_item_activate),
+		                       info,
+		                       (GClosureNotify) gsm_menu_item_info_destroy, 0);
+	}
+	g_slist_free (connections);
+
 	gtk_check_menu_item_set_draw_as_radio (item, TRUE);
 	gtk_check_menu_item_set_active (item, nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED);
 
@@ -154,6 +190,7 @@
 	info = g_slice_new (GSMMenuItemInfo);
 	info->applet = applet;
 	info->device = device;
+	info->connection = NULL; // FIXME
 
 	g_signal_connect_data (item, "activate",
 	                       G_CALLBACK (gsm_menu_item_activate),
@@ -215,7 +252,6 @@
 		return NULL;
 
 	dclass->new_auto_connection = gsm_new_auto_connection;
-	dclass->connection_filter = gsm_connection_filter;
 	dclass->add_menu_item = gsm_add_menu_item;
 	dclass->device_state_changed = gsm_device_state_changed;
 	dclass->get_icon = gsm_get_icon;

Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c	(original)
+++ trunk/src/applet-device-wired.c	Fri Jan 18 17:20:42 2008
@@ -41,11 +41,18 @@
 typedef struct {
 	NMApplet *applet;
 	NMDevice *device;
+	NMConnection *connection;
 } WiredMenuItemInfo;
 
 static void
 wired_menu_item_info_destroy (gpointer data)
 {
+	WiredMenuItemInfo *info = (WiredMenuItemInfo *) data;
+
+	g_object_unref (G_OBJECT (info->device));
+	if (info->connection)
+		g_object_unref (G_OBJECT (info->connection));
+
 	g_slice_free (WiredMenuItemInfo, data);
 }
 
@@ -72,32 +79,15 @@
 	return connection;
 }
 
-
-static gboolean
-wired_connection_filter (NMConnection *connection,
-                         NMDevice *device,
-                         NMApplet *applet,
-                         gpointer user_data)
-{
-	NMSettingConnection *s_con;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
-
-	// FIXME: check MAC address of connection too
-	if (!strcmp (s_con->type, NM_SETTING_WIRED_SETTING_NAME))
-		return TRUE;
-
-	return FALSE;
-}
-
 static void
 wired_menu_item_activate (GtkMenuItem *item, gpointer user_data)
 {
 	WiredMenuItemInfo *info = (WiredMenuItemInfo *) user_data;
 
 	applet_menu_item_activate_helper (info->device,
-	                                  info->applet,
+	                                  info->connection,
 	                                  "/",
+	                                  info->applet,
 	                                  user_data);
 }
 
@@ -107,9 +97,10 @@
                      GtkWidget *menu,
                      NMApplet *applet)
 {
-	WiredMenuItemInfo *info;
 	char *text;
 	GtkCheckMenuItem *item;
+	GSList *connections, *all, *iter;
+	WiredMenuItemInfo *info;
 
 	if (n_devices > 1) {
 		const char *desc;
@@ -129,9 +120,67 @@
 	item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_mnemonic (text));
 	g_free (text);
 
+	all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+	connections = utils_filter_connections_for_device (device, all);
+	g_slist_free (all);
+
+	/* If there's only one connection, don't show the submenu */
+	if (g_slist_length (connections) > 1) {
+		GtkWidget *submenu;
+
+		submenu = gtk_menu_new ();
+
+		for (iter = connections; iter; iter = g_slist_next (iter)) {
+			NMConnection *connection = NM_CONNECTION (iter->data);
+			NMSettingConnection *s_con;
+			GtkWidget *subitem;
+
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+			subitem = gtk_menu_item_new_with_label (s_con->id);
+
+			info = g_slice_new0 (WiredMenuItemInfo);
+			info->applet = applet;
+			info->device = g_object_ref (G_OBJECT (device));
+			info->connection = g_object_ref (connection);
+
+			g_signal_connect_data (subitem, "activate",
+			                       G_CALLBACK (wired_menu_item_activate),
+			                       info,
+			                       (GClosureNotify) wired_menu_item_info_destroy, 0);
+
+			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
+		}
+
+		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+	} else {
+		NMConnection *connection;
+
+		info = g_slice_new0 (WiredMenuItemInfo);
+		info->applet = applet;
+		info->device = g_object_ref (G_OBJECT (device));
+
+		if (g_slist_length (connections) == 1) {
+			connection = NM_CONNECTION (g_slist_nth_data (connections, 0));
+			info->connection = g_object_ref (G_OBJECT (connection));
+		}
+
+		g_signal_connect_data (item, "activate",
+		                       G_CALLBACK (wired_menu_item_activate),
+		                       info,
+		                       (GClosureNotify) wired_menu_item_info_destroy, 0);
+	}
+	g_slist_free (connections);
+
 	gtk_check_menu_item_set_draw_as_radio (item, TRUE);
+
+	g_signal_handlers_block_matched (item, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
+	                                 G_CALLBACK (wired_menu_item_activate), NULL);
+
 	gtk_check_menu_item_set_active (item, nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED);
 
+	g_signal_handlers_unblock_matched (item, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
+	                                   G_CALLBACK (wired_menu_item_activate), NULL);
+
 	/* Only dim the item if the device supports carrier detection AND
 	 * we know it doesn't have a link.
 	 */
@@ -140,15 +189,6 @@
 
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
 	gtk_widget_show (GTK_WIDGET (item));
-
-	info = g_slice_new (WiredMenuItemInfo);
-	info->applet = applet;
-	info->device = device;
-
-	g_signal_connect_data (item, "activate",
-	                       G_CALLBACK (wired_menu_item_activate),
-	                       info,
-	                       (GClosureNotify) wired_menu_item_info_destroy, 0);
 }
 
 static void
@@ -221,7 +261,7 @@
 	nm_connection_add_setting (connection, (NMSetting *) s_wired);
 	nm_connection_add_setting (connection, (NMSetting *) s_con);
 
-	applet_dbus_settings_add_connection (settings, connection);
+	applet_dbus_settings_user_add_connection (settings, connection);
 }
 
 NMADeviceClass *
@@ -234,7 +274,6 @@
 		return NULL;
 
 	dclass->new_auto_connection = wired_new_auto_connection;
-	dclass->connection_filter = wired_connection_filter;
 	dclass->add_menu_item = wired_add_menu_item;
 	dclass->device_state_changed = wired_device_state_changed;
 	dclass->get_icon = wired_get_icon;

Modified: trunk/src/applet-device-wireless.c
==============================================================================
--- trunk/src/applet-device-wireless.c	(original)
+++ trunk/src/applet-device-wireless.c	Fri Jan 18 17:20:42 2008
@@ -135,11 +135,20 @@
 	NMApplet *applet;
 	NMDevice80211Wireless *device;
 	NMAccessPoint *ap;
+	NMConnection *connection;
 } WirelessMenuItemInfo;
 
 static void
 wireless_menu_item_info_destroy (gpointer data)
 {
+	WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) data;
+
+	g_object_unref (G_OBJECT (info->device));
+	g_object_unref (G_OBJECT (info->ap));
+
+	if (info->connection)
+		g_object_unref (G_OBJECT (info->connection));
+
 	g_slice_free (WirelessMenuItemInfo, data);
 }
 
@@ -351,37 +360,6 @@
 	return connection;
 }
 
-static gboolean
-wireless_connection_filter (NMConnection *connection,
-                            NMDevice *device,
-                            NMApplet *applet,
-                            gpointer user_data)
-{
-	WirelessMenuItemInfo *info = (WirelessMenuItemInfo *) user_data;
-	NMSettingConnection *s_con;
-	NMSettingWireless *s_wireless;
-	const GByteArray *ap_ssid;
-
-	s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
-	g_assert (s_con);
-
-	if (strcmp (s_con->type, NM_SETTING_WIRELESS_SETTING_NAME))
-		return FALSE;
-
-	s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
-	if (!s_wireless)
-		return FALSE;
-
-	ap_ssid = nm_access_point_get_ssid (info->ap);
-	if (!nm_utils_same_ssid (s_wireless->ssid, ap_ssid, TRUE))
-		return FALSE;
-
-	if (!utils_check_ap_compatible (info->ap, connection))
-		return FALSE;
-
-	return TRUE;
-}
-
 static void
 wireless_menu_item_activate (GtkMenuItem *item, gpointer user_data)
 {
@@ -391,8 +369,9 @@
 	if (info->ap)
 		specific_object = nm_object_get_path (NM_OBJECT (info->ap));
 	applet_menu_item_activate_helper (NM_DEVICE (info->device),
-	                                  info->applet,
+	                                  info->connection,
 	                                  specific_object ? specific_object : "/",
+	                                  info->applet,
 	                                  user_data);
 }
 
@@ -430,9 +409,107 @@
 		data->found = widget;
 }
 
+static NMNetworkMenuItem *
+add_new_ap_item (NMDevice80211Wireless *device,
+                 NMAccessPoint *ap,
+                 struct dup_data *dup_data,
+                 NMAccessPoint *active_ap,
+                 GSList *connections,
+                 GtkWidget *menu,
+                 NMApplet *applet)
+{
+	WirelessMenuItemInfo *info;
+	GtkWidget *foo;
+	GSList *iter;
+	NMNetworkMenuItem *item = NULL;
+	GSList *ap_connections = NULL;
+	const GByteArray *ssid;
+	guint8 strength;
+
+	for (iter = connections; iter; iter = g_slist_next (iter)) {
+		NMConnection *candidate = NM_CONNECTION (iter->data);
+
+		if (utils_connection_valid_for_device (candidate, NM_DEVICE (device), (gpointer) ap))
+			ap_connections = g_slist_append (ap_connections, candidate);
+	}
+
+	foo = nm_network_menu_item_new (applet->encryption_size_group,
+	                                dup_data->hash, AP_HASH_LEN);
+	item = NM_NETWORK_MENU_ITEM (foo);
+
+	ssid = nm_access_point_get_ssid (ap);
+	nm_network_menu_item_set_ssid (item, (GByteArray *) ssid);
+
+	strength = nm_access_point_get_strength (ap);
+	nm_network_menu_item_set_strength (item, strength);
+
+	nm_network_menu_item_set_detail (item, ap, applet->adhoc_icon);
+	nm_network_menu_item_add_dupe (item, ap);
+
+	g_object_set_data (G_OBJECT (item), "device", NM_DEVICE (device));
+
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
+
+	/* If there's only one connection, don't show the submenu */
+	if (g_slist_length (ap_connections) > 1) {
+		GtkWidget *submenu;
+
+		submenu = gtk_menu_new ();
+
+		for (iter = ap_connections; iter; iter = g_slist_next (iter)) {
+			NMConnection *connection = NM_CONNECTION (iter->data);
+			NMSettingConnection *s_con;
+			GtkWidget *subitem;
+
+			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+			subitem = gtk_menu_item_new_with_label (s_con->id);
+
+			info = g_slice_new0 (WirelessMenuItemInfo);
+			info->applet = applet;
+			info->device = g_object_ref (G_OBJECT (device));
+			info->ap = g_object_ref (G_OBJECT (ap));
+			info->connection = g_object_ref (G_OBJECT (connection));
+
+			g_signal_connect_data (subitem, "activate",
+			                       G_CALLBACK (wireless_menu_item_activate),
+			                       info,
+			                       (GClosureNotify) wireless_menu_item_info_destroy, 0);
+
+			gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
+		}
+
+		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+	} else {
+		NMConnection *connection;
+
+		info = g_slice_new0 (WirelessMenuItemInfo);
+		info->applet = applet;
+		info->device = g_object_ref (G_OBJECT (device));
+		info->ap = g_object_ref (G_OBJECT (ap));
+
+		if (g_slist_length (ap_connections) == 1) {
+			connection = NM_CONNECTION (g_slist_nth_data (connections, 0));
+			info->connection = g_object_ref (G_OBJECT (connection));
+		}
+
+		g_signal_connect_data (GTK_WIDGET (item),
+		                       "activate",
+		                       G_CALLBACK (wireless_menu_item_activate),
+		                       info,
+		                       (GClosureNotify) wireless_menu_item_info_destroy,
+		                       0);
+	}
+
+	gtk_widget_show_all (GTK_WIDGET (item));
+
+	g_slist_free (ap_connections);
+	return item;
+}
+
 static void
 add_one_ap_menu_item (NMDevice80211Wireless *device,
                       NMAccessPoint *ap,
+                      GSList *connections,
                       NMAccessPoint *active_ap,
                       GtkWidget *menu,
                       NMApplet *applet)
@@ -467,34 +544,7 @@
 
 		nm_network_menu_item_add_dupe (item, ap);
 	} else {
-		WirelessMenuItemInfo *info;
-		GtkWidget *foo;
-
-		foo = nm_network_menu_item_new (applet->encryption_size_group,
-		                                dup_data.hash, AP_HASH_LEN);
-		item = NM_NETWORK_MENU_ITEM (foo);
-		nm_network_menu_item_set_ssid (item, (GByteArray *) ssid);
-		nm_network_menu_item_set_strength (item, strength);
-		nm_network_menu_item_set_detail (item, ap, applet->adhoc_icon);
-		nm_network_menu_item_add_dupe (item, ap);
-
-		g_object_set_data (G_OBJECT (item), "device", NM_DEVICE (device));
-
-		gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
-
-		info = g_slice_new0 (WirelessMenuItemInfo);
-		info->applet = applet;
-		info->device = device;
-		info->ap = ap;
-
-		g_signal_connect_data (GTK_WIDGET (item),
-		                       "activate",
-		                       G_CALLBACK (wireless_menu_item_activate),
-		                       info,
-		                       (GClosureNotify) wireless_menu_item_info_destroy,
-		                       0);
-
-		gtk_widget_show_all (GTK_WIDGET (item));
+		item = add_new_ap_item (device, ap, &dup_data, active_ap, connections, menu, applet);
 	}
 
 	if (!active_ap)
@@ -576,13 +626,13 @@
                         GtkWidget *menu,
                         NMApplet *applet)
 {
-	WirelessMenuItemInfo *info;
 	NMDevice80211Wireless *wdev;
 	char *text;
 	GtkMenuItem *item;
 	GSList *aps;
 	GSList *iter;
 	NMAccessPoint *active_ap = NULL;
+	GSList *connections = NULL, *all;
 
 	wdev = NM_DEVICE_802_11_WIRELESS (device);
 	aps = nm_device_802_11_wireless_get_access_points (wdev);
@@ -610,28 +660,24 @@
 	gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
 	gtk_widget_show (GTK_WIDGET (item));
 
-	info = g_slice_new0 (WirelessMenuItemInfo);
-	info->applet = applet;
-	info->device = wdev;
-
-	g_signal_connect_data (item, "activate",
-	                       G_CALLBACK (wireless_menu_item_activate),
-	                       info,
-	                       (GClosureNotify) wireless_menu_item_info_destroy, 0);
-
 	/* Don't display APs when wireless is disabled */
 	if (!nm_client_wireless_get_enabled (applet->nm_client))
 		goto out;
 
+	all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+	connections = utils_filter_connections_for_device (device, all);
+	g_slist_free (all);
+
 	aps = nm_device_802_11_wireless_get_access_points (wdev);
 	active_ap = nm_device_802_11_wireless_get_active_access_point (wdev);
 
 	/* Add all networks in our network list to the menu */
 	aps = g_slist_sort (aps, sort_wireless_networks);
 	for (iter = aps; iter; iter = g_slist_next (iter))
-		add_one_ap_menu_item (wdev, NM_ACCESS_POINT (iter->data), active_ap, menu, applet);
+		add_one_ap_menu_item (wdev, NM_ACCESS_POINT (iter->data), connections, active_ap, menu, applet);
 
 out:
+	g_slist_free (connections);
 	g_slist_free (aps);
 }
 
@@ -1062,11 +1108,11 @@
 			s_con->autoconnect = TRUE;
 	}
 
-	exported_con = applet_dbus_settings_get_by_connection (APPLET_DBUS_SETTINGS (applet->settings),
-	                                                       connection);
+	exported_con = applet_dbus_settings_user_get_by_connection (APPLET_DBUS_SETTINGS (applet->settings),
+	                                                            connection);
 	if (!exported_con) {
-		exported_con = applet_dbus_settings_add_connection (APPLET_DBUS_SETTINGS (applet->settings),
-		                                                    connection);
+		exported_con = applet_dbus_settings_user_add_connection (APPLET_DBUS_SETTINGS (applet->settings),
+		                                                         connection);
 		if (!exported_con) {
 			nm_warning ("Couldn't create other network connection.");
 			goto done;
@@ -1200,7 +1246,7 @@
 	 * saving to GConf might trigger the GConf change notifiers, resulting
 	 * in the connection being read back in from GConf which clears secrets.
 	 */
-	applet_connection = applet_dbus_settings_get_by_connection (APPLET_DBUS_SETTINGS (applet->settings), connection);
+	applet_connection = applet_dbus_settings_user_get_by_connection (APPLET_DBUS_SETTINGS (applet->settings), connection);
 	if (applet_connection)
 		applet_dbus_connection_settings_save (NM_CONNECTION_SETTINGS (applet_connection));
 
@@ -1272,7 +1318,6 @@
 		return NULL;
 
 	dclass->new_auto_connection = wireless_new_auto_connection;
-	dclass->connection_filter = wireless_connection_filter;
 	dclass->add_menu_item = wireless_add_menu_item;
 	dclass->device_added = wireless_device_added;
 	dclass->device_state_changed = wireless_device_state_changed;

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Fri Jan 18 17:20:42 2008
@@ -116,54 +116,46 @@
 
 void
 applet_menu_item_activate_helper (NMDevice *device,
-                                  NMApplet *applet,
+                                  NMConnection *connection,
                                   const char *specific_object,
+                                  NMApplet *applet,
                                   gpointer user_data)
 {
 	AppletDbusSettings *applet_settings = APPLET_DBUS_SETTINGS (applet->settings);
-	NMConnection *connection = NULL;
+	AppletDbusConnectionSettings *exported_con = NULL;
 	char *con_path = NULL;
-	GSList *elt, *connections;
-	NMADeviceClass *dclass;
+	gboolean is_system = FALSE;
 
-	dclass = get_device_class (device, applet);
-	g_assert (dclass);
+	g_return_if_fail (NM_IS_DEVICE (device));
+	g_return_if_fail (connection != NULL);
+	g_return_if_fail (NM_IS_CONNECTION (connection));
 
-	/* Find a connection that applies to this device */
-	// FIXME: handle multiple applicable connections per device
-	connections = applet_dbus_settings_list_connections (applet_settings);
-	for (elt = connections; elt; elt = g_slist_next (elt)) {
-		NMConnectionSettings *applet_connection = NM_CONNECTION_SETTINGS (elt->data);
-		NMConnection *candidate;
-
-		candidate = applet_dbus_connection_settings_get_connection (applet_connection);
-		if (dclass->connection_filter (candidate, device, applet, user_data)) {
-			NMSettingConnection *s_con;
-
-			con_path = (char *) nm_connection_settings_get_dbus_object_path (applet_connection);
-			s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION));
-			g_message ("Found connection '%s' to activate at %s.", s_con->id, con_path);
-			connection = candidate;
-			break;
+	if (connection) {
+		exported_con = applet_dbus_settings_user_get_by_connection (applet_settings, connection);
+		if (exported_con) {
+			con_path = (char *) nm_connection_settings_get_dbus_object_path (NM_CONNECTION_SETTINGS (exported_con));
+		} else {
+			con_path = (char *) applet_dbus_settings_system_get_dbus_path (applet_settings, connection);
+			if (con_path)
+				is_system = TRUE;
+			else
+				return;
 		}
-	}
-
-	/* If no existing connection was found, create a new default connection
-	 * for this device type.
-	 */
-	if (!connection) {
-		AppletDbusConnectionSettings *exported_con;
+	} else {
+		NMADeviceClass *dclass = get_device_class (device, applet);
 
+		/* If no connection was given, create a new default connection for this
+		 * device type.
+		 */
+		g_assert (dclass);
 		connection = dclass->new_auto_connection (device, applet, user_data);
 		if (!connection) {
 			nm_warning ("Couldn't create default connection.");
 			return;
 		}
 
-		exported_con = applet_dbus_settings_add_connection (applet_settings, connection);
-		if (exported_con)
-			con_path = (char *) nm_connection_settings_get_dbus_object_path (NM_CONNECTION_SETTINGS (exported_con));
-		else {
+		exported_con = applet_dbus_settings_user_add_connection (applet_settings, connection);
+		if (!exported_con) {
 			/* If the setting isn't valid, because it needs more authentication
 			 * or something, ask the user for it.
 			 */
@@ -174,12 +166,16 @@
 			}
 			return;
 		}
+
+		con_path = (char *) nm_connection_settings_get_dbus_object_path (NM_CONNECTION_SETTINGS (exported_con));
 	}
 
+	g_assert (con_path);
+
 	/* Finally, tell NM to activate the connection */
 	nm_client_activate_device (applet->nm_client,
 	                           device,
-	                           NM_DBUS_SERVICE_USER_SETTINGS,
+	                           is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
 	                           con_path,
 	                           specific_object,
 	                           activate_device_cb,
@@ -937,8 +933,8 @@
 		if (!g_slist_find (act_con->devices, device))
 			continue;
 
-		connection_settings = applet_dbus_settings_get_by_dbus_path (APPLET_DBUS_SETTINGS (applet->settings),
-		                                                             act_con->connection_path);
+		connection_settings = applet_dbus_settings_user_get_by_dbus_path (APPLET_DBUS_SETTINGS (applet->settings),
+		                                                                  act_con->connection_path);
 		if (!connection_settings || !connection_settings->connection)
 			continue;
 

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Fri Jan 18 17:20:42 2008
@@ -149,7 +149,6 @@
 
 struct NMADeviceClass {
 	NMConnection * (*new_auto_connection) (NMDevice *device, NMApplet *applet, gpointer user_data);
-	gboolean       (*connection_filter) (NMConnection *connection, NMDevice *device, NMApplet *applet, gpointer user_data);
 	void           (*add_menu_item) (NMDevice *device, guint32 num_devices, GtkWidget *menu, NMApplet *applet);
 	void           (*device_added) (NMDevice *device, NMApplet *applet);
 	void           (*device_state_changed) (NMDevice *device, NMDeviceState state, NMApplet *applet);
@@ -173,8 +172,9 @@
 void applet_schedule_update_icon (NMApplet *applet);
 
 void applet_menu_item_activate_helper (NMDevice *device,
-                                       NMApplet *applet,
+                                       NMConnection *connection,
                                        const char *specific_object,
+                                       NMApplet *applet,
                                        gpointer user_data);
 
 AppletDbusConnectionSettings *applet_get_connection_settings_for_device (NMDevice *device, NMApplet *applet);

Modified: trunk/src/utils/utils.c
==============================================================================
--- trunk/src/utils/utils.c	(original)
+++ trunk/src/utils/utils.c	Fri Jan 18 17:20:42 2008
@@ -460,7 +460,7 @@
 	return TRUE;
 }
 
-gboolean
+static gboolean
 utils_check_ap_compatible (NMAccessPoint *ap,
                            NMConnection *connection)
 {
@@ -566,8 +566,6 @@
 	NMDevice80211Wireless *wdev = NM_DEVICE_802_11_WIRELESS (device);
 	NMSettingWireless *s_wireless;
 	NMSettingWirelessSecurity *s_wireless_sec;
-	const char *str_mac;
-	struct ether_addr *bin_mac;
 	guint32 wcaps;
 	NMAccessPoint *ap;
 
@@ -578,17 +576,28 @@
 	g_return_val_if_fail (s_wireless != NULL, FALSE);
 
 	/* Match MAC address */
-	if (!s_wireless->mac_address)
-		return TRUE;
+	if (s_wireless->mac_address) {
+		const char *str_mac;
+		struct ether_addr *bin_mac;
 
-	str_mac = nm_device_802_11_wireless_get_hw_address (wdev);
-	g_return_val_if_fail (str_mac != NULL, FALSE);
+		str_mac = nm_device_802_11_wireless_get_hw_address (wdev);
+		g_return_val_if_fail (str_mac != NULL, FALSE);
 
-	bin_mac = ether_aton (str_mac);
-	g_return_val_if_fail (bin_mac != NULL, FALSE);
+		bin_mac = ether_aton (str_mac);
+		g_return_val_if_fail (bin_mac != NULL, FALSE);
 
-	if (memcmp (bin_mac->ether_addr_octet, s_wireless->mac_address->data, ETH_ALEN))
-		return FALSE;
+		if (memcmp (bin_mac->ether_addr_octet, s_wireless->mac_address->data, ETH_ALEN))
+			return FALSE;
+	}
+
+	/* If an AP was given make sure that's compatible with the connection first */
+	if (specific_object) {
+		ap = NM_ACCESS_POINT (specific_object);
+		g_assert (ap);
+
+		if (!utils_check_ap_compatible (ap, connection))
+			return FALSE;
+	}
 
 	if (!s_wireless->security || strcmp (s_wireless->security, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME))
 		return TRUE; /* all devices can do unencrypted networks */
@@ -631,18 +640,6 @@
 	    && !(wcaps & NM_802_11_DEVICE_CAP_CIPHER_CCMP))
 		return FALSE;
 
-	/* Match the AP */
-
-	if (!specific_object)
-		return TRUE;
-
-	ap = NM_ACCESS_POINT (specific_object);
-	if (!ap)
-		return TRUE;
-
-	if (!utils_check_ap_compatible (ap, connection))
-		return FALSE;
-
 	return TRUE;
 }
 

Modified: trunk/src/utils/utils.h
==============================================================================
--- trunk/src/utils/utils.h	(original)
+++ trunk/src/utils/utils.h	Fri Jan 18 17:20:42 2008
@@ -49,8 +49,6 @@
 
 gboolean utils_ether_addr_valid (const struct ether_addr *test_addr);
 
-gboolean utils_check_ap_compatible (NMAccessPoint *ap, NMConnection *connection);
-
 gboolean utils_connection_valid_for_device (NMConnection *connection,
                                             NMDevice *device,
                                             gpointer specific_object);



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