filechooser: add Connect to Server

Same as in GTK 3 and Nautilus, and shares their list of servers. GVfs
does the mounting; on Windows the shell connects to \\server\share,
on the Mac the Finder does it (Cmd+K).
This commit is contained in:
Daemonratte 2026-10-18 17:07:10 +02:00
commit a009f8f759
7 changed files with 658 additions and 3 deletions

View file

@ -975,7 +975,7 @@ libgtk_quartz_2_0_la_LDFLAGS = $(libtool_opts)
libgtk_directfb_2_0_la_LDFLAGS = $(libtool_opts)
libgtk_x11_2_0_la_LIBADD = $(libadd)
libgtk_win32_2_0_la_LIBADD = $(libadd) -lole32 -lgdi32 -lcomdlg32 -lwinspool -lcomctl32 -lshell32
libgtk_win32_2_0_la_LIBADD = $(libadd) -lole32 -lgdi32 -lcomdlg32 -lwinspool -lcomctl32 -lshell32 -lmpr
libgtk_quartz_2_0_la_LIBADD = $(libadd)
libgtk_directfb_2_0_la_LIBADD = $(libadd)

View file

@ -94,6 +94,8 @@
#include <io.h>
#include <windows.h>
#include <shellapi.h>
#include <winnetwk.h>
#include "win32/gdkwin32.h"
#endif
/* Profiling stuff */
@ -178,6 +180,7 @@ enum {
FORWARD_FOLDER,
UNDO,
REDO,
CONNECT_TO_SERVER,
LAST_SIGNAL
};
@ -202,7 +205,8 @@ typedef enum {
SHORTCUT_TYPE_VOLUME,
SHORTCUT_TYPE_SEPARATOR,
SHORTCUT_TYPE_SEARCH,
SHORTCUT_TYPE_RECENT
SHORTCUT_TYPE_RECENT,
SHORTCUT_TYPE_CONNECT
} ShortcutType;
#define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \
@ -326,6 +330,7 @@ typedef enum {
SHORTCUTS_HOME,
SHORTCUTS_DESKTOP,
SHORTCUTS_VOLUMES,
SHORTCUTS_CONNECT,
SHORTCUTS_SHORTCUTS,
SHORTCUTS_BOOKMARKS_SEPARATOR,
SHORTCUTS_BOOKMARKS,
@ -426,6 +431,12 @@ static void history_buttons_create (GtkFileChooserDefault *impl,
GtkWidget *box);
static void forward_folder_handler (GtkFileChooserDefault *impl);
static void undo_handler (GtkFileChooserDefault *impl);
static void connect_to_server_handler (GtkFileChooserDefault *impl);
static GdkPixbuf *render_connect_icon (GtkFileChooserDefault *impl);
static void shortcuts_append_connect (GtkFileChooserDefault *impl);
#ifdef GDK_WINDOWING_QUARTZ
static gboolean connect_waited (gpointer data);
#endif
static void redo_handler (GtkFileChooserDefault *impl);
static void down_folder_handler (GtkFileChooserDefault *impl);
static void home_folder_handler (GtkFileChooserDefault *impl);
@ -793,8 +804,22 @@ _gtk_file_chooser_default_class_init (GtkFileChooserDefaultClass *class)
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[CONNECT_TO_SERVER] =
g_signal_new_class_handler (I_("connect-to-server"),
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_CALLBACK (connect_to_server_handler),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
binding_set = gtk_binding_set_by_class (class);
#ifdef GDK_WINDOWING_QUARTZ
/* as in the Finder */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_k, GDK_MOD2_MASK, "connect-to-server", 0);
#endif
/* Undo and Redo of what was done to files */
#ifdef GDK_WINDOWING_QUARTZ
gtk_binding_entry_add_signal (binding_set, GDK_KEY_z, GDK_MOD2_MASK, "undo", 0);
@ -1814,6 +1839,10 @@ shortcuts_reload_icons (GtkFileChooserDefault *impl)
{
pixbuf = render_recent_icon (impl);
}
else if (shortcut_type == SHORTCUT_TYPE_CONNECT)
{
pixbuf = render_connect_icon (impl);
}
gtk_list_store_set (impl->shortcuts_model, &iter,
SHORTCUTS_COL_PIXBUF, pixbuf,
@ -2451,6 +2480,11 @@ shortcuts_get_index (GtkFileChooserDefault *impl,
n += impl->num_volumes;
if (where == SHORTCUTS_CONNECT)
goto out;
n += impl->has_connect ? 1 : 0;
if (where == SHORTCUTS_SHORTCUTS)
goto out;
@ -2794,6 +2828,7 @@ shortcuts_model_create (GtkFileChooserDefault *impl)
shortcuts_append_home (impl);
shortcuts_append_desktop (impl);
shortcuts_add_volumes (impl);
shortcuts_append_connect (impl);
}
impl->shortcuts_pane_filter_model = shortcuts_pane_model_filter_new (impl,
@ -11187,6 +11222,13 @@ gtk_file_chooser_default_dispose (GObject *object)
/* it belongs to the toplevel, not to us, but speaks to us */
if (impl->preferences_dialog)
gtk_widget_destroy (impl->preferences_dialog);
if (impl->connect_dialog)
gtk_widget_destroy (impl->connect_dialog);
impl->connect_dialog = NULL;
#ifdef GDK_WINDOWING_QUARTZ
if (impl->connect_timeout)
connect_waited (impl);
#endif
if (impl->preferences_apply_id)
{
g_source_remove (impl->preferences_apply_id);
@ -16475,6 +16517,562 @@ out:
g_object_unref (cancellable);
}
/* Connect to Server, as GTK+ 3 and Nautilus have it ("Other Locations"),
* the Finder (Command+K) and Explorer (\\server\share): a place opens a
* dialog for the address of the server, with the servers used before
* (the list of GTK+ 3 and Nautilus, ~/.config/gtk-3.0/servers, so that
* they share it) and examples of the protocols there are. GVfs mounts
* the server, asking for a password as needed; it then shows up among
* the places with its eject button. On Windows the shell connects to the
* share and asks for the name and password itself; on the Mac the Finder
* connects, and the server is opened once it is there. The place is
* only there where servers can be reached. */
#if !defined (G_OS_WIN32) && !defined (GDK_WINDOWING_QUARTZ)
static const struct
{
const gchar *scheme;
const gchar *example;
} connect_examples[] = {
{ "smb", "smb://server/share" },
{ "sftp", "sftp://user@server/folder" },
{ "ftp", "ftp://server" },
{ "dav", "dav://server/folder" },
{ "davs", "davs://server/folder" },
{ "nfs", "nfs://server/path" },
{ "afp", "afp://server/volume" }
};
static gboolean
connect_scheme_supported (const gchar *scheme)
{
const gchar * const *schemes = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
gint i;
for (i = 0; schemes && schemes[i]; i++)
if (g_ascii_strcasecmp (schemes[i], scheme) == 0)
return TRUE;
return FALSE;
}
#endif
static gboolean
connect_to_server_possible (void)
{
#if defined (G_OS_WIN32) || defined (GDK_WINDOWING_QUARTZ)
return TRUE;
#else
gint i;
for (i = 0; i < G_N_ELEMENTS (connect_examples); i++)
if (connect_scheme_supported (connect_examples[i].scheme))
return TRUE;
return FALSE;
#endif
}
static gchar *
connect_servers_filename (void)
{
return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "servers", NULL);
}
static gint64
connect_visited (GBookmarkFile *bookmarks,
const gchar *uri)
{
#if GLIB_CHECK_VERSION (2, 66, 0)
GDateTime *date = g_bookmark_file_get_visited_date_time (bookmarks, uri, NULL);
return date ? g_date_time_to_unix (date) : 0;
#else
return g_bookmark_file_get_visited (bookmarks, uri, NULL);
#endif
}
static gint
connect_compare_visited (gconstpointer a,
gconstpointer b,
gpointer bookmarks)
{
gint64 ta = connect_visited (bookmarks, *(const gchar **) a);
gint64 tb = connect_visited (bookmarks, *(const gchar **) b);
return ta < tb ? 1 : ta > tb ? -1 : 0;
}
/* The servers used before, most recent first */
static gchar **
connect_servers_load (void)
{
GBookmarkFile *bookmarks = g_bookmark_file_new ();
gchar *filename = connect_servers_filename ();
gchar **uris = NULL;
gsize n = 0;
if (g_bookmark_file_load_from_file (bookmarks, filename, NULL))
{
uris = g_bookmark_file_get_uris (bookmarks, &n);
g_qsort_with_data (uris, n, sizeof (gchar *), connect_compare_visited, bookmarks);
}
g_bookmark_file_free (bookmarks);
g_free (filename);
return uris;
}
static void
connect_servers_add (GFile *file)
{
GBookmarkFile *bookmarks = g_bookmark_file_new ();
gchar *filename = connect_servers_filename ();
gchar *dir = g_path_get_dirname (filename);
gchar *uri = g_file_get_uri (file);
gchar *title = _gtk_file_chooser_label_for_file (file);
g_bookmark_file_load_from_file (bookmarks, filename, NULL);
g_bookmark_file_set_title (bookmarks, uri, title);
#if GLIB_CHECK_VERSION (2, 66, 0)
{
GDateTime *now = g_date_time_new_now_utc ();
g_bookmark_file_set_visited_date_time (bookmarks, uri, now);
g_date_time_unref (now);
}
#else
g_bookmark_file_set_visited (bookmarks, uri, -1);
#endif
g_bookmark_file_add_application (bookmarks, uri, NULL, NULL);
g_mkdir_with_parents (dir, 0700);
g_bookmark_file_to_file (bookmarks, filename, NULL);
g_bookmark_file_free (bookmarks);
g_free (title);
g_free (uri);
g_free (dir);
g_free (filename);
}
/* What was typed, as a location: a URI, a path (\\server\share on
* Windows), or a server name for the protocol of Windows networks */
static GFile *
connect_parse_address (const gchar *text)
{
gchar *scheme;
while (g_ascii_isspace (*text))
text++;
if (*text == '\0')
return NULL;
#ifdef G_OS_WIN32
if (g_path_is_absolute (text))
return g_file_new_for_path (text);
scheme = g_uri_parse_scheme (text);
if (scheme && g_ascii_strcasecmp (scheme, "smb") == 0)
{
/* smb://server/share/folder is \\server\share\folder */
gchar *path = g_strdelimit (g_strconcat ("\\\\", text + strlen ("smb://"), NULL), "/", '\\');
gchar *unescaped = g_uri_unescape_string (path, NULL);
GFile *file = g_file_new_for_path (unescaped ? unescaped : path);
g_free (unescaped);
g_free (path);
g_free (scheme);
return file;
}
if (scheme)
{
g_free (scheme);
return g_file_new_for_uri (text);
}
{
gchar *path = g_strdelimit (g_strconcat ("\\\\", text, NULL), "/", '\\');
GFile *file = g_file_new_for_path (path);
g_free (path);
return file;
}
#else
if (g_path_is_absolute (text))
return g_file_new_for_path (text);
scheme = g_uri_parse_scheme (text);
if (scheme)
{
g_free (scheme);
return g_file_new_for_uri (text);
}
else
{
/* "server/share", as people of Windows networks write it */
gchar *uri = g_strconcat ("smb://", text, NULL);
GFile *file = g_file_new_for_uri (uri);
g_free (uri);
return file;
}
#endif
}
static void
connect_show (GtkFileChooserDefault *impl,
GFile *file,
gboolean remember)
{
if (impl->local_only && !_gtk_file_has_native_path (file))
{
error_message (impl, _("The server could not be opened"),
_("This program can only open local files, and the server has no local path here."));
return;
}
if (change_folder_and_display_error (impl, file, FALSE) && remember)
connect_servers_add (file);
}
#ifdef GDK_WINDOWING_QUARTZ
/* in gtkquartz.c, where Cocoa is */
gboolean _gtk_quartz_connect_to_server (const gchar *uri);
/* The Finder mounts the server into /Volumes: what comes next is opened */
static void
connect_mount_added (GVolumeMonitor *monitor,
GMount *mount,
GtkFileChooserDefault *impl)
{
GFile *root = g_mount_get_root (mount);
g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl);
if (impl->connect_timeout)
{
g_source_remove (impl->connect_timeout);
impl->connect_timeout = 0;
}
set_busy_cursor (impl, FALSE);
connect_show (impl, root, FALSE);
g_object_unref (root);
g_object_unref (impl);
}
static gboolean
connect_waited (gpointer data)
{
GtkFileChooserDefault *impl = data;
GVolumeMonitor *monitor = g_volume_monitor_get ();
impl->connect_timeout = 0;
set_busy_cursor (impl, FALSE);
g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl);
g_object_unref (monitor);
g_object_unref (impl);
return FALSE;
}
#endif
#if !defined (G_OS_WIN32) && !defined (GDK_WINDOWING_QUARTZ)
typedef struct
{
GtkFileChooserDefault *impl;
GFile *file;
} ConnectData;
static void
connect_mounted (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
ConnectData *data = user_data;
GError *error = NULL;
gboolean mounted;
mounted = g_file_mount_enclosing_volume_finish (G_FILE (source), result, &error);
GDK_THREADS_ENTER ();
set_busy_cursor (data->impl, FALSE);
if (mounted ||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED) ||
(g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED) && g_file_is_native (data->file)))
connect_show (data->impl, data->file, !g_file_is_native (data->file));
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED))
error_message (data->impl, _("The server could not be connected"),
error ? error->message : "");
GDK_THREADS_LEAVE ();
g_clear_error (&error);
g_object_unref (data->impl);
g_object_unref (data->file);
g_slice_free (ConnectData, data);
}
#endif
static void
connect_to (GtkFileChooserDefault *impl,
const gchar *address)
{
GFile *file = connect_parse_address (address);
if (file == NULL)
return;
#ifdef G_OS_WIN32
{
gchar *path = g_file_get_path (file);
/* \\server\share: the shell connects, asking for the name and the
* password where they are needed */
if (path && path[0] == '\\' && path[1] == '\\')
{
gchar **parts = g_strsplit (path + 2, "\\", 3);
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
HWND hwnd = NULL;
NETRESOURCEW resource = { 0 };
gchar *share;
gunichar2 *wshare;
DWORD result;
share = g_strdup_printf ("\\\\%s\\%s", parts[0] ? parts[0] : "",
parts[0] && parts[1] ? parts[1] : "");
wshare = g_utf8_to_utf16 (share, -1, NULL, NULL, NULL);
if (gtk_widget_get_realized (toplevel))
hwnd = GDK_WINDOW_HWND (toplevel->window);
resource.dwType = RESOURCETYPE_DISK;
resource.lpRemoteName = (wchar_t *) wshare;
set_busy_cursor (impl, TRUE);
result = WNetAddConnection3W (hwnd, &resource, NULL, NULL,
CONNECT_INTERACTIVE | CONNECT_TEMPORARY);
set_busy_cursor (impl, FALSE);
g_free (wshare);
g_free (share);
g_strfreev (parts);
if (result == NO_ERROR || result == ERROR_SESSION_CREDENTIAL_CONFLICT ||
result == ERROR_ALREADY_ASSIGNED || result == ERROR_DEVICE_ALREADY_REMEMBERED)
connect_show (impl, file, TRUE);
else if (result != ERROR_CANCELLED)
{
gchar *message = g_win32_error_message (result);
error_message (impl, _("The server could not be connected"), message);
g_free (message);
}
g_free (path);
g_object_unref (file);
return;
}
g_free (path);
connect_show (impl, file, FALSE);
}
#elif defined (GDK_WINDOWING_QUARTZ)
if (g_file_is_native (file))
connect_show (impl, file, FALSE);
else
{
gchar *uri = g_file_get_uri (file);
if (_gtk_quartz_connect_to_server (uri))
{
GVolumeMonitor *monitor = g_volume_monitor_get ();
connect_servers_add (file);
g_signal_handlers_disconnect_by_func (monitor, connect_mount_added, impl);
if (impl->connect_timeout)
g_source_remove (impl->connect_timeout);
else
g_object_ref (impl);
g_signal_connect (monitor, "mount-added", G_CALLBACK (connect_mount_added), impl);
impl->connect_timeout = gdk_threads_add_timeout_seconds (120, connect_waited, impl);
set_busy_cursor (impl, TRUE);
g_object_unref (monitor);
}
else
error_message (impl, _("The server could not be connected"), uri);
g_free (uri);
}
#else
{
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
GMountOperation *operation = gtk_mount_operation_new (GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL);
ConnectData *data = g_slice_new (ConnectData);
data->impl = g_object_ref (impl);
data->file = g_object_ref (file);
set_busy_cursor (impl, TRUE);
g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, operation, NULL,
connect_mounted, data);
g_object_unref (operation);
}
#endif
g_object_unref (file);
}
static void
connect_entry_changed (GtkEditable *entry,
GtkWidget *dialog)
{
const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry));
while (g_ascii_isspace (*text))
text++;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, *text != '\0');
}
static void
connect_response (GtkDialog *dialog,
gint response,
GtkFileChooserDefault *impl)
{
GtkWidget *combo = g_object_get_data (G_OBJECT (dialog), "gtk-connect-combo");
gchar *address = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)))));
gtk_widget_destroy (GTK_WIDGET (dialog));
impl->connect_dialog = NULL;
if (response == GTK_RESPONSE_ACCEPT)
connect_to (impl, address);
g_free (address);
/* the place is no folder to stay on */
shortcuts_find_current_folder (impl);
}
static void
connect_to_server_handler (GtkFileChooserDefault *impl)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl));
GtkWidget *dialog, *vbox, *hbox, *label, *combo, *entry, *help;
GString *examples;
gchar **servers, *markup;
gboolean have_examples;
gint i;
if (impl->connect_dialog)
{
gtk_window_present (GTK_WINDOW (impl->connect_dialog));
return;
}
dialog = gtk_dialog_new_with_buttons (_("Connect to Server"),
GTK_IS_WINDOW (toplevel) ? GTK_WINDOW (toplevel) : NULL,
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT |
GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
_("C_onnect"), GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT,
GTK_RESPONSE_CANCEL, -1);
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
impl->connect_dialog = dialog;
vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), vbox, TRUE, TRUE, 0);
hbox = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic (_("Server _Address:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
/* the servers used before */
combo = gtk_combo_box_text_new_with_entry ();
servers = connect_servers_load ();
for (i = 0; servers && servers[i] && i < 10; i++)
{
GFile *file = g_file_new_for_uri (servers[i]);
if (!g_file_is_native (file))
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), servers[i]);
g_object_unref (file);
}
g_strfreev (servers);
entry = gtk_bin_get_child (GTK_BIN (combo));
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
gtk_entry_set_width_chars (GTK_ENTRY (entry), 36);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
g_signal_connect (entry, "changed", G_CALLBACK (connect_entry_changed), dialog);
gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
g_object_set_data (G_OBJECT (dialog), I_("gtk-connect-combo"), combo);
/* what can be typed */
examples = g_string_new (NULL);
#ifdef G_OS_WIN32
g_string_append (examples, "\\\\server\\share\nsmb://server/share");
#elif defined (GDK_WINDOWING_QUARTZ)
g_string_append (examples, "smb://server/share\nafp://server/volume\nftp://server\nhttp://server/webdav");
#else
for (i = 0; i < G_N_ELEMENTS (connect_examples); i++)
if (connect_scheme_supported (connect_examples[i].scheme))
{
if (examples->len)
g_string_append_c (examples, '\n');
g_string_append (examples, connect_examples[i].example);
}
#endif
have_examples = examples->len > 0;
{
gchar *escaped = g_markup_escape_text (examples->str, -1);
/* Translators: above examples of server addresses */
markup = g_strdup_printf ("<small>%s\n%s</small>", _("For example:"), escaped);
g_free (escaped);
}
g_string_free (examples, TRUE);
help = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (help), markup);
gtk_misc_set_alignment (GTK_MISC (help), 0.0, 0.0);
gtk_label_set_selectable (GTK_LABEL (help), TRUE);
gtk_box_pack_start (GTK_BOX (vbox), help, FALSE, FALSE, 0);
gtk_widget_set_no_show_all (help, !have_examples);
g_free (markup);
g_signal_connect (dialog, "response", G_CALLBACK (connect_response), impl);
gtk_widget_show_all (dialog);
gtk_widget_grab_focus (entry);
}
static GdkPixbuf *
render_connect_icon (GtkFileChooserDefault *impl)
{
GtkIconTheme *theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (impl)));
GdkPixbuf *pixbuf;
pixbuf = gtk_icon_theme_load_icon (theme, "network-server", impl->list_view_icon_size, 0, NULL);
if (pixbuf == NULL)
pixbuf = gtk_icon_theme_load_icon (theme, "network-workgroup", impl->list_view_icon_size, 0, NULL);
if (pixbuf == NULL)
pixbuf = gtk_widget_render_icon (GTK_WIDGET (impl), GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU, NULL);
return pixbuf;
}
static void
shortcuts_append_connect (GtkFileChooserDefault *impl)
{
GdkPixbuf *pixbuf;
GtkTreeIter iter;
impl->has_connect = connect_to_server_possible ();
if (!impl->has_connect)
return;
pixbuf = render_connect_icon (impl);
gtk_list_store_insert (impl->shortcuts_model, &iter,
shortcuts_get_index (impl, SHORTCUTS_CONNECT));
gtk_list_store_set (impl->shortcuts_model, &iter,
SHORTCUTS_COL_PIXBUF, pixbuf,
SHORTCUTS_COL_PIXBUF_VISIBLE, TRUE,
SHORTCUTS_COL_NAME, _("Connect to Server…"),
SHORTCUTS_COL_DATA, NULL,
SHORTCUTS_COL_TYPE, SHORTCUT_TYPE_CONNECT,
SHORTCUTS_COL_REMOVABLE, FALSE,
-1);
if (pixbuf)
g_object_unref (pixbuf);
}
static void
shortcuts_activate_iter (GtkFileChooserDefault *impl,
GtkTreeIter *iter)
@ -16539,6 +17137,10 @@ shortcuts_activate_iter (GtkFileChooserDefault *impl,
{
operation_mode_set (impl, OPERATION_MODE_RECENT);
}
else if (shortcut_type == SHORTCUT_TYPE_CONNECT)
{
connect_to_server_handler (impl);
}
}
/* Handler for GtkWidget::key-press-event on the shortcuts list */

