[Gpa-commits] r939 - in trunk: . src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Jan 26 15:17:02 CET 2009


Author: werner
Date: 2009-01-26 15:17:00 +0100 (Mon, 26 Jan 2009)
New Revision: 939

Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/ChangeLog
   trunk/src/cardman.c
   trunk/src/gpaoperation.c
   trunk/src/gpapinchange.c
Log:
Cleanups.
Experimental use of gpgme_op_assuan_transact.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/ChangeLog	2009-01-26 14:17:00 UTC (rev 939)
@@ -1,3 +1,7 @@
+2009-01-26  Werner Koch  <wk at g10code.com>
+
+	* configure.ac: Check for gpgme_op_assuan_transact.
+
 2009-01-17  Moritz  <moritz at gnu.org>
 
 	* configure.ac: Use AC_CHECK_HEADERS to check for locale.h.

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/configure.ac	2009-01-26 14:17:00 UTC (rev 939)
@@ -202,6 +202,9 @@
 AM_PATH_LIBASSUAN("$NEED_LIBASSUAN_API:$NEED_LIBASSUAN_VERSION",
                   have_libassuan=yes,have_libassuan=no)
 
+# We need this for GPGME
+AC_SYS_LARGEFILE
+
 #
 # Depending on the OS we need to test for different versions of gpgme.
 #
@@ -217,9 +220,11 @@
   AM_PATH_GPGME("$NEED_GPGME_API:$NEED_GPGME_VERSION",
                 have_gpgme=yes,have_gpgme=no)
 fi
+_save_libs=$LIBS
+LIBS="$LIBS $GPGME_LIBS"
+AC_CHECK_FUNCS([gpgme_op_assuan_transact])
+LIBS=$_save_libs
 
-# We need this for GPGME
-AC_SYS_LARGEFILE
 
 #
 # Checks for header files.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/src/ChangeLog	2009-01-26 14:17:00 UTC (rev 939)
@@ -1,3 +1,15 @@
+2009-01-26  Werner Koch  <wk at g10code.com>
+
+	* cardman.c (ADD_TABLE_ROW): Replace macro by ..
+	(add_table_row): New function.
+	(struct _GpaCardManager): Add fields GENERAL_FRAME, PERSONAL_FRAME
+	and KEYS_FRAME.
+	(construct_card_widget): Initialize them and add new field for the
+	card type.
+	(card_reload_cb): Show the card type.
+	(update_info_visibility): Hide only the personal and keys frame.
+	(get_serial_direct, opass_status_cb): New.
+
 2009-01-17  Moritz  <moritz at gnu.org>
 
 	* cardman.c: Include "convert.h".
@@ -22,7 +34,7 @@
 	* gpapinchange.h, gpapinchange.c: New.
 	* Makefile.am (gpa_SOURCES): Add them
 
-	* convert.c (gpa_unit_expiry_time_string): Change retrun type to
+	* convert.c (gpa_unit_expiry_time_string): Change return type to
 	const char.  Do bounds checks.
 	(gpa_time_unit_from_string): Take a const char * arg.  Make code
 	more robust.

Modified: trunk/src/cardman.c
===================================================================
--- trunk/src/cardman.c	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/src/cardman.c	2009-01-26 14:17:00 UTC (rev 939)
@@ -57,7 +57,11 @@
   GtkUIManager *ui_manager;
 
   GtkWidget *card_widget;     /* The container of all the info widgets.  */
+  GtkWidget *general_frame;
+  GtkWidget *personal_frame;
+  GtkWidget *keys_frame;
 
+  GtkWidget *entryType;
   GtkWidget *entrySerialno;
   GtkWidget *entryVersion;
   GtkWidget *entryManufacturer;
@@ -170,10 +174,12 @@
       
       statusbar_update (cardman, tmp);
       xfree (tmp);
-      if (cardman->is_openpgp)
-        gtk_widget_show_all (cardman->card_widget);
-      else
-        gtk_widget_hide_all (cardman->card_widget);
+      gtk_widget_show_all (cardman->card_widget);
+      if (!cardman->is_openpgp)
+        {
+          gtk_widget_hide_all (cardman->personal_frame);
+          gtk_widget_hide_all (cardman->keys_frame);
+        }
     }
   else
     {
@@ -183,6 +189,52 @@
 }
 
 
