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},
|
"print the Xapian query", NULL},
|
||||||
{"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields,
|
{"fields", 'f', 0, G_OPTION_ARG_STRING, &opts->fields,
|
||||||
"fields to display in output", NULL},
|
"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},
|
"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},
|
"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},
|
"sort descending (down)", NULL},
|
||||||
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
{ NULL, 0, 0, 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
@ -128,6 +128,9 @@ mu_config_init (MuConfigOptions *opts)
|
||||||
/* querying */
|
/* querying */
|
||||||
opts->xquery = FALSE;
|
opts->xquery = FALSE;
|
||||||
opts->fields = "d f s";
|
opts->fields = "d f s";
|
||||||
|
opts->sortfield = "d";
|
||||||
|
opts->ascending = FALSE;
|
||||||
|
opts->descending = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,10 @@ struct _MuConfigOptions {
|
||||||
search results */
|
search results */
|
||||||
const char *fields; /* fields to show in output */
|
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 descending; /* sort descending? */
|
||||||
gboolean sortdir_descending ; /* sort descending? */
|
gboolean ascending;
|
||||||
gboolean sortdir_ascending;
|
|
||||||
gboolean ascending_flag, descending_flag;
|
|
||||||
};
|
};
|
||||||
typedef struct _MuConfigOptions MuConfigOptions;
|
typedef struct _MuConfigOptions MuConfigOptions;
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,7 @@ const MuMsgField*
|
||||||
sort_field_from_string (const char* fieldstr)
|
sort_field_from_string (const char* fieldstr)
|
||||||
{
|
{
|
||||||
const MuMsgField *field;
|
const MuMsgField *field;
|
||||||
|
|
||||||
if (fieldstr)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
field = mu_msg_field_from_name (fieldstr);
|
field = mu_msg_field_from_name (fieldstr);
|
||||||
if (!field && strlen(fieldstr) == 1)
|
if (!field && strlen(fieldstr) == 1)
|
||||||
field = mu_msg_field_from_shortcut(fieldstr[0]);
|
field = mu_msg_field_from_shortcut(fieldstr[0]);
|
||||||
|
@ -95,36 +92,35 @@ sort_field_from_string (const char* fieldstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* FIXME */
|
|
||||||
static gboolean
|
static gboolean
|
||||||
handle_options (MuConfigOptions *opts)
|
handle_options (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
if (opts->ascending_flag && opts->descending_flag) {
|
if (opts->ascending && opts->descending) {
|
||||||
g_printerr ("ignoring option '--descending'\n");
|
g_printerr ("only one of --ascending and --descending "
|
||||||
opts->sortdir_ascending = TRUE;
|
"may be specied\n");
|
||||||
} else if (!opts->descending_flag)
|
return FALSE;
|
||||||
opts->sortdir_ascending = !opts->descending_flag;
|
}
|
||||||
|
|
||||||
return TRUE;
|
return opts->ascending = opts->descending ? FALSE : TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
MuMsgXapian *row;
|
MuMsgXapian *row;
|
||||||
const MuMsgField *sortfield;
|
const MuMsgField *sortfield;
|
||||||
|
|
||||||
sortfield = NULL;
|
sortfield = NULL;
|
||||||
if (opts->sortfield_str) {
|
if (opts->sortfield) {
|
||||||
sortfield = sort_field_from_string (opts->sortfield_str);
|
sortfield = sort_field_from_string (opts->sortfield);
|
||||||
if (!sortfield) /* error occured? */
|
if (!sortfield) /* error occured? */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = mu_query_xapian_run (xapian, query,
|
row = mu_query_xapian_run (xapian, query,
|
||||||
sortfield,
|
sortfield,
|
||||||
opts->sortdir_ascending);
|
opts->ascending);
|
||||||
if (!row) {
|
if (!row) {
|
||||||
g_printerr ("error: running query failed\n");
|
g_printerr ("error: running query failed\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in New Issue