diff src/cache.c @ 37:67ba4381497e

Wed Apr 13 18:16:14 2005 John Ellis <johne@verizon.net> * cache-loader.[ch]: New utility to load cache-able data. * cache.[ch]: Add embedded (exif) date caching. * pan-view.c: Use new cache loading mechanism. Add exif date support to timeline and calendar view. * src/Makefile.am: Add cache-loader.[c,h]. ##### Note: GQview CVS on sourceforge is not always up to date, please use ##### ##### an offical release when making enhancements and translation updates. #####
author gqview
date Wed, 13 Apr 2005 22:29:53 +0000
parents d907d608745f
children 64068b1bab89
line wrap: on
line diff
--- a/src/cache.c	Tue Apr 12 12:11:31 2005 +0000
+++ b/src/cache.c	Wed Apr 13 22:29:53 2005 +0000
@@ -27,6 +27,7 @@
  * SIMcache
  * #coment
  * Dimensions=[<width> x <height>]
+ * Date=[<value in time_t format, or -1 if no embedded date>]
  * Checksum=[<value>]
  * MD5sum=[<32 character ascii text digest>]
  * SimilarityGrid[32 x 32]=<3072 bytes of data (1024 pixels in RGB format, 1 pixel is 24bits)>
@@ -51,8 +52,7 @@
 	CacheData *cd;
 
 	cd = g_new0(CacheData, 1);
-	cd->dimensions = FALSE;
-	cd->similarity = FALSE;
+	cd->date = -1;
 
 	return cd;
 }
@@ -81,6 +81,15 @@
 	return TRUE;
 }
 
+static gint cache_sim_write_date(FILE *f, CacheData *cd)
+{
+	if (!f || !cd || !cd->have_date) return FALSE;
+
+	fprintf(f, "Date=[%ld]\n", cd->date);
+
+	return TRUE;
+}
+
 static gint cache_sim_write_checksum(FILE *f, CacheData *cd)
 {
 	if (!f || !cd || !cd->have_checksum) return FALSE;
@@ -157,6 +166,7 @@
 
 	fprintf(f, "SIMcache\n#%s %s\n", PACKAGE, VERSION);
 	cache_sim_write_dimensions(f, cd);
+	cache_sim_write_date(f, cd);
 	cache_sim_write_checksum(f, cd);
 	cache_sim_write_md5sum(f, cd);
 	cache_sim_write_similarity(f, cd);
@@ -234,6 +244,46 @@
 	return FALSE;
 }
 
+static gint cache_sim_read_date(FILE *f, char *buf, int s, CacheData *cd)
+{
+	if (!f || !buf || !cd) return FALSE;
+
+	if (s < 4 || strncmp("Date", buf, 4) != 0) return FALSE;
+
+	if (fseek(f, - s, SEEK_CUR) == 0)
+		{
+		char b;
+		char buf[1024];
+		gint p = 0;
+
+		b = 'X';
+		while (b != '[')
+			{
+			if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
+			}
+		while (b != ']' && p < 1023)
+			{
+			if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
+			buf[p] = b;
+			p++;
+			}
+
+		while (b != '\n')
+			{
+			if (fread(&b, sizeof(b), 1, f) != 1) break;
+			}
+
+		buf[p] = '\0';
+		cd->date = strtol(buf, NULL, 10);
+
+		cd->have_date = TRUE;
+
+		return TRUE;
+		}
+
+	return FALSE;
+}
+
 static gint cache_sim_read_checksum(FILE *f, char *buf, int s, CacheData *cd)
 {
 	if (!f || !buf || !cd) return FALSE;
@@ -414,6 +464,7 @@
 			{
 			if (!cache_sim_read_comment(f, buf, s, cd) &&
 			    !cache_sim_read_dimensions(f, buf, s, cd) &&
+			    !cache_sim_read_date(f, buf, s, cd) &&
 			    !cache_sim_read_checksum(f, buf, s, cd) &&
 			    !cache_sim_read_md5sum(f, buf, s, cd) &&
 			    !cache_sim_read_similarity(f, buf, s, cd))
@@ -449,6 +500,14 @@
 	cd->dimensions = TRUE;
 }
 
+void cache_sim_data_set_date(CacheData *cd, time_t date)
+{
+	if (!cd) return;
+
+	cd->date = date;
+	cd->have_date = TRUE;
+}
+
 void cache_sim_data_set_checksum(CacheData *cd, long checksum)
 {
 	if (!cd) return;