~ubuntu-branches/ubuntu/quantal/maildir-utils/quantal

« back to all changes in this revision

Viewing changes to src/mu-config.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-01-19 20:12:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100119201243-d8qmzgxgexhy1bs0
Tags: 0.6~beta1-1
* new upstream release 0.6-beta
  - that merges the several different programs under one binary mu
  - no sqlite storage is used anymore
* debian packaging changes:
  - debian/patches
    . remove all patches
  - remove debian/HOWTO (upstream document) it is completely outdated
  - debian/control:
    . adjust build-dep for gmime-2.4
    . remove build-dep on quilt and sqlite
    . adjust the description to new reality
  - debian/rules:
    . do not try to install doc files that are not present anymore
    . disable quilt adaptions
  - add debian/NEWS that explains that the separate programs are gone

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
 
3
**
 
4
** This program is free software; you can redistribute it and/or modify it
 
5
** under the terms of the GNU General Public License as published by the
 
6
** Free Software Foundation; either version 3, or (at your option) any
 
7
** later version.
 
8
**
 
9
** This program is distributed in the hope that it will be useful,
 
10
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
** GNU General Public License for more details.
 
13
**
 
14
** You should have received a copy of the GNU General Public License
 
15
** along with this program; if not, write to the Free Software Foundation,
 
16
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
**
 
18
*/
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include <glib.h>
 
23
#include <string.h> /* memset */
 
24
 
 
25
#include "mu-util.h"
 
26
#include "mu-config.h"
 
27
 
 
28
 
 
29
GOptionGroup*
 
30
mu_config_options_group_mu (MuConfigOptions *opts)
 
31
{
 
32
        GOptionGroup *og;
 
33
        GOptionEntry entries[] = {
 
34
                { "debug", 'd', 0, G_OPTION_ARG_NONE, &opts->debug,
 
35
                  "print debug output to standard error", NULL },
 
36
                { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opts->quiet,
 
37
                  "don't give any progress information", NULL },
 
38
                {"version", 'v', 0, G_OPTION_ARG_NONE, &opts->version,
 
39
                 "display version and copyright information", NULL},
 
40
                {"muhome", 'a', 0, G_OPTION_ARG_FILENAME, &opts->muhome,
 
41
                 "specify an alternative mu directory ", NULL},
 
42
                {"log-stderr", 'e', 0, G_OPTION_ARG_NONE, &opts->log_stderr,
 
43
                 "log to standard error", NULL},
 
44
                { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
 
45
                  &opts->params, "parameters", NULL },
 
46
                { NULL, 0, 0, 0, NULL, NULL, NULL }
 
47
        };
 
48
        
 
49
        og = g_option_group_new ("mu",
 
50
                                 "general mu options",
 
51
                                 "", NULL, NULL);       
 
52
        g_option_group_add_entries (og, entries);
 
53
        
 
54
        return og;
 
55
}
 
56
 
 
57
 
 
58
 
 
59
GOptionGroup*
 
60
mu_config_options_group_index (MuConfigOptions *opts)
 
61
{
 
62
        GOptionGroup *og;
 
63
        GOptionEntry entries[] = {
 
64
                {"maildir", 'm', 0, G_OPTION_ARG_FILENAME, &opts->maildir,
 
65
                 "top of the maildir", NULL},
 
66
                {"reindex", 'r', 0, G_OPTION_ARG_NONE, &opts->reindex,
 
67
                 "index already indexed messages too", NULL},
 
68
                {"nocleanup", 'u', 0, G_OPTION_ARG_NONE, &opts->nocleanup,
 
69
                 "don't clean up the database after indexing", NULL},
 
70
                { NULL, 0, 0, 0, NULL, NULL, NULL }
 
71
        };
 
72
        
 
73
        og = g_option_group_new ("index",
 
74
                                 "options for the 'index' command",
 
75
                                 "", NULL, NULL);       
 
76
        g_option_group_add_entries (og, entries);
 
77
        
 
78
        return og;
 
79
}
 
80
 
 
81
GOptionGroup*
 
82
mu_config_options_group_find (MuConfigOptions *opts)
 
