Commit 463e8d1b authored by Cosimo Cecchi's avatar Cosimo Cecchi

places-sidebar: make sure to always notify when unmounting

When unmounting from the sidebar with an operation other than eject, we
still need to set up the progress notification, as some drives return
FALSE for can_eject.

https://bugzilla.redhat.com/show_bug.cgi?id=885133
parent e6b70a2c
......@@ -2028,11 +2028,25 @@ nautilus_file_operations_delete (GList *files,
typedef struct {
gboolean eject;
GMount *mount;
GMountOperation *mount_operation;
GtkWindow *parent_window;
NautilusUnmountCallback callback;
gpointer callback_data;
} UnmountData;
static void
unmount_data_free (UnmountData *data)
{
if (data->parent_window) {
g_object_remove_weak_pointer (G_OBJECT (data->parent_window),
(gpointer *) &data->parent_window);
}
g_clear_object (&data->mount_operation);
g_object_unref (data->mount);
g_free (data);
}
static void
unmount_mount_callback (GObject *source_object,
GAsyncResult *res,
......@@ -2073,14 +2087,8 @@ unmount_mount_callback (GObject *source_object,
if (error != NULL) {
g_error_free (error);
}
if (data->parent_window) {
g_object_remove_weak_pointer (G_OBJECT (data->parent_window),
(gpointer *) &data->parent_window);
}
g_object_unref (data->mount);
g_free (data);
unmount_data_free (data);
}
static void
......@@ -2088,7 +2096,11 @@ do_unmount (UnmountData *data)
{
GMountOperation *mount_op;
mount_op = gtk_mount_operation_new (data->parent_window);
if (data->mount_operation) {
mount_op = g_object_ref (data->mount_operation);
} else {
mount_op = gtk_mount_operation_new (data->parent_window);
}
if (data->eject) {
g_mount_eject_with_operation (data->mount,
0,
......@@ -2260,6 +2272,7 @@ empty_trash_for_unmount_done (gboolean success,
void
nautilus_file_operations_unmount_mount_full (GtkWindow *parent_window,
GMount *mount,
GMountOperation *mount_operation,
gboolean eject,
gboolean check_trash,
NautilusUnmountCallback callback,
......@@ -2277,6 +2290,9 @@ nautilus_file_operations_unmount_mount_full (GtkWindow *par
(gpointer *) &data->parent_window);
}
if (mount_operation) {
data->mount_operation = g_object_ref (mount_operation);
}
data->eject = eject;
data->mount = g_object_ref (mount);
......@@ -2302,13 +2318,7 @@ nautilus_file_operations_unmount_mount_full (GtkWindow *par
callback (callback_data);
}
if (data->parent_window) {
g_object_remove_weak_pointer (G_OBJECT (data->parent_window),
(gpointer *) &data->parent_window);
}
g_object_unref (data->mount);
g_free (data);
unmount_data_free (data);
return;
}
}
......@@ -2322,7 +2332,7 @@ nautilus_file_operations_unmount_mount (GtkWindow *parent_w
gboolean eject,
gboolean check_trash)
{
nautilus_file_operations_unmount_mount_full (parent_window, mount, eject,
nautilus_file_operations_unmount_mount_full (parent_window, mount, NULL, eject,
check_trash, NULL, NULL);
}
......
......@@ -107,6 +107,7 @@ void nautilus_file_operations_unmount_mount (GtkWindow *par
gboolean check_trash);
void nautilus_file_operations_unmount_mount_full (GtkWindow *parent_window,
GMount *mount,
GMountOperation *mount_operation,
gboolean eject,
gboolean check_trash,
NautilusUnmountCallback callback,
......
......@@ -1262,7 +1262,7 @@ nautilus_file_unmount (NautilusFile *file,
data->file = nautilus_file_ref (file);
data->callback = callback;
data->callback_data = callback_data;
nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, FALSE, TRUE, unmount_done, data);
nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, FALSE, TRUE, unmount_done, data);
} else if (callback) {
callback (file, NULL, NULL, callback_data);
}
......@@ -1296,7 +1296,7 @@ nautilus_file_eject (NautilusFile *file,
data->file = nautilus_file_ref (file);
data->callback = callback;
data->callback_data = callback_data;
nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, TRUE, TRUE, unmount_done, data);
nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, TRUE, TRUE, unmount_done, data);
} else if (callback) {
callback (file, NULL, NULL, callback_data);
}
......
......@@ -1974,14 +1974,56 @@ unmount_done (gpointer data)
g_object_unref (window);
}
static void
show_unmount_progress_cb (GMountOperation *op,
const gchar *message,
gint64 time_left,
gint64 bytes_left,
gpointer user_data)
{
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
if (bytes_left == 0) {
nautilus_application_notify_unmount_done (app, message);
} else {
nautilus_application_notify_unmount_show (app, message);
}
}
static void
show_unmount_progress_aborted_cb (GMountOperation *op,
gpointer user_data)
{
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
nautilus_application_notify_unmount_done (app, NULL);
}
static GMountOperation *
get_unmount_operation (NautilusPlacesSidebar *sidebar)
{
GMountOperation *mount_op;
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
g_signal_connect (mount_op, "show-unmount-progress",
G_CALLBACK (show_unmount_progress_cb), sidebar);
g_signal_connect (mount_op, "aborted",
G_CALLBACK (show_unmount_progress_aborted_cb), sidebar);
return mount_op;
}
static void
do_unmount (GMount *mount,
NautilusPlacesSidebar *sidebar)
{
GMountOperation *mount_op;
if (mount != NULL) {
nautilus_file_operations_unmount_mount_full (NULL, mount, FALSE, TRUE,
mount_op = get_unmount_operation (sidebar);
nautilus_file_operations_unmount_mount_full (NULL, mount, mount_op, FALSE, TRUE,
unmount_done,
g_object_ref (sidebar->window));
g_object_unref (mount_op);
}
}
......@@ -2012,30 +2054,6 @@ unmount_shortcut_cb (GtkMenuItem *item,
do_unmount_selection (sidebar);
}
static void
show_unmount_progress_cb (GMountOperation *op,
const gchar *message,
gint64 time_left,
gint64 bytes_left,
gpointer user_data)
{
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
if (bytes_left == 0) {
nautilus_application_notify_unmount_done (app, message);
} else {
nautilus_application_notify_unmount_show (app, message);
}
}
static void
show_unmount_progress_aborted_cb (GMountOperation *op,
gpointer user_data)
{
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
nautilus_application_notify_unmount_done (app, NULL);
}
static void
drive_eject_cb (GObject *source_object,
GAsyncResult *res,
......@@ -2126,9 +2144,8 @@ do_eject (GMount *mount,
GDrive *drive,
NautilusPlacesSidebar *sidebar)
{
GMountOperation *mount_op;
GMountOperation *mount_op = get_unmount_operation (sidebar);
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
if (mount != NULL) {
g_mount_eject_with_operation (mount, 0, mount_op, NULL, mount_eject_cb,
g_object_ref (sidebar->window));
......@@ -2140,10 +2157,6 @@ do_eject (GMount *mount,
g_object_ref (sidebar->window));
}
g_signal_connect (mount_op, "show-unmount-progress",
G_CALLBACK (show_unmount_progress_cb), sidebar);
g_signal_connect (mount_op, "aborted",
G_CALLBACK (show_unmount_progress_aborted_cb), sidebar);
g_object_unref (mount_op);
}
......@@ -2381,9 +2394,7 @@ stop_shortcut_cb (GtkMenuItem *item,
-1);
if (drive != NULL) {
GMountOperation *mount_op;
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
GMountOperation *mount_op = get_unmount_operation (sidebar);
g_drive_stop (drive, G_MOUNT_UNMOUNT_NONE, mount_op, NULL, drive_stop_cb,
g_object_ref (sidebar->window));
g_object_unref (mount_op);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment