Parcourir la source

Do not overwrite a file without user confirmation.

Make sure the user is fine with overwriting an existing file. If
the user selects a file with the file chooser dialog, then the
dialog takes care of asking for confirmation. Otherwise, if the
user does not change the default filename, then we need to
explicitly ask for confirmation.
master yorkie-0.1.0
Damien Goutte-Gattat il y a 8 mois
Parent
révision
892125e1ec
1 fichiers modifiés avec 30 ajouts et 1 suppressions
  1. +30
    -1
      src/encrypt.c

+ 30
- 1
src/encrypt.c Voir le fichier

@ -150,6 +150,7 @@ output_clicked(GtkButton *button, gpointer data)
NULL);
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dlg), yki->output_filename);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dlg), yki->output_basename);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dlg), TRUE);
if ( gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT ) {
g_free(yki->output_filename);
@ -222,6 +223,29 @@ create_encrypt_dialog(yki_encrypt_data_t *yki)
return GTK_DIALOG(gtk_builder_get_object(builder, "dlgEncrypt"));
}
static int
confirm_overwrite(GtkWindow *parent, yki_encrypt_data_t *yki)
{
GtkWidget *dlg;
int ret;
dlg = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
"A file name \"%s\" already exists. "
"Do you want to replace it?", yki->output_basename);
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dlg),
"Replacing it will overwrite its contents.");
gtk_dialog_add_buttons(GTK_DIALOG(dlg),
"Cancel", GTK_RESPONSE_CANCEL,
"Replace", GTK_RESPONSE_OK,
NULL);
ret = gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_OK;
gtk_widget_destroy(dlg);
return ret;
}
/* Dealing with public keys. */
@ -356,7 +380,12 @@ yki_encrypt(gpgme_ctx_t gpgme, const char *file, GError **error)
if ( ret && gtk_dialog_run(dlg) == GTK_RESPONSE_OK && yki_can_encrypt(yki) ) {
gpgme_set_armor(gpgme, yki.armored);
ret = gpgutil_open_file(file, "r", &in, error);
/* Check with user before overwriting a file with the default filename. */
if ( g_file_test(yki.output_filename, G_FILE_TEST_EXISTS) && ! yki.output_filename_userset )
ret = confirm_overwrite(GTK_WINDOW(dlg), &yki);
if ( ret )
ret = gpgutil_open_file(file, "r", &in, error);
if ( ret )
ret = gpgutil_open_file(yki.output_filename, "w", &out, error);


Chargement…
Annuler
Enregistrer