]> Pileus Git - lackey/commitdiff
Auto select the first event from calendar
authorAndy Spencer <andy753421@gmail.com>
Sun, 27 Nov 2016 08:12:55 +0000 (08:12 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 28 Nov 2016 09:54:02 +0000 (09:54 +0000)
If the calendar listed on the command line as an event in the future,
select soonest upcoming event. If all the events are in the past, then
just pick the first event in the calendar.

src/args.c

index d7a6c685ec6d29dc49c3c4b5cacba787b2135a7b..d577fdc32b64549e923d6471bd5793285c8b3864 100644 (file)
@@ -38,8 +38,9 @@ struct option long_options[] = {
        {"week", 2, NULL, 'w'},
 };
 
-static int print_day  = 0;
-static int print_week = 0;
+static int   print_day  = 0;
+static int   print_week = 0;
+static char *calendar   = NULL;
 
 /* Usage */
 static void usage(char *name)
@@ -83,6 +84,9 @@ void args_init(void)
                }
        }
 
+       /* Save default calendar */
+       calendar = argv[optind];
+
        /* Load calendars */
        for (int i = optind; i < argc; i++)
                cal_config("ical", argv[i], "location", argv[i]);
@@ -94,6 +98,23 @@ void args_init(void)
 
 void args_main(void)
 {
+       /* Focus the default calendar */
+       if (calendar) {
+               event_t *event = EVENTS;
+               date_t   start = {SEL.year, SEL.month, SEL.day, 0, 0};
+               while (event && compare(&start, &event->start) > 0)
+                       event = event->next;
+               while (event && !match(calendar, event->cal->name))
+                       event = event->next;
+               if (!event)
+                       event = EVENTS;
+               while (event && !match(calendar, event->cal->name))
+                       event = event->next;
+               if (event)
+                       SEL = event->start;
+       }
+
+       /* Print days or week */
        if (print_day || print_week) {
                event_t *event = EVENTS;
                for (int d = 0; d < (print_day ? 1 : 7); d++) {