[Gpa-commits] r995 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 14 11:25:52 CEST 2009


Author: werner
Date: 2009-05-14 11:25:51 +0200 (Thu, 14 May 2009)
New Revision: 995

Modified:
   trunk/src/ChangeLog
   trunk/src/cardman.c
   trunk/src/cm-openpgp.c
   trunk/src/cm-openpgp.h
   trunk/src/gpagenkeyadvop.c
   trunk/src/gpagenkeycardop.c
   trunk/src/gpagenkeycardop.h
   trunk/src/gpgmeedit.c
   trunk/src/gpgmetools.c
   trunk/src/gpgmetools.h
   trunk/src/keygendlg.c
   trunk/src/keygendlg.h
Log:
Improved card key generation


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/ChangeLog	2009-05-14 09:25:51 UTC (rev 995)
@@ -1,3 +1,35 @@
+2009-05-14  Werner Koch  <wk at g10code.com>
+
+	* cm-openpgp.c (struct _GpaCMOpenpgp): Add field KEY_ATTRIBUTES.
+	(gpa_cm_openpgp_finalize): Release it.
+	(update_entry_key_attr): Set them.
+	(gpa_cm_openpgp_get_key_attributes): New.
+	* gpagenkeycardop.h (struct _GpaGenKeyCardOperation): Add field
+	KEY_ATTRIBUTES and R_ERROR_DESC.
+	* gpagenkeycardop.c (gpa_gen_key_card_operation_finalize): Release
+	these fields.
+	(gpa_gen_key_card_operation_new): Set that field.
+	(gpa_gen_key_card_operation_idle_cb): Pass it to the generate fnc.
+	(gpa_gen_key_card_operation_done_error_cb): Print status error.
+	* keygendlg.c (gpa_key_gen_run_dialog): Change arg FORCARD to a
+	string.
+	(create_dialog): Show the key attributes of a card. Add backup
+	checkbox.
+	(gpa_key_gen_run_dialog): Store backup flag in the params.
+	* gpgmetools.h (gpa_keygen_para_t): Add field BACKUP and R_ERROR_DESC.
+	* gpgmeedit.c (struct genkey_parms_s): Add field BACKUP.
+	(card_edit_genkey_parms_new): Set that field.
+	(card_edit_genkey_fnc_action): Use that field.
+	(struct edit_parms_s): Add fucntion ptr SAVE_ERROR.
+	(edit_fnc): Call it.
+	(gpa_gpgme_edit_trust_parms_new, gpa_gpgme_edit_expire_parms_new)
+	(gpa_gpgme_edit_sign_parms_new, gpa_gpgme_edit_passwd_parms_new):
+	Use g_malloc0.
+	(card_edit_genkey_save_error): New.
+	(edit_fnc): Ignore STATUS_PROGRESS.
+
+	* gpgmetools.c (gpa_gpgme_warning_ext): New.
+
 2009-05-13  Werner Koch  <wk at g10code.com>
 
 	* helpmenu.c (gpa_help_about): Show GnuPG version.

Modified: trunk/src/cardman.c
===================================================================
--- trunk/src/cardman.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/cardman.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -549,6 +549,7 @@
 {
   GpaGenKeyCardOperation *op;
   gpg_error_t err;
+  char *keyattr;
 
   if (cardman->cardtype != GPA_CM_OPENPGP_TYPE)
     return;  /* Not possible.  */
@@ -572,8 +573,11 @@
       return;
     }
 
+  keyattr = (cardman->card_widget
+             ? gpa_cm_openpgp_get_key_attributes (cardman->card_widget)
+             : NULL);
 
-  op = gpa_gen_key_card_operation_new (GTK_WIDGET (cardman));
+  op = gpa_gen_key_card_operation_new (GTK_WIDGET (cardman), keyattr);
   g_signal_connect_swapped (G_OBJECT (op), "completed",
                             G_CALLBACK (card_genkey_completed), cardman);
   g_signal_connect (G_OBJECT (op), "completed",

Modified: trunk/src/cm-openpgp.c
===================================================================
--- trunk/src/cm-openpgp.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/cm-openpgp.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -91,6 +91,10 @@
     int nbits;
   } key_attr[3];
 
