[gnome-disk-utility] Rework formatting tool so it's simpler and easier to use



commit 2caa1743c2d171776c70421e7025e53772fccd5d
Author: David Zeuthen <davidz redhat com>
Date:   Wed Jun 17 17:34:13 2009 -0400

    Rework formatting tool so it's simpler and easier to use
    
    Screenshots:
    
     http://people.freedesktop.org/~david/gdu-nformat-1.png
     http://people.freedesktop.org/~david/gdu-nformat-2.png
     http://people.freedesktop.org/~david/gdu-nformat-3.png

 src/format-tool/gdu-format-dialog.c          |   97 ++++------
 src/format-tool/gdu-format-progress-dialog.c |    3 +
 src/format-tool/gdu-format-tool.c            |  264 ++++++++++++++++++++++++--
 src/nautilus-extension/nautilus-gdu.c        |   59 +------
 4 files changed, 290 insertions(+), 133 deletions(-)
---
diff --git a/src/format-tool/gdu-format-dialog.c b/src/format-tool/gdu-format-dialog.c
index 7c24284..d8d86e4 100644
--- a/src/format-tool/gdu-format-dialog.c
+++ b/src/format-tool/gdu-format-dialog.c
@@ -258,6 +258,15 @@ on_combo_box_changed (GtkWidget *combo_box,
         gtk_entry_set_max_length (GTK_ENTRY (dialog->priv->fs_label_entry), max_label_len);
 }
 
+static void
+on_fs_label_entry_activated (GtkWidget *combo_box,
+                             gpointer   user_data)
+{
+        GduFormatDialog *dialog = GDU_FORMAT_DIALOG (user_data);
+
+        gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
@@ -289,47 +298,17 @@ gdu_format_dialog_constructed (GObject *object)
         gint row;
         GduPool *pool;
         GduDevice *device;
-        GduPresentable *toplevel;
-        gchar *drive_name;
-        gchar *name;
-        gchar *primary;
-        gchar *secondary;
         gboolean ret;
         GtkWidget *align;
+        gchar *s;
 
-        toplevel = NULL;
-        name = NULL;
-        drive_name = NULL;
-        primary = NULL;
-        secondary = NULL;
         ret = FALSE;
 
         pool = gdu_presentable_get_pool (GDU_PRESENTABLE (dialog->priv->volume));
         device = gdu_presentable_get_device (GDU_PRESENTABLE (dialog->priv->volume));
-        name = gdu_presentable_get_name (GDU_PRESENTABLE (dialog->priv->volume));
-        toplevel = gdu_presentable_get_toplevel (GDU_PRESENTABLE (dialog->priv->volume));
-        if (toplevel != NULL && GDU_IS_DRIVE (toplevel)) {
-                drive_name = gdu_presentable_get_name (toplevel);
-        }
 
         pixbuf = gdu_util_get_pixbuf_for_presentable (GDU_PRESENTABLE (dialog->priv->volume), GTK_ICON_SIZE_DIALOG);
 
-        primary = g_strconcat ("<big><big><b>",
-                               _("Are you sure you want to format the volume?"),
-                               "</b></big></big>", NULL);
-        if (drive_name != NULL) {
-                secondary = g_strdup_printf (_("You are about to format the volume \"%s\" on the drive \"%s\" (%s). "
-                                               "All existing data will be irrevocably erased."),
-                                             name,
-                                             drive_name,
-                                             gdu_device_get_device_file (device));
-        } else {
-                secondary = g_strdup_printf (_("You are about to format the volume \"%s\" (%s). "
-                                               "All existing data will be irrevocably erased."),
-                                             name,
-                                             gdu_device_get_device_file (device));
-        }
-
         gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
         gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
         gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 0);
@@ -342,23 +321,22 @@ gdu_format_dialog_constructed (GObject *object)
 
         gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
         button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+                                        /* Translators: Format is used as a verb here */
                                         _("_Format"),
                                         GTK_RESPONSE_OK);
-        icon = gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
-        gtk_button_set_image (GTK_BUTTON (button), icon);
         button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Disk _Utility"), GTK_RESPONSE_ACCEPT);
         icon = gtk_image_new_from_icon_name ("palimpsest", GTK_ICON_SIZE_BUTTON);
         gtk_button_set_image (GTK_BUTTON (button), icon);
         gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
                                             button,
                                             TRUE);
