network-manager-applet r826 - in trunk: . src/connection-editor



Author: dcbw
Date: Wed Aug  6 23:16:53 2008
New Revision: 826
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=826&view=rev

Log:
2008-08-06  Dan Williams  <dcbw redhat com>

	* src/connection-editor/ce-page-ip4.glade
		- Add a checkbox for 'ignore-auto-routes'

	* src/connection-editor/ip4-routes-dialog.c
	  src/connection-editor/ip4-routes-dialog.h
	  src/connection-editor/page-ip4.c
		- Handle route editing



Modified:
   trunk/ChangeLog
   trunk/src/connection-editor/ce-page-ip4.glade
   trunk/src/connection-editor/ip4-routes-dialog.c
   trunk/src/connection-editor/ip4-routes-dialog.h
   trunk/src/connection-editor/page-ip4.c

Modified: trunk/src/connection-editor/ce-page-ip4.glade
==============================================================================
--- trunk/src/connection-editor/ce-page-ip4.glade	(original)
+++ trunk/src/connection-editor/ce-page-ip4.glade	Wed Aug  6 23:16:53 2008
@@ -358,6 +358,19 @@
             <property name="position">1</property>
           </packing>
         </child>
+        <child>
+          <widget class="GtkCheckButton" id="ip4_ignore_auto_routes">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="label" translatable="yes">Ignore automatically obtained routes</property>
+            <property name="response_id">0</property>
+            <property name="draw_indicator">True</property>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
         <child internal-child="action_area">
           <widget class="GtkHButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>

Modified: trunk/src/connection-editor/ip4-routes-dialog.c
==============================================================================
--- trunk/src/connection-editor/ip4-routes-dialog.c	(original)
+++ trunk/src/connection-editor/ip4-routes-dialog.c	Wed Aug  6 23:16:53 2008
@@ -24,6 +24,8 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
+#include <errno.h>
+#include <stdlib.h>
 
 #include <glade/glade.h>
 #include <glib/gi18n.h>
@@ -32,7 +34,7 @@
 
 #define COL_ADDRESS 0
 #define COL_PREFIX  1
-#define COL_GATEWAY 2
+#define COL_NEXT_HOP 2
 #define COL_METRIC  3
 
 static void
@@ -184,7 +186,9 @@
 }
 
 GtkWidget *
-ip4_routes_dialog_new (GSList *routes)
+ip4_routes_dialog_new (GSList *routes,
+                       gboolean automatic,
+                       gboolean ignore_auto_routes)
 {
 	GladeXML *xml;
 	GtkWidget *dialog, *widget;
@@ -218,7 +222,7 @@
 
 	/* Add existing routes */
 	for (iter = routes; iter; iter = g_slist_next (iter)) {
-		NMSettingIP4Address *route = (NMSettingIP4Address *) iter->data;
+		NMSettingIP4Route *route = (NMSettingIP4Route *) iter->data;
 		struct in_addr tmp_addr;
 		char ip_string[50];
 
@@ -235,11 +239,11 @@
 
 		gtk_list_store_set (store, &model_iter, COL_PREFIX, g_strdup_printf ("%d", route->prefix), -1);
 
-		tmp_addr.s_addr = route->gateway;
+		tmp_addr.s_addr = route->next_hop;
 		if (inet_ntop (AF_INET, &tmp_addr, &ip_string[0], sizeof (ip_string)))
-			gtk_list_store_set (store, &model_iter, COL_GATEWAY, g_strdup (ip_string), -1);
+			gtk_list_store_set (store, &model_iter, COL_NEXT_HOP, g_strdup (ip_string), -1);
 
-		gtk_list_store_set (store, &model_iter, COL_METRIC, g_strdup_printf ("%d", 1), -1);
+		gtk_list_store_set (store, &model_iter, COL_METRIC, g_strdup_printf ("%d", route->metric), -1);
 	}
 
 	widget = glade_xml_get_widget (xml, "ip4_routes");
@@ -280,12 +284,12 @@
 	renderer = gtk_cell_renderer_text_new ();
 	g_object_set (renderer, "editable", TRUE, NULL);
 	g_signal_connect (renderer, "edited", G_CALLBACK (cell_edited), xml);
-	g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER (COL_GATEWAY));
+	g_object_set_data (G_OBJECT (renderer), "column", GUINT_TO_POINTER (COL_NEXT_HOP));
 	g_signal_connect (renderer, "editing-started", G_CALLBACK (cell_editing_started), store);
 
 	offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (widget),
 	                                                      -1, _("Gateway"), renderer,