+  /* A malloced string with the key attributes in a human readable
+     format.  */
+  char *key_attributes;
+
   GtkLabel  *puk_label;  /* The label of the PUK field.  */
 
   /* An array with the current value of the retry counters.  */
@@ -476,13 +480,15 @@
           buf = tmpbuf;
         }
 
+      g_free (card->key_attributes);
+      card->key_attributes = buf;
+
       s = gtk_label_get_text (GTK_LABEL (card->entries[ENTRY_VERSION]));
       if (!s)
         s = "";
-      tmpbuf = g_strdup_printf ("%s  (%s)", s, buf);
+      buf = g_strdup_printf ("%s  (%s)", s, card->key_attributes);
+      gtk_label_set_text (GTK_LABEL (card->entries[ENTRY_VERSION]), buf);
       g_free (buf);
-      gtk_label_set_text (GTK_LABEL (card->entries[ENTRY_VERSION]), tmpbuf);
-      g_free (tmpbuf);
     }
 }
 
@@ -1528,8 +1534,11 @@
 static void
 gpa_cm_openpgp_finalize (GObject *object)
 {  
-/*   GpaCMOpenpgp *card = GPA_CM_OPENPGP (object); */
+  GpaCMOpenpgp *card = GPA_CM_OPENPGP (object);
 
+  xfree (card->key_attributes);
+  card->key_attributes = NULL;
+
   parent_class->finalize (object);
 }
 
@@ -1588,3 +1597,10 @@
         reload_data (GPA_CM_OPENPGP (widget));
     }
 }
+
+char *
+gpa_cm_openpgp_get_key_attributes (GtkWidget *widget)
+{
+  g_return_val_if_fail (GPA_IS_CM_OPENPGP (widget), NULL);
+  return g_strdup (GPA_CM_OPENPGP (widget)->key_attributes);
+}

Modified: trunk/src/cm-openpgp.h
===================================================================
--- trunk/src/cm-openpgp.h	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/cm-openpgp.h	2009-05-14 09:25:51 UTC (rev 995)
@@ -51,6 +51,7 @@
 /* The class specific API.  */
 GtkWidget *gpa_cm_openpgp_new (void);
 void gpa_cm_openpgp_reload (GtkWidget *widget, gpgme_ctx_t gpgagent);
+char *gpa_cm_openpgp_get_key_attributes (GtkWidget *widget);
 
 
 

Modified: trunk/src/gpagenkeyadvop.c
===================================================================
--- trunk/src/gpagenkeyadvop.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpagenkeyadvop.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -152,7 +152,7 @@
   gpg_error_t err;
   gpa_keygen_para_t *parms;
   
-  parms = gpa_key_gen_run_dialog (GPA_OPERATION (op)->window, 0);
+  parms = gpa_key_gen_run_dialog (GPA_OPERATION (op)->window, NULL);
   if (!parms)
     g_signal_emit_by_name (op, "completed", gpg_error (GPG_ERR_CANCELED));
   else