-        gtk_widget_set_tooltip_text (button, _("Open volume in Palimpsest Disk Utility"));
-        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+        gtk_widget_set_tooltip_text (button, _("Use Disk Utility to format volume"));
+        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
         content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
         gtk_container_set_border_width (GTK_CONTAINER (content_area), 10);
 
-        /*  icon and primary+secondary labels  */
+        /*  icon and text labels  */
         hbox = gtk_hbox_new (FALSE, 0);
         gtk_box_pack_start (GTK_BOX (content_area), hbox, FALSE, TRUE, 0);
 
@@ -373,18 +351,6 @@ gdu_format_dialog_constructed (GObject *object)
         vbox2 = gtk_vbox_new (FALSE, 12);
         gtk_container_add (GTK_CONTAINER (align), vbox2);
 
-        label = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label), primary);
-        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-        gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
-
-        label = gtk_label_new (NULL);
-        gtk_label_set_markup (GTK_LABEL (label), secondary);
-        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-        gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-        gtk_box_pack_start (GTK_BOX (vbox2), label, FALSE, TRUE, 0);
-
         row = 0;
 
         table = gtk_table_new (2, 2, FALSE);
@@ -394,7 +360,7 @@ gdu_format_dialog_constructed (GObject *object)
 
         /*  filesystem type  */
         label = gtk_label_new (NULL);
-        gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
         gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("_Type:"));
         gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
                           GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
@@ -412,13 +378,13 @@ gdu_format_dialog_constructed (GObject *object)
         dialog->priv->fs_type = g_strdup ("vfat");
         dialog->priv->encrypt = FALSE;
         gtk_table_attach (GTK_TABLE (table), combo_box, 1, 2, row, row +1,
-                          GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
         gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo_box);
         row++;
 
         /*  filesystem label  */
         label = gtk_label_new (NULL);
-        gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
         gtk_label_set_markup_with_mnemonic (GTK_LABEL (label), _("_Name:"));
         gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row + 1,
                           GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
@@ -426,24 +392,47 @@ gdu_format_dialog_constructed (GObject *object)
         /* Translators: Keep length of translation of "New Volume" to less than 16 characters */
         gtk_entry_set_text (GTK_ENTRY (entry), _("New Volume"));
         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row + 1,
-                          GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
+                          GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 2);
         gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
         dialog->priv->fs_label_entry = entry;
         row++;
 
+        hbox = gtk_hbox_new (FALSE, 6);
+        gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
+
+        image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
+        gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+	label = gtk_label_new (NULL);
+        s = g_strconcat ("<i>",
+                         _("Warning: All data on the volume will be irrevocably lost."),
+                         "</i>",
+                         NULL);
+        gtk_label_set_markup (GTK_LABEL (label), s);
+        g_free (s);
+	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+
         g_signal_connect (combo_box,
                           "changed",
                           G_CALLBACK (on_combo_box_changed),
                           dialog);
 
+        g_signal_connect (dialog->priv->fs_label_entry,
+                          "activate",
+                          G_CALLBACK (on_fs_label_entry_activated),
+                          dialog);
+
         /* nuke dialog if device is yanked */
         g_signal_connect (dialog->priv->volume,
                           "removed",
                           G_CALLBACK (on_presentable_removed),
                           dialog);
 
-        gtk_widget_grab_focus (entry);
-        gtk_editable_select_region (GTK_EDITABLE (entry), 0, 1000);
+        gtk_widget_grab_focus (dialog->priv->fs_label_entry);
+        gtk_editable_select_region (GTK_EDITABLE (dialog->priv->fs_label_entry), 0, 1000);
 
         if (G_OBJECT_CLASS (gdu_format_dialog_parent_class)->constructed != NULL)
                 G_OBJECT_CLASS (gdu_format_dialog_parent_class)->constructed (object);