+#ifdef HAVE_GPGME_OP_ASSUAN_TRANSACT  
+static gpg_error_t
+opass_status_cb (void *opaque, const char *status, const char *args)
+{
+  GpaCardManager *cardman = opaque;
+
+  if (!strcmp (status, "SERIALNO"))
+    gtk_entry_set_text (GTK_ENTRY (cardman->entrySerialno), args);
+
+  return 0;
+}     
+#endif /*HAVE_GPGME_OP_ASSUAN_TRANSACT*/
+
+
+static void
+get_serial_direct (GpaCardManager *cardman)
+{
+#ifdef HAVE_GPGME_OP_ASSUAN_TRANSACT  
+  gpg_error_t err;
+  gpgme_ctx_t ctx;
+
+  ctx = gpa_gpgme_new ();
+  err = gpgme_set_protocol (ctx, GPGME_PROTOCOL_ASSUAN);
+  if (err)
+    goto leave;
+      
+  err = gpgme_op_assuan_transact (ctx, "SCD SERIALNO",
+                                  NULL, NULL, NULL, NULL,
+                                  opass_status_cb, cardman);
+  if (!err)
+    err = gpgme_op_assuan_result (ctx);
+
+  /* Nothing to do because the status cb takes care of updating the
+     serialno.  */
+
+ leave:
+  gpgme_release (ctx);
+  if (err)
+    g_debug ("gpgme_op_assuan_transact failed: %s <%s>",
+             gpg_strerror (err), gpg_strsource (err));
+#endif /*HAVE_GPGME_OP_ASSUAN_TRANSACT*/
+}
+
+
+
+
 /* This is the callback used by the GpaCardReloadOp object. It's
    called for each data item during a reload operation and updates the
    according widgets. */
@@ -203,18 +255,32 @@
         }
       else if (idx == 1)
         {
+          const char *cardtype;
+
           if (!strcmp (string, "openpgp-card"))
             {
-              cardman->cardtype = "OpenPGP";
+              cardman->cardtype = cardtype = "OpenPGP";
               cardman->is_openpgp = 1;
             }
           else if (!strcmp (string, "netkey-card"))
-            cardman->cardtype = "NetKey";
+            cardman->cardtype = cardtype = "NetKey";
           else if (!strcmp (string, "dinsig-card"))
-            cardman->cardtype = "DINSIG";
+            cardman->cardtype = cardtype = "DINSIG";
           else if (!strcmp (string, "pkcs15-card"))
-            cardman->cardtype = "PKCS#15";
+            cardman->cardtype = cardtype = "PKCS#15";
+          else
+            cardtype = string;
 
+          gtk_entry_set_text (GTK_ENTRY (cardman->entryType), cardtype);
+          if (!cardman->is_openpgp)
+            {
+              gtk_entry_set_text (GTK_ENTRY (cardman->entrySerialno), "");
+              gtk_entry_set_text (GTK_ENTRY (cardman->entryVersion), "");
+              gtk_entry_set_text (GTK_ENTRY (cardman->entryManufacturer), "");
+              /* Try to get the serial number directly from the card.  */
+              get_serial_direct (cardman);
+            }
+
           update_info_visibility (cardman);
           update_title (cardman);
         }
@@ -526,6 +592,28 @@
 }
 
 
+/* Helper for construct_card_widget.  */
+static void
+add_table_row (GtkWidget *table, int *rowidx,
+               const char *labelstr, GtkWidget *widget)
+{
+  GtkWidget *label;
+
+  label = gtk_label_new (labelstr);
+  gtk_label_set_width_chars  (GTK_LABEL (label), 20);
+  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);	       
+  gtk_table_attach (GTK_TABLE (table), label, 0, 1,	       
+                    *rowidx, *rowidx + 1, GTK_FILL, GTK_SHRINK, 0, 0); 
+
+  gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
+  gtk_entry_set_has_frame (GTK_ENTRY (widget), FALSE);
+
+  gtk_table_attach (GTK_TABLE (table), widget, 1, 2,
+                    *rowidx, *rowidx + 1, GTK_FILL , GTK_SHRINK, 0, 0);
+  ++*rowidx;
+}
+
+
 /* This function constructs the container holding the card "form". It
    updates CARDMAN with new references to the entry widgets, etc.  */
 static GtkWidget *
@@ -539,131 +627,115 @@
   GtkWidget *personal_table;
   GtkWidget *keys_frame;
   GtkWidget *keys_table;
-  int rowidx = 0;
+  int rowidx;
 
   container = gtk_vbox_new (FALSE, 0);
 
