network-manager-applet r738 - in trunk: . src



Author: dcbw
Date: Thu May 29 21:33:56 2008
New Revision: 738
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=738&view=rev

Log:
2008-05-29  Dan Williams  <dcbw redhat com>

	* src/applet.c
		- (applet_get_default_active_connection): if the only active connection
			is an adhoc connection but it's not 'default' becuase it doesn't
			have a route the internet, show it's state anyway



Modified:
   trunk/ChangeLog
   trunk/src/applet.c

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Thu May 29 21:33:56 2008
@@ -52,6 +52,7 @@
 #include <nm-setting-vpn-properties.h>
 #include <nm-active-connection.h>
 #include <nm-dbus-settings-system.h>
+#include <nm-setting-wireless.h>
 
 #include <glade/glade.h>
 #include <gconf/gconf-client.h>
@@ -133,6 +134,8 @@
 applet_get_default_active_connection (NMApplet *applet, NMDevice **device)
 {
 	NMActiveConnection *default_ac = NULL;
+	NMDevice *adhoc_device = NULL;
+	NMActiveConnection *adhoc_ac = NULL;
 	const GPtrArray *connections;
 	int i;
 
@@ -144,9 +147,42 @@
 	for (i = 0; connections && (i < connections->len); i++) {
 		NMActiveConnection *candidate = g_ptr_array_index (connections, i);
 		const GPtrArray *devices;
+		gboolean is_adhoc = FALSE;
 
-		if (!nm_active_connection_get_default (candidate))
-			continue;
+		/* If the only connection is an adhoc connection, show it even though
+		 * it's not 'default'.
+		 */
+		if (adhoc_ac == NULL) {
+			NMConnectionScope scope;
+			const char *cpath;
+			NMConnection *connection = NULL;
+
+			scope = nm_active_connection_get_scope (candidate);
+			cpath = nm_active_connection_get_connection (candidate);
+			if (scope == NM_CONNECTION_SCOPE_USER) {
+				NMAGConfConnection *gconf_connection;
+
+				gconf_connection = nma_gconf_settings_get_by_dbus_path (applet->gconf_settings, cpath);
+				if (gconf_connection)
+					connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (gconf_connection));
+			} else if (scope == NM_CONNECTION_SCOPE_SYSTEM) {
+				NMDBusConnection *dbus_connection;
+
+				dbus_connection = nm_dbus_settings_get_connection_by_path (applet->dbus_settings, cpath);
+				if (dbus_connection)
+					connection = nm_exported_connection_get_connection (NM_EXPORTED_CONNECTION (dbus_connection));
+			}
+
+			if (connection) {
+				NMSettingWireless *s_wireless;
+
+				s_wireless = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
+				if (s_wireless) {
+					if (s_wireless->mode && !strcmp (s_wireless->mode, "adhoc"))
+						is_adhoc = TRUE;
+				}
+			}
+		}
 
 		devices = nm_active_connection_get_devices (candidate);
 		if (!devices || !devices->len) {
@@ -155,11 +191,29 @@
 			continue;
 		}
 
+		if (!nm_active_connection_get_default (candidate)) {
+			/* Cache a non-default adhoc connection so that if it's the
+			 * only active connection, we'll return it even though it's not default.
+			 */
+			if (!adhoc_ac && is_adhoc) {
+				adhoc_device = g_ptr_array_index (devices, 0);
+				adhoc_ac = candidate;
+			}
+			continue;
+		}
+
 		*device = g_ptr_array_index (devices, 0);
 		default_ac = candidate;
 		break;
 	}
 
+	/* If the only active connection was a non-default adhoc connection,
+	 * return that.
+	 */
+	if (!default_ac && adhoc_ac) {
+		default_ac = adhoc_ac;
+		*device = adhoc_device;
+	}
 	return default_ac;
 }
 



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