1765 Commits

Author SHA1 Message Date
Lars Henriksen
8b39637a62 Move user information after save/reload to the command level
Moving user information to calcurse.c makes it easier to perform the actual
save/reload operatons in io.c, e.g. it is possible to load instead of
reload after a merge in conflict resolving.

The save/reload operations are of such importance that the user should always be
informed of the result (it's a bit disquieting when there is no reaction to a
save or reload command). Hence, the save/reload status messages are no longer
conditioned by show_dialogs(). No confirmation is asked for, so a message stays
until the status bar is updated by another action.

Care is taken to inform about save/reload actions that result in no change.

Texts are kept concise because of the limited message area. When conflicts are
present, whether saving or reloading, the "continue/merge/cancel" pattern seems
easier to grasp.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
d7777ed44e A save refinement: no action if everything is unchanged
A reload action will do nothing if in-memory data as well as data files are
unchanged. This commit accomplishes the equivalent for a save action.

Because saving of configuration data and key bindings are mixed up with saving
of data files, any changes in those will only be saved if data files also have
changed. Hence, configuration data and key bindings are also saved upon exit
from the configuration menu.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
5ad0019b23 Only reload if data files were changed (replacement)
This is a replacement for commits 57dd3d6 and 912124b.

The idea is to move the check for modified files and the list initialization
into io_load_data(), and let io_load_data() decide what to load. A new
argument is used to force a load.

The return code from new_data() (the renamed version of
io_check_data_files_modified()) tells which files have changed.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
ab0fe68225 Reload data after resolving save conflict (improved)
After resolving a save conflict with the merge tool, a save operation has,
in effect, occurred, and data files must be reloaded to import the result of
the conflict resolution.

This is a replacement for commit 2fe9c7e. The operations concerned with the user
interface are kept out the io-operations (as in all other cases) and take place
at the command-level in calcurse.c. and not at the io-level (io.c).

Shorter, more concise prompt texts.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
8c2ccebe35 Handling of modified flag
The flag modified (io.c) keeps track of the memory state of data:
	modified == 0: unchanged since load or last save
	modified == 1: changed since load or last save
It is now unset in io_load_data() and io_save_cal() only.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
e97360df71 Update windows at the right level
The wins_update() call is the responsibility of the caller of
io_resolve_save_conflict().

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
a5ae7256b3 Stop/start the notify main thread at the right level
The thread is stopped/started in wins_prepare/unprepare_external() when hooks
are run. There is no need to do it in io_reload_data(). In fact, because of the
nested calls

notify_stop_main_thread() <--- io_reload_data()
...
	notify_stop_main_thread() <--- hook/wins_prepare_external()
	...
	notify_start_main_thread() <--- hook/wins_unprepare_external()
...
notify_start_main_thread() <--- io_reload_data()

the thread has been running after the first hook anyway.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lars Henriksen
a94b0ecde0 Fix window update after hook execution
The introduction of hooks raised a problem with window updates. The diagnosis
in commit feb059e8 (Fix segmentation fault on reload with pre-load hook) was
right, the cure was wrong.

The problem is wins_update(), not the listbox contents. The wins_update() call
does not belong in wins_unprepare_external() (or in io_reload_data()), but at a
higher level. It should be called _after_ reload, as indeed it is in
key_generic_reload() when the listbox contents have been updated (todo as well
as appointments). The call was introduced in commit 8ae75f3 without comment.

The todo updates in io_reload_data() also belong in key_generic_reload() where
they were before commit 7f06c252.

When saving data, all panels must be updated in case a hook was executed.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lukas Fleischer
37d8725e78 contrib/caldav/Makefile.am: add config.sample
Fixes GitHub issue #144.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-10-21 20:01:34 +02:00
Lukas Fleischer
c4960aaf93 calcurse-caldav: fix auth method check
Fixes a regression introduced in 6a6c711 (calcurse-caldav: fix basic
authentication, 2018-07-20).

