evolution-data-server r8874 - branches/camel-db-summary/camel



Author: psankar
Date: Thu May 29 18:22:55 2008
New Revision: 8874
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8874&view=rev

Log:
Saving and loading messageinfos to and from the db.
Fixed miscellaneous compiler warnings.

Folder and Message summaries loads just fine.
Date calculation is correct but initial parsing is buggy.



Modified:
   branches/camel-db-summary/camel/camel-db.c
   branches/camel-db-summary/camel/camel-db.h
   branches/camel-db-summary/camel/camel-folder-summary.c
   branches/camel-db-summary/camel/camel-folder-summary.h

Modified: branches/camel-db-summary/camel/camel-db.c
==============================================================================
--- branches/camel-db-summary/camel/camel-db.c	(original)
+++ branches/camel-db-summary/camel/camel-db.c	Thu May 29 18:22:55 2008
@@ -177,7 +177,7 @@
 
   	for(i=0; i<argc; i++) {
 		if (strstr(azColName[i], "count")) {
-			(*(int **)data) = atoi(argv[i]);
+			*(int **)data = atoi(argv[i]);
 		}
   	}
 
@@ -265,7 +265,19 @@
 	char *del_query;
 	char *ins_query;
 
-	ins_query = g_strdup_printf ("INSERT INTO \"%s\" VALUES (\"%s\", %d, %d, %d, %d, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" )", folder_name, record->uid, record->flags, record->read, record->deleted, record->replied, record->important, record->junk, record->attachment, record->size, ctime (&(record->dsent)), ctime (&(record->dreceived)), record->subject, record->from, record->to, record->cc, record->mlist, record->followup_flag, record->followup_completed_on, record->followup_due_by, record->part, record->labels, record->usertags, record->cinfo, record->bdata);
+	char date_sent [255];
+	char date_received [255];
+
+	struct tm sent;
+	struct tm received;
+
+	gmtime_r (&(record->dsent), &sent);
+	gmtime_r (&(record->dreceived), &received);
+
+	strftime (date_sent, sizeof (date_sent), "%F", &sent);
+	strftime (date_received, sizeof (date_received), "%F", &received);
+
+	ins_query = g_strdup_printf ("INSERT INTO \"%s\" VALUES (\"%s\", %d, %d, %d, %d, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" )", folder_name, record->uid, record->flags, record->read, record->deleted, record->replied, record->important, record->junk, record->attachment, record->size, date_sent, date_received, record->subject, record->from, record->to, record->cc, record->mlist, record->followup_flag, record->followup_completed_on, record->followup_due_by, record->part, record->labels, record->usertags, record->cinfo, record->bdata);
 	
 	del_query = g_strdup_printf ("DELETE FROM %s WHERE uid = \"%s\"", folder_name, record->uid);
 
@@ -383,7 +395,15 @@
 	return (camel_db_select (cdb, query, read_fir_callback, record, ex));
 }
 
+int
+camel_db_read_message_info_records (CamelDB *cdb, char *folder_name, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex)
+{
+	char *query;
 
+	query = g_strdup_printf ("SELECT * FROM \"%s\" ", folder_name);
+
+	return (camel_db_select (cdb, query, read_mir_callback, p, ex));
+}
 
 gboolean
 camel_db_delete_uid (CamelDB *cdb, char *folder, char *uid, CamelException *ex)

Modified: branches/camel-db-summary/camel/camel-db.h
==============================================================================
--- branches/camel-db-summary/camel/camel-db.h	(original)
+++ branches/camel-db-summary/camel/camel-db.h	Thu May 29 18:22:55 2008
@@ -112,6 +112,8 @@
 int camel_db_read_folder_info_record (CamelDB *cdb, char *folder_name, CamelFIRecord **record, CamelException *ex);
 
 int camel_db_write_message_info_record (CamelDB *cdb, const char *folder_name, CamelMIRecord *record, CamelException *ex);
+int camel_db_read_message_info_records (CamelDB *cdb, char *folder_name, gpointer **p, CamelDBSelectCB read_mir_callback, CamelException *ex);
+
 guint32 camel_db_count (CamelDB *cdb, const char *stmt);
 #endif
 

Modified: branches/camel-db-summary/camel/camel-folder-summary.c
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.c	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.c	Thu May 29 18:22:55 2008
@@ -33,7 +33,11 @@
 #include <fcntl.h>
 #include <errno.h>
 
+#define _XOPEN_SOURCE
+#include <time.h>
+
 #include <glib.h>
+#include <glib-object.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -67,7 +71,7 @@
 /* this should probably be conditional on it existing */
 #define USE_BSEARCH
 
-#define d(x) 
+#define d(x) x
 #define io(x)			/* io debug */
 #define w(x)
 
@@ -115,6 +119,7 @@
 static void		         content_info_free(CamelFolderSummary *, CamelMessageContentInfo *);
 
 static int save_message_infos_to_db (CamelFolderSummary *s, CamelException *ex);
+static int camel_read_mir_callback (void * ref, int ncol, char ** cols, char ** name);
 
 static char *next_uid_string(CamelFolderSummary *s);
 
@@ -584,12 +589,92 @@
 
 	g_free (record);
 
-	/* FIXME: What about message-info ? Ye Need to load them. */
+	camel_db_read_message_info_records (cdb, folder_name, (gpointer**) &s, camel_read_mir_callback, &ex);
 
 	return ret;
 
 }
 
