Index: capplets/network/gnome-network-preferences.glade
===================================================================
--- capplets/network/gnome-network-preferences.glade	(revision 8930)
+++ capplets/network/gnome-network-preferences.glade	(working copy)
@@ -21,11 +21,54 @@
   <property name="urgency_hint">False</property>
   <property name="has_separator">False</property>
 
-  <child internal-child="vbox">
-    <widget class="GtkVBox" id="dialog-vbox1">
-      <property name="visible">True</property>
-      <property name="homogeneous">False</property>
-      <property name="spacing">2</property>
+      <child internal-child="vbox">
+	<widget class="GtkVBox" id="dialog-vbox1">
+	<property name="visible">True</property>
+	<property name="homogeneous">False</property>
+	<property name="spacing">2</property>
+	  <child>
+		<widget class="GtkHBox" id="hbox2">
+		  <property name="visible">True</property>
+		  <property name="spacing">3</property>
+		  <child>
+			<widget class="GtkLabel" id="label1">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">Location:</property>
+			  <property name="xalign">1</property>
+			</widget>
+			<packing>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		  </child>
+		  <child>
+			<widget class="GtkComboBox" id="location_combobox">
+			  <property name="visible">True</property>
+			</widget>
+			<packing>
+			  <property name="position">1</property>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		  </child>
+		  <child>
+			<widget class="GtkLabel" id="label2">
+			  <property name="visible">True</property>
+			  <property name="label"></property>
+			  <property name="xalign">1</property>
+			</widget>
+			<packing>
+			  <property name="expand">True</property>
+			  <property name="fill">True</property>
+			</packing>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		  <property name="position">1</property>
+		</packing>
+	  </child>
 
       <child internal-child="action_area">
 	<widget class="GtkHButtonBox" id="dialog-action_area1">
@@ -44,7 +87,14 @@
 	      <property name="response_id">-11</property>
 	    </widget>
 	  </child>
-
+	  <child>
+		<widget class="GtkButton" id="delete_button">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="sensitive">False</property>
+		  <property name="label" translatable="yes">_Delete Location</property>
+		</widget>
+	  </child>
 	  <child>
 	    <widget class="GtkButton" id="closebutton1">
 	      <property name="visible">True</property>
Index: capplets/network/gnome-network-preferences.c
===================================================================
--- capplets/network/gnome-network-preferences.c	(revision 8930)
+++ capplets/network/gnome-network-preferences.c	(working copy)
@@ -46,6 +46,11 @@ static GEnumValue proxytype_values[] = {
 	{ 0, NULL, NULL }
 };
 
+enum {
+	COL_NAME,
+	COL_STYLE
+};
+
 #define USE_PROXY_KEY   "/system/http_proxy/use_http_proxy"
 #define USE_SAME_PROXY_KEY   "/system/http_proxy/use_same_proxy"
 #define HTTP_PROXY_HOST_KEY  "/system/http_proxy/host"