Addresses GitHub issue #149.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-09-27 07:33:47 +02:00
Lukas Fleischer
ea0a33645a README.md: add demo
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-30 07:25:25 +02:00
Lukas Fleischer
9f8622905c Update README.md
* Add more details on the project directory structure.
* Add information on contributions and donations.
* Move contributors to the manual but keep a reference.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-30 07:25:25 +02:00
Lukas Fleischer
5efc334c1b Fix memory leak in run_hook()
Fixes GitHub issue #139.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:22:29 +02:00
Lars Henriksen
7f448ee8cd Minor merge adjustments
Comments inserted.

Slightly different implementations of parse_time() and parse_datetime().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:15:33 +02:00
Lars Henriksen
0543df5f31 Fix memory leak in update_duration()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:15:33 +02:00
Lars Henriksen
b6cdc29255 Fix seg fault in update_rept()
Memory pointers must be initialized at the start in case memory is
freed (cleanup) before it is allocated.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:15:33 +02:00
Lars Henriksen
fa353e5eb7 Buffer mixup
Use one (small) buffer long enough to hold a date.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:15:33 +02:00
Lars Henriksen
223810cf0e Major overhaul of appointment/event input routines.
When setting start time for a new appointment, a date is disallowed
(in all other cases both time and date are still allowed).

Both date and time are displayed for the user to correct when an
appointment is changed or moved.

Built-in help in the status bar for display of input formats.

Several bug fixes that resulted in data inconsistencies (end time
before start time).

The routines use the enhanced parsing funtions to validate input:
ui_day_item_add(void)
	parse_datetime()
	parse_duration()
	parse_datetime()
ui_day_item_repeat(void)
	parse_date_duration()
	parse_date()
ui_day_item_edit(void)
	update_start_time()
		day_edit_time()
			parse_datetime()
	update_duration()
		parse_duration()
		parse_datetime()
	update_rept()
		parse_date_duration()
		parse_date()

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:15:33 +02:00
Lars Henriksen
fd635150a8 Start and end time validation.
All appointment times are checked for validity. Overflow by time
arithmetic is detected. End times are checked when appointments
are moved. Three functions are involved: parse_datetime(),
parse_duration() and parse_date_duration(); they all have a
new argument for validation purposes.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:03:28 +02:00
Lars Henriksen
c45da5f5ca New support functions for input validation.
check_sec(), overflow_add(), overflow_mul()

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:03:28 +02:00
Lars Henriksen
16d30327ba Refactoring update_duration/day_edit_duration.
Incorporated day_edit_duraton() into update_duration().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 10:03:28 +02:00
Lukas Fleischer
a5febe2e22 Make editing of punctual appointments more intuitive
When editing the start time, move the item instead of keeping the
previous start time as end time. When editing the end time, start with
an empty end time instead of the previous start time.

Fixes GitHub issue #89.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 09:28:56 +02:00
Lukas Fleischer
8466717f06 calcurse-caldav: print executed commands in debug mode
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 08:54:03 +02:00
Lukas Fleischer
41f4a92fa9 Only stop threads when exiting from interactive mode
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-25 08:47:18 +02:00
Lukas Fleischer
dd4d444c0c calcurse-caldav: print HTTP status codes in debug mode
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-21 05:51:35 +02:00
Lars Henriksen
ddc3fda5f1 Initialize variables in non-interactive mode in all cases
The changed handling of thread ids implies that they must be initialized
before exit of calcurse where they are used. Hence the function
vars_init() is now called irrespective of command line arguments.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-19 09:10:06 +02:00
Quentin Hibon
e9611ce3a6 Use a path instead of a file for -C option
Allows to specify a configuration directory containing:
* conf
* keys
* hooks

When used in combination with -D $ddir, $ddir contains all the other
files not mentioned above.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-08-05 18:36:25 +02:00
Lars Henriksen
3788df6d78 Fix multiple, simultaneous periodic saves
A new save thread was started every time a positive periodic save value
was input in the general options configuration menu. And only one thread
can be stopped by entering 0, also when done repeatedly.

Always stop the old thread before (possibly) starting a new.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-28 14:21:38 +02:00
Lars Henriksen
5e53708648 Solve deadlock in notification bar
calcurse deadlocks when

