* mu-msg-fields: cleanup, use MuMsgFieldId rather than MuMsgField*

This commit is contained in:
Dirk-Jan C. Binnema
2010-11-20 14:41:21 +02:00
parent 7e96b1b483
commit de1deb4e80
2 changed files with 187 additions and 200 deletions

View File

@ -27,7 +27,7 @@ G_BEGIN_DECLS
/* don't change the order, add new types at the end, as these numbers
* are used in the database */
enum _MuMsgFieldId {
MU_MSG_FIELD_ID_BODY_TEXT,
MU_MSG_FIELD_ID_BODY_TEXT = 0,
MU_MSG_FIELD_ID_BODY_HTML,
MU_MSG_FIELD_ID_CC,
MU_MSG_FIELD_ID_DATE,
@ -42,13 +42,16 @@ enum _MuMsgFieldId {
MU_MSG_FIELD_ID_MSGID,
MU_MSG_FIELD_ID_TIMESTAMP,
MU_MSG_FIELD_ID_NUM,
MU_MSG_FIELD_ID_NUM
};
typedef enum _MuMsgFieldId MuMsgFieldId;
static const guint MU_MSG_FIELD_ID_NONE = MU_MSG_FIELD_ID_NUM + 1;
struct _MuMsgField;
typedef struct _MuMsgField MuMsgField;
static const guint MU_MSG_FIELD_ID_NONE = (guint)-1;
typedef guint MuMsgFieldId;
#define mu_msg_field_id_is_valid(MFID) \
((MFID) < MU_MSG_FIELD_ID_NUM)
/* don't change the order, add new types at the end (before _NUM)*/
enum _MuMsgFieldType {
@ -61,9 +64,11 @@ enum _MuMsgFieldType {
MU_MSG_FIELD_TYPE_NUM
};
typedef enum _MuMsgFieldType MuMsgFieldType;
static const guint MU_MSG_FIELD_TYPE_NONE = MU_MSG_FIELD_TYPE_NUM + 1;
static const guint MU_MSG_FIELD_TYPE_NONE = (guint)-1;
typedef void (*MuMsgFieldForEachFunc) (const MuMsgField *field,
typedef void (*MuMsgFieldForEachFunc) (MuMsgFieldId id,
gconstpointer data);
/**
@ -79,43 +84,32 @@ void mu_msg_field_foreach (MuMsgFieldForEachFunc func, gconstpointer data);
* get the name of the field -- this a name that can be use in queries,
* ie. 'subject:foo', with 'subject' being the name
*
* @param field a MuMsgField
*
* @param id a MuMsgFieldId
*
* @return the name of the field as a constant string, or
* NULL if the field is unknown
*/
const char* mu_msg_field_name (const MuMsgField *field) G_GNUC_CONST;
const char* mu_msg_field_name (MuMsgFieldId id) G_GNUC_PURE;
/**
* get the shortcut of the field -- this a shortcut that can be use in
* queries, ie. 's:foo', with 's' meaning 'subject' being the name
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return the shortcut of the field as a constant string, or
* NULL if the field is unknown
* @return the shortcut character, or 0 if the field is unknown
*/
const char* mu_msg_field_shortcut (const MuMsgField *field) G_GNUC_CONST;
char mu_msg_field_shortcut (MuMsgFieldId id) G_GNUC_PURE;
/**
* get the xapian prefix of the field -- that is, the prefix used in
* the Xapian database to identify the field
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return the xapian prefix of the field as a constant string, or
* NULL if the field is unknown
* @return the xapian prefix char or 0 if the field is unknown
*/
const char* mu_msg_field_xapian_prefix (const MuMsgField *field) G_GNUC_PURE;
/**
* get the numerical ID of the field
*
* @param field a MuMsgField
*
* @return an id, or MU_MSG_FIELD_TYPE_NONE if the field is not known
*/
MuMsgFieldId mu_msg_field_id (const MuMsgField *field) G_GNUC_CONST;
char mu_msg_field_xapian_prefix (MuMsgFieldId id) G_GNUC_PURE;
/**
@ -126,18 +120,17 @@ MuMsgFieldId mu_msg_field_id (const MuMsgField *field) G_GNUC_CONST;
* @return the type of the field (a #MuMsgFieldType), or
* MU_MSG_FIELD_TYPE_NONE if it is not found
*/
MuMsgFieldType mu_msg_field_type (const MuMsgField *field) G_GNUC_CONST;
MuMsgFieldType mu_msg_field_type (MuMsgFieldId id) G_GNUC_PURE;
/**
* is the field numeric (has type MU_MSG_FIELD_TYPE_(BYTESIZE|TIME_T|INT))?
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return TRUE if the field is numeric, FALSE otherwise
*/
gboolean mu_msg_field_is_numeric (const MuMsgField *field) G_GNUC_CONST;
gboolean mu_msg_field_is_numeric (MuMsgFieldId id) G_GNUC_PURE;
/**
@ -145,20 +138,20 @@ gboolean mu_msg_field_is_numeric (const MuMsgField *field) G_GNUC_CONST
* indexed in the in the Xapian database, so we can use the all the
* phrasing, stemming etc. magic
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return TRUE if the field is Xapian-enabled, FALSE otherwise
*/
gboolean mu_msg_field_xapian_index (const MuMsgField *field) G_GNUC_PURE;
gboolean mu_msg_field_xapian_index (MuMsgFieldId id) G_GNUC_PURE;
/**
* should this field be stored as a xapian term?
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return TRUE if the field is Xapian-enabled, FALSE otherwise
*/
gboolean mu_msg_field_xapian_term (const MuMsgField *field) G_GNUC_PURE;
gboolean mu_msg_field_xapian_term (MuMsgFieldId id) G_GNUC_PURE;
/**
* should this field be stored as a xapian value?
@ -167,57 +160,55 @@ gboolean mu_msg_field_xapian_term (const MuMsgField *field) G_GNUC_PURE;
*
* @return TRUE if the field is Xapian-enabled, FALSE otherwise
*/
gboolean mu_msg_field_xapian_value (const MuMsgField *field) G_GNUC_PURE;
gboolean mu_msg_field_xapian_value (MuMsgFieldId id) G_GNUC_PURE;
/**
* should this field be stored as contact information? This means that
* e-mail address will be stored as terms, and names will be indexed
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return TRUE if the field should be stored as contact information,
* FALSE otherwise
*/
gboolean mu_msg_field_xapian_contact (const MuMsgField *field) G_GNUC_PURE;
gboolean mu_msg_field_xapian_contact (MuMsgFieldId id) G_GNUC_PURE;
/**
* is the field gmime-enabled? That is, can be field be retrieved
* using GMime?
*
* @param field a MuMsgField
* @param id a MuMsgFieldId
*
* @return TRUE if the field is Gmime-enabled, FALSE otherwise
*/
gboolean mu_msg_field_gmime (const MuMsgField *field) G_GNUC_PURE;
gboolean mu_msg_field_gmime (MuMsgFieldId id) G_GNUC_PURE;
/**
* get the corresponding MuMsgField for a name (as in mu_msg_field_name)
*
* @param str a name
* @param err, if TRUE, when the shortcut is not found, will issue a
* g_critical warning
*
* @return a MuMsgField, or NULL if it could not be found
*/
const MuMsgField* mu_msg_field_from_name (const char* str) G_GNUC_PURE;
MuMsgFieldId mu_msg_field_id_from_name (const char* str,
gboolean err) G_GNUC_PURE;
/**
* get the corresponding MuMsgField for a shortcut (as in mu_msg_field_shortcut)
*
* @param kar a shortcut character
* @param err, if TRUE, when the shortcut is not found, will issue a
* g_critical warning
*
* @return a MuMsgField, or NULL if it could not be found
*/
const MuMsgField* mu_msg_field_from_shortcut (char kar) G_GNUC_CONST;
MuMsgFieldId mu_msg_field_id_from_shortcut (char kar,
gboolean err) G_GNUC_PURE;
/**
* get the corresponding MuMsgField for an id (as in mu_msg_field_id)
*
* @param id an id
*
* @return a MuMsgField, or NULL if it could not be found
*/
const MuMsgField* mu_msg_field_from_id (MuMsgFieldId id) G_GNUC_CONST;
G_END_DECLS