83
{
 
84
        GOptionGroup *og;
 
85
        GOptionEntry entries[] = {
 
86
                {"xquery", 'x', 0, G_OPTION_ARG_NONE, &opts->xquery,
 
87
                 "print the Xapian query", NULL},
 
88
                {"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields,
 
89
                 "fields to display in the output", NULL},
 
90
                {"sortfield", 's', 0, G_OPTION_ARG_STRING, &opts->sortfield,
 
91
                 "field to sort on", NULL},
 
92
                {"descending", 'z', 0, G_OPTION_ARG_NONE, &opts->descending,
 
93
                 "sort in descending order (z -> a)", NULL},
 
94
                {"linksdir", 'l', 0, G_OPTION_ARG_STRING, &opts->linksdir,
 
95
                 "output as symbolic links to a target maildir", NULL },
 
96
                {"clearlinks", 'c', 0, G_OPTION_ARG_NONE, &opts->clearlinks,
 
97
                 "clear old links before filling a linksdir", NULL},
 
98
                { NULL, 0, 0, 0, NULL, NULL, NULL }
 
99
        };
 
100
 
 
101
        og = g_option_group_new ("find",
 
102
                                 "options for the 'find' command",
 
103
                                 "", NULL, NULL);       
 
104
        g_option_group_add_entries (og, entries);
 
105
        
 
106
        return og;
 
107
}
 
108
 
 
109
 
 
110
void
 
111
mu_config_init (MuConfigOptions *opts)
 
112
{
 
113
        g_return_if_fail (opts);
 
114
 
 
115
        /* start from zero */
 
116
        memset (opts, 0, sizeof(MuConfigOptions));
 
117
}
 
118
 
 
119
static gchar*
 
120
guess_muhome (void)
 
121
{
 
122
        const char* home;
 
123
 
 
124
        home = g_getenv ("HOME");
 
125
        if (!home)
 
126
                home = g_get_home_dir ();
 
127
 
 
128
        if (!home)
 
129
                MU_WRITE_LOG ("failed to determine homedir");
 
130
        
 
131
        return g_strdup_printf ("%s%c%s", home ? home : ".", G_DIR_SEPARATOR,
 
132
                                ".mu");
 
133
}
 
134
 
 
135
 
 
136
void
 
137
mu_config_set_defaults (MuConfigOptions *opts)
 
138
{
 
139
        gchar *old;
 
140
        g_return_if_fail (opts);
 
141
        
 
142
        if (!opts->muhome)
 
143
                opts->muhome = guess_muhome ();
 
144
        
 
145
        /* note: xpath is is *not* settable from the cmdline */
 
146
        opts->xpath = g_strdup_printf ("%s%c%s", opts->muhome,G_DIR_SEPARATOR,
 
147
                                       MU_XAPIAN_DIR_NAME);
 
148
 
 
149
        /* indexing */
 
150
        old = opts->maildir;
 
151
        if (opts->maildir)
 
152
                opts->maildir = mu_util_dir_expand (opts->maildir);
 
153
        else
 
154
                opts->maildir = mu_util_guess_maildir();
 
155
        g_free (old);
 
156
        
 
157
        /* querying */
 
158
        
 
159
        /* note, when no fields are specified, we use
 
160
         * date-from-subject, and sort descending by date. If fields
 
161
         * *are* specified, we sort in ascending order. */
 
162
        if (!opts->fields) {
 
163
                opts->descending = TRUE;
 
164
                opts->fields     = "d f s";
 
165
                opts->sortfield  = "d";
 
166
        }
 
167
 
 
168
        if (opts->linksdir) {
 
169
                gchar *old = opts->linksdir;
 
170
                opts->linksdir = mu_util_dir_expand (opts->linksdir);
 
171
                g_free(old);
 
172
        }
 
173
}
 
174
 
 
175
 
 
176
void
 
177
mu_config_uninit (MuConfigOptions *opts)
 
178
{
 
179
        g_return_if_fail (opts);
 
180
 
 
181
        g_free (opts->muhome);
 
182
        g_free (opts->xpath);
 
183
        g_free (opts->maildir);
 
184
        g_free (opts->linksdir);
 
185
 
 
186
        g_strfreev (opts->params);
 
187
}
 
188
 
 
189