Yet another style for source code. GNU style now used (I am fed up with tabs...)

This commit is contained in:
Frederic Culot
2008-04-12 21:14:03 +00:00
parent 0c281d2c1e
commit efd782699b
33 changed files with 7612 additions and 7053 deletions
+4
View File
@@ -1,3 +1,7 @@
12 Apr 2008:
Yet another style for source code. GNU style now used (I am fed up
with tabs...)
09 Apr 2008: 09 Apr 2008:
Tony's patch concerning date format configuration imported, many Tony's patch concerning date format configuration imported, many
thanks to him thanks to him
+463 -419
View File
File diff suppressed because it is too large Load Diff
+38 -34
View File
@@ -1,4 +1,4 @@
/* $calcurse: apoint.h,v 1.12 2008/01/20 10:45:38 culot Exp $ */ /* $calcurse: apoint.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -39,42 +39,46 @@
#define APOINT_NOTIFY 0x1 /* Item needs to be notified */ #define APOINT_NOTIFY 0x1 /* Item needs to be notified */
#define APOINT_NOTIFIED 0x2 /* Item was already notified */ #define APOINT_NOTIFIED 0x2 /* Item was already notified */
typedef struct apoint_llist_node { typedef struct apoint_llist_node
struct apoint_llist_node *next; {
long start; /* seconds since 1 jan 1970 */ struct apoint_llist_node *next;
long dur; /* duration of the appointment in seconds */ long start; /* seconds since 1 jan 1970 */
char state; /* 8 bits to store item state */ long dur; /* duration of the appointment in seconds */
char *mesg; char state; /* 8 bits to store item state */
char *note; char *mesg;
} apoint_llist_node_t; char *note;
}
apoint_llist_node_t;
typedef struct apoint_llist { typedef struct apoint_llist
apoint_llist_node_t *root; {
pthread_mutex_t mutex; apoint_llist_node_t *root;
} apoint_llist_t; pthread_mutex_t mutex;
}
apoint_llist_t;
extern apoint_llist_t *alist_p; extern apoint_llist_t *alist_p;
int apoint_llist_init(void); int apoint_llist_init (void);
void apoint_hilt_set(int); void apoint_hilt_set (int);
void apoint_hilt_decrease(void); void apoint_hilt_decrease (void);
void apoint_hilt_increase(void); void apoint_hilt_increase (void);
int apoint_hilt(void); int apoint_hilt (void);
apoint_llist_node_t *apoint_new(char *, char *, long, long, char); apoint_llist_node_t *apoint_new (char *, char *, long, long, char);
void apoint_add(void); void apoint_add (void);
void apoint_delete(conf_t *, unsigned *, unsigned *); void apoint_delete (conf_t *, unsigned *, unsigned *);
unsigned apoint_inday(apoint_llist_node_t *, long); unsigned apoint_inday (apoint_llist_node_t *, long);
void apoint_sec2str(apoint_llist_node_t *, int, long, void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
char *, char *); char *);
void apoint_write(apoint_llist_node_t *, FILE *); void apoint_write (apoint_llist_node_t *, FILE *);
apoint_llist_node_t *apoint_scan(FILE *, struct tm, struct tm, char, char *); apoint_llist_node_t *apoint_scan (FILE *, struct tm, struct tm, char, char *);
apoint_llist_node_t *apoint_get(long, int); apoint_llist_node_t *apoint_get (long, int);
void apoint_delete_bynum(long, unsigned, erase_flag_e); void apoint_delete_bynum (long, unsigned, erase_flag_e);
void apoint_scroll_pad_down(int, int); void apoint_scroll_pad_down (int, int);
void apoint_scroll_pad_up(int); void apoint_scroll_pad_up (int);
struct notify_app_s *apoint_check_next(struct notify_app_s *, long); struct notify_app_s *apoint_check_next (struct notify_app_s *, long);
apoint_llist_node_t *apoint_recur_s2apoint_s(recur_apoint_llist_node_t *); apoint_llist_node_t *apoint_recur_s2apoint_s (recur_apoint_llist_node_t *);
void apoint_switch_notify(void); void apoint_switch_notify (void);
void apoint_update_panel(window_t *, int); void apoint_update_panel (window_t *, int);
#endif /* CALCURSE_APOINT_H */ #endif /* CALCURSE_APOINT_H */
+495 -444
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,4 +1,4 @@
/* $calcurse: args.h,v 1.8 2007/07/28 13:11:42 culot Exp $ */ /* $calcurse: args.h,v 1.9 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -27,6 +27,6 @@
#ifndef CALCURSE_ARGS_H #ifndef CALCURSE_ARGS_H
#define CALCURSE_ARGS_H #define CALCURSE_ARGS_H
int parse_args(int, char **, conf_t *); int parse_args (int, char **, conf_t *);
#endif /* CALCURSE_ARGS_H */ #endif /* CALCURSE_ARGS_H */
+427 -407
View File
@@ -1,4 +1,4 @@
/* $calcurse: calcurse.c,v 1.61 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: calcurse.c,v 1.62 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -44,446 +44,466 @@
/* /*
* Calcurse is a text-based personal organizer which helps keeping track * Calcurse is a text-based personal organizer which helps keeping track
* of events and everyday tasks. It contains a calendar, a 'todo' list, * of events and everyday tasks. It contains a calendar, a 'todo' list,
* and puts your appointments in order. The user interface is configurable, * and puts your appointments in order. The user interface is configurable,
* and one can choose between different color schemes and layouts. * and one can choose between different color schemes and layouts.
* All of the commands are documented within an online help system. * All of the commands are documented within an online help system.
*/ */
int int
main(int argc, char **argv) main (int argc, char **argv)
{ {
conf_t conf; conf_t conf;
day_items_nb_t inday; day_items_nb_t inday;
int ch, background, foreground; int ch, background, foreground;
int non_interactive; int non_interactive;
int no_data_file = 1; int no_data_file = 1;
int sav_hilt_app = 0; int sav_hilt_app = 0;
int sav_hilt_tod = 0; int sav_hilt_tod = 0;
struct sigaction sigact; struct sigaction sigact;
bool do_storage = false; bool do_storage = false;
bool do_update = true; bool do_update = true;
bool day_changed = false; bool day_changed = false;
char *no_color_support = char *no_color_support =
_("Sorry, colors are not supported by your terminal\n" _("Sorry, colors are not supported by your terminal\n"
"(Press [ENTER] to continue)"); "(Press [ENTER] to continue)");
char *quit_message = _("Do you really want to quit ?"); char *quit_message = _("Do you really want to quit ?");
char choices[] = "[y/n] "; char choices[] = "[y/n] ";
#if ENABLE_NLS #if ENABLE_NLS
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE); textdomain (PACKAGE);
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
/* Thread-safe data structure init */ /* Thread-safe data structure init */
apoint_llist_init(); apoint_llist_init ();
recur_apoint_llist_init(); recur_apoint_llist_init ();
/* /*
* Begin by parsing and handling command line arguments. * Begin by parsing and handling command line arguments.
* The data path is also initialized here. * The data path is also initialized here.
*/ */
non_interactive = parse_args(argc, argv, &conf); non_interactive = parse_args (argc, argv, &conf);
if (non_interactive) if (non_interactive)
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
/* Begin of interactive mode with ncurses interface. */ /* Begin of interactive mode with ncurses interface. */
sigs_init(&sigact); /* signal handling init */ sigs_init (&sigact); /* signal handling init */
initscr(); /* start the curses mode */ initscr (); /* start the curses mode */
cbreak(); /* control chars generate a signal */ cbreak (); /* control chars generate a signal */
noecho(); /* controls echoing of typed chars */ noecho (); /* controls echoing of typed chars */
curs_set(0); /* make cursor invisible */ curs_set (0); /* make cursor invisible */
calendar_set_current_date(); calendar_set_current_date ();
notify_init_vars(); notify_init_vars ();
wins_get_config(); wins_get_config ();
/* Check if terminal supports color. */ /* Check if terminal supports color. */
if (has_colors()) { if (has_colors ())
colorize = true; {
background = COLOR_BLACK; colorize = true;
foreground = COLOR_WHITE; background = COLOR_BLACK;
start_color(); foreground = COLOR_WHITE;
start_color ();
#ifdef NCURSES_VERSION #ifdef NCURSES_VERSION
if (use_default_colors() != ERR) { if (use_default_colors () != ERR)
background = -1; {
foreground = -1; background = -1;
} foreground = -1;
}
#endif /* NCURSES_VERSION */ #endif /* NCURSES_VERSION */
/* Color assignment */ /* Color assignment */
init_pair(COLR_RED, COLOR_RED, background); init_pair (COLR_RED, COLOR_RED, background);
init_pair(COLR_GREEN, COLOR_GREEN, background); init_pair (COLR_GREEN, COLOR_GREEN, background);
init_pair(COLR_YELLOW, COLOR_YELLOW, background); init_pair (COLR_YELLOW, COLOR_YELLOW, background);
init_pair(COLR_BLUE, COLOR_BLUE, background); init_pair (COLR_BLUE, COLOR_BLUE, background);
init_pair(COLR_MAGENTA, COLOR_MAGENTA, background); init_pair (COLR_MAGENTA, COLOR_MAGENTA, background);
init_pair(COLR_CYAN, COLOR_CYAN, background); init_pair (COLR_CYAN, COLOR_CYAN, background);
init_pair(COLR_DEFAULT, foreground, background); init_pair (COLR_DEFAULT, foreground, background);
init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN); init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
init_pair(COLR_CUSTOM, COLOR_RED, background); init_pair (COLR_CUSTOM, COLOR_RED, background);
} else { }
colorize = false; else
background = COLOR_BLACK; {
} colorize = false;
background = COLOR_BLACK;
}
vars_init(&conf); vars_init (&conf);
wins_init(); wins_init ();
wins_slctd_init(); wins_slctd_init ();
notify_init_bar(); notify_init_bar ();
reset_status_page(); reset_status_page ();
/* /*
* Read the data from files : first the user * Read the data from files : first the user
* configuration (the display is then updated), and then * configuration (the display is then updated), and then
* the todo list, appointments and events. * the todo list, appointments and events.
*/ */
no_data_file = io_check_data_files(); no_data_file = io_check_data_files ();
custom_load_conf(&conf, background); custom_load_conf (&conf, background);
erase_status_bar(); erase_status_bar ();
io_load_todo(); io_load_todo ();
io_load_app(); io_load_app ();
wins_reinit(); wins_reinit ();
if (notify_bar()) { if (notify_bar ())
notify_start_main_thread(); {
notify_check_next_app(); notify_start_main_thread ();
} notify_check_next_app ();
wins_update(); }
io_startup_screen(conf.skip_system_dialogs, no_data_file); wins_update ();
inday = *day_process_storage(0, day_changed, &inday); io_startup_screen (conf.skip_system_dialogs, no_data_file);
wins_slctd_set(CAL); inday = *day_process_storage (0, day_changed, &inday);
wins_update(); wins_slctd_set (CAL);
calendar_start_date_thread(); wins_update ();
calendar_start_date_thread ();
/* User input */ /* User input */
for (;;) { for (;;)
{
do_update = true;
ch = wgetch (win[STA].p);
switch (ch)
{
case ERR:
do_update = false;
break;
do_update = true; case CTRL ('R'):
ch = wgetch(win[STA].p); case KEY_RESIZE:
do_update = false;
wins_reset ();
break;
switch (ch) { case 9: /* The TAB key was hit. */
reset_status_page ();
/* Save previously highlighted event. */
switch (wins_slctd ())
{
case TOD:
sav_hilt_tod = todo_hilt ();
todo_hilt_set (0);
break;
case APP:
sav_hilt_app = apoint_hilt ();
apoint_hilt_set (0);
break;
default:
break;
}
wins_slctd_next ();
case ERR: /* Select the event to highlight. */
do_update = false; switch (wins_slctd ())
break; {
case TOD:
if ((sav_hilt_tod == 0) && (todo_nb () != 0))
todo_hilt_set (1);
else
todo_hilt_set (sav_hilt_tod);
break;
case APP:
if ((sav_hilt_app == 0)
&& ((inday.nb_events + inday.nb_apoints) != 0))
apoint_hilt_set (1);
else
apoint_hilt_set (sav_hilt_app);
break;
default:
break;
}
break;
case CTRL('R'): case 'O':
case KEY_RESIZE: case 'o':
do_update = false; other_status_page (wins_slctd ());
wins_reset(); break;
break;
case 9: /* The TAB key was hit. */ case 'G':
reset_status_page(); case 'g': /* Goto function */
/* Save previously highlighted event. */ erase_status_bar ();
switch (wins_slctd()) { calendar_set_current_date ();
case TOD: calendar_change_day (conf.input_datefmt);
sav_hilt_tod = todo_hilt(); do_storage = true;
todo_hilt_set(0); day_changed = true;
break; break;
case APP:
sav_hilt_app = apoint_hilt();
apoint_hilt_set(0);
break;
default:
break;
}
wins_slctd_next();
/* Select the event to highlight. */ case 'V':
switch (wins_slctd()) { case 'v': /* View function */
case TOD: if ((wins_slctd () == APP) && (apoint_hilt () != 0))
if ((sav_hilt_tod == 0) && (todo_nb() != 0)) day_popup_item ();
todo_hilt_set(1); else if ((wins_slctd () == TOD) && (todo_hilt () != 0))
else item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :"));
todo_hilt_set(sav_hilt_tod); break;
break;
case APP:
if ((sav_hilt_app == 0) &&
((inday.nb_events + inday.nb_apoints) != 0))
apoint_hilt_set(1);
else
apoint_hilt_set(sav_hilt_app);
break;
default:
break;
}
break;
case 'O':
case 'o':
other_status_page(wins_slctd());
break;
case 'G':
case 'g': /* Goto function */
erase_status_bar();
calendar_set_current_date();
calendar_change_day(conf.input_datefmt);
do_storage = true;
day_changed = true;
break;
case 'V':
case 'v': /* View function */
if ((wins_slctd() == APP) && (apoint_hilt() != 0))
day_popup_item();
else if ((wins_slctd() == TOD) && (todo_hilt() != 0))
item_in_popup(NULL, NULL, todo_saved_mesg(),
_("To do :"));
break;
case 'C':
case 'c': /* Configuration menu */
erase_status_bar ();
config_bar ();
while ((ch = wgetch (win[STA].p)) != 'q')
{
switch (ch)
{
case 'C': case 'C':
case 'c': /* Configuration menu */ case 'c':
erase_status_bar(); if (has_colors ())
config_bar(); custom_color_config ();
while ((ch = wgetch(win[STA].p)) != 'q') { else
switch (ch) { {
case 'C': colorize = false;
case 'c': erase_status_bar ();
if (has_colors()) mvwprintw (win[STA].p, 0, 0, _(no_color_support));
custom_color_config(); wgetch (win[STA].p);
else { }
colorize = false; break;
erase_status_bar(); case 'L':
mvwprintw(win[STA].p, 0, 0, case 'l':
_(no_color_support)); layout_config ();
wgetch(win[STA].p); break;
} case 'G':
break; case 'g':
case 'L': custom_general_config (&conf);
case 'l': break;
layout_config();
break;
case 'G':
case 'g':
custom_general_config(&conf);
break;
case 'N':
case 'n':
notify_config_bar();
break;
}
wins_reset();
wins_update();
do_storage = true;
erase_status_bar();
config_bar();
}
wins_update();
break;
case CTRL('A'): /* Add an app, whatever panel selected */
apoint_add();
do_storage = true;
break;
case CTRL('T'): /* Add a todo, whatever panel selected */
todo_new_item();
if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase();
break;
case 'A':
case 'a': /* Add an item */
switch (wins_slctd()) {
case APP:
apoint_add();
do_storage = true;
break;
case TOD:
todo_new_item();
if (todo_hilt() == 0 && todo_nb() == 1)
todo_hilt_increase();
break;
default:
break;
}
break;
case 'E':
case 'e': /* Edit an existing item */
if (wins_slctd() == APP && apoint_hilt() != 0)
day_edit_item(&conf);
else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_edit_item();
do_storage = true;
break;
case 'D':
case 'd': /* Delete an item */
if (wins_slctd() == APP && apoint_hilt() != 0)
apoint_delete(&conf, &inday.nb_events,
&inday.nb_apoints);
else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_delete(&conf);
do_storage = true;
break;
case 'R':
case 'r':
if (wins_slctd() == APP && apoint_hilt() != 0)
recur_repeat_item(&conf);
do_storage = true;
break;
case '!':
if (wins_slctd() == APP && apoint_hilt() != 0)
apoint_switch_notify();
do_storage = true;
break;
case '+':
case '-':
if (wins_slctd() == TOD && todo_hilt() != 0) {
todo_chg_priority(ch);
if (todo_hilt_pos() < 0)
todo_set_first(todo_hilt());
else if (todo_hilt_pos() >= win[TOD].h - 4)
todo_set_first(todo_hilt() -
win[TOD].h + 5);
}
break;
case 'N': case 'N':
case 'n': case 'n':
/* Attach a note to an item, create it if necessary */ notify_config_bar ();
if (wins_slctd() == APP && apoint_hilt() != 0) break;
day_edit_note(conf.editor);
else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_edit_note(conf.editor);
do_storage = true;
break;
case '>':
/* View a note previously attached to an item */
if (wins_slctd() == APP && apoint_hilt() != 0)
day_view_note(conf.pager);
else if (wins_slctd() == TOD && todo_hilt() != 0)
todo_view_note(conf.pager);
break;
case '?': /* Online help system */
status_bar();
help_screen();
break;
case 'S':
case 's': /* Save function */
io_save_cal(&conf);
break;
case 'X':
case 'x': /* Export function */
io_export_data(IO_EXPORT_INTERACTIVE, &conf);
break;
case (261): /* right arrow */
case ('L'):
case ('l'):
case CTRL('L'):
if (wins_slctd() == CAL || ch == CTRL('L')) {
do_storage = true;
day_changed = true;
calendar_move(RIGHT);
}
break;
case (260): /* left arrow */
case ('H'):
case ('h'):
case CTRL('H'):
if (wins_slctd() == CAL || ch == CTRL('H')) {
do_storage = true;
day_changed = true;
calendar_move(LEFT);
}
break;
case (259): /* up arrow */
case ('K'):
case ('k'):
case CTRL('K'):
if (wins_slctd() == CAL || ch == CTRL('K')) {
do_storage = true;
day_changed = true;
calendar_move(UP);
} else {
if ((wins_slctd() == APP) &&
(apoint_hilt() > 1)) {
apoint_hilt_decrease();
apoint_scroll_pad_up(inday.nb_events);
} else if ((wins_slctd() == TOD) &&
(todo_hilt() > 1)) {
todo_hilt_decrease();
if (todo_hilt_pos() < 0)
todo_first_decrease();
}
}
break;
case (258): /* down arrow */
case ('J'):
case ('j'):
case CTRL('J'):
if (wins_slctd() == CAL || ch == CTRL('J')) {
do_storage = true;
day_changed = true;
calendar_move(DOWN);
} else {
if ((wins_slctd() == APP) &&
(apoint_hilt() < inday.nb_events +
inday.nb_apoints)) {
apoint_hilt_increase();
apoint_scroll_pad_down(inday.nb_events,
win[APP].h);
}
if ((wins_slctd() == TOD) &&
(todo_hilt() < todo_nb())) {
todo_hilt_increase();
if (todo_hilt_pos() == win[TOD].h - 4)
todo_first_increase();
}
}
break;
case ('Q'): /* Quit calcurse :( */
case ('q'):
if (conf.auto_save)
io_save_cal(&conf);
if (conf.confirm_quit) {
status_mesg(_(quit_message), choices);
ch = wgetch(win[STA].p);
if ( ch == 'y' )
exit_calcurse(EXIT_SUCCESS);
else {
erase_status_bar();
break;
}
} else
exit_calcurse(EXIT_SUCCESS);
break;
default:
do_update = false;
break;
} }
wins_reset ();
wins_update ();
do_storage = true;
erase_status_bar ();
config_bar ();
}
wins_update ();
break;
if (do_storage) { case CTRL ('A'): /* Add an app, whatever panel selected */
inday = *day_process_storage(calendar_get_slctd_day(), apoint_add ();
day_changed, &inday); do_storage = true;
do_storage = !do_storage; break;
if (day_changed) {
sav_hilt_app = 0; case CTRL ('T'): /* Add a todo, whatever panel selected */
day_changed = !day_changed; todo_new_item ();
if ((wins_slctd() == APP) && if (todo_hilt () == 0 && todo_nb () == 1)
(inday.nb_events + inday.nb_apoints != 0)) todo_hilt_increase ();
apoint_hilt_set(1); break;
}
case 'A':
case 'a': /* Add an item */
switch (wins_slctd ())
{
case APP:
apoint_add ();
do_storage = true;
break;
case TOD:
todo_new_item ();
if (todo_hilt () == 0 && todo_nb () == 1)
todo_hilt_increase ();
break;
default:
break;
}
break;
case 'E':
case 'e': /* Edit an existing item */
if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_item (&conf);
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_item ();
do_storage = true;
break;
case 'D':
case 'd': /* Delete an item */
if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints);
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_delete (&conf);
do_storage = true;
break;
case 'R':
case 'r':
if (wins_slctd () == APP && apoint_hilt () != 0)
recur_repeat_item (&conf);
do_storage = true;
break;
case '!':
if (wins_slctd () == APP && apoint_hilt () != 0)
apoint_switch_notify ();
do_storage = true;
break;
case '+':
case '-':
if (wins_slctd () == TOD && todo_hilt () != 0)
{
todo_chg_priority (ch);
if (todo_hilt_pos () < 0)
todo_set_first (todo_hilt ());
else if (todo_hilt_pos () >= win[TOD].h - 4)
todo_set_first (todo_hilt () - win[TOD].h + 5);
}
break;
case 'N':
case 'n':
/* Attach a note to an item, create it if necessary */
if (wins_slctd () == APP && apoint_hilt () != 0)
day_edit_note (conf.editor);
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_edit_note (conf.editor);
do_storage = true;
break;
case '>':
/* View a note previously attached to an item */
if (wins_slctd () == APP && apoint_hilt () != 0)
day_view_note (conf.pager);
else if (wins_slctd () == TOD && todo_hilt () != 0)
todo_view_note (conf.pager);
break;
case '?': /* Online help system */
status_bar ();
help_screen ();
break;
case 'S':
case 's': /* Save function */
io_save_cal (&conf);
break;
case 'X':
case 'x': /* Export function */
io_export_data (IO_EXPORT_INTERACTIVE, &conf);
break;
case (261): /* right arrow */
case ('L'):
case ('l'):
case CTRL ('L'):
if (wins_slctd () == CAL || ch == CTRL ('L'))
{
do_storage = true;
day_changed = true;
calendar_move (RIGHT);
}
break;
case (260): /* left arrow */
case ('H'):
case ('h'):
case CTRL ('H'):
if (wins_slctd () == CAL || ch == CTRL ('H'))
{
do_storage = true;
day_changed = true;
calendar_move (LEFT);
}
break;
case (259): /* up arrow */
case ('K'):
case ('k'):
case CTRL ('K'):
if (wins_slctd () == CAL || ch == CTRL ('K'))
{
do_storage = true;
day_changed = true;
calendar_move (UP);
}
else
{
if ((wins_slctd () == APP) && (apoint_hilt () > 1))
{
apoint_hilt_decrease ();
apoint_scroll_pad_up (inday.nb_events);
} }
if (do_update) else if ((wins_slctd () == TOD) && (todo_hilt () > 1))
wins_update(); {
todo_hilt_decrease ();
if (todo_hilt_pos () < 0)
todo_first_decrease ();
}
}
break;
case (258): /* down arrow */
case ('J'):
case ('j'):
case CTRL ('J'):
if (wins_slctd () == CAL || ch == CTRL ('J'))
{
do_storage = true;
day_changed = true;
calendar_move (DOWN);
}
else
{
if ((wins_slctd () == APP) &&
(apoint_hilt () < inday.nb_events + inday.nb_apoints))
{
apoint_hilt_increase ();
apoint_scroll_pad_down (inday.nb_events, win[APP].h);
}
if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ()))
{
todo_hilt_increase ();
if (todo_hilt_pos () == win[TOD].h - 4)
todo_first_increase ();
}
}
break;
case ('Q'): /* Quit calcurse :( */
case ('q'):
if (conf.auto_save)
io_save_cal (&conf);
if (conf.confirm_quit)
{
status_mesg (_(quit_message), choices);
ch = wgetch (win[STA].p);
if (ch == 'y')
exit_calcurse (EXIT_SUCCESS);
else
{
erase_status_bar ();
break;
}
}
else
exit_calcurse (EXIT_SUCCESS);
break;
default:
do_update = false;
break;
} }
if (do_storage)
{
inday = *day_process_storage (calendar_get_slctd_day (),
day_changed, &inday);
do_storage = !do_storage;
if (day_changed)
{
sav_hilt_app = 0;
day_changed = !day_changed;
if ((wins_slctd () == APP) &&
(inday.nb_events + inday.nb_apoints != 0))
apoint_hilt_set (1);
}
}
if (do_update)
wins_update ();
}
} }
+349 -347
View File
@@ -1,4 +1,4 @@
/* $calcurse: calendar.c,v 1.14 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: calendar.c,v 1.15 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -55,273 +55,276 @@
#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
static date_t today, slctd_day; static date_t today, slctd_day;
static bool week_begins_on_monday; static bool week_begins_on_monday;
static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t date_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t calendar_t_date; static pthread_t calendar_t_date;
/* Thread needed to update current date in calendar. */ /* Thread needed to update current date in calendar. */
static void * static void *
calendar_date_thread(void *arg) calendar_date_thread (void *arg)
{ {
time_t now, tomorrow; time_t now, tomorrow;
for (;;) { for (;;)
tomorrow = (time_t)(get_today() + DAYINSEC); {
tomorrow = (time_t) (get_today () + DAYINSEC);
while ((now = time(NULL)) < tomorrow) { while ((now = time (NULL)) < tomorrow)
sleep(tomorrow - now); {
} sleep (tomorrow - now);
calendar_set_current_date();
calendar_update_panel(win[CAL].p);
} }
pthread_exit((void*) 0); calendar_set_current_date ();
calendar_update_panel (win[CAL].p);
}
pthread_exit ((void *) 0);
} }
/* Launch the calendar date thread. */ /* Launch the calendar date thread. */
void void
calendar_start_date_thread(void) calendar_start_date_thread (void)
{ {
pthread_create(&calendar_t_date, NULL, calendar_date_thread, NULL); pthread_create (&calendar_t_date, NULL, calendar_date_thread, NULL);
return; return;
} }
/* Stop the calendar date thread. */ /* Stop the calendar date thread. */
void void
calendar_stop_date_thread(void) calendar_stop_date_thread (void)
{ {
pthread_cancel(calendar_t_date); pthread_cancel (calendar_t_date);
return; return;
} }
/* Set static variable today to current date */ /* Set static variable today to current date */
void void
calendar_set_current_date(void) calendar_set_current_date (void)
{ {
time_t timer; time_t timer;
struct tm *tm; struct tm *tm;
timer = time(NULL); timer = time (NULL);
tm = localtime(&timer); tm = localtime (&timer);
pthread_mutex_lock(&date_thread_mutex); pthread_mutex_lock (&date_thread_mutex);
today.dd = tm->tm_mday; today.dd = tm->tm_mday;
today.mm = tm->tm_mon + 1; today.mm = tm->tm_mon + 1;
today.yyyy = tm->tm_year + 1900; today.yyyy = tm->tm_year + 1900;
pthread_mutex_unlock(&date_thread_mutex); pthread_mutex_unlock (&date_thread_mutex);
} }
/* Needed to display sunday or monday as the first day of week in calendar. */ /* Needed to display sunday or monday as the first day of week in calendar. */
void void
calendar_set_first_day_of_week(wday_e first_day) calendar_set_first_day_of_week (wday_e first_day)
{ {
switch (first_day) { switch (first_day)
case SUNDAY: {
week_begins_on_monday = false; case SUNDAY:
break; week_begins_on_monday = false;
case MONDAY: break;
week_begins_on_monday = true; case MONDAY:
break; week_begins_on_monday = true;
default: break;
fputs(_("ERROR in calendar_set_first_day_of_week\n"), stderr); default:
week_begins_on_monday = false; fputs (_("ERROR in calendar_set_first_day_of_week\n"), stderr);
/* NOTREACHED */ week_begins_on_monday = false;
} /* NOTREACHED */
}
} }
/* Swap first day of week in calendar. */ /* Swap first day of week in calendar. */
void void
calendar_change_first_day_of_week(void) calendar_change_first_day_of_week (void)
{ {
week_begins_on_monday = !week_begins_on_monday; week_begins_on_monday = !week_begins_on_monday;
} }
/* Return true if week begins on monday, false otherwise. */ /* Return true if week begins on monday, false otherwise. */
bool bool
calendar_week_begins_on_monday(void) calendar_week_begins_on_monday (void)
{ {
return (week_begins_on_monday); return (week_begins_on_monday);
} }
/* Fill in the given variable with the current date. */ /* Fill in the given variable with the current date. */
void void
calendar_store_current_date(date_t *date) calendar_store_current_date (date_t *date)
{ {
pthread_mutex_lock(&date_thread_mutex); pthread_mutex_lock (&date_thread_mutex);
*date = today; *date = today;
pthread_mutex_unlock(&date_thread_mutex); pthread_mutex_unlock (&date_thread_mutex);
} }
/* This is to start at the current date in calendar. */ /* This is to start at the current date in calendar. */
void void
calendar_init_slctd_day(void) calendar_init_slctd_day (void)
{ {
calendar_store_current_date(&slctd_day); calendar_store_current_date (&slctd_day);
} }
/* Return the selected day in calendar */ /* Return the selected day in calendar */
date_t * date_t *
calendar_get_slctd_day(void) calendar_get_slctd_day (void)
{ {
return (&slctd_day); return (&slctd_day);
} }
/* Returned value represents the selected day in calendar (in seconds) */ /* Returned value represents the selected day in calendar (in seconds) */
long long
calendar_get_slctd_day_sec(void) calendar_get_slctd_day_sec (void)
{ {
return (date2sec(slctd_day, 0, 0)); return (date2sec (slctd_day, 0, 0));
} }
static int static int
isBissextile(unsigned year) isBissextile (unsigned year)
{ {
return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
} }
static unsigned static unsigned
months_to_days(unsigned month) months_to_days (unsigned month)
{ {
return ((month * 3057 - 3007) / 100); return ((month * 3057 - 3007) / 100);
} }
static long static long
years_to_days(unsigned year) years_to_days (unsigned year)
{ {
return (year * 365L + year / 4 - year / 100 + year / 400); return (year * 365L + year / 4 - year / 100 + year / 400);
} }
static long static long
ymd_to_scalar(unsigned year, unsigned month, unsigned day) ymd_to_scalar (unsigned year, unsigned month, unsigned day)
{ {
long scalar; long scalar;
scalar = day + months_to_days(month); scalar = day + months_to_days (month);
if (month > 2) if (month > 2)
scalar -= isBissextile(year) ? 1 : 2; scalar -= isBissextile (year) ? 1 : 2;
year--; year--;
scalar += years_to_days(year); scalar += years_to_days (year);
return (scalar); return (scalar);
} }
/* Function used to display the calendar panel. */ /* Function used to display the calendar panel. */
void void
calendar_update_panel(WINDOW *cwin) calendar_update_panel (WINDOW *cwin)
{ {
date_t current_day, check_day; date_t current_day, check_day;
int c_day, c_day_1, day_1_sav, numdays, j; int c_day, c_day_1, day_1_sav, numdays, j;
unsigned yr, mo; unsigned yr, mo;
int ofs_x, ofs_y; int ofs_x, ofs_y;
int item_this_day = 0; int item_this_day = 0;
int title_lines = 3; int title_lines = 3;
int sunday_first = 0; int sunday_first = 0;
/* inits */ /* inits */
calendar_store_current_date(&current_day); calendar_store_current_date (&current_day);
erase_window_part(cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2); erase_window_part (cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
mo = slctd_day.mm; mo = slctd_day.mm;
yr = slctd_day.yyyy; yr = slctd_day.yyyy;
if (!calendar_week_begins_on_monday()) if (!calendar_week_begins_on_monday ())
sunday_first = 1; sunday_first = 1;
/* offset for centering calendar in window */ /* offset for centering calendar in window */
ofs_y = 2 + (CALHEIGHT - 9) / 2; ofs_y = 2 + (CALHEIGHT - 9) / 2;
ofs_x = (CALWIDTH - 27) / 2; ofs_x = (CALWIDTH - 27) / 2;
/* checking the number of days in february */ /* checking the number of days in february */
numdays = days[mo - 1]; numdays = days[mo - 1];
if (2 == mo && isBissextile(yr)) if (2 == mo && isBissextile (yr))
++numdays; ++numdays;
/* /*
* the first calendar day will be monday or sunday, depending on * the first calendar day will be monday or sunday, depending on
* 'week_begins_on_monday' value * 'week_begins_on_monday' value
*/ */
c_day_1 = c_day_1 = (int) ((ymd_to_scalar (yr, mo, 1 + sunday_first) - (long) 1) % 7L);
(int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
/* Write the current month and year on top of the calendar */ /* Write the current month and year on top of the calendar */
custom_apply_attr(cwin, ATTR_HIGH); custom_apply_attr (cwin, ATTR_HIGH);
mvwprintw(cwin, ofs_y, mvwprintw (cwin, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
(CALWIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2, "%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy); custom_remove_attr (cwin, ATTR_HIGH);
custom_remove_attr(cwin, ATTR_HIGH); ++ofs_y;
++ofs_y;
/* print the days, with regards to the first day of the week */ /* print the days, with regards to the first day of the week */
custom_apply_attr(cwin, ATTR_HIGH); custom_apply_attr (cwin, ATTR_HIGH);
for (j = 0; j < 7; j++) { for (j = 0; j < 7; j++)
mvwprintw(cwin, ofs_y, ofs_x + 4 * j, "%s", {
_(daynames[1 + j - sunday_first])); mvwprintw (cwin, ofs_y, ofs_x + 4 * j, "%s",
_(daynames[1 + j - sunday_first]));
}
custom_remove_attr (cwin, ATTR_HIGH);
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7)
{
check_day.dd = c_day;
check_day.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */
item_this_day = day_check_if_item (check_day);
/* Go to next line, the week is over. */
if (!c_day_1 && 1 != c_day)
{
++ofs_y;
ofs_x = 2 - day_1_sav - 4 * c_day - 1;
} }
custom_remove_attr(cwin, ATTR_HIGH);
day_1_sav = (c_day_1 + 1) * 3 + c_day_1 - 7;
for (c_day = 1; c_day <= numdays; ++c_day, ++c_day_1, c_day_1 %= 7) {
check_day.dd = c_day;
check_day.mm = slctd_day.mm;
check_day.yyyy = slctd_day.yyyy;
/* check if the day contains an event or an appointment */
item_this_day =
day_check_if_item(check_day);
/* Go to next line, the week is over. */
if (!c_day_1 && 1 != c_day) {
++ofs_y;
ofs_x = 2 - day_1_sav - 4 * c_day - 1;
}
/* This is today, so print it in yellow. */
if (c_day == current_day.dd && current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy &&
current_day.dd != slctd_day.dd) {
custom_apply_attr(cwin, ATTR_LOWEST);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin, ATTR_LOWEST);
} else if (c_day == slctd_day.dd &&
( (current_day.dd != slctd_day.dd) ||
(current_day.mm != slctd_day.mm)
|| (current_day.yyyy != slctd_day.yyyy))) {
/* This is the selected day, print it in red. */
custom_apply_attr(cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin, ATTR_MIDDLE);
} else if (c_day == slctd_day.dd &&
current_day.dd == slctd_day.dd &&
current_day.mm == slctd_day.mm &&
current_day.yyyy == slctd_day.yyyy) {
/* today is the selected day */
custom_apply_attr(cwin, ATTR_MIDDLE);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin, ATTR_MIDDLE);
} else if (item_this_day) {
custom_apply_attr(cwin, ATTR_LOW);
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr(cwin, ATTR_LOW);
} else
/* otherwise, print normal days in black */
mvwprintw(cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
/* This is today, so print it in yellow. */
if (c_day == current_day.dd && current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy
&& current_day.dd != slctd_day.dd)
{
custom_apply_attr (cwin, ATTR_LOWEST);
mvwprintw (cwin, ofs_y + 1,
ofs_x + day_1_sav + 4 * c_day + 1, "%2d", c_day);
custom_remove_attr (cwin, ATTR_LOWEST);
} }
wnoutrefresh(cwin); else if (c_day == slctd_day.dd &&
((current_day.dd != slctd_day.dd)
|| (current_day.mm != slctd_day.mm)
|| (current_day.yyyy != slctd_day.yyyy)))
{
/* This is the selected day, print it in red. */
custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_MIDDLE);
}
else if (c_day == slctd_day.dd && current_day.dd == slctd_day.dd
&& current_day.mm == slctd_day.mm
&& current_day.yyyy == slctd_day.yyyy)
{
/* today is the selected day */
custom_apply_attr (cwin, ATTR_MIDDLE);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_MIDDLE);
}
else if (item_this_day)
{
custom_apply_attr (cwin, ATTR_LOW);
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
custom_remove_attr (cwin, ATTR_LOW);
}
else
/* otherwise, print normal days in black */
mvwprintw (cwin, ofs_y + 1, ofs_x + day_1_sav + 4 * c_day + 1, "%2d",
c_day);
}
wnoutrefresh (cwin);
} }
/* /*
@@ -332,60 +335,58 @@ calendar_update_panel(WINDOW *cwin)
* with the newly selected date. * with the newly selected date.
*/ */
void void
calendar_change_day(int datefmt) calendar_change_day (int datefmt)
{ {
#define LDAY 11 #define LDAY 11
char selected_day[LDAY] = ""; char selected_day[LDAY] = "";
char outstr[BUFSIZ]; char outstr[BUFSIZ];
date_t today; date_t today;
int dday, dmonth, dyear; int dday, dmonth, dyear;
int wrong_day = 1; int wrong_day = 1;
char *mesg_line1 = char *mesg_line1 =
_("The day you entered is not valid (should be between 01/01/1902 and 12/31/2037)"); _("The day you entered is not valid "
char *mesg_line2 = _("Press [ENTER] to continue"); "(should be between 01/01/1902 and 12/31/2037)");
char *request_date = char *mesg_line2 = _("Press [ENTER] to continue");
"Enter the day to go to [ENTER for today] : %s"; char *request_date = "Enter the day to go to [ENTER for today] : %s";
while (wrong_day) {
snprintf(outstr, BUFSIZ, request_date,
DATEFMT_DESC(datefmt));
status_mesg(_(outstr), "");
if (getstring(win[STA].p, selected_day, LDAY, 0, 1) ==
GETSTRING_ESC)
return;
else {
if (strlen(selected_day) == 0) {
calendar_store_current_date(&today);
/* go to today */
wrong_day = 0;
slctd_day.dd = today.dd;
slctd_day.mm = today.mm;
slctd_day.yyyy = today.yyyy;
} else if (strlen(selected_day) != LDAY - 1) {
wrong_day = 1;
} else if (parse_date(selected_day, datefmt,
&dyear, &dmonth, &dday)) {
wrong_day = 0;
/* go to chosen day */
slctd_day.dd = dday;
slctd_day.mm = dmonth;
slctd_day.yyyy = dyear;
}
if (wrong_day) {
status_mesg(mesg_line1, mesg_line2);
wgetch(win[STA].p);
}
}
}
while (wrong_day)
{
snprintf (outstr, BUFSIZ, request_date, DATEFMT_DESC (datefmt));
status_mesg (_(outstr), "");
if (getstring (win[STA].p, selected_day, LDAY, 0, 1) == GETSTRING_ESC)
return; return;
else
{
if (strlen (selected_day) == 0)
{
calendar_store_current_date (&today);
/* go to today */
wrong_day = 0;
slctd_day.dd = today.dd;
slctd_day.mm = today.mm;
slctd_day.yyyy = today.yyyy;
}
else if (strlen (selected_day) != LDAY - 1)
{
wrong_day = 1;
}
else if (parse_date (selected_day, datefmt, &dyear, &dmonth, &dday))
{
wrong_day = 0;
/* go to chosen day */
slctd_day.dd = dday;
slctd_day.mm = dmonth;
slctd_day.yyyy = dyear;
}
if (wrong_day)
{
status_mesg (mesg_line1, mesg_line2);
wgetch (win[STA].p);
}
}
}
return;
} }
/* /*
@@ -393,68 +394,70 @@ calendar_change_day(int datefmt)
* Returns 0 on success, 1 otherwise. * Returns 0 on success, 1 otherwise.
*/ */
int int
date_change(struct tm *date, int delta_month, int delta_day) date_change (struct tm *date, int delta_month, int delta_day)
{ {
struct tm t; struct tm t;
t = *date; t = *date;
t.tm_mon += delta_month; t.tm_mon += delta_month;
t.tm_mday += delta_day; t.tm_mday += delta_day;
if (mktime(&t) == -1) if (mktime (&t) == -1)
return (1); return (1);
else { else
*date = t; {
return (0); *date = t;
} return (0);
}
} }
void void
calendar_move(move_t move) calendar_move (move_t move)
{ {
int ret; int ret;
struct tm t; struct tm t;
memset(&t, 0, sizeof(struct tm)); memset (&t, 0, sizeof (struct tm));
t.tm_mday = slctd_day.dd; t.tm_mday = slctd_day.dd;
t.tm_mon = slctd_day.mm - 1; t.tm_mon = slctd_day.mm - 1;
t.tm_year = slctd_day.yyyy - 1900; t.tm_year = slctd_day.yyyy - 1900;
switch (move) { switch (move)
case UP: {
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1) && case UP:
(slctd_day.yyyy == 1902)) if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
return; && (slctd_day.yyyy == 1902))
ret = date_change(&t, 0, -WEEKINDAYS); return;
break; ret = date_change (&t, 0, -WEEKINDAYS);
case DOWN: break;
if ((slctd_day.dd > days[slctd_day.mm - 1] - 7) case DOWN:
&& (slctd_day.mm == 12) && (slctd_day.yyyy == 2037)) if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
return; && (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
ret = date_change(&t, 0, WEEKINDAYS); return;
break; ret = date_change (&t, 0, WEEKINDAYS);
case LEFT: break;
if ((slctd_day.dd == 1) && (slctd_day.mm == 1) && case LEFT:
(slctd_day.yyyy == 1902)) if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
return; && (slctd_day.yyyy == 1902))
ret = date_change(&t, 0, -1); return;
break; ret = date_change (&t, 0, -1);
case RIGHT: break;
if ((slctd_day.dd == 31) && (slctd_day.mm == 12) && case RIGHT:
(slctd_day.yyyy == 2037)) if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
return; && (slctd_day.yyyy == 2037))
ret = date_change(&t, 0, 1); return;
break; ret = date_change (&t, 0, 1);
default: break;
ret = 1; default:
/* NOTREACHED */ ret = 1;
} /* NOTREACHED */
}
if (ret == 0) { if (ret == 0)
slctd_day.dd = t.tm_mday; {
slctd_day.mm = t.tm_mon + 1; slctd_day.dd = t.tm_mday;
slctd_day.yyyy = t.tm_year + 1900; slctd_day.mm = t.tm_mon + 1;
} slctd_day.yyyy = t.tm_year + 1900;
}
} }
/* /*
@@ -499,9 +502,9 @@ calendar_move(move_t move)
* convert degrees to radians * convert degrees to radians
*/ */
static double static double
dtor(double deg) dtor (double deg)
{ {
return(deg * M_PI / 180); return (deg * M_PI / 180);
} }
/* /*
@@ -509,15 +512,15 @@ dtor(double deg)
* adjust value so 0 <= deg <= 360 * adjust value so 0 <= deg <= 360
*/ */
static void static void
adj360(double *deg) adj360 (double *deg)
{ {
for (;;) for (;;)
if (*deg < 0.0) if (*deg < 0.0)
*deg += 360.0; *deg += 360.0;
else if (*deg > 360.0) else if (*deg > 360.0)
*deg -= 360.0; *deg -= 360.0;
else else
break; break;
} }
/* /*
@@ -525,35 +528,35 @@ adj360(double *deg)
* return phase of the moon * return phase of the moon
*/ */
static double static double
potm(double days) potm (double days)
{ {
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime; double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
double A4, lprime, V, ldprime, D, Nm; double A4, lprime, V, ldprime, D, Nm;
N = 360.0 * days / 365.242191; /* sec 46 #3 */ N = 360.0 * days / 365.242191; /* sec 46 #3 */
adj360(&N); adj360 (&N);
Msol = N + EPSILONg - RHOg; /* sec 46 #4 */ Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
adj360(&Msol); adj360 (&Msol);
Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */ Ec = 360 / M_PI * ECCEN * sin (dtor (Msol)); /* sec 46 #5 */
LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */ LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
adj360(&LambdaSol); adj360 (&LambdaSol);
l = 13.1763966 * days + lzero; /* sec 65 #4 */ l = 13.1763966 * days + lzero; /* sec 65 #4 */
adj360(&l); adj360 (&l);
Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */ Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
adj360(&Mm); adj360 (&Mm);
Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */ Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
adj360(&Nm); adj360 (&Nm);
Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 65 #7 */ Ev = 1.2739 * sin (dtor (2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */ Ac = 0.1858 * sin (dtor (Msol)); /* sec 65 #8 */
A3 = 0.37 * sin(dtor(Msol)); A3 = 0.37 * sin (dtor (Msol));
Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */ Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */ Ec = 6.2886 * sin (dtor (Mmprime)); /* sec 65 #10 */
A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */ A4 = 0.214 * sin (dtor (2 * Mmprime)); /* sec 65 #11 */
lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */ lprime = l + Ev + Ec - Ac + A4; /* sec 65 #12 */
V = 0.6583 * sin(dtor(2 * (lprime - LambdaSol))); /* sec 65 #13 */ V = 0.6583 * sin (dtor (2 * (lprime - LambdaSol))); /* sec 65 #13 */
ldprime = lprime + V; /* sec 65 #14 */ ldprime = lprime + V; /* sec 65 #14 */
D = ldprime - LambdaSol; /* sec 67 #2 */ D = ldprime - LambdaSol; /* sec 67 #2 */
return(50.0 * (1 - cos(dtor(D)))); /* sec 67 #3 */ return (50.0 * (1 - cos (dtor (D)))); /* sec 67 #3 */
} }
/* /*
@@ -568,24 +571,24 @@ potm(double days)
* *
*/ */
static double static double
pom(time_t tmpt) pom (time_t tmpt)
{ {
struct tm *GMT; struct tm *GMT;
double days; double days;
int cnt; int cnt;
pom_e pom; pom_e pom;
pom = NO_POM; pom = NO_POM;
GMT = gmtime(&tmpt); GMT = gmtime (&tmpt);
days = (GMT->tm_yday + 1) + ((GMT->tm_hour + days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
(GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0); (GMT->tm_sec / 3600.0)) / 24.0);
for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt) for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
days += isleap(cnt + TM_YEAR_BASE) ? 366 : 365; days += isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
/* Selected time could be before EPOCH */ /* Selected time could be before EPOCH */
for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt) for (cnt = GMT->tm_year; cnt < EPOCH; ++cnt)
days -= isleap(cnt + TM_YEAR_BASE) ? 366 : 365; days -= isleap (cnt + TM_YEAR_BASE) ? 366 : 365;
return (potm(days)); return (potm (days));
} }
/* /*
@@ -594,25 +597,24 @@ pom(time_t tmpt)
* the phase of the moon for previous day. * the phase of the moon for previous day.
*/ */
char * char *
calendar_get_pom(time_t date) calendar_get_pom (time_t date)
{ {
char *pom_pict[MOON_PHASES] = {" ", "|) ", "(|)", "(| ", " | "}; char *pom_pict[MOON_PHASES] = { " ", "|) ", "(|)", "(| ", " | " };
pom_e phase = NO_POM; pom_e phase = NO_POM;
double pom_today, relative_pom, pom_yesterday, pom_tomorrow; double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
const double half = 50.0; const double half = 50.0;
pom_yesterday = pom(date); pom_yesterday = pom (date);
pom_today = pom(date + DAYINSEC); pom_today = pom (date + DAYINSEC);
relative_pom = abs(pom_today - half); relative_pom = abs (pom_today - half);
pom_tomorrow = pom(date + 2 * DAYINSEC); pom_tomorrow = pom (date + 2 * DAYINSEC);
if (pom_today > pom_yesterday && pom_today > pom_tomorrow) if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
phase = FULL_MOON; phase = FULL_MOON;
else if (pom_today < pom_yesterday && pom_today < pom_tomorrow) else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
phase = NEW_MOON; phase = NEW_MOON;
else if (relative_pom < abs(pom_yesterday - half) && else if (relative_pom < abs (pom_yesterday - half)
relative_pom < abs(pom_tomorrow - half)) && relative_pom < abs (pom_tomorrow - half))
phase = (pom_tomorrow > pom_today) ? phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
FIRST_QUARTER : LAST_QUARTER;
return (pom_pict[phase]); return (pom_pict[phase]);
} }
+53 -45
View File
@@ -1,4 +1,4 @@
/* $calcurse: calendar.h,v 1.9 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: calendar.h,v 1.10 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -34,53 +34,61 @@
#define CALHEIGHT 12 #define CALHEIGHT 12
#define CALWIDTH 30 #define CALWIDTH 30
typedef enum { /* days of week */ typedef enum
SUNDAY, { /* days of week */
MONDAY, SUNDAY,
TUESDAY, MONDAY,
WEDNESDAY, TUESDAY,
THURSDAY, WEDNESDAY,
FRIDAY, THURSDAY,
SATURDAY, FRIDAY,
WDAYS SATURDAY,
} wday_e; WDAYS
}
wday_e;
typedef struct { typedef struct
unsigned dd; {
unsigned mm; unsigned dd;
unsigned yyyy; unsigned mm;
} date_t; unsigned yyyy;
}
date_t;
typedef enum { typedef enum
NO_POM, {
FIRST_QUARTER, NO_POM,
FULL_MOON, FIRST_QUARTER,
LAST_QUARTER, FULL_MOON,
NEW_MOON, LAST_QUARTER,
MOON_PHASES NEW_MOON,
} pom_e; MOON_PHASES
}
pom_e;
typedef enum { typedef enum
UP, {
DOWN, UP,
LEFT, DOWN,
RIGHT, LEFT,
MOVES RIGHT,
} move_t; MOVES
}
move_t;
void calendar_start_date_thread(void); void calendar_start_date_thread (void);
void calendar_stop_date_thread(void); void calendar_stop_date_thread (void);
void calendar_set_current_date(void); void calendar_set_current_date (void);
void calendar_set_first_day_of_week(wday_e); void calendar_set_first_day_of_week (wday_e);
void calendar_change_first_day_of_week(void); void calendar_change_first_day_of_week (void);
bool calendar_week_begins_on_monday(void); bool calendar_week_begins_on_monday (void);
void calendar_store_current_date(date_t *); void calendar_store_current_date (date_t *);
void calendar_init_slctd_day(void); void calendar_init_slctd_day (void);
date_t *calendar_get_slctd_day(void); date_t *calendar_get_slctd_day (void);
long calendar_get_slctd_day_sec(void); long calendar_get_slctd_day_sec (void);
void calendar_update_panel(WINDOW *); void calendar_update_panel (WINDOW *);
void calendar_change_day(int datefmt); void calendar_change_day (int);
void calendar_move(move_t); void calendar_move (move_t);
char *calendar_get_pom(time_t); char *calendar_get_pom (time_t);
#endif /* CALCURSE_CALENDAR_H */ #endif /* CALCURSE_CALENDAR_H */
+678 -645
View File
File diff suppressed because it is too large Load Diff
+45 -42
View File
@@ -1,4 +1,4 @@
/* $calcurse: custom.h,v 1.11 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: custom.h,v 1.12 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -32,52 +32,55 @@
#define NBUSERCOLORS 6 #define NBUSERCOLORS 6
enum { /* Color pairs */ enum
COLR_RED = 1, { /* Color pairs */
COLR_GREEN, COLR_RED = 1,
COLR_YELLOW, COLR_GREEN,
COLR_BLUE, COLR_YELLOW,
COLR_MAGENTA, COLR_BLUE,
COLR_CYAN, COLR_MAGENTA,
COLR_DEFAULT, COLR_CYAN,
COLR_HIGH, COLR_DEFAULT,
COLR_CUSTOM COLR_HIGH,
COLR_CUSTOM
}; };
enum { /* Configuration variables */ enum
CUSTOM_CONF_NOVARIABLE, { /* Configuration variables */
CUSTOM_CONF_AUTOSAVE, CUSTOM_CONF_NOVARIABLE,
CUSTOM_CONF_CONFIRMQUIT, CUSTOM_CONF_AUTOSAVE,
CUSTOM_CONF_CONFIRMDELETE, CUSTOM_CONF_CONFIRMQUIT,
CUSTOM_CONF_SKIPSYSTEMDIALOGS, CUSTOM_CONF_CONFIRMDELETE,
CUSTOM_CONF_SKIPPROGRESSBAR, CUSTOM_CONF_SKIPSYSTEMDIALOGS,
CUSTOM_CONF_WEEKBEGINSONMONDAY, CUSTOM_CONF_SKIPPROGRESSBAR,
CUSTOM_CONF_COLORTHEME, CUSTOM_CONF_WEEKBEGINSONMONDAY,
CUSTOM_CONF_LAYOUT, CUSTOM_CONF_COLORTHEME,
CUSTOM_CONF_NOTIFYBARSHOW, CUSTOM_CONF_LAYOUT,
CUSTOM_CONF_NOTIFYBARDATE, CUSTOM_CONF_NOTIFYBARSHOW,
CUSTOM_CONF_NOTIFYBARCLOCK, CUSTOM_CONF_NOTIFYBARDATE,
CUSTOM_CONF_NOTIFYBARWARNING, CUSTOM_CONF_NOTIFYBARCLOCK,
CUSTOM_CONF_NOTIFYBARCOMMAND, CUSTOM_CONF_NOTIFYBARWARNING,
CUSTOM_CONF_OUTPUTDATEFMT, CUSTOM_CONF_NOTIFYBARCOMMAND,
CUSTOM_CONF_INPUTDATEFMT, CUSTOM_CONF_OUTPUTDATEFMT,
CUSTOM_CONF_VARIABLES CUSTOM_CONF_INPUTDATEFMT,
CUSTOM_CONF_VARIABLES
}; };
struct attribute_s { struct attribute_s
int color[7]; {
int nocolor[7]; int color[7];
int nocolor[7];
}; };
void custom_init_attr(void); void custom_init_attr (void);
void custom_apply_attr(WINDOW *, int); void custom_apply_attr (WINDOW *, int);
void custom_remove_attr(WINDOW *, int); void custom_remove_attr (WINDOW *, int);
void custom_load_conf(conf_t *, int); void custom_load_conf (conf_t *, int);
void config_bar(void); void config_bar (void);
void layout_config(void); void layout_config (void);
void custom_color_config(void); void custom_color_config (void);
void custom_color_theme_name(char *); void custom_color_theme_name (char *);
void custom_confwin_init(window_t *, char *); void custom_confwin_init (window_t *, char *);
void custom_general_config(conf_t *); void custom_general_config (conf_t *);
#endif /* CALCURSE_CUSTOM_H */ #endif /* CALCURSE_CUSTOM_H */
+702 -640
View File
File diff suppressed because it is too large Load Diff
+35 -31
View File
@@ -1,4 +1,4 @@
/* $calcurse: day.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: day.h,v 1.19 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -38,40 +38,44 @@
#define RECUR_APPT 3 #define RECUR_APPT 3
#define APPT 4 #define APPT 4
typedef struct { typedef struct
unsigned nb_events; {
unsigned nb_apoints; unsigned nb_events;
} day_items_nb_t; unsigned nb_apoints;
}
day_items_nb_t;
struct day_item_s { struct day_item_s
struct day_item_s *next; {
long start; /* seconds since 1 jan 1970 */ struct day_item_s *next;
long appt_dur; /* appointment duration in seconds */ long start; /* seconds since 1 jan 1970 */
int type; /* (recursive or normal) event or appointment */ long appt_dur; /* appointment duration in seconds */
int evnt_id; /* event identifier */ int type; /* (recursive or normal) event or appointment */
int appt_pos; /* real position in recurrent list */ int evnt_id; /* event identifier */
char state; /* appointment state */ int appt_pos; /* real position in recurrent list */
char *mesg; /* item description */ char state; /* appointment state */
char *note; /* note attached to item */ char *mesg; /* item description */
char *note; /* note attached to item */
}; };
struct day_saved_item_s { struct day_saved_item_s
char start[BUFSIZ]; {
char end[BUFSIZ]; char start[BUFSIZ];
char state; char end[BUFSIZ];
char type ; char state;
char *mesg; char type;
char *mesg;
}; };
day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *); day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
void day_write_pad(long, int, int, int); void day_write_pad (long, int, int, int);
void day_popup_item(void); void day_popup_item (void);
int day_check_if_item(date_t); int day_check_if_item (date_t);
void day_edit_item(conf_t *); void day_edit_item (conf_t *);
int day_erase_item(long, int, erase_flag_e); int day_erase_item (long, int, erase_flag_e);
struct day_item_s *day_get_item(int); struct day_item_s *day_get_item (int);
int day_item_nb(long, int, int); int day_item_nb (long, int, int);
void day_edit_note(char *); void day_edit_note (char *);
void day_view_note(char *); void day_view_note (char *);
#endif /* CALCURSE_DAY_H */ #endif /* CALCURSE_DAY_H */
+105 -93
View File
@@ -1,4 +1,4 @@
/* $calcurse: event.c,v 1.6 2008/01/20 10:45:38 culot Exp $ */ /* $calcurse: event.c,v 1.7 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -37,132 +37,144 @@ struct event_s *eventlist;
/* Create a new event */ /* Create a new event */
struct event_s * struct event_s *
event_new(char *mesg, char *note, long day, int id) event_new (char *mesg, char *note, long day, int id)
{ {
struct event_s *o, **i; struct event_s *o, **i;
o = (struct event_s *) malloc(sizeof(struct event_s)); o = (struct event_s *) malloc (sizeof (struct event_s));
o->mesg = (char *) malloc(strlen(mesg) + 1); o->mesg = (char *) malloc (strlen (mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1); strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->day = day; o->day = day;
o->id = id; o->id = id;
o->note = (note != NULL) ? strdup(note) : NULL; o->note = (note != NULL) ? strdup (note) : NULL;
i = &eventlist; i = &eventlist;
for (;;) { for (;;)
if (*i == 0 || (*i)->day > day) { {
o->next = *i; if (*i == 0 || (*i)->day > day)
*i = o; {
break; o->next = *i;
} *i = o;
i = &(*i)->next; break;
} }
return o; i = &(*i)->next;
}
return (o);
} }
/* Check if the event belongs to the selected day */ /* Check if the event belongs to the selected day */
unsigned unsigned
event_inday(struct event_s *i, long start) event_inday (struct event_s *i, long start)
{ {
if (i->day <= start + DAYINSEC && i->day > start) { if (i->day <= start + DAYINSEC && i->day > start)
return 1; {
} return (1);
return 0; }
return (0);
} }
/* Write to file the event in user-friendly format */ /* Write to file the event in user-friendly format */
void void
event_write(struct event_s *o, FILE * f) event_write (struct event_s *o, FILE *f)
{ {
struct tm *lt; struct tm *lt;
time_t t; time_t t;
t = o->day; t = o->day;
lt = localtime(&t); lt = localtime (&t);
fprintf(f, "%02u/%02u/%04u [%d] ", fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, o->id); 1900 + lt->tm_year, o->id);
if (o->note != NULL) if (o->note != NULL)
fprintf(f, ">%s ", o->note); fprintf (f, ">%s ", o->note);
fprintf(f, "%s\n", o->mesg); fprintf (f, "%s\n", o->mesg);
} }
/* Load the events from file */ /* Load the events from file */
struct event_s * struct event_s *
event_scan(FILE * f, struct tm start, int id, char *note) event_scan (FILE *f, struct tm start, int id, char *note)
{ {
struct tm *lt; struct tm *lt;
char buf[MESG_MAXSIZE], *nl; char buf[MESG_MAXSIZE], *nl;
time_t tstart, t; time_t tstart, t;
t = time(NULL); t = time (NULL);
lt = localtime(&t); lt = localtime (&t);
/* Read the event description */ /* Read the event description */
fgets(buf, MESG_MAXSIZE, f); fgets (buf, MESG_MAXSIZE, f);
nl = strchr(buf, '\n'); nl = strchr (buf, '\n');
if (nl) { if (nl)
*nl = '\0'; {
} *nl = '\0';
start.tm_hour = 12; }
start.tm_min = 0; start.tm_hour = 12;
start.tm_sec = 0; start.tm_min = 0;
start.tm_isdst = -1; start.tm_sec = 0;
start.tm_year -= 1900; start.tm_isdst = -1;
start.tm_mon--; start.tm_year -= 1900;
start.tm_mon--;
tstart = mktime(&start); tstart = mktime (&start);
if (tstart == -1) { if (tstart == -1)
fputs(_("FATAL ERROR in event_scan: date error in the event\n"), stderr); {
exit(EXIT_FAILURE); fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
} stderr);
return (event_new(buf, note, tstart, id)); exit (EXIT_FAILURE);
}
return (event_new (buf, note, tstart, id));
} }
/* Retrieve an event from the list, given the day and item position. */ /* Retrieve an event from the list, given the day and item position. */
struct event_s * struct event_s *
event_get(long day, int pos) event_get (long day, int pos)
{ {
struct event_s *o; struct event_s *o;
int n; int n;
n = 0; n = 0;
for (o = eventlist; o; o = o->next) { for (o = eventlist; o; o = o->next)
if (event_inday(o, day)) { {
if (n == pos) if (event_inday (o, day))
return o; {
n++; if (n == pos)
} return o;
n++;
} }
/* NOTREACHED */ }
fputs(_("FATAL ERROR in event_get: no such item\n"), stderr); /* NOTREACHED */
exit(EXIT_FAILURE); fputs (_("FATAL ERROR in event_get: no such item\n"), stderr);
exit (EXIT_FAILURE);
} }
/* Delete an event from the list. */ /* Delete an event from the list. */
void void
event_delete_bynum(long start, unsigned num, erase_flag_e flag) event_delete_bynum (long start, unsigned num, erase_flag_e flag)
{ {
unsigned n; unsigned n;
struct event_s *i, **iptr; struct event_s *i, **iptr;
n = 0; n = 0;
iptr = &eventlist; iptr = &eventlist;
for (i = eventlist; i != 0; i = i->next) { for (i = eventlist; i != 0; i = i->next)
if (event_inday(i, start)) { {
if (n == num) { if (event_inday (i, start))
if (flag == ERASE_FORCE_ONLY_NOTE) {
erase_note(&i->note, flag); if (n == num)
else { {
*iptr = i->next; if (flag == ERASE_FORCE_ONLY_NOTE)
free(i->mesg); erase_note (&i->note, flag);
erase_note(&i->note, flag); else
free(i); {
} *iptr = i->next;
return; free (i->mesg);
} erase_note (&i->note, flag);
n++; free (i);
} }
iptr = &i->next; return;
}
n++;
} }
/* NOTREACHED */ iptr = &i->next;
fputs(_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr); }
exit(EXIT_FAILURE); /* NOTREACHED */
fputs (_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
exit (EXIT_FAILURE);
} }
+14 -13
View File
@@ -1,4 +1,4 @@
/* $calcurse: event.h,v 1.5 2008/01/20 10:45:38 culot Exp $ */ /* $calcurse: event.h,v 1.6 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -32,21 +32,22 @@
#define HRMIN_SIZE 6 #define HRMIN_SIZE 6
#define MESG_MAXSIZE 256 #define MESG_MAXSIZE 256
struct event_s { struct event_s
struct event_s *next; {
int id; /* event identifier */ struct event_s *next;
long day; /* seconds since 1 jan 1970 */ int id; /* event identifier */
char *mesg; long day; /* seconds since 1 jan 1970 */
char *note; char *mesg;
char *note;
}; };
extern struct event_s *eventlist; extern struct event_s *eventlist;
struct event_s *event_new(char *, char *, long, int); struct event_s *event_new (char *, char *, long, int);
unsigned event_inday(struct event_s *, long); unsigned event_inday (struct event_s *, long);
void event_write(struct event_s *, FILE *); void event_write (struct event_s *, FILE *);
struct event_s *event_scan(FILE *, struct tm, int, char *); struct event_s *event_scan (FILE *, struct tm, int, char *);
struct event_s *event_get(long, int); struct event_s *event_get (long, int);
void event_delete_bynum(long, unsigned, erase_flag_e); void event_delete_bynum (long, unsigned, erase_flag_e);
#endif /* CALCURSE_EVENT_H */ #endif /* CALCURSE_EVENT_H */
+482 -472
View File
File diff suppressed because it is too large Load Diff
+8 -6
View File
@@ -1,4 +1,4 @@
/* $calcurse: help.h,v 1.4 2007/07/28 13:11:42 culot Exp $ */ /* $calcurse: help.h,v 1.5 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -27,11 +27,13 @@
#ifndef CALCURSE_HELP_H #ifndef CALCURSE_HELP_H
#define CALCURSE_HELP_H #define CALCURSE_HELP_H
typedef struct { typedef struct
char *title; {
char *text; char *title;
} help_page_t; char *text;
}
help_page_t;
void help_screen(void); void help_screen (void);
#endif /* CALCURSE_HELP_H */ #endif /* CALCURSE_HELP_H */
+17 -17
View File
@@ -1,4 +1,4 @@
/* $calcurse: i18n.h,v 1.1 2006/07/31 21:00:03 culot Exp $ */ /* $calcurse: i18n.h,v 1.2 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -32,23 +32,23 @@
#endif /* HAVE_CONFIG_H */ #endif /* HAVE_CONFIG_H */
#if ENABLE_NLS #if ENABLE_NLS
#include <libintl.h> #include <libintl.h>
#undef _ #undef _
#define _(String) gettext(String) #define _(String) gettext(String)
#ifdef gettext_noop #ifdef gettext_noop
#define N_(String) gettext_noop(String) #define N_(String) gettext_noop(String)
#else #else
#define N_(String) (String) #define N_(String) (String)
#endif #endif
#else /* NLS disabled */ #else /* NLS disabled */
#define _(String) (String) #define _(String) (String)
#define N_(String) (String) #define N_(String) (String)
#define textdomain(String) (String) #define textdomain(String) (String)
#define gettext(String) (String) #define gettext(String) (String)
#define dgettext(String) (String) #define dgettext(String) (String)
#define dcgettext(String) (String) #define dcgettext(String) (String)
#define bindtextdomain(String) (String) #define bindtextdomain(String) (String)
#define bind_textdomain_codeset(Domain,Codeset) (Codeset) #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
#endif /* ENABLE_NLS */ #endif /* ENABLE_NLS */
#endif /* CALCURSE_I18N_H */ #endif /* CALCURSE_I18N_H */
+747 -653
View File
File diff suppressed because it is too large Load Diff
+17 -15
View File
@@ -1,8 +1,8 @@
/* $calcurse: io.h,v 1.8 2007/08/15 15:36:27 culot Exp $ */ /* $calcurse: io.h,v 1.9 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2004-2007 Frederic Culot * Copyright (c) 2004-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -29,19 +29,21 @@
#include "vars.h" #include "vars.h"
typedef enum { typedef enum
IO_EXPORT_NONINTERACTIVE, {
IO_EXPORT_INTERACTIVE, IO_EXPORT_NONINTERACTIVE,
IO_EXPORT_NBMODES IO_EXPORT_INTERACTIVE,
} export_mode_t; IO_EXPORT_NBMODES
}
export_mode_t;
void io_init(char *); void io_init (char *);
void io_extract_data(char *, const char *, int); void io_extract_data (char *, const char *, int);
void io_save_cal(conf_t *); void io_save_cal (conf_t *);
void io_load_app(void); void io_load_app (void);
void io_load_todo(void); void io_load_todo (void);
int io_check_data_files(void); int io_check_data_files (void);
void io_startup_screen(bool, int); void io_startup_screen (bool, int);
void io_export_data(export_mode_t, conf_t *); void io_export_data (export_mode_t, conf_t *);
#endif /* CALCURSE_IO_H */ #endif /* CALCURSE_IO_H */
+439 -417
View File
File diff suppressed because it is too large Load Diff
+30 -28
View File
@@ -1,8 +1,8 @@
/* $calcurse: notify.h,v 1.12 2007/08/15 15:33:01 culot Exp $ */ /* $calcurse: notify.h,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2004-2007 Frederic Culot * Copyright (c) 2004-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -33,35 +33,37 @@
#define NOTIFY_FIELD_LENGTH 25 #define NOTIFY_FIELD_LENGTH 25
struct notify_vars_s { struct notify_vars_s
WINDOW *win; {
long time_in_sec; WINDOW *win;
char *apts_file; long time_in_sec;
char time[NOTIFY_FIELD_LENGTH]; char *apts_file;
char date[NOTIFY_FIELD_LENGTH]; char time[NOTIFY_FIELD_LENGTH];
pthread_mutex_t mutex; char date[NOTIFY_FIELD_LENGTH];
pthread_mutex_t mutex;
}; };
struct notify_app_s { struct notify_app_s
long time; {
int got_app; long time;
char *txt; int got_app;
char state; char *txt;
pthread_mutex_t mutex; char state;
pthread_mutex_t mutex;
}; };
int notify_bar(void); int notify_bar (void);
void notify_init_vars(void); void notify_init_vars (void);
void notify_init_bar(void); void notify_init_bar (void);
void notify_start_main_thread(void); void notify_start_main_thread (void);
void notify_stop_main_thread(void); void notify_stop_main_thread (void);
void notify_reinit_bar(int, int, int, int); void notify_reinit_bar (int, int, int, int);
void notify_update_bar(void); void notify_update_bar (void);
void notify_check_next_app(void); void notify_check_next_app (void);
void notify_check_added(char *, long, char); void notify_check_added (char *, long, char);
void notify_check_repeated(recur_apoint_llist_node_t *); void notify_check_repeated (recur_apoint_llist_node_t *);
int notify_same_item(long); int notify_same_item (long);
int notify_same_recur_item(recur_apoint_llist_node_t *); int notify_same_recur_item (recur_apoint_llist_node_t *);
void notify_config_bar(void); void notify_config_bar (void);
#endif /* CALCURSE_NOTIFY_H */ #endif /* CALCURSE_NOTIFY_H */
+722 -651
View File
File diff suppressed because it is too large Load Diff
+69 -59
View File
@@ -1,4 +1,4 @@
/* $calcurse: recur.h,v 1.18 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: recur.h,v 1.19 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -27,75 +27,85 @@
#ifndef CALCURSE_RECUR_H #ifndef CALCURSE_RECUR_H
#define CALCURSE_RECUR_H #define CALCURSE_RECUR_H
typedef enum { RECUR_NO, typedef enum
RECUR_DAILY, { RECUR_NO,
RECUR_WEEKLY, RECUR_DAILY,
RECUR_MONTHLY, RECUR_WEEKLY,
RECUR_YEARLY, RECUR_MONTHLY,
RECUR_TYPES RECUR_YEARLY,
} recur_types_t; RECUR_TYPES
}
recur_types_t;
struct days_s { struct days_s
struct days_s *next; {
long st; /* beggining of the considered day, in seconds */ struct days_s *next;
long st; /* beggining of the considered day, in seconds */
}; };
struct rpt_s { struct rpt_s
int type; /* repetition type, see RECUR_* defines */ {
int freq; /* repetition frequence */ int type; /* repetition type, see RECUR_* defines */
long until; /* ending date for repeated event */ int freq; /* repetition frequence */
long until; /* ending date for repeated event */
}; };
typedef struct recur_apoint_llist_node { typedef struct recur_apoint_llist_node
struct recur_apoint_llist_node *next; {
struct rpt_s *rpt; /* information about repetition */ struct recur_apoint_llist_node *next;
struct days_s *exc; /* days when the item should not be repeated */ struct rpt_s *rpt; /* information about repetition */
long start; /* beggining of the appointment */ struct days_s *exc; /* days when the item should not be repeated */
long dur; /* duration of the appointment */ long start; /* beggining of the appointment */
char state; /* 8 bits to store item state */ long dur; /* duration of the appointment */
char *mesg; /* appointment description */ char state; /* 8 bits to store item state */
char *note; /* note attached to appointment */ char *mesg; /* appointment description */
} recur_apoint_llist_node_t; char *note; /* note attached to appointment */
}
recur_apoint_llist_node_t;
typedef struct recur_apoint_llist { typedef struct recur_apoint_llist
recur_apoint_llist_node_t *root; {
pthread_mutex_t mutex; recur_apoint_llist_node_t *root;
} recur_apoint_llist_t; pthread_mutex_t mutex;
}
recur_apoint_llist_t;
struct recur_event_s { struct recur_event_s
struct recur_event_s *next; {
struct rpt_s *rpt; /* information about repetition */ struct recur_event_s *next;
struct days_s *exc; /* days when the item should not be repeated */ struct rpt_s *rpt; /* information about repetition */
int id; /* event type */ struct days_s *exc; /* days when the item should not be repeated */
long day; /* day at which event occurs */ int id; /* event type */
char *mesg; /* event description */ long day; /* day at which event occurs */
char *note; /* note attached to event */ char *mesg; /* event description */
char *note; /* note attached to event */
}; };
extern recur_apoint_llist_t *recur_alist_p; extern recur_apoint_llist_t *recur_alist_p;
extern struct recur_event_s *recur_elist; extern struct recur_event_s *recur_elist;
int recur_apoint_llist_init(void); int recur_apoint_llist_init (void);
char recur_def2char(recur_types_t); char recur_def2char (recur_types_t);
int recur_char2def(char); int recur_char2def (char);
recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm, recur_apoint_llist_node_t *recur_apoint_scan (FILE *, struct tm, struct tm,
char, int, struct tm, char *, char, int, struct tm, char *,
struct days_s *, char); struct days_s *, char);
struct recur_event_s *recur_event_scan(FILE *, struct tm, int, char, struct recur_event_s *recur_event_scan (FILE *, struct tm, int, char,
int, struct tm, char *, struct days_s *); int, struct tm, char *,
void recur_save_data(FILE *); struct days_s *);
unsigned recur_item_inday(long, struct days_s *, int, void recur_save_data (FILE *);
int, long, long); unsigned recur_item_inday (long, struct days_s *, int, int,
void recur_event_erase(long, unsigned, unsigned, long, long);
erase_flag_e); void recur_event_erase (long, unsigned, unsigned,
void recur_apoint_erase(long, unsigned, unsigned, erase_flag_e);
erase_flag_e); void recur_apoint_erase (long, unsigned, unsigned,
void recur_repeat_item(conf_t *); erase_flag_e);
struct days_s *recur_exc_scan(FILE *); void recur_repeat_item (conf_t *);
struct notify_app_s *recur_apoint_check_next(struct notify_app_s *, struct days_s *recur_exc_scan (FILE *);
long, long); struct notify_app_s *recur_apoint_check_next (struct notify_app_s *,
recur_apoint_llist_node_t *recur_get_apoint(long, int); long, long);
struct recur_event_s *recur_get_event(long, int); recur_apoint_llist_node_t *recur_get_apoint (long, int);
void recur_apoint_switch_notify(long, int); struct recur_event_s *recur_get_event (long, int);
void recur_apoint_switch_notify (long, int);
#endif /* CALCURSE_RECUR_H */ #endif /* CALCURSE_RECUR_H */
+39 -35
View File
@@ -1,8 +1,8 @@
/* $calcurse: sigs.c,v 1.5 2008/02/14 20:20:23 culot Exp $ */ /* $calcurse: sigs.c,v 1.6 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot * Copyright (c) 2007-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -40,45 +40,49 @@
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically. * Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
*/ */
static void static void
signal_handler(int sig) signal_handler (int sig)
{ {
switch (sig) { switch (sig)
case SIGCHLD: {
while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0) case SIGCHLD:
; while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0)
break; ;
case SIGWINCH: break;
clearok(curscr, TRUE); case SIGWINCH:
ungetch(KEY_RESIZE); clearok (curscr, TRUE);
break; ungetch (KEY_RESIZE);
} break;
}
} }
/* Signal handling init. */ /* Signal handling init. */
void void
sigs_init(struct sigaction *sa) sigs_init (struct sigaction *sa)
{ {
sa->sa_handler = signal_handler; sa->sa_handler = signal_handler;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction(SIGCHLD, sa, NULL) != 0) { if (sigaction (SIGCHLD, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
} exit (EXIT_FAILURE);
}
sa->sa_handler = signal_handler; sa->sa_handler = signal_handler;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&sa->sa_mask); sigemptyset (&sa->sa_mask);
if (sigaction(SIGWINCH, sa, NULL) != 0) { if (sigaction (SIGWINCH, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
} exit (EXIT_FAILURE);
}
sa->sa_handler = SIG_IGN; sa->sa_handler = SIG_IGN;
sa->sa_flags = 0; sa->sa_flags = 0;
sigemptyset(&(sa->sa_mask)); sigemptyset (&(sa->sa_mask));
if (sigaction(SIGINT, sa, NULL) != 0) { if (sigaction (SIGINT, sa, NULL) != 0)
perror("sigaction"); {
exit(EXIT_FAILURE); perror ("sigaction");
} exit (EXIT_FAILURE);
}
} }
+3 -3
View File
@@ -1,8 +1,8 @@
/* $calcurse: sigs.h,v 1.2 2008/02/14 20:20:23 culot Exp $ */ /* $calcurse: sigs.h,v 1.3 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot * Copyright (c) 2007-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -27,6 +27,6 @@
#ifndef CALCURSE_SIGS_H #ifndef CALCURSE_SIGS_H
#define CALCURSE_SIGS_H #define CALCURSE_SIGS_H
void sigs_init(struct sigaction *); void sigs_init (struct sigaction *);
#endif /* CALCURSE_SIGS_H */ #endif /* CALCURSE_SIGS_H */
+311 -286
View File
@@ -1,8 +1,8 @@
/* $calcurse: todo.c,v 1.20 2008/04/04 21:31:20 culot Exp $ */ /* $calcurse: todo.c,v 1.21 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2004-2007 Frederic Culot * Copyright (c) 2004-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -33,83 +33,84 @@
#include "i18n.h" #include "i18n.h"
#include "todo.h" #include "todo.h"
struct todo_s *todolist; struct todo_s *todolist;
static int hilt = 0; static int hilt = 0;
static int todos = 0; static int todos = 0;
static int first = 1; static int first = 1;
static char *msgsav; static char *msgsav;
/* Returns a structure containing the selected item. */ /* Returns a structure containing the selected item. */
static struct todo_s * static struct todo_s *
todo_get_item(int item_number) todo_get_item (int item_number)
{ {
struct todo_s *o; struct todo_s *o;
int i; int i;
o = todolist; o = todolist;
for (i = 1; i < item_number; i++) { for (i = 1; i < item_number; i++)
o = o->next; {
} o = o->next;
return o; }
return (o);
} }
/* Sets which todo is highlighted. */ /* Sets which todo is highlighted. */
void void
todo_hilt_set(int highlighted) todo_hilt_set (int highlighted)
{ {
hilt = highlighted; hilt = highlighted;
} }
void void
todo_hilt_decrease(void) todo_hilt_decrease (void)
{ {
hilt--; hilt--;
} }
void void
todo_hilt_increase(void) todo_hilt_increase (void)
{ {
hilt++; hilt++;
} }
/* Return which todo is highlighted. */ /* Return which todo is highlighted. */
int int
todo_hilt(void) todo_hilt (void)
{ {
return (hilt); return (hilt);
} }
/* Return the number of todos. */ /* Return the number of todos. */
int int
todo_nb(void) todo_nb (void)
{ {
return (todos); return (todos);
} }
/* Set the number of todos. */ /* Set the number of todos. */
void void
todo_set_nb(int nb) todo_set_nb (int nb)
{ {
todos = nb; todos = nb;
} }
/* Set which one is the first todo to be displayed. */ /* Set which one is the first todo to be displayed. */
void void
todo_set_first(int nb) todo_set_first (int nb)
{ {
first = nb; first = nb;
} }
void void
todo_first_increase(void) todo_first_increase (void)
{ {
first++; first++;
} }
void void
todo_first_decrease(void) todo_first_decrease (void)
{ {
first--; first--;
} }
/* /*
@@ -117,176 +118,187 @@ todo_first_decrease(void)
* displayed. * displayed.
*/ */
int int
todo_hilt_pos(void) todo_hilt_pos (void)
{ {
return (hilt - first); return (hilt - first);
} }
/* Return the last visited todo. */ /* Return the last visited todo. */
char * char *
todo_saved_mesg(void) todo_saved_mesg (void)
{ {
return (msgsav); return (msgsav);
} }
/* Request user to enter a new todo item. */ /* Request user to enter a new todo item. */
void void
todo_new_item(void) todo_new_item (void)
{ {
int ch = 0; int ch = 0;
char *mesg = _("Enter the new ToDo item : "); char *mesg = _("Enter the new ToDo item : ");
char *mesg_id = char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :"); char todo_input[BUFSIZ] = "";
char todo_input[BUFSIZ] = "";
status_mesg(mesg, ""); status_mesg (mesg, "");
if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) == if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
GETSTRING_VALID) { {
while ( (ch < '1') || (ch > '9') ) { while ((ch < '1') || (ch > '9'))
status_mesg(mesg_id, ""); {
ch = wgetch(win[STA].p); status_mesg (mesg_id, "");
} ch = wgetch (win[STA].p);
todo_add(todo_input, ch - '0', NULL);
todos++;
} }
todo_add (todo_input, ch - '0', NULL);
todos++;
}
} }
/* Add an item in the todo linked list. */ /* Add an item in the todo linked list. */
struct todo_s * struct todo_s *
todo_add(char *mesg, int id, char *note) todo_add (char *mesg, int id, char *note)
{ {
struct todo_s *o, **i; struct todo_s *o, **i;
o = (struct todo_s *) malloc(sizeof(struct todo_s)); o = (struct todo_s *) malloc (sizeof (struct todo_s));
o->mesg = (char *) malloc(strlen(mesg) + 1); o->mesg = (char *) malloc (strlen (mesg) + 1);
strncpy(o->mesg, mesg, strlen(mesg) + 1); strncpy (o->mesg, mesg, strlen (mesg) + 1);
o->id = id; o->id = id;
o->note = (note != NULL && note[0] != '\0') ? strdup(note) : NULL; o->note = (note != NULL && note[0] != '\0') ? strdup (note) : NULL;
i = &todolist; i = &todolist;
for (;;) { for (;;)
if (*i == 0 || (*i)->id > id) { {
o->next = *i; if (*i == 0 || (*i)->id > id)
*i = o; {
break; o->next = *i;
} *i = o;
i = &(*i)->next; break;
} }
return o; i = &(*i)->next;
}
return (o);
} }
/* Delete a note previously attached to a todo item. */ /* Delete a note previously attached to a todo item. */
static void static void
todo_delete_note_bynum(unsigned num) todo_delete_note_bynum (unsigned num)
{ {
unsigned n; unsigned n;
struct todo_s *i, **iptr; struct todo_s *i, **iptr;
n = 0; n = 0;
iptr = &todolist; iptr = &todolist;
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
if (n == num) { {
if (i->note == NULL) if (n == num)
ierror( {
_("FATAL ERROR in todo_delete_note_bynum: " if (i->note == NULL)
"no note attached\n"), IERROR_FATAL); ierror (_("FATAL ERROR in todo_delete_note_bynum: "
erase_note(&i->note, ERASE_FORCE_ONLY_NOTE); "no note attached\n"), IERROR_FATAL);
return; erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
} return;
iptr = &i->next;
n++;
} }
/* NOTREACHED */ iptr = &i->next;
ierror(_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"), n++;
IERROR_FATAL); }
exit(EXIT_FAILURE); /* NOTREACHED */
ierror (_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
IERROR_FATAL);
exit (EXIT_FAILURE);
} }
/* Delete an item from the todo linked list. */ /* Delete an item from the todo linked list. */
static void static void
todo_delete_bynum(unsigned num, erase_flag_e flag) todo_delete_bynum (unsigned num, erase_flag_e flag)
{ {
unsigned n; unsigned n;
struct todo_s *i, **iptr; struct todo_s *i, **iptr;
n = 0; n = 0;
iptr = &todolist; iptr = &todolist;
for (i = todolist; i != 0; i = i->next) { for (i = todolist; i != 0; i = i->next)
if (n == num) { {
*iptr = i->next; if (n == num)
free(i->mesg); {
if (i->note != NULL) *iptr = i->next;
erase_note(&i->note, flag); free (i->mesg);
free(i); if (i->note != NULL)
return; erase_note (&i->note, flag);
} free (i);
iptr = &i->next; return;
n++;
} }
/* NOTREACHED */ iptr = &i->next;
ierror(_("FATAL ERROR in todo_delete_bynum: no such todo\n"), n++;
IERROR_FATAL); }
exit(EXIT_FAILURE); /* NOTREACHED */
ierror (_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
IERROR_FATAL);
exit (EXIT_FAILURE);
} }
/* Delete an item from the ToDo list. */ /* Delete an item from the ToDo list. */
void void
todo_delete(conf_t *conf) todo_delete (conf_t *conf)
{ {
char *choices = "[y/n] "; char *choices = "[y/n] ";
char *del_todo_str = _("Do you really want to delete this task ?"); char *del_todo_str = _("Do you really want to delete this task ?");
char *erase_warning = char *erase_warning =
_("This item has a note attached to it. " _("This item has a note attached to it. "
"Delete (t)odo or just its (n)ote ?"); "Delete (t)odo or just its (n)ote ?");
char *erase_choice = char *erase_choice = _("[t/n] ");
_("[t/n] "); bool go_for_todo_del = false;
bool go_for_todo_del = false; int answer = 0, has_note;
int answer = 0, has_note;
if (conf->confirm_delete) { if (conf->confirm_delete)
status_mesg(del_todo_str, choices); {
answer = wgetch(win[STA].p); status_mesg (del_todo_str, choices);
if ( (answer == 'y') && (todos > 0) ) { answer = wgetch (win[STA].p);
go_for_todo_del = true; if ((answer == 'y') && (todos > 0))
} else { {
erase_status_bar(); go_for_todo_del = true;
return;
}
} else
if (todos > 0)
go_for_todo_del = true;
if (go_for_todo_del == false) {
erase_status_bar();
return;
} }
else
answer = 0; {
has_note = (todo_get_item(hilt)->note != NULL) ? 1 : 0; erase_status_bar ();
if (has_note == 0) return;
answer = 't';
while (answer != 't' && answer != 'n' && answer != ESCAPE) {
status_mesg(erase_warning, erase_choice);
answer = wgetch(win[STA].p);
} }
}
else if (todos > 0)
go_for_todo_del = true;
switch (answer) { if (go_for_todo_del == false)
case 't': {
todo_delete_bynum(hilt - 1, ERASE_FORCE); erase_status_bar ();
todos--; return;
if (hilt > 1) }
hilt--;
if (todos == 0) answer = 0;
hilt = 0; has_note = (todo_get_item (hilt)->note != NULL) ? 1 : 0;
if (hilt - first < 0) if (has_note == 0)
first--; answer = 't';
break;
case 'n': while (answer != 't' && answer != 'n' && answer != ESCAPE)
todo_delete_note_bynum(hilt - 1); {
break; status_mesg (erase_warning, erase_choice);
default: answer = wgetch (win[STA].p);
erase_status_bar(); }
return;
} switch (answer)
{
case 't':
todo_delete_bynum (hilt - 1, ERASE_FORCE);
todos--;
if (hilt > 1)
hilt--;
if (todos == 0)
hilt = 0;
if (hilt - first < 0)
first--;
break;
case 'n':
todo_delete_note_bynum (hilt - 1);
break;
default:
erase_status_bar ();
return;
}
} }
/* /*
@@ -294,172 +306,185 @@ todo_delete(conf_t *conf)
* given todo_s item. * given todo_s item.
*/ */
static int static int
todo_get_position(struct todo_s *i) todo_get_position (struct todo_s *i)
{ {
struct todo_s *o; struct todo_s *o;
int n = 1, found = 0; int n = 1, found = 0;
for (o = todolist; o; o = o->next) { for (o = todolist; o; o = o->next)
if (o == i) { {
found = 1; if (o == i)
break; {
} found = 1;
n++; break;
}
if (found) {
return n;
} else {
fputs(_("FATAL ERROR in todo_get_position: todo not found\n"),
stderr);
exit(EXIT_FAILURE);
} }
n++;
}
if (found)
{
return (n);
}
else
{
fputs (_("FATAL ERROR in todo_get_position: todo not found\n"), stderr);
exit (EXIT_FAILURE);
}
} }
/* Change an item priority by pressing '+' or '-' inside TODO panel. */ /* Change an item priority by pressing '+' or '-' inside TODO panel. */
void void
todo_chg_priority(int action) todo_chg_priority (int action)
{ {
struct todo_s *backup; struct todo_s *backup;
char backup_mesg[BUFSIZ]; char backup_mesg[BUFSIZ];
int backup_id; int backup_id;
char backup_note[NOTESIZ + 1]; char backup_note[NOTESIZ + 1];
int do_chg = 1; int do_chg = 1;
backup = todo_get_item(hilt); backup = todo_get_item (hilt);
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1); strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
backup_id = backup->id; backup_id = backup->id;
if (backup->note) if (backup->note)
strncpy(backup_note, backup->note, NOTESIZ + 1); strncpy (backup_note, backup->note, NOTESIZ + 1);
else else
backup_note[0] = '\0'; backup_note[0] = '\0';
if (action == '+') { if (action == '+')
(backup_id > 1) ? backup_id-- : do_chg--; {
} else if (action == '-') { (backup_id > 1) ? backup_id-- : do_chg--;
(backup_id < 9) ? backup_id++ : do_chg--; }
} else { /* NOTREACHED */ else if (action == '-')
fputs(_("FATAL ERROR in todo_chg_priority: no such action\n"), {
stderr); (backup_id < 9) ? backup_id++ : do_chg--;
} }
if (do_chg) { else
todo_delete_bynum(hilt - 1, ERASE_FORCE_KEEP_NOTE); { /* NOTREACHED */
backup = todo_add(backup_mesg, backup_id, backup_note); fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr);
hilt = todo_get_position(backup); }
} if (do_chg)
{
todo_delete_bynum (hilt - 1, ERASE_FORCE_KEEP_NOTE);
backup = todo_add (backup_mesg, backup_id, backup_note);
hilt = todo_get_position (backup);
}
} }
/* Edit the description of an already existing todo item. */ /* Edit the description of an already existing todo item. */
void void
todo_edit_item(void) todo_edit_item (void)
{ {
struct todo_s *i; struct todo_s *i;
char *mesg = _("Enter the new ToDo description :"); char *mesg = _("Enter the new ToDo description :");
status_mesg(mesg, ""); status_mesg (mesg, "");
i = todo_get_item(hilt); i = todo_get_item (hilt);
updatestring(win[STA].p, &i->mesg, 0, 1); updatestring (win[STA].p, &i->mesg, 0, 1);
} }
/* Display todo items in the corresponding panel. */ /* Display todo items in the corresponding panel. */
static void static void
display_todo_item(int incolor, char *msg, int prio, int note, int len, int y, display_todo_item (int incolor, char *msg, int prio, int note, int len, int y,
int x) int x)
{ {
WINDOW *w; WINDOW *w;
int ch_note; int ch_note;
char buf[len]; char buf[len];
w = win[TOD].p; w = win[TOD].p;
ch_note = (note) ? '>' : '.'; ch_note = (note) ? '>' : '.';
if (incolor == 0) if (incolor == 0)
custom_apply_attr(w, ATTR_HIGHEST); custom_apply_attr (w, ATTR_HIGHEST);
if (strlen(msg) < len) if (strlen (msg) < len)
mvwprintw(w, y, x, "%d%c %s", prio, ch_note, msg); mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
else { else
strncpy(buf, msg, len - 1); {
buf[len - 1] = '\0'; strncpy (buf, msg, len - 1);
mvwprintw(w, y, x, "%d%c %s...", prio, ch_note, buf); buf[len - 1] = '\0';
} mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
if (incolor == 0) }
custom_remove_attr(w, ATTR_HIGHEST); if (incolor == 0)
custom_remove_attr (w, ATTR_HIGHEST);
} }
/* Updates the ToDo panel. */ /* Updates the ToDo panel. */
void void
todo_update_panel(window_t *wintod, int which_pan) todo_update_panel (window_t *wintod, int which_pan)
{ {
struct todo_s *i; struct todo_s *i;
int len = wintod->w - 8; int len = wintod->w - 8;
int num_todo = 0; int num_todo = 0;
int y_offset = 3, x_offset = 1; int y_offset = 3, x_offset = 1;
int t_realpos = -1; int t_realpos = -1;
int title_lines = 3; int title_lines = 3;
int todo_lines = 1; int todo_lines = 1;
int max_items = wintod->h - 4; int max_items = wintod->h - 4;
int incolor = -1; int incolor = -1;
/* Print todo item in the panel. */ /* Print todo item in the panel. */
erase_window_part(win[TOD].p, 1, title_lines, wintod->w - 2, erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
wintod->h - 2); for (i = todolist; i != 0; i = i->next)
for (i = todolist; i != 0; i = i->next) { {
num_todo++; num_todo++;
t_realpos = num_todo - first; t_realpos = num_todo - first;
incolor = num_todo - hilt; incolor = num_todo - hilt;
if (incolor == 0) if (incolor == 0)
msgsav = i->mesg; msgsav = i->mesg;
if (t_realpos >= 0 && t_realpos < max_items) { if (t_realpos >= 0 && t_realpos < max_items)
display_todo_item(incolor, i->mesg, i->id, {
(i->note != NULL) ? 1 : 0, len, y_offset, x_offset); display_todo_item (incolor, i->mesg, i->id,
y_offset = y_offset + todo_lines; (i->note != NULL) ? 1 : 0, len, y_offset,
} x_offset);
y_offset = y_offset + todo_lines;
} }
}
/* Draw the scrollbar if necessary. */ /* Draw the scrollbar if necessary. */
if (todos > max_items){ if (todos > max_items)
float ratio = ((float) max_items) / ((float) todos); {
int sbar_length = (int) (ratio * (max_items + 1)); float ratio = ((float) max_items) / ((float) todos);
int highend = (int) (ratio * first); int sbar_length = (int) (ratio * (max_items + 1));
bool hilt_bar = (which_pan == TOD) ? true : false; int highend = (int) (ratio * first);
int sbar_top = highend + title_lines; bool hilt_bar = (which_pan == TOD) ? true : false;
int sbar_top = highend + title_lines;
if ((sbar_top + sbar_length) > wintod->h - 1) if ((sbar_top + sbar_length) > wintod->h - 1)
sbar_length = wintod->h - 1 - sbar_top; sbar_length = wintod->h - 1 - sbar_top;
draw_scrollbar(win[TOD].p, sbar_top, wintod->w - 2, draw_scrollbar (win[TOD].p, sbar_top, wintod->w - 2,
sbar_length, title_lines, wintod->h - 1, hilt_bar); sbar_length, title_lines, wintod->h - 1, hilt_bar);
} }
wnoutrefresh(win[TOD].p); wnoutrefresh (win[TOD].p);
} }
/* Attach a note to a todo */ /* Attach a note to a todo */
void void
todo_edit_note(char *editor) todo_edit_note (char *editor)
{ {
struct todo_s *i; struct todo_s *i;
char fullname[BUFSIZ]; char fullname[BUFSIZ];
char *filename; char *filename;
i = todo_get_item(hilt); i = todo_get_item (hilt);
if (i->note == NULL) { if (i->note == NULL)
if ((filename = new_tempfile(path_notes, NOTESIZ)) {
!= NULL) if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
i->note = filename; i->note = filename;
else else
return; return;
} }
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external(fullname, editor); wins_launch_external (fullname, editor);
} }
/* View a note previously attached to a todo */ /* View a note previously attached to a todo */
void void
todo_view_note(char *pager) todo_view_note (char *pager)
{ {
struct todo_s *i; struct todo_s *i;
char fullname[BUFSIZ]; char fullname[BUFSIZ];
i = todo_get_item(hilt); i = todo_get_item (hilt);
if (i->note == NULL) if (i->note == NULL)
return; return;
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note); snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
wins_launch_external(fullname, pager); wins_launch_external (fullname, pager);
} }
+27 -26
View File
@@ -1,8 +1,8 @@
/* $calcurse: todo.h,v 1.10 2007/12/30 16:27:59 culot Exp $ */ /* $calcurse: todo.h,v 1.11 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2004-2007 Frederic Culot * Copyright (c) 2004-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -29,33 +29,34 @@
#include "wins.h" #include "wins.h"
struct todo_s { struct todo_s
struct todo_s *next; {
char *mesg; struct todo_s *next;
int id; char *mesg;
char *note; int id;
char *note;
}; };
extern struct todo_s *todolist; extern struct todo_s *todolist;
void todo_hilt_set(int); void todo_hilt_set (int);
void todo_hilt_decrease(void); void todo_hilt_decrease (void);
void todo_hilt_increase(void); void todo_hilt_increase (void);
int todo_hilt(void); int todo_hilt (void);
int todo_nb(void); int todo_nb (void);
void todo_set_nb(int); void todo_set_nb (int);
void todo_set_first(int); void todo_set_first (int);
void todo_first_increase(void); void todo_first_increase (void);
void todo_first_decrease(void); void todo_first_decrease (void);
int todo_hilt_pos(void); int todo_hilt_pos (void);
char *todo_saved_mesg(void); char *todo_saved_mesg (void);
void todo_new_item(void); void todo_new_item (void);
struct todo_s *todo_add(char *, int, char *); struct todo_s *todo_add (char *, int, char *);
void todo_delete(conf_t *); void todo_delete (conf_t *);
void todo_chg_priority(int); void todo_chg_priority (int);
void todo_edit_item(void); void todo_edit_item (void);
void todo_update_panel(window_t *, int); void todo_update_panel (window_t *, int);
void todo_edit_note(char *); void todo_edit_note (char *);
void todo_view_note(char *); void todo_view_note (char *);
#endif /* CALCURSE_TODO_H */ #endif /* CALCURSE_TODO_H */
+640 -602
View File
File diff suppressed because it is too large Load Diff
+65 -59
View File
@@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.28 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: utils.h,v 1.29 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -36,70 +36,76 @@
((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \ ((e) ? (void)0 : aerror(__FILE__, __LINE__, #e)); \
} while (0) } while (0)
#define SPC 32 /* ASCII code for white space */ #define SPC 32 /* ASCII code for white space */
#define NB_CAL_CMDS 16 /* number of commands while in cal view */ #define NB_CAL_CMDS 16 /* number of commands while in cal view */
#define NB_APP_CMDS 23 /* same thing while in appointment view */ #define NB_APP_CMDS 23 /* same thing while in appointment view */
#define NB_TOD_CMDS 22 /* same thing while in todo view */ #define NB_TOD_CMDS 22 /* same thing while in todo view */
#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS #define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */ #define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
#define CMDS_PER_LINE 6 /* max number of commands per line */ #define CMDS_PER_LINE 6 /* max number of commands per line */
#define KEY_LENGTH 4 /* length of each keybinding + one space */ #define KEY_LENGTH 4 /* length of each keybinding + one space */
#define LABEL_LENGTH 8 /* length of command description */ #define LABEL_LENGTH 8 /* length of command description */
#define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */ #define GETSTRING_VALID 0 /* value returned by getstring() if text is valid */
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */ #define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
#define GETSTRING_RET 2 /* return was pressed without entering any text */ #define GETSTRING_RET 2 /* return was pressed without entering any text */
typedef struct { /* structure defining a keybinding */ typedef struct
char *key; { /* structure defining a keybinding */
char *label; char *key;
} binding_t; char *label;
}
binding_t;
typedef enum { typedef enum
IERROR_FATAL, {
IERROR_WARN IERROR_FATAL,
} ierror_sev_e; IERROR_WARN
}
ierror_sev_e;
typedef enum { typedef enum
ERASE_DONT_FORCE, {
ERASE_FORCE, ERASE_DONT_FORCE,
ERASE_FORCE_KEEP_NOTE, ERASE_FORCE,
ERASE_FORCE_ONLY_NOTE ERASE_FORCE_KEEP_NOTE,
} erase_flag_e; ERASE_FORCE_ONLY_NOTE
}
erase_flag_e;
void exit_calcurse(int); void exit_calcurse (int);
void ierror(const char *, ierror_sev_e); void ierror (const char *, ierror_sev_e);
void aerror(const char *, int, const char *); void aerror (const char *, int, const char *);
void status_mesg(char *, char *); void status_mesg (char *, char *);
void erase_status_bar(void); void erase_status_bar (void);
void erase_window_part(WINDOW *, int, int, int, int); void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup(int, int, int, int, char *); WINDOW *popup (int, int, int, int, char *);
void print_in_middle(WINDOW *, int, int, int, char *); void print_in_middle (WINDOW *, int, int, int, char *);
int getstring(WINDOW *, char *, int, int, int); int getstring (WINDOW *, char *, int, int, int);
int updatestring(WINDOW *, char **, int, int); int updatestring (WINDOW *, char **, int, int);
int is_all_digit(char *); int is_all_digit (char *);
void status_bar(void); void status_bar (void);
long date2sec(date_t, unsigned, unsigned); long date2sec (date_t, unsigned, unsigned);
char *date_sec2hour_str(long); char *date_sec2hour_str (long);
char *date_sec2date_str(long, char *); char *date_sec2date_str (long, char *);
void date_sec2ical_date(long, char *); void date_sec2ical_date (long, char *);
void date_sec2ical_datetime(long, char *); void date_sec2ical_datetime (long, char *);
long update_time_in_date(long, unsigned, unsigned); long update_time_in_date (long, unsigned, unsigned);
long get_sec_date(date_t); long get_sec_date (date_t);
long min2sec(unsigned); long min2sec (unsigned);
int check_time(char *); int check_time (char *);
void draw_scrollbar(WINDOW *, int, int, int, int, int, bool); void draw_scrollbar (WINDOW *, int, int, int, int, int, bool);
void item_in_popup(char *, char *, char *, char *); void item_in_popup (char *, char *, char *, char *);
void reset_status_page(void); void reset_status_page (void);
void other_status_page(int); void other_status_page (int);
long get_today(void); long get_today (void);
long now(void); long now (void);
char *mycpy(const char *); char *mycpy (const char *);
long mystrtol(const char *); long mystrtol (const char *);
void print_option_incolor(WINDOW *, bool, int, int); void print_option_incolor (WINDOW *, bool, int, int);
char *new_tempfile(const char *, int); char *new_tempfile (const char *, int);
void erase_note(char **, erase_flag_e); void erase_note (char **, erase_flag_e);
int parse_date(char *, int, int *, int *, int *); int parse_date (char *, int, int *, int *, int *);
#endif /* CALCURSE_UTILS_H */ #endif /* CALCURSE_UTILS_H */
+58 -57
View File
@@ -1,4 +1,4 @@
/* $calcurse: vars.c,v 1.7 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: vars.c,v 1.8 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -45,29 +45,31 @@ bool colorize = false;
* variables to store calendar names * variables to store calendar names
*/ */
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char *monthnames[12] = char *monthnames[12] = {
{ N_("January"), N_("January"),
N_("February"), N_("February"),
N_("March"), N_("March"),
N_("April"), N_("April"),
N_("May"), N_("May"),
N_("June"), N_("June"),
N_("July"), N_("July"),
N_("August"), N_("August"),
N_("September"), N_("September"),
N_("October"), N_("October"),
N_("November"), N_("November"),
N_("December") }; N_("December")
};
char *daynames[8] = char *daynames[8] = {
{ N_("Sun"), N_("Sun"),
N_("Mon"), N_("Mon"),
N_("Tue"), N_("Tue"),
N_("Wed"), N_("Wed"),
N_("Thu"), N_("Thu"),
N_("Fri"), N_("Fri"),
N_("Sat"), N_("Sat"),
N_("Sun") }; N_("Sun")
};
/* /*
* variables to store data path names, which are initialized in * variables to store data path names, which are initialized in
@@ -85,51 +87,50 @@ struct pad_s *apad;
/* Variable to store notify-bar settings. */ /* Variable to store notify-bar settings. */
struct nbar_s *nbar; struct nbar_s *nbar;
/* /*
* Variables init * Variables init
*/ */
void void
vars_init(conf_t *conf) vars_init (conf_t *conf)
{ {
char *PATH_VI = "/usr/bin/vi"; char *PATH_VI = "/usr/bin/vi";
char *PATH_LESS = "/usr/bin/less"; char *PATH_LESS = "/usr/bin/less";
char *ed, *pg; char *ed, *pg;
/* Variables for user configuration */ /* Variables for user configuration */
conf->confirm_quit = true; conf->confirm_quit = true;
conf->confirm_delete = true; conf->confirm_delete = true;
conf->auto_save = true; conf->auto_save = true;
conf->skip_system_dialogs = false; conf->skip_system_dialogs = false;
conf->skip_progress_bar = false; conf->skip_progress_bar = false;
strncpy(conf->output_datefmt, "%D", 3); strncpy (conf->output_datefmt, "%D", 3);
conf->input_datefmt = 1; conf->input_datefmt = 1;
/* Default external editor and pager */ /* Default external editor and pager */
ed = getenv("VISUAL"); ed = getenv ("VISUAL");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = getenv("EDITOR"); ed = getenv ("EDITOR");
if (ed == NULL || ed[0] == '\0') if (ed == NULL || ed[0] == '\0')
ed = PATH_VI; ed = PATH_VI;
conf->editor = ed; conf->editor = ed;
pg = getenv("PAGER"); pg = getenv ("PAGER");
if (pg == NULL || pg[0] == '\0') if (pg == NULL || pg[0] == '\0')
pg = PATH_LESS; pg = PATH_LESS;
conf->pager = pg; conf->pager = pg;
wins_set_layout(1); wins_set_layout (1);
calendar_set_first_day_of_week(MONDAY); calendar_set_first_day_of_week (MONDAY);
/* Pad structure to scroll text inside the appointment panel */ /* Pad structure to scroll text inside the appointment panel */
apad = (struct pad_s *) malloc(sizeof(struct pad_s)); apad = (struct pad_s *) malloc (sizeof (struct pad_s));
apad->length = 1; apad->length = 1;
apad->first_onscreen = 0; apad->first_onscreen = 0;
/* Attribute definitions for color and non-color terminals */ /* Attribute definitions for color and non-color terminals */
custom_init_attr(); custom_init_attr ();
/* Start at the current date */ /* Start at the current date */
calendar_init_slctd_day(); calendar_init_slctd_day ();
} }
+43 -39
View File
@@ -1,4 +1,4 @@
/* $calcurse: vars.h,v 1.21 2008/04/09 20:38:29 culot Exp $ */ /* $calcurse: vars.h,v 1.22 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@@ -61,50 +61,54 @@
#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \ #define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
(datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd"))) (datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
struct pad_s { struct pad_s
int width; {
int length; int width;
int first_onscreen; /* first line to be displayed inside window */ int length;
WINDOW *ptrwin; /* pointer to the pad window */ int first_onscreen; /* first line to be displayed inside window */
WINDOW *ptrwin; /* pointer to the pad window */
}; };
struct nbar_s { struct nbar_s
int show; /* display or hide the notify-bar */ {
int cntdwn; /* warn when time left before next app int show; /* display or hide the notify-bar */
* becomes lesser than cntdwn */ int cntdwn; /* warn when time left before next app
char datefmt[BUFSIZ]; /* format for displaying date */ * becomes lesser than cntdwn */
char timefmt[BUFSIZ]; /* format for displaying time */ char datefmt[BUFSIZ]; /* format for displaying date */
char cmd[BUFSIZ]; /* notification command */ char timefmt[BUFSIZ]; /* format for displaying time */
char *shell; /* user shell to launch notif. cmd */ char cmd[BUFSIZ]; /* notification command */
pthread_mutex_t mutex; char *shell; /* user shell to launch notif. cmd */
pthread_mutex_t mutex;
}; };
/* General configuration variables */ /* General configuration variables */
typedef struct { typedef struct
bool auto_save; {
bool confirm_quit; bool auto_save;
bool confirm_delete; bool confirm_quit;
bool skip_system_dialogs; bool confirm_delete;
bool skip_progress_bar; bool skip_system_dialogs;
char *editor; bool skip_progress_bar;
char *pager; char *editor;
char output_datefmt[BUFSIZ]; /* format for displaying date */ char *pager;
int input_datefmt; /* format for reading date */ char output_datefmt[BUFSIZ]; /* format for displaying date */
} conf_t; int input_datefmt; /* format for reading date */
}
conf_t;
extern int col, row; extern int col, row;
extern bool colorize; extern bool colorize;
extern int days[12]; extern int days[12];
extern char *monthnames[12]; extern char *monthnames[12];
extern char *daynames[8]; extern char *daynames[8];
extern char path_dir[BUFSIZ]; extern char path_dir[BUFSIZ];
extern char path_todo[BUFSIZ]; extern char path_todo[BUFSIZ];
extern char path_apts[BUFSIZ]; extern char path_apts[BUFSIZ];
extern char path_conf[BUFSIZ]; extern char path_conf[BUFSIZ];
extern char path_notes[BUFSIZ]; extern char path_notes[BUFSIZ];
extern struct pad_s *apad; extern struct pad_s *apad;
extern struct nbar_s *nbar; extern struct nbar_s *nbar;
void vars_init(conf_t *conf); void vars_init (conf_t *conf);
#endif /* CALCURSE_VARS_H */ #endif /* CALCURSE_VARS_H */
+271 -256
View File
@@ -1,8 +1,8 @@
/* $calcurse: wins.c,v 1.12 2008/02/14 20:20:23 culot Exp $ */ /* $calcurse: wins.c,v 1.13 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot * Copyright (c) 2007-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -37,85 +37,85 @@
/* Variables to handle calcurse windows. */ /* Variables to handle calcurse windows. */
window_t win[NBWINS]; window_t win[NBWINS];
static window_e slctd_win; static window_e slctd_win;
static int layout; static int layout;
/* Get the current layout. */ /* Get the current layout. */
int int
wins_layout(void) wins_layout (void)
{ {
return (layout); return (layout);
} }
/* Set the current layout. */ /* Set the current layout. */
void void
wins_set_layout(int nb) wins_set_layout (int nb)
{ {
layout = nb; layout = nb;
} }
/* Initialize the selected window in calcurse's interface. */ /* Initialize the selected window in calcurse's interface. */
void void
wins_slctd_init(void) wins_slctd_init (void)
{ {
wins_slctd_set(CAL); wins_slctd_set (CAL);
} }
/* Returns an enum which corresponds to the window which is selected. */ /* Returns an enum which corresponds to the window which is selected. */
window_e window_e
wins_slctd(void) wins_slctd (void)
{ {
return (slctd_win); return (slctd_win);
} }
/* Sets the selected window. */ /* Sets the selected window. */
void void
wins_slctd_set(window_e window) wins_slctd_set (window_e window)
{ {
slctd_win = window; slctd_win = window;
} }
/* TAB key was hit in the interface, need to select next window. */ /* TAB key was hit in the interface, need to select next window. */
void void
wins_slctd_next(void) wins_slctd_next (void)
{ {
if (slctd_win == TOD) if (slctd_win == TOD)
slctd_win = CAL; slctd_win = CAL;
else else
slctd_win++; slctd_win++;
} }
/* Create all the windows. */ /* Create all the windows. */
void void
wins_init(void) wins_init (void)
{ {
char label[BUFSIZ]; char label[BUFSIZ];
/* /*
* Create the three main windows plus the status bar and the pad used to * Create the three main windows plus the status bar and the pad used to
* display appointments and event. * display appointments and event.
*/ */
win[CAL].p = newwin(CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x); win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
snprintf(label, BUFSIZ, _("Calendar")); snprintf (label, BUFSIZ, _("Calendar"));
wins_show(win[CAL].p, label); wins_show (win[CAL].p, label);
win[APP].p = newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x); win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x);
snprintf(label, BUFSIZ, _("Appointments")); snprintf (label, BUFSIZ, _("Appointments"));
wins_show(win[APP].p, label); wins_show (win[APP].p, label);
apad->width = win[APP].w - 3; apad->width = win[APP].w - 3;
apad->ptrwin = newpad(apad->length, apad->width); apad->ptrwin = newpad (apad->length, apad->width);
win[TOD].p = newwin(win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x); win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
snprintf(label, BUFSIZ, _("ToDo")); snprintf (label, BUFSIZ, _("ToDo"));
wins_show(win[TOD].p, label); wins_show (win[TOD].p, label);
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x); win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
/* Enable function keys (i.e. arrow keys) in those windows */ /* Enable function keys (i.e. arrow keys) in those windows */
keypad(win[CAL].p, TRUE); keypad (win[CAL].p, TRUE);
keypad(win[APP].p, TRUE); keypad (win[APP].p, TRUE);
keypad(win[TOD].p, TRUE); keypad (win[TOD].p, TRUE);
keypad(win[STA].p, TRUE); keypad (win[STA].p, TRUE);
} }
/* /*
@@ -123,191 +123,204 @@ wins_init(void)
* size and placement. * size and placement.
*/ */
void void
wins_reinit(void) wins_reinit (void)
{ {
delwin(win[STA].p); delwin (win[STA].p);
delwin(win[CAL].p); delwin (win[CAL].p);
delwin(win[APP].p); delwin (win[APP].p);
delwin(apad->ptrwin); delwin (apad->ptrwin);
delwin(win[TOD].p); delwin (win[TOD].p);
wins_get_config(); wins_get_config ();
wins_init(); wins_init ();
if (notify_bar()) if (notify_bar ())
notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y, notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
win[NOT].x);
} }
/* Show the window with a border and a label. */ /* Show the window with a border and a label. */
void void
wins_show(WINDOW * win, char *label) wins_show (WINDOW *win, char *label)
{ {
int startx, starty, height, width; int startx, starty, height, width;
getbegyx(win, starty, startx); getbegyx (win, starty, startx);
getmaxyx(win, height, width); getmaxyx (win, height, width);
box(win, 0, 0); box (win, 0, 0);
mvwaddch(win, 2, 0, ACS_LTEE); mvwaddch (win, 2, 0, ACS_LTEE);
mvwhline(win, 2, 1, ACS_HLINE, width - 2); mvwhline (win, 2, 1, ACS_HLINE, width - 2);
mvwaddch(win, 2, width - 1, ACS_RTEE); mvwaddch (win, 2, width - 1, ACS_RTEE);
print_in_middle(win, 1, 0, width, label); print_in_middle (win, 1, 0, width, label);
} }
/* /*
* Get the screen size and recalculate the windows configurations. * Get the screen size and recalculate the windows configurations.
*/ */
void void
wins_get_config(void) wins_get_config (void)
{ {
/* Get the screen configuration */ /* Get the screen configuration */
getmaxyx(stdscr, row, col); getmaxyx (stdscr, row, col);
/* fixed values for status, notification bars and calendar */ /* fixed values for status, notification bars and calendar */
win[STA].h = STATUSHEIGHT; win[STA].h = STATUSHEIGHT;
win[STA].w = col; win[STA].w = col;
win[STA].y = row - win[STA].h; win[STA].y = row - win[STA].h;
win[STA].x = 0; win[STA].x = 0;
if (notify_bar()) { if (notify_bar ())
win[NOT].h = 1; {
win[NOT].w = col; win[NOT].h = 1;
win[NOT].y = win[STA].y - 1; win[NOT].w = col;
win[NOT].x = 0; win[NOT].y = win[STA].y - 1;
} else { win[NOT].x = 0;
win[NOT].h = 0; }
win[NOT].w = 0; else
win[NOT].y = 0; {
win[NOT].x = 0; win[NOT].h = 0;
} win[NOT].w = 0;
win[NOT].y = 0;
win[NOT].x = 0;
}
if (layout <= 4) { /* APPOINTMENT is the biggest panel */ if (layout <= 4)
win[APP].w = col - CALWIDTH; { /* APPOINTMENT is the biggest panel */
win[APP].h = row - (win[STA].h + win[NOT].h); win[APP].w = col - CALWIDTH;
win[TOD].w = CALWIDTH; win[APP].h = row - (win[STA].h + win[NOT].h);
win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h); win[TOD].w = CALWIDTH;
} else { /* TODO is the biggest panel */ win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
win[TOD].w = col - CALWIDTH; }
win[TOD].h = row - (win[STA].h + win[NOT].h); else
win[APP].w = CALWIDTH; { /* TODO is the biggest panel */
win[APP].h = row - (CALHEIGHT + win[STA].h + win[NOT].h); win[TOD].w = col - CALWIDTH;
} win[TOD].h = row - (win[STA].h + win[NOT].h);
win[APP].w = CALWIDTH;
win[APP].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
}
/* defining the layout */ /* defining the layout */
switch (layout) { switch (layout)
case 1: {
win[APP].y = 0; case 1:
win[APP].x = 0; win[APP].y = 0;
win[CAL].y = 0; win[APP].x = 0;
win[TOD].x = win[APP].w; win[CAL].y = 0;
win[TOD].y = CALHEIGHT; win[TOD].x = win[APP].w;
win[CAL].x = win[APP].w; win[TOD].y = CALHEIGHT;
break; win[CAL].x = win[APP].w;
case 2: break;
win[APP].y = 0; case 2:
win[APP].x = 0; win[APP].y = 0;
win[TOD].y = 0; win[APP].x = 0;
win[TOD].x = win[APP].w; win[TOD].y = 0;
win[CAL].x = win[APP].w; win[TOD].x = win[APP].w;
win[CAL].y = win[TOD].h; win[CAL].x = win[APP].w;
break; win[CAL].y = win[TOD].h;
case 3: break;
win[APP].y = 0; case 3:
win[TOD].x = 0; win[APP].y = 0;
win[CAL].x = 0; win[TOD].x = 0;
win[CAL].y = 0; win[CAL].x = 0;
win[APP].x = CALWIDTH; win[CAL].y = 0;
win[TOD].y = CALHEIGHT; win[APP].x = CALWIDTH;
break; win[TOD].y = CALHEIGHT;
case 4: break;
win[APP].y = 0; case 4:
win[TOD].x = 0; win[APP].y = 0;
win[TOD].y = 0; win[TOD].x = 0;
win[CAL].x = 0; win[TOD].y = 0;
win[APP].x = CALWIDTH; win[CAL].x = 0;
win[CAL].y = win[TOD].h; win[APP].x = CALWIDTH;
break; win[CAL].y = win[TOD].h;
case 5: break;
win[TOD].y = 0; case 5:
win[TOD].x = 0; win[TOD].y = 0;
win[CAL].y = 0; win[TOD].x = 0;
win[APP].y = CALHEIGHT; win[CAL].y = 0;
win[APP].x = win[TOD].w; win[APP].y = CALHEIGHT;
win[CAL].x = win[TOD].w; win[APP].x = win[TOD].w;
break; win[CAL].x = win[TOD].w;
case 6: break;
win[TOD].y = 0; case 6:
win[TOD].x = 0; win[TOD].y = 0;
win[APP].y = 0; win[TOD].x = 0;
win[APP].x = win[TOD].w; win[APP].y = 0;
win[CAL].x = win[TOD].w; win[APP].x = win[TOD].w;
win[CAL].y = win[APP].h; win[CAL].x = win[TOD].w;
break; win[CAL].y = win[APP].h;
case 7: break;
win[TOD].y = 0; case 7:
win[APP].x = 0; win[TOD].y = 0;
win[CAL].x = 0; win[APP].x = 0;
win[CAL].y = 0; win[CAL].x = 0;
win[TOD].x = CALWIDTH; win[CAL].y = 0;
win[APP].y = CALHEIGHT; win[TOD].x = CALWIDTH;
break; win[APP].y = CALHEIGHT;
case 8: break;
win[TOD].y = 0; case 8:
win[APP].x = 0; win[TOD].y = 0;
win[CAL].x = 0; win[APP].x = 0;
win[APP].y = 0; win[CAL].x = 0;
win[TOD].x = CALWIDTH; win[APP].y = 0;
win[CAL].y = win[APP].h; win[TOD].x = CALWIDTH;
break; win[CAL].y = win[APP].h;
} break;
}
} }
/* draw panel border in color */ /* draw panel border in color */
static void static void
border_color(WINDOW *window) border_color (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_BOLD; int no_color_attr = A_BOLD;
if (colorize) { if (colorize)
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); {
box(window, 0, 0); wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
} else { box (window, 0, 0);
wattron(window, no_color_attr); }
box(window, 0, 0); else
} {
wattron (window, no_color_attr);
if (colorize) { box (window, 0, 0);
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM)); }
} else { if (colorize)
wattroff(window, no_color_attr); {
} wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
}
wnoutrefresh(window); else
{
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
/* draw panel border without any color */ /* draw panel border without any color */
static void static void
border_nocolor(WINDOW *window) border_nocolor (WINDOW *window)
{ {
int color_attr = A_BOLD; int color_attr = A_BOLD;
int no_color_attr = A_DIM; int no_color_attr = A_DIM;
if (colorize) { if (colorize)
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); {
} else { wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
wattron(window, no_color_attr); }
} else
{
box(window, 0, 0); wattron (window, no_color_attr);
}
if (colorize) { box (window, 0, 0);
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT)); if (colorize)
} else { {
wattroff(window, no_color_attr); wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
} }
else
wnoutrefresh(window); {
wattroff (window, no_color_attr);
}
wnoutrefresh (window);
} }
/* /*
@@ -315,53 +328,53 @@ border_nocolor(WINDOW *window)
* selected window. * selected window.
*/ */
void void
wins_update(void) wins_update (void)
{ {
switch (slctd_win) { switch (slctd_win)
{
case CAL:
border_color (win[CAL].p);
border_nocolor (win[APP].p);
border_nocolor (win[TOD].p);
break;
case CAL: case APP:
border_color(win[CAL].p); border_color (win[APP].p);
border_nocolor(win[APP].p); border_nocolor (win[CAL].p);
border_nocolor(win[TOD].p); border_nocolor (win[TOD].p);
break; break;
case APP: case TOD:
border_color(win[APP].p); border_color (win[TOD].p);
border_nocolor(win[CAL].p); border_nocolor (win[APP].p);
border_nocolor(win[TOD].p); border_nocolor (win[CAL].p);
break; break;
case TOD: default:
border_color(win[TOD].p); ierror (_("FATAL ERROR in wins_update: no window selected\n"),
border_nocolor(win[APP].p); IERROR_FATAL);
border_nocolor(win[CAL].p); /* NOTREACHED */
break; }
default: apoint_update_panel (&win[APP], slctd_win);
ierror(_("FATAL ERROR in wins_update: no window selected\n"), todo_update_panel (&win[TOD], slctd_win);
IERROR_FATAL); calendar_update_panel (win[CAL].p);
/* NOTREACHED */ status_bar ();
} if (notify_bar ())
notify_update_bar ();
apoint_update_panel(&win[APP], slctd_win); wmove (win[STA].p, 0, 0);
todo_update_panel(&win[TOD], slctd_win); doupdate ();
calendar_update_panel(win[CAL].p);
status_bar();
if (notify_bar())
notify_update_bar();
wmove(win[STA].p, 0, 0);
doupdate();
} }
/* Reset the screen, needed when resizing terminal for example. */ /* Reset the screen, needed when resizing terminal for example. */
void void
wins_reset(void) wins_reset (void)
{ {
endwin(); endwin ();
refresh(); refresh ();
curs_set(0); curs_set (0);
wins_reinit(); wins_reinit ();
wins_update(); wins_update ();
} }
/* /*
@@ -369,30 +382,32 @@ wins_reset(void)
* file. * file.
*/ */
void void
wins_launch_external(const char *file, const char *cmd) wins_launch_external (const char *file, const char *cmd)
{ {
char *p; char *p;
int len; int len;
len = strlen(file) + strlen(cmd) + 2; /* Beware of space between cmd and /* Beware of space between cmd and file. */
file. */ len = strlen (file) + strlen (cmd) + 2;
p = (char *)malloc(sizeof(char) * len);
if (snprintf(p, len, "%s %s", cmd, file) == -1) { p = (char *) malloc (sizeof (char) * len);
free(p); if (snprintf (p, len, "%s %s", cmd, file) == -1)
return; {
} free (p);
if (notify_bar()) return;
notify_stop_main_thread(); }
def_prog_mode(); if (notify_bar ())
endwin(); notify_stop_main_thread ();
clear(); def_prog_mode ();
refresh(); endwin ();
system(p); clear ();
reset_prog_mode(); refresh ();
clearok(curscr, TRUE); system (p);
curs_set(0); reset_prog_mode ();
refresh(); clearok (curscr, TRUE);
if (notify_bar()) curs_set (0);
notify_start_main_thread(); refresh ();
free(p); if (notify_bar ())
notify_start_main_thread ();
free (p);
} }
+35 -31
View File
@@ -1,8 +1,8 @@
/* $calcurse: wins.h,v 1.6 2008/02/14 20:20:23 culot Exp $ */ /* $calcurse: wins.h,v 1.7 2008/04/12 21:14:03 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
* Copyright (c) 2007 Frederic Culot * Copyright (c) 2007-2008 Frederic Culot
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -29,38 +29,42 @@
#include "vars.h" #include "vars.h"
typedef enum { typedef enum
CAL, {
APP, CAL,
TOD, APP,
NOT, TOD,
STA, NOT,
NBWINS STA,
} window_e; NBWINS
}
window_e;
/* Window properties */ /* Window properties */
typedef struct { typedef struct
WINDOW *p; /* pointer to window */ {
unsigned w; /* width */ WINDOW *p; /* pointer to window */
unsigned h; /* height */ unsigned w; /* width */
int x; /* x position */ unsigned h; /* height */
int y; /* y position */ int x; /* x position */
} window_t; int y; /* y position */
}
window_t;
extern window_t win[NBWINS]; extern window_t win[NBWINS];
int wins_layout(void); int wins_layout (void);
void wins_set_layout(int); void wins_set_layout (int);
void wins_slctd_init(void); void wins_slctd_init (void);
window_e wins_slctd(void); window_e wins_slctd (void);
void wins_slctd_set(window_e); void wins_slctd_set (window_e);
void wins_slctd_next(void); void wins_slctd_next (void);
void wins_init(void); void wins_init (void);
void wins_reinit(void); void wins_reinit (void);
void wins_show(WINDOW *, char *); void wins_show (WINDOW *, char *);
void wins_get_config(void); void wins_get_config (void);
void wins_update(void); void wins_update (void);
void wins_reset(void); void wins_reset (void);
void wins_launch_external(const char *, const char *); void wins_launch_external (const char *, const char *);
#endif /* CALCURSE_WINS_H */ #endif /* CALCURSE_WINS_H */