diff --git a/src/format-tool/gdu-format-progress-dialog.c b/src/format-tool/gdu-format-progress-dialog.c
index 63de555..6d29cda 100644
--- a/src/format-tool/gdu-format-progress-dialog.c
+++ b/src/format-tool/gdu-format-progress-dialog.c
@@ -150,6 +150,9 @@ gdu_format_progress_dialog_constructed (GObject *object)
 
 
         gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+        gtk_dialog_add_button (GTK_DIALOG (dialog),
+                               GTK_STOCK_CANCEL,
+                               GTK_RESPONSE_CANCEL);
 
         gtk_window_set_title (GTK_WINDOW (dialog), "");
         gtk_window_set_icon_name (GTK_WINDOW (dialog), "nautilus-gdu");
diff --git a/src/format-tool/gdu-format-tool.c b/src/format-tool/gdu-format-tool.c
index a12e846..19722f9 100644
--- a/src/format-tool/gdu-format-tool.c
+++ b/src/format-tool/gdu-format-tool.c
@@ -42,6 +42,7 @@ typedef struct
         GMainLoop *loop;
         GError    *error;
         gchar     *mount_point;
+        gboolean   format_in_progress;
 } FormatData;
 
 static gboolean
@@ -131,6 +132,44 @@ static GOptionEntry entries[] = {
         { NULL }
 };
 
+typedef struct
+{
+        GMainLoop *loop;
+        GError    *error;
+} UnmountData;
+
+static void
+unmount_cb (GObject      *source_object,
+            GAsyncResult *res,
+            gpointer      user_data)
+{
+        GMount *mount = G_MOUNT (source_object);
+        UnmountData *data = user_data;
+
+        g_mount_unmount_finish (mount, res, &data->error);
+
+        g_main_loop_quit (data->loop);
+}
+
+static void
+on_progress_dialog_response (GtkDialog *dialog,
+                             gint       response_id,
+                             gpointer   user_data)
+{
+        FormatData *data = user_data;
+
+        data->error = g_error_new (G_IO_ERROR, G_IO_ERROR_CANCELLED, _("Operation was cancelled"));
+        g_main_loop_quit (data->loop);
+}
+
+static gboolean
+on_grace_timeout (gpointer user_data)
+{
+        FormatData *data = user_data;
+        g_main_loop_quit (data->loop);
+        return FALSE;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -138,8 +177,11 @@ main (int argc, char *argv[])
         GError *error;
         GduPool *pool;
         GduDevice *device;
+        GduDevice *device_to_unmount;
         GduDevice *device_to_mount;
         GduPresentable *volume;
+        gchar *volume_name;
+        gchar *confirmation_secondary;
         GtkWidget *dialog;
         gint response;
         gchar *fs_type;
@@ -149,17 +191,45 @@ main (int argc, char *argv[])
         gboolean save_passphrase_in_keyring;
         gboolean save_passphrase_in_keyring_session;
         GMainLoop *loop;
+        GVolumeMonitor *gvolume_monitor;
+        GList *l;
+        GList *gvolumes;
+        GVolume *gvolume;
+        GMount *gmount;
+        gboolean take_ownership;
+        FormatData *format_data;
+        GduPresentable *toplevel;
+        gchar *drive_name;
+        gchar *format_desc;
+        gchar *formatting_desc;
+        gchar *size_str;
+        gint grace_timeout_id;
 
         ret = 1;
         pool = NULL;
         device = NULL;
+        device_to_unmount = NULL;
         device_to_mount = NULL;
         volume = NULL;
+        volume_name = NULL;
+        confirmation_secondary = NULL;
         dialog = NULL;
         fs_type = NULL;
         fs_label = NULL;
         passphrase = NULL;
         loop = NULL;
+        volume = NULL;
+        gmount = NULL;
+        gvolume_monitor = NULL;
+        gvolumes = NULL;
+        gvolume = NULL;
+        gmount = NULL;
+        format_data = NULL;
+        toplevel = NULL;
+        drive_name = NULL;
+        format_desc = NULL;
+        formatting_desc = NULL;
+        size_str = NULL;
 
         g_thread_init (NULL);
 
@@ -198,13 +268,68 @@ main (int argc, char *argv[])
                 goto out;
         }
 
