[git] GPA - branch, master, updated. gpa-0.9.9-4-gea99f88

by Neal H. Walfield cvs at cvs.gnupg.org
Tue Nov 3 22:10:07 CET 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Assistant".

The branch, master has been updated
       via  ea99f888c0f557fdce3870bb021ac7c3dd84a12d (commit)
      from  60ddc172ba09d7c0c57835e23ddb6074a695e258 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ea99f888c0f557fdce3870bb021ac7c3dd84a12d
Author: Neal H. Walfield <neal at gnu.org>
Date:   Tue Nov 3 22:09:54 2015 +0100

    Provide an option to choose an alternate name for files that exist
    
    * src/gpgmetools.c (check_overwriting): Change return type from a
    boolean to a char *.  If the file exists, offer the user the option to
    select a different file.  Return the file that is actually used.
    (gpa_fopen): Take an additional parameter, FILENAME_USED.  Save the
    filename returned by check_overwriting there.  Update users.
    (gpa_open_output): Likewise.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
    GnuPG-bug-id: 758

diff --git a/src/gpafiledecryptop.c b/src/gpafiledecryptop.c
index 362d15d..64aa719 100644
--- a/src/gpafiledecryptop.c
+++ b/src/gpafiledecryptop.c
@@ -1,6 +1,6 @@
 /* gpafiledecryptop.c - The GpaOperation object.
  * Copyright (C) 2003 Miguel Coca.
- * Copyright (C) 2008 g10 Code GmbH.
+ * Copyright (C) 2008, 2015 g10 Code GmbH.
  *
  * This file is part of GPA
  *
@@ -307,6 +307,7 @@ gpa_file_decrypt_operation_start (GpaFileDecryptOperation *op,
   else
     {
       gchar *cipher_filename = file_item->filename_in;
+      char *filename_used;
 
       file_item->filename_out = destination_filename (cipher_filename);
       /* Open the files */
@@ -317,15 +318,20 @@ gpa_file_decrypt_operation_start (GpaFileDecryptOperation *op,
 	return gpg_error (GPG_ERR_GENERAL);
 
       op->plain_fd = gpa_open_output (file_item->filename_out, &op->plain,
-				      GPA_OPERATION (op)->window);
+				      GPA_OPERATION (op)->window,
+                                      &filename_used);
       if (op->plain_fd == -1)
 	{
 	  gpgme_data_release (op->cipher);
 	  close (op->cipher_fd);
+          xfree (filename_used);
 	  /* FIXME: Error value.  */
 	  return gpg_error (GPG_ERR_GENERAL);
 	}
 
+      xfree (file_item->filename_out);
+      file_item->filename_out = filename_used;
+
       gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
                           is_cms_file (cipher_filename) ?
                           GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP);
diff --git a/src/gpafileencryptop.c b/src/gpafileencryptop.c
index 4731fda..4e22446 100644
--- a/src/gpafileencryptop.c
+++ b/src/gpafileencryptop.c
@@ -1,6 +1,6 @@
 /* gpafiledecryptop.c - The GpaOperation object.
  * Copyright (C) 2003 Miguel Coca.
- * Copyright (C) 2008 g10 Code GmbH.
+ * Copyright (C) 2008, 2015 g10 Code GmbH.
  *
  * This file is part of GPA
  *
@@ -310,6 +310,7 @@ gpa_file_encrypt_operation_start (GpaFileEncryptOperation *op,
   else
     {
       gchar *plain_filename = file_item->filename_in;
+      char *filename_used;
 
       file_item->filename_out = destination_filename
 	(plain_filename, gpgme_get_armor (GPA_OPERATION (op)->context->ctx));
@@ -321,15 +322,20 @@ gpa_file_encrypt_operation_start (GpaFileEncryptOperation *op,
 	return gpg_error (GPG_ERR_GENERAL);
 
       op->cipher_fd = gpa_open_output (file_item->filename_out, &op->cipher,
-				       GPA_OPERATION (op)->window);
+				       GPA_OPERATION (op)->window,
+                                       &filename_used);
       if (op->cipher_fd == -1)
 	{
 	  gpgme_data_release (op->plain);
 	  close (op->plain_fd);
 	  op->plain_fd = -1;
+          xfree (filename_used);
 	  /* FIXME: Error value.  */
 	  return gpg_error (GPG_ERR_GENERAL);
 	}
+
+      xfree (file_item->filename_out);
+      file_item->filename_out = filename_used;
     }
 
   /* Start the operation.  */
