[git] GPA - branch, master, updated. gpa-0.9.4-47-gac007f3

by Werner Koch cvs at cvs.gnupg.org
Tue Nov 18 20:41:56 CET 2014


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  ac007f3204c06b3cb4b272fd1de17baa4d589ae8 (commit)
       via  7bf586c3d5fec9c7db12e208361843fcd2b66163 (commit)
       via  68b7faa05eb825ead05c27bb42860da8390f3a25 (commit)
      from  8bbf24ba918bae0d593ce5431c234789cfad8a7b (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 ac007f3204c06b3cb4b272fd1de17baa4d589ae8
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Nov 18 20:42:15 2014 +0100

    Make receiving keys from a keyserver work with GnuPG 2.1
    
    * src/gpaimportop.h (_GpaImportOperation): Add field source2.
    (_GpaImportOperationClass): Change prototype of get_source and all
    callers.
    * src/gpaimportop.c (gpa_import_operation_finalize): Release source2
    var.
    (gpa_import_operation_idle_cb): Use import_keys if source2 is set.
    (key_import_results_dialog_run): Use modern info functions.
    * src/gpaimportserverop.c (MAX_KEYSEARCH_RESULTS): New.
    (search_keys): New.
    (gpa_import_server_operation_get_source): Make use of source2.
    
    * src/gparecvkeydlg.c (gpa_receive_key_dialog_init): Change prompt for
    gnupg 2.1.0.
    --
    
    Passing the instance variable to several fucntions of the class was a
    bit weird.  Thus changed to use it direct.

diff --git a/src/gpaexportclipop.c b/src/gpaexportclipop.c
index 62edb12..1e4c306 100644
--- a/src/gpaexportclipop.c
+++ b/src/gpaexportclipop.c
@@ -136,8 +136,8 @@ gpa_export_clipboard_operation_complete_export (GpaExportOperation *operation)
   GpaExportClipboardOperation *op = GPA_EXPORT_CLIPBOARD_OPERATION (operation);
   if (!dump_data_to_clipboard (operation->dest, gtk_clipboard_get
                                (GDK_SELECTION_CLIPBOARD)))
-    gpa_window_message (_("The keys have been copied to the clipboard."),
-                        GPA_OPERATION (op)->window);
+    gpa_show_info(GPA_OPERATION (op)->window,
+                  _("The keys have been copied to the clipboard."));
 }
 
 /* API */
diff --git a/src/gpaimportclipop.c b/src/gpaimportclipop.c
index 2e1eb59..7162982 100644
--- a/src/gpaimportclipop.c
+++ b/src/gpaimportclipop.c
@@ -30,9 +30,8 @@
 static GObjectClass *parent_class = NULL;
 
 static gboolean
-gpa_import_clipboard_operation_get_source (GpaImportOperation *operation, 
-					   gpgme_data_t *source);
-static void 
+gpa_import_clipboard_operation_get_source (GpaImportOperation *operation);
+static void
 gpa_import_clipboard_operation_complete_import (GpaImportOperation *operation);
 
 /* GObject boilerplate */
@@ -50,14 +49,14 @@ gpa_import_clipboard_operation_class_init (GpaImportClipboardOperationClass *kla
   parent_class = g_type_class_peek_parent (klass);
 
   import_class->get_source = gpa_import_clipboard_operation_get_source;
-  import_class->complete_import = gpa_import_clipboard_operation_complete_import;  
+  import_class->complete_import = gpa_import_clipboard_operation_complete_import;
 }
 
 GType
 gpa_import_clipboard_operation_get_type (void)
 {
   static GType clipboard_operation_type = 0;
-  
+
   if (!clipboard_operation_type)
     {
       static const GTypeInfo clipboard_operation_info =
@@ -72,36 +71,38 @@ gpa_import_clipboard_operation_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_import_clipboard_operation_init,
       };
-      
+
       clipboard_operation_type = g_type_register_static (GPA_IMPORT_OPERATION_TYPE,
 							 "GpaImportClipboardOperation",
 							 &clipboard_operation_info, 0);
     }
-  
+
   return clipboard_operation_type;
 }
 
 /* Virtual methods */
 
 static gboolean