1) an upcoming appointment is on display in the notification bar,
2) an external command (like help) is started,
3) the time for the upcoming appointment arrives, and
4) the external command is exited.

The notification bar thread is stopped while the external command is
running. Upon exit from the external command, the n-bar thread is
restarted and calcurse locks.

The cause is the way in which the main notification bar thread is
stopped:

static pthread_t notify_t_main;
void notify_stop_main_thread(void)
{
	if (notify_t_main) {
		pthread_cancel(notify_t_main);
		pthread_join(notify_t_main, NULL);
	}
}

Objects of type pthread_t are opaque and should not be accessed
directly.  Initially notify_t_main is an uninitialised static variable
(0), but later it has a value, which may or may not be the thread id of
the notification main thread.

Note that the thread id after exit of a thread may become the thread id
of a new thread. Thus the variable set when the thread is created, is
invalid after exit of the thread.

Specifically, the first time notify_stop_main_thread() is called (by
notify_start_main_thread() before the thread is created) is harmless
(because notify_t_main is 0). Calling notify_stop_main_thread() later
may be either

OK
    because the main thread is running, or
harmless
    because no thread with id notify_t_main is running: the two
    functions will fail with return value ESRCH (no such process), or
fatal
    because an unrelated thread with this thread id is running: it will
    be cancelled, and the join may or may not succeed depending on
    whether the thread is joinable or detached.

The "unrelated thread" could be the next-appointment thread,
notify_thread_app, launched by notify_check_next_app().

Always calling notify_stop_main_thread() before starting the main thread
becomes fatal when notify_check_next_app() is called shortly before
notify_start_main_thread(). This is the case in the scenario described.
The next-app-thread is then running when notify_stop_main_thread() is
called, and apparently it has the thread id of the old main thread
(confirmed by logging the return values from pthread_cancel() and
pthread_join(); the first succeeds while the second fails with EINVALID
which means that the thread is not joinable). The next-app-thread will
therefore exit without unlocking mutexes.

Ensure that notify_t_main, in case the notify main thread is not
running, has a value that it will never have when it is running. A
possibility is the thread id of the main() calcurse process (returned by
pthread_self()).

Check for this condition in notify_stop_main_thread() and set
notify_t_main when the thread is stopped.

Similar changes have been introduced for the periodic save thread and
the calendar date thread.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-28 14:06:15 +02:00
Dino Macri
6a6c7117de calcurse-caldav: fix basic authentication
Read whether basic authentication is used and add the credentials to
httplib2 when making a request.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-22 11:00:12 +02:00
Dino Macri
61dc7ab538 calcurse-caldav: add HTTP support
Introduce support for HTTP connections. Use "HTTPS" in the config file
to enable/disable (default is enabled). The option modifies the prefix
of the host name to "http://" when disabled, rather than always using
"https://" with no option to change.

httplib2 automatically handles URLs beginning with either http or https.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-07-22 10:58:33 +02:00
Lars Henriksen
163730cabf Fix end-before-start inconsistency
Due to deficient validation, it is possible to get an inconsistent
database with an appointment that ends before it begins. Edit an
existing one and specify an end time by a date that precedes the start
date, or create a new one and give a date as end time that precedes the
start. Then exit calcurse; on restart it will report a data error and
exit.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-05 05:52:39 +02:00
Lars Henriksen
40eb6f809e Fix appointment becoming event
You try to enter an appointment, but enter an invalid start time (by
mistake). Calcurse rejects the input. You enter the correct start time
and calcurse asks for the description, not the end time, i.e. you get an
event.

The check for an event must only be performed on valid input.

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-05 05:52:30 +02:00
Lars Henriksen
500b0c080e Support UTF-8 encoded characters in user choices
Translations (in po-files) of texts that are used for alternative
choices (e.g. [dwmy]), may use UTF-8 encoded Unicode characters (e.g.
[éãüå]).

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:28:46 +02:00
Lars Henriksen
7078556f9d Key bindings for UTF-8 encoded characters
Internally characters (keys) have two representations: integers and key
names. Key names are characters strings, usually the name of the
character; e.g., the character A has the representations 65 and "A", and
the tab character the representations 9 and "TAB".