-	                                                      "text", COL_GATEWAY,
+	                                                      "text", COL_NEXT_HOP,
 	                                                      NULL);
 	column = gtk_tree_view_get_column (GTK_TREE_VIEW (widget), offset - 1);
 	gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
@@ -322,11 +326,130 @@
 	                  G_CALLBACK (route_delete_clicked),
 	                  glade_xml_get_widget (xml, "ip4_routes"));
 
+	widget = glade_xml_get_widget (xml, "ip4_ignore_auto_routes");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), ignore_auto_routes);
+	gtk_widget_set_sensitive (widget, automatic);
+
 	return dialog;
 }
 
+static gboolean
+get_one_int (GtkTreeModel *model,
+             GtkTreeIter *iter,
+             int column,
+             const char *name,
+             guint32 max_value,
+             guint32 *out)
+{
+	char *item = NULL;
+	gboolean success = FALSE;
+	long int tmp_int;
+
+	gtk_tree_model_get (model, iter, column, &item, -1);
+	if (!item) {
+		g_warning ("%s: IPv4 %s '%s' missing!",
+		           __func__, name, item ? item : "<none>");
+		return FALSE;
+	}
+
+	errno = 0;
+	tmp_int = strtol (item, NULL, 10);
+	if (errno || tmp_int < 0 || tmp_int > max_value) {
+		g_warning ("%s: IPv4 %s '%s' invalid!",
+		           __func__, name, item ? item : "<none>");
+		goto out;
+	}
+	*out = (guint32) tmp_int;
+	success = TRUE;
+
+out:
+	g_free (item);
+	return success;
+}
+
+static gboolean
+get_one_addr (GtkTreeModel *model,
+              GtkTreeIter *iter,
+              int column,
+              const char *name,
+              gboolean fail_if_missing,
+              guint32 *out)
+{
+	char *item = NULL;
+	struct in_addr tmp_addr;
+	gboolean success = FALSE;
+
+	gtk_tree_model_get (model, iter, column, &item, -1);
+	if (!item && !fail_if_missing)
+		return TRUE;
+
+	if (item && (inet_pton (AF_INET, item, &tmp_addr) > 0)) {
+		*out = tmp_addr.s_addr;
+		success = TRUE;
+	} else {
+		g_warning ("%s: IPv4 %s '%s' missing or invalid!",
+	           __func__, name, item ? item : "<none>");
+	}
+
+	g_free (item);
+	return success;
+}
+
 void
 ip4_routes_dialog_update_setting (GtkWidget *dialog, NMSettingIP4Config *s_ip4)
 {
+	GladeXML *xml;
+	GtkWidget *widget;
+	GtkTreeModel *model;
+	GtkTreeIter tree_iter;
+	gboolean iter_valid;
+
+	g_return_if_fail (dialog != NULL);
+	g_return_if_fail (s_ip4 != NULL);
+
+	xml = g_object_get_data (G_OBJECT (dialog), "glade-xml");
+	g_return_if_fail (xml != NULL);
+	g_return_if_fail (GLADE_IS_XML (xml));
+
+	widget = glade_xml_get_widget (xml, "ip4_routes");
+	model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+	iter_valid = gtk_tree_model_get_iter_first (model, &tree_iter);
+
+	g_slist_foreach (s_ip4->routes, (GFunc) g_free, NULL);
+	g_slist_free (s_ip4->routes);
+	s_ip4->routes = NULL;
+
+	while (iter_valid) {
+		guint32 addr = 0, prefix = 0, next_hop = 0, metric = 0;
+		NMSettingIP4Route *route;
+
+		/* Address */
+		if (!get_one_addr (model, &tree_iter, COL_ADDRESS, "address", TRUE, &addr))
+			goto next;
+
+		/* Prefix */
+		if (!get_one_int (model, &tree_iter, COL_PREFIX, "prefix", 32, &prefix))
+			goto next;
+
+		/* Next hop (optional) */
+		get_one_addr (model, &tree_iter, COL_NEXT_HOP, "next hop", TRUE, &next_hop);
+
+		/* Prefix (optional) */
+		get_one_int (model, &tree_iter, COL_METRIC, "metric", G_MAXUINT32, &metric);
+
+		route = g_malloc0 (sizeof (NMSettingIP4Route));
+		route->address = addr;
+		route->prefix = prefix;
+		route->next_hop = next_hop;
+		route->metric = metric;
+
+		s_ip4->routes = g_slist_append (s_ip4->routes, route);
+
+	next:
+		iter_valid = gtk_tree_model_iter_next (model, &tree_iter);
+	}
+
+	widget = glade_xml_get_widget (xml, "ip4_ignore_auto_routes");
+	s_ip4->ignore_auto_routes = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
 }
 

