gnome-utils r7913 - in trunk/baobab: . src
- From: pborelli svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-utils r7913 - in trunk/baobab: . src
- Date: Sun, 4 May 2008 18:16:37 +0100 (BST)
Author: pborelli
Date: Sun May 4 17:16:37 2008
New Revision: 7913
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=7913&view=rev
Log:
2008-05-04 Paolo Borelli <pborelli katamail com>
* src/baobab-remote-connect-dialog.c:
* src/baobab-remote-connect-dialog.h:
* src/callbacks.c:
First cut at gio port of the remote connect dialog (mostly borrowing
code from nautilus).
Modified:
trunk/baobab/ChangeLog
trunk/baobab/src/baobab-remote-connect-dialog.c
trunk/baobab/src/baobab-remote-connect-dialog.h
trunk/baobab/src/callbacks.c
Modified: trunk/baobab/src/baobab-remote-connect-dialog.c
==============================================================================
--- trunk/baobab/src/baobab-remote-connect-dialog.c (original)
+++ trunk/baobab/src/baobab-remote-connect-dialog.c Sun May 4 17:16:37 2008
@@ -30,20 +30,15 @@
#include "baobab-remote-connect-dialog.h"
#include <string.h>
-
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-volume.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include "baobab.h"
struct _BaobabRemoteConnectDialogDetails {
-
- char *uri;
- GtkWidget *required_table;
- GtkWidget *optional_table;
+ GtkWidget *table;
GtkWidget *type_combo;
GtkWidget *uri_entry;
@@ -53,33 +48,137 @@
GtkWidget *folder_entry;
GtkWidget *domain_entry;
GtkWidget *user_entry;
-
- GtkWidget *name_entry;
};
static void baobab_remote_connect_dialog_class_init (BaobabRemoteConnectDialogClass *class);
static void baobab_remote_connect_dialog_init (BaobabRemoteConnectDialog *dialog);
+G_DEFINE_TYPE(BaobabRemoteConnectDialog, baobab_remote_connect_dialog, GTK_TYPE_DIALOG)
+
#define RESPONSE_CONNECT GTK_RESPONSE_OK
-/*
-enum {
+
+
+static void
+display_error_dialog (GError *error,
+ GFile *location,
+ GtkWidget *parent)
+{
+ GtkWidget *dlg;
+ char *parse_name;
+ char *error_message;
+
+ parse_name = g_file_get_parse_name (location);
+ error_message = g_strdup_printf (_("Cannot scan location \"%s\""),
+ parse_name);
+ g_free (parse_name);
+
+ dlg = gtk_message_dialog_new (GTK_WINDOW (parent),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ error_message);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+ error->message);
+
+ g_free (error_message);
+
+ gtk_dialog_run (GTK_DIALOG (dlg));
+ gtk_widget_destroy (dlg);
+}
+
+static void
+mount_enclosing_ready_cb (GFile *location,
+ GAsyncResult *res,
+ GtkWidget *widget)
+{
+ GError *error = NULL;
- RESPONSE_CONNECT
-};
-*/
+ g_file_mount_enclosing_volume_finish (location,
+ res, &error);
+ if (error) {
+ display_error_dialog (error, location, widget);
+ } else {
+ /* volume is mounted, show it */
+ baobab_scan_location (location);
+ }
+
+ if (location)
+ g_object_unref (location);
+}
+
+static void
+connect_server_dialog_present_uri (GFile *location,
+ GtkWidget *widget)
+{
+ GMountOperation *op;
-/* Keep this order in sync with strings below */
+/* op = eel_mount_operation_new (GTK_WINDOW (widget));*/
+ op = g_mount_operation_new ();
+ g_file_mount_enclosing_volume (location,
+ 0, op,
+ NULL,
+ (GAsyncReadyCallback) mount_enclosing_ready_cb,
+ widget);
+}
+
+struct MethodInfo {
+ const char *scheme;
+ 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
};
-G_DEFINE_TYPE(BaobabRemoteConnectDialog, baobab_remote_connect_dialog, GTK_TYPE_DIALOG)
+/* Remember to fill in descriptions below */
+static struct MethodInfo methods[] = {
+ /* FIXME: we need to alias ssh to sftp */
+ { "sftp", 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 },
+ /* FIXME: hrm, shouldn't it work? */
+ { "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->scheme) {
+ return _("Custom Location");
+ } else if (strcmp (meth->scheme, "sftp") == 0) {
+ return _("SSH");
+ } else if (strcmp (meth->scheme, "ftp") == 0) {
+ if (meth->flags & IS_ANONYMOUS) {
+ return _("Public FTP");
+ } else {
+ return _("FTP (with login)");
+ }
+ } else if (strcmp (meth->scheme, "smb") == 0) {
+ return _("Windows share");
+ } else if (strcmp (meth->scheme, "dav") == 0) {
+ return _("WebDAV (HTTP)");
+ } else if (strcmp (meth->scheme, "davs") == 0) {
+ return _("Secure WebDAV (HTTPS)");
+
+ /* No descriptive text */
+ } else {
+ return meth->scheme;
+ }
+}
static void
baobab_remote_connect_dialog_finalize (GObject *object)
@@ -88,8 +187,6 @@
dialog = BAOBAB_REMOTE_CONNECT_DIALOG(object);
- g_free (dialog->details->uri);
-
g_object_unref (dialog->details->uri_entry);
g_object_unref (dialog->details->server_entry);
g_object_unref (dialog->details->share_entry);
@@ -97,62 +194,33 @@
g_object_unref (dialog->details->folder_entry);
g_object_unref (dialog->details->domain_entry);
g_object_unref (dialog->details->user_entry);
- g_object_unref (dialog->details->name_entry);
g_free (dialog->details);
G_OBJECT_CLASS (baobab_remote_connect_dialog_parent_class)->finalize (object);
}
-static gboolean
-remote_connect (BaobabRemoteConnectDialog *dialog)
+static void
+connect_to_server (BaobabRemoteConnectDialog *dialog)
{
+ struct MethodInfo *meth;
char *uri;
- char *user_uri;
- GnomeVFSURI *vfs_uri;
- char *error_message;
- char *name;
- int type;
-
- g_free (dialog->details->uri);
- dialog->details->uri = NULL;
-
- type = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
-
- if (type == TYPE_URI) {
- 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);
-
- vfs_uri = gnome_vfs_uri_new (uri);
-
- if (vfs_uri == NULL) {
- GtkWidget *dlg;
-
- error_message = g_strdup_printf (_("\"%s\" is not a valid location"), uri);
-
- dlg = gtk_message_dialog_new (GTK_WINDOW (dialog),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- error_message);
-
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
- _("Please check the spelling and try again."));
-
- g_free(error_message);
-
- gtk_dialog_run (GTK_DIALOG (dlg));
- gtk_widget_destroy (dlg);
-
- return FALSE;
- }
- else {
- gnome_vfs_uri_unref (vfs_uri);
- }
- }
- else {
- char *method, *user, *port, *initial_path, *server, *folder, *domain;
+ GFile *location;
+ int index;
+ GtkTreeIter iter;
+
+ /* Get our method info */
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->details->type_combo), &iter);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->details->type_combo)),
+ &iter, 0, &index, -1);
+ g_assert (index < G_N_ELEMENTS (methods) && index >= 0);
+ meth = &(methods[index]);
+
+ if (meth->scheme == NULL) {
+ uri = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->uri_entry), 0, -1);
+ /* FIXME: we should validate it in some way? */
+ } else {
+ char *user, *port, *initial_path, *server, *folder ,*domain ;
char *t, *join;
gboolean free_initial_path, free_user, free_domain, free_port;
@@ -164,20 +232,18 @@
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
- _("You must enter a name for the server"));
+ _("Cannot Connect to Server. You must enter a name for the server."));
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
_("Please enter a name and try again."));
- g_free(server);
-
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
- return FALSE;
+ g_free (server);
+ return;
}
- method = "";
user = "";
port = "";
initial_path = "";
@@ -186,30 +252,17 @@
free_user = FALSE;
free_domain = FALSE;
free_port = FALSE;
- switch (type) {
- case TYPE_SSH:
- method = "sftp";
- break;
- case TYPE_ANON_FTP:
- method = "ftp";
+
+ /* FTP special case */
+ if (meth->flags & IS_ANONYMOUS) {
user = "anonymous";
- break;
- case TYPE_FTP:
- method = "ftp";
- break;
- case TYPE_SMB:
- method = "smb";
+
+ /* SMB special case */
+ } else if (strcmp (meth->scheme, "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) {
@@ -222,7 +275,7 @@
t = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->user_entry), 0, -1);
- user = gnome_vfs_escape_string (t);
+ user = g_uri_escape_string (t, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, FALSE);
g_free (t);
}
@@ -256,11 +309,11 @@
g_free (t);
t = folder;
- folder = gnome_vfs_escape_path_string (t);
+ folder = g_uri_escape_string (t, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
g_free (t);
uri = g_strdup_printf ("%s://%s%s%s%s%s%s",
- method,
+ meth->scheme,
user, (user[0] != 0) ? "@" : "",
server,
(port[0] != 0) ? ":" : "", port,
@@ -281,44 +334,14 @@
g_free (domain);
}
}
-
- name = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->name_entry), 0, -1);
- if (strlen (name) == 0) {
- const char *host, *path;
- char *path_utf8, *basename;
-
- g_free (name);
-
- vfs_uri = gnome_vfs_uri_new (uri);
-
- if (vfs_uri == NULL) {
- g_warning ("Illegal uri in connect to server!\n");
- g_free (uri);
- g_free (name);
- return FALSE;
- }
-
- host = gnome_vfs_uri_get_host_name (vfs_uri);
- path = gnome_vfs_uri_get_path (vfs_uri);
- if (path != NULL &&
- strlen (path) > 0 &&
- strcmp (path, "/") != 0) {
- path_utf8 = gnome_vfs_format_uri_for_display (uri);
- basename = g_path_get_basename (path_utf8);
- name = g_strdup_printf (_("%s on %s"), basename, host);
- g_free (path_utf8);
- g_free (basename);
- } else {
- name = g_strdup (host);
- }
- gnome_vfs_uri_unref (vfs_uri);
- }
- dialog->details->uri = uri;
+ gtk_widget_hide (GTK_WIDGET (dialog));
- g_free (name);
+ location = g_file_new_for_uri (uri);
+ g_free (uri);
- return TRUE;
+ connect_server_dialog_present_uri (location,
+ GTK_WIDGET (dialog));
}
static void
@@ -326,15 +349,16 @@
int response_id,
gpointer data)
{
+ GError *error;
+
switch (response_id) {
case RESPONSE_CONNECT:
- if (!remote_connect (dialog))
- g_signal_stop_emission_by_name (dialog, "response");
+ connect_to_server (dialog);
break;
case GTK_RESPONSE_NONE:
case GTK_RESPONSE_DELETE_EVENT:
case GTK_RESPONSE_CANCEL:
-
+ gtk_widget_destroy (GTK_WIDGET (dialog));
break;
default :
g_assert_not_reached ();
@@ -353,54 +377,55 @@
static void
setup_for_type (BaobabRemoteConnectDialog *dialog)
{
- int type, i;
- gboolean show_share, show_port, show_user, show_domain;
- GtkWidget *align, *label, *table;
- gchar *str;
-
- type = gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->details->type_combo));
+ struct MethodInfo *meth;
+ int index, i;
+ GtkWidget *label, *table;
+ GtkTreeIter iter;
+
+ /* Get our method info */
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->details->type_combo), &iter);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->details->type_combo)),
+ &iter, 0, &index, -1);
+ 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->required_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->uri_entry);
}
if (dialog->details->server_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->required_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->server_entry);
}
if (dialog->details->share_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->share_entry);
}
if (dialog->details->port_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->port_entry);
}
if (dialog->details->folder_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->folder_entry);
}
if (dialog->details->user_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->user_entry);
}
if (dialog->details->domain_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
+ gtk_container_remove (GTK_CONTAINER (dialog->details->table),
dialog->details->domain_entry);
}
- if (dialog->details->name_entry->parent != NULL) {
- gtk_container_remove (GTK_CONTAINER (dialog->details->optional_table),
- dialog->details->name_entry);
- }
/* Destroy all labels */
- gtk_container_foreach (GTK_CONTAINER (dialog->details->required_table),
+ gtk_container_foreach (GTK_CONTAINER (dialog->details->table),
(GtkCallback) gtk_widget_destroy, NULL);
i = 1;
- table = dialog->details->required_table;
+ table = dialog->details->table;
- if (type == TYPE_URI) {
+ if (meth->scheme == NULL) {
label = gtk_label_new_with_mnemonic (_("_Location (URI):"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
@@ -419,36 +444,9 @@
0, 0);
i++;
-
- return;
}
- 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 (_("S_erver:"));
+ label = gtk_label_new_with_mnemonic (_("_Server:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
gtk_table_attach (GTK_TABLE (table), label,
@@ -467,46 +465,19 @@
i++;
- align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding (GTK_ALIGNMENT (align), 12, 0, 0, 0);
- gtk_table_attach (GTK_TABLE (table), align,
- 0, 2,
- i, i+1,
- GTK_FILL, GTK_FILL,
- 0, 0);
- gtk_widget_show (align);
-
- i++;
-
- str = g_strdup_printf ("<b>%s</b>", _("Optional Information"));
- label = gtk_label_new (str);
- g_free (str);
-
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ label = gtk_label_new (_("Optional information:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
- gtk_container_add (GTK_CONTAINER (align), label);
-
- align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
- gtk_table_attach (GTK_TABLE (table), align,
+ gtk_table_attach (GTK_TABLE (table), label,
0, 2,
i, i+1,
GTK_FILL, GTK_FILL,
0, 0);
- gtk_widget_show (align);
-
+
+ i++;
- dialog->details->optional_table = table = gtk_table_new (1, 2, FALSE);
- gtk_table_set_row_spacings (GTK_TABLE (table), 6);
- gtk_table_set_col_spacings (GTK_TABLE (table), 12);
- gtk_widget_show (table);
- gtk_container_add (GTK_CONTAINER (align), table);
-
- i = 0;
-
- if (show_share) {
- label = gtk_label_new_with_mnemonic (_("Sh_are:"));
+ 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);
gtk_table_attach (GTK_TABLE (table), label,
@@ -526,7 +497,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);
@@ -566,8 +537,8 @@
i++;
- if (show_user) {
- label = gtk_label_new_with_mnemonic (_("_User name:"));
+ 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);
gtk_table_attach (GTK_TABLE (table), label,
@@ -587,8 +558,8 @@
i++;
}
- if (show_domain) {
- label = gtk_label_new_with_mnemonic (_("_Domain name:"));
+ 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);
gtk_table_attach (GTK_TABLE (table), label,
@@ -607,8 +578,6 @@
i++;
}
-
-
}
static void
@@ -618,38 +587,46 @@
setup_for_type (dialog);
}
-
static void
port_insert_text (GtkEditable *editable,
const gchar *new_text,
gint new_text_length,
gint *position)
{
+ int pos;
+
if (new_text_length < 0) {
new_text_length = strlen (new_text);
}
- if (new_text_length != 1 ||
- !g_ascii_isdigit (new_text[0])) {
- gdk_display_beep (gtk_widget_get_display (GTK_WIDGET (editable)));
- g_signal_stop_emission_by_name (editable, "insert_text");
+ /* Only allow digits to be inserted as port number */
+ for (pos = 0; pos < new_text_length; pos++) {
+ if (!g_ascii_isdigit (new_text[pos])) {
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (editable));
+ if (toplevel != NULL) {
+ gdk_window_beep (toplevel->window);
+ }
+ g_signal_stop_emission_by_name (editable, "insert_text");
+ return;
+ }
}
}
static void
baobab_remote_connect_dialog_init (BaobabRemoteConnectDialog *dialog)
{
- GtkWidget *align;
GtkWidget *label;
GtkWidget *table;
GtkWidget *combo;
GtkWidget *hbox;
GtkWidget *vbox;
- gchar *str;
+ GtkListStore *store;
+ GtkCellRenderer *renderer;
+ int i;
dialog->details = g_new0 (BaobabRemoteConnectDialogDetails, 1);
- gtk_window_set_title (GTK_WINDOW (dialog), _("Scan Remote Folder"));
+ gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Server"));
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);
@@ -666,33 +643,64 @@
hbox, FALSE, TRUE, 0);
gtk_widget_show (hbox);
- str = g_strdup_printf ("<b>%s</b>", _("Service _type:"));
- label = gtk_label_new_with_mnemonic (str);
- g_free (str);
-
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ label = gtk_label_new_with_mnemonic (_("Service _type:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (hbox),
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);
+ dialog->details->type_combo = combo = gtk_combo_box_new ();
+
+ /* each row contains: method index, textual description */
+ store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
+ g_object_unref (G_OBJECT (store));
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 1);
+
+ for (i = 0; i < G_N_ELEMENTS (methods); i++) {
+ GtkTreeIter iter;
+ const gchar * const *supported;
+ int j;
+
+ /* skip methods that don't have corresponding GnomeVFSMethods */
+ supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+
+ if (methods[i].scheme != NULL) {
+ gboolean found;
+
+ found = FALSE;
+ for (j = 0; supported[j] != NULL; j++) {
+ if (strcmp (methods[i].scheme, supported[j]) == 0) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found) {
+ continue;
+ }
+ }
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, i,
+ 1, get_method_description (&(methods[i])),
+ -1);
+
+
+ if (methods[i].flags & DEFAULT_METHOD) {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
+ }
+ }
+
+ if (gtk_combo_box_get_active (GTK_COMBO_BOX (combo)) < 0) {
+ /* default method not available, use any other */
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
+ }
+
gtk_widget_show (combo);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
gtk_box_pack_start (GTK_BOX (hbox),
@@ -701,23 +709,24 @@
G_CALLBACK (combo_changed_callback),
dialog);
+
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (vbox),
hbox, FALSE, TRUE, 0);
gtk_widget_show (hbox);
- align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
- gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, 12, 0);
+ label = gtk_label_new_with_mnemonic (" ");
+ gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (hbox),
- align, TRUE, TRUE, 0);
- gtk_widget_show (align);
+ label, FALSE, FALSE, 0);
- dialog->details->required_table = table = gtk_table_new (1, 2, FALSE);
+ dialog->details->table = table = gtk_table_new (5, 2, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_table_set_col_spacings (GTK_TABLE (table), 12);
gtk_widget_show (table);
- gtk_container_add (GTK_CONTAINER (align), table);
+ gtk_box_pack_start (GTK_BOX (hbox),
+ table, TRUE, TRUE, 0);
//dialog->details->uri_entry = nautilus_location_entry_new ();
dialog->details->uri_entry = gtk_entry_new();
@@ -729,7 +738,15 @@
dialog->details->folder_entry = gtk_entry_new ();
dialog->details->domain_entry = gtk_entry_new ();
dialog->details->user_entry = gtk_entry_new ();
- dialog->details->name_entry = gtk_entry_new ();
+
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->uri_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->server_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->share_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->port_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->folder_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->domain_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->user_entry), TRUE);
+
/* We need an extra ref so we can remove them from the table */
g_object_ref (dialog->details->uri_entry);
g_object_ref (dialog->details->server_entry);
@@ -738,15 +755,17 @@
g_object_ref (dialog->details->folder_entry);
g_object_ref (dialog->details->domain_entry);
g_object_ref (dialog->details->user_entry);
- g_object_ref (dialog->details->name_entry);
setup_for_type (dialog);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ GTK_STOCK_HELP,
+ GTK_RESPONSE_HELP);
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gtk_dialog_add_button (GTK_DIALOG (dialog),
- _("_Scan"),
+ _("C_onnect"),
RESPONSE_CONNECT);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
RESPONSE_CONNECT);
@@ -757,11 +776,10 @@
}
GtkWidget *
-baobab_remote_connect_dialog_new (GtkWindow *window, const gchar *location)
+baobab_remote_connect_dialog_new (GtkWindow *window, GFile *location)
{
BaobabRemoteConnectDialog *conndlg;
GtkWidget *dialog;
- GnomeVFSURI *uri;
dialog = gtk_widget_new (BAOBAB_TYPE_REMOTE_CONNECT_DIALOG, NULL);
@@ -770,29 +788,8 @@
gtk_window_set_screen (GTK_WINDOW (dialog),
gtk_window_get_screen (GTK_WINDOW (window)));
-
- 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);
- }
-;
- gnome_vfs_uri_unref (uri);
- }
}
return dialog;
}
-char *
-baobab_remote_connect_dialog_get_uri (BaobabRemoteConnectDialog *dlg)
-{
- return g_strdup (dlg->details->uri);
-}
-
Modified: trunk/baobab/src/baobab-remote-connect-dialog.h
==============================================================================
--- trunk/baobab/src/baobab-remote-connect-dialog.h (original)
+++ trunk/baobab/src/baobab-remote-connect-dialog.h Sun May 4 17:16:37 2008
@@ -53,12 +53,6 @@
GType baobab_remote_connect_dialog_get_type (void);
GtkWidget* baobab_remote_connect_dialog_new (GtkWindow *window,
- const gchar *uri);
+ GFile *location);
-char *baobab_remote_connect_dialog_get_uri (BaobabRemoteConnectDialog *dlg);
-
-/* Private internal calls */
-
-
-
#endif /* BAOBAB_REMOTE_CONNECT_DIALOG_H */
Modified: trunk/baobab/src/callbacks.c
==============================================================================
--- trunk/baobab/src/callbacks.c (original)
+++ trunk/baobab/src/callbacks.c Sun May 4 17:16:37 2008
@@ -153,27 +153,13 @@
void
on_tb_scan_remote_clicked (GtkToolButton *toolbutton, gpointer user_data)
{
- gint response;
GtkWidget *dlg;
- char *uri = NULL;
-
+
dlg = baobab_remote_connect_dialog_new (GTK_WINDOW (baobab.window),
NULL);
- response = gtk_dialog_run (GTK_DIALOG (dlg));
-
- if (response == GTK_RESPONSE_OK) {
- uri = baobab_remote_connect_dialog_get_uri (BAOBAB_REMOTE_CONNECT_DIALOG (dlg));
- }
+ gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
-
- if (uri) {
- GFile *file;
- file = g_file_new_for_uri (uri);
- baobab_scan_location (file);
- g_object_unref (file);
- g_free (uri);
- }
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]