+        /* if the user specified a luks device, find the slave backing device */
+        if (gdu_device_is_luks_cleartext (device)) {
+                const gchar *slave;
+                slave = gdu_device_luks_cleartext_get_slave (device);
+                g_object_ref (device);
+                device = gdu_pool_get_by_object_path (pool, slave);
+                /* don't support LUKS in LUKS... */
+                g_assert (!gdu_device_is_luks_cleartext (device));
+        }
+
         volume = gdu_pool_get_volume_by_device (pool, device);
         if (volume == NULL) {
                 g_printerr ("%s is not a volume\n", device_file);
                 goto out;
         }
+        volume_name = gdu_presentable_get_name (volume);
+
+        toplevel = gdu_presentable_get_toplevel (GDU_PRESENTABLE (volume));
+        if (toplevel != NULL && GDU_IS_DRIVE (toplevel)) {
+                drive_name = gdu_presentable_get_name (toplevel);
+        }
+        size_str = gdu_util_get_size_for_display (gdu_device_get_size (device), FALSE);
+
+        if (drive_name != NULL) {
+                if (gdu_device_is_partition (device)) {
+                        /* Translators: First argument is the partition number, second argument is the drive name,
+                         * third argument is the size (e.g. 10 GB)
+                         */
+                        format_desc = g_strdup_printf (_("Format partition %d of %s (%s)"),
+                                                       gdu_device_partition_get_number (device),
+                                                       drive_name,
+                                                       size_str);
+                        /* Translators: First argument is the partition number, second argument is the drive name,
+                         * third argument is the size (e.g. 10 GB)
+                         */
+                        formatting_desc = g_strdup_printf (_("Formatting partition %d of %s (%s)"),
+                                                           gdu_device_partition_get_number (device),
+                                                           drive_name,
+                                                           size_str);
+                } else {
+                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
+                        format_desc = g_strdup_printf (_("Format %s (%s)"),
+                                                       drive_name,
+                                                       size_str);
+                        /* Translators: First argument is the drive name, second argument is the size (e.g. 10 GB) */
+                        formatting_desc = g_strdup_printf (_("Formatting %s (%s)"),
+                                                           drive_name,
+                                                           size_str);
+                }
+        } else {
+                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
+                format_desc = g_strdup_printf (_("Format %s Volume (%s)"),
+                                               size_str,
+                                               gdu_device_get_device_file (device));
+                /* Translators: First argument is the size (e.g. 10 GB), second is the device (e.g. /dev/md0) */
+                formatting_desc = g_strdup_printf (_("Formatting %s Volume (%s)"),
+                                                   size_str,
+                                                   gdu_device_get_device_file (device));
+        }
 
         dialog = gdu_format_dialog_new (NULL, GDU_VOLUME (volume));
+        gtk_window_set_title (GTK_WINDOW (dialog), format_desc);
         gtk_widget_show_all (dialog);
 
         response = gtk_dialog_run (GTK_DIALOG (dialog));
@@ -230,6 +355,7 @@ main (int argc, char *argv[])
         gtk_widget_destroy (dialog);
         dialog = NULL;
 
+        /* Ask for passphrase if needed */
         passphrase = NULL;
         save_passphrase_in_keyring = FALSE;
         save_passphrase_in_keyring_session = FALSE;
@@ -241,36 +367,113 @@ main (int argc, char *argv[])
                         goto out;
         }
 
-        gboolean take_ownership;
-        FormatData data;
-
         take_ownership = (g_strcmp0 (fs_type, "vfat") != 0);
 
-        data.loop = loop;
-        data.error = NULL;
+
+        format_data = g_new0 (FormatData, 1);
+        format_data->loop = loop;
+        format_data->error = NULL;
+
         dialog = gdu_format_progress_dialog_new (NULL,
                                                  device,
-                                                 _("Formatting volume..."));
+                                                 _("Preparing..."));
+        gtk_window_set_title (GTK_WINDOW (dialog), formatting_desc);
         gtk_widget_show_all (dialog);