-gpa_import_clipboard_operation_get_source (GpaImportOperation *operation, 
-					   gpgme_data_t *source)
+gpa_import_clipboard_operation_get_source (GpaImportOperation *operation)
 {
   gpg_error_t err;
-  gchar *text = gtk_clipboard_wait_for_text (gtk_clipboard_get
-					     (GDK_SELECTION_CLIPBOARD));
-  
+  gchar *text;
+
+  text = gtk_clipboard_wait_for_text (gtk_clipboard_get
+                                      (GDK_SELECTION_CLIPBOARD));
+  gpgme_data_release (operation->source);
   if (text)
     {
       /* Fill the data from the selection clipboard.
        */
-      err = gpgme_data_new_from_mem (source, text, strlen (text), FALSE);
+      err = gpgme_data_new_from_mem (&operation->source,
+                                     text, strlen (text), TRUE);
     }
   else
     {
-      /* If the keyboard was empty, create an empty data
+      /* If the keyboard was empty, create an empty data object.
        */
-      err = gpgme_data_new (source);
+      err = gpgme_data_new (&operation->source);
     }
 
   if (err)
@@ -112,7 +113,7 @@ gpa_import_clipboard_operation_get_source (GpaImportOperation *operation,
   return TRUE;
 }
 
-static void 
+static void
 gpa_import_clipboard_operation_complete_import (GpaImportOperation *operation)
 {
   /* Nothing special to do */
@@ -124,7 +125,7 @@ GpaImportClipboardOperation*
 gpa_import_clipboard_operation_new (GtkWidget *window)
 {
   GpaImportClipboardOperation *op;
-  
+
   op = g_object_new (GPA_IMPORT_CLIPBOARD_OPERATION_TYPE,
 		     "window", window, NULL);
 
diff --git a/src/gpaimportfileop.c b/src/gpaimportfileop.c
index 71cb02b..81d7995 100644
--- a/src/gpaimportfileop.c
+++ b/src/gpaimportfileop.c
@@ -31,8 +31,7 @@
 static GObjectClass *parent_class = NULL;
 
 static gboolean
-gpa_import_file_operation_get_source (GpaImportOperation *operation,
-				      gpgme_data_t *source);
+gpa_import_file_operation_get_source (GpaImportOperation *operation);
 static void
 gpa_import_file_operation_complete_import (GpaImportOperation *operation);
 
@@ -121,8 +120,7 @@ gpa_import_file_operation_get_type (void)
 /* Virtual methods */
 
 static gboolean
-gpa_import_file_operation_get_source (GpaImportOperation *operation,
-				      gpgme_data_t *source)
+gpa_import_file_operation_get_source (GpaImportOperation *operation)
 {
   GpaImportFileOperation *op = GPA_IMPORT_FILE_OPERATION (operation);
   GtkWidget *dialog;
@@ -134,6 +132,9 @@ gpa_import_file_operation_get_source (GpaImportOperation *operation,
      GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
 
+  gpgme_data_release (operation->source);
+  operation->source = NULL;
+
   /* Run the dialog until there is a valid response.  */
   do
     {
@@ -145,8 +146,9 @@ gpa_import_file_operation_get_source (GpaImportOperation *operation,
 			   (GTK_FILE_CHOOSER (dialog)));
     }
   while (response == GTK_RESPONSE_OK
-	 && (op->fd = gpa_open_input
-	     (op->file, source, GPA_OPERATION (op)->window)) == -1);
+	 && (op->fd = gpa_open_input (op->file,
+                                      &operation->source,
+                                      GPA_OPERATION (op)->window)) == -1);
   gtk_widget_destroy (dialog);
 
   return (response == GTK_RESPONSE_OK);
diff --git a/src/gpaimportop.c b/src/gpaimportop.c
index 0680a21..6169952 100644
--- a/src/gpaimportop.c
+++ b/src/gpaimportop.c
@@ -51,11 +51,17 @@ static void
 gpa_import_operation_finalize (GObject *object)
 {
   GpaImportOperation *op = GPA_IMPORT_OPERATION (object);
+  int i;
 
   /* Free the data object, if it exists */
-  if (op->source)
+  gpgme_data_release (op->source);
+  op->source = NULL;
+  if (op->source2)
     {
-      gpgme_data_release (op->source);
+      for (i=0; op->source2[i]; i++)
+        gpgme_key_unref (op->source2[i]);
+      g_free (op->source2);
+      op->source2 = NULL;
     }
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -65,6 +71,7 @@ static void
 gpa_import_operation_init (GpaImportOperation *op)
 {
   op->source = NULL;
+  op->source2 = NULL;
 }
 
 static GObject*
@@ -162,15 +169,29 @@ gpa_import_operation_idle_cb (gpointer data)
 {
   GpaImportOperation *op = data;
 
-  if (GPA_IMPORT_OPERATION_GET_CLASS (op)->get_source (op, &op->source))
+  if (GPA_IMPORT_OPERATION_GET_CLASS (op)->get_source (op))
     {
       gpg_error_t err;
 
-      gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
-                          is_cms_data_ext (op->source)?
-                          GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP);
-      err = gpgme_op_import_start (GPA_OPERATION (op)->context->ctx,
-				   op->source);
+      if (op->source)
+        {
+          gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
+                              is_cms_data_ext (op->source)?
+                              GPGME_PROTOCOL_CMS : GPGME_PROTOCOL_OpenPGP);
+          err = gpgme_op_import_start (GPA_OPERATION (op)->context->ctx,
+                                       op->source);
+        }
+      else if (op->source2)
+        {
+          /* The only protocol where an array of keys is used in GPA
+             is OpenPGP.  */
+          gpgme_set_protocol (GPA_OPERATION (op)->context->ctx,
+                              GPGME_PROTOCOL_OpenPGP);
+          err = gpgme_op_import_keys_start (GPA_OPERATION (op)->context->ctx,
+                                            op->source2);
+        }
+      else
+        err = gpg_error (GPG_ERR_BUG);
       if (err)
 	{
 	  gpa_gpgme_warning (err);
@@ -185,6 +206,7 @@ gpa_import_operation_idle_cb (gpointer data)
   return FALSE;
 }
 
+
 static void
 key_import_results_dialog_run (GtkWidget *parent,
 			       gpgme_import_result_t info)
@@ -192,35 +214,19 @@ key_import_results_dialog_run (GtkWidget *parent,
   GtkWidget *dialog;
 
   if (info->considered == 0)
-    {
-      dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
-                                       GTK_DIALOG_MODAL,
-                                       GTK_MESSAGE_WARNING,
-                                       GTK_BUTTONS_CLOSE,
-                                       _("No keys were found."));
-    }
+    gpa_show_warning (parent, _("No keys were found."));
   else
-    {
-      dialog = gtk_message_dialog_new (GTK_WINDOW (parent),
-                                       GTK_DIALOG_MODAL,
-                                       GTK_MESSAGE_INFO,
-                                       GTK_BUTTONS_CLOSE,
-                                       _("%i public keys read\n"
-                                         "%i public keys imported\n"
-                                         "%i public keys unchanged\n"
-                                         "%i secret keys read\n"
-                                         "%i secret keys imported\n"
-                                         "%i secret keys unchanged"),
-                                       info->considered, info->imported,
-                                       info->unchanged, info->secret_read,
-                                       info->secret_imported,
-				       info->secret_unchanged);
-    }
-
-  /* Run the dialog */
-  gtk_widget_show_all (dialog);
-  gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
+    gpa_show_info (parent,
+                   _("%i public keys read\n"
+                     "%i public keys imported\n"
+                     "%i public keys unchanged\n"
+                     "%i secret keys read\n"
+                     "%i secret keys imported\n"
+                     "%i secret keys unchanged"),
+                   info->considered, info->imported,
+                   info->unchanged, info->secret_read,
+                   info->secret_imported,
+                   info->secret_unchanged);
 }
 
 
diff --git a/src/gpaimportop.h b/src/gpaimportop.h
index ac14b22..19efea8 100644
--- a/src/gpaimportop.h
+++ b/src/gpaimportop.h
@@ -41,16 +41,17 @@ typedef struct _GpaImportOperationClass GpaImportOperationClass;
 struct _GpaImportOperation {
   GpaOperation parent;
 
-  gpgme_data_t source;
+  gpgme_data_t source;    /* Either a data object with the full key  */
+  gpgme_key_t *source2;   /* or an array of key descriptions.  */
 };
 
 struct _GpaImportOperationClass {
   GpaOperationClass parent_class;
 
-  /* Get the gpgme_data_t from which the keys should be imported.
-   * Returns FALSE if the operation should be aborted.
+  /* Get the data from which the keys should be imported.  Returns
+   * FALSE if the operation should be aborted.
    */
-  gboolean (*get_source) (GpaImportOperation *op, gpgme_data_t *source);
+  gboolean (*get_source) (GpaImportOperation *op);
 
   /* Do whatever it takes to complete the import once the gpgme_data_t is
    * filled. Basically, this sends the data to the server, the clipboard,
diff --git a/src/gpaimportserverop.c b/src/gpaimportserverop.c
index d1d93a5..fe383a3 100644
--- a/src/gpaimportserverop.c
+++ b/src/gpaimportserverop.c
@@ -29,11 +29,17 @@
 #include "gpaimportserverop.h"
 #include "server-access.h"
 
+/* The number of keys we allow to import at once.  If we have more
+   than this we terminate the dialog and ask the user to give a better
+   specification of the key.  A better way to do this would be to pop
+   up a dialog to allow the user to select matching keys.  */
+#define MAX_KEYSEARCH_RESULTS 5
+
+
 static GObjectClass *parent_class = NULL;
 
 static gboolean
-gpa_import_server_operation_get_source (GpaImportOperation *operation,
-					gpgme_data_t *source);
+gpa_import_server_operation_get_source (GpaImportOperation *operation);
 static void
 gpa_import_server_operation_complete_import (GpaImportOperation *operation);
 
@@ -111,28 +117,132 @@ gpa_import_server_operation_get_type (void)
 
 /* Internal */
 
+/* Search for keys with KEYID.  Return true on success and set the
+   SOURCE2 instance variable.  */
+static gboolean
+search_keys (GpaImportOperation *operation, const char *keyid)
+{
+  gpg_error_t err;
+  gboolean result = FALSE;
+  gpgme_ctx_t ctx;
+  gpgme_key_t key;
+  gpgme_key_t *keyarray;
+  int i, nkeys;
+
+  if (!keyid || !*keyid)
+    return FALSE;
+
+  keyarray = g_malloc0_n (MAX_KEYSEARCH_RESULTS + 1, sizeof *keyarray);
+
+  /* We need to use a separate context because the operaion's context
+     has already been setup and the done signal would relate to the
+     actual import operation done later.  */
+  ctx = gpa_gpgme_new ();
+  gpgme_set_protocol (ctx, GPGME_PROTOCOL_OpenPGP);
+  /* Switch to extern-only list mode.  */
+  err = gpgme_set_keylist_mode (ctx, GPGME_KEYLIST_MODE_EXTERN);
+  if (err)
+    gpa_gpgme_error (err);
+
+  /* List keys matching the given keyid.  Actually all kind of search
+     specifications can be given.  */
+  nkeys = 0;
+  err = gpgme_op_keylist_start (ctx, keyid, 0);
+  while (!err && !(err = gpgme_op_keylist_next (ctx, &key)))
+    {
+      if (nkeys >= MAX_KEYSEARCH_RESULTS)
+        {
+          gpa_show_warning (GPA_OPERATION (operation)->window,
+                            _("More than %d keys match your search pattern.\n"
+                              "Use the long keyid or a fingerprint "
+                              "for a better match"), nkeys);
+          gpgme_key_unref (key);
+          err = gpg_error (GPG_ERR_TRUNCATED);
+          break;
+        }
+      keyarray[nkeys++] = key;
+    }
+  gpgme_op_keylist_end (ctx);
+  if (gpg_err_code (err) == GPG_ERR_EOF)
+    err = 0;
+
+  if (!err && !nkeys)
+    {
+      gpa_show_warning (GPA_OPERATION (operation)->window,
+                        _("No keys were found."));
+    }
+  else if (!err)
+    {
+      operation->source2 = keyarray;
+      keyarray = NULL;
+      result = TRUE;
+    }
+  else if (gpg_err_code (err) != GPG_ERR_TRUNCATED)
+    gpa_gpgme_warning (err);
+
+  gpgme_release (ctx);
+  if (keyarray)
+    {
+      for (i=0; keyarray[i]; i++)
+        gpgme_key_unref (keyarray[i]);
+      g_free (keyarray);
+    }
+  return result;
+}
+
+
 /* Virtual methods */
 
 static gboolean
-gpa_import_server_operation_get_source (GpaImportOperation *operation,
-					gpgme_data_t *source)
+gpa_import_server_operation_get_source (GpaImportOperation *operation)
 {
   GpaImportServerOperation *op = GPA_IMPORT_SERVER_OPERATION (operation);
-  GtkWidget *dialog = gpa_receive_key_dialog_new (GPA_OPERATION (op)->window);
+  GtkWidget *dialog;
   GtkResponseType response;
   gchar *keyid;
+  int i;
 
+  dialog = gpa_receive_key_dialog_new (GPA_OPERATION (op)->window);
   gtk_widget_show_all (dialog);
   response = gtk_dialog_run (GTK_DIALOG (dialog));
   keyid = g_strdup (gpa_receive_key_dialog_get_id
 		    (GPA_RECEIVE_KEY_DIALOG (dialog)));
   gtk_widget_destroy (dialog);
 
-  if (response == GTK_RESPONSE_OK)
+  /* Better reset the source variables.  */
+  gpgme_data_release (operation->source);
+  operation->source = NULL;
+  if (operation->source2)
+    {
+      for (i=0; operation->source2[i]; i++)
+        gpgme_key_unref (operation->source2[i]);
+      g_free (operation->source2);
+      operation->source2 = NULL;
+    }
+
+  if (response == GTK_RESPONSE_OK && is_gpg_version_at_least ("2.1.0"))
+    {
+      /* GnuPG 2.1.0 does not anymore use the keyserver helpers and
+         thus we need to use the real API for receiving keys.  Given
+         that there is currently no way to create a list of keys from
+         the keyids to be passed to the import function we run a
+         --search-keys first to get the list of matching keys and pass
+         them to the actual import function (which does a --recv-keys).  */
+      /* Fixme: As with server_get_key (below), this is a blocking
+         operation. */
+      if (search_keys (operation, keyid))
+        {
+          /* Okay, found key(s).  */
+	  g_free (keyid);
+	  return TRUE;
+        }
+    }
+  else if (response == GTK_RESPONSE_OK)
     {
       if (server_get_key (gpa_options_get_default_keyserver
 			  (gpa_options_get_instance ()),
-			  keyid, source, GPA_OPERATION (op)->window))
+			  keyid,
+                          &operation->source, GPA_OPERATION (op)->window))
 	{
 	  g_free (keyid);
 	  return TRUE;
@@ -142,6 +252,7 @@ gpa_import_server_operation_get_source (GpaImportOperation *operation,
   return FALSE;
 }
 
+
 static void
 gpa_import_server_operation_complete_import (GpaImportOperation *operation)
 {
diff --git a/src/gparecvkeydlg.c b/src/gparecvkeydlg.c
index c0cd752..758190e 100644
--- a/src/gparecvkeydlg.c
+++ b/src/gparecvkeydlg.c
@@ -46,7 +46,7 @@ gpa_receive_key_dialog_get_property (GObject *object, guint prop_id,
 				     GValue *value, GParamSpec *pspec)
 {
   GpaReceiveKeyDialog *dialog = GPA_RECEIVE_KEY_DIALOG (object);
-  
+
   switch (prop_id)
     {
     case PROP_WINDOW:
@@ -100,24 +100,34 @@ gpa_receive_key_dialog_init (GpaReceiveKeyDialog *dialog)
                                            GTK_RESPONSE_OK,
                                            GTK_RESPONSE_CANCEL,
                                            -1);
-  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),5);
+  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),10);
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
-  label = gtk_label_new (_("Which key do you want to import? (The key must "
+  label = gtk_label_new (is_gpg_version_at_least ("2.1.0")?
+                         _("Which key do you want to import?") :
+                         _("Which key do you want to import? (The key must "
 			   "be specified by key ID)."));
   gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), label, FALSE,
-		      TRUE, 5);
+		      TRUE, 10);
 
   dialog->entry = gtk_entry_new ();
-  hbox = gtk_hbox_new (0, FALSE);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE, 
-		      TRUE, 5);
-  label = gtk_label_new_with_mnemonic (_("Key _ID:"));
-  gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->entry);
-
-  gtk_box_pack_start_defaults (GTK_BOX (hbox), label);
-  gtk_box_pack_start_defaults (GTK_BOX (hbox), dialog->entry);
+  if (is_gpg_version_at_least ("2.1.0"))
+    {
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
+                          dialog->entry, FALSE, TRUE, 10);
+    }
+  else
+    {
+      hbox = gtk_hbox_new (0, FALSE);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox, FALSE,
+                          TRUE, 10);
+      label = gtk_label_new_with_mnemonic (_("Key _ID:"));
+      gtk_label_set_mnemonic_widget (GTK_LABEL (label), dialog->entry);
+      gtk_box_pack_start_defaults (GTK_BOX (hbox), label);
+      gtk_box_pack_start_defaults (GTK_BOX (hbox), dialog->entry);
+    }
+
 }
 
 
