From 06ad732d816f0812c63b7601520ecff9bcc41b59 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 30 Nov 2009 00:04:16 +0200 Subject: [PATCH] * expand dir names (ie. ~/Maildir => /home/user/Maildir); add init/uninit --- src/mu-config.c | 23 +++++++++++++++++++---- src/mu-config.h | 23 ++++++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/mu-config.c b/src/mu-config.c index 6b67882d..570f5018 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -19,6 +19,8 @@ #include #include /* memset */ + +#include "mu-util.h" #include "mu-config.h" @@ -104,7 +106,7 @@ mu_config_options_group_query (MuConfigOptions *opts) void -mu_config_set_defaults (MuConfigOptions *opts) +mu_config_init (MuConfigOptions *opts) { g_return_if_fail (opts); @@ -112,11 +114,12 @@ mu_config_set_defaults (MuConfigOptions *opts) memset (opts, 0, sizeof(MuConfigOptions)); /* general */ - opts->quiet = FALSE; - opts->debug = FALSE; + opts->quiet = FALSE; + opts->debug = FALSE; + opts->muhome = mu_util_dir_expand ("~/.mu"); /* indexing */ - opts->maildir = "/home/djcb/Maildir"; + opts->maildir = mu_util_dir_expand ("~/Maildir"); opts->cleanup = FALSE; opts->reindex = FALSE; @@ -124,3 +127,15 @@ mu_config_set_defaults (MuConfigOptions *opts) opts->xquery = FALSE; opts->fields = "d f s"; } + + +void +mu_config_uninit (MuConfigOptions *opts) +{ + g_return_if_fail (opts); + + /* yes, this is fine -- they are only const + * for the 'outside world' */ + g_free ((gchar*)opts->muhome); + g_free ((gchar*)opts->maildir); +} diff --git a/src/mu-config.h b/src/mu-config.h index 62cf4667..dcd42bb6 100644 --- a/src/mu-config.h +++ b/src/mu-config.h @@ -29,13 +29,14 @@ struct _MuConfigOptions { /* general options */ - gboolean quiet; /* don't give any output */ - gboolean debug; /* spew out debug info */ + gboolean quiet; /* don't give any output */ + gboolean debug; /* spew out debug info */ const char *muhome;/* the House of Mu */ gboolean version; /* request mu version */ gboolean log_stderr; /*log to stderr (instead of logfile)*/ gboolean log_append; /* append to log (instead of overwriting)*/ + /* options for indexing */ const char *maildir; /* where the mails are */ gboolean cleanup; /* cleanup deleted mails form db */ @@ -57,12 +58,22 @@ typedef struct _MuConfigOptions MuConfigOptions; /** - * set default values for the configuration options + * set default values for the configuration options; when you call + * mu_config_init, you should also call mu_config_uninit when the data + * is no longer needed. + * + * @param opts options + */ +void mu_config_init (MuConfigOptions *opts); + + +/** + * free the MuOptionsCOnfig structure; the the muhome and maildir + * members are heap-allocated, so must be freed. * * @param opts */ -void mu_config_set_defaults (MuConfigOptions *opts); - +void mu_config_uninit (MuConfigOptions *opts); /** * get the general options option group @@ -92,4 +103,6 @@ GOptionGroup* mu_config_options_group_index (MuConfigOptions *opts); GOptionGroup* mu_config_options_group_query (MuConfigOptions *opts); +char* mu_config_expanded_mu_home (MuConfigOptions *opts); + #endif /*__MU_CONFIG_H__*/