Re: Fixing SMB browsing
- From: Nate Nielsen <nielsen-list memberwebs com>
- To: nielsen memberwebs com
- Cc: Federico Mena Quintero <federico ximian com>, Nautilus List <nautilus-list gnome org>, Alexander Larsson <alexl redhat com>, "gnome-vfs-list gnome org" <gnome-vfs-list gnome org>
- Subject: Re: Fixing SMB browsing
- Date: Thu, 23 Feb 2006 23:02:29 +0000 (GMT)
Nate Nielsen wrote:
> You're right. I thought I had commit this code, but it looks like I
> forgot. The idea was that when you browsed to a share, and then chose
> 'Connect to Server' from there it would show you the 'Connect to Server'
> dialog with 'Windows Share' all nicely selected and ready for you to
> customize, by changing the user name for example. But currently it just
> displays an arcane (to the user) URI.
>
> I'll remedy this as soon as I can, after which we'll have a decent UI
> for using alternate credentials on SMB shares.
Here's the patch I mentioned, cleaned up a bit. It also allows
nautilus-connect-server to accept a uri on the command line, which gets
parsed and displayed.
Cheers,
Nate
Index: src/nautilus-connect-server-dialog-main.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-connect-server-dialog-main.c,v
retrieving revision 1.5
diff -U3 -r1.5 nautilus-connect-server-dialog-main.c
--- src/nautilus-connect-server-dialog-main.c 9 Dec 2005 14:35:32 -0000 1.5
+++ src/nautilus-connect-server-dialog-main.c 23 Feb 2006 22:17:30 -0000
@@ -42,6 +42,11 @@
#include "nautilus-window.h"
#include "nautilus-connect-server-dialog.h"
+static const struct poptOption options[] = {
+ POPT_AUTOHELP
+ POPT_TABLEEND
+};
+
static int open_dialogs;
static void
@@ -94,15 +99,20 @@
int
main (int argc, char *argv[])
{
+ GnomeProgram *program;
GtkWidget *dialog;
+ poptContext ctx;
+ GValue value = { 0, };
+ const char **args;
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- gnome_program_init ("nautilus-connect-server", VERSION,
- LIBGNOMEUI_MODULE, argc, argv,
- NULL);
+ program = gnome_program_init ("nautilus-connect-server", VERSION,
+ LIBGNOMEUI_MODULE, argc, argv,
+ GNOME_PARAM_POPT_TABLE, options,
+ NULL);
gnome_authentication_manager_init ();
@@ -110,7 +120,16 @@
gtk_window_set_default_icon_name ("gnome-fs-directory");
- dialog = nautilus_connect_server_dialog_new (NULL, NULL);
+ /* Get the POPT context */
+ g_value_init (&value, G_TYPE_POINTER);
+ g_object_get_property (G_OBJECT (program), GNOME_PARAM_POPT_CONTEXT, &value);
+ ctx = g_value_get_pointer (&value);
+ g_value_unset (&value);
+
+ /* command line arguments, null terminated array */
+ args = poptGetArgs(ctx);
+
+ dialog = nautilus_connect_server_dialog_new (NULL, args ? *args : NULL);
open_dialogs = 1;
g_signal_connect (dialog, "destroy",
Index: src/nautilus-connect-server-dialog.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-connect-server-dialog.c,v
retrieving revision 1.17
diff -U3 -r1.17 nautilus-connect-server-dialog.c
--- src/nautilus-connect-server-dialog.c 9 Dec 2005 14:35:32 -0000 1.17
+++ src/nautilus-connect-server-dialog.c 23 Feb 2006 22:17:31 -0000
@@ -75,17 +75,61 @@
RESPONSE_CONNECT
};
-/* Keep this order in sync with strings below */
+struct MethodInfo {
+ const char *method;
+ guint flags;
+};
+
+/* A collection of flags for MethodInfo.flags */
enum {
- TYPE_SSH,
- TYPE_ANON_FTP,
- TYPE_FTP,
- TYPE_SMB,
- TYPE_DAV,
- TYPE_DAVS,
- TYPE_URI
+ DEFAULT_METHOD = 0x00000001,
+
+ /* Widgets to display in setup_for_type */
+ SHOW_SHARE = 0x00000010,
+ SHOW_PORT = 0x00000020,
+ SHOW_USER = 0x00000040,
+ SHOW_DOMAIN = 0x00000080,
+
+ IS_ANONYMOUS = 0x00001000
};
+/* Remember to fill in descriptions below */
+static struct MethodInfo methods[] = {
+ { "ssh", SHOW_PORT | SHOW_USER },
+ { "ftp", SHOW_PORT | SHOW_USER },
+ { "ftp", DEFAULT_METHOD | IS_ANONYMOUS | SHOW_PORT},
+ { "smb", SHOW_SHARE | SHOW_USER | SHOW_DOMAIN },
+ { "dav", SHOW_PORT | SHOW_USER },
+ { "davs", SHOW_PORT | SHOW_USER },
+ { NULL, 0 }, /* Custom URI method */
+};
+
+/* To get around non constant gettext strings */
+static const char*
+get_method_description (struct MethodInfo *meth)
+{
+ if (!meth->method)
+ return _("Custom Location");
+ else if (strcmp (meth->method, "ssh") == 0)
+ return _("SSH");
+ else if (strcmp (meth->method, "ftp") == 0) {
+ if (meth->flags & IS_ANONYMOUS)
+ return _("Public FTP");
+ else
+ return _("FTP (with login)");
+ }
+ else if (strcmp (meth->method, "smb") == 0)
+ return _("Windows share");
+ else if (strcmp (meth->method, "dav") == 0)
+ return _("WebDAV (HTTP)");
+ else if (strcmp (meth->method, "davs") == 0)
+ return _("Secure WebDAV (HTTPS)");
+
+ /* No descriptive text */
+ else
+ return meth->method;
+}
+
static void
nautilus_connect_server_dialog_finalize (GObject *object)
{
@@ -120,17 +164,21 @@
static void
connect_to_server (NautilusConnectServerDialog *dialog)
{
+ struct MethodInfo *meth;
char *uri;
char *user_uri;
GnomeVFSURI *vfs_uri;
char *error_message;
char *name;
char *icon;
- int type;
+ int index;
- type = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
+ /* Get our method info */
+ index = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
+ g_assert (index < G_N_ELEMENTS (methods) && index >= 0);
+ meth = &(methods[index]);
- if (type == TYPE_URI) {
+ if (meth->method == NULL) {
user_uri = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->uri_entry), 0, -1);
uri = gnome_vfs_make_uri_from_input (user_uri);
g_free (user_uri);
@@ -149,7 +197,7 @@
gnome_vfs_uri_unref (vfs_uri);
}
} else {
- char *method, *user, *port, *initial_path, *server, *folder ,*domain ;
+ char *user, *port, *initial_path, *server, *folder ,*domain ;
char *t, *join;
gboolean free_initial_path, free_user, free_domain, free_port;
@@ -162,7 +210,6 @@
return;
}
- method = "";
user = "";
port = "";
initial_path = "";
@@ -171,30 +218,15 @@
free_user = FALSE;
free_domain = FALSE;
free_port = FALSE;
- switch (type) {
- case TYPE_SSH:
- method = "sftp";
- break;
- case TYPE_ANON_FTP:
- method = "ftp";
+
+ /* Some special cases */
+ if (meth->flags & IS_ANONYMOUS)
user = "anonymous";
- break;
- case TYPE_FTP:
- method = "ftp";
- break;
- case TYPE_SMB:
- method = "smb";
+ else if (strcmp(meth->method, "smb") == 0) {
t = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->share_entry), 0, -1);
initial_path = g_strconcat ("/", t, NULL);
free_initial_path = TRUE;
g_free (t);
- break;
- case TYPE_DAV:
- method = "dav";
- break;
- case TYPE_DAVS:
- method = "davs";
- break;
}
if (dialog->details->port_entry->parent != NULL) {
@@ -245,7 +277,7 @@
g_free (t);
uri = g_strdup_printf ("%s://%s%s%s%s%s%s",
- method,
+ meth->method,
user, (user[0] != 0) ? "@" : "",
server,
(port[0] != 0) ? ":" : "", port,
@@ -366,11 +398,14 @@
static void
setup_for_type (NautilusConnectServerDialog *dialog)
{
- int type, i;
- gboolean show_share, show_port, show_user, show_domain;
+ struct MethodInfo *meth;
+ int index, i;
GtkWidget *label, *table;
- type = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
+ /* Get our method info */
+ index = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
+ g_assert (index < G_N_ELEMENTS (methods) && index >= 0);
+ meth = &(methods[index]);
if (dialog->details->uri_entry->parent != NULL) {
gtk_container_remove (GTK_CONTAINER (dialog->details->table),
@@ -412,7 +447,7 @@
i = 1;
table = dialog->details->table;
- if (type == TYPE_URI) {
+ if (meth->method == NULL) {
label = gtk_label_new_with_mnemonic (_("_Location (URI):"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -435,31 +470,6 @@
goto connection_name;
}
- switch (type) {
- default:
- case TYPE_SSH:
- case TYPE_FTP:
- case TYPE_DAV:
- case TYPE_DAVS:
- show_share = FALSE;
- show_port = TRUE;
- show_user = TRUE;
- show_domain = FALSE;
- break;
- case TYPE_ANON_FTP:
- show_share = FALSE;
- show_port = TRUE;
- show_user = FALSE;
- show_domain = FALSE;
- break;
- case TYPE_SMB:
- show_share = TRUE;
- show_port = FALSE;
- show_user = TRUE;
- show_domain =TRUE;
- break;
- }
-
label = gtk_label_new_with_mnemonic (_("_Server:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -490,7 +500,7 @@
i++;
- if (show_share) {
+ if (meth->flags & SHOW_SHARE) {
label = gtk_label_new_with_mnemonic (_("_Share:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -511,7 +521,7 @@
i++;
}
- if (show_port) {
+ if (meth->flags & SHOW_PORT) {
label = gtk_label_new_with_mnemonic (_("_Port:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -551,7 +561,7 @@
i++;
- if (show_user) {
+ if (meth->flags & SHOW_USER) {
label = gtk_label_new_with_mnemonic (_("_User Name:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -572,7 +582,7 @@
i++;
}
- if (show_domain) {
+ if (meth->flags & SHOW_DOMAIN) {
label = gtk_label_new_with_mnemonic (_("_Domain Name:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -619,6 +629,107 @@
}
static void
+display_server_uri (NautilusConnectServerDialog *dialog, GnomeVFSURI *uri)
+{
+ struct MethodInfo *meth = NULL;
+ const char *method;
+ int i, index = 0;
+ const char *folder;
+ const char *t;
+
+ /* Find an appropriate method */
+ method = gnome_vfs_uri_get_scheme (uri);
+ g_return_if_fail (method != NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (methods); i++) {
+ /* The default is 'Custom URI' */
+ if (methods[i].method == NULL) {
+ meth = &(methods[i]);
+ index = i;
+ } else if (strcmp (methods[i].method, method) == 0) {
+ meth = &(methods[i]);
+ index = i;
+ break;
+ }
+ }
+
+ g_assert (meth);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (dialog->details->type_combo), index);
+ setup_for_type (dialog);
+
+ /* Custom URI */
+ if (meth->method == NULL) {
+ gchar *suri = gnome_vfs_uri_to_string (uri,
+ GNOME_VFS_URI_HIDE_PASSWORD | GNOME_VFS_URI_HIDE_FRAGMENT_IDENTIFIER);
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->uri_entry), suri);
+ g_free (suri);
+
+ } else {
+
+ folder = gnome_vfs_uri_get_path (uri);
+ if (!folder)
+ folder = "";
+ else if (folder[0] == '/')
+ folder++;
+
+ /* Server */
+ t = gnome_vfs_uri_get_host_name (uri);
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->server_entry),
+ t ? t : "");
+
+ /* Share */
+ if (meth->flags & SHOW_SHARE) {
+ t = strchr (folder, '/');
+ if (t) {
+ char *share = g_strndup (folder, t - folder);
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->share_entry), share);
+ g_free (share);
+ folder = t + 1;
+ }
+
+ }
+
+ /* Port */
+ if (meth->flags & SHOW_PORT) {
+ guint port = gnome_vfs_uri_get_host_port (uri);
+ if (port != 0) {
+ char *sport = g_strdup_printf ("%d", port);
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->port_entry), sport);
+ g_free (sport);
+ }
+ }
+
+ /* Folder */
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->folder_entry), folder);
+
+ /* User */
+ if (meth->flags & SHOW_USER) {
+ const char *user = gnome_vfs_uri_get_user_name (uri);
+ if (user) {
+ t = strchr (user, ';');
+ if (t)
+ user = t + 1;
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->user_entry), user);
+ }
+ }
+
+ /* Domain */
+ if (meth->flags & SHOW_DOMAIN) {
+ const char *user = gnome_vfs_uri_get_user_name (uri);
+ if (user) {
+ t = strchr (user, ';');
+ if (t) {
+ char *domain = g_strndup (user, t - user);
+ gtk_entry_set_text (GTK_ENTRY (dialog->details->domain_entry), domain);
+ g_free (domain);
+ }
+ }
+ }
+ }
+}
+
+static void
combo_changed_callback (GtkComboBox *combo_box,
NautilusConnectServerDialog *dialog)
{
@@ -652,6 +763,7 @@
GtkWidget *combo;
GtkWidget *hbox;
GtkWidget *vbox;
+ int i;
dialog->details = g_new0 (NautilusConnectServerDialogDetails, 1);
@@ -679,22 +791,13 @@
label, FALSE, FALSE, 0);
dialog->details->type_combo = combo = gtk_combo_box_new_text ();
- /* Keep this in sync with enum */
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("SSH"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("Public FTP"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("FTP (with login)"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("Windows share"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("WebDAV (HTTP)"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("Secure WebDAV (HTTPS)"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo),
- _("Custom Location"));
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo), TYPE_ANON_FTP);
+
+ for (i = 0; i < G_N_ELEMENTS (methods); i++) {
+ gtk_combo_box_append_text (GTK_COMBO_BOX (combo), get_method_description (&(methods[i])));
+ if (methods[i].flags & DEFAULT_METHOD)
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), i);
+ }
+
gtk_widget_show (combo);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
gtk_box_pack_start (GTK_BOX (hbox),
@@ -771,28 +874,24 @@
GnomeVFSURI *uri;
dialog = gtk_widget_new (NAUTILUS_TYPE_CONNECT_SERVER_DIALOG, NULL);
+ conndlg = NAUTILUS_CONNECT_SERVER_DIALOG (dialog);
if (window) {
- conndlg = NAUTILUS_CONNECT_SERVER_DIALOG (dialog);
-
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_window_get_screen (GTK_WINDOW (window)));
conndlg->details->application = window->application;
+ }
- if (location) {
- uri = gnome_vfs_uri_new (location);
- g_return_val_if_fail (uri != NULL, dialog);
-
- /* ... and if it's a remote URI, then load as the default */
- if (!g_str_equal (gnome_vfs_uri_get_scheme (uri), "file") &&
- !gnome_vfs_uri_is_local (uri)) {
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (conndlg->details->type_combo), TYPE_URI);
- gtk_entry_set_text (GTK_ENTRY (conndlg->details->uri_entry), location);
- }
+ if (location) {
+ uri = gnome_vfs_uri_new (location);
+ g_return_val_if_fail (uri != NULL, dialog);
+
+ /* If it's a remote URI, then load as the default */
+ if (!g_str_equal (gnome_vfs_uri_get_scheme (uri), "file") &&
+ !gnome_vfs_uri_is_local (uri))
+ display_server_uri (conndlg, uri);
- gnome_vfs_uri_unref (uri);
- }
+ gnome_vfs_uri_unref (uri);
}
return dialog;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]