Modified: trunk/src/gpagenkeycardop.c
===================================================================
--- trunk/src/gpagenkeycardop.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpagenkeycardop.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -56,7 +56,11 @@
 {
   GpaGenKeyCardOperation *op = GPA_GEN_KEY_CARD_OPERATION (object);
 
+  xfree (op->key_attributes);
+  op->key_attributes = NULL;
   gtk_widget_destroy (op->progress_dialog);
+  gpa_keygen_para_free (op->parms);
+  op->parms = NULL;
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -136,12 +140,13 @@
 /* API */
 
 GpaGenKeyCardOperation* 
-gpa_gen_key_card_operation_new (GtkWidget *window)
+gpa_gen_key_card_operation_new (GtkWidget *window, const char *keyattr)
 {
   GpaGenKeyCardOperation *op;
   
   op = g_object_new (GPA_GEN_KEY_CARD_OPERATION_TYPE,
 		     "window", window, NULL);
+  op->key_attributes = g_strdup (keyattr);
 
   return op;
 }
@@ -153,14 +158,16 @@
 {
   GpaGenKeyCardOperation *op = data;
   gpg_error_t err;
-  gpa_keygen_para_t *parms;
   
-  parms = gpa_key_gen_run_dialog (GPA_OPERATION (op)->window, 1);
-  if (!parms)
+  op->parms = gpa_key_gen_run_dialog 
+    (GPA_OPERATION (op)->window, op->key_attributes? op->key_attributes : "");
+
+  if (!op->parms)
     g_signal_emit_by_name (op, "completed", gpg_error (GPG_ERR_CANCELED));
   else
     {
-      err = gpa_gpgme_card_edit_genkey_start (GPA_OPERATION (op)->context, parms);
+      err = gpa_gpgme_card_edit_genkey_start (GPA_OPERATION (op)->context,
+                                              op->parms);
       if (err)
         {
           gpa_gpgme_warning (err);
@@ -169,7 +176,7 @@
       else
         gtk_widget_show_all (op->progress_dialog);
     }
-  return FALSE;
+  return FALSE;  /* Remove this idle function.  */
 }
 
 
@@ -201,7 +208,7 @@
       /* Ignore these */
       break;
     default:
-      gpa_gpgme_warning (err);
+      gpa_gpgme_warning_ext (err, op->parms? op->parms->r_error_desc : NULL);
       break;
     }
 }

Modified: trunk/src/gpagenkeycardop.h
===================================================================
--- trunk/src/gpagenkeycardop.h	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpagenkeycardop.h	2009-05-14 09:25:51 UTC (rev 995)
@@ -39,10 +39,13 @@
 typedef struct _GpaGenKeyCardOperation GpaGenKeyCardOperation;
 typedef struct _GpaGenKeyCardOperationClass GpaGenKeyCardOperationClass;
 
-struct _GpaGenKeyCardOperation {
+struct _GpaGenKeyCardOperation 
+{
   GpaGenKeyOperation parent;
-
+  
   GtkWidget *progress_dialog;
+  char *key_attributes;
+  gpa_keygen_para_t *parms;
 };
 
 struct _GpaGenKeyCardOperationClass {
@@ -54,6 +57,7 @@
 
 /* API */
 
-GpaGenKeyCardOperation *gpa_gen_key_card_operation_new (GtkWidget *window);
+GpaGenKeyCardOperation *gpa_gen_key_card_operation_new (GtkWidget *window,
+                                                        const char *keyattr);
 
 #endif

Modified: trunk/src/gpgmeedit.c
===================================================================
--- trunk/src/gpgmeedit.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpgmeedit.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -56,6 +56,7 @@
                                const char *args, void *opaque,
                                gpg_error_t *err);
 
+
 /* States for the edit expire command.  */
 enum
   {
@@ -176,6 +177,11 @@
   /* The transit function */
   edit_transit_t transit;
 
+  /* This optional function is called with a string describing the
+     error conveyed by the GPGME_STATUS_ERROR message.  The function
+     takes ownership of the malloced string.  */
+  void (*save_error) (void *opaque, char *errdesc);
+
   /* The output data object */
   gpgme_data_t out;
 
@@ -209,7 +215,8 @@
       || status == GPGME_STATUS_BAD_PASSPHRASE
       || status == GPGME_STATUS_USERID_HINT
       || status == GPGME_STATUS_SIGEXPIRED
-      || status == GPGME_STATUS_KEYEXPIRED)
+      || status == GPGME_STATUS_KEYEXPIRED
+      || status == GPGME_STATUS_PROGRESS)
     {
       return parms->err;
     }
@@ -219,6 +226,15 @@
       return parms->err;
     }
 
+  /* Call the save_error function.  */
+  if (status == GPGME_STATUS_ERROR && args && parms->save_error)
+    {
+      int n = strcspn (args, " \t");
+      char *buf = g_strdup_printf ("%.*s: %s", n, args,
+                                   gpg_strerror (strtoul (args+n, NULL, 10)));
+      parms->save_error (parms->opaque, buf);
+    }
+
 #if DEBUG_FSM
   g_debug ("edit_fnc: state=%d input=%d (%s)", parms->state, status, args);
 #endif
