diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2011-06-03 19:31:15 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2011-06-03 19:31:15 -0400 |
commit | f83bdf0081bfb5d6b8caad8848a267fecb95b85b (patch) | |
tree | a0a682698aa234fbd07ca6050773c836655e3852 | |
parent | e3f055c886e9db0c105de59e80573a9715c41060 (diff) | |
download | nautilus-f83bdf0081bfb5d6b8caad8848a267fecb95b85b.tar.gz |
connect-server: handle closing of the dialog while connecting
If we start a connect operation, but close the dialog before providing
the credential details, cancel the operation and hide the dialog,
instead of segfaulting.
The dialog will eventually be destroyed when the the mount operation
terminates (with error).
-rw-r--r-- | src/nautilus-connect-server-dialog.c | 29 | ||||
-rw-r--r-- | src/nautilus-connect-server-operation.c | 13 |
2 files changed, 37 insertions, 5 deletions
diff --git a/src/nautilus-connect-server-dialog.c b/src/nautilus-connect-server-dialog.c index f1aa337bb..46ecc00b4 100644 --- a/src/nautilus-connect-server-dialog.c +++ b/src/nautilus-connect-server-dialog.c @@ -73,6 +73,8 @@ struct _NautilusConnectServerDialogDetails { gboolean last_password_set; gulong password_sensitive_id; gboolean should_destroy; + + GCancellable *mount_cancellable; }; G_DEFINE_TYPE (NautilusConnectServerDialog, nautilus_connect_server_dialog, @@ -486,6 +488,8 @@ mount_enclosing_ready_cb (GObject *source, } } + g_clear_object (&dialog->details->mount_cancellable); + if (error != NULL) { g_error_free (error); } @@ -497,9 +501,11 @@ connect_dialog_present_uri_async (NautilusConnectServerDialog *self, { GMountOperation *op; + self->details->mount_cancellable = g_cancellable_new (); + op = nautilus_connect_server_operation_new (self); g_file_mount_enclosing_volume (location, - 0, op, NULL, + 0, op, self->details->mount_cancellable, mount_enclosing_ready_cb, self); g_object_unref (op); } @@ -636,7 +642,12 @@ connect_to_server_or_finish_fill (NautilusConnectServerDialog *dialog) static gboolean connect_dialog_abort_mount_operation (NautilusConnectServerDialog *dialog) { - if (dialog->details->fill_details_res != NULL) { + 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); @@ -648,10 +659,10 @@ connect_dialog_abort_mount_operation (NautilusConnectServerDialog *dialog) dialog->details->fill_operation = NULL; } - return TRUE; + retval = TRUE; } - return FALSE; + return retval; } static void @@ -659,6 +670,7 @@ connect_dialog_destroy (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)); } @@ -1205,6 +1217,15 @@ nautilus_connect_server_dialog_fill_details_async (NautilusConnectServerDialog * 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); diff --git a/src/nautilus-connect-server-operation.c b/src/nautilus-connect-server-operation.c index 19e2ac74a..8d3ead329 100644 --- a/src/nautilus-connect-server-operation.c +++ b/src/nautilus-connect-server-operation.c @@ -93,7 +93,7 @@ nautilus_connect_server_operation_set_property (GObject *object, switch (property_id) { case PROP_DIALOG: - self->details->dialog = g_value_get_object (value); + self->details->dialog = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -102,6 +102,16 @@ nautilus_connect_server_operation_set_property (GObject *object, } 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; @@ -110,6 +120,7 @@ nautilus_connect_server_operation_class_init (NautilusConnectServerOperationClas 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; |