+        g_signal_connect (dialog, "response", G_CALLBACK (on_progress_dialog_response), format_data);
+
+        /* first a small 2.5 sec window to allow the user to cancel before initiating */
+        grace_timeout_id = g_timeout_add (2500, on_grace_timeout, format_data);
+        g_main_loop_run (loop);
+        g_source_remove (grace_timeout_id);
+        if (format_data->error != NULL &&
+            format_data->error->domain == G_IO_ERROR &&
+            format_data->error->code == G_IO_ERROR_CANCELLED) {
+                /* cancelled already, we are done */
+                goto out;
+        }
+
+        /* then unmount the mount if needed; we use GIO for this to handle tearing
+         * down LUKS; first determine the device to unmount
+         */
+        if (gdu_device_is_luks (device)) {
+                const gchar *holder;
+                holder = gdu_device_luks_get_holder (device);
+                device_to_unmount = gdu_pool_get_by_object_path (pool, holder);
+        } else {
+                device_to_unmount = g_object_ref (device);
+        }
+        g_assert (device_to_unmount != NULL);
+        gvolume_monitor = g_volume_monitor_get ();
+        gvolumes = g_volume_monitor_get_volumes (gvolume_monitor);
+        for (l = gvolumes; l != NULL; l = l->next) {
+                GVolume *v = G_VOLUME (l->data);
+                if (g_strcmp0 (g_volume_get_identifier (v, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE),
+                               gdu_device_get_device_file (device_to_unmount)) == 0) {
+                        gvolume = g_object_ref (v);
+                        break;
+                }
+        }
+        if (gvolume != NULL) {
+                gmount = g_volume_get_mount (gvolume);
+                if (gmount != NULL) {
+                        gdu_format_progress_dialog_set_text (GDU_FORMAT_PROGRESS_DIALOG (dialog),
+                                                             _("Unmounting..."));
+
+                        g_mount_unmount (gmount,
+                                         G_MOUNT_UNMOUNT_NONE,
+                                         NULL,
+                                         unmount_cb,
+                                         format_data);
+                        g_main_loop_run (format_data->loop);
+
+                        if (format_data->error != NULL) {
+                                gchar *primary;
+
+                                primary = g_strdup_printf (_("Unable to format '%s'"), volume_name);
+                                show_error_dialog (NULL,
+                                                   primary,
+                                                   format_data->error->message);
+
+                                g_error_free (format_data->error);
+                                g_free (primary);
+                                goto out;
+                        }
+                }
+        }
+
+        /* and now, kick off the operation */
+        gdu_format_progress_dialog_set_text (GDU_FORMAT_PROGRESS_DIALOG (dialog),
+                                             _("Formatting..."));
         gdu_device_op_filesystem_create (device,
                                          fs_type,
                                          fs_label,
                                          passphrase,
                                          take_ownership,
                                          fs_create_cb,
-                                         &data);
+                                         format_data);
+ again:
         g_main_loop_run (loop);
-        if (data.error != NULL) {
+        if (format_data->error != NULL) {
                 gtk_widget_destroy (dialog);
                 dialog = NULL;
 
-                /* TODO: we could handle things like GDU_ERROR_BUSY here, e.g. unmount
-                 *       and/or tear down LUKS mapping
-                 */
-                show_error_dialog (NULL,
-                                   _("Error creating filesystem"),
-                                   data.error->message);
-                g_error_free (data.error);
+                if (format_data->error->domain == G_IO_ERROR &&
+                    format_data->error->code == G_IO_ERROR_CANCELLED) {
+                        gdu_format_progress_dialog_set_text (GDU_FORMAT_PROGRESS_DIALOG (dialog),
+                                                             _("Cancelling..."));
+
+                        /* cancel the job; no callback since op_filesystem_create will return an error */
+                        gdu_device_op_cancel_job (device,
+                                                  NULL,
+                                                  NULL);
+                        goto again;
+
+                } else {
+                        show_error_dialog (NULL,
+                                           _("Error formatting volume"),
+                                           format_data->error->message);
+                        g_error_free (format_data->error);
+                }
                 goto out;
         }
 
@@ -296,22 +499,22 @@ main (int argc, char *argv[])
         gdu_device_op_filesystem_mount (device_to_mount,
                                         NULL,
                                         fs_mount_cb,
-                                        &data);
+                                        format_data);
         g_main_loop_run (loop);
         gtk_widget_destroy (dialog);
         dialog = NULL;
-        if (data.error != NULL) {
+        if (format_data->error != NULL) {
                 show_error_dialog (NULL,
                                    _("Error mounting device"),
-                                   data.error->message);
-                g_error_free (data.error);
+                                   format_data->error->message);
+                g_error_free (format_data->error);
                 goto out;
         }
 
         /* open file manager */
