? .nautilus-connect-server-dialog.c.swp
? nautilus-connect-server-dialog.glade
? nautilus-connect-server-dialog.gladep
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/nautilus/src/Makefile.am,v
retrieving revision 1.155
diff -u -p -r1.155 Makefile.am
--- Makefile.am	18 Feb 2004 11:59:02 -0000	1.155
+++ Makefile.am	31 May 2004 13:29:47 -0000
@@ -164,6 +164,7 @@ gladedir = $(datadir)/nautilus/glade
 glade_DATA = \
 	nautilus-bookmarks-window.glade			\
 	nautilus-file-management-properties.glade	\
+	nautilus-connect-server-dialog.glade		\
 	$(NULL)
 
 CLEANFILES = \
Index: nautilus-connect-server-dialog.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-connect-server-dialog.c,v
retrieving revision 1.7
diff -u -p -r1.7 nautilus-connect-server-dialog.c
--- nautilus-connect-server-dialog.c	6 Feb 2004 17:25:36 -0000	1.7
+++ nautilus-connect-server-dialog.c	31 May 2004 13:29:48 -0000
@@ -28,15 +28,19 @@
 #include <eel/eel-gtk-macros.h>
 #include <eel/eel-stock-dialogs.h>
 #include <eel/eel-vfs-extensions.h>
-#include <gtk/gtkhbox.h>
-#include <gtk/gtktable.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkstock.h>
+#include <gtk/gtk.h>
+#include <glade/glade.h>
 #include "nautilus-location-entry.h"
 
 struct _NautilusConnectServerDialogDetails {
-	GtkWidget *name_entry;
 	GtkWidget *uri_entry;
+	
+	GtkWidget *add_favourite_button;
+	GtkWidget *remove_button;
+	GtkWidget *connect_server_button;
+
+	GtkListStore *recent_servers_list;
+	GtkListStore *favourite_servers_list;
 };
 
 static void  nautilus_connect_server_dialog_class_init       (NautilusConnectServerDialogClass *class);
@@ -71,6 +75,41 @@ nautilus_connect_server_dialog_destroy (
 	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
 }
 
+/* this function was ripped off from nautilus-window.c */
+static char *
+compute_default_title (const char *text_uri)
+{
+        NautilusFile *file;
+        GnomeVFSURI *uri;
+        char *title, *displayname;
+        const char *hostname;
+
+        hostname = NULL;
+
+        if (text_uri) {
+                file = nautilus_file_get (text_uri);
+                uri = gnome_vfs_uri_new (text_uri);
+                if (uri && !gnome_vfs_uri_is_local (uri)) {
+                        hostname = gnome_vfs_uri_get_host_name (uri);
+                }
+                displayname = nautilus_file_get_display_name (file);
+                if (hostname) {
+                        title = g_strdup_printf (_("%s on %s"), displayname, hostname);
+                        g_free (displayname);
+                } else {
+                        title = displayname;
+                }
+                if (uri) {
+                        gnome_vfs_uri_unref (uri);
+                }
+                nautilus_file_unref (file);
+        } else {
+                title = g_strdup ("");
+        }
+
+        return title;
+}
+
 static void
 connect_to_server (NautilusConnectServerDialog *dialog)
 {
@@ -81,20 +120,12 @@ connect_to_server (NautilusConnectServer
 	char *name;
 	char *icon;
 
-	name = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->name_entry), 0, -1);
-	if (strlen (name) == 0) {
-                eel_show_error_dialog (_("You must enter a name for the server."), 
-		                       _("Please enter a name and try again."), 
-		                       _("Can't Connect to Server"), GTK_WINDOW (dialog));
-		g_free (name);
-		return;
-	}
-	
 	user_uri = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->uri_entry), 0, -1);
 	uri = eel_make_uri_from_input (user_uri);
 	g_free (user_uri);
 	
 	vfs_uri = gnome_vfs_uri_new (uri);
+	name = compute_default_title (uri);
 	
 	if (vfs_uri == NULL) {
 		error_message = g_strdup_printf
@@ -117,9 +148,12 @@ connect_to_server (NautilusConnectServer
 		}
 
 		gnome_vfs_connect_to_server (uri, name, icon);
+
+		/* FIXME: Add code to store recent servers */
+
 		gtk_widget_destroy (GTK_WIDGET (dialog));
 	}
-		g_free (name);
+	g_free (name);
 	g_free (uri);
 }
 
@@ -143,7 +177,7 @@ response_callback (NautilusConnectServer
 }
 
 static void
