1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /* nautilus-connect-server-main.c - Start the "Connect to Server" dialog.
6 * Copyright (C) 2005 Vincent Untz
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; see the file COPYING. If not,
20 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 * Vincent Untz <vincent@vuntz.net>
29 #include <glib/gi18n.h>
31 #include <gtk/gtkmain.h>
32 #include <gtk/gtkwidget.h>
34 #include <libgnome/gnome-program.h>
35 #include <libgnomeui/gnome-ui-init.h>
36 #include <libgnomeui/gnome-authentication-manager.h>
38 #include <eel/eel-app-launch-context.h>
39 #include <eel/eel-preferences.h>
40 #include <eel/eel-stock-dialogs.h>
41 #include <eel/eel-mount-operation.h>
43 #include <libnautilus-private/nautilus-icon-names.h>
45 #include "nautilus-window.h"
46 #include "nautilus-connect-server-dialog.h"
48 static int open_dialogs
;
51 main_dialog_destroyed (GtkWidget
*widget
,
54 /* this only happens when user clicks "cancel"
55 * on the main dialog or when we are all done.
61 error_dialog_destroyed (GtkWidget
*widget
,
62 GtkWidget
*main_dialog
)
64 if (--open_dialogs
<= 0)
65 gtk_widget_destroy (main_dialog
);
69 display_error_dialog (GError
*error
,
73 GtkDialog
*error_dialog
;
76 error_message
= g_strdup_printf (_("Can't display location \"%s\""),
78 error_dialog
= eel_show_error_dialog (error_message
,
84 g_signal_connect (error_dialog
, "destroy",
85 G_CALLBACK (error_dialog_destroyed
), parent
);
87 gtk_window_set_screen (GTK_WINDOW (error_dialog
),
88 gtk_widget_get_screen (parent
));
90 g_free (error_message
);
94 show_uri (const char *uri
,
98 EelAppLaunchContext
*launch_context
;
100 launch_context
= eel_app_launch_context_new ();
101 eel_app_launch_context_set_screen (launch_context
,
102 gtk_widget_get_screen (widget
));
105 g_app_info_launch_default_for_uri (uri
,
106 G_APP_LAUNCH_CONTEXT (launch_context
),
109 g_object_unref (launch_context
);
112 display_error_dialog (error
, uri
, widget
);
113 g_error_free (error
);
115 /* everything is OK, destroy the main dialog and quit */
116 gtk_widget_destroy (widget
);
121 mount_enclosing_ready_cb (GFile
*location
,
126 GError
*error
= NULL
;
128 g_file_mount_enclosing_volume_finish (location
,
130 uri
= g_file_get_uri (location
);
132 display_error_dialog (error
, uri
, widget
);
134 /* volume is mounted, show it */
135 show_uri (uri
, widget
);
136 g_object_unref (location
);
142 nautilus_connect_server_dialog_present_uri (NautilusApplication
*application
,
148 op
= eel_mount_operation_new (GTK_WINDOW (widget
));
149 g_file_mount_enclosing_volume (location
,
152 (GAsyncReadyCallback
) mount_enclosing_ready_cb
,
157 main (int argc
, char *argv
[])
159 GnomeProgram
*program
;
161 GOptionContext
*context
;
164 const GOptionEntry options
[] = {
165 { G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_STRING_ARRAY
, &args
, NULL
, N_("[URI]") },
169 bindtextdomain (GETTEXT_PACKAGE
, GNOMELOCALEDIR
);
170 bind_textdomain_codeset (GETTEXT_PACKAGE
, "UTF-8");
171 textdomain (GETTEXT_PACKAGE
);
174 /* Translators: This is the --help description gor the connect to server app,
175 the initial newlines are between the command line arg and the description */
176 context
= g_option_context_new (N_("\n\nAdd connect to server mount"));
177 g_option_context_add_main_entries (context
, options
, GETTEXT_PACKAGE
);
179 g_option_context_set_translation_domain(context
, GETTEXT_PACKAGE
);
181 program
= gnome_program_init ("nautilus-connect-server", VERSION
,
182 LIBGNOMEUI_MODULE
, argc
, argv
,
183 GNOME_PARAM_GOPTION_CONTEXT
, context
,
186 gnome_authentication_manager_init ();
188 eel_preferences_init ("/apps/nautilus");
190 gtk_window_set_default_icon_name (NAUTILUS_ICON_FOLDER
);
193 /* command line arguments, null terminated array */
196 location
= g_file_new_for_commandline_arg (*args
);
199 dialog
= nautilus_connect_server_dialog_new (NULL
, location
);
202 g_object_unref (location
);
206 g_signal_connect (dialog
, "destroy",
207 G_CALLBACK (main_dialog_destroyed
), NULL
);
209 gtk_widget_show (dialog
);