@@ -844,13 +860,11 @@
 gpa_gpgme_edit_trust_parms_new (GpaContext *ctx, const char *trust_string,
 				gpgme_data_t out)
 {
-  struct edit_parms_s *edit_parms = g_malloc (sizeof (struct edit_parms_s));
+  struct edit_parms_s *edit_parms = g_malloc0 (sizeof (struct edit_parms_s));
 
   edit_parms->state = TRUST_START;
-  edit_parms->err = gpg_error (GPG_ERR_NO_ERROR);
   edit_parms->action = edit_trust_fnc_action;
   edit_parms->transit = edit_trust_fnc_transit;
-  edit_parms->signal_id = 0;
   edit_parms->out = out;
   edit_parms->opaque = g_strdup (trust_string);
 
@@ -907,15 +921,13 @@
 gpa_gpgme_edit_expire_parms_new (GpaContext *ctx, GDate *date,
 				 gpgme_data_t out)
 {
-  struct edit_parms_s *edit_parms = g_malloc (sizeof (struct edit_parms_s));
+  struct edit_parms_s *edit_parms = g_malloc0 (sizeof (struct edit_parms_s));
   int buf_len = 12;
   gchar *buf = g_malloc (buf_len);
 
   edit_parms->state = EXPIRE_START;
-  edit_parms->err = gpg_error (GPG_ERR_NO_ERROR);
   edit_parms->action = edit_expire_fnc_action;
   edit_parms->transit = edit_expire_fnc_transit;
-  edit_parms->signal_id = 0;
   edit_parms->out = out;
   edit_parms->opaque = buf;
 
@@ -980,14 +992,12 @@
 gpa_gpgme_edit_sign_parms_new (GpaContext *ctx, char *check_level,
 			       gboolean local, gpgme_data_t out)
 {
-  struct sign_parms_s *sign_parms = g_malloc (sizeof (struct sign_parms_s));
-  struct edit_parms_s *edit_parms = g_malloc (sizeof (struct edit_parms_s));
+  struct sign_parms_s *sign_parms = g_malloc0 (sizeof (struct sign_parms_s));
+  struct edit_parms_s *edit_parms = g_malloc0 (sizeof (struct edit_parms_s));
 
   edit_parms->state = SIGN_START;
-  edit_parms->err = gpg_error (GPG_ERR_NO_ERROR);
   edit_parms->action = edit_sign_fnc_action;
   edit_parms->transit = edit_sign_fnc_transit;
-  edit_parms->signal_id = 0;
   edit_parms->out = out;
   edit_parms->opaque = sign_parms;
   sign_parms->check_level = check_level;
@@ -1090,15 +1100,13 @@
 static struct edit_parms_s*
 gpa_gpgme_edit_passwd_parms_new (GpaContext *ctx, gpgme_data_t out)
 {
-  struct edit_parms_s *edit_parms = g_malloc (sizeof (struct edit_parms_s));
-  struct passwd_parms_s *passwd_parms = g_malloc (sizeof 
-						  (struct passwd_parms_s));
+  struct edit_parms_s *edit_parms = g_malloc0 (sizeof (struct edit_parms_s));
+  struct passwd_parms_s *passwd_parms = g_malloc0 (sizeof 
+                                                   (struct passwd_parms_s));
 
   edit_parms->state = PASSWD_START;
-  edit_parms->err = gpg_error (GPG_ERR_NO_ERROR);
   edit_parms->action = edit_passwd_fnc_action;
   edit_parms->transit = edit_passwd_fnc_transit;
-  edit_parms->signal_id = 0;
   edit_parms->out = out;
   edit_parms->opaque = passwd_parms;
   gpgme_get_passphrase_cb (ctx->ctx, &passwd_parms->func,
@@ -1157,6 +1165,8 @@
   char *name;
   char *email;
   char *comment;
+  gboolean backup;
+  char **error_desc_adr;
 };
 
 
@@ -1181,9 +1191,7 @@
       break;
 
     case CARD_GENERATE_BACKUP:
-      /* FIXME: disable encryption key backup functionality for
-	 now. -mo  */
-      *result = "N";
+      *result = parms->backup? "Y":"N";
       break;
 
     case CARD_GENERATE_REPLACE_KEYS:
@@ -1402,7 +1410,20 @@
 }
 
 
+
 static void
+card_edit_genkey_save_error (void *opaque, char *errdesc)
+{
+  struct genkey_parms_s *parms = opaque;
+
+  if (*parms->error_desc_adr)
+    xfree (errdesc); /* Already set.  */
+  else
+    *parms->error_desc_adr = errdesc;
+}
+
+
+static void
 card_edit_genkey_parms_release (GpaContext *ctx, gpg_error_t err,
 				struct edit_parms_s *parms)
 {
@@ -1431,6 +1452,7 @@
   edit_parms->state = CARD_START;
   edit_parms->action = card_edit_genkey_fnc_action;
   edit_parms->transit = card_edit_genkey_fnc_transit;
+  edit_parms->save_error = card_edit_genkey_save_error;
   edit_parms->out = out;
   edit_parms->opaque = genkey_parms;
 
@@ -1448,6 +1470,8 @@
   genkey_parms->name = parms->name;
   genkey_parms->email = parms->email;
   genkey_parms->comment = parms->comment;
+  genkey_parms->backup = parms->backup;
+  genkey_parms->error_desc_adr = &parms->r_error_desc;
 
   /* Make sure the cleanup is run when the edit completes */
   edit_parms->signal_id =
@@ -1477,4 +1501,3 @@
 
   return err;
 }
-

Modified: trunk/src/gpgmetools.c
===================================================================
--- trunk/src/gpgmetools.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpgmetools.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -82,19 +82,39 @@
 
 
 void
-gpa_gpgme_warning (gpg_error_t err)
+gpa_gpgme_warning_ext (gpg_error_t err, const char *desc)
 {
-  gchar *message = g_strdup_printf 
+  char *argbuf = NULL;
+  const char *arg;
+  char *message;
+
+  if (desc && (!err || gpg_err_code (err) == GPG_ERR_GENERAL))
+    arg = desc;
+  else if (desc)
+    {
+      argbuf = g_strdup_printf ("%s (%s)", gpgme_strerror (err), desc);
+      arg = argbuf;
+    }
+  else
+    arg = gpgme_strerror (err);
+
+  message = g_strdup_printf 
     (_("The GPGME library returned an unexpected\n"
        "error. The error was:\n\n"
        "\t%s\n\n"
        "This is probably a bug in GPA.\n"
        "GPA will now try to recover from this error."),
-     gpgme_strerror (err));
+     arg);
+  g_free (argbuf);
   gpa_window_error (message, NULL);
   g_free (message);
 }
 
+void
+gpa_gpgme_warning (gpg_error_t err)
+{
+  gpa_gpgme_warning_ext (err, NULL);
+}
 
 /* Initialize a gpgme_ctx_t for use with GPA.  */
 gpgme_ctx_t
@@ -569,10 +589,14 @@
 void
 gpa_keygen_para_free (gpa_keygen_para_t *params)
 {
-  g_free (params->name);
-  g_free (params->email);
-  g_free (params->comment);
-  g_free (params);
+  if (params)
+    {
+      g_free (params->name);
+      g_free (params->email);
+      g_free (params->comment);
+      g_free (params->r_error_desc);
+      g_free (params);
+    }
 }
 
 

Modified: trunk/src/gpgmetools.h
===================================================================
--- trunk/src/gpgmetools.h	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/gpgmetools.h	2009-05-14 09:25:51 UTC (rev 995)
@@ -59,6 +59,12 @@
   /* Epiration date.  It is only used if it is valid.  */
   GDate expire;
 
+  /* True if the encryption key is created with an backup file.  */
+  gboolean backup;
+
+  /* Used to return an error description.  */
+  char *r_error_desc;
+
 } gpa_keygen_para_t;
 
 
@@ -69,6 +75,7 @@
 void _gpa_gpgme_error (gpg_error_t err, const char *file, int line);
 
 /* The same as gpa_gpgme_error, without quitting.  */
+void gpa_gpgme_warning_ext (gpg_error_t err, const char *desc);
 void gpa_gpgme_warning (gpg_error_t err);
 
 /* Initialize a gpgme_ctx_t for use with GPA.  */

Modified: trunk/src/keygendlg.c
===================================================================
--- trunk/src/keygendlg.c	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/keygendlg.c	2009-05-14 09:25:51 UTC (rev 995)
@@ -58,6 +58,7 @@
   GtkWidget *entry_email;
   GtkWidget *entry_comment;
   GtkWidget *entry_expire;
+  GtkWidget *entry_backup;
 
   GtkWidget *label_userid;
 };
