mirror of https://github.com/djcb/mu.git
* mu-config, mu-query: implement sortfield and ascending/descending
This commit is contained in:
parent
1cff4534b8
commit
9792e3c4e1
|
@ -86,11 +86,11 @@ mu_config_options_group_query (MuConfigOptions *opts)
|
|||
"print the Xapian query", NULL},
|
||||
{"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields,
|
||||
"fields to display in output", NULL},
|
||||
{"sortfield", 's', 0, G_OPTION_ARG_STRING, &opts->sortfield_str,
|
||||
{"sortfield", 's', 0, G_OPTION_ARG_STRING, &opts->sortfield,
|
||||
"field to sort on", NULL},
|
||||
{"ascending", 'u', 0, G_OPTION_ARG_NONE, &opts->ascending_flag,
|
||||
{"ascending", 'u', 0, G_OPTION_ARG_NONE, &opts->ascending,
|
||||
"sort ascending (up)", NULL},
|
||||
{"descending", 'd', 0, G_OPTION_ARG_NONE, &opts->descending_flag,
|
||||
{"descending", 'd', 0, G_OPTION_ARG_NONE, &opts->descending,
|
||||
"sort descending (down)", NULL},
|
||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||
};
|
||||
|
@ -128,6 +128,9 @@ mu_config_init (MuConfigOptions *opts)
|
|||
/* querying */
|
||||
opts->xquery = FALSE;
|
||||
opts->fields = "d f s";
|
||||
opts->sortfield = "d";
|
||||
opts->ascending = FALSE;
|
||||
opts->descending = TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,12 +48,10 @@ struct _MuConfigOptions {
|
|||
search results */
|
||||
const char *fields; /* fields to show in output */
|
||||
|
||||
const char *sortfield_str; /* field to sort by (string) */
|
||||
const char *sortfield; /* field to sort by (string) */
|
||||
|
||||
/* FIXME: clean up this mess */
|
||||
gboolean sortdir_descending ; /* sort descending? */
|
||||
gboolean sortdir_ascending;
|
||||
gboolean ascending_flag, descending_flag;
|
||||
gboolean descending; /* sort descending? */
|
||||
gboolean ascending;
|
||||
};
|
||||
typedef struct _MuConfigOptions MuConfigOptions;
|
||||
|
||||
|
|
|
@ -81,10 +81,7 @@ const MuMsgField*
|
|||
sort_field_from_string (const char* fieldstr)
|
||||
{
|
||||
const MuMsgField *field;
|
||||
|
||||
if (fieldstr)
|
||||
return NULL;
|
||||
|
||||
|
||||
field = mu_msg_field_from_name (fieldstr);
|
||||
if (!field && strlen(fieldstr) == 1)
|
||||
field = mu_msg_field_from_shortcut(fieldstr[0]);
|
||||
|
@ -95,36 +92,35 @@ sort_field_from_string (const char* fieldstr)
|
|||
}
|
||||
|
||||
|
||||
/* FIXME */
|
||||
static gboolean
|
||||
handle_options (MuConfigOptions *opts)
|
||||
{
|
||||
if (opts->ascending_flag && opts->descending_flag) {
|
||||
g_printerr ("ignoring option '--descending'\n");
|
||||
opts->sortdir_ascending = TRUE;
|
||||
} else if (!opts->descending_flag)
|
||||
opts->sortdir_ascending = !opts->descending_flag;
|
||||
|
||||
return TRUE;
|
||||
if (opts->ascending && opts->descending) {
|
||||
g_printerr ("only one of --ascending and --descending "
|
||||
"may be specied\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return opts->ascending = opts->descending ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||
{
|
||||
MuMsgXapian *row;
|
||||
const MuMsgField *sortfield;
|
||||
MuMsgXapian *row;
|
||||
const MuMsgField *sortfield;
|
||||
|
||||
sortfield = NULL;
|
||||
if (opts->sortfield_str) {
|
||||
sortfield = sort_field_from_string (opts->sortfield_str);
|
||||
sortfield = NULL;
|
||||
if (opts->sortfield) {
|
||||
sortfield = sort_field_from_string (opts->sortfield);
|
||||
if (!sortfield) /* error occured? */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
row = mu_query_xapian_run (xapian, query,
|
||||
sortfield,
|
||||
opts->sortdir_ascending);
|
||||
opts->ascending);
|
||||
if (!row) {
|
||||
g_printerr ("error: running query failed\n");
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in New Issue