The function keys_int2str() turns the integer representation of a
key/character into the key name.

For display purposes the key names are usually confined to have display
width at most three. Some curses pseudo-keys have longer key names;
e.g., the back-tab character is "KEY_BTAB". A long key name makes a
character difficult to recognize in the status bar menu.

The key name of a multibyte, UTF-8 encoded character is the conventional
Unicode name of the code point; e.g., the character ü has key name
"U+00FC" because ü is the code point 0xFC. Most of these look alike in
the status bar menu.

The patch makes the key name of a multibyte character look like that of
a singlebyte character: the character itself, i.e. the key name of the
character ü is "ü".

The main tool is implementation of a utf8_encode() routine.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:26:12 +02:00
Lars Henriksen
431e4a00e7 Rename utf8_ord() to utf8_decode()
Purely for readability and in preparation for the counterpart utf8_encode().

Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 11:24:37 +02:00
Lukas Fleischer
30f411257a Do not stop already cancelled notification thread
Add a static state variable to indicate whether the notification thread
is already running or not. Only start the thread if the notification
thread is paused. Only stop the thread if the notification thread is
actually running.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 10:28:28 +02:00
Lukas Fleischer
e55aead126 Only lock save mutex as short as possible
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-06-03 10:28:28 +02:00
Lars Henriksen
d5961baa13 Check for empty string in config_parse_int()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-28 17:31:06 +02:00
Quentin Hibon
407d5abd23 Add option to specify the configuration file used
The configuration file (~/.calcurse/conf by default) can now be
specified with -C or --conf.

Workaround for GitHub issue #86.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-28 06:29:09 +02:00
Lukas Fleischer
574156be7c Always NUL-terminate buffer in note_gc()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:05:50 +02:00
Lukas Fleischer
68cac7345c Always NUL-terminate buffer in keys_fill_missing()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:05:41 +02:00
Lukas Fleischer
7efe03cf05 Fix buffer overflow in keys_action_allkeys()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 12:03:03 +02:00
Lukas Fleischer
2cd60c78cf Always NUL-terminate buffer in io_load_keys()
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:52:41 +02:00
Lukas Fleischer
65c2b6d9b8 notify.c: fix several buffer overflows
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:51:38 +02:00
Lukas Fleischer
8abb1a93ad Properly NUL-terminate the day heading after editing
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:47:01 +02:00
Lukas Fleischer
7e5f8ed7bc Avoid buffer overrun in config_parse_str()
The previous implementation only read a prefix from the configuration
file if the configuration value was too long and forgot to terminate the
string with a NUL character.

Return 0 if the string is too long instead.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:44:30 +02:00
Lars Henriksen
bb7381765c Scrollbar and right window border (corrected)
When a scrollbar is on display in APP or TOD windows, the right
vertical border (outside the scrollbar) is not highlighted
when the window is selected.

The scrollbar is always highlighted:
- when APP or TOD is deselected
- in configuration windows where borders otherwise are not

The patch moves the scrollbar parameters (except highlight)
from arguments of draw_scrollbar() to the function itself.
The highlight argument was 1; instead it is set higher in
the call hierarchy (wins_update_panels()) and passed on down.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:31:43 +02:00
Lars Henriksen
a5cc46cd55 Transparent cursor fix
Commit f8e6e0d (Fix no-colour theme, 2017-12-10) partly destroyed the
cursor in getstring() by turning it into a solid block. The fix
reintroduces wchgat() which requires a color pair argument. When no
colors are wanted, color pair 0 is used.

A similar problem exists in the layout and colour customization windows
and is fixed in the same way: move to the position and apply the reverse
video attribute.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-26 11:30:03 +02:00
Lars Henriksen
65dd82a626 Fix end-of-string calculation
In keys_fill_missing() a pointer is walked through a string of
space-separated character names, but misses the string-terminating null
character.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
2018-05-24 16:23:23 +02:00