View file

@ -180,6 +180,8 @@ struct _GtkFileChooserDefault
GtkWidget *browse_shortcuts_popup_menu_unmount_item;
GtkWidget *browse_shortcuts_popup_menu_eject_item;
GtkCellRenderer *shortcuts_eject_renderer;
GtkWidget *connect_dialog;
guint connect_timeout;
/* the free space of a place, for its tooltip */
GFile *place_space_file;
@ -415,6 +417,7 @@ struct _GtkFileChooserDefault
guint has_home : 1;
guint has_desktop : 1;
guint has_search : 1;
guint has_connect : 1;
guint show_size_column : 1;
guint show_type_column : 1;
guint show_thumbnails : 1;

View file

@ -453,3 +453,20 @@ _gtk_quartz_trash_file (GFile *file,
return done;
}
/* Connect to Server on the Mac: the Finder connects (smb, afp, ftp, nfs,
* WebDAV), asking for the name and the password, and mounts the server
* into /Volumes */
gboolean
_gtk_quartz_connect_to_server (const gchar *uri)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSURL *url = [NSURL URLWithString: [NSString stringWithUTF8String: uri]];
gboolean done = FALSE;
if (url)
done = [[NSWorkspace sharedWorkspace] openURL: url];
[pool release];
return done;
}

