diff options
author | William Jon McCann <jmccann@redhat.com> | 2012-09-02 19:23:29 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2012-09-02 19:24:10 -0400 |
commit | 95d42ea01f7f9c60210b415554e7bbf6f4e1b334 (patch) | |
tree | f30bba6e0a2a45a70525ef8bbe0c18ee37cd6270 | |
parent | 2562f8a800165c55dd30298282602f9feeb96a61 (diff) | |
download | nautilus-95d42ea01f7f9c60210b415554e7bbf6f4e1b334.tar.gz |
New design for the connect to server dialog
https://bugzilla.gnome.org/show_bug.cgi?id=682637
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rw-r--r-- | src/nautilus-application.c | 107 | ||||
-rw-r--r-- | src/nautilus-connect-server-dialog-main.c | 159 | ||||
-rw-r--r-- | src/nautilus-connect-server-dialog-nonmain.c | 86 | ||||
-rw-r--r-- | src/nautilus-connect-server-dialog.c | 1476 | ||||
-rw-r--r-- | src/nautilus-connect-server-dialog.h | 21 | ||||
-rw-r--r-- | src/nautilus-connect-server-operation.c | 151 | ||||
-rw-r--r-- | src/nautilus-connect-server-operation.h | 63 |
8 files changed, 587 insertions, 1490 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 336c06ffb..0fc13ce20 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,6 @@ include $(top_srcdir)/Makefile.shared bin_PROGRAMS= \ nautilus \ nautilus-autorun-software \ - nautilus-connect-server \ $(NULL) libexec_PROGRAMS= \ @@ -135,9 +134,6 @@ nautilus_SOURCES = \ nautilus-canvas-view-container.h \ nautilus-connect-server-dialog.c \ nautilus-connect-server-dialog.h \ - nautilus-connect-server-dialog-nonmain.c \ - nautilus-connect-server-operation.c \ - nautilus-connect-server-operation.h \ nautilus-desktop-canvas-view.c \ nautilus-desktop-canvas-view.h \ nautilus-desktop-item-properties.c \ @@ -227,16 +223,6 @@ nautilus_autorun_software_SOURCES= \ nautilus-autorun-software.c \ $(NULL) -nautilus_connect_server_SOURCES= \ - nautilus-bookmark-list.c \ - nautilus-bookmark-list.h \ - nautilus-connect-server-dialog.c \ - nautilus-connect-server-dialog.h \ - nautilus-connect-server-dialog-main.c \ - nautilus-connect-server-operation.c \ - nautilus-connect-server-operation.h \ - $(NULL) - nautilus_convert_metadata_SOURCES= \ nautilus-convert-metadata.c \ $(NULL) diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 5bab06884..272246492 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -110,6 +110,8 @@ struct _NautilusApplicationPriv { NotifyNotification *unmount_notify; NautilusBookmarkList *bookmark_list; + + GtkWidget *connect_server_window; }; NautilusBookmarkList * @@ -702,16 +704,115 @@ action_new_window (GSimpleAction *action, nautilus_window_slot_go_home (nautilus_window_get_active_slot (window), 0); } +static gboolean +go_to_server_cb (NautilusWindow *window, + GError *error, + gpointer user_data) +{ + GFile *location = user_data; + + if (error == NULL) { + GBookmarkFile *bookmarks; + GError *error = NULL; + char *datadir; + char *filename; + char *uri; + char *title; + NautilusFile *file; + gboolean safe_to_save = TRUE; + + file = nautilus_file_get_existing (location); + + bookmarks = g_bookmark_file_new (); + datadir = g_build_filename (g_get_user_config_dir (), "nautilus", NULL); + filename = g_build_filename (datadir, "servers", NULL); + g_mkdir_with_parents (datadir, 0700); + g_free (datadir); + g_bookmark_file_load_from_file (bookmarks, + filename, + &error); + if (error != NULL) { + if (! g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + /* only warn if the file exists */ + g_warning ("Unable to open server bookmarks: %s", error->message); + safe_to_save = FALSE; + } + g_error_free (error); + } + + if (safe_to_save) { + uri = nautilus_file_get_uri (file); + title = nautilus_file_get_display_name (file); + g_bookmark_file_set_title (bookmarks, uri, title); + g_bookmark_file_set_visited (bookmarks, uri, -1); + g_bookmark_file_add_application (bookmarks, uri, NULL, NULL); + g_free (uri); + g_free (title); + + g_bookmark_file_to_file (bookmarks, filename, NULL); + } + + g_free (filename); + g_bookmark_file_free (bookmarks); + } else { + g_warning ("Unable to connect to server: %s\n", error->message); + } + + g_object_unref (location); + + return TRUE; +} + +static void +on_connect_server_response (GtkDialog *dialog, + int response, + GtkApplication *application) +{ + if (response == GTK_RESPONSE_OK) { + GFile *location; + + location = nautilus_connect_server_dialog_get_location (NAUTILUS_CONNECT_SERVER_DIALOG (dialog)); + if (location != NULL) { + nautilus_window_go_to_full (NAUTILUS_WINDOW (get_focus_window (application)), + location, + go_to_server_cb, + location); + } + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); +} + +static void +nautilus_application_connect_server (NautilusApplication *application, + NautilusWindow *window) +{ + GtkWidget *dialog; + + dialog = application->priv->connect_server_window; + + if (dialog == NULL) { + dialog = nautilus_connect_server_dialog_new (window); + g_signal_connect (dialog, "response", G_CALLBACK (on_connect_server_response), application); + application->priv->connect_server_window = GTK_WIDGET (dialog); + + g_object_add_weak_pointer (G_OBJECT (dialog), + (gpointer *) &application->priv->connect_server_window); + } + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); + gtk_window_set_screen (GTK_WINDOW (dialog), gtk_window_get_screen (GTK_WINDOW (window))); + gtk_window_present (GTK_WINDOW (dialog)); +} + static void action_connect_to_server (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GtkApplication *application = user_data; - GtkWidget *dialog; - dialog = nautilus_connect_server_dialog_new (NAUTILUS_WINDOW (get_focus_window (application))); - gtk_widget_show (dialog); + nautilus_application_connect_server (NAUTILUS_APPLICATION (application), NAUTILUS_WINDOW (get_focus_window (application))); } static void diff --git a/src/nautilus-connect-server-dialog-main.c b/src/nautilus-connect-server-dialog-main.c deleted file mode 100644 index 49646f4f1..000000000 --- a/src/nautilus-connect-server-dialog-main.c +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* nautilus-connect-server-main.c - Start the "Connect to Server" dialog. - * Nautilus - * - * Copyright (C) 2005 Vincent Untz - * - * Nautilus is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * Nautilus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; see the file COPYING. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: - * Vincent Untz <vincent@vuntz.net> - * Cosimo Cecchi <cosimoc@gnome.org> - */ - -#include <config.h> - -#include <glib/gi18n.h> - -#include <gtk/gtk.h> -#include <gdk/gdk.h> - -#include <stdlib.h> - -#include <eel/eel-stock-dialogs.h> - -#include <libnautilus-private/nautilus-icon-names.h> -#include <libnautilus-private/nautilus-global-preferences.h> - -#include "nautilus-connect-server-dialog.h" - -static GSimpleAsyncResult *display_location_res = NULL; -static gboolean just_print_uri = FALSE; - -static void -main_dialog_destroyed (GtkWidget *widget, - gpointer user_data) -{ - /* this only happens when user clicks "cancel" - * on the main dialog or when we are all done. - */ - gtk_main_quit (); -} - -gboolean -nautilus_connect_server_dialog_display_location_finish (NautilusConnectServerDialog *self, - GAsyncResult *res, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) { - return FALSE; - } - - return TRUE; -} - -void -nautilus_connect_server_dialog_display_location_async (NautilusConnectServerDialog *self, - GFile *location, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GError *error; - GdkAppLaunchContext *launch_context; - gchar *uri; - - display_location_res = g_simple_async_result_new (G_OBJECT (self), - callback, user_data, - nautilus_connect_server_dialog_display_location_async); - - error = NULL; - uri = g_file_get_uri (location); - - if (just_print_uri) { - g_print ("%s\n", uri); - } - else { - launch_context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (self))); - gdk_app_launch_context_set_screen (launch_context, - gtk_widget_get_screen (GTK_WIDGET (self))); - - g_app_info_launch_default_for_uri (uri, - G_APP_LAUNCH_CONTEXT (launch_context), - &error); - - g_object_unref (launch_context); - } - - if (error != NULL) { - g_simple_async_result_set_from_error (display_location_res, error); - g_error_free (error); - } - - g_simple_async_result_complete_in_idle (display_location_res); - - g_free (uri); - g_object_unref (display_location_res); - display_location_res = NULL; -} - -int -main (int argc, char *argv[]) -{ - GtkWidget *dialog; - GOptionContext *context; - GError *error; - const GOptionEntry options[] = { - { "print-uri", 0, 0, G_OPTION_ARG_NONE, &just_print_uri, N_("Print but do not open the URI"), NULL }, - { NULL } - }; - - bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - /* Translators: This is the --help description for the connect to server app, - the initial newlines are between the command line arg and the description */ - context = g_option_context_new (N_("\n\nAdd connect to server mount")); - g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); - g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); - g_option_context_add_group (context, gtk_get_option_group (TRUE)); - - if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_critical ("Failed to parse arguments: %s", error->message); - g_error_free (error); - g_option_context_free (context); - exit (1); - } - - g_option_context_free (context); - - nautilus_global_preferences_init (); - - gtk_window_set_default_icon_name (NAUTILUS_ICON_FOLDER); - - dialog = nautilus_connect_server_dialog_new (NULL); - - g_signal_connect (dialog, "destroy", - G_CALLBACK (main_dialog_destroyed), NULL); - - gtk_widget_show (dialog); - - gtk_main (); - - return 0; -} diff --git a/src/nautilus-connect-server-dialog-nonmain.c b/src/nautilus-connect-server-dialog-nonmain.c deleted file mode 100644 index 74430b36c..000000000 --- a/src/nautilus-connect-server-dialog-nonmain.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ - -/* - * Nautilus - * - * Copyright (C) 2005 Red Hat, Inc. - * - * Nautilus is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * Nautilus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; see the file COPYING. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gio/gio.h> -#include "nautilus-connect-server-dialog.h" -#include <libnautilus-private/nautilus-global-preferences.h> - -/* This file contains the glue for the calls from the connect to server dialog - * to the main nautilus binary. A different version of this glue is in - * nautilus-connect-server-dialog-main.c for the standalone version. - */ - -static GSimpleAsyncResult *display_location_res = NULL; - -static gboolean -window_go_to_cb (NautilusWindow *window, - GError *error, - gpointer user_data) -{ - if (error != NULL) { - g_simple_async_result_set_from_error (display_location_res, error); - } - - g_simple_async_result_complete (display_location_res); - - g_object_unref (display_location_res); - display_location_res = NULL; - - return TRUE; -} - -gboolean -nautilus_connect_server_dialog_display_location_finish (NautilusConnectServerDialog *self, - GAsyncResult *res, - GError **error) -{ - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) { - return FALSE; - } - - return TRUE; -} - -void -nautilus_connect_server_dialog_display_location_async (NautilusConnectServerDialog *self, - GFile *location, - GAsyncReadyCallback callback, - gpointer user_data) -{ - NautilusWindow *window; - GtkWidget *widget; - - widget = GTK_WIDGET (self); - - display_location_res = - g_simple_async_result_new (G_OBJECT (self), - callback, user_data, - nautilus_connect_server_dialog_display_location_async); - - window = nautilus_application_create_window (NAUTILUS_APPLICATION (g_application_get_default ()), - gtk_widget_get_screen (widget)); - - nautilus_window_go_to_full (window, location, - window_go_to_cb, self); -} diff --git a/src/nautilus-connect-server-dialog.c b/src/nautilus-connect-server-dialog.c index dcbc55315..b5c7b4a71 100644 --- a/src/nautilus-connect-server-dialog.c +++ b/src/nautilus-connect-server-dialog.c @@ -27,1104 +27,689 @@ #include <string.h> #include <eel/eel-stock-dialogs.h> +#include <eel/eel-gtk-extensions.h> #include <glib/gi18n.h> #include <gio/gio.h> #include <gtk/gtk.h> -#include "nautilus-bookmark-list.h" -#include "nautilus-connect-server-operation.h" #include "nautilus-window.h" -#include <libnautilus-private/nautilus-global-preferences.h> -#include <libnautilus-private/nautilus-icon-names.h> - -/* TODO: - * - name entry + pre-fill - * - NetworkManager integration - */ - struct _NautilusConnectServerDialogDetails { + GtkTreeView *view; + GtkListStore *store; GtkWidget *primary_grid; - GtkWidget *user_details; - GtkWidget *port_spinbutton; - - GtkWidget *info_bar; - GtkWidget *info_bar_content; - - GtkWidget *type_combo; - GtkWidget *server_entry; - GtkWidget *share_entry; - GtkWidget *folder_entry; - GtkWidget *domain_entry; - GtkWidget *user_entry; - GtkWidget *password_entry; - GtkWidget *remember_checkbox; - GtkWidget *connect_button; - - GtkSizeGroup *labels_size_group; - GtkSizeGroup *contents_size_group; - - GList *iconized_entries; - - GSimpleAsyncResult *fill_details_res; - GAskPasswordFlags fill_details_flags; - GMountOperation *fill_operation; - - gboolean last_password_set; - gulong password_sensitive_id; - gboolean should_destroy; - - GCancellable *mount_cancellable; -}; -G_DEFINE_TYPE (NautilusConnectServerDialog, nautilus_connect_server_dialog, - GTK_TYPE_DIALOG) + GtkWidget *uri_entry; + GtkWidget *error_label; -static void sensitive_entry_changed_callback (GtkEditable *editable, - GtkWidget *widget); -static void iconized_entry_changed_cb (GtkEditable *entry, - NautilusConnectServerDialog *dialog); + GtkWidget *menu; + GtkWidget *remove_menu_item; + GtkWidget *clear_menu_item; -enum { - RESPONSE_CONNECT -}; - -struct MethodInfo { - const char *scheme; - guint flags; - guint default_port; + char **supported; }; -/* A collection of flags for MethodInfo.flags */ enum { - DEFAULT_METHOD = (1 << 0), - - /* Widgets to display in connect_dialog_setup_for_type */ - SHOW_SHARE = (1 << 1), - SHOW_PORT = (1 << 2), - SHOW_USER = (1 << 3), - SHOW_DOMAIN = (1 << 4), - - IS_ANONYMOUS = (1 << 5) + COLUMN_NAME, + COLUMN_URI, + NUM_COLUMNS }; -/* Remember to fill in descriptions below */ -static struct MethodInfo methods[] = { - { "afp", SHOW_SHARE | SHOW_USER, 548 }, - /* FIXME: we need to alias ssh to sftp */ - { "sftp", SHOW_PORT | SHOW_USER, 22 }, - { "ftp", SHOW_PORT | SHOW_USER, 21 }, - { "ftp", DEFAULT_METHOD | IS_ANONYMOUS | SHOW_PORT, 21 }, - { "smb", SHOW_SHARE | SHOW_USER | SHOW_DOMAIN, 0 }, - { "dav", SHOW_PORT | SHOW_USER, 80 }, - /* FIXME: hrm, shouldn't it work? */ - { "davs", SHOW_PORT | SHOW_USER, 443 }, -}; -/* To get around non constant gettext strings */ -static const char* -get_method_description (struct MethodInfo *meth) -{ - 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)"); - } else if (strcmp (meth->scheme, "afp") == 0) { - return _("Apple Filing Protocol (AFP)"); - } else { - /* No descriptive text */ - return meth->scheme; - } -} +G_DEFINE_TYPE (NautilusConnectServerDialog, nautilus_connect_server_dialog, + GTK_TYPE_DIALOG) -static void -connect_dialog_restore_info_bar (NautilusConnectServerDialog *dialog, - GtkMessageType message_type) +GFile * +nautilus_connect_server_dialog_get_location (NautilusConnectServerDialog *dialog) { - if (dialog->details->info_bar_content != NULL) { - gtk_widget_destroy (dialog->details->info_bar_content); - dialog->details->info_bar_content = NULL; + const char *uri; + GFile *file = NULL; + + uri = gtk_entry_get_text (GTK_ENTRY (dialog->details->uri_entry)); + if (uri != NULL && uri[0] != '\0') { + file = g_file_new_for_commandline_arg (uri); } - gtk_info_bar_set_message_type (GTK_INFO_BAR (dialog->details->info_bar), - message_type); + return file; } static void -connect_dialog_set_connecting (NautilusConnectServerDialog *dialog) +nautilus_connect_server_dialog_response (GtkDialog *dialog, + int response_id, + gpointer data) { - GtkWidget *hbox; - GtkWidget *widget; - GtkWidget *content_area; - gint width, height; - - connect_dialog_restore_info_bar (dialog, GTK_MESSAGE_INFO); - gtk_widget_show (dialog->details->info_bar); - - content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (dialog->details->info_bar)); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_container_add (GTK_CONTAINER (content_area), hbox); - gtk_widget_show (hbox); - - dialog->details->info_bar_content = hbox; - - widget = gtk_spinner_new (); - gtk_icon_size_lookup (GTK_ICON_SIZE_SMALL_TOOLBAR, &width, &height); - gtk_widget_set_size_request (widget, width, height); - gtk_spinner_start (GTK_SPINNER (widget)); - gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6); - gtk_widget_show (widget); - - widget = gtk_label_new (_("Connecting...")); - gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6); - gtk_widget_show (widget); + GError *error; + NautilusConnectServerDialog *cs_dialog = NAUTILUS_CONNECT_SERVER_DIALOG (dialog); - gtk_widget_set_sensitive (dialog->details->connect_button, FALSE); + switch (response_id) { + case GTK_RESPONSE_ACCEPT: + g_signal_stop_emission_by_name (dialog, "response"); + gtk_entry_set_text (GTK_ENTRY (cs_dialog->details->uri_entry), "network:///"); + gtk_dialog_response (dialog, GTK_RESPONSE_OK); + break; + case GTK_RESPONSE_HELP: + error = NULL; + gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)), + "help:gnome-help/nautilus-connect", + gtk_get_current_event_time (), &error); + if (error) { + eel_show_error_dialog (_("There was an error displaying help."), error->message, + GTK_WINDOW (dialog)); + g_error_free (error); + } + g_signal_stop_emission_by_name (dialog, "response"); + break; + default : + break; + } } -static void -connect_dialog_gvfs_error (NautilusConnectServerDialog *dialog) +static gboolean +is_scheme_supported (NautilusConnectServerDialog *dialog, + const char *scheme) { - GtkWidget *hbox, *image, *content_area, *label; + int i; - connect_dialog_restore_info_bar (dialog, GTK_MESSAGE_ERROR); + if (dialog->details->supported == NULL) { + return FALSE; + } - content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (dialog->details->info_bar)); + for (i = 0; dialog->details->supported[i] != NULL; i++) { + if (strcmp (scheme, dialog->details->supported[i]) == 0) { + return TRUE; + } + } - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_container_add (GTK_CONTAINER (content_area), hbox); - gtk_widget_show (hbox); + return FALSE; +} - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 6); - gtk_widget_show (image); - - label = gtk_label_new (_("Can't load the supported server method list.\n" - "Please check your gvfs installation.")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - gtk_widget_show (label); +static gboolean +validate_uri (NautilusConnectServerDialog *dialog, + const char *uri, + GError **error) +{ + gboolean valid = FALSE; + char *scheme; + + scheme = g_uri_parse_scheme (uri); + if (scheme != NULL) { + valid = is_scheme_supported (dialog, scheme); + if (! valid) { + g_set_error_literal (error, + G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + _("Don't recognize this file server type.")); + } + g_free (scheme); + } else { + g_set_error_literal (error, + G_IO_ERROR, + G_IO_ERROR_INVALID_ARGUMENT, + _("This doesn't look like an address.")); - gtk_widget_set_sensitive (dialog->details->connect_button, FALSE); - gtk_widget_set_sensitive (dialog->details->primary_grid, FALSE); + } - gtk_widget_show (dialog->details->info_bar); + return valid; } static void -iconized_entry_restore (gpointer data, - gpointer user_data) +on_uri_entry_clear (GtkEntry *entry, + NautilusConnectServerDialog *dialog) { - GtkEntry *entry; - NautilusConnectServerDialog *dialog; - - entry = data; - dialog = user_data; - - gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), - GTK_ENTRY_ICON_SECONDARY, - NULL); - - g_signal_handlers_disconnect_by_func (entry, - iconized_entry_changed_cb, - dialog); + gtk_entry_set_text (entry, ""); } -static void -iconized_entry_changed_cb (GtkEditable *entry, - NautilusConnectServerDialog *dialog) +static const char * +get_default_scheme (NautilusConnectServerDialog *dialog) { - dialog->details->iconized_entries = - g_list_remove (dialog->details->iconized_entries, entry); + if (dialog->details->supported == NULL) { + return NULL; + } - iconized_entry_restore (entry, dialog); + return dialog->details->supported[0]; } -static void -iconize_entry (NautilusConnectServerDialog *dialog, - GtkWidget *entry) +static int +get_index (const char **names, + const char *needle) { - if (!g_list_find (dialog->details->iconized_entries, entry)) { - dialog->details->iconized_entries = - g_list_prepend (dialog->details->iconized_entries, entry); - - gtk_entry_set_icon_from_stock (GTK_ENTRY (entry), - GTK_ENTRY_ICON_SECONDARY, - GTK_STOCK_DIALOG_WARNING); + int i; + int index = G_MAXINT; + for (i = 0; names[i] != NULL; i++) { + if (strcmp (needle, names[i]) == 0) { + index = i; + break; + } + } - gtk_widget_grab_focus (entry); + return index; +} - g_signal_connect (entry, "changed", - G_CALLBACK (iconized_entry_changed_cb), dialog); +static int +sort_supported (gconstpointer a, + gconstpointer b, + gpointer user_data) +{ + const char **preferred = user_data; + const char *s_a = *((char **)a); + const char *s_b = *((char **)b); + int i_a; + int i_b; + + i_a = get_index (preferred, s_a); + i_b = get_index (preferred, s_b); + + if (i_b == i_a) { + return 0; + } else if (i_a > i_b) { + return 1; + } else { + return -1; } } static void -connect_dialog_set_info_bar_error (NautilusConnectServerDialog *dialog, - GError *error) +populate_supported_list (NautilusConnectServerDialog *dialog) { - GtkWidget *content_area, *label, *entry, *hbox, *icon; - gchar *str; - const gchar *folder, *server; - - connect_dialog_restore_info_bar (dialog, GTK_MESSAGE_WARNING); - - content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (dialog->details->info_bar)); - entry = NULL; + const char * const *supported; + GPtrArray *good; + int i; + int j; + const char * unsupported[] = { "file", "afc", "obex", "http", "trash", "burn", "computer", "archive", "recent", "localtest", NULL }; + const char * preferred[] = { "smb", "afp", "sftp", "ssh", "davs", "dav", "ftp", NULL }; - switch (error->code) { - case G_IO_ERROR_FAILED_HANDLED: + supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ()); + if (supported == NULL) { return; - case G_IO_ERROR_NOT_FOUND: - folder = gtk_entry_get_text (GTK_ENTRY (dialog->details->folder_entry)); - server = gtk_entry_get_text (GTK_ENTRY (dialog->details->server_entry)); - str = g_strdup_printf (_("The folder “%s” cannot be opened on “%s”."), - folder, server); - label = gtk_label_new (str); - entry = dialog->details->folder_entry; - - g_free (str); - - break; - case G_IO_ERROR_HOST_NOT_FOUND: - server = gtk_entry_get_text (GTK_ENTRY (dialog->details->server_entry)); - str = g_strdup_printf (_("The server at “%s” cannot be found."), server); - label = gtk_label_new (str); - entry = dialog->details->server_entry; - - g_free (str); - - break; - case G_IO_ERROR_FAILED: - default: - label = gtk_label_new (error->message); - break; } - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_widget_show (dialog->details->info_bar); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 6); - gtk_widget_show (hbox); - - icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, - GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 6); - gtk_widget_show (icon); - - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - gtk_widget_show (label); - - if (entry != NULL) { - iconize_entry (dialog, entry); + good = g_ptr_array_new (); + for (i = 0; supported[i] != NULL; i++) { + gboolean support = TRUE; + for (j = 0; unsupported[j] != NULL; j++) { + if (strcmp (supported[i], unsupported[j]) == 0) { + support = FALSE; + break; + } + } + if (support) { + g_ptr_array_add (good, g_strdup (supported[i])); + } } + g_ptr_array_sort_with_data (good, sort_supported, preferred); - dialog->details->info_bar_content = hbox; + g_ptr_array_add (good, NULL); - gtk_button_set_label (GTK_BUTTON (dialog->details->connect_button), - _("Try Again")); - gtk_widget_set_sensitive (dialog->details->connect_button, TRUE); + dialog->details->supported = (char **)g_ptr_array_free (good, FALSE); } static void -connect_dialog_finish_fill (NautilusConnectServerDialog *dialog) +reset_example_label (NautilusConnectServerDialog *dialog) { - GAskPasswordFlags flags; - GMountOperation *op; - - flags = dialog->details->fill_details_flags; - op = G_MOUNT_OPERATION (dialog->details->fill_operation); + char *text; + char *uri; - if (flags & G_ASK_PASSWORD_NEED_PASSWORD) { - g_mount_operation_set_password (op, gtk_entry_get_text (GTK_ENTRY (dialog->details->password_entry))); - } + uri = g_strdup_printf ("%s://foo.example.com", get_default_scheme (dialog)); + /* Translators: %s is a URI of the form "smb://foo.example.com" */ + text = g_strdup_printf (_("For example, %s"), uri); + g_free (uri); + gtk_label_set_text (GTK_LABEL (dialog->details->error_label), text); + g_free (text); +} - if (flags & G_ASK_PASSWORD_NEED_USERNAME) { - g_mount_operation_set_username (op, gtk_entry_get_text (GTK_ENTRY (dialog->details->user_entry))); +static void +check_uri_entry (NautilusConnectServerDialog *dialog) +{ + guint length; + gboolean active = FALSE; + const char *text = NULL; + const char *icon_name = NULL; + + length = gtk_entry_get_text_length (GTK_ENTRY (dialog->details->uri_entry)); + if (length > 0) { + GError *error = NULL; + + text = gtk_entry_get_text (GTK_ENTRY (dialog->details->uri_entry)); + active = validate_uri (dialog, text, &error); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) { + gtk_label_set_text (GTK_LABEL (dialog->details->error_label), error->message); + } else { + reset_example_label (dialog); + } + g_clear_error (&error); } - if (flags & G_ASK_PASSWORD_NEED_DOMAIN) { - g_mount_operation_set_domain (op, gtk_entry_get_text (GTK_ENTRY (dialog->details->domain_entry))); - } + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, active); - if (flags & G_ASK_PASSWORD_SAVING_SUPPORTED && - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->details->remember_checkbox))) { - g_mount_operation_set_password_save (op, G_PASSWORD_SAVE_PERMANENTLY); + if (length > 0) { + icon_name = "edit-clear-symbolic"; } - connect_dialog_set_connecting (dialog); - - g_simple_async_result_set_op_res_gboolean (dialog->details->fill_details_res, TRUE); - g_simple_async_result_complete (dialog->details->fill_details_res); - - g_object_unref (dialog->details->fill_details_res); - dialog->details->fill_details_res = NULL; - - g_object_unref (dialog->details->fill_operation); - dialog->details->fill_operation = NULL; + g_object_set (dialog->details->uri_entry, + "secondary-icon-name", icon_name, + "secondary-icon-activatable", active, + "secondary-icon-sensitive", active, + NULL); } static void -connect_dialog_request_additional_details (NautilusConnectServerDialog *self, - GAskPasswordFlags flags, - const gchar *default_user, - const gchar *default_domain) +on_uri_entry_changed (GtkEditable *editable, + NautilusConnectServerDialog *dialog) { - GtkWidget *content_area, *label, *hbox, *icon; - - self->details->fill_details_flags = flags; + GtkTreeSelection *selection; - connect_dialog_restore_info_bar (self, GTK_MESSAGE_WARNING); - - content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (self->details->info_bar)); - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, FALSE, 6); - gtk_widget_show (hbox); - - icon = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, - GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 6); - gtk_widget_show (icon); - - label = gtk_label_new (_("Please verify your user details.")); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 6); - gtk_widget_show (label); + /* if the uri is changed at all it isn't the selected on anymore */ + selection = gtk_tree_view_get_selection (dialog->details->view); + gtk_tree_selection_unselect_all (selection); - if (flags & G_ASK_PASSWORD_NEED_PASSWORD) { - iconize_entry (self, self->details->password_entry); - } + check_uri_entry (dialog); +} - if (flags & G_ASK_PASSWORD_NEED_USERNAME) { - if (default_user != NULL && g_strcmp0 (default_user, "") != 0) { - gtk_entry_set_text (GTK_ENTRY (self->details->user_entry), - default_user); - } else { - iconize_entry (self, self->details->user_entry); - } - } +static char * +get_selected (NautilusConnectServerDialog *dialog, + GtkTreeIter *iter_out) +{ + GtkTreeSelection *selection; + GtkTreeIter iter; + char *uri = NULL; - if (flags & G_ASK_PASSWORD_NEED_DOMAIN) { - if (default_domain != NULL && g_strcmp0 (default_domain, "") != 0) { - gtk_entry_set_text (GTK_ENTRY (self->details->domain_entry), - default_domain); - } else { - iconize_entry (self, self->details->domain_entry); + selection = gtk_tree_view_get_selection (dialog->details->view); + if (gtk_tree_selection_get_selected (selection, NULL, &iter)) { + gtk_tree_model_get (GTK_TREE_MODEL (dialog->details->store), + &iter, + COLUMN_URI, &uri, + -1); + if (iter_out) { + *iter_out = iter; } } - self->details->info_bar_content = hbox; - - gtk_widget_set_sensitive (self->details->connect_button, TRUE); - gtk_button_set_label (GTK_BUTTON (self->details->connect_button), - _("Continue")); - - if (!(flags & G_ASK_PASSWORD_SAVING_SUPPORTED)) { - g_signal_handler_disconnect (self->details->password_entry, - self->details->password_sensitive_id); - self->details->password_sensitive_id = 0; - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->details->remember_checkbox), - FALSE); - gtk_widget_set_sensitive (self->details->remember_checkbox, FALSE); - } + return uri; } static void -display_location_async_cb (GObject *source, - GAsyncResult *res, - gpointer user_data) +on_selection_changed (GtkTreeSelection *selection, + NautilusConnectServerDialog *dialog) { - NautilusConnectServerDialog *dialog; - GError *error; - - dialog = NAUTILUS_CONNECT_SERVER_DIALOG (source); - error = NULL; - - nautilus_connect_server_dialog_display_location_finish (dialog, - res, &error); - - if (error != NULL) { - connect_dialog_set_info_bar_error (dialog, error); - g_error_free (error); + char *uri; + + uri = get_selected (dialog, NULL); + if (uri != NULL) { + g_signal_handlers_block_by_func (dialog->details->uri_entry, on_uri_entry_changed, dialog); + gtk_entry_set_text (GTK_ENTRY (dialog->details->uri_entry), uri); + g_signal_handlers_unblock_by_func (dialog->details->uri_entry, on_uri_entry_changed, dialog); + check_uri_entry (dialog); + g_free (uri); + gtk_widget_set_sensitive (dialog->details->remove_menu_item, TRUE); } else { - gtk_widget_destroy (GTK_WIDGET (dialog)); + gtk_widget_set_sensitive (dialog->details->remove_menu_item, FALSE); } } -static void -mount_enclosing_ready_cb (GObject *source, - GAsyncResult *res, - gpointer user_data) +static GBookmarkFile * +server_list_load (NautilusConnectServerDialog *dialog) { - GFile *location; - NautilusConnectServerDialog *dialog; - GError *error; - - error = NULL; - location = G_FILE (source); - dialog = user_data; - - g_file_mount_enclosing_volume_finish (location, res, &error); - - if (!error || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED)) { - /* volume is mounted, show it */ - nautilus_connect_server_dialog_display_location_async (dialog, location, - display_location_async_cb, NULL); - } else { - if (dialog->details->should_destroy) { - gtk_widget_destroy (GTK_WIDGET (dialog)); - } else { - connect_dialog_set_info_bar_error (dialog, error); - } - } - - g_clear_object (&dialog->details->mount_cancellable); - + GBookmarkFile *bookmarks; + GError *error = NULL; + char *datadir; + char *filename; + + bookmarks = g_bookmark_file_new (); + datadir = g_build_filename (g_get_user_config_dir (), "nautilus", NULL); + filename = g_build_filename (datadir, "servers", NULL); + g_mkdir_with_parents (datadir, 0700); + g_free (datadir); + g_bookmark_file_load_from_file (bookmarks, + filename, + &error); + g_free (filename); if (error != NULL) { + if (! g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + /* only warn if the file exists */ + g_warning ("Unable to open server bookmarks: %s", error->message); + } g_error_free (error); + g_bookmark_file_free (bookmarks); + bookmarks = NULL; } + + return bookmarks; } static void -connect_dialog_present_uri_async (NautilusConnectServerDialog *self, - GFile *location) +server_list_save (NautilusConnectServerDialog *dialog, + GBookmarkFile *bookmarks) { - GMountOperation *op; - - self->details->mount_cancellable = g_cancellable_new (); + char *filename; - op = nautilus_connect_server_operation_new (self); - g_file_mount_enclosing_volume (location, - 0, op, self->details->mount_cancellable, - mount_enclosing_ready_cb, self); - g_object_unref (op); + filename = g_build_filename (g_get_user_config_dir (), "nautilus", "servers", NULL); + g_bookmark_file_to_file (bookmarks, filename, NULL); } static void -connect_dialog_connect_to_server (NautilusConnectServerDialog *dialog) +populate_server_list (NautilusConnectServerDialog *dialog) { - struct MethodInfo *meth; - GFile *location; - int index; + GBookmarkFile *bookmarks; GtkTreeIter iter; - char *user, *initial_path, *server, *folder, *domain, *port_str; - char *t, *join, *uri; - char *temp, *stripped_server; - double port; - - /* 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]); - - server = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->server_entry), 0, -1); - - temp = g_strconcat (meth->scheme, "://", NULL); - if (g_str_has_prefix (server, temp)) { - stripped_server = g_strdup (server + strlen (temp)); - g_free (server); - server = stripped_server; - } - g_free (temp); - - user = NULL; - initial_path = g_strdup (""); - domain = NULL; - folder = NULL; - - if (meth->flags & IS_ANONYMOUS) { - /* FTP special case */ - user = g_strdup ("anonymous"); - } else if ((strcmp (meth->scheme, "smb") == 0) || - (strcmp (meth->scheme, "afp") == 0)){ - /* SMB/AFP special case */ - g_free (initial_path); - - t = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->share_entry), 0, -1); - initial_path = g_strconcat ("/", t, NULL); - - g_free (t); - } - - /* username */ - if (!user) { - t = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->user_entry), 0, -1); - user = g_uri_escape_string (t, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, FALSE); - g_free (t); - } - - /* domain */ - domain = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->domain_entry), 0, -1); - - if (strlen (domain) != 0) { - t = user; + char **uris; + int i; - user = g_strconcat (domain , ";" , t, NULL); - g_free (t); + bookmarks = server_list_load (dialog); + if (bookmarks == NULL) { + return; } - - /* folder */ - folder = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->folder_entry), 0, -1); - - if (folder[0] != 0 && - folder[0] != '/') { - join = "/"; + uris = g_bookmark_file_get_uris (bookmarks, NULL); + if (uris != NULL) { + for (i = 0; uris[i] != NULL; i++) { + char *name; + + name = g_bookmark_file_get_title (bookmarks, uris[i], NULL); + gtk_list_store_append (dialog->details->store, &iter); + gtk_list_store_set (dialog->details->store, &iter, + COLUMN_URI, uris[i], + COLUMN_NAME, name, + -1); + g_free (name); + } + g_strfreev (uris); + gtk_widget_set_sensitive (dialog->details->clear_menu_item, TRUE); } else { - join = ""; + gtk_widget_set_sensitive (dialog->details->clear_menu_item, FALSE); } - t = folder; - folder = g_strconcat (initial_path, join, t, NULL); - g_free (t); - - t = folder; - folder = g_uri_escape_string (t, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE); - g_free (t); + g_bookmark_file_free (bookmarks); +} - /* port */ - port = gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->details->port_spinbutton)); +static void +server_list_remove (NautilusConnectServerDialog *dialog, + const char *uri) +{ + GBookmarkFile *bookmarks; - if (port != 0 && port != meth->default_port) { - port_str = g_strdup_printf ("%d", (int) port); - } else { - port_str = NULL; + bookmarks = server_list_load (dialog); + if (bookmarks == NULL) { + return; } - /* final uri */ - uri = g_strdup_printf ("%s://%s%s%s%s%s%s", - meth->scheme, - (user != NULL) ? user : "", - (user[0] != 0) ? "@" : "", - server, - (port_str != NULL) ? ":" : "", - (port_str != NULL) ? port_str : "", - (folder != NULL) ? folder : ""); - - g_free (initial_path); - g_free (server); - g_free (folder); - g_free (user); - g_free (domain); - g_free (port_str); - - location = g_file_new_for_uri (uri); - g_free (uri); - - connect_dialog_set_connecting (dialog); - connect_dialog_present_uri_async (dialog, - location); - - g_object_unref (location); + g_bookmark_file_remove_item (bookmarks, uri, NULL); + server_list_save (dialog, bookmarks); + g_bookmark_file_free (bookmarks); } static void -connect_to_server_or_finish_fill (NautilusConnectServerDialog *dialog) +server_list_remove_all (NautilusConnectServerDialog *dialog) { - if (dialog->details->fill_details_res != NULL) { - connect_dialog_finish_fill (dialog); - } else { - connect_dialog_connect_to_server (dialog); + GBookmarkFile *bookmarks; + + bookmarks = g_bookmark_file_new (); + if (bookmarks == NULL) { + return; } + server_list_save (dialog, bookmarks); + g_bookmark_file_free (bookmarks); } -static gboolean -connect_dialog_abort_mount_operation (NautilusConnectServerDialog *dialog) +static void +boldify_label (GtkLabel *label) { - gboolean retval = FALSE; - - if (dialog->details->mount_cancellable != NULL) { - g_cancellable_cancel (dialog->details->mount_cancellable); - retval = TRUE; - } else if (dialog->details->fill_details_res != NULL) { - g_simple_async_result_set_op_res_gboolean (dialog->details->fill_details_res, FALSE); - g_simple_async_result_complete (dialog->details->fill_details_res); - - g_object_unref (dialog->details->fill_details_res); - dialog->details->fill_details_res = NULL; - - if (dialog->details->fill_operation) { - g_object_unref (dialog->details->fill_operation); - dialog->details->fill_operation = NULL; - } - - retval = TRUE; - } - - return retval; + PangoAttrList *attrs; + attrs = pango_attr_list_new (); + pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); + gtk_label_set_attributes (label, attrs); + pango_attr_list_unref (attrs); } static void -connect_dialog_destroy (NautilusConnectServerDialog *dialog) +on_clear_item_activated (GtkMenuItem *item, + NautilusConnectServerDialog *dialog) { - if (connect_dialog_abort_mount_operation (dialog)) { - dialog->details->should_destroy = TRUE; - gtk_widget_hide (GTK_WIDGET (dialog)); - } else { - gtk_widget_destroy (GTK_WIDGET (dialog)); - } + server_list_remove_all (dialog); + gtk_list_store_clear (dialog->details->store); + gtk_widget_set_sensitive (dialog->details->clear_menu_item, FALSE); } static void -connect_dialog_response_cb (NautilusConnectServerDialog *dialog, - int response_id, - gpointer data) +on_remove_item_activated (GtkMenuItem *item, + NautilusConnectServerDialog *dialog) { - GError *error; + char *uri; + GtkTreeIter iter; - switch (response_id) { - case RESPONSE_CONNECT: - connect_to_server_or_finish_fill (dialog); - break; - case GTK_RESPONSE_NONE: - case GTK_RESPONSE_DELETE_EVENT: - case GTK_RESPONSE_CANCEL: - connect_dialog_destroy (dialog); - break; - case GTK_RESPONSE_HELP : - error = NULL; - gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (dialog)), - "help:gnome-help/nautilus-connect", - gtk_get_current_event_time (), &error); - if (error) { - eel_show_error_dialog (_("There was an error displaying help."), error->message, - GTK_WINDOW (dialog)); - g_error_free (error); - } - break; - default : - g_assert_not_reached (); + uri = get_selected (dialog, &iter); + if (uri != NULL) { + server_list_remove (dialog, uri); + gtk_list_store_remove (dialog->details->store, &iter); + g_free (uri); } } static void -connect_dialog_cleanup (NautilusConnectServerDialog *dialog) +on_row_activated (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column, + NautilusConnectServerDialog *dialog) { - /* hide the infobar */ - gtk_widget_hide (dialog->details->info_bar); - - /* set the connect button label back to 'Connect' */ - gtk_button_set_label (GTK_BUTTON (dialog->details->connect_button), - _("C_onnect")); - - /* if there was a pending mount operation, cancel it. */ - connect_dialog_abort_mount_operation (dialog); - - /* restore password checkbox sensitivity */ - if (dialog->details->password_sensitive_id == 0) { - dialog->details->password_sensitive_id = - g_signal_connect (dialog->details->password_entry, "changed", - G_CALLBACK (sensitive_entry_changed_callback), - dialog->details->remember_checkbox); - sensitive_entry_changed_callback (GTK_EDITABLE (dialog->details->password_entry), - dialog->details->remember_checkbox); - } - - /* remove icons on the entries */ - g_list_foreach (dialog->details->iconized_entries, - (GFunc) iconized_entry_restore, dialog); - g_list_free (dialog->details->iconized_entries); - dialog->details->iconized_entries = NULL; - - dialog->details->last_password_set = FALSE; + gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); } - static void -connect_dialog_setup_for_type (NautilusConnectServerDialog *dialog) +on_popup_menu_detach (GtkWidget *attach_widget, + GtkMenu *menu) { - struct MethodInfo *meth; - int index;; - GtkTreeIter iter; + NautilusConnectServerDialog *dialog = NAUTILUS_CONNECT_SERVER_DIALOG (attach_widget); - connect_dialog_cleanup (dialog); + dialog->details->menu = NULL; + dialog->details->remove_menu_item = NULL; + dialog->details->clear_menu_item = NULL; +} - /* get our method info */ - if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->details->type_combo), - &iter)) { - /* there are no entries in the combo, something is wrong - * with our GVfs installation. - */ - connect_dialog_gvfs_error (dialog); +static void +create_popup_menu (NautilusConnectServerDialog *dialog) +{ + GtkWidget *menu; + GtkWidget *item; + if (dialog->details->menu != NULL) { return; } - 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]); + menu = gtk_menu_new (); + dialog->details->menu = menu; + gtk_menu_attach_to_widget (GTK_MENU (menu), + GTK_WIDGET (dialog), + on_popup_menu_detach); - g_object_set (dialog->details->share_entry, - "visible", - (meth->flags & SHOW_SHARE) != 0, - NULL); + item = gtk_menu_item_new_with_mnemonic (_("_Remove")); + dialog->details->remove_menu_item = item; + g_signal_connect (item, "activate", + G_CALLBACK (on_remove_item_activated), dialog); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); - g_object_set (dialog->details->port_spinbutton, - "sensitive", - (meth->flags & SHOW_PORT) != 0, - "value", (gdouble) meth->default_port, - NULL); - - g_object_set (dialog->details->user_details, - "visible", - (meth->flags & SHOW_USER) != 0 || - (meth->flags & SHOW_DOMAIN) != 0, - NULL); - - g_object_set (dialog->details->user_entry, - "visible", - (meth->flags & SHOW_USER) != 0, - NULL); - - g_object_set (dialog->details->password_entry, - "visible", - (meth->flags & SHOW_USER) != 0, - NULL); + eel_gtk_menu_append_separator (GTK_MENU (menu)); - g_object_set (dialog->details->domain_entry, - "visible", - (meth->flags & SHOW_DOMAIN) != 0, - NULL); + item = gtk_menu_item_new_with_mnemonic (_("_Clear All")); + dialog->details->clear_menu_item = item; + g_signal_connect (item, "activate", + G_CALLBACK (on_clear_item_activated), dialog); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); } static void -sensitive_entry_changed_callback (GtkEditable *editable, - GtkWidget *widget) +history_popup_menu (NautilusConnectServerDialog *dialog) { - guint length; - - length = gtk_entry_get_text_length (GTK_ENTRY (editable)); - - gtk_widget_set_sensitive (widget, length > 0); + create_popup_menu (dialog); + eel_pop_up_context_menu (GTK_MENU (dialog->details->menu), NULL); } -static void -bind_visibility (NautilusConnectServerDialog *dialog, - GtkWidget *source, - GtkWidget *dest) +static gboolean +on_popup_menu (GtkWidget *widget, + NautilusConnectServerDialog *dialog) { - g_object_bind_property (source, - "visible", - dest, - "visible", - G_BINDING_DEFAULT); + history_popup_menu (dialog); + return TRUE; } static void nautilus_connect_server_dialog_init (NautilusConnectServerDialog *dialog) { GtkWidget *label; - GtkWidget *alignment; + GtkWidget *button; + GtkWidget *sw; + GtkWidget *view; + GtkWidget *box; GtkWidget *content_area; - GtkWidget *combo, *grid; - GtkWidget *hbox, *connect_button, *checkbox; + GtkWidget *grid; + int row; + GtkCellRenderer *cell; + GtkTreeSelection *selection; GtkListStore *store; - GtkCellRenderer *renderer; - gchar *str; - int i; - + dialog->details = G_TYPE_INSTANCE_GET_PRIVATE (dialog, NAUTILUS_TYPE_CONNECT_SERVER_DIALOG, NautilusConnectServerDialogDetails); + populate_supported_list (dialog); + content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); /* set dialog properties */ gtk_window_set_title (GTK_WINDOW (dialog), _("Connect to Server")); - gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); - gtk_box_set_spacing (GTK_BOX (content_area), 2); - gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - - /* create the size group */ - dialog->details->labels_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - dialog->details->contents_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - - /* infobar */ - dialog->details->info_bar = gtk_info_bar_new (); - gtk_info_bar_set_message_type (GTK_INFO_BAR (dialog->details->info_bar), - GTK_MESSAGE_INFO); - gtk_box_pack_start (GTK_BOX (content_area), dialog->details->info_bar, - FALSE, FALSE, 6); - - /* server settings label */ - label = gtk_label_new (NULL); - str = g_strdup_printf ("<b>%s</b>", _("Server Details")); - gtk_label_set_markup (GTK_LABEL (label), str); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (content_area), label, FALSE, FALSE, 6); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_widget_show (label); - - /* server settings alignment */ - alignment = gtk_alignment_new (0, 0, 0, 0); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), - 0, 0, 12, 0); - gtk_box_pack_start (GTK_BOX (content_area), alignment, TRUE, TRUE, 0); - gtk_widget_show (alignment); + gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); grid = gtk_grid_new (); gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL); gtk_grid_set_row_spacing (GTK_GRID (grid), 6); - gtk_grid_set_column_spacing (GTK_GRID (grid), 3); - gtk_container_add (GTK_CONTAINER (alignment), grid); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_widget_set_margin_bottom (grid, 12); + gtk_container_set_border_width (GTK_CONTAINER (grid), 5); + gtk_container_add (GTK_CONTAINER (content_area), grid); gtk_widget_show (grid); dialog->details->primary_grid = grid; - /* first row: server entry + port spinbutton */ - label = gtk_label_new_with_mnemonic (_("_Server:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_widget_show (label); + row = 0; - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_widget_show (hbox); - gtk_grid_attach_next_to (GTK_GRID (grid), hbox, label, - GTK_POS_RIGHT, - 1, 1); - gtk_size_group_add_widget (dialog->details->contents_size_group, hbox); - - dialog->details->server_entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->server_entry), TRUE); - gtk_box_pack_start (GTK_BOX (hbox), dialog->details->server_entry, FALSE, FALSE, 0); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->server_entry); - gtk_widget_show (dialog->details->server_entry); - - /* port */ - label = gtk_label_new_with_mnemonic (_("_Port:")); + label = gtk_label_new_with_mnemonic (_("_Server Address")); + boldify_label (GTK_LABEL (label)); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1); gtk_widget_show (label); - dialog->details->port_spinbutton = - gtk_spin_button_new_with_range (0.0, 65535.0, 1.0); - g_object_set (dialog->details->port_spinbutton, - "digits", 0, - "numeric", TRUE, - "update-policy", GTK_UPDATE_IF_VALID, - NULL); - gtk_box_pack_start (GTK_BOX (hbox), dialog->details->port_spinbutton, - FALSE, FALSE, 0); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->port_spinbutton); - gtk_widget_show (dialog->details->port_spinbutton); + dialog->details->uri_entry = gtk_entry_new (); - /* second row: type combobox */ - label = gtk_label_new_with_mnemonic (_("_Type:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_widget_show (label); + gtk_widget_set_hexpand (dialog->details->uri_entry, TRUE); + gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->uri_entry), TRUE); + gtk_grid_attach (GTK_GRID (grid), dialog->details->uri_entry, 0, row++, 1, 1); - dialog->details->type_combo = combo = gtk_combo_box_new (); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->type_combo); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->type_combo); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->uri_entry); + gtk_widget_show (dialog->details->uri_entry); - /* 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 (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 gvfs uri schemes */ - 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_grid_attach_next_to (GTK_GRID (grid), combo, label, - GTK_POS_RIGHT, 1, 1); - g_signal_connect_swapped (combo, "changed", - G_CALLBACK (connect_dialog_setup_for_type), - dialog); - - /* third row: share entry */ - label = gtk_label_new_with_mnemonic (_("Sh_are:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - - dialog->details->share_entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->share_entry), TRUE); - gtk_grid_attach_next_to (GTK_GRID (grid), dialog->details->share_entry, label, - GTK_POS_RIGHT, 1, 1); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->share_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->share_entry); - - bind_visibility (dialog, dialog->details->share_entry, label); - - /* fourth row: folder entry */ - label = gtk_label_new_with_mnemonic (_("_Folder:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->share_entry); - gtk_widget_show (label); - - dialog->details->folder_entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (dialog->details->folder_entry), "/"); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->folder_entry), TRUE); - gtk_grid_attach_next_to (GTK_GRID (grid), dialog->details->folder_entry, label, - GTK_POS_RIGHT, 1, 1); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->folder_entry); - gtk_widget_show (dialog->details->folder_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->folder_entry); - - /* user details label */ label = gtk_label_new (NULL); - str = g_strdup_printf ("<b>%s</b>", _("User Details")); - gtk_label_set_markup (GTK_LABEL (label), str); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_box_pack_start (GTK_BOX (content_area), label, FALSE, FALSE, 6); - - /* user details alignment */ - alignment = gtk_alignment_new (0, 0, 0, 0); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), - 0, 0, 12, 0); - gtk_box_pack_start (GTK_BOX (content_area), alignment, TRUE, TRUE, 0); - - bind_visibility (dialog, alignment, label); - dialog->details->user_details = alignment; - - grid = gtk_grid_new (); - gtk_grid_set_row_spacing (GTK_GRID (grid), 6); - gtk_grid_set_column_spacing (GTK_GRID (grid), 3); - gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL); - gtk_container_add (GTK_CONTAINER (alignment), grid); - gtk_widget_show (grid); + gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1); + gtk_widget_show (label); + dialog->details->error_label = label; + reset_example_label (dialog); + gtk_widget_set_margin_bottom (label, 12); + gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label"); - /* first row: domain entry */ - label = gtk_label_new_with_mnemonic (_("_Domain name:")); + label = gtk_label_new_with_mnemonic (_("_Recent Servers")); + boldify_label (GTK_LABEL (label)); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); + gtk_grid_attach (GTK_GRID (grid), label, 0, row++, 1, 1); + gtk_widget_show (label); - dialog->details->domain_entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->domain_entry), TRUE); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - gtk_grid_attach_next_to (GTK_GRID (grid), dialog->details->domain_entry, label, - GTK_POS_RIGHT, 1, 1); + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); + gtk_widget_set_hexpand (box, TRUE); + gtk_widget_set_vexpand (box, TRUE); + gtk_grid_attach (GTK_GRID (grid), box, 0, row++, 1, 1); + gtk_widget_show (box); + + sw = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_widget_set_size_request (sw, 400, 150); + gtk_widget_show (sw); + gtk_widget_set_hexpand (sw, TRUE); + gtk_widget_set_vexpand (sw, TRUE); + gtk_container_add (GTK_CONTAINER (box), sw); + + view = gtk_tree_view_new (); + gtk_widget_show (view); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE); + gtk_container_add (GTK_CONTAINER (sw), view); + + g_signal_connect (view, "row-activated", + G_CALLBACK (on_row_activated), + dialog); + g_signal_connect (view, "popup-menu", + G_CALLBACK (on_popup_menu), + dialog); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->domain_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->domain_entry); - bind_visibility (dialog, dialog->details->domain_entry, label); + store = gtk_list_store_new (NUM_COLUMNS, + G_TYPE_STRING, + G_TYPE_STRING); - /* second row: username entry */ - label = gtk_label_new_with_mnemonic (_("_User name:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); + gtk_tree_view_set_model (GTK_TREE_VIEW (view), + GTK_TREE_MODEL (store)); + g_object_unref (store); - dialog->details->user_entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->user_entry), TRUE); - gtk_grid_attach_next_to (GTK_GRID (grid), dialog->details->user_entry, label, - GTK_POS_RIGHT, 1, 1); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->user_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->user_entry); + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view)); + g_signal_connect (selection, "changed", + G_CALLBACK (on_selection_changed), + dialog); - bind_visibility (dialog, dialog->details->user_entry, label); + cell = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), + -1, + NULL, + cell, + "text", COLUMN_NAME, + NULL); + cell = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view), + -1, + NULL, + cell, + "text", COLUMN_URI, + NULL); + dialog->details->view = GTK_TREE_VIEW (view); + dialog->details->store = store; + + button = gtk_dialog_add_button (GTK_DIALOG (dialog), + _("_Browse"), + GTK_RESPONSE_ACCEPT); + gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))), + button, TRUE); - /* third row: password entry */ - label = gtk_label_new_with_mnemonic (_("Pass_word:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_container_add (GTK_CONTAINER (grid), label); - gtk_size_group_add_widget (dialog->details->labels_size_group, label); - - dialog->details->password_entry = gtk_entry_new (); - gtk_entry_set_activates_default (GTK_ENTRY (dialog->details->password_entry), TRUE); - gtk_entry_set_visibility (GTK_ENTRY (dialog->details->password_entry), FALSE); - gtk_grid_attach_next_to (GTK_GRID (grid), dialog->details->password_entry, label, - GTK_POS_RIGHT, 1, 1); - gtk_size_group_add_widget (dialog->details->contents_size_group, dialog->details->password_entry); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->details->password_entry); - - bind_visibility (dialog, dialog->details->password_entry, label); - - /* fourth row: remember checkbox */ - checkbox = gtk_check_button_new_with_mnemonic (_("_Remember this password")); - gtk_grid_attach_next_to (GTK_GRID (grid), checkbox, dialog->details->password_entry, - GTK_POS_BOTTOM, 1, 1); - dialog->details->remember_checkbox = checkbox; - - bind_visibility (dialog, dialog->details->password_entry, checkbox); - - 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); - connect_button = gtk_dialog_add_button (GTK_DIALOG (dialog), - _("C_onnect"), - RESPONSE_CONNECT); + gtk_dialog_add_button (GTK_DIALOG (dialog), + _("C_onnect"), + GTK_RESPONSE_OK); gtk_dialog_set_default_response (GTK_DIALOG (dialog), - RESPONSE_CONNECT); - dialog->details->connect_button = connect_button; + GTK_RESPONSE_OK); + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), + GTK_RESPONSE_OK, + FALSE); - g_signal_connect (dialog->details->server_entry, "changed", - G_CALLBACK (sensitive_entry_changed_callback), - connect_button); - sensitive_entry_changed_callback (GTK_EDITABLE (dialog->details->server_entry), - connect_button); + g_signal_connect (dialog->details->uri_entry, "changed", + G_CALLBACK (on_uri_entry_changed), + dialog); + g_signal_connect (dialog->details->uri_entry, "icon-release", + G_CALLBACK (on_uri_entry_clear), + dialog); g_signal_connect (dialog, "response", - G_CALLBACK (connect_dialog_response_cb), - dialog); + G_CALLBACK (nautilus_connect_server_dialog_response), + NULL); - connect_dialog_setup_for_type (dialog); + create_popup_menu (dialog); + populate_server_list (dialog); } static void @@ -1134,12 +719,7 @@ nautilus_connect_server_dialog_finalize (GObject *object) dialog = NAUTILUS_CONNECT_SERVER_DIALOG (object); - connect_dialog_abort_mount_operation (dialog); - - if (dialog->details->iconized_entries != NULL) { - g_list_free (dialog->details->iconized_entries); - dialog->details->iconized_entries = NULL; - } + g_strfreev (dialog->details->supported); G_OBJECT_CLASS (nautilus_connect_server_dialog_parent_class)->finalize (object); } @@ -1169,97 +749,3 @@ nautilus_connect_server_dialog_new (NautilusWindow *window) return dialog; } - -gboolean -nautilus_connect_server_dialog_fill_details_finish (NautilusConnectServerDialog *self, - GAsyncResult *result) -{ - return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)); -} - -void -nautilus_connect_server_dialog_fill_details_async (NautilusConnectServerDialog *self, - GMountOperation *operation, - const gchar *default_user, - const gchar *default_domain, - GAskPasswordFlags flags, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *fill_details_res; - const gchar *str; - GAskPasswordFlags set_flags; - - if (g_cancellable_is_cancelled (self->details->mount_cancellable)) { - g_simple_async_report_error_in_idle (G_OBJECT (self), - callback, user_data, - G_IO_ERROR, G_IO_ERROR_CANCELLED, - "%s", _("Operation cancelled")); - - return; - } - - fill_details_res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, - nautilus_connect_server_dialog_fill_details_async); - - self->details->fill_details_res = fill_details_res; - set_flags = (flags & G_ASK_PASSWORD_NEED_PASSWORD) | - (flags & G_ASK_PASSWORD_NEED_USERNAME) | - (flags & G_ASK_PASSWORD_NEED_DOMAIN); - - if (set_flags & G_ASK_PASSWORD_NEED_PASSWORD) { - /* provide the password */ - str = gtk_entry_get_text (GTK_ENTRY (self->details->password_entry)); - - if (str != NULL && g_strcmp0 (str, "") != 0 && - !self->details->last_password_set) { - g_mount_operation_set_password (G_MOUNT_OPERATION (operation), - str); - set_flags ^= G_ASK_PASSWORD_NEED_PASSWORD; - - if (flags & G_ASK_PASSWORD_SAVING_SUPPORTED && - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->details->remember_checkbox))) { - g_mount_operation_set_password_save (G_MOUNT_OPERATION (operation), - G_PASSWORD_SAVE_PERMANENTLY); - } - - self->details->last_password_set = TRUE; - } - } - - if (set_flags & G_ASK_PASSWORD_NEED_USERNAME) { - /* see if the default username is different from ours */ - str = gtk_entry_get_text (GTK_ENTRY (self->details->user_entry)); - - if (str != NULL && g_strcmp0 (str, "") != 0 && - g_strcmp0 (str, default_user) != 0) { - g_mount_operation_set_username (G_MOUNT_OPERATION (operation), - str); - set_flags ^= G_ASK_PASSWORD_NEED_USERNAME; - } - } - - if (set_flags & G_ASK_PASSWORD_NEED_DOMAIN) { - /* see if the default domain is different from ours */ - str = gtk_entry_get_text (GTK_ENTRY (self->details->domain_entry)); - - if (str != NULL && g_strcmp0 (str, "") && - g_strcmp0 (str, default_domain) != 0) { - g_mount_operation_set_domain (G_MOUNT_OPERATION (operation), - str); - set_flags ^= G_ASK_PASSWORD_NEED_DOMAIN; - } - } - - if (set_flags != 0) { - set_flags |= (flags & G_ASK_PASSWORD_SAVING_SUPPORTED); - self->details->fill_operation = g_object_ref (operation); - connect_dialog_request_additional_details (self, set_flags, default_user, default_domain); - } else { - g_simple_async_result_set_op_res_gboolean (fill_details_res, TRUE); - g_simple_async_result_complete (fill_details_res); - g_object_unref (self->details->fill_details_res); - - self->details->fill_details_res = NULL; - } -} diff --git a/src/nautilus-connect-server-dialog.h b/src/nautilus-connect-server-dialog.h index bd2dc3d35..e42c4b858 100644 --- a/src/nautilus-connect-server-dialog.h +++ b/src/nautilus-connect-server-dialog.h @@ -56,24 +56,7 @@ struct _NautilusConnectServerDialogClass { GType nautilus_connect_server_dialog_get_type (void); -GtkWidget* nautilus_connect_server_dialog_new (NautilusWindow *window); - -void nautilus_connect_server_dialog_display_location_async (NautilusConnectServerDialog *self, - GFile *location, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nautilus_connect_server_dialog_display_location_finish (NautilusConnectServerDialog *self, - GAsyncResult *result, - GError **error); - -void nautilus_connect_server_dialog_fill_details_async (NautilusConnectServerDialog *self, - GMountOperation *operation, - const gchar *default_user, - const gchar *default_domain, - GAskPasswordFlags flags, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean nautilus_connect_server_dialog_fill_details_finish (NautilusConnectServerDialog *self, - GAsyncResult *result); +GtkWidget * nautilus_connect_server_dialog_new (NautilusWindow *window); +GFile * nautilus_connect_server_dialog_get_location (NautilusConnectServerDialog *dialog); #endif /* NAUTILUS_CONNECT_SERVER_DIALOG_H */ diff --git a/src/nautilus-connect-server-operation.c b/src/nautilus-connect-server-operation.c deleted file mode 100644 index 8d3ead329..000000000 --- a/src/nautilus-connect-server-operation.c +++ /dev/null @@ -1,151 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* - * Nautilus - * - * Copyright (C) 2010 Cosimo Cecchi <cosimoc@gnome.org> - * - * Nautilus is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * Nautilus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; see the file COPYING. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Cosimo Cecchi <cosimoc@gnome.org> - */ - -#include <config.h> - -#include "nautilus-connect-server-operation.h" - -#include "nautilus-connect-server-dialog.h" - -G_DEFINE_TYPE (NautilusConnectServerOperation, - nautilus_connect_server_operation, GTK_TYPE_MOUNT_OPERATION); - -enum { - PROP_DIALOG = 1, - NUM_PROPERTIES -}; - -struct _NautilusConnectServerOperationDetails { - NautilusConnectServerDialog *dialog; -}; - -static void -fill_details_async_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - NautilusConnectServerDialog *dialog; - NautilusConnectServerOperation *self; - gboolean res; - - self = user_data; - dialog = NAUTILUS_CONNECT_SERVER_DIALOG (source); - - res = nautilus_connect_server_dialog_fill_details_finish (dialog, result); - - if (!res) { - g_mount_operation_reply (G_MOUNT_OPERATION (self), G_MOUNT_OPERATION_ABORTED); - } else { - g_mount_operation_reply (G_MOUNT_OPERATION (self), G_MOUNT_OPERATION_HANDLED); - } -} - -static void -nautilus_connect_server_operation_ask_password (GMountOperation *op, - const gchar *message, - const gchar *default_user, - const gchar *default_domain, - GAskPasswordFlags flags) -{ - NautilusConnectServerOperation *self; - - self = NAUTILUS_CONNECT_SERVER_OPERATION (op); - - nautilus_connect_server_dialog_fill_details_async (self->details->dialog, - G_MOUNT_OPERATION (self), - default_user, - default_domain, - flags, - fill_details_async_cb, - self); -} - -static void -nautilus_connect_server_operation_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - NautilusConnectServerOperation *self; - - self = NAUTILUS_CONNECT_SERVER_OPERATION (object); - - switch (property_id) { - case PROP_DIALOG: - self->details->dialog = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -nautilus_connect_server_operation_dispose (GObject *object) -{ - NautilusConnectServerOperation *self = NAUTILUS_CONNECT_SERVER_OPERATION (object); - - g_clear_object (&self->details->dialog); - - G_OBJECT_CLASS (nautilus_connect_server_operation_parent_class)->dispose (object); -} - -static void -nautilus_connect_server_operation_class_init (NautilusConnectServerOperationClass *klass) -{ - GMountOperationClass *mount_op_class; - GObjectClass *object_class; - GParamSpec *pspec; - - object_class = G_OBJECT_CLASS (klass); - object_class->set_property = nautilus_connect_server_operation_set_property; - object_class->dispose = nautilus_connect_server_operation_dispose; - - mount_op_class = G_MOUNT_OPERATION_CLASS (klass); - mount_op_class->ask_password = nautilus_connect_server_operation_ask_password; - - pspec = g_param_spec_object ("dialog", "The connect dialog", - "The connect to server dialog", - NAUTILUS_TYPE_CONNECT_SERVER_DIALOG, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DIALOG, pspec); - - g_type_class_add_private (klass, sizeof (NautilusConnectServerOperationDetails)); -} - -static void -nautilus_connect_server_operation_init (NautilusConnectServerOperation *self) -{ - self->details = G_TYPE_INSTANCE_GET_PRIVATE (self, - NAUTILUS_TYPE_CONNECT_SERVER_OPERATION, - NautilusConnectServerOperationDetails); -} - -GMountOperation * -nautilus_connect_server_operation_new (NautilusConnectServerDialog *dialog) -{ - return g_object_new (NAUTILUS_TYPE_CONNECT_SERVER_OPERATION, - "dialog", dialog, - NULL); -} diff --git a/src/nautilus-connect-server-operation.h b/src/nautilus-connect-server-operation.h deleted file mode 100644 index de24060e2..000000000 --- a/src/nautilus-connect-server-operation.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* - * Nautilus - * - * Copyright (C) 2010 Cosimo Cecchi <cosimoc@gnome.org> - * - * Nautilus is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * Nautilus is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; see the file COPYING. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Cosimo Cecchi <cosimoc@gnome.org> - */ - -#ifndef __NAUTILUS_CONNECT_SERVER_OPERATION_H__ -#define __NAUTILUS_CONNECT_SERVER_OPERATION_H__ - -#include <gio/gio.h> -#include <gtk/gtk.h> - -#include "nautilus-connect-server-dialog.h" - -#define NAUTILUS_TYPE_CONNECT_SERVER_OPERATION\ - (nautilus_connect_server_operation_get_type ()) -#define NAUTILUS_CONNECT_SERVER_OPERATION(obj)\ - (G_TYPE_CHECK_INSTANCE_CAST ((obj),\ - NAUTILUS_TYPE_CONNECT_SERVER_OPERATION,\ - NautilusConnectServerOperation)) -#define NAUTILUS_CONNECT_SERVER_OPERATION_CLASS(klass)\ - (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_CONNECT_SERVER_OPERATION,\ - NautilusConnectServerOperationClass)) -#define NAUTILUS_IS_CONNECT_SERVER_OPERATION(obj)\ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_CONNECT_SERVER_OPERATION) - -typedef struct _NautilusConnectServerOperationDetails - NautilusConnectServerOperationDetails; - -typedef struct { - GtkMountOperation parent; - NautilusConnectServerOperationDetails *details; -} NautilusConnectServerOperation; - -typedef struct { - GtkMountOperationClass parent_class; -} NautilusConnectServerOperationClass; - -GType nautilus_connect_server_operation_get_type (void); - -GMountOperation * -nautilus_connect_server_operation_new (NautilusConnectServerDialog *dialog); - - -#endif /* __NAUTILUS_CONNECT_SERVER_OPERATION_H__ */ |