+static int 
+camel_read_mir_callback (void * ref, int ncol, char ** cols, char ** name)
+{
+	CamelFolderSummary *s = * (CamelFolderSummary **) ref;
+	CamelMIRecord *mir;
+	CamelMessageInfo *info;
+	int i;
+
+	mir = g_new0 (CamelMIRecord , 1);
+
+	for (i = 0; i < ncol; ++i) {
+
+		if ( !strcmp (name [i], "uid") ) 
+			mir->uid = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "flags") ) 
+			mir->flags = cols [i] ? strtoul (cols [i], NULL, 10) : 0;
+		else if ( !strcmp (name [i], "read") ) 
+			mir->read =  (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "deleted") ) 
+			mir->deleted = (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "replied") ) 
+			mir->replied = (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "important") ) 
+			mir->important = (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "junk") ) 
+			mir->junk = (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "attachment") ) 
+			mir->attachment = (cols [i]) ? ( ((strtoul (cols [i], NULL, 10)) ? TRUE : FALSE)) : FALSE;
+		else if ( !strcmp (name [i], "size") ) 
+			mir->size =  cols [i] ? strtoul (cols [i], NULL, 10) : 0;
+		else if ( !strcmp (name [i], "dsent") ) {
+			struct tm tmm;
+			strptime (cols [i], "%F", &(tmm));
+			mir->dsent = mktime (&tmm);
+		} else if ( !strcmp (name [i], "dreceived") )  {
+			struct tm tmm;
+			strptime (cols [i], "%F", &(tmm));
+			mir->dreceived = mktime (&tmm);
+		} else if ( !strcmp (name [i], "subject") ) 
+			mir->subject = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "from") ) 
+			mir->from = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "to") ) 
+			mir->to = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "cc") ) 
+			mir->cc = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "mlist") ) 
+			mir->mlist = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "followup_flag") ) 
+			mir->followup_flag = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "followup_completed_on") ) 
+			mir->followup_completed_on = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "followup_due_by") ) 
+			mir->followup_due_by = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "part") ) 
+			mir->part = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "labels") ) 
+			mir->labels = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "usertags") ) 
+			mir->usertags = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "cinfo") ) 
+			mir->cinfo = g_strdup (cols [i]);
+		else if ( !strcmp (name [i], "bdata") ) 
+			mir->bdata = g_strdup (cols [i]);
+
+	}
+
+	info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_from_db (s, mir);
+
+	if (info) {
+		camel_folder_summary_add (s, info);
+		d(g_print ("\nAdding messageinfo to db from db \n"));
+	} else
+		g_warning ("Loading messageinfo from db failed");
+
+	g_object_unref (mir);
+
+	return 0;
+}
+
 /**
  * camel_folder_summary_load:
  * @summary: a #CamelFolderSummary object
@@ -696,7 +781,7 @@
 	count = s->messages->len;
 	for (i = 0; i < count; ++i) {
 		mi = s->messages->pdata [i];
-//		mir = message_info_to_db (mi);
+		mir = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_to_db (s, mi);
 		if (camel_db_write_message_info_record (cdb, folder_name, mir, ex) != 0)
 			return -1;
 	}	
@@ -728,7 +813,7 @@
 		return -1;
 	}
 
-	ret = (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->save_message_infos_to_db (s, ex));
+	ret = save_message_infos_to_db (s, ex);
 	if (ret != 0) {
 		camel_db_abort_transaction (cdb, ex);
 		return -1;
@@ -2220,7 +2305,7 @@
 		for (i=0;i<mi->references->size;i++) 
 			g_string_append_printf (tmp, " %lu %lu", (long unsigned)mi->references->references[i].id.part.hi, (long unsigned)mi->references->references[i].id.part.lo);
 	} else {
-		g_string_append_printf (tmp, "%lu %lu %lu", (long unsigned)mi->message_id.id.part.hi, (long unsigned)mi->message_id.id.part.lo, 0);		
+		g_string_append_printf (tmp, "%lu %lu %lu", (long unsigned)mi->message_id.id.part.hi, (long unsigned)mi->message_id.id.part.lo, (unsigned long) 0);
 	}
 	record->part = tmp->str;
 	g_string_free (tmp, FALSE);
@@ -2846,6 +2931,9 @@
 {
 	CamelFlag *flag, *tmp;
 
+	if (!name)
+		return TRUE;
+
 	/* this 'trick' works because flag->next is the first element */
 	flag = (CamelFlag *)list;
 	while (flag->next) {
@@ -3721,7 +3809,6 @@
 	klass->message_info_to_db = message_info_to_db;
 	klass->content_info_from_db = content_info_from_db;
 	klass->content_info_to_db = content_info_to_db;
-	klass->save_message_infos_to_db = save_message_infos_to_db;
 
 	klass->message_info_new_from_header  = message_info_new_from_header;
 	klass->message_info_new_from_parser = message_info_new_from_parser;

Modified: branches/camel-db-summary/camel/camel-folder-summary.h
==============================================================================
--- branches/camel-db-summary/camel/camel-folder-summary.h	(original)
+++ branches/camel-db-summary/camel/camel-folder-summary.h	Thu May 29 18:22:55 2008
@@ -247,7 +247,6 @@
 	CamelMIRecord * (*message_info_to_db) (CamelFolderSummary *, CamelMessageInfo *);
 	CamelMessageContentInfo * (*content_info_from_db) (CamelFolderSummary *, CamelMIRecord *);
 	int (*content_info_to_db) (CamelFolderSummary *, CamelMessageContentInfo *, CamelMIRecord *);
-	int (*save_message_infos_to_db) (CamelFolderSummary *s, CamelException *ex);
 	
 	/* create/save/load an individual message info */
 	CamelMessageInfo * (*message_info_new_from_header)(CamelFolderSummary *, struct _camel_header_raw *);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]