View file

@ -42,6 +42,7 @@ void _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
gboolean _gtk_quartz_trash_file (GFile *file,
GFile **trashed,
GError **error);
gboolean _gtk_quartz_connect_to_server (const gchar *uri);
NSImage *_gtk_quartz_create_image_from_pixbuf (GdkPixbuf *pixbuf);

View file

@ -645,7 +645,7 @@ libgtk-win32-$(GTK_VER)-0.dll : $(gtk_SUBLIBS) gtk.def gtk-win32.res
$(CC) $(CFLAGS) -LD -Fm -Fe$@ $(gtk_SUBLIBS) gtk-win32.res \
$(GDK_LIBS) $(GDK_PIXBUF_LIBS) $(PANGO_LIBS) $(INTL_LIBS) $(GLIB_LIBS) $(GMODULE_LIBS) \
$(CAIRO_LIBS) $(PANGOCAIRO_LIBS) \
gdi32.lib user32.lib advapi32.lib wsock32.lib shell32.lib ole32.lib comdlg32.lib winspool.lib comctl32.lib \
gdi32.lib user32.lib advapi32.lib wsock32.lib shell32.lib ole32.lib comdlg32.lib winspool.lib comctl32.lib mpr.lib \
$(LDFLAGS) /implib:gtk-win32-$(GTK_VER).lib /def:gtk.def
gtk-win32-$(GTK_VER)s.lib : $(gtk_OBJECTS)