@@ -125,9 +135,9 @@ static void
 gpa_receive_key_dialog_class_init (GpaReceiveKeyDialogClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
-  
+
   object_class->finalize = gpa_receive_key_dialog_finalize;
   object_class->set_property = gpa_receive_key_dialog_set_property;
   object_class->get_property = gpa_receive_key_dialog_get_property;
@@ -135,7 +145,7 @@ gpa_receive_key_dialog_class_init (GpaReceiveKeyDialogClass *klass)
   /* Properties */
   g_object_class_install_property (object_class,
 				   PROP_WINDOW,
-				   g_param_spec_object 
+				   g_param_spec_object
 				   ("window", "Parent window",
 				    "Parent window", GTK_TYPE_WIDGET,
 				    G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
@@ -146,7 +156,7 @@ GType
 gpa_receive_key_dialog_get_type (void)
 {
   static GType verify_dialog_type = 0;
-  
+
   if (!verify_dialog_type)
     {
       static const GTypeInfo verify_dialog_info =
@@ -161,12 +171,12 @@ gpa_receive_key_dialog_get_type (void)
 	  0,              /* n_preallocs */
 	  (GInstanceInitFunc) gpa_receive_key_dialog_init,
 	};
-      
+
       verify_dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
 						    "GpaReceiveKeyDialog",
 						    &verify_dialog_info, 0);
     }
-  
+
   return verify_dialog_type;
 }
 
@@ -177,7 +187,7 @@ GtkWidget*
 gpa_receive_key_dialog_new (GtkWidget *parent)
 {
   GpaReceiveKeyDialog *dialog;
-  
+
   dialog = g_object_new (GPA_RECEIVE_KEY_DIALOG_TYPE,
 			 "window", parent, NULL);
 
diff --git a/src/server-access.c b/src/server-access.c
index 94fe0ca..18ecdca 100644
--- a/src/server-access.c
+++ b/src/server-access.c
@@ -18,6 +18,10 @@
    along with GPA; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  */
 
+/* Note: This is the old code using the keyserver helpers
+         directly.  This code is not used if GnuPG 2.1 is used.  */
+
+
 #include <config.h>
 
 #include "gpa.h"
@@ -58,7 +62,7 @@
 
 /* Internal API */
 
-/* FIXME: THIS SHOULDN'T BE HERE 
+/* FIXME: THIS SHOULDN'T BE HERE
  * The strsep function is not portable, yet parse_keyserver_uri needs it and
  * I'm too lazy to rewrite it using GLib or ANSI functions, so we copy an
  * implementation here. If there is no other way around it, this kind or
@@ -116,7 +120,7 @@ strsep (char **stringp, const char *delim)
 #endif /*HAVE_STRSEP*/
 
 /* Code adapted from GnuPG (file g10/keyserver.c) */
-static gboolean 
+static gboolean
 parse_keyserver_uri (char *uri, char **scheme, char **host,
 		     char **port, char **opaque)
 {
@@ -232,19 +236,19 @@ helper_path (const gchar *scheme)
       path = g_build_filename (GPA_KEYSERVER_HELPERS_DIR, helper, NULL);
       g_free (helper);
     }
-#endif  
+#endif
   return path;
 }
 
 /* Find out the plugin protocol version */
-static int 
+static int
 protocol_version (const gchar *scheme)
 {
   gchar *helper[] = {helper_path (scheme), "-V", NULL};
   gchar *output = NULL;
   gint version;
 
-  g_spawn_sync (NULL, helper, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, 
+  g_spawn_sync (NULL, helper, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
 		&output, NULL, NULL, NULL);
   if (output && *output)
     {
@@ -280,7 +284,7 @@ parse_helper_output (const gchar *filename)
 	break;
       }
   fclose (file);
-  
+
   return error;
 }
 
@@ -327,7 +331,7 @@ error_string (gint error_code)
 
 static void
 write_command (FILE *file, const char *scheme,
-	       const char *host, const char *port, 
+	       const char *host, const char *port,
 	       const char *opaque, const char *command)
 {
   fprintf (file, "%s\n", "VERSION 1");
@@ -353,9 +357,9 @@ write_command (FILE *file, const char *scheme,
 static GtkWidget *
 wait_dialog (const gchar *server, GtkWidget *parent)
 {
-  GtkWidget *dialog = 
+  GtkWidget *dialog =
     gtk_message_dialog_new (GTK_WINDOW (parent),
-			    GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR, 
+			    GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR,
 			    GTK_MESSAGE_INFO, GTK_BUTTONS_NONE,
 			    _("Connecting to server \"%s\".\n"
 			      "Please wait."), server);
@@ -370,7 +374,7 @@ static gboolean
 check_errors (int exit_status, gchar *error_message, gchar *output_filename,
               int version, GtkWidget *parent)
 {
-  /* Error during connection. Try to parse the output and report the 
+  /* Error during connection. Try to parse the output and report the
    * error.
    */
   if (version == 0)
@@ -381,7 +385,7 @@ check_errors (int exit_status, gchar *error_message, gchar *output_filename,
       if (exit_status)
         {
           gchar *message = g_strdup_printf (_("An error ocurred while "
-                                              "contacting the server:\n\n%s"), 
+                                              "contacting the server:\n\n%s"),
                                             error_message);
           gpa_window_error (message, parent);
           return TRUE;
@@ -401,7 +405,7 @@ check_errors (int exit_status, gchar *error_message, gchar *output_filename,
       else
         {
           gchar *message = g_strdup_printf (_("An error ocurred while "
-                                              "contacting the server:\n\n%s"), 
+                                              "contacting the server:\n\n%s"),
                                             error_string (error_code));
           gpa_window_error (message, parent);
           return TRUE;
@@ -447,15 +451,15 @@ do_spawn (const gchar *scheme, const gchar *command_filename,
   /* Invoke the keyserver helper */
 #ifdef G_OS_UNIX
   /* On Unix, run the helper asyncronously, so that we can update the dialog */
-  g_spawn_async_with_pipes (NULL, helper_argv, NULL, 
+  g_spawn_async_with_pipes (NULL, helper_argv, NULL,
                             G_SPAWN_STDOUT_TO_DEV_NULL|
-                            G_SPAWN_DO_NOT_REAP_CHILD, 
+                            G_SPAWN_DO_NOT_REAP_CHILD,
                             NULL, NULL, &pid, NULL, NULL, &standard_error,
                             &error);
 #else
   /* On Windows, use syncronous spawn */
-  g_spawn_sync (NULL, helper_argv, NULL, 
-		G_SPAWN_STDOUT_TO_DEV_NULL, NULL, NULL, 
+  g_spawn_sync (NULL, helper_argv, NULL,
+		G_SPAWN_STDOUT_TO_DEV_NULL, NULL, NULL,
 		NULL, error_output, exit_status, &error);
 #endif
 
@@ -525,7 +529,7 @@ invoke_helper (const gchar *server, const gchar *scheme,
 
 /* Public functions */
 
-gboolean 
+gboolean
 server_send_keys (const gchar *server, const gchar *keyid,
                   gpgme_data_t data, GtkWidget *parent)
 {
@@ -552,7 +556,7 @@ server_send_keys (const gchar *server, const gchar *keyid,
   dump_data_to_file (data, command);
   fprintf (command, "\nKEY %s END\n", keyid);
   fclose (command);
-  success = invoke_helper (server, scheme, command_filename, 
+  success = invoke_helper (server, scheme, command_filename,
                            &output_filename, parent);
   g_free (keyserver);
   /* Delete temp files */
@@ -564,7 +568,7 @@ server_send_keys (const gchar *server, const gchar *keyid,
   return success;
 }
 
-gboolean 
+gboolean
 server_get_key (const gchar *server, const gchar *keyid,
                 gpgme_data_t *data, GtkWidget *parent)
 {

commit 7bf586c3d5fec9c7db12e208361843fcd2b66163
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Nov 18 20:08:19 2014 +0100

    Add functions gpa_show_info and gpa_show_warning.
    
    * src/gtktools.c (gpa_show_info): New.
    (gpa_show_warning): New.
    (gpa_window_message, gpa_window_error): Make them wrappers fro the new
    functions.
    --
    
    Using the message dialog functions is better than doing it ourselves.
    Note that a title bar is not anymore show but that is compensate by
    the fact that these dialogs do not anymore show up in the taskbar.

diff --git a/src/gtktools.c b/src/gtktools.c
index 973d974..8bf2867 100644
--- a/src/gtktools.c
+++ b/src/gtktools.c
@@ -35,95 +35,65 @@
 #include "icons.h"
 
 
-/* BEGIN of old unchecked code (wk 2008-03-07) */
-
-static char *
-make_box_title (const char *string)
+/* Deprecated - use gpa_show_warning instead.  */
+void
+gpa_window_error (const gchar *message, GtkWidget *messenger)
 {
-  return g_strdup_printf ("%s %s", GPA_NAME, string);
+  gpa_show_warning (messenger, "%s", message);
 }
 
 
+/* Deprecated - use gpa_show_info instead.  */
 void
-gpa_window_error (const gchar *message, GtkWidget *messenger)
+gpa_window_message (const gchar *message, GtkWidget * messenger)
+{
+  gpa_show_info (messenger, "%s", message);
+}
+
+
+static void
+show_gtk_message (GtkWidget *parent, GtkMessageType mtype,
+                  const char *format, va_list arg_ptr)
 {
-  GtkWidget *windowError;
-  GtkWidget *hboxError;
-  GtkWidget *labelMessage;
-  GtkWidget *pixmap;
-  char *title;
-
-  title = make_box_title (_("Error"));
-  windowError = gtk_dialog_new_with_buttons (title,
-                                             (messenger ?
-                                             GTK_WINDOW(messenger) : NULL),
-                                             GTK_DIALOG_MODAL,
-                                             _("_Close"),
-                                             GTK_RESPONSE_CLOSE,
-                                             NULL);
-  g_free (title);
-  if (messenger)
-    gtk_window_set_transient_for (GTK_WINDOW (windowError),
-                                  GTK_WINDOW (messenger));
-
-  gtk_container_set_border_width (GTK_CONTAINER (windowError), 5);
-  gtk_dialog_set_default_response (GTK_DIALOG (windowError),
-                                   GTK_RESPONSE_CLOSE);
-  hboxError = gtk_hbox_new (FALSE, 0);
-  gtk_container_set_border_width (GTK_CONTAINER (hboxError), 5);
-  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (windowError)->vbox),
-                               hboxError);
-  pixmap = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
-                                     GTK_ICON_SIZE_DIALOG);
-  gtk_box_pack_start (GTK_BOX (hboxError), pixmap, TRUE, FALSE, 10);
-  labelMessage = gtk_label_new (message);
-  gtk_box_pack_start (GTK_BOX (hboxError), labelMessage, TRUE, FALSE, 10);
-
-  gtk_widget_show_all (windowError);
-  gtk_dialog_run (GTK_DIALOG (windowError));
-  gtk_widget_destroy (windowError);
+  GtkWidget *dialog;
+  char *buffer;
+
+  buffer = g_strdup_vprintf (format, arg_ptr);
+  dialog = gtk_message_dialog_new (parent? GTK_WINDOW (parent):NULL,
+                                   GTK_DIALOG_MODAL,
+                                   mtype,
+                                   GTK_BUTTONS_CLOSE,
+                                   "%s", buffer);
+  g_free (buffer);
+
+  gtk_widget_show_all (dialog);
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
 }
 
 
+/* Show a modal info message. */
 void
-gpa_window_message (gchar * message, GtkWidget * messenger)
+gpa_show_info (GtkWidget *parent, const char *format, ...)
 {
-  GtkWidget *window;
-  GtkWidget *hbox;
-  GtkWidget *labelMessage;
-  GtkWidget *pixmap;
-  char *title;
-
-  title = make_box_title (_("Message"));
-  window = gtk_dialog_new_with_buttons (title,
-					(messenger ?
-					 GTK_WINDOW(messenger) : NULL),
-					GTK_DIALOG_MODAL,
-					_("_Close"),
-					GTK_RESPONSE_CLOSE,
-					NULL);
-  g_free (title);
-  gtk_container_set_border_width (GTK_CONTAINER (window), 5);
-  gtk_dialog_set_default_response (GTK_DIALOG (window),
-                                   GTK_RESPONSE_CLOSE);
-  hbox = gtk_hbox_new (FALSE, 0);
-  gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
-  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (window)->vbox),
-                               hbox);
-  pixmap = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO,
-                                     GTK_ICON_SIZE_DIALOG);
-  gtk_box_pack_start (GTK_BOX (hbox), pixmap, TRUE, FALSE, 10);
-  labelMessage = gtk_label_new (message);
-  gtk_box_pack_start (GTK_BOX (hbox), labelMessage, TRUE, FALSE, 10);
-
-  gtk_widget_show_all (window);
-  gtk_dialog_run (GTK_DIALOG (window));
-  gtk_widget_destroy (window);
+  va_list arg_ptr;
+
+  va_start (arg_ptr, format);
+  show_gtk_message (parent, GTK_MESSAGE_INFO, format, arg_ptr);
+  va_end (arg_ptr);
 }
 
 
-/* END of old unchecked code (wk 2008-03-07) */
-

+/* Show a modal warning message. */
+void
+gpa_show_warning (GtkWidget *parent, const char *format, ...)
+{
+  va_list arg_ptr;
+
+  va_start (arg_ptr, format);
+  show_gtk_message (parent, GTK_MESSAGE_WARNING, format, arg_ptr);
+  va_end (arg_ptr);
+}
 
 
 /* Set a tooltip TEXT to WIDGET.  TEXT and WIDGET may both be NULL.
diff --git a/src/gtktools.h b/src/gtktools.h
index 3a204ba..41fafc5 100644
--- a/src/gtktools.h
+++ b/src/gtktools.h
@@ -23,9 +23,13 @@
 
 #include <gtk/gtk.h>
 
-extern void gpa_window_error (const gchar * message, GtkWidget * messenger);
-extern void gpa_window_message (gchar * message, GtkWidget * messenger);
 
+/* Show a modal info message. */
+void gpa_show_info (GtkWidget *parent,
+                    const char *format, ...) G_GNUC_PRINTF(2,3);
+/* Show a modal warning message. */
+void gpa_show_warning (GtkWidget *parent,
+                       const char *format, ...) G_GNUC_PRINTF(2,3);
 
 /* Set a tooltip TEXT to WIDGET.  TEXT and WIDGET may both be NULL.
    This function is useful so that GPA can be build with older GTK+
@@ -44,4 +48,10 @@ void gpa_window_set_title (GtkWindow *window, const char *string);
 
 
 
+/* Deprecated functions.  */
+void gpa_window_error (const gchar * message, GtkWidget * messenger);
+void gpa_window_message (const gchar * message, GtkWidget * messenger);
+
+
+
 #endif /* GTK_TOOLS_H_ */

commit 68b7faa05eb825ead05c27bb42860da8390f3a25
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Nov 18 17:03:27 2014 +0100

    Do not show the keyserver setting with gnupg 2.1.0.
    
    * src/settingsdlg.c (_SettingsDlg): Add field gnupg21.
    (settings_dlg_init): Init new field.
    (settings_dlg_constructor): Do not show the keyserver option with
    gnupg 2.1.
    (update_show_advanced_options): Skip the keyserver option with 2.1
    (keyserver_selected_from_list_cb): Ditto.
    (check_default_keyserver): Ditto.
    (load_settings, save_settings): Ditto.

diff --git a/src/settingsdlg.c b/src/settingsdlg.c
index 66bed62..fe9e529 100644
--- a/src/settingsdlg.c
+++ b/src/settingsdlg.c
@@ -58,7 +58,8 @@ struct _SettingsDlg
 {
   GtkDialog parent;
 
-  gboolean modified;  /* True is tehre are unsaved changes.  */
+  gboolean modified;  /* True is there are unsaved changes.  */
+  gboolean gnupg21;   /* True if gnupg 2.1.0 or later is in use.  */
 
   /* Data for the user interface frame.  */
   struct {
@@ -170,7 +171,8 @@ update_show_advanced_options (SettingsDlg *dialog)
   if (gpa_options_get_show_advanced_options (options))
     {
 #ifdef ENABLE_KEYSERVER_SUPPORT
-      gtk_widget_show_all (dialog->keyserver.frame);
+      if (!dialog->gnupg21)
+        gtk_widget_show_all (dialog->keyserver.frame);
 #endif /*ENABLE_KEYSERVER_SUPPORT*/
       if (dialog->akl.enabled)
         gtk_widget_show_all (dialog->akl.frame);
@@ -178,7 +180,8 @@ update_show_advanced_options (SettingsDlg *dialog)
   else
     {
 #ifdef ENABLE_KEYSERVER_SUPPORT
-      gtk_widget_hide_all (dialog->keyserver.frame);
+      if (!dialog->gnupg21)
+        gtk_widget_hide_all (dialog->keyserver.frame);
 #endif /*ENABLE_KEYSERVER_SUPPORT*/
       if (dialog->akl.enabled)
         gtk_widget_hide_all (dialog->akl.frame);
@@ -353,6 +356,9 @@ keyserver_selected_from_list_cb (SettingsDlg *dialog)
 {
   char *text;
 
+  if (dialog->gnupg21)
+    return;
+
   text = gtk_combo_box_get_active_text (dialog->keyserver.combo);
   g_message ("got `%s'", text);
   xfree (dialog->keyserver.url);
@@ -370,6 +376,9 @@ check_default_keyserver (SettingsDlg *dialog)
 {
   keyserver_spec_t kspec;
 
+  if (dialog->gnupg21)
+    return NULL; /* GnuPG manages the keyservers.  */
+
   keyserver_selected_from_list_cb (dialog);
 
   if (!dialog->keyserver.url)
@@ -728,9 +737,13 @@ load_settings (SettingsDlg *dialog)
 
   /* Default keyserver section.  */
 #ifdef ENABLE_KEYSERVER_SUPPORT
-  gtk_entry_set_text (GTK_ENTRY
-                      (gtk_bin_get_child (GTK_BIN (dialog->keyserver.combo))),
-                      gpa_options_get_default_keyserver (options));
+  if (!dialog->gnupg21)
+    {
+      gtk_entry_set_text (GTK_ENTRY
+                          (gtk_bin_get_child
+                           (GTK_BIN (dialog->keyserver.combo))),
+                          gpa_options_get_default_keyserver (options));
+    }
 #endif /*ENABLE_KEYSERVER_SUPPORT*/
 
   /* AKL section. */
@@ -758,13 +771,16 @@ save_settings (SettingsDlg *dialog)
     }
 
 #ifdef ENABLE_KEYSERVER_SUPPORT
-  if ((errwdg = check_default_keyserver (dialog)))
+  if (!dialog->gnupg21)
     {
-      gpa_window_error
-        (_("The URL given for the keyserver is not valid."),
-         GTK_WIDGET (dialog));
-      gtk_widget_grab_focus (errwdg);
-      return -1;
+      if ((errwdg = check_default_keyserver (dialog)))
+        {
+          gpa_window_error
+            (_("The URL given for the keyserver is not valid."),
+             GTK_WIDGET (dialog));
+          gtk_widget_grab_focus (errwdg);
+          return -1;
+        }
     }
 #endif /*ENABLE_KEYSERVER_SUPPORT*/
 
@@ -893,7 +909,7 @@ static void
 settings_dlg_init (SettingsDlg *dialog)
 {
   dialog->akl.method_idx = -1;
-
+  dialog->gnupg21 = is_gpg_version_at_least ("2.1.0");
 }
 
 
@@ -931,15 +947,21 @@ settings_dlg_constructor (GType type, guint n_construct_properties,
   frame = default_key_frame (dialog);
   gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame);
 
-  /* The default keyserver section.  */
+  /* The default keyserver section.  Note that there is no keyserver
+     entry if we are using gnupg 2.1.  There we do not have the
+     keyserver helpers anymore and thus the keyservers are to be
+     enabled in the backend preferences. */
 #ifdef ENABLE_KEYSERVER_SUPPORT
-  frame = default_keyserver_frame (dialog);
-  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
-                      FALSE, FALSE, 0);
+  if (!dialog->gnupg21)
+    {
+      frame = default_keyserver_frame (dialog);
+      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame,
+                          FALSE, FALSE, 0);
+    }
 #endif /*ENABLE_KEYSERVER_SUPPORT*/
 
   /* The auto key locate section.  */
-  dialog->akl.enabled = is_gpg_version_at_least ("2.0.10");
+  dialog->akl.enabled = dialog->gnupg21;
   if (dialog->akl.enabled)
     {
       frame = auto_key_locate_frame (dialog);

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

Summary of changes:
 src/gpaexportclipop.c   |    4 +-
 src/gpaimportclipop.c   |   35 ++++++-------
 src/gpaimportfileop.c   |   14 +++---
 src/gpaimportop.c       |   78 +++++++++++++++--------------
 src/gpaimportop.h       |    9 ++--
 src/gpaimportserverop.c |  125 ++++++++++++++++++++++++++++++++++++++++++++---
 src/gparecvkeydlg.c     |   48 +++++++++++-------
 src/gtktools.c          |  120 +++++++++++++++++----------------------------
 src/gtktools.h          |   14 +++++-
 src/server-access.c     |   42 +++++++++-------
 src/settingsdlg.c       |   58 +++++++++++++++-------
 11 files changed, 342 insertions(+), 205 deletions(-)


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




More information about the Gnupg-commits mailing list