From 7498bc38414c5af655b254c70286f9cc6f209a12 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Sun, 15 May 2011 11:06:55 +0300 Subject: [PATCH] * WIP: hook up mu-msg-db with mu-msg (CTOR) --- src/mu-msg-db.cc | 2 +- src/mu-msg-db.h | 5 ++--- src/mu-msg-priv.h | 7 ++++++- src/mu-msg.c | 40 ++++++++++++++++++++++++++++++++++++---- src/mu-msg.h | 20 ++++++++++++++++++-- src/mu-util.h | 5 +++++ 6 files changed, 68 insertions(+), 11 deletions(-) diff --git a/src/mu-msg-db.cc b/src/mu-msg-db.cc index c9e934d8..5ded9f0c 100644 --- a/src/mu-msg-db.cc +++ b/src/mu-msg-db.cc @@ -37,7 +37,7 @@ private: MuMsgDb* -mu_msg_db_new (XapianDocument *doc, GError **err) +mu_msg_db_new (const XapianDocument *doc, GError **err) { g_return_val_if_fail (doc, NULL); diff --git a/src/mu-msg-db.h b/src/mu-msg-db.h index 75cb861d..380fe367 100644 --- a/src/mu-msg-db.h +++ b/src/mu-msg-db.h @@ -21,14 +21,13 @@ #define __MU_MSG_DB_H__ #include +#include /* for XapianDocument */ G_BEGIN_DECLS struct _MuMsgDb; typedef struct _MuMsgDb MuMsgDb; -typedef gpointer XapianDocument; - /** * create a new MuMsgDb instance * @@ -40,7 +39,7 @@ typedef gpointer XapianDocument; * @return a new MuMsgDb instance (free with mu_msg_db_destroy), or * NULL in case of error. */ -MuMsgDb* mu_msg_db_new (XapianDocument *doc, GError **err); +MuMsgDb* mu_msg_db_new (const XapianDocument *doc, GError **err); /** diff --git a/src/mu-msg-priv.h b/src/mu-msg-priv.h index b73c51e7..e515d6ff 100644 --- a/src/mu-msg-priv.h +++ b/src/mu-msg-priv.h @@ -25,6 +25,7 @@ #include "mu-msg.h" #include "mu-msg-file.h" +#include "mu-msg-db.h" #include "mu-msg-cache.h" G_BEGIN_DECLS @@ -34,7 +35,7 @@ struct _MuMsgFile { GMimeMessage *_mime_msg; time_t _timestamp; size_t _size; - char _path [PATH_MAX + 1]; + char _path [PATH_MAX + 1]; char _maildir [PATH_MAX + 1]; }; @@ -44,7 +45,11 @@ struct _MuMsgFile { struct _MuMsg { guint _refcount; + + /* our two backend */ MuMsgFile *_file; + MuMsgDb *_db; + MuMsgCache *_cache; }; diff --git a/src/mu-msg.c b/src/mu-msg.c index 30a22f54..8e466718 100644 --- a/src/mu-msg.c +++ b/src/mu-msg.c @@ -61,6 +61,20 @@ gmime_uninit (void) _gmime_initialized = FALSE; } + +static MuMsg* +msg_new (void) +{ + MuMsg *self; + + self = g_slice_new0 (MuMsg); + + self->_refcount = 1; + self->_cache = mu_msg_cache_new (); + + return self; +} + MuMsg* mu_msg_new_from_file (const char *path, const char *mdir, GError **err) { @@ -78,16 +92,32 @@ mu_msg_new_from_file (const char *path, const char *mdir, GError **err) if (!msgfile) return NULL; - self = g_slice_new0 (MuMsg); - + self = msg_new (); self->_file = msgfile; - self->_refcount = 1; - self->_cache = mu_msg_cache_new (); return self; } +MuMsg* +mu_msg_new_from_db (const XapianDocument* doc, GError **err) +{ + MuMsg *self; + MuMsgDb *msgdb; + + g_return_val_if_fail (doc, NULL); + + msgdb = mu_msg_db_new (doc, err); + if (!msgdb) + return NULL; + + self = msg_new (); + self->_db = msgdb; + + return self; +} + + static void mu_msg_destroy (MuMsg *self) { @@ -95,6 +125,8 @@ mu_msg_destroy (MuMsg *self) return; mu_msg_file_destroy (self->_file); + mu_msg_db_destroy (self->_db); + mu_msg_cache_destroy (self->_cache); g_slice_free (MuMsg, self); diff --git a/src/mu-msg.h b/src/mu-msg.h index 77b194a3..c23af6e3 100644 --- a/src/mu-msg.h +++ b/src/mu-msg.h @@ -1,4 +1,4 @@ -/* +/* ** Copyright (C) 2010 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify @@ -23,7 +23,7 @@ #include #include #include -#include /* for MuResult, MuError */ +#include /* for MuResult, MuError and XapianDocument */ G_BEGIN_DECLS @@ -49,6 +49,22 @@ MuMsg *mu_msg_new_from_file (const char* filepath, const char *maildir, GError **err) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; +/** + * create a new MuMsg* instance based on a Xapian::Document + * + * @param doc a ptr to a Xapian::Document (but cast to XapianDocument, + * because this is C not C++) + * @param err receive error information, or NULL. There + * will only be err info if the function returns NULL + * + * @return a new MuMsg instance or NULL in case of error; call + * mu_msg_unref when done with this message + */ +MuMsg *mu_msg_new_from_db (const XapianDocument* doc, GError **err) + G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT; + + + /** * increase the reference count for this message * diff --git a/src/mu-util.h b/src/mu-util.h index cb9d773a..d2669a1e 100644 --- a/src/mu-util.h +++ b/src/mu-util.h @@ -244,6 +244,11 @@ enum { unsigned char mu_util_get_dtype_with_lstat (const char *path); +/* + * we need this when using Xapian::Document* from C + */ +typedef gpointer XapianDocument; + /** * * don't repeat these catch blocks everywhere...