1176 Commits

Author SHA1 Message Date
Lars Henriksen
3095bf4214 Add missing string initialization
When introducing the fmt_day_heading() function in commit d56cc7a (Make
heading in appointments panel configurable, 2017-08-19), we forgot to
initialize the dynamic string. This resulted in calling mem_free() with
a garbage pointer, potentially resulting in a segmentation fault. Fix
this by calling string_init() before using the string.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-04 16:34:19 +02:00
Lukas Fleischer
2e584f03e6 Replace remaining uses of wgetch() by keys_wgetch()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 16:37:35 +02:00
Lukas Fleischer
53f0f1d2e3 Add a function to wait for any key press
Introduce a new function keys_wait_for_any_key() and use it instead of
wgetch() whenever the return value is discarded.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 16:37:35 +02:00
Lukas Fleischer
8373ecfe51 Improve default selection when editing key bindings
When adding a new key binding, automatically select the new binding.
When removing a key binding, keep the selection index (unless the last
binding of a row is removed).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 15:51:01 +02:00
Lukas Fleischer
6521d8cc0a Use strncpy() properly in general_option_edit()
Always use strncpy() to copy strings between fixed-size buffers and pass
the buffer size as maximal length parameter.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-09-03 09:31:33 +02:00
Lukas Fleischer
578091f051 Add support for UTF-8 key bindings
A new function keys_wgetch() reads full UTF-8 characters instead of
single ASCII characters only.

Key bindings for regular ASCII characters are stored in a hash map while
the actions of keys with higher code points are stored in a linked list
for space efficiency.

The key serialization methods are updated to handle UTF-8 characters as
well; extended UTF-8 characters (characters not in the ASCII range) are
serialized by using the hexadecimal representation of the corresponding
code points (e.g. "U+00E4").

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:39:23 +02:00
Lukas Fleischer
8544e4a570 Rename keys_getch() to keys_get()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:26:10 +02:00
Lukas Fleischer
273e32d43d Factor out UTF-8 code point decoding
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:17:28 +02:00
Lukas Fleischer
6cb26c2f27 Relocate HANDLE_KEY macros
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-30 16:15:39 +02:00
Quentin Hibon
04fb4caf8f Implement CTRL-U in getstring()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-29 20:14:39 +02:00
Lars Henriksen
26aeddd490 Use nl_langinfo() for month and day names
Use the locale setting to fetch the month names and abbreviated day
names.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lars Henriksen
3efb3e42c9 Remove extra star from recurrent appointments
In the appointments panel, an appointment has a '-' to mark the time
span, and the description on the following line is slightly indented.
When the appointment is changed into a recurrent one, the '-' is changed
to a '*', making it easily distinguishable but the description also gets
a '*', thus breaking the pattern. Drop the extra '*'.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lars Henriksen
e12875b420 Remove some leftovers from the past
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lars Henriksen
d56cc7acfe Make heading in appointments panel configurable
Add a new configuration variable format.dayheading to set the format of
the date displayed at the top of the event and appointment list.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lukas Fleischer
550a2e9379 Extend strings API for formatted dates
Add two new functions string_catftime(), resp. string_strftime(), which
can be used to append, resp. print, a formatted date to a dynamic
string.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lars Henriksen
0c63b4661f Make the selected day in the calendar stand out
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:30:38 +02:00
Lukas Fleischer
7924315bfb Fix support for punctual appointments at 00:00
When checking whether an appointment belongs to a given day in
apoint_inday(), the return value was 0 if the end time of the
appointment matched 00:00 on that day (because we do not want to include
appointments starting on the day before and lasting until midnight).
However, this means that punctual appointments at 00:00 were not
included in any day. Fix the apoint_inday() logic to take this into
consideration.

Fixes GitHub issue #39.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-28 07:06:06 +02:00
Lars Henriksen
b36dd2e614 Fix empty warning box when key is already in use
When adding a key already in use for another action, a warning box is
displayed. The text length is limited by the window width through the
use of strncpy(). If the limit is exceeded, the string will have no null
termination, resulting in unpredictable behaviour.