-entry_activate_callback (GtkEntry *entry,
+url_entry_activate_callback (GtkEntry *entry,
 			 gpointer user_data)
 {
 	NautilusConnectServerDialog *dialog;
@@ -153,6 +187,110 @@ entry_activate_callback (GtkEntry *entry
 }
 
 static void
+entry_changed_cb (GtkEditable *editable, gpointer user_data)
+{
+	NautilusConnectServerDialog *dialog;
+	gchar *text;
+	gboolean value;
+
+	dialog = NAUTILUS_CONNECT_SERVER_DIALOG (user_data);
+
+	text = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->uri_entry), 0, -1);
+
+	value = strlen (text) != 0;
+	gtk_widget_set_sensitive (dialog->details->connect_server_button, value);
+	gtk_widget_set_sensitive (dialog->details->add_favourite_button, value);
+
+	g_free (text);
+
+	/* FIXME: we should unselect the current selected Favourite here */
+}
+
+static void
+add_favourite_button_clicked_cb (GtkWidget *button, gpointer user_data)
+{
+	NautilusConnectServerDialog *dialog;
+	GtkTreeIter iter;
+	gboolean is_in_list;
+	gchar *text, *uri;
+
+	dialog = NAUTILUS_CONNECT_SERVER_DIALOG (user_data);
+	is_in_list = FALSE;
+
+	uri = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->uri_entry), 0, -1);
+	if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dialog->details->favourite_servers_list), &iter))
+		do
+		{
+			gtk_tree_model_get (GTK_TREE_MODEL (dialog->details->favourite_servers_list), &iter, 0, &text, -1);
+			is_in_list = is_in_list || (strcmp (uri, text) == 0);
+			g_free (text);
+		}
+		while (gtk_tree_model_iter_next (GTK_TREE_MODEL (dialog->details->favourite_servers_list), &iter));
+
+	if (!is_in_list)
+	{
+		gtk_list_store_append (dialog->details->favourite_servers_list, &iter);
+		gtk_list_store_set (dialog->details->favourite_servers_list, &iter,
+				0, uri,
+				-1);
+	
+		/* FIXME: store this favourite somewhere */
+	}
+}
+
+static void
+server_selected_callback (GtkTreeSelection	*selection,
+			  gpointer		user_data)
+{
+	NautilusConnectServerDialog *dialog;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	char *uri;
+
+	dialog = NAUTILUS_CONNECT_SERVER_DIALOG (user_data);
+
+	if (gtk_tree_selection_get_selected (selection, &model, &iter))
+	{
+		gtk_widget_set_sensitive (dialog->details->remove_button, TRUE);
+		
+		gtk_tree_model_get (model, &iter, 0, &uri, -1);
+		gtk_entry_set_text (GTK_ENTRY (dialog->details->uri_entry), g_strdup (uri));
+
+		g_free (uri);
+	}
+	else
+	{
+		gtk_widget_set_sensitive (dialog->details->remove_button, FALSE);
+	}
+}
+
+static void
+server_activated_callback (GtkTreeView		*tree,
+			   GtkTreePath		*arg1,
+			   GtkTreeViewColumn	*arg2,
+			   gpointer		user_data)
+{
+	NautilusConnectServerDialog *dialog;
+
+	dialog = NAUTILUS_CONNECT_SERVER_DIALOG (user_data);
+
+	connect_to_server (dialog);
+}
+
+static void
+remove_button_clicked_cb (GtkWidget *button, gpointer user_data)
+{
+	GtkTreeSelection *selection;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	selection = GTK_TREE_SELECTION (user_data);
+	
+	if (gtk_tree_selection_get_selected (selection, &model, &iter))
+		gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+}
+
+static void
 nautilus_connect_server_dialog_class_init (NautilusConnectServerDialogClass *class)
 {
 	GObjectClass *gobject_class;
@@ -168,91 +306,77 @@ nautilus_connect_server_dialog_class_ini
 static void
 nautilus_connect_server_dialog_init (NautilusConnectServerDialog *dialog)
 {
-	GtkWidget *label;
-	GtkWidget *table;
-	char *text;
+	GladeXML *xml;
+	GtkWidget *widget;
+	GtkCellRenderer *renderer;
+	
+	xml = glade_xml_new (GLADEDIR "/nautilus-connect-server-dialog.glade", "cts_vbox", NULL);
+	widget = glade_xml_get_widget (xml, "cts_vbox");
+	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), widget, TRUE, TRUE, 0);
 	
 	dialog->details = g_new0 (NautilusConnectServerDialogDetails, 1);
 
 	gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Server"));
-	gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1);
+	gtk_window_set_default_size (GTK_WINDOW (dialog), 500, -1);
 	gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
 	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
 	gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
 