@@ -132,12 +133,13 @@
 
 /* Helper to create the dialog.  PARENT is the parent window.  */
 static void
-create_dialog (GpaKeyGenDlg *self, GtkWidget *parent)
+create_dialog (GpaKeyGenDlg *self, GtkWidget *parent, const char *forcard)
 {
   GtkWidget *dialog;
   GtkWidget *vbox;
   GtkWidget *table;
 
+  GtkWidget *hbox;
   GtkWidget *label;
   GtkWidget *combo;
   GtkWidget *entry;
@@ -147,7 +149,7 @@
 
 
   dialog = gtk_dialog_new_with_buttons
-    (self->forcard ? _("Generate new keys on card") : _("Generate key"),
+    (forcard ? _("Generate card key") : _("Generate key"),
      GTK_WINDOW (parent),
      GTK_DIALOG_MODAL,
      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@@ -163,19 +165,26 @@
   vbox = GTK_DIALOG (dialog)->vbox;
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
 
-  table = gtk_table_new (7, 2, FALSE);
+  table = gtk_table_new (9, 2, FALSE);
   gtk_container_set_border_width (GTK_CONTAINER (table), 5);
   gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
   rowidx = 0;
 
+  label = gtk_label_new_with_mnemonic (_("_Algorithm: "));
+  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, rowidx, rowidx+1,
+                    GTK_FILL, GTK_SHRINK, 0, 0);
 
-  if (!self->forcard)
+  if (forcard)
     {
-      label = gtk_label_new_with_mnemonic (_("_Algorithm: "));
-      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
-      gtk_table_attach (GTK_TABLE (table), label, 0, 1, rowidx, rowidx+1,
+      label = gtk_label_new (forcard);
+      gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+      gtk_table_attach (GTK_TABLE (table), label, 1, 2, rowidx, rowidx+1,
                         GTK_FILL, GTK_SHRINK, 0, 0);
-      
+      rowidx++;
+    }
+  else
+    {
       combo = gtk_combo_box_new_text ();
       for (idx=0; algorithm_table[idx].name; idx++)
 	gtk_combo_box_append_text (GTK_COMBO_BOX (combo), 
@@ -212,9 +221,14 @@
   rowidx++;
 
 
+  label = gtk_label_new_with_mnemonic (_("User ID: "));
+  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, rowidx, rowidx+1,
+		    GTK_FILL, GTK_SHRINK, 0, 0);
   label = gtk_label_new (NULL);
-  gtk_table_attach (GTK_TABLE (table), label, 0, 2, rowidx, rowidx+1,
-                    GTK_FILL, GTK_FILL, 0, 0);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+  gtk_table_attach (GTK_TABLE (table), label, 1, 2, rowidx, rowidx+1,
+                    GTK_FILL, GTK_SHRINK, 0, 0);
   self->label_userid = label;
   rowidx++;
 
@@ -223,14 +237,14 @@
                     GTK_FILL, GTK_FILL, 0, 0);
   rowidx++;
 
-  label = gtk_label_new_with_mnemonic (_("_User ID: "));
+  label = gtk_label_new_with_mnemonic (_("_Name: "));
   gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
   gtk_table_attach (GTK_TABLE (table), label, 0, 1, rowidx, rowidx+1,
 		    GTK_FILL, GTK_SHRINK, 0, 0);
   entry = gtk_entry_new ();
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, rowidx, rowidx+1,
-                    GTK_FILL, GTK_SHRINK, 0, 0);
+                    GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
   self->entry_name = entry;
   g_signal_connect (G_OBJECT (entry), "changed",
                     G_CALLBACK (update_preview_cb), self);
@@ -243,7 +257,7 @@
   entry = gtk_entry_new ();
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, rowidx, rowidx+1,
-                    GTK_FILL, GTK_SHRINK, 0, 0);
+                    GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
   self->entry_email = entry;
   g_signal_connect (G_OBJECT (entry), "changed",
                     G_CALLBACK (update_preview_cb), self);
@@ -256,7 +270,7 @@
   entry = gtk_entry_new ();
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
   gtk_table_attach (GTK_TABLE (table), entry, 1, 2, rowidx, rowidx+1,
-                    GTK_FILL, GTK_SHRINK, 0, 0);
+                    GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
   self->entry_comment = entry;
   g_signal_connect (G_OBJECT (entry), "changed",
                     G_CALLBACK (update_preview_cb), self);
@@ -270,25 +284,45 @@
   gtk_table_attach (GTK_TABLE (table), button, 1, 2, rowidx, rowidx+1,
                     GTK_FILL, GTK_SHRINK, 0, 0);
   self->entry_expire = button;
+  rowidx++;
 
+  label = gtk_label_new_with_mnemonic (_("Backup: "));
+  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1, rowidx, rowidx+1,
+                    GTK_FILL, GTK_SHRINK, 0, 0);
+  button = gtk_check_button_new ();
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+  hbox = gtk_hbox_new (FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, rowidx, rowidx+1,
+                    GTK_FILL, GTK_SHRINK, 0, 0);
+  self->entry_backup = button;
+  gpa_add_tooltip (hbox,
+                   _("If checked the encryption key will be created "
+                     "and stored to a backup file and then loaded into "
+                     "the card.  This is recommended so that encrypted "
+                     "messages can be decrypted even if the card has a "
+                     "malfunction."));
+
 }
 
 
 /* Run the "Generate Key" dialog and if the user presses OK, return
    the values from the dialog in a newly allocated gpa_keygen_para_t
-   struct.  If FORCARD is true, display the dialog suitable for
-   generation keys on the OpenPGP smartcard. If the user pressed
-   "Cancel", return NULL.  The returned struct has to be freed with
-   gpa_keygen_para_free.  */
+   struct.  If FORCARD is not NULL display a dialog suitable for
+   generation of keys on the OpenPGP smartcard; thye string will be
+   shown to identify the capabilities of the card.  If the user
+   pressed "Cancel", return NULL.  The returned struct has to be freed
+   with gpa_keygen_para_free.  */
 gpa_keygen_para_t *
