mirror of https://github.com/djcb/mu.git
* WIP: hook up mu-msg-db with mu-msg (CTOR)
This commit is contained in:
parent
f9f3c11f28
commit
7498bc3841
|
@ -37,7 +37,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
MuMsgDb*
|
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);
|
g_return_val_if_fail (doc, NULL);
|
||||||
|
|
||||||
|
|
|
@ -21,14 +21,13 @@
|
||||||
#define __MU_MSG_DB_H__
|
#define __MU_MSG_DB_H__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <mu-util.h> /* for XapianDocument */
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
struct _MuMsgDb;
|
struct _MuMsgDb;
|
||||||
typedef struct _MuMsgDb MuMsgDb;
|
typedef struct _MuMsgDb MuMsgDb;
|
||||||
|
|
||||||
typedef gpointer XapianDocument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new MuMsgDb instance
|
* create a new MuMsgDb instance
|
||||||
*
|
*
|
||||||
|
@ -40,7 +39,7 @@ typedef gpointer XapianDocument;
|
||||||
* @return a new MuMsgDb instance (free with mu_msg_db_destroy), or
|
* @return a new MuMsgDb instance (free with mu_msg_db_destroy), or
|
||||||
* NULL in case of error.
|
* NULL in case of error.
|
||||||
*/
|
*/
|
||||||
MuMsgDb* mu_msg_db_new (XapianDocument *doc, GError **err);
|
MuMsgDb* mu_msg_db_new (const XapianDocument *doc, GError **err);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
#include "mu-msg-file.h"
|
#include "mu-msg-file.h"
|
||||||
|
#include "mu-msg-db.h"
|
||||||
#include "mu-msg-cache.h"
|
#include "mu-msg-cache.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
@ -34,7 +35,7 @@ struct _MuMsgFile {
|
||||||
GMimeMessage *_mime_msg;
|
GMimeMessage *_mime_msg;
|
||||||
time_t _timestamp;
|
time_t _timestamp;
|
||||||
size_t _size;
|
size_t _size;
|
||||||
char _path [PATH_MAX + 1];
|
char _path [PATH_MAX + 1];
|
||||||
char _maildir [PATH_MAX + 1];
|
char _maildir [PATH_MAX + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +45,11 @@ struct _MuMsgFile {
|
||||||
struct _MuMsg {
|
struct _MuMsg {
|
||||||
|
|
||||||
guint _refcount;
|
guint _refcount;
|
||||||
|
|
||||||
|
/* our two backend */
|
||||||
MuMsgFile *_file;
|
MuMsgFile *_file;
|
||||||
|
MuMsgDb *_db;
|
||||||
|
|
||||||
MuMsgCache *_cache;
|
MuMsgCache *_cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
40
src/mu-msg.c
40
src/mu-msg.c
|
@ -61,6 +61,20 @@ gmime_uninit (void)
|
||||||
_gmime_initialized = FALSE;
|
_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*
|
MuMsg*
|
||||||
mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
|
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)
|
if (!msgfile)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self = g_slice_new0 (MuMsg);
|
self = msg_new ();
|
||||||
|
|
||||||
self->_file = msgfile;
|
self->_file = msgfile;
|
||||||
self->_refcount = 1;
|
|
||||||
self->_cache = mu_msg_cache_new ();
|
|
||||||
|
|
||||||
return self;
|
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
|
static void
|
||||||
mu_msg_destroy (MuMsg *self)
|
mu_msg_destroy (MuMsg *self)
|
||||||
{
|
{
|
||||||
|
@ -95,6 +125,8 @@ mu_msg_destroy (MuMsg *self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mu_msg_file_destroy (self->_file);
|
mu_msg_file_destroy (self->_file);
|
||||||
|
mu_msg_db_destroy (self->_db);
|
||||||
|
|
||||||
mu_msg_cache_destroy (self->_cache);
|
mu_msg_cache_destroy (self->_cache);
|
||||||
|
|
||||||
g_slice_free (MuMsg, self);
|
g_slice_free (MuMsg, self);
|
||||||
|
|
20
src/mu-msg.h
20
src/mu-msg.h
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify
|
** This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
#include <mu-msg-flags.h>
|
#include <mu-msg-flags.h>
|
||||||
#include <mu-msg-fields.h>
|
#include <mu-msg-fields.h>
|
||||||
#include <mu-msg-prio.h>
|
#include <mu-msg-prio.h>
|
||||||
#include <mu-util.h> /* for MuResult, MuError */
|
#include <mu-util.h> /* for MuResult, MuError and XapianDocument */
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
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;
|
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
|
* increase the reference count for this message
|
||||||
*
|
*
|
||||||
|
|
|
@ -244,6 +244,11 @@ enum {
|
||||||
unsigned char mu_util_get_dtype_with_lstat (const char *path);
|
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...
|
* don't repeat these catch blocks everywhere...
|
||||||
|
|
Loading…
Reference in New Issue