summaryrefslogtreecommitdiff
path: root/src/caja-connect-server-dialog-main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/caja-connect-server-dialog-main.c')
-rw-r--r--src/caja-connect-server-dialog-main.c150
1 files changed, 31 insertions, 119 deletions
diff --git a/src/caja-connect-server-dialog-main.c b/src/caja-connect-server-dialog-main.c
index 44c57980..4c80fc16 100644
--- a/src/caja-connect-server-dialog-main.c
+++ b/src/caja-connect-server-dialog-main.c
@@ -22,6 +22,7 @@
*
* Authors:
* Vincent Untz <[email protected]>
+ * Cosimo Cecchi <[email protected]>
*/
#include <config.h>
@@ -38,10 +39,9 @@
#include <libcaja-private/caja-icon-names.h>
#include <libcaja-private/caja-global-preferences.h>
-#include "caja-window.h"
#include "caja-connect-server-dialog.h"
-static int open_dialogs;
+static GSimpleAsyncResult *display_location_res = NULL;
static void
main_dialog_destroyed (GtkWidget *widget,
@@ -53,117 +53,53 @@ main_dialog_destroyed (GtkWidget *widget,
gtk_main_quit ();
}
-static void
-error_dialog_destroyed (GtkWidget *widget,
- GtkWidget *main_dialog)
-{
- if (--open_dialogs <= 0)
- gtk_widget_destroy (main_dialog);
-}
-
-static void
-display_error_dialog (GError *error,
- const char *uri,
- GtkWidget *parent)
+gboolean
+caja_connect_server_dialog_display_location_finish (CajaConnectServerDialog *self,
+ GAsyncResult *res,
+ GError **error)
{
- GtkDialog *error_dialog;
- char *error_message;
-
- error_message = g_strdup_printf (_("Cannot display location \"%s\""),
- uri);
- error_dialog = eel_show_error_dialog (error_message,
- error->message,
- NULL);
-
- open_dialogs++;
-
- g_signal_connect (error_dialog, "destroy",
- G_CALLBACK (error_dialog_destroyed), parent);
-
- gtk_window_set_screen (GTK_WINDOW (error_dialog),
- gtk_widget_get_screen (parent));
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error)) {
+ return FALSE;
+ }
- g_free (error_message);
+ return TRUE;
}
-static void
-show_uri (const char *uri,
- GtkWidget *widget)
+void
+caja_connect_server_dialog_display_location_async (CajaConnectServerDialog *self,
+ CajaApplication *application,
+ GFile *location,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GError *error;
+ GError *error;
GdkAppLaunchContext *launch_context;
+ gchar *uri;
+
+ display_location_res = g_simple_async_result_new (G_OBJECT (self),
+ callback, user_data,
+ caja_connect_server_dialog_display_location_async);
+ error = NULL;
+ uri = g_file_get_uri (location);
launch_context = gdk_app_launch_context_new ();
gdk_app_launch_context_set_screen (launch_context,
- gtk_widget_get_screen (widget));
+ gtk_widget_get_screen (GTK_WIDGET (self)));
- error = NULL;
g_app_info_launch_default_for_uri (uri,
G_APP_LAUNCH_CONTEXT (launch_context),
&error);
g_object_unref (launch_context);
- if (error)
- {
- display_error_dialog (error, uri, widget);
- g_error_free (error);
- }
- else
- {
- /* everything is OK, destroy the main dialog and quit */
- gtk_widget_destroy (widget);
- }
-}
-
-static void
-mount_enclosing_ready_cb (GFile *location,
- GAsyncResult *res,
- GtkWidget *widget)
-{
- char *uri;
- gboolean success;
- GError *error = NULL;
-
- uri = g_file_get_uri (location);
- success = g_file_mount_enclosing_volume_finish (location,
- res, &error);
-
- if (success ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED))
- {
- /* volume is mounted, show it */
- show_uri (uri, widget);
- }
- else
- {
- display_error_dialog (error, uri, widget);
- }
-
- if (error)
- {
+ 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_object_unref (location);
- g_free (uri);
-}
-
-void
-caja_connect_server_dialog_present_uri (CajaApplication *application,
- GFile *location,
- GtkWidget *widget)
-{
- GMountOperation *op;
-
- op = gtk_mount_operation_new (GTK_WINDOW (widget));
- g_mount_operation_set_password_save (op, G_PASSWORD_SAVE_FOR_SESSION);
- g_file_mount_enclosing_volume (location,
- 0, op,
- NULL,
- (GAsyncReadyCallback) mount_enclosing_ready_cb,
- widget);
- g_object_unref (op);
+ g_object_unref (display_location_res);
+ display_location_res = NULL;
}
int
@@ -171,26 +107,16 @@ main (int argc, char *argv[])
{
GtkWidget *dialog;
GOptionContext *context;
- const char **args;
- GFile *location;
GError *error;
- const GOptionEntry options[] =
- {
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("[URI]") },
- { NULL }
- };
bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- args = NULL;
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_add_main_entries (context, options, GETTEXT_PACKAGE);
-
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
@@ -208,22 +134,8 @@ main (int argc, char *argv[])
gtk_window_set_default_icon_name (CAJA_ICON_FOLDER);
+ dialog = caja_connect_server_dialog_new (NULL);
- /* command line arguments, null terminated array */
- location = NULL;
- if (args)
- {
- location = g_file_new_for_commandline_arg (*args);
- }
-
- dialog = caja_connect_server_dialog_new (NULL, location);
-
- if (location)
- {
- g_object_unref (location);
- }
-
- open_dialogs = 0;
g_signal_connect (dialog, "destroy",
G_CALLBACK (main_dialog_destroyed), NULL);