-gpa_key_gen_run_dialog (GtkWidget *parent, gboolean forcard)
+gpa_key_gen_run_dialog (GtkWidget *parent, const char *forcard)
 {
   GpaKeyGenDlg *self;
   gpa_keygen_para_t *params;
 
   self = xcalloc (1, sizeof *self);
-  self->forcard = forcard;
-  create_dialog (self, parent);
+  self->forcard = !!forcard;
+  create_dialog (self, parent, forcard);
   g_signal_connect (G_OBJECT (self->dialog), "response",
                     G_CALLBACK (response_cb), self);
 
@@ -335,6 +369,9 @@
       
   gpa_date_box_get_date (GPA_DATE_BOX (self->entry_expire), &params->expire);
 
+  params->backup = gtk_toggle_button_get_active 
+    (GTK_TOGGLE_BUTTON (self->entry_backup));
+
   gtk_widget_destroy (self->dialog);
   g_free (self);
 

Modified: trunk/src/keygendlg.h
===================================================================
--- trunk/src/keygendlg.h	2009-05-13 18:03:40 UTC (rev 994)
+++ trunk/src/keygendlg.h	2009-05-14 09:25:51 UTC (rev 995)
@@ -26,7 +26,7 @@
 #include "gpgmetools.h"
 
 gpa_keygen_para_t * gpa_key_gen_run_dialog (GtkWidget *parent, 
-                                              gboolean forcard);
+                                            const char *forcard);
 
 
 #endif /* KEYSIGNDLG_H */



More information about the Gpa-commits mailing list