1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
6 * Copyright (C) 2003 Red Hat, Inc.
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; see the file COPYING. If not,
20 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include "nautilus-connect-server-dialog.h"
28 #include <eel/eel-gtk-macros.h>
29 #include <eel/eel-stock-dialogs.h>
30 #include <eel/eel-vfs-extensions.h>
31 #include <libgnomeui/gnome-help.h>
32 #include <glib/gi18n.h>
34 #include <gtk/gtkcelllayout.h>
35 #include <gtk/gtkcellrenderertext.h>
36 #include <gtk/gtkcheckbutton.h>
37 #include <gtk/gtkhbox.h>
38 #include <gtk/gtkvbox.h>
39 #include <gtk/gtktable.h>
40 #include <gtk/gtktreemodel.h>
41 #include <gtk/gtklabel.h>
42 #include <gtk/gtkliststore.h>
43 #include <gtk/gtkstock.h>
44 #include <gtk/gtkcombobox.h>
45 #include "nautilus-location-entry.h"
46 #include <libnautilus-private/nautilus-global-preferences.h>
49 * - dns-sd fill out servers
51 * - name entry + pre-fill
52 * - folder browse function
57 * - see FIXME in nautilus-connect-server-dialog-main.c
60 struct _NautilusConnectServerDialogDetails
{
61 NautilusApplication
*application
;
65 GtkWidget
*type_combo
;
67 GtkWidget
*server_entry
;
68 GtkWidget
*share_entry
;
69 GtkWidget
*port_entry
;
70 GtkWidget
*folder_entry
;
71 GtkWidget
*domain_entry
;
72 GtkWidget
*user_entry
;
74 GtkWidget
*bookmark_check
;
75 GtkWidget
*name_entry
;
78 static void nautilus_connect_server_dialog_class_init (NautilusConnectServerDialogClass
*class);
79 static void nautilus_connect_server_dialog_init (NautilusConnectServerDialog
*dialog
);
81 EEL_CLASS_BOILERPLATE (NautilusConnectServerDialog
,
82 nautilus_connect_server_dialog
,
93 /* A collection of flags for MethodInfo.flags */
95 DEFAULT_METHOD
= 0x00000001,
97 /* Widgets to display in setup_for_type */
98 SHOW_SHARE
= 0x00000010,
99 SHOW_PORT
= 0x00000020,
100 SHOW_USER
= 0x00000040,
101 SHOW_DOMAIN
= 0x00000080,
103 IS_ANONYMOUS
= 0x00001000
106 /* Remember to fill in descriptions below */
107 static struct MethodInfo methods
[] = {
108 /* FIXME: we need to alias ssh to sftp */
109 { "sftp", SHOW_PORT
| SHOW_USER
},
110 { "ftp", SHOW_PORT
| SHOW_USER
},
111 { "ftp", DEFAULT_METHOD
| IS_ANONYMOUS
| SHOW_PORT
},
112 { "smb", SHOW_SHARE
| SHOW_USER
| SHOW_DOMAIN
},
113 { "dav", SHOW_PORT
| SHOW_USER
},
114 /* FIXME: hrm, shouldn't it work? */
115 { "davs", SHOW_PORT
| SHOW_USER
},
116 { NULL
, 0 }, /* Custom URI method */
119 /* To get around non constant gettext strings */
121 get_method_description (struct MethodInfo
*meth
)
124 return _("Custom Location");
125 } else if (strcmp (meth
->scheme
, "sftp") == 0) {
127 } else if (strcmp (meth
->scheme
, "ftp") == 0) {
128 if (meth
->flags
& IS_ANONYMOUS
) {
129 return _("Public FTP");
131 return _("FTP (with login)");
133 } else if (strcmp (meth
->scheme
, "smb") == 0) {
134 return _("Windows share");
135 } else if (strcmp (meth
->scheme
, "dav") == 0) {
136 return _("WebDAV (HTTP)");
137 } else if (strcmp (meth
->scheme
, "davs") == 0) {
138 return _("Secure WebDAV (HTTPS)");
140 /* No descriptive text */
147 nautilus_connect_server_dialog_finalize (GObject
*object
)
149 NautilusConnectServerDialog
*dialog
;
151 dialog
= NAUTILUS_CONNECT_SERVER_DIALOG (object
);
153 g_object_unref (dialog
->details
->uri_entry
);
154 g_object_unref (dialog
->details
->server_entry
);
155 g_object_unref (dialog
->details
->share_entry
);
156 g_object_unref (dialog
->details
->port_entry
);
157 g_object_unref (dialog
->details
->folder_entry
);
158 g_object_unref (dialog
->details
->domain_entry
);
159 g_object_unref (dialog
->details
->user_entry
);
160 g_object_unref (dialog
->details
->bookmark_check
);
161 g_object_unref (dialog
->details
->name_entry
);
163 g_free (dialog
->details
);
165 EEL_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (object
));
169 nautilus_connect_server_dialog_destroy (GtkObject
*object
)
171 NautilusConnectServerDialog
*dialog
;
173 dialog
= NAUTILUS_CONNECT_SERVER_DIALOG (object
);
175 EEL_CALL_PARENT (GTK_OBJECT_CLASS
, destroy
, (object
));
179 connect_to_server (NautilusConnectServerDialog
*dialog
)
181 struct MethodInfo
*meth
;
187 /* Get our method info */
188 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog
->details
->type_combo
), &iter
);
189 gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog
->details
->type_combo
)),
190 &iter
, 0, &index
, -1);
191 g_assert (index
< G_N_ELEMENTS (methods
) && index
>= 0);
192 meth
= &(methods
[index
]);
194 if (meth
->scheme
== NULL
) {
195 uri
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->uri_entry
), 0, -1);
196 /* FIXME: we should validate it in some way? */
198 char *user
, *port
, *initial_path
, *server
, *folder
,*domain
;
200 gboolean free_initial_path
, free_user
, free_domain
, free_port
;
202 server
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->server_entry
), 0, -1);
203 if (strlen (server
) == 0) {
204 eel_show_error_dialog (_("Cannot Connect to Server. You must enter a name for the server."),
205 _("Please enter a name and try again."),
206 GTK_WINDOW (dialog
));
215 free_initial_path
= FALSE
;
220 /* FTP special case */
221 if (meth
->flags
& IS_ANONYMOUS
) {
224 /* SMB special case */
225 } else if (strcmp (meth
->scheme
, "smb") == 0) {
226 t
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->share_entry
), 0, -1);
227 initial_path
= g_strconcat ("/", t
, NULL
);
228 free_initial_path
= TRUE
;
232 if (dialog
->details
->port_entry
->parent
!= NULL
) {
234 port
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->port_entry
), 0, -1);
236 folder
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->folder_entry
), 0, -1);
237 if (dialog
->details
->user_entry
->parent
!= NULL
) {
240 t
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->user_entry
), 0, -1);
242 user
= g_uri_escape_string (t
, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO
, FALSE
);
246 if (dialog
->details
->domain_entry
->parent
!= NULL
) {
249 domain
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->domain_entry
), 0, -1);
251 if (strlen (domain
) != 0) {
254 user
= g_strconcat (domain
, ";" , t
, NULL
);
264 if (folder
[0] != 0 &&
272 folder
= g_strconcat (initial_path
, join
, t
, NULL
);
276 folder
= g_uri_escape_string (t
, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH
, FALSE
);
279 uri
= g_strdup_printf ("%s://%s%s%s%s%s%s",
281 user
, (user
[0] != 0) ? "@" : "",
283 (port
[0] != 0) ? ":" : "", port
,
286 if (free_initial_path
) {
287 g_free (initial_path
);
302 gtk_widget_hide (GTK_WIDGET (dialog
));
304 location
= g_file_new_for_uri (uri
);
307 /* FIXME: sensitivity */
308 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog
->details
->bookmark_check
))) {
310 NautilusBookmark
*bookmark
;
311 NautilusBookmarkList
*list
;
313 name
= gtk_editable_get_chars (GTK_EDITABLE (dialog
->details
->name_entry
), 0, -1);
314 bookmark
= nautilus_bookmark_new (location
, strlen (name
) ? name
: NULL
);
315 list
= nautilus_bookmark_list_new ();
316 if (!nautilus_bookmark_list_contains (list
, bookmark
)) {
317 nautilus_bookmark_list_append (list
, bookmark
);
320 g_object_unref (bookmark
);
321 g_object_unref (list
);
325 nautilus_connect_server_dialog_present_uri (dialog
->details
->application
,
327 GTK_WIDGET (dialog
));
331 response_callback (NautilusConnectServerDialog
*dialog
,
337 switch (response_id
) {
338 case RESPONSE_CONNECT
:
339 connect_to_server (dialog
);
341 case GTK_RESPONSE_NONE
:
342 case GTK_RESPONSE_DELETE_EVENT
:
343 case GTK_RESPONSE_CANCEL
:
344 gtk_widget_destroy (GTK_WIDGET (dialog
));
346 case GTK_RESPONSE_HELP
:
348 gnome_help_display_desktop_on_screen (NULL
, "user-guide", "user-guide.xml",
349 "nautilus-server-connect",
350 gtk_window_get_screen (GTK_WINDOW (dialog
)),
353 eel_show_error_dialog (_("There was an error displaying help."), error
->message
,
354 GTK_WINDOW (dialog
));
355 g_error_free (error
);
359 g_assert_not_reached ();
364 nautilus_connect_server_dialog_class_init (NautilusConnectServerDialogClass
*class)
366 GObjectClass
*gobject_class
;
367 GtkObjectClass
*object_class
;
369 gobject_class
= G_OBJECT_CLASS (class);
370 gobject_class
->finalize
= nautilus_connect_server_dialog_finalize
;
372 object_class
= GTK_OBJECT_CLASS (class);
373 object_class
->destroy
= nautilus_connect_server_dialog_destroy
;
377 setup_for_type (NautilusConnectServerDialog
*dialog
)
379 struct MethodInfo
*meth
;
381 GtkWidget
*label
, *table
;
384 /* Get our method info */
385 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog
->details
->type_combo
), &iter
);
386 gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog
->details
->type_combo
)),
387 &iter
, 0, &index
, -1);
388 g_assert (index
< G_N_ELEMENTS (methods
) && index
>= 0);
389 meth
= &(methods
[index
]);
391 if (dialog
->details
->uri_entry
->parent
!= NULL
) {
392 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
393 dialog
->details
->uri_entry
);
395 if (dialog
->details
->server_entry
->parent
!= NULL
) {
396 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
397 dialog
->details
->server_entry
);
399 if (dialog
->details
->share_entry
->parent
!= NULL
) {
400 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
401 dialog
->details
->share_entry
);
403 if (dialog
->details
->port_entry
->parent
!= NULL
) {
404 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
405 dialog
->details
->port_entry
);
407 if (dialog
->details
->folder_entry
->parent
!= NULL
) {
408 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
409 dialog
->details
->folder_entry
);
411 if (dialog
->details
->user_entry
->parent
!= NULL
) {
412 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
413 dialog
->details
->user_entry
);
415 if (dialog
->details
->domain_entry
->parent
!= NULL
) {
416 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
417 dialog
->details
->domain_entry
);
419 if (dialog
->details
->bookmark_check
->parent
!= NULL
) {
420 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
421 dialog
->details
->bookmark_check
);
423 if (dialog
->details
->name_entry
->parent
!= NULL
) {
424 gtk_container_remove (GTK_CONTAINER (dialog
->details
->table
),
425 dialog
->details
->name_entry
);
427 /* Destroy all labels */
428 gtk_container_foreach (GTK_CONTAINER (dialog
->details
->table
),
429 (GtkCallback
) gtk_widget_destroy
, NULL
);
433 table
= dialog
->details
->table
;
435 if (meth
->scheme
== NULL
) {
436 label
= gtk_label_new_with_mnemonic (_("_Location (URI):"));
437 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
438 gtk_widget_show (label
);
439 gtk_table_attach (GTK_TABLE (table
), label
,
445 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->uri_entry
);
446 gtk_widget_show (dialog
->details
->uri_entry
);
447 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->uri_entry
,
450 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
455 goto connection_name
;
458 label
= gtk_label_new_with_mnemonic (_("_Server:"));
459 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
460 gtk_widget_show (label
);
461 gtk_table_attach (GTK_TABLE (table
), label
,
467 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->server_entry
);
468 gtk_widget_show (dialog
->details
->server_entry
);
469 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->server_entry
,
472 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
477 label
= gtk_label_new (_("Optional information:"));
478 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
479 gtk_widget_show (label
);
480 gtk_table_attach (GTK_TABLE (table
), label
,
488 if (meth
->flags
& SHOW_SHARE
) {
489 label
= gtk_label_new_with_mnemonic (_("_Share:"));
490 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
491 gtk_widget_show (label
);
492 gtk_table_attach (GTK_TABLE (table
), label
,
498 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->share_entry
);
499 gtk_widget_show (dialog
->details
->share_entry
);
500 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->share_entry
,
503 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
509 if (meth
->flags
& SHOW_PORT
) {
510 label
= gtk_label_new_with_mnemonic (_("_Port:"));
511 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
512 gtk_widget_show (label
);
513 gtk_table_attach (GTK_TABLE (table
), label
,
519 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->port_entry
);
520 gtk_widget_show (dialog
->details
->port_entry
);
521 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->port_entry
,
524 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
530 label
= gtk_label_new_with_mnemonic (_("_Folder:"));
531 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
532 gtk_widget_show (label
);
533 gtk_table_attach (GTK_TABLE (table
), label
,
539 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->folder_entry
);
540 gtk_widget_show (dialog
->details
->folder_entry
);
541 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->folder_entry
,
544 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
549 if (meth
->flags
& SHOW_USER
) {
550 label
= gtk_label_new_with_mnemonic (_("_User Name:"));
551 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
552 gtk_widget_show (label
);
553 gtk_table_attach (GTK_TABLE (table
), label
,
559 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->user_entry
);
560 gtk_widget_show (dialog
->details
->user_entry
);
561 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->user_entry
,
564 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
570 if (meth
->flags
& SHOW_DOMAIN
) {
571 label
= gtk_label_new_with_mnemonic (_("_Domain Name:"));
572 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
573 gtk_widget_show (label
);
574 gtk_table_attach (GTK_TABLE (table
), label
,
580 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->domain_entry
);
581 gtk_widget_show (dialog
->details
->domain_entry
);
582 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->domain_entry
,
585 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
595 gtk_widget_show (dialog
->details
->bookmark_check
);
596 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->bookmark_check
,
603 label
= gtk_label_new_with_mnemonic (_("Bookmark _name:"));
604 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
605 gtk_widget_show (label
);
606 gtk_table_attach (GTK_TABLE (table
), label
,
612 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), dialog
->details
->name_entry
);
613 gtk_widget_show (dialog
->details
->name_entry
);
614 gtk_table_attach (GTK_TABLE (table
), dialog
->details
->name_entry
,
617 GTK_FILL
| GTK_EXPAND
, GTK_FILL
,
625 display_server_location (NautilusConnectServerDialog
*dialog
, GFile
*location
)
628 struct MethodInfo
*meth
= NULL
;
634 /* Find an appropriate method */
635 scheme
= g_file_get_uri_scheme (location
);
636 g_return_if_fail (scheme
!= NULL
);
638 for (i
= 0; i
< G_N_ELEMENTS (methods
); i
++) {
640 /* The default is 'Custom URI' */
641 if (methods
[i
].scheme
== NULL
) {
642 meth
= &(methods
[i
]);
645 } else if (strcmp (methods
[i
].scheme
, scheme
) == 0) {
647 /* FTP Special case: If no user keep searching for public ftp */
648 if (strcmp (scheme
, "ftp") == 0) {
649 t
= gnome_vfs_uri_get_user_name (uri
);
650 if ((!t
|| !t
[0] || strcmp (t
, "anonymous") == 0) &&
651 (!(methods
[i
].flags
& IS_ANONYMOUS
))) {
656 meth
= &(methods
[i
]);
665 gtk_combo_box_set_active (GTK_COMBO_BOX (dialog
->details
->type_combo
), index
);
666 setup_for_type (dialog
);
669 if (meth
->scheme
== NULL
) {
672 /* FIXME: with gnome-vfs, we had GNOME_VFS_URI_HIDE_PASSWORD |
673 * GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER */
674 uri
= g_file_get_uri (location
)
675 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->uri_entry
), uri
);
680 folder
= g_file_get_path (location
);
683 } else if (folder
[0] == '/') {
688 t
= gnome_vfs_uri_get_host_name (uri
);
689 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->server_entry
),
693 if (meth
->flags
& SHOW_SHARE
) {
694 t
= strchr (folder
, '/');
696 char *share
= g_strndup (folder
, t
- folder
);
697 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->share_entry
), share
);
705 if (meth
->flags
& SHOW_PORT
) {
706 guint port
= gnome_vfs_uri_get_host_port (uri
);
709 g_snprintf (sport
, sizeof (sport
), "%d", port
);
710 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->port_entry
), sport
);
715 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->folder_entry
), folder
);
719 if (meth
->flags
& SHOW_USER
) {
720 const char *user
= gnome_vfs_uri_get_user_name (uri
);
722 t
= strchr (user
, ';');
726 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->user_entry
), user
);
731 if (meth
->flags
& SHOW_DOMAIN
) {
732 const char *user
= gnome_vfs_uri_get_user_name (uri
);
734 t
= strchr (user
, ';');
736 char *domain
= g_strndup (user
, t
- user
);
737 gtk_entry_set_text (GTK_ENTRY (dialog
->details
->domain_entry
), domain
);
747 combo_changed_callback (GtkComboBox
*combo_box
,
748 NautilusConnectServerDialog
*dialog
)
750 setup_for_type (dialog
);
754 port_insert_text (GtkEditable
*editable
,
755 const gchar
*new_text
,
756 gint new_text_length
,
761 if (new_text_length
< 0) {
762 new_text_length
= strlen (new_text
);
765 /* Only allow digits to be inserted as port number */
766 for (pos
= 0; pos
< new_text_length
; pos
++) {
767 if (!g_ascii_isdigit (new_text
[pos
])) {
768 GtkWidget
*toplevel
= gtk_widget_get_toplevel (GTK_WIDGET (editable
));
769 if (toplevel
!= NULL
) {
770 gdk_window_beep (toplevel
->window
);
772 g_signal_stop_emission_by_name (editable
, "insert_text");
779 bookmark_checkmark_toggled (GtkToggleButton
*toggle
, NautilusConnectServerDialog
*dialog
)
781 gtk_widget_set_sensitive (GTK_WIDGET(dialog
->details
->name_entry
),
782 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (toggle
)));
786 nautilus_connect_server_dialog_init (NautilusConnectServerDialog
*dialog
)
794 GtkCellRenderer
*renderer
;
797 dialog
->details
= g_new0 (NautilusConnectServerDialogDetails
, 1);
799 gtk_window_set_title (GTK_WINDOW (dialog
), _("Connect to Server"));
800 gtk_dialog_set_has_separator (GTK_DIALOG (dialog
), FALSE
);
801 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 5);
802 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog
)->vbox
), 2);
803 gtk_window_set_resizable (GTK_WINDOW (dialog
), FALSE
);
805 vbox
= gtk_vbox_new (FALSE
, 6);
806 gtk_container_set_border_width (GTK_CONTAINER (vbox
), 5);
807 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog
)->vbox
),
808 vbox
, FALSE
, TRUE
, 0);
809 gtk_widget_show (vbox
);
811 hbox
= gtk_hbox_new (FALSE
, 6);
812 gtk_box_pack_start (GTK_BOX (vbox
),
813 hbox
, FALSE
, TRUE
, 0);
814 gtk_widget_show (hbox
);
816 label
= gtk_label_new_with_mnemonic (_("Service _type:"));
817 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
818 gtk_widget_show (label
);
819 gtk_box_pack_start (GTK_BOX (hbox
),
820 label
, FALSE
, FALSE
, 0);
822 dialog
->details
->type_combo
= combo
= gtk_combo_box_new ();
824 /* each row contains: method index, textual description */
825 store
= gtk_list_store_new (2, G_TYPE_INT
, G_TYPE_STRING
);
826 gtk_combo_box_set_model (GTK_COMBO_BOX (combo
), GTK_TREE_MODEL (store
));
827 g_object_unref (G_OBJECT (store
));
829 renderer
= gtk_cell_renderer_text_new ();
830 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo
), renderer
, TRUE
);
831 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo
), renderer
, "text", 1);
833 for (i
= 0; i
< G_N_ELEMENTS (methods
); i
++) {
835 const gchar
* const *supported
;
838 /* skip methods that don't have corresponding GnomeVFSMethods */
839 supported
= g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
841 if (methods
[i
].scheme
!= NULL
) {
845 for (j
= 0; supported
[j
] != NULL
; j
++) {
846 if (strcmp (methods
[i
].scheme
, supported
[j
]) == 0) {
857 gtk_list_store_append (store
, &iter
);
858 gtk_list_store_set (store
, &iter
,
860 1, get_method_description (&(methods
[i
])),
864 if (methods
[i
].flags
& DEFAULT_METHOD
) {
865 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo
), &iter
);
869 if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo
)) < 0) {
870 /* default method not available, use any other */
871 gtk_combo_box_set_active (GTK_COMBO_BOX (combo
), 0);
874 gtk_widget_show (combo
);
875 gtk_label_set_mnemonic_widget (GTK_LABEL (label
), combo
);
876 gtk_box_pack_start (GTK_BOX (hbox
),
877 combo
, TRUE
, TRUE
, 0);
878 g_signal_connect (combo
, "changed",
879 G_CALLBACK (combo_changed_callback
),
883 hbox
= gtk_hbox_new (FALSE
, 6);
884 gtk_box_pack_start (GTK_BOX (vbox
),
885 hbox
, FALSE
, TRUE
, 0);
886 gtk_widget_show (hbox
);
888 label
= gtk_label_new_with_mnemonic (" ");
889 gtk_widget_show (label
);
890 gtk_box_pack_start (GTK_BOX (hbox
),
891 label
, FALSE
, FALSE
, 0);
894 dialog
->details
->table
= table
= gtk_table_new (5, 2, FALSE
);
895 gtk_table_set_row_spacings (GTK_TABLE (table
), 6);
896 gtk_table_set_col_spacings (GTK_TABLE (table
), 12);
897 gtk_widget_show (table
);
898 gtk_box_pack_start (GTK_BOX (hbox
),
899 table
, TRUE
, TRUE
, 0);
901 dialog
->details
->uri_entry
= nautilus_location_entry_new ();
902 dialog
->details
->server_entry
= gtk_entry_new ();
903 dialog
->details
->share_entry
= gtk_entry_new ();
904 dialog
->details
->port_entry
= gtk_entry_new ();
905 g_signal_connect (dialog
->details
->port_entry
, "insert_text", G_CALLBACK (port_insert_text
),
907 dialog
->details
->folder_entry
= gtk_entry_new ();
908 dialog
->details
->domain_entry
= gtk_entry_new ();
909 dialog
->details
->user_entry
= gtk_entry_new ();
910 dialog
->details
->bookmark_check
= gtk_check_button_new_with_mnemonic (_("Add _bookmark"));
911 dialog
->details
->name_entry
= gtk_entry_new ();
913 g_signal_connect (dialog
->details
->bookmark_check
, "toggled",
914 G_CALLBACK (bookmark_checkmark_toggled
), dialog
);
916 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog
->details
->bookmark_check
), FALSE
);
917 gtk_widget_set_sensitive (GTK_WIDGET(dialog
->details
->name_entry
), FALSE
);
919 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->uri_entry
), TRUE
);
920 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->server_entry
), TRUE
);
921 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->share_entry
), TRUE
);
922 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->port_entry
), TRUE
);
923 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->folder_entry
), TRUE
);
924 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->domain_entry
), TRUE
);
925 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->user_entry
), TRUE
);
926 gtk_entry_set_activates_default (GTK_ENTRY (dialog
->details
->name_entry
), TRUE
);
928 /* We need an extra ref so we can remove them from the table */
929 g_object_ref (dialog
->details
->uri_entry
);
930 g_object_ref (dialog
->details
->server_entry
);
931 g_object_ref (dialog
->details
->share_entry
);
932 g_object_ref (dialog
->details
->port_entry
);
933 g_object_ref (dialog
->details
->folder_entry
);
934 g_object_ref (dialog
->details
->domain_entry
);
935 g_object_ref (dialog
->details
->user_entry
);
936 g_object_ref (dialog
->details
->bookmark_check
);
937 g_object_ref (dialog
->details
->name_entry
);
939 setup_for_type (dialog
);
941 gtk_dialog_add_button (GTK_DIALOG (dialog
),
944 gtk_dialog_add_button (GTK_DIALOG (dialog
),
946 GTK_RESPONSE_CANCEL
);
947 gtk_dialog_add_button (GTK_DIALOG (dialog
),
950 gtk_dialog_set_default_response (GTK_DIALOG (dialog
),
953 g_signal_connect (dialog
, "response",
954 G_CALLBACK (response_callback
),
961 nautilus_connect_server_dialog_new (NautilusWindow
*window
, GFile
*location
)
963 NautilusConnectServerDialog
*conndlg
;
966 dialog
= gtk_widget_new (NAUTILUS_TYPE_CONNECT_SERVER_DIALOG
, NULL
);
967 conndlg
= NAUTILUS_CONNECT_SERVER_DIALOG (dialog
);
970 gtk_window_set_screen (GTK_WINDOW (dialog
),
971 gtk_window_get_screen (GTK_WINDOW (window
)));
972 conndlg
->details
->application
= window
->application
;
976 /* If it's a remote URI, then load as the default */
977 if (!g_file_is_native (location
)) {
978 display_server_location (conndlg
, location
);