Modified: trunk/src/connection-editor/ip4-routes-dialog.h
==============================================================================
--- trunk/src/connection-editor/ip4-routes-dialog.h	(original)
+++ trunk/src/connection-editor/ip4-routes-dialog.h	Wed Aug  6 23:16:53 2008
@@ -28,7 +28,9 @@
 
 #include "nm-setting-ip4-config.h"
 
-GtkWidget *ip4_routes_dialog_new (GSList *routes);
+GtkWidget *ip4_routes_dialog_new (GSList *routes,
+                                  gboolean automatic,
+                                  gboolean ignore_auto_routes);
 
 void ip4_routes_dialog_update_setting (GtkWidget *dialog, NMSettingIP4Config *s_ip4);
 

Modified: trunk/src/connection-editor/page-ip4.c
==============================================================================
--- trunk/src/connection-editor/page-ip4.c	(original)
+++ trunk/src/connection-editor/page-ip4.c	Wed Aug  6 23:16:53 2008
@@ -106,7 +106,7 @@
 
 	gtk_list_store_append (priv->method_store, &iter);
 	gtk_list_store_set (priv->method_store, &iter,
-	                    METHOD_COL_NAME, _("Automatic with manual DNS settings"),
+	                    METHOD_COL_NAME, _("Automatic addressing only"),
 	                    METHOD_COL_NUM, IP4_METHOD_AUTO_MANUAL_DNS,
 	                    -1);
 
@@ -254,7 +254,7 @@
 			method = IP4_METHOD_SHARED;
 	}
 
-	if (method == IP4_METHOD_AUTO && setting->ignore_dhcp_dns)
+	if (method == IP4_METHOD_AUTO && setting->ignore_auto_dns)
 		method = IP4_METHOD_AUTO_MANUAL_DNS;
 
 	info.method = method;
@@ -499,11 +499,15 @@
 	CEPageIP4 *self = CE_PAGE_IP4 (user_data);
 	CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
 	GtkWidget *dialog, *toplevel;
+	gboolean automatic = FALSE;
 
 	toplevel = gtk_widget_get_toplevel (CE_PAGE (self)->page);
 	g_return_if_fail (GTK_WIDGET_TOPLEVEL (toplevel));
 
-	dialog = ip4_routes_dialog_new (priv->setting->routes);
+	if (!strcmp (priv->setting->method, NM_SETTING_IP4_CONFIG_METHOD_AUTO))
+		automatic = TRUE;
+	
+	dialog = ip4_routes_dialog_new (priv->setting->routes, automatic, priv->setting->ignore_auto_routes);
 	if (!dialog) {
 		g_warning ("%s: failed to create the routes dialog!", __func__);
 		return;
@@ -666,7 +670,7 @@
 	GPtrArray *addresses = NULL;
 	gboolean valid = FALSE, iter_valid;
 	const char *text;
-	gboolean ignore_dhcp_dns = FALSE;
+	gboolean ignore_auto_dns = FALSE;
 	const char *dhcp_client_id = NULL;
 	char **items = NULL, **iter;
 
@@ -687,7 +691,7 @@
 		method = NM_SETTING_IP4_CONFIG_METHOD_SHARED;
 		break;
 	case IP4_METHOD_AUTO_MANUAL_DNS:
-		ignore_dhcp_dns = TRUE;
+		ignore_auto_dns = TRUE;
 		/* fall through */
 	default:
 		method = NM_SETTING_IP4_CONFIG_METHOD_AUTO;
@@ -806,7 +810,7 @@
 				  NM_SETTING_IP4_CONFIG_ADDRESSES, addresses,
 				  NM_SETTING_IP4_CONFIG_DNS, dns_servers,
 				  NM_SETTING_IP4_CONFIG_DNS_SEARCH, search_domains,
-				  NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+				  NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, ignore_auto_dns,
 				  NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, dhcp_client_id,
 				  NULL);
 	valid = TRUE;



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