A similar problem in fatalbox() is fixed as well.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-12 15:40:02 +02:00
Lars Henriksen
53db74ab34 Fix fatal error when using the help command
Check that an action is defined for the key.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-12 15:38:55 +02:00
Lars Henriksen
0df373f26a Check for optional argument to -s option
Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-08-12 15:38:24 +02:00
Lukas Fleischer
43cd40e8ce Include stdarg.h when using variable argument lists
Fixes GitHub issue #36.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-07-28 16:09:43 +02:00
Lukas Fleischer
5722d2ea4c Fix segmentation fault when changing colors
The pair_content() function can be used to retrieve a color pair. The
foreground and the background color numbers are written to addresses
specified by the second and third parameters. While both parameters were
optional in older ncurses implementations (making it possible to pass
NULL pointers if the one does not care about either foreground or
background color), recent implementations seem to assume that both
parameters are valid pointers. Thus, instead of passing NULL, we need to
pass a pointer to a dummy variable when we do not care about the
background color.

Partly fixes GitHub issue #31.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-07-28 16:02:46 +02:00
Lukas Fleischer
5aa7a0962a Fix another error in the notification code
In addition to checking whether a recurrent item predates the current
next appointment, we need to check that the actual occurrence of the
item predates the current appointment as well.

Fixes GitHub issue #26.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-02-11 11:50:51 +01:00
Lukas Fleischer
2084f353e3 Fix notification of recurrent appointments
The recur_apoint_starts_before() filter function expected the second
parameter to be passed by value, whereas its only caller passed the
value by reference. For consistency with apoint_starts_after(), change
the signature and the implementation of recur_apoint_starts_before()
such that the parameter is passed by reference.

Also, add a comment to the only caller of recur_apoint_starts_before()
to clarify on why recur_apoint_starts_before() is used.

Fixes GitHub issue #25.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-02-09 08:43:32 +01:00
Lukas Fleischer
ed6035afb1 Do not read past NUL character in ical_get_value()
Make sure we never read beyond the end of the buffer, even if the
terminating quote of a quoted string is missing.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-02-08 07:32:35 +01:00
Lukas Fleischer
e4e2e0eb20 Gracefully parse iCal parameters with colons
According to RFC 5545, iCalendar content lines can have optional
parameters, which can be quoted strings containing colons (":"). Make
sure that such colons are not interpreted as delimiters marking the
start of the value string.

Also, add a test case that covers this corner case.

Reported-by: Håkan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-02-07 21:54:05 +01:00
Lukas Fleischer
9f6678bc49 Update copyright ranges
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2017-01-12 08:40:30 +01:00
Lukas Fleischer
fd97187bcd Fix visible region after loading list box items
Make sure the visible region is updated after loading items, e.g. when
the users switches from the full todo list to the "uncompleted items
only" view.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-30 11:57:01 +01:00
Lukas Fleischer
cf75caeb61 Fix listbox_fix_visible_region()
Make sure that listbox_fix_visible_region() always updates the visible
region to show the entire list if it fits into the box. Also, reuse
listbox_fix_visible_region() in listbox_resize() instead of duplicating
the code.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-30 11:56:02 +01:00
Lukas Fleischer
0d74c14fd1 Do not start the daemon more than once
Avoid starting multiple daemon instances if the --daemon argument is
passed and the daemon is already running. Terminate the already running
instance before spawning a new one instead.