-        launch_file_manager (data.mount_point);
+        launch_file_manager (format_data->mount_point);
 
-        g_free (data.mount_point);
+        g_free (format_data->mount_point);
 
         /* save passphrase in keyring if requested */
         if (passphrase != NULL && (save_passphrase_in_keyring || save_passphrase_in_keyring_session)) {
@@ -328,6 +531,21 @@ main (int argc, char *argv[])
         ret = 0;
 
  out:
+        if (toplevel != NULL)
+                g_object_unref (toplevel);
+        g_free (drive_name);
+        g_free (size_str);
+        g_free (format_desc);
+        g_free (formatting_desc);
+        if (gmount != NULL)
+                g_object_unref (gmount);
+        if (gvolume != NULL)
+                g_object_unref (gvolume);
+        g_list_foreach (gvolumes, (GFunc) g_object_unref, NULL);
+        if (gvolume_monitor != NULL)
+                g_object_unref (gvolume_monitor);
+        g_free (confirmation_secondary);
+        g_free (volume_name);
         g_free (passphrase);
         g_free (fs_type);
         g_free (fs_label);
@@ -340,9 +558,13 @@ main (int argc, char *argv[])
                 g_object_unref (volume);
         if (device != NULL)
                 g_object_unref (device);
+        if (device_to_unmount != NULL)
+                g_object_unref (device_to_unmount);
         if (device_to_mount != NULL)
                 g_object_unref (device_to_mount);
         if (pool != NULL)
                 g_object_unref (pool);
+        if (format_data != NULL)
+                g_free (format_data);
         return ret;
 }
diff --git a/src/nautilus-extension/nautilus-gdu.c b/src/nautilus-extension/nautilus-gdu.c
index 66a3e56..09e131c 100644
--- a/src/nautilus-extension/nautilus-gdu.c
+++ b/src/nautilus-extension/nautilus-gdu.c
@@ -151,67 +151,10 @@ open_format_utility (NautilusMenuItem *item)
 }
 
 static void
-unmount_done (GObject      *object,
-              GAsyncResult *res,
-              gpointer      user_data)
-{
-        NautilusMenuItem *item = NAUTILUS_MENU_ITEM (user_data);
-        GError *error;
-
-        error = NULL;
-        if (g_mount_unmount_finish (G_MOUNT (object), res, &error)) {
-                open_format_utility (item);
-        } else if (error->code == G_IO_ERROR_FAILED_HANDLED) {
-                /* do nothing, error has already been presented to the user */
-                g_error_free (error);
-        } else {
-                GtkWidget *dialog;
-                gchar *name;
-                gchar *p;
-                gchar *text;
-
-                name = g_mount_get_name (G_MOUNT (object));
-                dialog = gtk_message_dialog_new (NULL, 0,
-                                                 GTK_MESSAGE_ERROR,
-                                                 GTK_BUTTONS_OK,
-                                                 _("Could not unmount '%s'"), name);
-                if (g_str_has_prefix (error->message, "org.freedesktop.DeviceKit")) {
-                        p = strchr (error->message, ':');
-                        if (p != NULL)
-                                text = p + 1;
-                        else
-                                text = error->message;
-                } else {
-                        text = error->message;
-                }
-
-                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                          "%s", text);
-                gtk_dialog_run (GTK_DIALOG (dialog));
-                gtk_widget_destroy (dialog);
-                g_error_free (error);
-                g_free (name);
-        }
-
-        g_object_unref (item);
-}
-
-static void
 format_callback (NautilusMenuItem *item,
                  gpointer user_data)
 {
-        NautilusFileInfo *nautilus_file;
-        GMount *mount;
-
-        /* Unmount the device if it's mounted */
-        nautilus_file = g_object_get_data (G_OBJECT (item), "nautilus-file");
-        mount = nautilus_file_info_get_mount (nautilus_file);
-        if (mount != NULL) {
-                g_mount_unmount (mount, G_MOUNT_UNMOUNT_NONE, NULL, unmount_done, g_object_ref (item));
-                g_object_unref (mount);
-        } else {
-                open_format_utility (g_object_ref (item));
-        }
+        open_format_utility (g_object_ref (item));
 }
 
 static GList *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]