@@ -68,6 +73,11 @@ static GEnumValue proxytype_values[] = {
 #define SOCKS_PROXY_PORT_KEY  "/system/proxy/socks_port"
 #define OLD_SOCKS_PROXY_PORT_KEY  "/system/proxy/old_socks_port"
 #define PROXY_AUTOCONFIG_URL_KEY  "/system/proxy/autoconfig_url"
+#define LOCATION_DIR "/apps/control-center/network"
+#define CURRENT_LOCATION "/apps/control-center/network/current_location"
+
+/* FIXME: get rid of this */
+#define LOCATION_LAST_DELETED "/apps/control-center/network/last_deleted"
 
 static GtkWidget *details_dialog = NULL;
 static GSList *ignore_hosts = NULL;
@@ -177,10 +187,12 @@ static void
 cb_dialog_response (GtkDialog *dialog, gint response_id)
 {
 	if (response_id == GTK_RESPONSE_HELP)
+	{
 		capplet_help (GTK_WINDOW (dialog),
 			"user-guide.xml",
 			"goscustdesk-50");
-	else
+	}
+	else if (response_id == GTK_RESPONSE_CLOSE || response_id == GTK_RESPONSE_DELETE_EVENT)
 	{
 		if (ignore_hosts) {
 			g_slist_foreach (ignore_hosts, (GFunc) g_free, NULL);
@@ -258,6 +270,492 @@ cb_http_details_button_clicked (GtkWidge
 }
 
 static void
+copy_location (const gchar *from, const gchar *to, GConfClient *client)
+{
+	int ti;
+	gboolean tb;
+	GSList *tl;
+	gchar *tstr, *dest, *src;
+
+	/* FIXME: don't recreate the entire gconf tree under control-center/network;
+	 * ie. instead of .../network/location/system/... use .../network/location/...
+	 * directly */
+
+	/* USE_PROXY */
+	dest = g_strconcat (to, USE_PROXY_KEY, NULL);
+	src = g_strconcat (from, USE_PROXY_KEY, NULL);
+
+	tb = gconf_client_get_bool (client, src, NULL);
+	gconf_client_set_bool (client, dest, tb, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* USE_SAME_PROXY */
+	dest = g_strconcat (to, USE_SAME_PROXY_KEY, NULL);
+	src = g_strconcat (from, USE_SAME_PROXY_KEY, NULL);
+
+	tb = gconf_client_get_bool (client, src, NULL);
+	gconf_client_set_bool (client, dest, tb, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* HTTP_PROXY_HOST */
+	dest = g_strconcat (to, HTTP_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, HTTP_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* HTTP_PROXY_PORT */
+	dest = g_strconcat (to, HTTP_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, HTTP_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* HTTP_USE_AUTH */
+	dest = g_strconcat (to, HTTP_USE_AUTH_KEY, NULL);
+	src = g_strconcat (from, HTTP_USE_AUTH_KEY, NULL);
+
+	tb = gconf_client_get_bool (client, src, NULL);
+	gconf_client_set_bool (client, dest, tb, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* HTTP_AUTH_USER */
+	dest = g_strconcat (to, HTTP_AUTH_USER_KEY, NULL);
+	src = g_strconcat (from, HTTP_AUTH_USER_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* HTTP_AUTH_PASSWD */
+	dest = g_strconcat (to, HTTP_AUTH_PASSWD_KEY, NULL);
+	src = g_strconcat (from, HTTP_AUTH_PASSWD_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		 gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* IGNORE_HOSTS */
+	dest = g_strconcat (to, IGNORE_HOSTS_KEY, NULL);
+	src = g_strconcat (from, IGNORE_HOSTS_KEY, NULL);
+
+	tl = gconf_client_get_list (client, src, GCONF_VALUE_STRING, NULL);
+	gconf_client_set_list (client, dest, GCONF_VALUE_STRING, tl, NULL);
+	g_slist_foreach (tl, (GFunc) g_free, NULL);
+	g_slist_free (tl);
+
+	g_free (dest);
+	g_free (src);
+
+	/* PROXY_MODE */
+	dest = g_strconcat (to, PROXY_MODE_KEY,NULL);
+	src = g_strconcat (from, PROXY_MODE_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* SECURE_PROXY_HOST */
+	dest = g_strconcat (to, SECURE_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, SECURE_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* OLD_SECURE_PROXY_HOST */
+	dest = g_strconcat (to, OLD_SECURE_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, OLD_SECURE_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* SECURE_PROXY_PORT */
+	dest = g_strconcat (to, SECURE_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, SECURE_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* OLD_SECURE_PROXY_PORT */
+	dest = g_strconcat (to, OLD_SECURE_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, OLD_SECURE_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* FTP_PROXY_HOST */
+	dest = g_strconcat (to, FTP_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, FTP_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* OLD_FTP_PROXY_HOST */
+	dest = g_strconcat (to, OLD_FTP_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, OLD_FTP_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* FTP_PROXY_PORT_KEY */
+	dest = g_strconcat (to, FTP_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, FTP_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* OLD_FTP_PROXY_PORT */
+	dest = g_strconcat (to, OLD_FTP_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, OLD_FTP_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* SOCKS_PROXY_HOST */
+	dest = g_strconcat (to, SOCKS_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, SOCKS_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free	(dest);
+	g_free (src);
+
+	/* OLD_SOCKS_PROXY_HOST */
+	dest = g_strconcat (to, OLD_SOCKS_PROXY_HOST_KEY, NULL);
+	src = g_strconcat (from, OLD_SOCKS_PROXY_HOST_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+
+	/* SOCKS_PROXY_PORT */
+	dest = g_strconcat (to, SOCKS_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, SOCKS_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* OLD_SOCKS_PROXY_PORT */
+	dest = g_strconcat (to, OLD_SOCKS_PROXY_PORT_KEY, NULL);
+	src = g_strconcat (from, OLD_SOCKS_PROXY_PORT_KEY, NULL);
+
+	ti = gconf_client_get_int (client, src, NULL);
+	gconf_client_set_int (client, dest, ti, NULL);
+
+	g_free (dest);
+	g_free (src);
+
+	/* PROXY_AUTOCONFIG_URL */
+	dest = g_strconcat (to, PROXY_AUTOCONFIG_URL_KEY, NULL);
+	src = g_strconcat (from, PROXY_AUTOCONFIG_URL_KEY, NULL);
+
+	tstr = gconf_client_get_string (client, src, NULL);
+	if (tstr != NULL)
+	{
+		gconf_client_set_string (client, dest, tstr, NULL);
+		g_free (tstr);
+	}
+
+	g_free (dest);
+	g_free (src);
+}
+
+static void
+save_location (GConfClient *client, const gchar *key)
+{
+	copy_location ("", key, client);
+}
+
+static gboolean
+location_combo_separator (GtkTreeModel *model,
+			  GtkTreeIter *iter,
+			  gpointer data)
+{
+	gchar *name;
+	gboolean ret;
+
+	gtk_tree_model_get (model, iter, COL_NAME, &name, -1);
+
+	ret = name == NULL || name[0] == '\0';
+
+	g_free (name);
+
+	return ret;
+}
+
+static void
+location_new (GladeXML *dialog)
+{
+	GtkWidget *askdialog, *text, *content_area;
+	const gchar *name;
+	int response;
+
+	/* FIXME: use "Create"/"Cancel" for buttons */
+	askdialog = gtk_dialog_new_with_buttons (_("Create New Location"),
+	                                         NULL,
+	                                         GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_MODAL,
+	                                         GTK_STOCK_OK,
+	                                         GTK_RESPONSE_OK,
+	                                         GTK_STOCK_CANCEL,
+	                                         GTK_RESPONSE_CANCEL,
+	                                         NULL);
+	/* FIXME: move to glade?, add label/explanatory text
+	 * like: "Please enter a name for the new location:" */
+	content_area = gtk_dialog_get_content_area (GTK_DIALOG (askdialog));
+	text = gtk_entry_new ();
+	gtk_widget_show (text);
+	gtk_container_add (GTK_CONTAINER (content_area), text);
+
+	response = gtk_dialog_run (GTK_DIALOG (askdialog));
+	name = gtk_entry_get_text (GTK_ENTRY (text));
+
+	/* FIXME: if user chooses CANCEL, the combobox needs to
+	 * go back to the previous setting instead of staying on
+	 * New Location */
+	if (response == GTK_RESPONSE_OK && name[0] != '\0')
+	{
+		GConfClient *client;
+		gchar *key_name, *key_esc;
+
+		/* FIXME: this is still a bit off: I started with
+		 * only "Default" in the list, hit new, "Test",
+		 * and ended up with only "Test" and my "Default"
+		 * location was gone */
+		client = gconf_client_get_default ();
+
+		key_esc = gconf_escape_key (name, -1);
+		key_name = g_strconcat (LOCATION_DIR "/", key_esc, NULL);
+
+		gconf_client_set_string (client, LOCATION_LAST_DELETED, "", NULL);
+		save_location (client, key_name);
+		gconf_client_set_string (client, CURRENT_LOCATION, key_esc, NULL);
+
+		g_free (key_name);
+		g_free (key_esc);
+		g_object_unref (client);
+	}
+	gtk_widget_destroy (askdialog);
+}
+
+static void
+cb_change_location_dir (GConfClient *client,
+			guint cnxn_id,
+			GConfEntry *entry,
+			GladeXML *dialog)
+{
+	int i, select;
+	gchar *current = gconf_client_get_string (client, CURRENT_LOCATION, NULL);
+	GtkComboBox *location = GTK_COMBO_BOX (WID ("location_combobox"));
+	GSList *list = gconf_client_all_dirs (client, LOCATION_DIR, NULL);
+	GtkTreeIter titer;
+	GtkListStore *store;
+	GSList *iter;
+
+	store = GTK_LIST_STORE (gtk_combo_box_get_model (location));
+	gtk_list_store_clear (store);
+
+	select = -1;
+	for (i = 0, iter = list; iter != NULL; iter = g_slist_next (iter), ++i)
+	{
+		gchar *locp, *key_name;
+
+		locp = iter->data + strlen (LOCATION_DIR) + 1;
+		key_name = gconf_unescape_key (locp, -1);
+
+		gtk_list_store_append (store, &titer);
+		gtk_list_store_set (store, &titer,
+				    COL_NAME, key_name,
+		 		    COL_STYLE, PANGO_STYLE_NORMAL, -1);
+
+		g_free (key_name);
+
+		if (current != NULL && strcmp (locp, current) == 0)
+			select = i;
+	}
+	if (i == 0)
+	{
+		gtk_list_store_append (store, &titer);
+		gtk_list_store_set (store, &titer,
+				    COL_NAME , _("Default"),
+				    COL_STYLE, PANGO_STYLE_NORMAL, -1);
+		++i;
+	}
+	if (select == -1) select = i - 1;
+	gtk_widget_set_sensitive (WID ("delete_button"), i > 1);
+
+	gtk_list_store_append (store, &titer);
+	gtk_list_store_set (store, &titer,
+			    COL_NAME, "",
+			    COL_STYLE, PANGO_STYLE_NORMAL, -1);
+
+	gtk_list_store_append (store, &titer);
+	gtk_list_store_set (store, &titer,
+			    COL_NAME, _("New Location..."),
+			    COL_STYLE, PANGO_STYLE_ITALIC, -1);
+
+	gtk_combo_box_set_row_separator_func (location, location_combo_separator, NULL, NULL);
+	gtk_combo_box_set_active (location, select);
+	g_free (current);
+	g_slist_foreach (list, (GFunc) gconf_entry_free, NULL);
+	g_slist_free (list);
+}
+
+static void
+cb_location_changed (GtkWidget *location,
+		     GladeXML *dialog)
+{
+	static gchar *last_location = NULL;
+	gchar *name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (location));
+	GConfClient *client = gconf_client_get_default ();
+
+	if (name == NULL) return;
+
+	if (last_location != NULL)
+	{
+		gchar *str = gconf_client_get_string (client, LOCATION_LAST_DELETED, NULL);
+		if (str == NULL || strcmp (str, last_location + strlen (LOCATION_DIR) + 1) != 0)	copy_location ("", last_location, client);
+		g_free (str);
+	}
+
+	if (strcmp (name, _("New Location...")) == 0)
+	{
+		location_new (dialog);
+	}
+	else
+	{
+		gchar *key, *str, *current;
+
+		key = gconf_escape_key (name, -1);
+		str = g_strconcat (LOCATION_DIR "/", key, NULL);
+		g_free (key);
+
+		current = gconf_client_get_string (client, CURRENT_LOCATION, NULL);
+
+		if (strcmp (current, name) != 0)
+		{
+			gconf_client_set_string (client, CURRENT_LOCATION, name, NULL);
+			copy_location (str, "", client);
+		}
+		g_free (last_location);
+		last_location = str;
+		g_free (current);
+	}
+	g_free (name);
+	g_object_unref (client);
+}
+
+static void
+cb_delete_button_clicked (GtkWidget *button,
+			  GladeXML *dialog)
+{
+	GConfClient *client = gconf_client_get_default ();
+	gchar *name = gconf_client_get_string (client, CURRENT_LOCATION, NULL);
+
+	if (name != NULL)
+	{
+		gchar *str = g_strconcat (LOCATION_DIR "/", name, NULL);
+
+		gtk_combo_box_set_active (GTK_COMBO_BOX (WID ("location_combobox")), 0);
+
+		gconf_client_set_string (client, LOCATION_LAST_DELETED, name, NULL);
+		gconf_client_recursive_unset (client, str, GCONF_UNSET_INCLUDING_SCHEMA_NAMES, NULL);
+
+		g_free (str);
+		g_free (name);
+	}
+
+	g_object_unref (client);
+}
+
+static void
 cb_use_same_proxy_checkbutton_clicked (GtkWidget *checkbutton,
 					GladeXML *dialog)
 {
@@ -438,6 +936,9 @@ setup_dialog (GladeXML *dialog)
 	GType mode_type = 0;
 	GConfClient *client;
 	gint port_value;
+	GtkWidget *location_box;
+	GtkCellRenderer *location_renderer;
+	GtkListStore *store;
 
 	mode_type = g_enum_register_static ("NetworkPreferencesProxyType",
 				            proxytype_values);
@@ -445,6 +946,29 @@ setup_dialog (GladeXML *dialog)
 	/* There's a bug in peditors that cause them to not initialize the entry
 	 * correctly. */
 	client = gconf_client_get_default ();
+
+	/* Locations */
+	location_box = WID ("location_combobox");
+	store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+	gtk_combo_box_set_model (GTK_COMBO_BOX (location_box), GTK_TREE_MODEL (store));
+
+	cb_change_location_dir (client, 0, NULL, dialog);
+	gconf_client_add_dir (client, LOCATION_DIR, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+	gconf_client_notify_add (client, LOCATION_DIR, (GConfClientNotifyFunc) cb_change_location_dir, dialog, NULL, NULL);
+	gconf_client_notify_add (client, CURRENT_LOCATION, (GConfClientNotifyFunc) cb_change_location_dir, dialog, NULL, NULL);
+
+	g_signal_connect (location_box, "changed", G_CALLBACK (cb_location_changed), dialog);
+	g_signal_connect (WID ("delete_button"), "clicked", G_CALLBACK (cb_delete_button_clicked), dialog);
+
+	gtk_button_set_image (GTK_BUTTON (WID ("delete_button")),
+			      gtk_image_new_from_stock (GTK_STOCK_DELETE, GTK_ICON_SIZE_BUTTON));
+
+	location_renderer = gtk_cell_renderer_text_new ();
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (location_box), location_renderer, TRUE);
+	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (location_box),
+					location_renderer,
+					"text", COL_NAME,
+					"style", COL_STYLE, NULL);
 
 	/* Hackety hack */
 	gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("none_radiobutton"))->child), TRUE);