-  general_frame = gtk_frame_new (NULL);
+  /* Create frames and tables. */
+  general_frame = cardman->general_frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (general_frame), GTK_SHADOW_NONE);
   label = gtk_label_new (_("<b>General</b>"));
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_frame_set_label_widget (GTK_FRAME (general_frame), label);
 
-  personal_frame = gtk_frame_new (NULL);
+  personal_frame = cardman->personal_frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (personal_frame), GTK_SHADOW_NONE);
   label = gtk_label_new (_("<b>Personal</b>"));
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_frame_set_label_widget (GTK_FRAME (personal_frame), label);
 
-  keys_frame = gtk_frame_new (NULL);
+  keys_frame = cardman->keys_frame = gtk_frame_new (NULL);
   gtk_frame_set_shadow_type (GTK_FRAME (keys_frame), GTK_SHADOW_NONE);
   label = gtk_label_new (_("<b>Keys</b>"));
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_frame_set_label_widget (GTK_FRAME (keys_frame), label);
 
-  general_table = gtk_table_new (3, 2, FALSE);
+  general_table = gtk_table_new (4, 2, FALSE);
   personal_table = gtk_table_new (6, 2, FALSE);
   keys_table = gtk_table_new (3, 2, FALSE);
 
   gtk_container_set_border_width (GTK_CONTAINER (general_table), 10);
   gtk_container_set_border_width (GTK_CONTAINER (personal_table), 10);
   gtk_container_set_border_width (GTK_CONTAINER (keys_table), 10);
+
   
-#define ADD_TABLE_ROW(table, rowidx, label, widget)		       \
-  {								       \
-    GtkWidget *tmp_label = gtk_label_new (_(label));		       \
-    gtk_label_set_width_chars  (GTK_LABEL (tmp_label), 20);            \
-    gtk_misc_set_alignment (GTK_MISC (tmp_label), 0, 0.5);	       \
-    gtk_table_attach (GTK_TABLE (table), tmp_label, 0, 1,	       \
-                      rowidx, rowidx + 1, GTK_FILL, GTK_SHRINK, 0, 0); \
-    gtk_table_attach (GTK_TABLE (table), widget, 1, 2,		       \
-                      rowidx, rowidx + 1, GTK_FILL ,       \
-		      GTK_SHRINK, 0, 0);			       \
-    rowidx++;							       \
-  }
-  
   /* General frame.  */
+  rowidx = 0;
 
+  cardman->entryType = gtk_entry_new ();
+  gtk_entry_set_width_chars (GTK_ENTRY (cardman->entryType), 24);
+  add_table_row (general_table, &rowidx,
+                 "Card Type: ", cardman->entryType);
+
   cardman->entrySerialno = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entrySerialno), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entrySerialno), FALSE);
-  gtk_entry_set_width_chars (GTK_ENTRY (cardman->entrySerialno), 24);
-  ADD_TABLE_ROW (general_table, rowidx, "Serial Number: ", cardman->entrySerialno);
+  add_table_row (general_table, &rowidx, 
+                 "Serial Number: ", cardman->entrySerialno);
 
   cardman->entryVersion = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryVersion), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryVersion), FALSE);
-  ADD_TABLE_ROW (general_table, rowidx, "Card Version: ", cardman->entryVersion);
+  add_table_row (general_table, &rowidx,
+                 "Card Version: ", cardman->entryVersion);
 
   cardman->entryManufacturer = gtk_entry_new ();
-  gtk_entry_set_has_frame (GTK_ENTRY(cardman->entryManufacturer), FALSE);
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryManufacturer), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryManufacturer), FALSE);
-  ADD_TABLE_ROW (general_table, rowidx, "Manufacturer: ", cardman->entryManufacturer);
+  add_table_row (general_table, &rowidx,
+                 "Manufacturer: ", cardman->entryManufacturer);
 
   gtk_container_add (GTK_CONTAINER (general_frame), general_table);
-  rowidx = 0;
 
   /* Personal frame.  */
+  rowidx = 0;
 
   cardman->entryFirstName = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryFirstName), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryFirstName), FALSE);
   gtk_entry_set_width_chars (GTK_ENTRY (cardman->entryFirstName), 48);
-  ADD_TABLE_ROW (personal_table, rowidx, "First Name: ", cardman->entryFirstName);
+  add_table_row (personal_table, &rowidx, 
+                 "First Name: ", cardman->entryFirstName);
 
   cardman->entryLastName = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryLastName), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryLastName), FALSE);
