[tepl] io-error-info-bars: add cant_create_backup()



commit 297bbf46dc9dc62292de66f23a1b7d03e9c52469
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Mar 24 10:37:22 2020 +0100

    io-error-info-bars: add cant_create_backup()
    
    And add possible TODO.

 docs/reference/tepl-4.0-sections.txt |  1 +
 tepl/tepl-io-error-info-bars.c       | 61 ++++++++++++++++++++++++++++++++++++
 tepl/tepl-io-error-info-bars.h       |  3 ++
 3 files changed, 65 insertions(+)
---
diff --git a/docs/reference/tepl-4.0-sections.txt b/docs/reference/tepl-4.0-sections.txt
index aca80a4..25a3484 100644
--- a/docs/reference/tepl-4.0-sections.txt
+++ b/docs/reference/tepl-4.0-sections.txt
@@ -292,6 +292,7 @@ TeplInfoBarClass
 <SECTION>
 <FILE>io-error-info-bars</FILE>
 tepl_io_error_info_bar_file_already_open_warning_new
+tepl_io_error_info_bar_cant_create_backup
 </SECTION>
 
 <SECTION>
diff --git a/tepl/tepl-io-error-info-bars.c b/tepl/tepl-io-error-info-bars.c
index 9bc81ab..ba9eec4 100644
--- a/tepl/tepl-io-error-info-bars.c
+++ b/tepl/tepl-io-error-info-bars.c
@@ -73,3 +73,64 @@ tepl_io_error_info_bar_file_already_open_warning_new (GFile *location)
 
        return info_bar;
 }
+
+/**
+ * tepl_io_error_info_bar_cant_create_backup:
+ * @location: the #GFile for which the backup failed to be created.
+ * @error: must be a %G_IO_ERROR_CANT_CREATE_BACKUP.
+ *
+ * When a %G_IO_ERROR_CANT_CREATE_BACKUP error occurs while saving @location,
+ * offer two possible actions:
+ * - Save anyway: %GTK_RESPONSE_YES.
+ * - Don't save: %GTK_RESPONSE_CANCEL.
+ *
+ * Returns: (transfer floating): the newly created #TeplInfoBar.
+ * Since: 4.6
+ */
+/* TODO add another possible action: save as? */
+TeplInfoBar *
+tepl_io_error_info_bar_cant_create_backup (GFile        *location,
+                                          const GError *error)
+{
+       TeplInfoBar *info_bar;
+       gchar *uri;
+       gchar *primary_msg;
+       const gchar *secondary_msg;
+
+       g_return_val_if_fail (G_IS_FILE (location), NULL);
+       g_return_val_if_fail (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANT_CREATE_BACKUP), NULL);
+
+       info_bar = tepl_info_bar_new ();
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("S_ave Anyway"),
+                                GTK_RESPONSE_YES);
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("_Don’t Save"),
+                                GTK_RESPONSE_CANCEL);
+
+       gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
+
+       uri = g_file_get_parse_name (location);
+       primary_msg = g_strdup_printf (_("Could not create a backup file while saving “%s”"), uri);
+       tepl_info_bar_add_primary_message (info_bar, primary_msg);
+       g_free (uri);
+       g_free (primary_msg);
+
+       secondary_msg = _("Could not back up the old copy of the file before saving the new one. "
+                         "You can ignore this warning and save the file anyway, but if an error "
+                         "occurs while saving, you could lose the old copy of the file. Save anyway?");
+       tepl_info_bar_add_secondary_message (info_bar, secondary_msg);
+
+       if (error->message != NULL)
+       {
+               gchar *error_msg;
+
+               error_msg = g_strdup_printf (_("Error message: %s"), error->message);
+               tepl_info_bar_add_secondary_message (info_bar, error_msg);
+               g_free (error_msg);
+       }
+
+       return info_bar;
+}
diff --git a/tepl/tepl-io-error-info-bars.h b/tepl/tepl-io-error-info-bars.h
index 19772ba..0c2ea96 100644
--- a/tepl/tepl-io-error-info-bars.h
+++ b/tepl/tepl-io-error-info-bars.h
@@ -27,6 +27,9 @@ G_BEGIN_DECLS
 
 TeplInfoBar *  tepl_io_error_info_bar_file_already_open_warning_new    (GFile *location);
 
+TeplInfoBar *  tepl_io_error_info_bar_cant_create_backup               (GFile        *location,
+                                                                        const GError *error);
+
 G_END_DECLS
 
 #endif /* TEPL_IO_ERROR_INFO_BARS_H */


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