summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@tbzatek.englab.brq.redhat.com>2009-02-03 18:17:50 +0100
committerTomas Bzatek <tbzatek@tbzatek.englab.brq.redhat.com>2009-02-03 18:17:50 +0100
commit303c8216dc6efaef7af0823ee0754fbfeb719989 (patch)
tree0279fbe740d734fe6c68f7509ccbfe2e17e51fbf /src
parentb7a646451fe20eabbdfe076d13117703d7d8b9c3 (diff)
downloadnautilus-gdu-303c8216dc6efaef7af0823ee0754fbfeb719989.tar.gz
nautilus-gdu-303c8216dc6efaef7af0823ee0754fbfeb719989.tar.xz
nautilus-gdu-303c8216dc6efaef7af0823ee0754fbfeb719989.zip
Add support for operation cancellation
Diffstat (limited to 'src')
-rw-r--r--src/nautilus-gdu-window.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/nautilus-gdu-window.c b/src/nautilus-gdu-window.c
index 0e193de..a0821f0 100644
--- a/src/nautilus-gdu-window.c
+++ b/src/nautilus-gdu-window.c
@@ -67,6 +67,7 @@ typedef struct {
GduPool *pool;
gboolean job_running;
+ gboolean job_cancelled;
PolKitAction *pk_unmount_action;
PolKitGnomeAction *unmount_action;
@@ -290,6 +291,7 @@ update_ui_progress (FormatDialogPrivate *priv,
if (working) {
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (priv->progress_bar), NULL);
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->progress_bar), 0.0);
+ gtk_button_set_label (GTK_BUTTON (priv->close_button), GTK_STOCK_STOP);
gtk_widget_show_all (priv->progress_bar_box);
if (data) {
data->job_handler_id = g_signal_connect (priv->presentable, "job-changed", G_CALLBACK (presentable_job_changed), data);
@@ -324,6 +326,7 @@ update_ui_progress (FormatDialogPrivate *priv,
}
}
gtk_widget_hide_all (priv->progress_bar_box);
+ gtk_button_set_label (GTK_BUTTON (priv->close_button), GTK_STOCK_CLOSE);
}
gtk_widget_set_sensitive (priv->controls_box, ! working);
gtk_widget_set_sensitive (priv->partition_label, ! working);
@@ -760,6 +763,9 @@ part_modify_action_callback (GtkAction *action, gpointer user_data)
g_return_if_fail (data != NULL);
g_print ("part_modify_action_callback\n");
+ if (data->priv->job_cancelled)
+ return;
+
/* DK is buggy, passing a label string causes the operation to fail */
gdu_device_op_partition_modify (data->device, data->recommended_part_type, NULL /* data->fslabel */, NULL, modify_partition_completed, data);
}
@@ -820,7 +826,7 @@ format_action_completed (GduDevice *device,
scheme = gdu_device_partition_get_scheme (device);
// g_print ("format_action_completed: scheme = %s\n", scheme);
/* TODO: extend to other partition types once this feature is working in DK */
- if (strcmp (scheme, "mbr") == 0) {
+ if (data->priv->job_cancelled && strcmp (scheme, "mbr") == 0) {
part_type = gdu_device_partition_get_type (device);
data->recommended_part_type = get_part_type_for_fs (data->fstype);
g_print ("format_action_completed: part_type = %s, recommended_part_type = %s\n", part_type, data->recommended_part_type);
@@ -848,6 +854,9 @@ format_action_callback (GtkAction *action, gpointer user_data)
g_return_if_fail (data != NULL);
g_print ("format_action_callback\n");
+ if (data->priv->job_cancelled)
+ return;
+
gdu_device_op_filesystem_create (data->device,
data->fstype,
data->fslabel,
@@ -887,7 +896,9 @@ unmount_show_busy (gpointer user_data)
if (gdu_util_dialog_show_filesystem_busy (GTK_WIDGET (data->priv->dialog), data->priv->presentable)) {
/* user managed to kill all applications; try again */
- gtk_action_activate (GTK_ACTION (data->priv->unmount_action));
+ if (! data->priv->job_cancelled) {
+ gtk_action_activate (GTK_ACTION (data->priv->unmount_action));
+ }
}
else {
/* cancel the whole operation */
@@ -928,6 +939,8 @@ unmount_action_completed (GduDevice *device,
{
/* TODO: maybe perform a refresh? */
g_print (" formatting...\n");
+ if (data->priv->job_cancelled)
+ return;
gtk_action_activate (GTK_ACTION (data->priv->format_action));
}
}
@@ -940,6 +953,9 @@ unmount_action_callback (GtkAction *action, gpointer user_data)
g_return_if_fail (data != NULL);
g_print ("unmount_action_callback\n");
+ if (data->priv->job_cancelled)
+ return;
+
gdu_device_op_filesystem_unmount (data->device, unmount_action_completed, data);
}
@@ -977,6 +993,7 @@ do_format (FormatDialogPrivate *priv)
GduKnownFilesystem *kfs;
+ priv->job_cancelled = FALSE;
data = g_new0 (FormatProcessData, 1);
data->priv = priv;
primary = NULL;
@@ -1137,6 +1154,24 @@ presentable_changed (GduPresentable *presentable, FormatDialogPrivate *priv)
}
static void
+cancel_operation (FormatDialogPrivate *priv)
+{
+ GduDevice *device;
+
+ g_return_if_fail (priv != NULL);
+ g_return_if_fail (priv->job_running == TRUE);
+ g_return_if_fail (priv->presentable != NULL);
+ g_warning ("Cancelling...\n");
+
+ priv->job_cancelled = TRUE;
+ device = gdu_presentable_get_device (priv->presentable);
+
+ g_return_if_fail (device != NULL);
+ gdu_device_op_cancel_job (device, NULL, NULL);
+ g_object_unref (device);
+}
+
+static void
format_dialog_got_response (GtkDialog *dialog,
gint response_id,
FormatDialogPrivate *priv)
@@ -1150,8 +1185,13 @@ format_dialog_got_response (GtkDialog *dialog,
update_ui (priv);
}
else {
- /* destroy the window and unref the presentable */
- nautilus_gdu_destroy (priv);
+ if (priv->job_running) {
+ cancel_operation (priv);
+ }
+ else {
+ /* destroy the window and unref the presentable */
+ nautilus_gdu_destroy (priv);
+ }
}
}