diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/args.c | 34 | ||||
-rw-r--r-- | src/calcurse.c | 4 | ||||
-rw-r--r-- | src/calcurse.h | 28 | ||||
-rw-r--r-- | src/io.c | 18 |
4 files changed, 68 insertions, 16 deletions
@@ -56,6 +56,9 @@ enum { OPT_FILTER_END_TO, OPT_FILTER_END_AFTER, OPT_FILTER_END_BEFORE, + OPT_FILTER_PRIORITY, + OPT_FILTER_COMPLETED, + OPT_FILTER_UNCOMPLETED, OPT_FROM, OPT_TO, OPT_FMT_APT, @@ -516,6 +519,10 @@ static int parse_type_mask(const char *str) mask |= TYPE_MASK_RECUR_APPT; } else if (!strcmp(p, "recur")) { mask |= TYPE_MASK_RECUR; + } else if (!strcmp(p, "cal")) { + mask |= TYPE_MASK_CAL; + } else if (!strcmp(p, "todo")) { + mask |= TYPE_MASK_TODO; } else { mask = 0; goto cleanup; @@ -552,7 +559,8 @@ int parse_args(int argc, char **argv) /* Query ranges */ long from = -1, to = -1; /* Filters */ - struct item_filter filter = { TYPE_MASK_ALL, NULL, -1, -1, -1, -1 }; + struct item_filter filter = + { TYPE_MASK_ALL, NULL, -1, -1, -1, -1, 0, 0, 0 }; /* Format strings */ const char *fmt_apt = " - %S -> %E\n\t%m\n"; const char *fmt_rapt = " - %S -> %E\n\t%m\n"; @@ -606,6 +614,9 @@ int parse_args(int argc, char **argv) {"filter-end-to", required_argument, NULL, OPT_FILTER_END_TO}, {"filter-end-after", required_argument, NULL, OPT_FILTER_END_AFTER}, {"filter-end-before", required_argument, NULL, OPT_FILTER_END_BEFORE}, + {"filter-priority", required_argument, NULL, OPT_FILTER_PRIORITY}, + {"filter-completed", no_argument, NULL, OPT_FILTER_COMPLETED}, + {"filter-uncompleted", no_argument, NULL, OPT_FILTER_UNCOMPLETED}, {"from", required_argument, NULL, OPT_FROM}, {"to", required_argument, NULL, OPT_TO}, {"format-apt", required_argument, NULL, OPT_FMT_APT}, @@ -773,6 +784,17 @@ int parse_args(int argc, char **argv) EXIT_IF(filter.end_to == -1, _("invalid filter end date")); break; + case OPT_FILTER_PRIORITY: + filter.priority = atoi(optarg); + EXIT_IF(filter.priority < 1 || filter.priority > 9, + _("invalid priority")); + break; + case OPT_FILTER_COMPLETED: + filter.completed = 1; + break; + case OPT_FILTER_UNCOMPLETED: + filter.uncompleted = 1; + break; case OPT_FROM: from = parse_datearg(optarg); EXIT_IF(from == -1, _("invalid start date")); @@ -852,7 +874,7 @@ int parse_args(int argc, char **argv) io_check_file(path_apts); io_check_file(path_todo); io_load_app(&filter); - io_load_todo(); + io_load_todo(&filter); note_gc(); non_interactive = 1; } else if (Qflag) { @@ -864,7 +886,7 @@ int parse_args(int argc, char **argv) vars_init(); config_load(); /* To get output date format. */ io_load_app(&filter); - io_load_todo(); + io_load_todo(&filter); day.dd = day.mm = day.yyyy = 0; date_arg_from_to(from, to, 1, fmt_apt, fmt_rapt, fmt_ev, fmt_rev, &limit); @@ -877,7 +899,7 @@ int parse_args(int argc, char **argv) /* Get default pager in case we need to show a log file. */ vars_init(); io_load_app(&filter); - io_load_todo(); + io_load_todo(&filter); io_import_data(IO_IMPORT_ICAL, ifile); io_save_apts(path_apts); io_save_todo(path_todo); @@ -887,14 +909,14 @@ int parse_args(int argc, char **argv) io_check_file(path_apts); io_check_file(path_todo); io_load_app(&filter); - io_load_todo(); + io_load_todo(&filter); io_export_data(xfmt); non_interactive = 1; return non_interactive; } if (tflag) { io_check_file(path_todo); - io_load_todo(); + io_load_todo(&filter); todo_arg(tnum, fmt_todo, &limit); non_interactive = 1; } diff --git a/src/calcurse.c b/src/calcurse.c index 242a142..0d78000 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -332,7 +332,7 @@ static inline void key_generic_reload(void) recur_event_llist_init(); todo_init_list(); - io_load_todo(); + io_load_todo(NULL); io_load_app(NULL); io_unset_modified(); ui_todo_load_items(); @@ -683,7 +683,7 @@ int main(int argc, char **argv) config_load(); wins_erase_status_bar(); io_load_keys(conf.pager); - io_load_todo(); + io_load_todo(NULL); io_load_app(NULL); io_unset_modified(); wins_slctd_set(conf.default_panel); diff --git a/src/calcurse.h b/src/calcurse.h index 0290520..2c6dd00 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -373,7 +373,7 @@ union aptev_ptr { struct recur_event *rev; }; -/* Available types of items. */ +/* Available item types in the calendar view. */ enum day_item_type { DAY_HEADING = 1, RECUR_EVNT, @@ -383,13 +383,24 @@ enum day_item_type { APPT }; +/* Available item types. */ +enum item_type { + TYPE_EVNT, + TYPE_APPT, + TYPE_RECUR_EVNT, + TYPE_RECUR_APPT, + TYPE_TODO +}; + /* Available item type masks. */ -#define TYPE_MASK_EVNT (1 << EVNT) -#define TYPE_MASK_APPT (1 << APPT) -#define TYPE_MASK_RECUR_EVNT (1 << RECUR_EVNT) -#define TYPE_MASK_RECUR_APPT (1 << RECUR_APPT) +#define TYPE_MASK_EVNT (1 << TYPE_EVNT) +#define TYPE_MASK_APPT (1 << TYPE_APPT) +#define TYPE_MASK_RECUR_EVNT (1 << TYPE_RECUR_EVNT) +#define TYPE_MASK_RECUR_APPT (1 << TYPE_RECUR_APPT) #define TYPE_MASK_RECUR (TYPE_MASK_RECUR_EVNT | TYPE_MASK_RECUR_APPT) -#define TYPE_MASK_ALL (TYPE_MASK_EVNT | TYPE_MASK_APPT | TYPE_MASK_RECUR) +#define TYPE_MASK_CAL (TYPE_MASK_EVNT | TYPE_MASK_APPT | TYPE_MASK_RECUR) +#define TYPE_MASK_TODO (1 << TYPE_TODO) +#define TYPE_MASK_ALL (TYPE_MASK_CAL | TYPE_MASK_TODO) /* Filter settings. */ struct item_filter { @@ -399,6 +410,9 @@ struct item_filter { long start_to; long end_from; long end_to; + int priority; + int completed; + int uncompleted; }; /* Generic item description (to hold appointments, events...). */ @@ -781,7 +795,7 @@ unsigned io_save_todo(const char *); unsigned io_save_keys(void); void io_save_cal(enum save_display); void io_load_app(struct item_filter *); -void io_load_todo(void); +void io_load_todo(struct item_filter *); void io_load_keys(const char *); int io_check_dir(const char *); unsigned io_dir_exists(const char *); @@ -644,7 +644,7 @@ void io_load_app(struct item_filter *filter) } /* Load the todo data */ -void io_load_todo(void) +void io_load_todo(struct item_filter *filter) { FILE *data_file; char *newline; @@ -687,6 +687,22 @@ void io_load_todo(void) if (newline) *newline = '\0'; io_extract_data(e_todo, buf, sizeof buf); + + /* Filter item. */ + if (filter) { + if (!(filter->type_mask & TYPE_MASK_TODO)) + continue; + if (filter->regex && + regexec(filter->regex, e_todo, 0, 0, 0)) + continue; + if (filter->priority && id != filter->priority) + continue; + if (filter->completed && id > 0) + continue; + if (filter->uncompleted && id < 0) + continue; + } + todo_add(e_todo, id, note); ++nb_tod; } |