View file

@ -6484,3 +6484,35 @@ msgstr "_Trotzdem fortfahren"
#, c-format
msgid "%s are needed, %s are free. What fits can be copied anyway."
msgstr "%s werden gebraucht, %s sind frei. Was passt, kann trotzdem kopiert werden."
#: gtk/gtkfilechooserdefault.c
msgid "Connect to Server"
msgstr "Mit Server verbinden"
#: gtk/gtkfilechooserdefault.c
msgid "Connect to Server…"
msgstr "Mit Server verbinden …"
#: gtk/gtkfilechooserdefault.c
msgid "Server _Address:"
msgstr "Server_adresse:"
#: gtk/gtkfilechooserdefault.c
msgid "For example:"
msgstr "Zum Beispiel:"
#: gtk/gtkfilechooserdefault.c
msgid "The server could not be opened"
msgstr "Der Server konnte nicht geöffnet werden"
#: gtk/gtkfilechooserdefault.c
msgid "This program can only open local files, and the server has no local path here."
msgstr "Dieses Programm kann nur lokale Dateien öffnen, und der Server hat hier keinen lokalen Pfad."
#: gtk/gtkfilechooserdefault.c
msgid "The server could not be connected"
msgstr "Mit dem Server konnte keine Verbindung hergestellt werden"
#: gtk/gtkfilechooserdefault.c
msgid "C_onnect"
msgstr "_Verbinden"