diff --git a/src/gpafilesignop.c b/src/gpafilesignop.c
index 5ecef78..b926d17 100644
--- a/src/gpafilesignop.c
+++ b/src/gpafilesignop.c
@@ -1,6 +1,6 @@
 /* gpafiledecryptop.c - The GpaOperation object.
  * Copyright (C) 2003 Miguel Coca.
- * Copyright (C) 2008 g10 Code GmbH.
+ * Copyright (C) 2008, 2015 g10 Code GmbH.
  *
  * This file is part of GPA
  *
@@ -285,6 +285,7 @@ gpa_file_sign_operation_start (GpaFileSignOperation *op,
   else
     {
       gchar *plain_filename = file_item->filename_in;
+      char *filename_used;
 
       file_item->filename_out = destination_filename
 	(plain_filename, gpgme_get_armor (GPA_OPERATION (op)->context->ctx),
@@ -298,14 +299,19 @@ gpa_file_sign_operation_start (GpaFileSignOperation *op,
 	return gpg_error (GPG_ERR_GENERAL);
 
       op->sig_fd = gpa_open_output (file_item->filename_out, &op->sig,
-				    GPA_OPERATION (op)->window);
+				    GPA_OPERATION (op)->window,
+                                    &filename_used);
       if (op->sig_fd == -1)
 	{
 	  gpgme_data_release (op->plain);
 	  close (op->plain_fd);
+          xfree (filename_used);
 	  /* FIXME: Error value.  */
 	  return gpg_error (GPG_ERR_GENERAL);
 	}
+
+      xfree (file_item->filename_out);
+      file_item->filename_out = filename_used;
     }
 
   /* Start the operation */
diff --git a/src/gpgmetools.c b/src/gpgmetools.c
index 83c4a69..cc45052 100644
--- a/src/gpgmetools.c
+++ b/src/gpgmetools.c
@@ -1,6 +1,6 @@
 /* gpgmetools.h - Additional gpgme support functions for GPA.
    Copyright (C) 2002 Miguel Coca.
-   Copyright (C) 2005, 2008, 2009, 2012, 2014 g10 Code GmbH.
+   Copyright (C) 2005, 2008, 2009, 2012, 2014, 2015 g10 Code GmbH.
 
    This file is part of GPA
 
@@ -160,28 +160,56 @@ dump_data_to_file (gpgme_data_t data, FILE *file)
 }
 
 
-static gboolean
+static char *
 check_overwriting (const char *filename, GtkWidget *parent)
 {
-  /* If the file exists, ask before overwriting.  */
-  if (g_file_test (filename, G_FILE_TEST_EXISTS))
-    {
-      GtkWidget *msgbox = gtk_message_dialog_new
-	(GTK_WINDOW(parent), GTK_DIALOG_MODAL,
-	 GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
-	 _("The file %s already exists.\n"
-	   "Do you want to overwrite it?"), filename);
-      gtk_dialog_add_buttons (GTK_DIALOG (msgbox),
-			      _("_Yes"), GTK_RESPONSE_YES,
-			      _("_No"), GTK_RESPONSE_NO, NULL);
-      if (gtk_dialog_run (GTK_DIALOG (msgbox)) != GTK_RESPONSE_YES)
-	{
-	  gtk_widget_destroy (msgbox);
-	  return FALSE;
-	}
-      gtk_widget_destroy (msgbox);
+  GtkWidget *dialog;
+  int response;
+  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
+  char *filename_used = xstrdup (filename);
+
+  while (1)
+    {
+      /* If the file exists, ask before overwriting.  */
+      if (! g_file_test (filename_used, G_FILE_TEST_EXISTS))
+        return filename_used;
+
+      dialog = gtk_message_dialog_new
+        (GTK_WINDOW (parent), GTK_DIALOG_MODAL,
+         GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
+         _("The file %s already exists.\n"
+           "Do you want to overwrite it?"), filename_used);
+      gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                              _("_Yes"), GTK_RESPONSE_YES,
+                              _("_No"), GTK_RESPONSE_NO,
+                              _("_Use a different filename"), 1,
+                              NULL);
+
+      response = gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+      if (response == GTK_RESPONSE_YES)
+        return filename_used;
+      if (response == GTK_RESPONSE_NO)
+        {
+          xfree (filename_used);
+          return NULL;
+        }
+
+      /* Use a different filename.  */
+      dialog = gtk_file_chooser_dialog_new
+        ("Open File", GTK_WINDOW (parent), action,
+         _("_Cancel"), GTK_RESPONSE_CANCEL,
+         _("_Open"), GTK_RESPONSE_ACCEPT,
+         NULL);
+      response = gtk_dialog_run (GTK_DIALOG (dialog));
+      if (response == GTK_RESPONSE_ACCEPT)
+        {
+          GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+          filename_used = gtk_file_chooser_get_filename (chooser);
+        }
+
+      gtk_widget_destroy (dialog);
     }
