[gnome-disk-utility] Show warning dialog if read errors occured during disk image creation



commit 9afd3e37ab157e9970a79192a6ca24077eaeca6f
Author: David Zeuthen <zeuthen gmail com>
Date:   Sat Jan 5 13:31:48 2013 -0500

    Show warning dialog if read errors occured during disk image creation
    
    Otherwise there is no way the user is informed that some data was
    replaced with zeroes.
    
    http://people.freedesktop.org/~david/disks-create-disk-image-error-dialog.png
    
    Signed-off-by: David Zeuthen <zeuthen gmail com>

 src/disks/gducreatediskimagedialog.c |   57 ++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/src/disks/gducreatediskimagedialog.c b/src/disks/gducreatediskimagedialog.c
index 50713af..bfb59f6 100644
--- a/src/disks/gducreatediskimagedialog.c
+++ b/src/disks/gducreatediskimagedialog.c
@@ -455,6 +455,63 @@ on_success (gpointer user_data)
   dialog_data_uninhibit (data);
   dialog_data_complete_and_unref (data);
 
+  /* OK, we're done but we had to replace unreadable data with
+   * zeroes. Bring up a modal dialog to inform the user of this and
+   * allow him to delete the file, if so desired.
+   */
+  if (data->num_error_bytes > 0)
+    {
+      GtkWidget *dialog, *button;
+      GFileInfo *fi = NULL;
+      GError *error = NULL;
+      gchar *s = NULL;
+      gint response;
+      gdouble percentage;
+
+      dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (data->window),
+                                                   GTK_DIALOG_MODAL,
+                                                   GTK_MESSAGE_WARNING,
+                                                   GTK_BUTTONS_CLOSE,
+                                                   "<big><b>%s</b></big>",
+                                                   /* Translators: Primary message in dialog if some data was unreadable while creating a disk image */
+                                                   _("Read errors while creating disk image"));
+      fi = g_file_query_info (data->output_file,
+                              "standard::display-name",
+                              G_FILE_QUERY_INFO_NONE, NULL, NULL);
+      s = g_format_size (data->num_error_bytes);
+      percentage = 100.0 * ((gdouble) data->num_error_bytes) / ((gdouble) gdu_estimator_get_completed_bytes (data->estimator));
+      gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+                                                  /* Translators: Secondary message in dialog if some data was unreadable while creating a disk image.
+                                                   * The first %s is the amount of unreadable data (ex. "4.2 MB").
+                                                   * The %f is the percentage of unreadable data (ex. 13.0).
+                                                   * The second %s is the name of the output file (ex "foo.iso").
+                                                   */
+                                                  _("%s (%2.1f%%) was unreadable and replaced with zeroes while creating the disk image â%sâ. If this is not acceptable, you may delete the disk image"),
+                                                  s,
+                                                  percentage,
+                                                  g_file_info_get_display_name (fi));
+      button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+                                      _("_Delete Disk Image"),
+                                      GTK_RESPONSE_NO);
+      gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
+                                          button, TRUE);
+      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
+      response = gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+      g_clear_object (&fi);
+      g_free (s);
+
+      if (response == GTK_RESPONSE_NO)
+        {
+          if (!g_file_delete (data->output_file, NULL, &error))
+            {
+              g_warning ("Error deleting file: %s (%s, %d)",
+                         error->message, g_quark_to_string (error->domain), error->code);
+              g_clear_error (&error);
+            }
+        }
+    }
+
   dialog_data_unref (data);
   return FALSE; /* remove source */
 }



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