[Gpa-commits] r937 - trunk/src

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Jan 17 15:41:50 CET 2009


Author: moritzs
Date: 2009-01-17 15:41:49 +0100 (Sat, 17 Jan 2009)
New Revision: 937

Modified:
   trunk/src/ChangeLog
   trunk/src/cardman.c
Log:
2009-01-17  Moritz  <moritz at gnu.org>

	* cardman.c (reader_status_t): New (enum) type.
	(reader_status_from_file): New function.
	(watcher_cb): New local variable: reader_status; call
	reader_status_from_file and statusbar_update.



Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-01-17 13:28:30 UTC (rev 936)
+++ trunk/src/ChangeLog	2009-01-17 14:41:49 UTC (rev 937)
@@ -1,3 +1,10 @@
+2009-01-17  Moritz  <moritz at gnu.org>
+
+	* cardman.c (reader_status_t): New (enum) type.
+	(reader_status_from_file): New function.
+	(watcher_cb): New local variable: reader_status; call
+	reader_status_from_file and statusbar_update.
+
 2009-01-16  Werner Koch  <wk at g10code.com>
 
 	* gpapinchange.h, gpapinchange.c: New.

Modified: trunk/src/cardman.c
===================================================================
--- trunk/src/cardman.c	2009-01-17 13:28:30 UTC (rev 936)
+++ trunk/src/cardman.c	2009-01-17 14:41:49 UTC (rev 937)
@@ -342,14 +342,62 @@
   card_genkey (cardman);
 }
 
+typedef enum
+  {
+    READER_STATUS_UNKNOWN,
+    READER_STATUS_NOCARD,
+    READER_STATUS_PRESENT,
+    READER_STATUS_USABLE
+  } reader_status_t;
 
+static reader_status_t
+reader_status_from_file (const char *filename)
+{
+  reader_status_t status = READER_STATUS_UNKNOWN;
+  char status_word[16];
+  FILE *fp;
+
+  fp = fopen (filename, "r");
+  if (fp)
+    {
+      if (fgets (status_word, sizeof (status_word), fp))
+	{
+	  /* Remove trailing newline from STATUS_WORD.  */
+	  char *nl = strchr (status_word, '\n');
+	  if (nl)
+	    *nl = '\0';
+
+	  /* Store enum value belonging to STATUS_WORD in STATUS. */
+	  if (strcmp (status_word, "NOCARD") == 0)
+	    status = READER_STATUS_NOCARD;
+	  else if (strcmp (status_word, "PRESENT") == 0)
+	    status = READER_STATUS_PRESENT;
+	  else if (strcmp (status_word, "USABLE") == 0)
+	    status = READER_STATUS_USABLE;
+	}
+      /* else: read error or EOF. */
+
+      fclose (fp);
+    }
+
+  return status;
+}
+
+
 static void
 watcher_cb (void *opaque, const char *filename, const char *reason)
 {
   GpaCardManager *cardman = opaque;
 
   if (cardman && strchr (reason, 'w') )
-    card_reload (cardman);
+    {
+      reader_status_t reader_status;
+
+      reader_status = reader_status_from_file (filename);
+      if (reader_status == READER_STATUS_PRESENT)
+	statusbar_update (cardman, _("Reloading card data..."));
+      card_reload (cardman);
+    }
 }
 
 



More information about the Gpa-commits mailing list