-	table = gtk_table_new (3, 2, FALSE);
-	gtk_container_set_border_width (GTK_CONTAINER (table), 5);
-	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
-			    table, TRUE, TRUE, 0);
-	gtk_table_set_row_spacings (GTK_TABLE (table), 6);
-	gtk_table_set_col_spacings (GTK_TABLE (table), 12);
-	gtk_widget_show (table);
-	
-	label = gtk_label_new_with_mnemonic (_("Link _name:"));
-	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-	gtk_widget_show (label);
-	gtk_table_attach (GTK_TABLE (table), label,
-			  0, 1,
-			  0, 1,
-			  GTK_FILL, GTK_FILL,
-			  0, 0);
-	
-	dialog->details->name_entry = gtk_entry_new ();
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->name_entry);
-	gtk_widget_show (dialog->details->name_entry);
-	gtk_table_attach (GTK_TABLE (table), dialog->details->name_entry,
-			  1, 2,
-			  0, 1,
-			  GTK_FILL | GTK_EXPAND, GTK_FILL,
-			  0, 0);
-
-	
-	label = gtk_label_new_with_mnemonic (_("_Location (URL):"));
-	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-	gtk_widget_show (label);
-	gtk_table_attach (GTK_TABLE (table), label,
-			  0, 1,
-			  1, 2,
-			  GTK_FILL, GTK_FILL,
-			  0, 0);
-	
-	dialog->details->uri_entry = nautilus_location_entry_new ();
-	gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->uri_entry);
-	g_signal_connect (dialog->details->uri_entry,
-			  "activate", 
-			  G_CALLBACK (entry_activate_callback),
-			  dialog);
-	gtk_widget_show (dialog->details->uri_entry);
-	gtk_table_attach (GTK_TABLE (table), dialog->details->uri_entry,
-			  1, 2,
-			  1, 2,
-			  GTK_FILL | GTK_EXPAND, GTK_FILL,
-			  0, 0);
-	text = g_strdup_printf ("<small><i><b>%s </b>ftp://ftp.gnome.org</i></small>", _("Example:"));
-	label = gtk_label_new (text);
-	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
-	gtk_widget_show (label);
-	g_free (text);
-	gtk_table_attach (GTK_TABLE (table), label,
-			  1, 2,
-			  2, 3,
-			  GTK_FILL | GTK_EXPAND, GTK_FILL,
-			  0, 0);
-	/*	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
-		label, TRUE, TRUE, 0);*/
-
+	widget = glade_xml_get_widget (xml, "cts_link_url");
+	dialog->details->uri_entry = GTK_BIN (widget)->child;
+	g_signal_connect (GTK_EDITABLE (dialog->details->uri_entry), "changed",
+			G_CALLBACK (entry_changed_cb), dialog);
+	g_signal_connect (GTK_ENTRY (dialog->details->uri_entry), "activate", 
+			G_CALLBACK (url_entry_activate_callback), dialog);
+
+	dialog->details->remove_button = glade_xml_get_widget (xml, "cts_remove_button");
+	
+	dialog->details->favourite_servers_list = gtk_list_store_new (1, G_TYPE_STRING);
+	dialog->details->recent_servers_list = gtk_list_store_new (1, G_TYPE_STRING);
+	
+	/* FIXME: populate the lists with recent/favourite items */
+	GtkTreeIter iter;
+	gtk_list_store_append (dialog->details->recent_servers_list, &iter);
+	gtk_list_store_set (dialog->details->recent_servers_list, &iter, 0, "ftp://ftp.gnome.org/", -1);
+
+	gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (dialog->details->recent_servers_list));
+	gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (widget), 0);
+	
+	widget = glade_xml_get_widget (xml, "cts_favourites_treeview");
+	gtk_tree_view_set_model (GTK_TREE_VIEW (widget), GTK_TREE_MODEL (dialog->details->favourite_servers_list));
+	g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)), "changed",
+			G_CALLBACK (server_selected_callback), dialog);
+	g_signal_connect (GTK_TREE_VIEW (widget), "row-activated",
+			G_CALLBACK (server_activated_callback), dialog);
+	renderer = gtk_cell_renderer_text_new ();
+	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (widget), -1,
+			_("URL"), renderer,
+			"text", 0, NULL);
+	
+	g_signal_connect (GTK_BUTTON (dialog->details->remove_button), "clicked",
+			G_CALLBACK (remove_button_clicked_cb), gtk_tree_view_get_selection (GTK_TREE_VIEW (widget)));
+
+	dialog->details->add_favourite_button = glade_xml_get_widget (xml, "cts_addtofavourites_button");
+	g_signal_connect (GTK_BUTTON (dialog->details->add_favourite_button), "clicked",
+			G_CALLBACK (add_favourite_button_clicked_cb), dialog);
+	
 	gtk_dialog_add_button (GTK_DIALOG (dialog),
 			       GTK_STOCK_CANCEL,
 			       GTK_RESPONSE_CANCEL);
-	gtk_dialog_add_button (GTK_DIALOG (dialog),
+	dialog->details->connect_server_button = gtk_dialog_add_button (
+			       GTK_DIALOG (dialog),
 			       _("C_onnect"),
 			       RESPONSE_CONNECT);
+	gtk_widget_set_sensitive (dialog->details->connect_server_button, FALSE);
 	gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 					 RESPONSE_CONNECT);
 
 	g_signal_connect (dialog, "response",
 			  G_CALLBACK (response_callback),
 			  dialog);
+
+	g_object_unref (xml);
+	gtk_widget_show_all (GTK_WIDGET (dialog));
 }
 
 GtkWidget *