-  ADD_TABLE_ROW (personal_table, rowidx, "Last Name: ", cardman->entryLastName);
+  add_table_row (personal_table, &rowidx,
+                 "Last Name: ", cardman->entryLastName);
 
   cardman->entrySex = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entrySex), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entrySex), FALSE);
-  ADD_TABLE_ROW (personal_table, rowidx, "Sex:", cardman->entrySex);
+  add_table_row (personal_table, &rowidx,
+                 "Sex:", cardman->entrySex);
 
   cardman->entryLanguage = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryLanguage), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryLanguage), FALSE);
-  ADD_TABLE_ROW (personal_table, rowidx, "Language: ", cardman->entryLanguage);
+  add_table_row (personal_table, &rowidx,
+                 "Language: ", cardman->entryLanguage);
 
   cardman->entryLogin = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryLogin), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryLogin), FALSE);
-  ADD_TABLE_ROW (personal_table, rowidx, "Login Data: ", cardman->entryLogin);
+  add_table_row (personal_table, &rowidx,
+                 "Login Data: ", cardman->entryLogin);
 
   cardman->entryPubkeyUrl = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryPubkeyUrl), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryPubkeyUrl), FALSE);
-  ADD_TABLE_ROW (personal_table, rowidx, "Public key URL: ", cardman->entryPubkeyUrl);
+  add_table_row (personal_table, &rowidx,
+                 "Public key URL: ", cardman->entryPubkeyUrl);
 
   gtk_container_add (GTK_CONTAINER (personal_frame), personal_table);
-  rowidx = 0;
 
   /* Keys frame.  */
+  rowidx = 0;
 
   cardman->entryKeySig = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryKeySig), FALSE);
   gtk_entry_set_width_chars (GTK_ENTRY (cardman->entryKeySig), 48);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryKeySig), FALSE);
-  ADD_TABLE_ROW (keys_table, rowidx, "Signature Key: ", cardman->entryKeySig);
+  add_table_row (keys_table, &rowidx, 
+                 "Signature Key: ", cardman->entryKeySig);
 
   cardman->entryKeyEnc = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryKeyEnc), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryKeyEnc), FALSE);
-  ADD_TABLE_ROW (keys_table, rowidx, "Encryption Key: ", cardman->entryKeyEnc);
+  add_table_row (keys_table, &rowidx,
+                 "Encryption Key: ", cardman->entryKeyEnc);
 
   cardman->entryKeyAuth = gtk_entry_new ();
-  gtk_editable_set_editable (GTK_EDITABLE (cardman->entryKeyAuth), FALSE);
-  gtk_entry_set_has_frame (GTK_ENTRY (cardman->entryKeyAuth), FALSE);
-  ADD_TABLE_ROW (keys_table, rowidx, "Authentication Key: ", cardman->entryKeyAuth);
+  add_table_row (keys_table, &rowidx,
+                 "Authentication Key: ", cardman->entryKeyAuth);
 
   gtk_container_add (GTK_CONTAINER (keys_frame), keys_table);
 
+
+  /* Put all frames together.  */
   gtk_box_pack_start (GTK_BOX (container), general_frame, FALSE, TRUE, 0);
   gtk_box_pack_start (GTK_BOX (container), personal_frame, FALSE, TRUE, 0);
   gtk_box_pack_start (GTK_BOX (container), keys_frame, FALSE, TRUE, 0);
 
+
   return container;
 }
 

Modified: trunk/src/gpaoperation.c
===================================================================
--- trunk/src/gpaoperation.c	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/src/gpaoperation.c	2009-01-26 14:17:00 UTC (rev 939)
@@ -261,7 +261,7 @@
 
   /* FIXME: Return value might require an allocator to not only get
      the last one.  */
-  g_signal_emit (GPA_OPERATION (op), signals[STATUS], NULL,
+  g_signal_emit (GPA_OPERATION (op), signals[STATUS], 0,
 		 statusname, buf, &err);
   
   va_end (arg_ptr);

Modified: trunk/src/gpapinchange.c
===================================================================
--- trunk/src/gpapinchange.c	2009-01-17 18:53:00 UTC (rev 938)
+++ trunk/src/gpapinchange.c	2009-01-26 14:17:00 UTC (rev 939)
@@ -88,7 +88,7 @@
 }
 
 
-/* Initialze an instance of the this class.  */
+/* Initialize an instance of the this class.  */
 static void
 gpa_pin_change_init (GpaPinChange *pinchange)
 {



More information about the Gpa-commits mailing list