-  return TRUE;
 }
 
 /* Not really a gpgme function, but needed in most places
@@ -190,20 +218,20 @@ check_overwriting (const char *filename, GtkWidget *parent)
    NULL on failure, but you can assume the user has been informed of
    the error (or maybe he just didn't want to overwrite!).  */
 FILE *
-gpa_fopen (const char *filename, GtkWidget *parent)
+gpa_fopen (const char *filename, GtkWidget *parent, char **filename_used)
 {
   FILE *target;
 
-  if (!check_overwriting (filename, parent))
+  *filename_used = check_overwriting (filename, parent);
+  if (! *filename_used)
     return NULL;
-  target = g_fopen (filename, "w");
+  target = g_fopen (*filename_used, "w");
   if (!target)
     {
       gchar *message;
-      message = g_strdup_printf ("%s: %s", filename, strerror(errno));
+      message = g_strdup_printf ("%s: %s", *filename_used, strerror(errno));
       gpa_window_error (message, parent);
       g_free (message);
-      return NULL;
     }
   return target;
 }
@@ -237,12 +265,17 @@ gpa_open_output_direct (const char *filename, gpgme_data_t *data,
 
 
 int
-gpa_open_output (const char *filename, gpgme_data_t *data, GtkWidget *parent)
+gpa_open_output (const char *filename, gpgme_data_t *data, GtkWidget *parent,
+                 char **filename_used)
 {
-  if (! check_overwriting (filename, parent))
+  int res;
+
+  *filename_used = check_overwriting (filename, parent);
+  if (! *filename_used)
     return -1;
 
-  return gpa_open_output_direct (filename, data, parent);
+  res = gpa_open_output_direct (*filename_used, data, parent);
+  return res;
 }
 
 
diff --git a/src/gpgmetools.h b/src/gpgmetools.h
index 1320f88..1cfeb3a 100644
--- a/src/gpgmetools.h
+++ b/src/gpgmetools.h
@@ -1,6 +1,7 @@
 /* gpgmetools.h - additional gpgme support functions for GPA.
    Copyright (C) 2002, Miguel Coca.
    Copyright (C) 2005, 2008 g10 Code GmbH.
+   Copyright (C) 2015 g10 Code GmbH.
 
    This file is part of GPA
 
@@ -114,8 +115,13 @@ void dump_data_to_file (gpgme_data_t data, FILE *file);
    dump_data_to_file is used.  Opens a file for writing, asking the
    user to overwrite if it exists and reporting any errors.  Returns
    NULL on failure, but you can assume the user has been informed of
-   the error (or maybe he just didn't want to overwrite!).  */
-FILE *gpa_fopen (const char *filename, GtkWidget *parent);
+   the error (or maybe he just didn't want to overwrite!).  The
+   filename of the file that is actually open (if FILENAME already
+   exists, then the user can choose a different file) is saved in
+   *FILENAME_USED.  It must be xfreed.  This is set even if this
+   function returns NULL!  */
+FILE *gpa_fopen (const char *filename, GtkWidget *parent,
+                 char **filename_used);
 
 /* Do a gpgme_data_new_from_file and report any GPG_ERR_File_Error to
    the user.  */
@@ -125,11 +131,15 @@ gpg_error_t gpa_gpgme_data_new_from_file (gpgme_data_t *data,
 
 /* Create a new gpgme_data_t from a file for writing, and return the
    file descriptor for the file.  Always reports all errors to the
-   user.  The _direct variant does not check for overwriting.  */
+   user.  The _direct variant does not check for overwriting.  The
+   filename of the file that is actually open (if FILENAME already
+   exists, then the user can choose a different file) is saved in
+   *FILENAME_USED.  It must be xfreed.  This is set even if this
+   function returns NULL!  */
 int gpa_open_output_direct (const char *filename, gpgme_data_t *data,
 			    GtkWidget *parent);
 int gpa_open_output (const char *filename, gpgme_data_t *data,
-		     GtkWidget *parent);
+		     GtkWidget *parent, char **filename_used);
 
 /* Create a new gpgme_data_t from a file for reading, and return the
    file descriptor for the file.  Always reports all errors to the user.  */

-----------------------------------------------------------------------

Summary of changes:
 src/gpafiledecryptop.c | 10 ++++--
 src/gpafileencryptop.c | 10 ++++--
 src/gpafilesignop.c    | 10 ++++--
 src/gpgmetools.c       | 89 ++++++++++++++++++++++++++++++++++----------------
 src/gpgmetools.h       | 18 +++++++---
 5 files changed, 99 insertions(+), 38 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Assistant
http://git.gnupg.org




More information about the Gnupg-commits mailing list