Suggested-by: Vlad Glagolev <scm@vaygr.net>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-19 18:19:02 +02:00
Lukas Fleischer
39d3007318 Prevent segfault when all todo items are hidden
To prevent from illegal memory access, we checked whether the list of
todo items is empty before performing an interactive todo item action
such as flagging or removal. However, since 1a4bf2b (Add a "hide
completed" view to the todo panel, 2016-01-17), it is possible to hide
completed items from the todo panel. Thus, it may occur that the todo
list box is empty while the list of todo items is not.

To detect such situations as well, teach todo_get_item() to return NULL
if the requested item does not exist. Then, instead of checking whether
the todo item list is non-empty, make sure that the item returned by
todo_get_item() is non-NULL when performing an action.

Reported-by: Vlad Glagolev <scm@vaygr.net>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-14 20:29:50 +02:00
Lukas Fleischer
9ef5fe2191 Always use memory management wrappers
Use mem_*() wrappers instead of directly accessing libc functions when
allocating/deallocating memory.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-13 19:51:43 +02:00
Vlad Glagolev
da6334cf38 Prevent free-before-init of timstr
Fixes a crash when editing the repetition of an appointment and passing
an empty repetition value.

Signed-off-by: Vlad Glagolev <scm@vaygr.net>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-13 06:44:26 +02:00
Lukas Fleischer
007a73f7a2 Replace parse_datetime() constants by named flags
Remove the magic constants used in the return value of parse_datetime()
and use named flags instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-10 09:02:42 +02:00
Lukas Fleischer
48bd82a003 Refactor duration/end time parsing
Replace all remaining invocations of parse_time() by parse_datetime()
which now indicates whether a date was supplied or not.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-10 09:02:42 +02:00
Lukas Fleischer
adf29c8ee9 Support dates when specifying start/end times
Add support for combined date/time or date-only strings when specifying
the start or end time of a new item.

This is a follow-up to 1f39b5c (Add support for moving items to another
day, 2016-09-30).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-09 20:21:04 +02:00
Lukas Fleischer
343d68596d Factor out parse_datetime()
Create a new function that takes a time stamp and updates the date or
time components of that time stamp according to a given date/time
string. Use that function for updating the start time of an item.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-09 18:12:45 +02:00
Lukas Fleischer
1f39b5c668 Add support for moving items to another day
When moving an item (or when changing the start time of an item), allow
for optionally specifying a date. If both date and time are entered, the
item is updated to start on the given date and time. If only a date is
entered, the item is modified to start on the given date, keeping the
current start time. If only a time is entered, the item is modified to
start on the current date and the new start time.

Fixes GitHub issue #12.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-08 14:42:51 +02:00
Lukas Fleischer
1003be18df Refactor day_edit_time()
Make the function more flexible by returning the updated time instead of
single hour and minute components.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-10-01 09:00:23 +02:00
Lukas Fleischer
1af9ccccd7 Automatically select new appointments/events
This is a follow-up to commit 65b699f (Make automatic selection of
appointments/events smarter, 2016-02-16). Newly created appointments and
events are now selected automatically.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-09-28 19:03:20 +02:00
Lukas Fleischer
ab9256adf0 Fix out-of-bounds memory access
Do not try to access freed day items. This also fixes unexpected
selection changes after modifying appointments or events.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-09-28 19:02:04 +02:00
Lukas Fleischer
77d5b10ee0 Fix key binding pagination
Do not create an empty key bindings page if the number of bindings is a
multiple of the number of slots per page.

Also, add comments to explain the computation.

Reported-by: Kevin Wang <kevin.wang2004@hotmail.com>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-09-27 08:56:12 +02:00
Lukas Fleischer
55afda8a73 Stop all threads before leaving curses mode
This prevents from notification bar artifacts being drawn after leaving
interactive mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-09-13 08:28:24 +02:00
Lukas Fleischer
e6f8a2932a Avoid starting the notification thread twice
Starting the notification thread more than once can result in strange
behavior. For example, when launching external commands, only the most
recently started thread is stopped which results in the external
command's screen output being overwritten by the notification bar.

Currently, there are a couple of situations where the thread is started
twice. As a first countermeasure, explicitly check whether the thread is
already running (and terminate it) before starting a new one.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-08-24 21:49:53 +02:00
Lukas Fleischer
8fe9dd1c2b Remove duplicate code in draw_monthly_view()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-06-27 08:59:35 +02:00
Lukas Fleischer
203ac0aa61 Highlight days with non-recurrent items
Use a different color for days with non-recurrent items in the calendar
panel. This makes it possible to easily spot days that actually contain
appointments.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-06-27 08:57:42 +02:00
Lukas Fleischer
1531425005 Support relative dates when adding recurrences
In commit f5d8b5e (Support durations in recurrence ending dates,
2016-02-25), we added support for the `+xxwxxd` syntax when specifying
recurrence end dates. However, this only worked when *editing* the
recurrence, not when converting a regular item to a recurrent one. Fix
this and support the new syntax in both cases.

Also, mention the new syntax in the prompt.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-04-01 08:51:26 +02:00
Lukas Fleischer
4633846550 Fix apoint_inday() with long appointments
Fixes a regression introduced in 9e160fa (Do not assume that days always
have 86400 seconds, 2016-03-27).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-03-28 08:45:49 +02:00
Lukas Fleischer
9e160fac16 Do not assume that days always have 86400 seconds
Make that date membership is computed correctly, even if a day has less
than 86400 seconds (e.g. after changing clocks).

Reported-by: Hakan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-03-27 13:06:18 +02:00
Lukas Fleischer
e1b6d22669 Add proper UTF-8 support to the notification area
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2016-02-26 21:52:14 +01:00