Yet another style for source code. GNU style now used (I am fed up with tabs...)
This commit is contained in:
parent
0c281d2c1e
commit
efd782699b
@ -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:
|
||||
Tony's patch concerning date format configuration imported, many
|
||||
thanks to him
|
||||
|
496
src/apoint.c
496
src/apoint.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: apoint.c,v 1.21 2008/01/20 10:45:38 culot Exp $ */
|
||||
/* $calcurse: apoint.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -43,67 +43,69 @@ apoint_llist_t *alist_p;
|
||||
static int hilt = 0;
|
||||
|
||||
int
|
||||
apoint_llist_init(void)
|
||||
apoint_llist_init (void)
|
||||
{
|
||||
alist_p = (apoint_llist_t *) malloc(sizeof(apoint_llist_t));
|
||||
alist_p = (apoint_llist_t *) malloc (sizeof (apoint_llist_t));
|
||||
alist_p->root = NULL;
|
||||
pthread_mutex_init(&(alist_p->mutex), NULL);
|
||||
pthread_mutex_init (&(alist_p->mutex), NULL);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Sets which appointment is highlighted. */
|
||||
void
|
||||
apoint_hilt_set(int highlighted)
|
||||
apoint_hilt_set (int highlighted)
|
||||
{
|
||||
hilt = highlighted;
|
||||
}
|
||||
|
||||
void
|
||||
apoint_hilt_decrease(void)
|
||||
apoint_hilt_decrease (void)
|
||||
{
|
||||
hilt--;
|
||||
}
|
||||
|
||||
void
|
||||
apoint_hilt_increase(void)
|
||||
apoint_hilt_increase (void)
|
||||
{
|
||||
hilt++;
|
||||
}
|
||||
|
||||
/* Return which appointment is highlighted. */
|
||||
int
|
||||
apoint_hilt(void)
|
||||
apoint_hilt (void)
|
||||
{
|
||||
return (hilt);
|
||||
}
|
||||
|
||||
apoint_llist_node_t *
|
||||
apoint_new(char *mesg, char *note, long start, long dur, char state)
|
||||
apoint_new (char *mesg, char *note, long start, long dur, char state)
|
||||
{
|
||||
apoint_llist_node_t *o, **i;
|
||||
|
||||
o = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
|
||||
o->mesg = (char *) malloc(strlen(mesg) + 1);
|
||||
strncpy(o->mesg, mesg, strlen(mesg) + 1);
|
||||
o->note = (note != NULL) ? strdup(note) : NULL;
|
||||
o = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
|
||||
o->mesg = (char *) malloc (strlen (mesg) + 1);
|
||||
strncpy (o->mesg, mesg, strlen (mesg) + 1);
|
||||
o->note = (note != NULL) ? strdup (note) : NULL;
|
||||
o->state = state;
|
||||
o->start = start;
|
||||
o->dur = dur;
|
||||
|
||||
pthread_mutex_lock(&(alist_p->mutex));
|
||||
pthread_mutex_lock (&(alist_p->mutex));
|
||||
i = &alist_p->root;
|
||||
for (;;) {
|
||||
if (*i == 0 || (*i)->start > start) {
|
||||
for (;;)
|
||||
{
|
||||
if (*i == 0 || (*i)->start > start)
|
||||
{
|
||||
o->next = *i;
|
||||
*i = o;
|
||||
break;
|
||||
}
|
||||
i = &(*i)->next;
|
||||
}
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
|
||||
return o;
|
||||
return (o);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -111,14 +113,19 @@ apoint_new(char *mesg, char *note, long start, long dur, char state)
|
||||
* depending if the start time is entered or not.
|
||||
*/
|
||||
void
|
||||
apoint_add(void)
|
||||
apoint_add (void)
|
||||
{
|
||||
#define LTIME 6
|
||||
char *mesg_1 = _("Enter start time ([hh:mm] or [h:mm]), leave blank for an all-day event : ");
|
||||
char *mesg_2 = _("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
|
||||
char *mesg_1 =
|
||||
_("Enter start time ([hh:mm] or [h:mm]), "
|
||||
"leave blank for an all-day event : ");
|
||||
char *mesg_2 =
|
||||
_("Enter end time ([hh:mm] or [h:mm]) or duration (in minutes) : ");
|
||||
char *mesg_3 = _("Enter description :");
|
||||
char *format_message_1 = _("You entered an invalid start time, should be [h:mm] or [hh:mm]");
|
||||
char *format_message_2 = _("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
|
||||
char *format_message_1 =
|
||||
_("You entered an invalid start time, should be [h:mm] or [hh:mm]");
|
||||
char *format_message_2 =
|
||||
_("You entered an invalid end time, should be [h:mm] or [hh:mm] or [mm]");
|
||||
char *enter_str = _("Press [Enter] to continue");
|
||||
int Id = 1;
|
||||
char item_time[LTIME] = "";
|
||||
@ -131,19 +138,25 @@ apoint_add(void)
|
||||
int is_appointment = 1;
|
||||
|
||||
/* Get the starting time */
|
||||
while (check_time(item_time) != 1) {
|
||||
status_mesg(mesg_1, "");
|
||||
if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
|
||||
GETSTRING_ESC) {
|
||||
if (strlen(item_time) == 0){
|
||||
while (check_time (item_time) != 1)
|
||||
{
|
||||
status_mesg (mesg_1, "");
|
||||
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_ESC)
|
||||
{
|
||||
if (strlen (item_time) == 0)
|
||||
{
|
||||
is_appointment = 0;
|
||||
break;
|
||||
} else if (check_time(item_time) != 1) {
|
||||
status_mesg(format_message_1, enter_str);
|
||||
wgetch(win[STA].p);
|
||||
} else
|
||||
sscanf(item_time, "%u:%u", &heures, &minutes);
|
||||
} else
|
||||
}
|
||||
else if (check_time (item_time) != 1)
|
||||
{
|
||||
status_mesg (format_message_1, enter_str);
|
||||
wgetch (win[STA].p);
|
||||
}
|
||||
else
|
||||
sscanf (item_time, "%u:%u", &heures, &minutes);
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
/*
|
||||
@ -151,65 +164,68 @@ apoint_add(void)
|
||||
* depending on the starting time, and record the
|
||||
* corresponding item.
|
||||
*/
|
||||
if (is_appointment){ /* Get the appointment duration */
|
||||
if (is_appointment)
|
||||
{ /* Get the appointment duration */
|
||||
item_time[0] = '\0';
|
||||
while (check_time(item_time) == 0) {
|
||||
status_mesg(mesg_2, "");
|
||||
if (getstring(win[STA].p, item_time, LTIME, 0, 1) !=
|
||||
GETSTRING_VALID)
|
||||
while (check_time (item_time) == 0)
|
||||
{
|
||||
status_mesg (mesg_2, "");
|
||||
if (getstring (win[STA].p, item_time, LTIME, 0, 1) != GETSTRING_VALID)
|
||||
return; //nothing entered, cancel adding of event
|
||||
else if (check_time(item_time) == 0) {
|
||||
status_mesg(format_message_2, enter_str);
|
||||
wgetch(win[STA].p);
|
||||
} else {
|
||||
if (check_time(item_time) == 2)
|
||||
apoint_duration = atoi(item_time);
|
||||
else if (check_time(item_time) == 1) {
|
||||
sscanf(item_time, "%u:%u",
|
||||
&end_h, &end_m);
|
||||
if (end_h < heures){
|
||||
apoint_duration =
|
||||
MININSEC - minutes + end_m
|
||||
+
|
||||
(24 + end_h - (heures + 1))
|
||||
* MININSEC;
|
||||
} else {
|
||||
apoint_duration =
|
||||
MININSEC - minutes +
|
||||
end_m +
|
||||
(end_h - (heures + 1)) *
|
||||
MININSEC;
|
||||
else if (check_time (item_time) == 0)
|
||||
{
|
||||
status_mesg (format_message_2, enter_str);
|
||||
wgetch (win[STA].p);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (check_time (item_time) == 2)
|
||||
apoint_duration = atoi (item_time);
|
||||
else if (check_time (item_time) == 1)
|
||||
{
|
||||
sscanf (item_time, "%u:%u", &end_h, &end_m);
|
||||
if (end_h < heures)
|
||||
{
|
||||
apoint_duration = MININSEC - minutes + end_m
|
||||
+ (24 + end_h - (heures + 1)) * MININSEC;
|
||||
}
|
||||
else
|
||||
{
|
||||
apoint_duration = MININSEC - minutes
|
||||
+ end_m + (end_h - (heures + 1)) * MININSEC;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else /* Insert the event Id */
|
||||
}
|
||||
else /* Insert the event Id */
|
||||
Id = 1;
|
||||
|
||||
status_mesg(mesg_3, "");
|
||||
if (getstring(win[STA].p, item_mesg, BUFSIZ, 0, 1) ==
|
||||
GETSTRING_VALID) {
|
||||
if (is_appointment) {
|
||||
apoint_start =
|
||||
date2sec(*calendar_get_slctd_day(), heures,
|
||||
minutes);
|
||||
apoint_pointeur = apoint_new(item_mesg, 0L, apoint_start,
|
||||
min2sec(apoint_duration), 0L);
|
||||
if (notify_bar())
|
||||
notify_check_added(item_mesg, apoint_start, 0L);
|
||||
} else
|
||||
event_pointeur = event_new(item_mesg, 0L,
|
||||
date2sec(*calendar_get_slctd_day(), 12, 0), Id);
|
||||
status_mesg (mesg_3, "");
|
||||
if (getstring (win[STA].p, item_mesg, BUFSIZ, 0, 1) == GETSTRING_VALID)
|
||||
{
|
||||
if (is_appointment)
|
||||
{
|
||||
apoint_start = date2sec (*calendar_get_slctd_day (), heures, minutes);
|
||||
apoint_pointeur = apoint_new (item_mesg, 0L, apoint_start,
|
||||
min2sec (apoint_duration), 0L);
|
||||
if (notify_bar ())
|
||||
notify_check_added (item_mesg, apoint_start, 0L);
|
||||
}
|
||||
else
|
||||
event_pointeur = event_new (item_mesg, 0L,
|
||||
date2sec (*calendar_get_slctd_day (), 12,
|
||||
0), Id);
|
||||
|
||||
if (hilt == 0)
|
||||
hilt++;
|
||||
}
|
||||
erase_status_bar();
|
||||
erase_status_bar ();
|
||||
}
|
||||
|
||||
/* Delete an item from the appointment list. */
|
||||
void
|
||||
apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
|
||||
apoint_delete (conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
|
||||
{
|
||||
char *choices = "[y/n] ";
|
||||
char *del_app_str = _("Do you really want to delete this item ?");
|
||||
@ -221,45 +237,50 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
|
||||
int answer = 0;
|
||||
int deleted_item_type = 0;
|
||||
|
||||
date = calendar_get_slctd_day_sec();
|
||||
date = calendar_get_slctd_day_sec ();
|
||||
|
||||
if (conf->confirm_delete) {
|
||||
status_mesg(del_app_str, choices);
|
||||
answer = wgetch(win[STA].p);
|
||||
if ( (answer == 'y') && (nb_items != 0) )
|
||||
if (conf->confirm_delete)
|
||||
{
|
||||
status_mesg (del_app_str, choices);
|
||||
answer = wgetch (win[STA].p);
|
||||
if ((answer == 'y') && (nb_items != 0))
|
||||
go_for_deletion = true;
|
||||
else {
|
||||
erase_status_bar();
|
||||
else
|
||||
{
|
||||
erase_status_bar ();
|
||||
return;
|
||||
}
|
||||
} else
|
||||
if (nb_items != 0)
|
||||
}
|
||||
else if (nb_items != 0)
|
||||
go_for_deletion = true;
|
||||
|
||||
if (go_for_deletion) {
|
||||
if (nb_items != 0) {
|
||||
deleted_item_type =
|
||||
day_erase_item(date, hilt, ERASE_DONT_FORCE);
|
||||
if (deleted_item_type == EVNT ||
|
||||
deleted_item_type == RECUR_EVNT) {
|
||||
if (go_for_deletion)
|
||||
{
|
||||
if (nb_items != 0)
|
||||
{
|
||||
deleted_item_type = day_erase_item (date, hilt, ERASE_DONT_FORCE);
|
||||
if (deleted_item_type == EVNT || deleted_item_type == RECUR_EVNT)
|
||||
{
|
||||
(*nb_events)--;
|
||||
to_be_removed = 1;
|
||||
} else if (deleted_item_type == APPT ||
|
||||
deleted_item_type == RECUR_APPT) {
|
||||
}
|
||||
else if (deleted_item_type == APPT || deleted_item_type == RECUR_APPT)
|
||||
{
|
||||
(*nb_apoints)--;
|
||||
to_be_removed = 3;
|
||||
} else if (deleted_item_type == 0) {
|
||||
}
|
||||
else if (deleted_item_type == 0)
|
||||
{
|
||||
to_be_removed = 0;
|
||||
} else
|
||||
ierror(errmsg, IERROR_FATAL);
|
||||
}
|
||||
else
|
||||
ierror (errmsg, IERROR_FATAL);
|
||||
/* NOTREACHED */
|
||||
|
||||
if (hilt > 1)
|
||||
hilt--;
|
||||
if (apad->first_onscreen >= to_be_removed)
|
||||
apad->first_onscreen =
|
||||
apad->first_onscreen -
|
||||
to_be_removed;
|
||||
apad->first_onscreen = apad->first_onscreen - to_be_removed;
|
||||
if (nb_items == 1)
|
||||
hilt = 0;
|
||||
}
|
||||
@ -267,82 +288,88 @@ apoint_delete(conf_t *conf, unsigned *nb_events, unsigned *nb_apoints)
|
||||
}
|
||||
|
||||
unsigned
|
||||
apoint_inday(apoint_llist_node_t *i, long start)
|
||||
apoint_inday (apoint_llist_node_t *i, long start)
|
||||
{
|
||||
if (i->start <= start + DAYINSEC && i->start + i->dur > start) {
|
||||
return 1;
|
||||
if (i->start <= start + DAYINSEC && i->start + i->dur > start)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
apoint_sec2str(apoint_llist_node_t *o, int type, long day, char *start,
|
||||
apoint_sec2str (apoint_llist_node_t *o, int type, long day, char *start,
|
||||
char *end)
|
||||
{
|
||||
struct tm *lt;
|
||||
time_t t;
|
||||
|
||||
if (o->start < day && type == APPT) {
|
||||
strncpy(start, "..:..", 6);
|
||||
} else {
|
||||
t = o->start;
|
||||
lt = localtime(&t);
|
||||
snprintf(start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
|
||||
lt->tm_min);
|
||||
if (o->start < day && type == APPT)
|
||||
{
|
||||
strncpy (start, "..:..", 6);
|
||||
}
|
||||
if (o->start + o->dur > day + DAYINSEC && type == APPT) {
|
||||
strncpy(end, "..:..", 6);
|
||||
} else {
|
||||
else
|
||||
{
|
||||
t = o->start;
|
||||
lt = localtime (&t);
|
||||
snprintf (start, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
|
||||
}
|
||||
if (o->start + o->dur > day + DAYINSEC && type == APPT)
|
||||
{
|
||||
strncpy (end, "..:..", 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
t = o->start + o->dur;
|
||||
lt = localtime(&t);
|
||||
snprintf(end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour,
|
||||
lt->tm_min);
|
||||
lt = localtime (&t);
|
||||
snprintf (end, HRMIN_SIZE, "%02u:%02u", lt->tm_hour, lt->tm_min);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
apoint_write(apoint_llist_node_t *o, FILE * f)
|
||||
apoint_write (apoint_llist_node_t *o, FILE *f)
|
||||
{
|
||||
struct tm *lt;
|
||||
time_t t;
|
||||
|
||||
t = o->start;
|
||||
lt = localtime(&t);
|
||||
fprintf(f, "%02u/%02u/%04u @ %02u:%02u",
|
||||
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
|
||||
lt->tm_hour, lt->tm_min);
|
||||
lt = localtime (&t);
|
||||
fprintf (f, "%02u/%02u/%04u @ %02u:%02u",
|
||||
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
|
||||
lt->tm_min);
|
||||
|
||||
t = o->start + o->dur;
|
||||
lt = localtime(&t);
|
||||
fprintf(f, " -> %02u/%02u/%04u @ %02u:%02u ",
|
||||
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year,
|
||||
lt->tm_hour, lt->tm_min);
|
||||
lt = localtime (&t);
|
||||
fprintf (f, " -> %02u/%02u/%04u @ %02u:%02u ",
|
||||
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, lt->tm_hour,
|
||||
lt->tm_min);
|
||||
|
||||
if (o->note != NULL)
|
||||
fprintf(f, ">%s ", o->note);
|
||||
fprintf (f, ">%s ", o->note);
|
||||
|
||||
if (o->state & APOINT_NOTIFY)
|
||||
fprintf(f, "!");
|
||||
fprintf (f, "!");
|
||||
else
|
||||
fprintf(f, "|");
|
||||
fprintf (f, "|");
|
||||
|
||||
fprintf(f, "%s\n", o->mesg);
|
||||
fprintf (f, "%s\n", o->mesg);
|
||||
}
|
||||
|
||||
apoint_llist_node_t *
|
||||
apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
|
||||
apoint_scan (FILE *f, struct tm start, struct tm end, char state, char *note)
|
||||
{
|
||||
struct tm *lt;
|
||||
char buf[MESG_MAXSIZE], *nl;
|
||||
time_t tstart, tend, t;
|
||||
|
||||
t = time(NULL);
|
||||
lt = localtime(&t);
|
||||
t = time (NULL);
|
||||
lt = localtime (&t);
|
||||
|
||||
/* Read the appointment description */
|
||||
fgets(buf, MESG_MAXSIZE, f);
|
||||
nl = strchr(buf, '\n');
|
||||
if (nl) {
|
||||
fgets (buf, MESG_MAXSIZE, f);
|
||||
nl = strchr (buf, '\n');
|
||||
if (nl)
|
||||
{
|
||||
*nl = '\0';
|
||||
}
|
||||
|
||||
@ -353,61 +380,68 @@ apoint_scan(FILE * f, struct tm start, struct tm end, char state, char *note)
|
||||
end.tm_year -= 1900;
|
||||
end.tm_mon--;
|
||||
|
||||
tstart = mktime(&start);
|
||||
tend = mktime(&end);
|
||||
if (tstart == -1 || tend == -1 || tstart > tend) {
|
||||
fputs(_("FATAL ERROR in apoint_scan: date error in the appointment\n"), stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
tstart = mktime (&start);
|
||||
tend = mktime (&end);
|
||||
if (tstart == -1 || tend == -1 || tstart > tend)
|
||||
{
|
||||
fputs (_("FATAL ERROR in apoint_scan: date error in the appointment\n"),
|
||||
stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (apoint_new(buf, note, tstart, tend - tstart, state));
|
||||
return (apoint_new (buf, note, tstart, tend - tstart, state));
|
||||
}
|
||||
|
||||
/* Retrieve an appointment from the list, given the day and item position. */
|
||||
apoint_llist_node_t *
|
||||
apoint_get(long day, int pos)
|
||||
apoint_get (long day, int pos)
|
||||
{
|
||||
apoint_llist_node_t *o;
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
for (o = alist_p->root; o; o = o->next) {
|
||||
if (apoint_inday(o, day)) {
|
||||
for (o = alist_p->root; o; o = o->next)
|
||||
{
|
||||
if (apoint_inday (o, day))
|
||||
{
|
||||
if (n == pos)
|
||||
return o;
|
||||
return (o);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
fputs(_("FATAL ERROR in apoint_get: no such item\n"), stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
fputs (_("FATAL ERROR in apoint_get: no such item\n"), stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void
|
||||
apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
|
||||
apoint_delete_bynum (long start, unsigned num, erase_flag_e flag)
|
||||
{
|
||||
unsigned n;
|
||||
int need_check_notify = 0;
|
||||
apoint_llist_node_t *i, **iptr;
|
||||
|
||||
n = 0;
|
||||
pthread_mutex_lock(&(alist_p->mutex));
|
||||
pthread_mutex_lock (&(alist_p->mutex));
|
||||
iptr = &alist_p->root;
|
||||
for (i = alist_p->root; i != 0; i = i->next) {
|
||||
if (apoint_inday(i, start)) {
|
||||
if (n == num) {
|
||||
for (i = alist_p->root; i != 0; i = i->next)
|
||||
{
|
||||
if (apoint_inday (i, start))
|
||||
{
|
||||
if (n == num)
|
||||
{
|
||||
if (flag == ERASE_FORCE_ONLY_NOTE)
|
||||
erase_note(&i->note, flag);
|
||||
else {
|
||||
if (notify_bar())
|
||||
need_check_notify =
|
||||
notify_same_item(i->start);
|
||||
erase_note (&i->note, flag);
|
||||
else
|
||||
{
|
||||
if (notify_bar ())
|
||||
need_check_notify = notify_same_item (i->start);
|
||||
*iptr = i->next;
|
||||
free(i->mesg);
|
||||
erase_note(&i->note, flag);
|
||||
free(i);
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
free (i->mesg);
|
||||
erase_note (&i->note, flag);
|
||||
free (i);
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
if (need_check_notify)
|
||||
notify_check_next_app();
|
||||
notify_check_next_app ();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -415,10 +449,10 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
|
||||
}
|
||||
iptr = &i->next;
|
||||
}
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
|
||||
/* NOTREACHED */
|
||||
ierror(_("FATAL ERROR in apoint_delete_bynum: no such appointment"),
|
||||
ierror (_("FATAL ERROR in apoint_delete_bynum: no such appointment"),
|
||||
IERROR_FATAL);
|
||||
}
|
||||
|
||||
@ -428,7 +462,7 @@ apoint_delete_bynum(long start, unsigned num, erase_flag_e flag)
|
||||
* to place beggining of the pad correctly.
|
||||
*/
|
||||
static int
|
||||
get_item_line(int item_nb, int nb_events_inday)
|
||||
get_item_line (int item_nb, int nb_events_inday)
|
||||
{
|
||||
int separator = 2;
|
||||
int line = 0;
|
||||
@ -436,8 +470,8 @@ get_item_line(int item_nb, int nb_events_inday)
|
||||
if (item_nb <= nb_events_inday)
|
||||
line = item_nb - 1;
|
||||
else
|
||||
line = nb_events_inday + separator +
|
||||
(item_nb - (nb_events_inday + 1))*3 - 1;
|
||||
line = nb_events_inday + separator
|
||||
+ (item_nb - (nb_events_inday + 1)) * 3 - 1;
|
||||
return line;
|
||||
}
|
||||
|
||||
@ -446,14 +480,14 @@ get_item_line(int item_nb, int nb_events_inday)
|
||||
* appointment panel scroll down next time pnoutrefresh is called.
|
||||
*/
|
||||
void
|
||||
apoint_scroll_pad_down(int nb_events_inday, int win_length)
|
||||
apoint_scroll_pad_down (int nb_events_inday, int win_length)
|
||||
{
|
||||
int pad_last_line = 0;
|
||||
int item_first_line = 0, item_last_line = 0;
|
||||
int borders = 6;
|
||||
int awin_length = win_length - borders;
|
||||
|
||||
item_first_line = get_item_line(hilt, nb_events_inday);
|
||||
item_first_line = get_item_line (hilt, nb_events_inday);
|
||||
if (hilt < nb_events_inday)
|
||||
item_last_line = item_first_line;
|
||||
else
|
||||
@ -468,11 +502,11 @@ apoint_scroll_pad_down(int nb_events_inday, int win_length)
|
||||
* appointment panel scroll up next time pnoutrefresh is called.
|
||||
*/
|
||||
void
|
||||
apoint_scroll_pad_up(int nb_events_inday)
|
||||
apoint_scroll_pad_up (int nb_events_inday)
|
||||
{
|
||||
int item_first_line = 0;
|
||||
|
||||
item_first_line = get_item_line(hilt, nb_events_inday);
|
||||
item_first_line = get_item_line (hilt, nb_events_inday);
|
||||
if (item_first_line < apad->first_onscreen)
|
||||
apad->first_onscreen = item_first_line;
|
||||
}
|
||||
@ -482,27 +516,32 @@ apoint_scroll_pad_up(int nb_events_inday)
|
||||
* stored in the notify_app structure (which is the next item to be notified).
|
||||
*/
|
||||
struct notify_app_s *
|
||||
apoint_check_next(struct notify_app_s *app, long start)
|
||||
apoint_check_next (struct notify_app_s *app, long start)
|
||||
{
|
||||
apoint_llist_node_t *i;
|
||||
|
||||
pthread_mutex_lock(&(alist_p->mutex));
|
||||
for (i = alist_p->root; i != 0; i = i->next) {
|
||||
if (i->start > app->time) {
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
return app;
|
||||
} else {
|
||||
if (i->start > start) {
|
||||
pthread_mutex_lock (&(alist_p->mutex));
|
||||
for (i = alist_p->root; i != 0; i = i->next)
|
||||
{
|
||||
if (i->start > app->time)
|
||||
{
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
return (app);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i->start > start)
|
||||
{
|
||||
app->time = i->start;
|
||||
app->txt = mycpy(i->mesg);
|
||||
app->txt = mycpy (i->mesg);
|
||||
app->state = i->state;
|
||||
app->got_app = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
|
||||
return app;
|
||||
return (app);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -510,73 +549,77 @@ apoint_check_next(struct notify_app_s *app, long start)
|
||||
* recur_apoint_s
|
||||
*/
|
||||
apoint_llist_node_t *
|
||||
apoint_recur_s2apoint_s(recur_apoint_llist_node_t *p)
|
||||
apoint_recur_s2apoint_s (recur_apoint_llist_node_t *p)
|
||||
{
|
||||
apoint_llist_node_t *a;
|
||||
|
||||
a = (apoint_llist_node_t *) malloc(sizeof(apoint_llist_node_t));
|
||||
a->mesg = (char *) malloc(strlen(p->mesg) + 1);
|
||||
a = (apoint_llist_node_t *) malloc (sizeof (apoint_llist_node_t));
|
||||
a->mesg = (char *) malloc (strlen (p->mesg) + 1);
|
||||
a->start = p->start;
|
||||
a->dur = p->dur;
|
||||
a->mesg = p->mesg;
|
||||
return a;
|
||||
return (a);
|
||||
}
|
||||
|
||||
/*
|
||||
* Switch notification state.
|
||||
*/
|
||||
void
|
||||
apoint_switch_notify(void)
|
||||
apoint_switch_notify (void)
|
||||
{
|
||||
apoint_llist_node_t *apoint;
|
||||
struct day_item_s *p;
|
||||
long date;
|
||||
int apoint_nb = 0, n, need_chk_notify;
|
||||
|
||||
p = day_get_item(hilt);
|
||||
p = day_get_item (hilt);
|
||||
if (p->type != APPT && p->type != RECUR_APPT)
|
||||
return;
|
||||
|
||||
date = calendar_get_slctd_day_sec();
|
||||
date = calendar_get_slctd_day_sec ();
|
||||
|
||||
if (p->type == RECUR_APPT) {
|
||||
recur_apoint_switch_notify(date, p->appt_pos);
|
||||
if (p->type == RECUR_APPT)
|
||||
{
|
||||
recur_apoint_switch_notify (date, p->appt_pos);
|
||||
return;
|
||||
} else if (p->type == APPT)
|
||||
apoint_nb = day_item_nb(date, hilt, APPT);
|
||||
}
|
||||
else if (p->type == APPT)
|
||||
apoint_nb = day_item_nb (date, hilt, APPT);
|
||||
|
||||
n = 0;
|
||||
need_chk_notify = 0;
|
||||
pthread_mutex_lock(&(alist_p->mutex));
|
||||
pthread_mutex_lock (&(alist_p->mutex));
|
||||
|
||||
for (apoint = alist_p->root; apoint != 0; apoint = apoint->next) {
|
||||
if (apoint_inday(apoint, date)) {
|
||||
if (n == apoint_nb) {
|
||||
for (apoint = alist_p->root; apoint != 0; apoint = apoint->next)
|
||||
{
|
||||
if (apoint_inday (apoint, date))
|
||||
{
|
||||
if (n == apoint_nb)
|
||||
{
|
||||
apoint->state ^= APOINT_NOTIFY;
|
||||
|
||||
if (notify_bar())
|
||||
notify_check_added(apoint->mesg,
|
||||
apoint->start, apoint->state);
|
||||
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
if (notify_bar ())
|
||||
{
|
||||
notify_check_added (apoint->mesg, apoint->start,
|
||||
apoint->state);
|
||||
}
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
if (need_chk_notify)
|
||||
notify_check_next_app();
|
||||
notify_check_next_app ();
|
||||
return;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
|
||||
/* NOTREACHED */
|
||||
ierror(
|
||||
_("FATAL ERROR in apoint_switch_notify: no such appointment"),
|
||||
ierror (_("FATAL ERROR in apoint_switch_notify: no such appointment"),
|
||||
IERROR_FATAL);
|
||||
}
|
||||
|
||||
/* Updates the Appointment panel */
|
||||
void
|
||||
apoint_update_panel(window_t *winapp, int which_pan)
|
||||
apoint_update_panel (window_t *winapp, int which_pan)
|
||||
{
|
||||
int title_xpos;
|
||||
int bordr = 1;
|
||||
@ -587,24 +630,24 @@ apoint_update_panel(window_t *winapp, int which_pan)
|
||||
date_t slctd_date;
|
||||
|
||||
/* variable inits */
|
||||
slctd_date = *calendar_get_slctd_day();
|
||||
title_xpos = winapp->w - (strlen(_(monthnames[slctd_date.mm - 1])) + 16);
|
||||
slctd_date = *calendar_get_slctd_day ();
|
||||
title_xpos = winapp->w - (strlen (_(monthnames[slctd_date.mm - 1])) + 16);
|
||||
if (slctd_date.dd < 10)
|
||||
title_xpos++;
|
||||
date = date2sec(slctd_date, 0, 0);
|
||||
day_write_pad(date, app_width, app_length, hilt);
|
||||
date = date2sec (slctd_date, 0, 0);
|
||||
day_write_pad (date, app_width, app_length, hilt);
|
||||
|
||||
/* Print current date in the top right window corner. */
|
||||
erase_window_part(win[APP].p, 1, title_lines, winapp->w - 2,
|
||||
winapp->h - 2);
|
||||
custom_apply_attr(win[APP].p, ATTR_HIGHEST);
|
||||
mvwprintw(win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
|
||||
calendar_get_pom(date), _(monthnames[slctd_date.mm - 1]),
|
||||
erase_window_part (win[APP].p, 1, title_lines, winapp->w - 2, winapp->h - 2);
|
||||
custom_apply_attr (win[APP].p, ATTR_HIGHEST);
|
||||
mvwprintw (win[APP].p, title_lines, title_xpos, "%s %s %d, %d",
|
||||
calendar_get_pom (date), _(monthnames[slctd_date.mm - 1]),
|
||||
slctd_date.dd, slctd_date.yyyy);
|
||||
custom_remove_attr(win[APP].p, ATTR_HIGHEST);
|
||||
custom_remove_attr (win[APP].p, ATTR_HIGHEST);
|
||||
|
||||
/* Draw the scrollbar if necessary. */
|
||||
if ((apad->length >= app_length)||(apad->first_onscreen > 0)) {
|
||||
if ((apad->length >= app_length) || (apad->first_onscreen > 0))
|
||||
{
|
||||
float ratio = ((float) app_length) / ((float) apad->length);
|
||||
int sbar_length = (int) (ratio * app_length);
|
||||
int highend = (int) (ratio * apad->first_onscreen);
|
||||
@ -613,12 +656,13 @@ apoint_update_panel(window_t *winapp, int which_pan)
|
||||
|
||||
if ((sbar_top + sbar_length) > winapp->h - 1)
|
||||
sbar_length = winapp->h - 1 - sbar_top;
|
||||
draw_scrollbar(win[APP].p, sbar_top, winapp->w - 2, sbar_length,
|
||||
draw_scrollbar (win[APP].p, sbar_top, winapp->w - 2, sbar_length,
|
||||
title_lines + 1, winapp->h - 1, hilt_bar);
|
||||
}
|
||||
|
||||
wnoutrefresh(win[APP].p);
|
||||
pnoutrefresh(apad->ptrwin, apad->first_onscreen, 0,
|
||||
wnoutrefresh (win[APP].p);
|
||||
pnoutrefresh (apad->ptrwin, apad->first_onscreen, 0,
|
||||
winapp->y + title_lines + 1, winapp->x + bordr,
|
||||
winapp->y + winapp->h - 2*bordr, winapp->x + winapp->w - 3*bordr);
|
||||
winapp->y + winapp->h - 2 * bordr,
|
||||
winapp->x + winapp->w - 3 * bordr);
|
||||
}
|
||||
|
56
src/apoint.h
56
src/apoint.h
@ -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
|
||||
@ -39,42 +39,46 @@
|
||||
#define APOINT_NOTIFY 0x1 /* Item needs to be 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 */
|
||||
long dur; /* duration of the appointment in seconds */
|
||||
char state; /* 8 bits to store item state */
|
||||
char *mesg;
|
||||
char *note;
|
||||
} apoint_llist_node_t;
|
||||
}
|
||||
apoint_llist_node_t;
|
||||
|
||||
typedef struct apoint_llist {
|
||||
typedef struct apoint_llist
|
||||
{
|
||||
apoint_llist_node_t *root;
|
||||
pthread_mutex_t mutex;
|
||||
} apoint_llist_t;
|
||||
}
|
||||
apoint_llist_t;
|
||||
|
||||
extern apoint_llist_t *alist_p;
|
||||
|
||||
int apoint_llist_init(void);
|
||||
void apoint_hilt_set(int);
|
||||
void apoint_hilt_decrease(void);
|
||||
void apoint_hilt_increase(void);
|
||||
int apoint_hilt(void);
|
||||
apoint_llist_node_t *apoint_new(char *, char *, long, long, char);
|
||||
void apoint_add(void);
|
||||
void apoint_delete(conf_t *, unsigned *, unsigned *);
|
||||
unsigned apoint_inday(apoint_llist_node_t *, long);
|
||||
void apoint_sec2str(apoint_llist_node_t *, int, long,
|
||||
char *, char *);
|
||||
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_get(long, int);
|
||||
void apoint_delete_bynum(long, unsigned, erase_flag_e);
|
||||
void apoint_scroll_pad_down(int, int);
|
||||
void apoint_scroll_pad_up(int);
|
||||
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 *);
|
||||
void apoint_switch_notify(void);
|
||||
void apoint_update_panel(window_t *, int);
|
||||
int apoint_llist_init (void);
|
||||
void apoint_hilt_set (int);
|
||||
void apoint_hilt_decrease (void);
|
||||
void apoint_hilt_increase (void);
|
||||
int apoint_hilt (void);
|
||||
apoint_llist_node_t *apoint_new (char *, char *, long, long, char);
|
||||
void apoint_add (void);
|
||||
void apoint_delete (conf_t *, unsigned *, unsigned *);
|
||||
unsigned apoint_inday (apoint_llist_node_t *, long);
|
||||
void apoint_sec2str (apoint_llist_node_t *, int, long, char *,
|
||||
char *);
|
||||
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_get (long, int);
|
||||
void apoint_delete_bynum (long, unsigned, erase_flag_e);
|
||||
void apoint_scroll_pad_down (int, int);
|
||||
void apoint_scroll_pad_up (int);
|
||||
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 *);
|
||||
void apoint_switch_notify (void);
|
||||
void apoint_update_panel (window_t *, int);
|
||||
|
||||
#endif /* CALCURSE_APOINT_H */
|
||||
|
455
src/args.c
455
src/args.c
@ -1,4 +1,4 @@
|
||||
/* $calcurse: args.c,v 1.31 2008/04/09 20:38:29 culot Exp $ */
|
||||
/* $calcurse: args.c,v 1.32 2008/04/12 21:14:03 culot Exp $ */
|
||||
|
||||
/*
|
||||
* Calcurse - text-based organizer
|
||||
@ -45,45 +45,42 @@
|
||||
* Print Calcurse usage and exit.
|
||||
*/
|
||||
static void
|
||||
usage()
|
||||
usage ()
|
||||
{
|
||||
char *arg_usage =
|
||||
_("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] [-c file]\n");
|
||||
|
||||
fputs(arg_usage, stdout);
|
||||
_("Usage: calcurse [-h|-v] [-x] [-N] [-an] [-t[num]] [-d date|num] "
|
||||
"[-c file]\n");
|
||||
fputs (arg_usage, stdout);
|
||||
}
|
||||
|
||||
static void
|
||||
usage_try()
|
||||
usage_try ()
|
||||
{
|
||||
char *arg_usage_try =
|
||||
_("Try 'calcurse -h' for more information.\n");
|
||||
|
||||
fputs(arg_usage_try, stdout);
|
||||
char *arg_usage_try = _("Try 'calcurse -h' for more information.\n");
|
||||
fputs (arg_usage_try, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print Calcurse version with a short copyright text and exit.
|
||||
*/
|
||||
static void
|
||||
version_arg()
|
||||
version_arg ()
|
||||
{
|
||||
char vtitle[BUFSIZ];
|
||||
char *vtext =
|
||||
_("\nCopyright (c) 2004-2007 Frederic Culot.\n"
|
||||
_("\nCopyright (c) 2004-2008 Frederic Culot.\n"
|
||||
"This is free software; see the source for copying conditions.\n");
|
||||
|
||||
snprintf(vtitle, BUFSIZ,
|
||||
_("Calcurse %s - text-based organizer\n"), VERSION);
|
||||
fputs(vtitle, stdout);
|
||||
fputs(vtext, stdout);
|
||||
snprintf (vtitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
|
||||
fputs (vtitle, stdout);
|
||||
fputs (vtext, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the command line options and exit.
|
||||
*/
|
||||
static void
|
||||
help_arg()
|
||||
help_arg ()
|
||||
{
|
||||
char htitle[BUFSIZ];
|
||||
char *htext =
|
||||
@ -121,11 +118,10 @@ help_arg()
|
||||
"or read the manpage.\n"
|
||||
"Mail bug reports and suggestions to <calcurse@culot.org>.\n");
|
||||
|
||||
snprintf(htitle, BUFSIZ,
|
||||
_("Calcurse %s - text-based organizer\n"), VERSION);
|
||||
fputs(htitle, stdout);
|
||||
usage();
|
||||
fputs(htext, stdout);
|
||||
snprintf (htitle, BUFSIZ, _("Calcurse %s - text-based organizer\n"), VERSION);
|
||||
fputs (htitle, stdout);
|
||||
usage ();
|
||||
fputs (htext, stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -137,7 +133,7 @@ help_arg()
|
||||
* (patch submitted by Erik Saule).
|
||||
*/
|
||||
static void
|
||||
print_notefile(FILE *out, char *filename, int nbtab)
|
||||
print_notefile (FILE *out, char *filename, int nbtab)
|
||||
{
|
||||
char path_to_notefile[BUFSIZ];
|
||||
FILE *notefile;
|
||||
@ -147,25 +143,30 @@ print_notefile(FILE *out, char *filename, int nbtab)
|
||||
int printlinestarter = 1;
|
||||
|
||||
for (i = 0; i < nbtab; i++)
|
||||
strcat(linestarter, "\t");
|
||||
strcat (linestarter, "\t");
|
||||
|
||||
snprintf(path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
|
||||
notefile = fopen(path_to_notefile, "r");
|
||||
if (notefile) {
|
||||
while (fgets(buffer, BUFSIZ, notefile) != NULL) {
|
||||
if (printlinestarter) {
|
||||
fputs(linestarter,out);
|
||||
snprintf (path_to_notefile, BUFSIZ, "%s/%s", path_notes, filename);
|
||||
notefile = fopen (path_to_notefile, "r");
|
||||
if (notefile)
|
||||
{
|
||||
while (fgets (buffer, BUFSIZ, notefile) != NULL)
|
||||
{
|
||||
if (printlinestarter)
|
||||
{
|
||||
fputs (linestarter, out);
|
||||
printlinestarter = 0;
|
||||
}
|
||||
fputs(buffer, out);
|
||||
if (buffer[strlen(buffer) - 1] == '\n')
|
||||
fputs (buffer, out);
|
||||
if (buffer[strlen (buffer) - 1] == '\n')
|
||||
printlinestarter = 1;
|
||||
}
|
||||
fputs("\n", out);
|
||||
fclose(notefile);
|
||||
} else {
|
||||
fputs(linestarter, out);
|
||||
fputs(_("No note file found\n"), out);
|
||||
fputs ("\n", out);
|
||||
fclose (notefile);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs (linestarter, out);
|
||||
fputs (_("No note file found\n"), out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,35 +175,38 @@ print_notefile(FILE *out, char *filename, int nbtab)
|
||||
* zero), then only todo items that have this priority will be displayed.
|
||||
*/
|
||||
static void
|
||||
todo_arg(int priority, int print_note)
|
||||
todo_arg (int priority, int print_note)
|
||||
{
|
||||
struct todo_s *i;
|
||||
int title = 1;
|
||||
char priority_str[BUFSIZ] = "";
|
||||
|
||||
io_load_todo();
|
||||
for (i = todolist; i != 0; i = i->next) {
|
||||
if (priority == 0 || i->id == priority) {
|
||||
if (title) {
|
||||
fputs(_("to do:\n"),stdout);
|
||||
io_load_todo ();
|
||||
for (i = todolist; i != 0; i = i->next)
|
||||
{
|
||||
if (priority == 0 || i->id == priority)
|
||||
{
|
||||
if (title)
|
||||
{
|
||||
fputs (_("to do:\n"), stdout);
|
||||
title = 0;
|
||||
}
|
||||
snprintf(priority_str, BUFSIZ, "%d. ", i->id);
|
||||
fputs(priority_str, stdout);
|
||||
fputs(i->mesg, stdout);
|
||||
fputs("\n", stdout);
|
||||
snprintf (priority_str, BUFSIZ, "%d. ", i->id);
|
||||
fputs (priority_str, stdout);
|
||||
fputs (i->mesg, stdout);
|
||||
fputs ("\n", stdout);
|
||||
if (print_note && i->note)
|
||||
print_notefile(stdout, i->note, 1);
|
||||
print_notefile (stdout, i->note, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Print the next appointment within the upcoming 24 hours. */
|
||||
static void
|
||||
next_arg(void)
|
||||
next_arg (void)
|
||||
{
|
||||
struct notify_app_s next_app;
|
||||
const long current_time = now();
|
||||
const long current_time = now ();
|
||||
int time_left, hours_left, min_left;
|
||||
char mesg[BUFSIZ];
|
||||
|
||||
@ -210,19 +214,19 @@ next_arg(void)
|
||||
next_app.got_app = 0;
|
||||
next_app.txt = NULL;
|
||||
|
||||
next_app = *recur_apoint_check_next(&next_app, current_time,
|
||||
get_today());
|
||||
next_app = *apoint_check_next(&next_app, current_time);
|
||||
next_app = *recur_apoint_check_next (&next_app, current_time, get_today ());
|
||||
next_app = *apoint_check_next (&next_app, current_time);
|
||||
|
||||
if (next_app.got_app) {
|
||||
if (next_app.got_app)
|
||||
{
|
||||
time_left = next_app.time - current_time;
|
||||
hours_left = (time_left / HOURINSEC);
|
||||
min_left = (time_left - hours_left * HOURINSEC) / MININSEC;
|
||||
fputs(_("next appointment:\n"), stdout);
|
||||
snprintf(mesg, BUFSIZ, " [%02d:%02d] %s\n",
|
||||
hours_left, min_left, next_app.txt);
|
||||
fputs(mesg, stdout);
|
||||
free(next_app.txt);
|
||||
fputs (_("next appointment:\n"), stdout);
|
||||
snprintf (mesg, BUFSIZ, " [%02d:%02d] %s\n", hours_left, min_left,
|
||||
next_app.txt);
|
||||
fputs (mesg, stdout);
|
||||
free (next_app.txt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,17 +234,17 @@ next_arg(void)
|
||||
* Print the date on stdout.
|
||||
*/
|
||||
static void
|
||||
arg_print_date(long date, conf_t *conf)
|
||||
arg_print_date (long date, conf_t *conf)
|
||||
{
|
||||
char date_str[BUFSIZ];
|
||||
time_t t;
|
||||
struct tm *lt;
|
||||
|
||||
t = date;
|
||||
lt = localtime(&t);
|
||||
strftime(date_str, BUFSIZ, conf->output_datefmt, lt);
|
||||
fputs(date_str,stdout);
|
||||
fputs(":\n",stdout);
|
||||
lt = localtime (&t);
|
||||
strftime (date_str, BUFSIZ, conf->output_datefmt, lt);
|
||||
fputs (date_str, stdout);
|
||||
fputs (":\n", stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -249,7 +253,7 @@ arg_print_date(long date, conf_t *conf)
|
||||
* If there is also no date given, current date is considered.
|
||||
*/
|
||||
static int
|
||||
app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
|
||||
app_arg (int add_line, date_t *day, long date, int print_note, conf_t *conf)
|
||||
{
|
||||
struct recur_event_s *re;
|
||||
struct event_s *j;
|
||||
@ -262,7 +266,7 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
|
||||
char apoint_end_time[100];
|
||||
|
||||
if (date == 0)
|
||||
today = get_sec_date(*day);
|
||||
today = get_sec_date (*day);
|
||||
else
|
||||
today = date;
|
||||
|
||||
@ -271,102 +275,117 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
|
||||
* that date and it is the first one, and then print all the events for
|
||||
* that date.
|
||||
*/
|
||||
for (re = recur_elist; re != 0; re = re->next) {
|
||||
if (recur_item_inday(re->day, re->exc, re->rpt->type,
|
||||
re->rpt->freq, re->rpt->until, today)) {
|
||||
for (re = recur_elist; re != 0; re = re->next)
|
||||
{
|
||||
if (recur_item_inday (re->day, re->exc, re->rpt->type, re->rpt->freq,
|
||||
re->rpt->until, today))
|
||||
{
|
||||
app_found = 1;
|
||||
if (add_line) {
|
||||
fputs("\n", stdout);
|
||||
if (add_line)
|
||||
{
|
||||
fputs ("\n", stdout);
|
||||
add_line = 0;
|
||||
}
|
||||
if (print_date) {
|
||||
arg_print_date(today, conf);
|
||||
if (print_date)
|
||||
{
|
||||
arg_print_date (today, conf);
|
||||
print_date = false;
|
||||
}
|
||||
fputs(" * ", stdout);
|
||||
fputs(re->mesg, stdout); fputs("\n", stdout);
|
||||
fputs (" * ", stdout);
|
||||
fputs (re->mesg, stdout);
|
||||
fputs ("\n", stdout);
|
||||
if (print_note && re->note)
|
||||
print_notefile(stdout, re->note, 2);
|
||||
print_notefile (stdout, re->note, 2);
|
||||
}
|
||||
}
|
||||
|
||||
for (j = eventlist; j != 0; j = j->next) {
|
||||
if (event_inday(j, today)) {
|
||||
for (j = eventlist; j != 0; j = j->next)
|
||||
{
|
||||
if (event_inday (j, today))
|
||||
{
|
||||
app_found = 1;
|
||||
if (add_line) {
|
||||
fputs("\n",stdout);
|
||||
if (add_line)
|
||||
{
|
||||
fputs ("\n", stdout);
|
||||
add_line = 0;
|
||||
}
|
||||
if (print_date) {
|
||||
arg_print_date(today, conf);
|
||||
if (print_date)
|
||||
{
|
||||
arg_print_date (today, conf);
|
||||
print_date = false;
|
||||
}
|
||||
fputs(" * ", stdout);
|
||||
fputs(j->mesg, stdout);
|
||||
fputs("\n", stdout);
|
||||
fputs (" * ", stdout);
|
||||
fputs (j->mesg, stdout);
|
||||
fputs ("\n", stdout);
|
||||
if (print_note && j->note)
|
||||
print_notefile(stdout, j->note, 2);
|
||||
print_notefile (stdout, j->note, 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Same process is performed but this time on the appointments. */
|
||||
pthread_mutex_lock(&(recur_alist_p->mutex));
|
||||
for (ra = recur_alist_p->root; ra != 0; ra = ra->next) {
|
||||
if (recur_item_inday(ra->start, ra->exc, ra->rpt->type,
|
||||
ra->rpt->freq, ra->rpt->until, today)) {
|
||||
pthread_mutex_lock (&(recur_alist_p->mutex));
|
||||
for (ra = recur_alist_p->root; ra != 0; ra = ra->next)
|
||||
{
|
||||
if (recur_item_inday (ra->start, ra->exc, ra->rpt->type, ra->rpt->freq,
|
||||
ra->rpt->until, today))
|
||||
{
|
||||
app_found = 1;
|
||||
if (add_line) {
|
||||
fputs("\n",stdout);
|
||||
if (add_line)
|
||||
{
|
||||
fputs ("\n", stdout);
|
||||
add_line = 0;
|
||||
}
|
||||
if (print_date) {
|
||||
arg_print_date(today, conf);
|
||||
if (print_date)
|
||||
{
|
||||
arg_print_date (today, conf);
|
||||
print_date = false;
|
||||
}
|
||||
apoint_sec2str(apoint_recur_s2apoint_s(ra),
|
||||
RECUR_APPT, today, apoint_start_time,
|
||||
apoint_end_time);
|
||||
fputs(" - ", stdout);
|
||||
fputs(apoint_start_time, stdout);
|
||||
fputs(" -> ", stdout);
|
||||
fputs(apoint_end_time, stdout);
|
||||
fputs("\n\t", stdout);
|
||||
fputs(ra->mesg, stdout);
|
||||
fputs("\n", stdout);
|
||||
apoint_sec2str (apoint_recur_s2apoint_s (ra), RECUR_APPT, today,
|
||||
apoint_start_time, apoint_end_time);
|
||||
fputs (" - ", stdout);
|
||||
fputs (apoint_start_time, stdout);
|
||||
fputs (" -> ", stdout);
|
||||
fputs (apoint_end_time, stdout);
|
||||
fputs ("\n\t", stdout);
|
||||
fputs (ra->mesg, stdout);
|
||||
fputs ("\n", stdout);
|
||||
if (print_note && ra->note)
|
||||
print_notefile(stdout, ra->note, 2);
|
||||
print_notefile (stdout, ra->note, 2);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(recur_alist_p->mutex));
|
||||
pthread_mutex_unlock (&(recur_alist_p->mutex));
|
||||
|
||||
pthread_mutex_lock(&(alist_p->mutex));
|
||||
for (i = alist_p->root; i != 0; i = i->next) {
|
||||
if (apoint_inday(i, today)) {
|
||||
pthread_mutex_lock (&(alist_p->mutex));
|
||||
for (i = alist_p->root; i != 0; i = i->next)
|
||||
{
|
||||
if (apoint_inday (i, today))
|
||||
{
|
||||
app_found = 1;
|
||||
if (add_line) {
|
||||
fputs("\n",stdout);
|
||||
if (add_line)
|
||||
{
|
||||
fputs ("\n", stdout);
|
||||
add_line = 0;
|
||||
}
|
||||
if (print_date) {
|
||||
arg_print_date(today, conf);
|
||||
if (print_date)
|
||||
{
|
||||
arg_print_date (today, conf);
|
||||
print_date = false;
|
||||
}
|
||||
apoint_sec2str(i, APPT, today, apoint_start_time,
|
||||
apoint_end_time);
|
||||
fputs(" - ", stdout);
|
||||
fputs(apoint_start_time, stdout);
|
||||
fputs(" -> ", stdout);
|
||||
fputs(apoint_end_time, stdout);
|
||||
fputs("\n\t", stdout);
|
||||
fputs(i->mesg, stdout);
|
||||
fputs("\n", stdout);
|
||||
apoint_sec2str (i, APPT, today, apoint_start_time, apoint_end_time);
|
||||
fputs (" - ", stdout);
|
||||
fputs (apoint_start_time, stdout);
|
||||
fputs (" -> ", stdout);
|
||||
fputs (apoint_end_time, stdout);
|
||||
fputs ("\n\t", stdout);
|
||||
fputs (i->mesg, stdout);
|
||||
fputs ("\n", stdout);
|
||||
if (print_note && i->note)
|
||||
print_notefile(stdout, i->note, 2);
|
||||
print_notefile (stdout, i->note, 2);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&(alist_p->mutex));
|
||||
pthread_mutex_unlock (&(alist_p->mutex));
|
||||
|
||||
return app_found;
|
||||
return (app_found);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -374,7 +393,7 @@ app_arg(int add_line, date_t *day, long date, int print_note, conf_t *conf)
|
||||
* days.
|
||||
*/
|
||||
static void
|
||||
date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
|
||||
date_arg (char *ddate, int add_line, int print_note, conf_t *conf)
|
||||
{
|
||||
int i;
|
||||
date_t day;
|
||||
@ -387,49 +406,56 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
|
||||
* Check (with the argument length) if a date or a number of days
|
||||
* was entered, and then call app_arg() to print appointments
|
||||
*/
|
||||
arg_len = strlen(ddate);
|
||||
if (arg_len <= 4) { /* a number of days was entered */
|
||||
for (i = 0; i <= arg_len-1; i++) {
|
||||
if (isdigit(ddate[i]))
|
||||
arg_len = strlen (ddate);
|
||||
if (arg_len <= 4)
|
||||
{ /* a number of days was entered */
|
||||
for (i = 0; i <= arg_len - 1; i++)
|
||||
{
|
||||
if (isdigit (ddate[i]))
|
||||
num_digit++;
|
||||
}
|
||||
if (num_digit == arg_len)
|
||||
numdays = atoi(ddate);
|
||||
numdays = atoi (ddate);
|
||||
|
||||
/*
|
||||
* Get current date, and print appointments for each day
|
||||
* in the chosen interval. app_found and add_line are used
|
||||
* to format the output correctly.
|
||||
*/
|
||||
timer = time(NULL);
|
||||
t = *localtime(&timer);
|
||||
timer = time (NULL);
|
||||
t = *localtime (&timer);
|
||||
|
||||
for (i = 0; i < numdays; i++) {
|
||||
for (i = 0; i < numdays; i++)
|
||||
{
|
||||
day.dd = t.tm_mday;
|
||||
day.mm = t.tm_mon + 1;
|
||||
day.yyyy = t.tm_year + 1900;
|
||||
app_found = app_arg(add_line, &day, 0, print_note, conf);
|
||||
app_found = app_arg (add_line, &day, 0, print_note, conf);
|
||||
if (app_found)
|
||||
add_line = 1;
|
||||
t.tm_mday++;
|
||||
mktime(&t);
|
||||
mktime (&t);
|
||||
}
|
||||
} else { /* a date was entered */
|
||||
if (parse_date(ddate, conf->input_datefmt,
|
||||
&day.yyyy, &day.mm, &day.dd)) {
|
||||
app_found = app_arg(add_line, &day, 0, print_note, conf);
|
||||
} else {
|
||||
fputs(_("Argument to the '-d' flag is not valid\n"),
|
||||
stdout);
|
||||
}
|
||||
else
|
||||
{ /* a date was entered */
|
||||
if (parse_date (ddate, conf->input_datefmt, &day.yyyy, &day.mm, &day.dd))
|
||||
{
|
||||
app_found = app_arg (add_line, &day, 0, print_note, conf);
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs (_("Argument to the '-d' flag is not valid\n"), stdout);
|
||||
char outstr[BUFSIZ];
|
||||
snprintf(outstr, BUFSIZ, "Possible argument format are: '%s' or 'n'\n",
|
||||
DATEFMT_DESC(conf->input_datefmt));
|
||||
fputs(_(outstr), stdout);
|
||||
fputs(_("\nFor more information, type '?' from within Calcurse, or read the manpage.\n"),
|
||||
stdout);
|
||||
fputs
|
||||
(_("Mail bug reports and suggestions to <calcurse@culot.org>.\n"),
|
||||
snprintf (outstr, BUFSIZ,
|
||||
"Possible argument format are: '%s' or 'n'\n",
|
||||
DATEFMT_DESC (conf->input_datefmt));
|
||||
fputs (_(outstr), stdout);
|
||||
fputs (_("\nFor more information, type '?' from within Calcurse, "
|
||||
"or read the manpage.\n"),
|
||||
stdout);
|
||||
fputs (_("Mail bug reports and suggestions to "
|
||||
"<calcurse@culot.org>.\n"), stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -439,7 +465,7 @@ date_arg(char *ddate, int add_line, int print_note, conf_t *conf)
|
||||
* routines to handle those arguments. Also initialize the data paths.
|
||||
*/
|
||||
int
|
||||
parse_args(int argc, char **argv, conf_t *conf)
|
||||
parse_args (int argc, char **argv, conf_t *conf)
|
||||
{
|
||||
int ch, add_line = 0;
|
||||
int unknown_flag = 0, app_found = 0;
|
||||
@ -474,8 +500,10 @@ parse_args(int argc, char **argv, conf_t *conf)
|
||||
{NULL, no_argument, NULL, 0}
|
||||
};
|
||||
|
||||
while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
while ((ch = getopt_long (argc, argv, optstr, longopts, NULL)) != -1)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
multiple_flag++;
|
||||
@ -509,14 +537,17 @@ parse_args(int argc, char **argv, conf_t *conf)
|
||||
multiple_flag++;
|
||||
load_data++;
|
||||
add_line = 1;
|
||||
if (optarg != NULL) {
|
||||
tnum = atoi(optarg);
|
||||
if (tnum < 1 || tnum > 9) {
|
||||
usage();
|
||||
usage_try();
|
||||
return EXIT_FAILURE;
|
||||
if (optarg != NULL)
|
||||
{
|
||||
tnum = atoi (optarg);
|
||||
if (tnum < 1 || tnum > 9)
|
||||
{
|
||||
usage ();
|
||||
usage_try ();
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
tnum = 0;
|
||||
break;
|
||||
case 'v':
|
||||
@ -528,8 +559,8 @@ parse_args(int argc, char **argv, conf_t *conf)
|
||||
load_data++;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
usage_try();
|
||||
usage ();
|
||||
usage_try ();
|
||||
unknown_flag = 1;
|
||||
non_interactive = 1;
|
||||
/* NOTREACHED */
|
||||
@ -538,60 +569,80 @@ parse_args(int argc, char **argv, conf_t *conf)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc >= 1) { /* incorrect arguments */
|
||||
usage();
|
||||
usage_try();
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
if (unknown_flag) {
|
||||
non_interactive = 1;
|
||||
} else if (hflag) {
|
||||
help_arg();
|
||||
non_interactive = 1;
|
||||
} else if (vflag) {
|
||||
version_arg();
|
||||
non_interactive = 1;
|
||||
} else if (multiple_flag) {
|
||||
if (load_data) {
|
||||
io_init(cfile);
|
||||
no_file = io_check_data_files();
|
||||
if (dflag || aflag || nflag || xflag)
|
||||
io_load_app();
|
||||
if (argc >= 1)
|
||||
{
|
||||
usage ();
|
||||
usage_try ();
|
||||
return (EXIT_FAILURE);
|
||||
/* Incorrect arguments */
|
||||
}
|
||||
if (xflag) {
|
||||
notify_init_vars();
|
||||
custom_load_conf(conf, 0);
|
||||
io_export_data(IO_EXPORT_NONINTERACTIVE, conf);
|
||||
else
|
||||
{
|
||||
if (unknown_flag)
|
||||
{
|
||||
non_interactive = 1;
|
||||
}
|
||||
else if (hflag)
|
||||
{
|
||||
help_arg ();
|
||||
non_interactive = 1;
|
||||
}
|
||||
else if (vflag)
|
||||
{
|
||||
version_arg ();
|
||||
non_interactive = 1;
|
||||
}
|
||||
else if (multiple_flag)
|
||||
{
|
||||
if (load_data)
|
||||
{
|
||||
io_init (cfile);
|
||||
no_file = io_check_data_files ();
|
||||
if (dflag || aflag || nflag || xflag)
|
||||
io_load_app ();
|
||||
}
|
||||
if (xflag)
|
||||
{
|
||||
notify_init_vars ();
|
||||
custom_load_conf (conf, 0);
|
||||
io_export_data (IO_EXPORT_NONINTERACTIVE, conf);
|
||||
non_interactive = 1;
|
||||
return (non_interactive);
|
||||
}
|
||||
if (tflag) {
|
||||
todo_arg(tnum, Nflag);
|
||||
if (tflag)
|
||||
{
|
||||
todo_arg (tnum, Nflag);
|
||||
non_interactive = 1;
|
||||
}
|
||||
if (nflag) {
|
||||
next_arg();
|
||||
if (nflag)
|
||||
{
|
||||
next_arg ();
|
||||
non_interactive = 1;
|
||||
}
|
||||
if (dflag) {
|
||||
notify_init_vars();
|
||||
vars_init(conf);
|
||||
custom_load_conf(conf, 0);
|
||||
date_arg(ddate, add_line, Nflag, conf);
|
||||
if (dflag)
|
||||
{
|
||||
notify_init_vars ();
|
||||
vars_init (conf);
|
||||
custom_load_conf (conf, 0);
|
||||
date_arg (ddate, add_line, Nflag, conf);
|
||||
non_interactive = 1;
|
||||
} else if (aflag) {
|
||||
}
|
||||
else if (aflag)
|
||||
{
|
||||
date_t day;
|
||||
day.dd = day.mm = day.yyyy = 0;
|
||||
notify_init_vars();
|
||||
vars_init(conf);
|
||||
custom_load_conf(conf, 0);
|
||||
app_found = app_arg(add_line, &day, 0, Nflag, conf);
|
||||
notify_init_vars ();
|
||||
vars_init (conf);
|
||||
custom_load_conf (conf, 0);
|
||||
app_found = app_arg (add_line, &day, 0, Nflag, conf);
|
||||
non_interactive = 1;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
non_interactive = 0;
|
||||
io_init(cfile);
|
||||
no_file = io_check_data_files();
|
||||
io_init (cfile);
|
||||
no_file = io_check_data_files ();
|
||||
}
|
||||
return (non_interactive);
|
||||
}
|
||||
|
@ -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
|
||||
@ -27,6 +27,6 @@
|
||||
#ifndef 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 */
|
||||
|
400
src/calcurse.c
400
src/calcurse.c
@ -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
|
||||
@ -51,7 +51,7 @@
|
||||
* All of the commands are documented within an online help system.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
conf_t conf;
|
||||
day_items_nb_t inday;
|
||||
@ -77,134 +77,140 @@ main(int argc, char **argv)
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
/* Thread-safe data structure init */
|
||||
apoint_llist_init();
|
||||
recur_apoint_llist_init();
|
||||
apoint_llist_init ();
|
||||
recur_apoint_llist_init ();
|
||||
|
||||
/*
|
||||
* Begin by parsing and handling command line arguments.
|
||||
* The data path is also initialized here.
|
||||
*/
|
||||
non_interactive = parse_args(argc, argv, &conf);
|
||||
non_interactive = parse_args (argc, argv, &conf);
|
||||
if (non_interactive)
|
||||
return (EXIT_SUCCESS);
|
||||
|
||||
/* Begin of interactive mode with ncurses interface. */
|
||||
sigs_init(&sigact); /* signal handling init */
|
||||
initscr(); /* start the curses mode */
|
||||
cbreak(); /* control chars generate a signal */
|
||||
noecho(); /* controls echoing of typed chars */
|
||||
curs_set(0); /* make cursor invisible */
|
||||
calendar_set_current_date();
|
||||
notify_init_vars();
|
||||
wins_get_config();
|
||||
sigs_init (&sigact); /* signal handling init */
|
||||
initscr (); /* start the curses mode */
|
||||
cbreak (); /* control chars generate a signal */
|
||||
noecho (); /* controls echoing of typed chars */
|
||||
curs_set (0); /* make cursor invisible */
|
||||
calendar_set_current_date ();
|
||||
notify_init_vars ();
|
||||
wins_get_config ();
|
||||
|
||||
/* Check if terminal supports color. */
|
||||
if (has_colors()) {
|
||||
if (has_colors ())
|
||||
{
|
||||
colorize = true;
|
||||
background = COLOR_BLACK;
|
||||
foreground = COLOR_WHITE;
|
||||
start_color();
|
||||
start_color ();
|
||||
|
||||
#ifdef NCURSES_VERSION
|
||||
if (use_default_colors() != ERR) {
|
||||
if (use_default_colors () != ERR)
|
||||
{
|
||||
background = -1;
|
||||
foreground = -1;
|
||||
}
|
||||
#endif /* NCURSES_VERSION */
|
||||
|
||||
/* Color assignment */
|
||||
init_pair(COLR_RED, COLOR_RED, background);
|
||||
init_pair(COLR_GREEN, COLOR_GREEN, background);
|
||||
init_pair(COLR_YELLOW, COLOR_YELLOW, background);
|
||||
init_pair(COLR_BLUE, COLOR_BLUE, background);
|
||||
init_pair(COLR_MAGENTA, COLOR_MAGENTA, background);
|
||||
init_pair(COLR_CYAN, COLOR_CYAN, background);
|
||||
init_pair(COLR_DEFAULT, foreground, background);
|
||||
init_pair(COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
|
||||
init_pair(COLR_CUSTOM, COLOR_RED, background);
|
||||
init_pair (COLR_RED, COLOR_RED, background);
|
||||
init_pair (COLR_GREEN, COLOR_GREEN, background);
|
||||
init_pair (COLR_YELLOW, COLOR_YELLOW, background);
|
||||
init_pair (COLR_BLUE, COLOR_BLUE, background);
|
||||
init_pair (COLR_MAGENTA, COLOR_MAGENTA, background);
|
||||
init_pair (COLR_CYAN, COLOR_CYAN, background);
|
||||
init_pair (COLR_DEFAULT, foreground, background);
|
||||
init_pair (COLR_HIGH, COLOR_BLACK, COLOR_GREEN);
|
||||
init_pair (COLR_CUSTOM, COLOR_RED, background);
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
colorize = false;
|
||||
background = COLOR_BLACK;
|
||||
}
|
||||
|
||||
vars_init(&conf);
|
||||
wins_init();
|
||||
wins_slctd_init();
|
||||
notify_init_bar();
|
||||
reset_status_page();
|
||||
vars_init (&conf);
|
||||
wins_init ();
|
||||
wins_slctd_init ();
|
||||
notify_init_bar ();
|
||||
reset_status_page ();
|
||||
|
||||
/*
|
||||
* Read the data from files : first the user
|
||||
* configuration (the display is then updated), and then
|
||||
* the todo list, appointments and events.
|
||||
*/
|
||||
no_data_file = io_check_data_files();
|
||||
custom_load_conf(&conf, background);
|
||||
erase_status_bar();
|
||||
io_load_todo();
|
||||
io_load_app();
|
||||
wins_reinit();
|
||||
if (notify_bar()) {
|
||||
notify_start_main_thread();
|
||||
notify_check_next_app();
|
||||
no_data_file = io_check_data_files ();
|
||||
custom_load_conf (&conf, background);
|
||||
erase_status_bar ();
|
||||
io_load_todo ();
|
||||
io_load_app ();
|
||||
wins_reinit ();
|
||||
if (notify_bar ())
|
||||
{
|
||||
notify_start_main_thread ();
|
||||
notify_check_next_app ();
|
||||
}
|
||||
wins_update();
|
||||
io_startup_screen(conf.skip_system_dialogs, no_data_file);
|
||||
inday = *day_process_storage(0, day_changed, &inday);
|
||||
wins_slctd_set(CAL);
|
||||
wins_update();
|
||||
calendar_start_date_thread();
|
||||
wins_update ();
|
||||
io_startup_screen (conf.skip_system_dialogs, no_data_file);
|
||||
inday = *day_process_storage (0, day_changed, &inday);
|
||||
wins_slctd_set (CAL);
|
||||
wins_update ();
|
||||
calendar_start_date_thread ();
|
||||
|
||||
/* User input */
|
||||
for (;;) {
|
||||
|
||||
for (;;)
|
||||
{
|
||||
do_update = true;
|
||||
ch = wgetch(win[STA].p);
|
||||
|
||||
switch (ch) {
|
||||
|
||||
ch = wgetch (win[STA].p);
|
||||
switch (ch)
|
||||
{
|
||||
case ERR:
|
||||
do_update = false;
|
||||
break;
|
||||
|
||||
case CTRL('R'):
|
||||
case CTRL ('R'):
|
||||
case KEY_RESIZE:
|
||||
do_update = false;
|
||||
wins_reset();
|
||||
wins_reset ();
|
||||
break;
|
||||
|
||||
case 9: /* The TAB key was hit. */
|
||||
reset_status_page();
|
||||
reset_status_page ();
|
||||
/* Save previously highlighted event. */
|
||||
switch (wins_slctd()) {
|
||||
switch (wins_slctd ())
|
||||
{
|
||||
case TOD:
|
||||
sav_hilt_tod = todo_hilt();
|
||||
todo_hilt_set(0);
|
||||
sav_hilt_tod = todo_hilt ();
|
||||
todo_hilt_set (0);
|
||||
break;
|
||||
case APP:
|
||||
sav_hilt_app = apoint_hilt();
|
||||
apoint_hilt_set(0);
|
||||
sav_hilt_app = apoint_hilt ();
|
||||
apoint_hilt_set (0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
wins_slctd_next();
|
||||
wins_slctd_next ();
|
||||
|
||||
/* Select the event to highlight. */
|
||||
switch (wins_slctd()) {
|
||||
switch (wins_slctd ())
|
||||
{
|
||||
case TOD:
|
||||
if ((sav_hilt_tod == 0) && (todo_nb() != 0))
|
||||
todo_hilt_set(1);
|
||||
if ((sav_hilt_tod == 0) && (todo_nb () != 0))
|
||||
todo_hilt_set (1);
|
||||
else
|
||||
todo_hilt_set(sav_hilt_tod);
|
||||
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);
|
||||
if ((sav_hilt_app == 0)
|
||||
&& ((inday.nb_events + inday.nb_apoints) != 0))
|
||||
apoint_hilt_set (1);
|
||||
else
|
||||
apoint_hilt_set(sav_hilt_app);
|
||||
apoint_hilt_set (sav_hilt_app);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -213,89 +219,91 @@ main(int argc, char **argv)
|
||||
|
||||
case 'O':
|
||||
case 'o':
|
||||
other_status_page(wins_slctd());
|
||||
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);
|
||||
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 :"));
|
||||
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) {
|
||||
erase_status_bar ();
|
||||
config_bar ();
|
||||
while ((ch = wgetch (win[STA].p)) != 'q')
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'C':
|
||||
case 'c':
|
||||
if (has_colors())
|
||||
custom_color_config();
|
||||
else {
|
||||
if (has_colors ())
|
||||
custom_color_config ();
|
||||
else
|
||||
{
|
||||
colorize = false;
|
||||
erase_status_bar();
|
||||
mvwprintw(win[STA].p, 0, 0,
|
||||
_(no_color_support));
|
||||
wgetch(win[STA].p);
|
||||
erase_status_bar ();
|
||||
mvwprintw (win[STA].p, 0, 0, _(no_color_support));
|
||||
wgetch (win[STA].p);
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
case 'l':
|
||||
layout_config();
|
||||
layout_config ();
|
||||
break;
|
||||
case 'G':
|
||||
case 'g':
|
||||
custom_general_config(&conf);
|
||||
custom_general_config (&conf);
|
||||
break;
|
||||
case 'N':
|
||||
case 'n':
|
||||
notify_config_bar();
|
||||
notify_config_bar ();
|
||||
break;
|
||||
}
|
||||
wins_reset();
|
||||
wins_update();
|
||||
wins_reset ();
|
||||
wins_update ();
|
||||
do_storage = true;
|
||||
erase_status_bar();
|
||||
config_bar();
|
||||
erase_status_bar ();
|
||||
config_bar ();
|
||||
}
|
||||
wins_update();
|
||||
wins_update ();
|
||||
break;
|
||||
|
||||
case CTRL('A'): /* Add an app, whatever panel selected */
|
||||
apoint_add();
|
||||
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();
|
||||
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()) {
|
||||
switch (wins_slctd ())
|
||||
{
|
||||
case APP:
|
||||
apoint_add();
|
||||
apoint_add ();
|
||||
do_storage = true;
|
||||
break;
|
||||
case TOD:
|
||||
todo_new_item();
|
||||
if (todo_hilt() == 0 && todo_nb() == 1)
|
||||
todo_hilt_increase();
|
||||
todo_new_item ();
|
||||
if (todo_hilt () == 0 && todo_nb () == 1)
|
||||
todo_hilt_increase ();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -304,121 +312,126 @@ main(int argc, char **argv)
|
||||
|
||||
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();
|
||||
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);
|
||||
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);
|
||||
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();
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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();
|
||||
status_bar ();
|
||||
help_screen ();
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
case 's': /* Save function */
|
||||
io_save_cal(&conf);
|
||||
io_save_cal (&conf);
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
case 'x': /* Export function */
|
||||
io_export_data(IO_EXPORT_INTERACTIVE, &conf);
|
||||
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')) {
|
||||
case CTRL ('L'):
|
||||
if (wins_slctd () == CAL || ch == CTRL ('L'))
|
||||
{
|
||||
do_storage = true;
|
||||
day_changed = true;
|
||||
calendar_move(RIGHT);
|
||||
calendar_move (RIGHT);
|
||||
}
|
||||
break;
|
||||
|
||||
case (260): /* left arrow */
|
||||
case ('H'):
|
||||
case ('h'):
|
||||
case CTRL('H'):
|
||||
if (wins_slctd() == CAL || ch == CTRL('H')) {
|
||||
case CTRL ('H'):
|
||||
if (wins_slctd () == CAL || ch == CTRL ('H'))
|
||||
{
|
||||
do_storage = true;
|
||||
day_changed = true;
|
||||
calendar_move(LEFT);
|
||||
calendar_move (LEFT);
|
||||
}
|
||||
break;
|
||||
|
||||
case (259): /* up arrow */
|
||||
case ('K'):
|
||||
case ('k'):
|
||||
case CTRL('K'):
|
||||
if (wins_slctd() == CAL || ch == CTRL('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();
|
||||
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;
|
||||
@ -426,24 +439,26 @@ main(int argc, char **argv)
|
||||
case (258): /* down arrow */
|
||||
case ('J'):
|
||||
case ('j'):
|
||||
case CTRL('J'):
|
||||
if (wins_slctd() == CAL || ch == CTRL('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);
|
||||
calendar_move (DOWN);
|
||||
}
|
||||
if ((wins_slctd() == TOD) &&
|
||||
(todo_hilt() < todo_nb())) {
|
||||
todo_hilt_increase();
|
||||
if (todo_hilt_pos() == win[TOD].h - 4)
|
||||
todo_first_increase();
|
||||
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;
|
||||
@ -451,19 +466,22 @@ main(int argc, char **argv)
|
||||
case ('Q'): /* Quit calcurse :( */
|
||||
case ('q'):
|
||||
if (conf.auto_save)
|
||||
io_save_cal(&conf);
|
||||
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();
|
||||
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);
|
||||
}
|
||||
else
|
||||
exit_calcurse (EXIT_SUCCESS);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -471,19 +489,21 @@ main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_storage) {
|
||||
inday = *day_process_storage(calendar_get_slctd_day(),
|
||||
if (do_storage)
|
||||
{
|
||||
inday = *day_process_storage (calendar_get_slctd_day (),
|
||||
day_changed, &inday);
|
||||
do_storage = !do_storage;
|
||||
if (day_changed) {
|
||||
if (day_changed)
|
||||
{
|
||||
sav_hilt_app = 0;
|
||||
day_changed = !day_changed;
|
||||
if ((wins_slctd() == APP) &&
|
||||
if ((wins_slctd () == APP) &&
|
||||
(inday.nb_events + inday.nb_apoints != 0))
|
||||
apoint_hilt_set(1);
|
||||
apoint_hilt_set (1);
|
||||
}
|
||||
}
|
||||
if (do_update)
|
||||
wins_update();
|
||||
wins_update ();
|
||||
}
|
||||
}
|
||||
|
354
src/calendar.c
354
src/calendar.c
@ -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
|
||||
@ -63,62 +63,65 @@ static pthread_t calendar_t_date;
|
||||
|
||||
/* Thread needed to update current date in calendar. */
|
||||
static void *
|
||||
calendar_date_thread(void *arg)
|
||||
calendar_date_thread (void *arg)
|
||||
{
|
||||
time_t now, tomorrow;
|
||||
|
||||
for (;;) {
|
||||
tomorrow = (time_t)(get_today() + DAYINSEC);
|
||||
for (;;)
|
||||
{
|
||||
tomorrow = (time_t) (get_today () + DAYINSEC);
|
||||
|
||||
while ((now = time(NULL)) < tomorrow) {
|
||||
sleep(tomorrow - now);
|
||||
while ((now = time (NULL)) < tomorrow)
|
||||
{
|
||||
sleep (tomorrow - now);
|
||||
}
|
||||
|
||||
calendar_set_current_date();
|
||||
calendar_update_panel(win[CAL].p);
|
||||
calendar_set_current_date ();
|
||||
calendar_update_panel (win[CAL].p);
|
||||
}
|
||||
|
||||
pthread_exit((void*) 0);
|
||||
pthread_exit ((void *) 0);
|
||||
}
|
||||
|
||||
/* Launch the calendar date thread. */
|
||||
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;
|
||||
}
|
||||
|
||||
/* Stop the calendar date thread. */
|
||||
void
|
||||
calendar_stop_date_thread(void)
|
||||
calendar_stop_date_thread (void)
|
||||
{
|
||||
pthread_cancel(calendar_t_date);
|
||||
pthread_cancel (calendar_t_date);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set static variable today to current date */
|
||||
void
|
||||
calendar_set_current_date(void)
|
||||
calendar_set_current_date (void)
|
||||
{
|
||||
time_t timer;
|
||||
struct tm *tm;
|
||||
|
||||
timer = time(NULL);
|
||||
tm = localtime(&timer);
|
||||
timer = time (NULL);
|
||||
tm = localtime (&timer);
|
||||
|
||||
pthread_mutex_lock(&date_thread_mutex);
|
||||
pthread_mutex_lock (&date_thread_mutex);
|
||||
today.dd = tm->tm_mday;
|
||||
today.mm = tm->tm_mon + 1;
|
||||
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. */
|
||||
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;
|
||||
break;
|
||||
@ -126,7 +129,7 @@ calendar_set_first_day_of_week(wday_e first_day)
|
||||
week_begins_on_monday = true;
|
||||
break;
|
||||
default:
|
||||
fputs(_("ERROR in calendar_set_first_day_of_week\n"), stderr);
|
||||
fputs (_("ERROR in calendar_set_first_day_of_week\n"), stderr);
|
||||
week_begins_on_monday = false;
|
||||
/* NOTREACHED */
|
||||
}
|
||||
@ -134,84 +137,84 @@ calendar_set_first_day_of_week(wday_e first_day)
|
||||
|
||||
/* Swap first day of week in calendar. */
|
||||
void
|
||||
calendar_change_first_day_of_week(void)
|
||||
calendar_change_first_day_of_week (void)
|
||||
{
|
||||
week_begins_on_monday = !week_begins_on_monday;
|
||||
}
|
||||
|
||||
/* Return true if week begins on monday, false otherwise. */
|
||||
bool
|
||||
calendar_week_begins_on_monday(void)
|
||||
calendar_week_begins_on_monday (void)
|
||||
{
|
||||
return (week_begins_on_monday);
|
||||
}
|
||||
|
||||
/* Fill in the given variable with the current date. */
|
||||
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;
|
||||
pthread_mutex_unlock(&date_thread_mutex);
|
||||
pthread_mutex_unlock (&date_thread_mutex);
|
||||
}
|
||||
|
||||
/* This is to start at the current date in calendar. */
|
||||
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 */
|
||||
date_t *
|
||||
calendar_get_slctd_day(void)
|
||||
calendar_get_slctd_day (void)
|
||||
{
|
||||
return (&slctd_day);
|
||||
}
|
||||
|
||||
/* Returned value represents the selected day in calendar (in seconds) */
|
||||
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
|
||||
isBissextile(unsigned year)
|
||||
isBissextile (unsigned year)
|
||||
{
|
||||
return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
|
||||
}
|
||||
|
||||
static unsigned
|
||||
months_to_days(unsigned month)
|
||||
months_to_days (unsigned month)
|
||||
{
|
||||
return ((month * 3057 - 3007) / 100);
|
||||
}
|
||||
|
||||
|
||||
static long
|
||||
years_to_days(unsigned year)
|
||||
years_to_days (unsigned year)
|
||||
{
|
||||
return (year * 365L + year / 4 - year / 100 + year / 400);
|
||||
}
|
||||
|
||||
static long
|
||||
ymd_to_scalar(unsigned year, unsigned month, unsigned day)
|
||||
ymd_to_scalar (unsigned year, unsigned month, unsigned day)
|
||||
{
|
||||
long scalar;
|
||||
|
||||
scalar = day + months_to_days(month);
|
||||
scalar = day + months_to_days (month);
|
||||
if (month > 2)
|
||||
scalar -= isBissextile(year) ? 1 : 2;
|
||||
scalar -= isBissextile (year) ? 1 : 2;
|
||||
year--;
|
||||
scalar += years_to_days(year);
|
||||
scalar += years_to_days (year);
|
||||
|
||||
return (scalar);
|
||||
}
|
||||
|
||||
/* Function used to display the calendar panel. */
|
||||
void
|
||||
calendar_update_panel(WINDOW *cwin)
|
||||
calendar_update_panel (WINDOW *cwin)
|
||||
{
|
||||
date_t current_day, check_day;
|
||||
int c_day, c_day_1, day_1_sav, numdays, j;
|
||||
@ -222,11 +225,11 @@ calendar_update_panel(WINDOW *cwin)
|
||||
int sunday_first = 0;
|
||||
|
||||
/* inits */
|
||||
calendar_store_current_date(¤t_day);
|
||||
erase_window_part(cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
|
||||
calendar_store_current_date (¤t_day);
|
||||
erase_window_part (cwin, 1, title_lines, CALWIDTH - 2, CALHEIGHT - 2);
|
||||
mo = slctd_day.mm;
|
||||
yr = slctd_day.yyyy;
|
||||
if (!calendar_week_begins_on_monday())
|
||||
if (!calendar_week_begins_on_monday ())
|
||||
sunday_first = 1;
|
||||
|
||||
/* offset for centering calendar in window */
|
||||
@ -235,93 +238,93 @@ calendar_update_panel(WINDOW *cwin)
|
||||
|
||||
/* checking the number of days in february */
|
||||
numdays = days[mo - 1];
|
||||
if (2 == mo && isBissextile(yr))
|
||||
if (2 == mo && isBissextile (yr))
|
||||
++numdays;
|
||||
|
||||
/*
|
||||
* the first calendar day will be monday or sunday, depending on
|
||||
* 'week_begins_on_monday' value
|
||||
*/
|
||||
c_day_1 =
|
||||
(int)((ymd_to_scalar(yr, mo, 1 + sunday_first) - (long)1) % 7L);
|
||||
c_day_1 = (int) ((ymd_to_scalar (yr, mo, 1 + sunday_first) - (long) 1) % 7L);
|
||||
|
||||
/* Write the current month and year on top of the calendar */
|
||||
custom_apply_attr(cwin, ATTR_HIGH);
|
||||
mvwprintw(cwin, ofs_y,
|
||||
(CALWIDTH - (strlen(_(monthnames[mo - 1])) + 5)) / 2,
|
||||
custom_apply_attr (cwin, ATTR_HIGH);
|
||||
mvwprintw (cwin, ofs_y, (CALWIDTH - (strlen (_(monthnames[mo - 1])) + 5)) / 2,
|
||||
"%s %d", _(monthnames[mo - 1]), slctd_day.yyyy);
|
||||
custom_remove_attr(cwin, ATTR_HIGH);
|
||||
custom_remove_attr (cwin, ATTR_HIGH);
|
||||
++ofs_y;
|
||||
|
||||
/* print the days, with regards to the first day of the week */
|
||||
custom_apply_attr(cwin, ATTR_HIGH);
|
||||
for (j = 0; j < 7; j++) {
|
||||
mvwprintw(cwin, ofs_y, ofs_x + 4 * j, "%s",
|
||||
custom_apply_attr (cwin, ATTR_HIGH);
|
||||
for (j = 0; j < 7; j++)
|
||||
{
|
||||
mvwprintw (cwin, ofs_y, ofs_x + 4 * j, "%s",
|
||||
_(daynames[1 + j - sunday_first]));
|
||||
}
|
||||
custom_remove_attr(cwin, ATTR_HIGH);
|
||||
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) {
|
||||
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);
|
||||
item_this_day = day_check_if_item (check_day);
|
||||
|
||||
/* Go to next line, the week is over. */
|
||||
if (!c_day_1 && 1 != c_day) {
|
||||
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,
|
||||
&& 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);
|
||||
|
||||
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,7 +335,7 @@ calendar_update_panel(WINDOW *cwin)
|
||||
* with the newly selected date.
|
||||
*/
|
||||
void
|
||||
calendar_change_day(int datefmt)
|
||||
calendar_change_day (int datefmt)
|
||||
{
|
||||
#define LDAY 11
|
||||
char selected_day[LDAY] = "";
|
||||
@ -341,46 +344,44 @@ calendar_change_day(int datefmt)
|
||||
int dday, dmonth, dyear;
|
||||
int wrong_day = 1;
|
||||
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 "
|
||||
"(should be between 01/01/1902 and 12/31/2037)");
|
||||
char *mesg_line2 = _("Press [ENTER] to continue");
|
||||
char *request_date =
|
||||
"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)
|
||||
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);
|
||||
|
||||
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) {
|
||||
|
||||
}
|
||||
else if (strlen (selected_day) != LDAY - 1)
|
||||
{
|
||||
wrong_day = 1;
|
||||
|
||||
} else if (parse_date(selected_day, datefmt,
|
||||
&dyear, &dmonth, &dday)) {
|
||||
|
||||
}
|
||||
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);
|
||||
if (wrong_day)
|
||||
{
|
||||
status_mesg (mesg_line1, mesg_line2);
|
||||
wgetch (win[STA].p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -393,7 +394,7 @@ calendar_change_day(int datefmt)
|
||||
* Returns 0 on success, 1 otherwise.
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -401,56 +402,58 @@ date_change(struct tm *date, int delta_month, int delta_day)
|
||||
t.tm_mon += delta_month;
|
||||
t.tm_mday += delta_day;
|
||||
|
||||
if (mktime(&t) == -1)
|
||||
if (mktime (&t) == -1)
|
||||
return (1);
|
||||
else {
|
||||
else
|
||||
{
|
||||
*date = t;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
calendar_move(move_t move)
|
||||
calendar_move (move_t move)
|
||||
{
|
||||
int ret;
|
||||
struct tm t;
|
||||
|
||||
memset(&t, 0, sizeof(struct tm));
|
||||
memset (&t, 0, sizeof (struct tm));
|
||||
t.tm_mday = slctd_day.dd;
|
||||
t.tm_mon = slctd_day.mm - 1;
|
||||
t.tm_year = slctd_day.yyyy - 1900;
|
||||
|
||||
switch (move) {
|
||||
switch (move)
|
||||
{
|
||||
case UP:
|
||||
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1) &&
|
||||
(slctd_day.yyyy == 1902))
|
||||
if ((slctd_day.dd <= 7) && (slctd_day.mm == 1)
|
||||
&& (slctd_day.yyyy == 1902))
|
||||
return;
|
||||
ret = date_change(&t, 0, -WEEKINDAYS);
|
||||
ret = date_change (&t, 0, -WEEKINDAYS);
|
||||
break;
|
||||
case DOWN:
|
||||
if ((slctd_day.dd > days[slctd_day.mm - 1] - 7)
|
||||
&& (slctd_day.mm == 12) && (slctd_day.yyyy == 2037))
|
||||
return;
|
||||
ret = date_change(&t, 0, WEEKINDAYS);
|
||||
ret = date_change (&t, 0, WEEKINDAYS);
|
||||
break;
|
||||
case LEFT:
|
||||
if ((slctd_day.dd == 1) && (slctd_day.mm == 1) &&
|
||||
(slctd_day.yyyy == 1902))
|
||||
if ((slctd_day.dd == 1) && (slctd_day.mm == 1)
|
||||
&& (slctd_day.yyyy == 1902))
|
||||
return;
|
||||
ret = date_change(&t, 0, -1);
|
||||
ret = date_change (&t, 0, -1);
|
||||
break;
|
||||
case RIGHT:
|
||||
if ((slctd_day.dd == 31) && (slctd_day.mm == 12) &&
|
||||
(slctd_day.yyyy == 2037))
|
||||
if ((slctd_day.dd == 31) && (slctd_day.mm == 12)
|
||||
&& (slctd_day.yyyy == 2037))
|
||||
return;
|
||||
ret = date_change(&t, 0, 1);
|
||||
ret = date_change (&t, 0, 1);
|
||||
break;
|
||||
default:
|
||||
ret = 1;
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
if (ret == 0)
|
||||
{
|
||||
slctd_day.dd = t.tm_mday;
|
||||
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
|
||||
*/
|
||||
static double
|
||||
dtor(double deg)
|
||||
dtor (double deg)
|
||||
{
|
||||
return(deg * M_PI / 180);
|
||||
return (deg * M_PI / 180);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -509,7 +512,7 @@ dtor(double deg)
|
||||
* adjust value so 0 <= deg <= 360
|
||||
*/
|
||||
static void
|
||||
adj360(double *deg)
|
||||
adj360 (double *deg)
|
||||
{
|
||||
for (;;)
|
||||
if (*deg < 0.0)
|
||||
@ -525,35 +528,35 @@ adj360(double *deg)
|
||||
* return phase of the moon
|
||||
*/
|
||||
static double
|
||||
potm(double days)
|
||||
potm (double days)
|
||||
{
|
||||
double N, Msol, Ec, LambdaSol, l, Mm, Ev, Ac, A3, Mmprime;
|
||||
double A4, lprime, V, ldprime, D, Nm;
|
||||
|
||||
N = 360.0 * days / 365.242191; /* sec 46 #3 */
|
||||
adj360(&N);
|
||||
adj360 (&N);
|
||||
Msol = N + EPSILONg - RHOg; /* sec 46 #4 */
|
||||
adj360(&Msol);
|
||||
Ec = 360 / M_PI * ECCEN * sin(dtor(Msol)); /* sec 46 #5 */
|
||||
adj360 (&Msol);
|
||||
Ec = 360 / M_PI * ECCEN * sin (dtor (Msol)); /* sec 46 #5 */
|
||||
LambdaSol = N + Ec + EPSILONg; /* sec 46 #6 */
|
||||
adj360(&LambdaSol);
|
||||
adj360 (&LambdaSol);
|
||||
l = 13.1763966 * days + lzero; /* sec 65 #4 */
|
||||
adj360(&l);
|
||||
adj360 (&l);
|
||||
Mm = l - (0.1114041 * days) - Pzero; /* sec 65 #5 */
|
||||
adj360(&Mm);
|
||||
adj360 (&Mm);
|
||||
Nm = Nzero - (0.0529539 * days); /* sec 65 #6 */
|
||||
adj360(&Nm);
|
||||
Ev = 1.2739 * sin(dtor(2*(l - LambdaSol) - Mm)); /* sec 65 #7 */
|
||||
Ac = 0.1858 * sin(dtor(Msol)); /* sec 65 #8 */
|
||||
A3 = 0.37 * sin(dtor(Msol));
|
||||
adj360 (&Nm);
|
||||
Ev = 1.2739 * sin (dtor (2 * (l - LambdaSol) - Mm)); /* sec 65 #7 */
|
||||
Ac = 0.1858 * sin (dtor (Msol)); /* sec 65 #8 */
|
||||
A3 = 0.37 * sin (dtor (Msol));
|
||||
Mmprime = Mm + Ev - Ac - A3; /* sec 65 #9 */
|
||||
Ec = 6.2886 * sin(dtor(Mmprime)); /* sec 65 #10 */
|
||||
A4 = 0.214 * sin(dtor(2 * Mmprime)); /* sec 65 #11 */
|
||||
Ec = 6.2886 * sin (dtor (Mmprime)); /* sec 65 #10 */
|
||||
A4 = 0.214 * sin (dtor (2 * Mmprime)); /* sec 65 #11 */
|
||||
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 */
|
||||
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,7 +571,7 @@ potm(double days)
|
||||
*
|
||||
*/
|
||||
static double
|
||||
pom(time_t tmpt)
|
||||
pom (time_t tmpt)
|
||||
{
|
||||
struct tm *GMT;
|
||||
double days;
|
||||
@ -576,16 +579,16 @@ pom(time_t tmpt)
|
||||
pom_e pom;
|
||||
|
||||
pom = NO_POM;
|
||||
GMT = gmtime(&tmpt);
|
||||
days = (GMT->tm_yday + 1) + ((GMT->tm_hour +
|
||||
(GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0);
|
||||
GMT = gmtime (&tmpt);
|
||||
days = (GMT->tm_yday + 1) + ((GMT->tm_hour + (GMT->tm_min / 60.0) +
|
||||
(GMT->tm_sec / 3600.0)) / 24.0);
|
||||
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 */
|
||||
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.
|
||||
*/
|
||||
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;
|
||||
double pom_today, relative_pom, pom_yesterday, pom_tomorrow;
|
||||
const double half = 50.0;
|
||||
|
||||
pom_yesterday = pom(date);
|
||||
pom_today = pom(date + DAYINSEC);
|
||||
relative_pom = abs(pom_today - half);
|
||||
pom_tomorrow = pom(date + 2 * DAYINSEC);
|
||||
pom_yesterday = pom (date);
|
||||
pom_today = pom (date + DAYINSEC);
|
||||
relative_pom = abs (pom_today - half);
|
||||
pom_tomorrow = pom (date + 2 * DAYINSEC);
|
||||
if (pom_today > pom_yesterday && pom_today > pom_tomorrow)
|
||||
phase = FULL_MOON;
|
||||
else if (pom_today < pom_yesterday && pom_today < pom_tomorrow)
|
||||
phase = NEW_MOON;
|
||||
else if (relative_pom < abs(pom_yesterday - half) &&
|
||||
relative_pom < abs(pom_tomorrow - half))
|
||||
phase = (pom_tomorrow > pom_today) ?
|
||||
FIRST_QUARTER : LAST_QUARTER;
|
||||
else if (relative_pom < abs (pom_yesterday - half)
|
||||
&& relative_pom < abs (pom_tomorrow - half))
|
||||
phase = (pom_tomorrow > pom_today) ? FIRST_QUARTER : LAST_QUARTER;
|
||||
|
||||
return (pom_pict[phase]);
|
||||
}
|
||||
|
@ -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
|
||||
@ -34,7 +34,8 @@
|
||||
#define CALHEIGHT 12
|
||||
#define CALWIDTH 30
|
||||
|
||||
typedef enum { /* days of week */
|
||||
typedef enum
|
||||
{ /* days of week */
|
||||
SUNDAY,
|
||||
MONDAY,
|
||||
TUESDAY,
|
||||
@ -43,44 +44,51 @@ typedef enum { /* days of week */
|
||||
FRIDAY,
|
||||
SATURDAY,
|
||||
WDAYS
|
||||
} wday_e;
|
||||
}
|
||||
wday_e;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
unsigned dd;
|
||||
unsigned mm;
|
||||
unsigned yyyy;
|
||||
} date_t;
|
||||
}
|
||||
date_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
NO_POM,
|
||||
FIRST_QUARTER,
|
||||
FULL_MOON,
|
||||
LAST_QUARTER,
|
||||
NEW_MOON,
|
||||
MOON_PHASES
|
||||
} pom_e;
|
||||
}
|
||||
pom_e;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT,
|
||||
MOVES
|
||||
} move_t;
|
||||
}
|
||||
move_t;
|
||||
|
||||
void calendar_start_date_thread(void);
|
||||
void calendar_stop_date_thread(void);
|
||||
void calendar_set_current_date(void);
|
||||
void calendar_set_first_day_of_week(wday_e);
|
||||
void calendar_change_first_day_of_week(void);
|
||||
bool calendar_week_begins_on_monday(void);
|
||||
void calendar_store_current_date(date_t *);
|
||||
void calendar_init_slctd_day(void);
|
||||
date_t *calendar_get_slctd_day(void);
|
||||
long calendar_get_slctd_day_sec(void);
|
||||
void calendar_update_panel(WINDOW *);
|
||||
void calendar_change_day(int datefmt);
|
||||
void calendar_move(move_t);
|
||||
char *calendar_get_pom(time_t);
|
||||
void calendar_start_date_thread (void);
|
||||
void calendar_stop_date_thread (void);
|
||||
void calendar_set_current_date (void);
|
||||
void calendar_set_first_day_of_week (wday_e);
|
||||
void calendar_change_first_day_of_week (void);
|
||||
bool calendar_week_begins_on_monday (void);
|
||||
void calendar_store_current_date (date_t *);
|
||||
void calendar_init_slctd_day (void);
|
||||
date_t *calendar_get_slctd_day (void);
|
||||
long calendar_get_slctd_day_sec (void);
|
||||
void calendar_update_panel (WINDOW *);
|
||||
void calendar_change_day (int);
|
||||
void calendar_move (move_t);
|
||||
char *calendar_get_pom (time_t);
|
||||
|
||||
#endif /* CALCURSE_CALENDAR_H */
|
||||
|
643
src/custom.c
643
src/custom.c
File diff suppressed because it is too large
Load Diff
31
src/custom.h
31
src/custom.h
@ -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
|
||||
@ -32,7 +32,8 @@
|
||||
|
||||
#define NBUSERCOLORS 6
|
||||
|
||||
enum { /* Color pairs */
|
||||
enum
|
||||
{ /* Color pairs */
|
||||
COLR_RED = 1,
|
||||
COLR_GREEN,
|
||||
COLR_YELLOW,
|
||||
@ -44,7 +45,8 @@ enum { /* Color pairs */
|
||||
COLR_CUSTOM
|
||||
};
|
||||
|
||||
enum { /* Configuration variables */
|
||||
enum
|
||||
{ /* Configuration variables */
|
||||
CUSTOM_CONF_NOVARIABLE,
|
||||
CUSTOM_CONF_AUTOSAVE,
|
||||
CUSTOM_CONF_CONFIRMQUIT,
|
||||
@ -64,20 +66,21 @@ enum { /* Configuration variables */
|
||||
CUSTOM_CONF_VARIABLES
|
||||
};
|
||||
|
||||
struct attribute_s {
|
||||
struct attribute_s
|
||||
{
|
||||
int color[7];
|
||||
int nocolor[7];
|
||||
};
|
||||
|
||||
void custom_init_attr(void);
|
||||
void custom_apply_attr(WINDOW *, int);
|
||||
void custom_remove_attr(WINDOW *, int);
|
||||
void custom_load_conf(conf_t *, int);
|
||||
void config_bar(void);
|
||||
void layout_config(void);
|
||||
void custom_color_config(void);
|
||||
void custom_color_theme_name(char *);
|
||||
void custom_confwin_init(window_t *, char *);
|
||||
void custom_general_config(conf_t *);
|
||||
void custom_init_attr (void);
|
||||
void custom_apply_attr (WINDOW *, int);
|
||||
void custom_remove_attr (WINDOW *, int);
|
||||
void custom_load_conf (conf_t *, int);
|
||||
void config_bar (void);
|
||||
void layout_config (void);
|
||||
void custom_color_config (void);
|
||||
void custom_color_theme_name (char *);
|
||||
void custom_confwin_init (window_t *, char *);
|
||||
void custom_general_config (conf_t *);
|
||||
|
||||
#endif /* CALCURSE_CUSTOM_H */
|
||||
|
36
src/day.h
36
src/day.h
@ -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
|
||||
@ -38,12 +38,15 @@
|
||||
#define RECUR_APPT 3
|
||||
#define APPT 4
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
unsigned nb_events;
|
||||
unsigned nb_apoints;
|
||||
} day_items_nb_t;
|
||||
}
|
||||
day_items_nb_t;
|
||||
|
||||
struct day_item_s {
|
||||
struct day_item_s
|
||||
{
|
||||
struct day_item_s *next;
|
||||
long start; /* seconds since 1 jan 1970 */
|
||||
long appt_dur; /* appointment duration in seconds */
|
||||
@ -55,23 +58,24 @@ struct day_item_s {
|
||||
char *note; /* note attached to item */
|
||||
};
|
||||
|
||||
struct day_saved_item_s {
|
||||
struct day_saved_item_s
|
||||
{
|
||||
char start[BUFSIZ];
|
||||
char end[BUFSIZ];
|
||||
char state;
|
||||
char type ;
|
||||
char type;
|
||||
char *mesg;
|
||||
};
|
||||
|
||||
day_items_nb_t *day_process_storage(date_t *, bool, day_items_nb_t *);
|
||||
void day_write_pad(long, int, int, int);
|
||||
void day_popup_item(void);
|
||||
int day_check_if_item(date_t);
|
||||
void day_edit_item(conf_t *);
|
||||
int day_erase_item(long, int, erase_flag_e);
|
||||
struct day_item_s *day_get_item(int);
|
||||
int day_item_nb(long, int, int);
|
||||
void day_edit_note(char *);
|
||||
void day_view_note(char *);
|
||||
day_items_nb_t *day_process_storage (date_t *, bool, day_items_nb_t *);
|
||||
void day_write_pad (long, int, int, int);
|
||||
void day_popup_item (void);
|
||||
int day_check_if_item (date_t);
|
||||
void day_edit_item (conf_t *);
|
||||
int day_erase_item (long, int, erase_flag_e);
|
||||
struct day_item_s *day_get_item (int);
|
||||
int day_item_nb (long, int, int);
|
||||
void day_edit_note (char *);
|
||||
void day_view_note (char *);
|
||||
|
||||
#endif /* CALCURSE_DAY_H */
|
||||
|
104
src/event.c
104
src/event.c
@ -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
|
||||
@ -37,68 +37,72 @@ struct event_s *eventlist;
|
||||
|
||||
/* Create a new event */
|
||||
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;
|
||||
o = (struct event_s *) malloc(sizeof(struct event_s));
|
||||
o->mesg = (char *) malloc(strlen(mesg) + 1);
|
||||
strncpy(o->mesg, mesg, strlen(mesg) + 1);
|
||||
o = (struct event_s *) malloc (sizeof (struct event_s));
|
||||
o->mesg = (char *) malloc (strlen (mesg) + 1);
|
||||
strncpy (o->mesg, mesg, strlen (mesg) + 1);
|
||||
o->day = day;
|
||||
o->id = id;
|
||||
o->note = (note != NULL) ? strdup(note) : NULL;
|
||||
o->note = (note != NULL) ? strdup (note) : NULL;
|
||||
i = &eventlist;
|
||||
for (;;) {
|
||||
if (*i == 0 || (*i)->day > day) {
|
||||
for (;;)
|
||||
{
|
||||
if (*i == 0 || (*i)->day > day)
|
||||
{
|
||||
o->next = *i;
|
||||
*i = o;
|
||||
break;
|
||||
}
|
||||
i = &(*i)->next;
|
||||
}
|
||||
return o;
|
||||
return (o);
|
||||
}
|
||||
|
||||
/* Check if the event belongs to the selected day */
|
||||
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) {
|
||||
return 1;
|
||||
if (i->day <= start + DAYINSEC && i->day > start)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Write to file the event in user-friendly format */
|
||||
void
|
||||
event_write(struct event_s *o, FILE * f)
|
||||
event_write (struct event_s *o, FILE *f)
|
||||
{
|
||||
struct tm *lt;
|
||||
time_t t;
|
||||
|
||||
t = o->day;
|
||||
lt = localtime(&t);
|
||||
fprintf(f, "%02u/%02u/%04u [%d] ",
|
||||
lt->tm_mon + 1, lt->tm_mday, 1900 + lt->tm_year, o->id);
|
||||
lt = localtime (&t);
|
||||
fprintf (f, "%02u/%02u/%04u [%d] ", lt->tm_mon + 1, lt->tm_mday,
|
||||
1900 + lt->tm_year, o->id);
|
||||
if (o->note != NULL)
|
||||
fprintf(f, ">%s ", o->note);
|
||||
fprintf(f, "%s\n", o->mesg);
|
||||
fprintf (f, ">%s ", o->note);
|
||||
fprintf (f, "%s\n", o->mesg);
|
||||
}
|
||||
|
||||
/* Load the events from file */
|
||||
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;
|
||||
char buf[MESG_MAXSIZE], *nl;
|
||||
time_t tstart, t;
|
||||
|
||||
t = time(NULL);
|
||||
lt = localtime(&t);
|
||||
t = time (NULL);
|
||||
lt = localtime (&t);
|
||||
|
||||
/* Read the event description */
|
||||
fgets(buf, MESG_MAXSIZE, f);
|
||||
nl = strchr(buf, '\n');
|
||||
if (nl) {
|
||||
fgets (buf, MESG_MAXSIZE, f);
|
||||
nl = strchr (buf, '\n');
|
||||
if (nl)
|
||||
{
|
||||
*nl = '\0';
|
||||
}
|
||||
start.tm_hour = 12;
|
||||
@ -108,53 +112,61 @@ event_scan(FILE * f, struct tm start, int id, char *note)
|
||||
start.tm_year -= 1900;
|
||||
start.tm_mon--;
|
||||
|
||||
tstart = mktime(&start);
|
||||
if (tstart == -1) {
|
||||
fputs(_("FATAL ERROR in event_scan: date error in the event\n"), stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
tstart = mktime (&start);
|
||||
if (tstart == -1)
|
||||
{
|
||||
fputs (_("FATAL ERROR in event_scan: date error in the event\n"),
|
||||
stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
return (event_new(buf, note, tstart, id));
|
||||
return (event_new (buf, note, tstart, id));
|
||||
}
|
||||
|
||||
/* Retrieve an event from the list, given the day and item position. */
|
||||
struct event_s *
|
||||
event_get(long day, int pos)
|
||||
event_get (long day, int pos)
|
||||
{
|
||||
struct event_s *o;
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
for (o = eventlist; o; o = o->next) {
|
||||
if (event_inday(o, day)) {
|
||||
for (o = eventlist; o; o = o->next)
|
||||
{
|
||||
if (event_inday (o, day))
|
||||
{
|
||||
if (n == pos)
|
||||
return o;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
fputs(_("FATAL ERROR in event_get: no such item\n"), stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
fputs (_("FATAL ERROR in event_get: no such item\n"), stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Delete an event from the list. */
|
||||
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;
|
||||
struct event_s *i, **iptr;
|
||||
|
||||
n = 0;
|
||||
iptr = &eventlist;
|
||||
for (i = eventlist; i != 0; i = i->next) {
|
||||
if (event_inday(i, start)) {
|
||||
if (n == num) {
|
||||
for (i = eventlist; i != 0; i = i->next)
|
||||
{
|
||||
if (event_inday (i, start))
|
||||
{
|
||||
if (n == num)
|
||||
{
|
||||
if (flag == ERASE_FORCE_ONLY_NOTE)
|
||||
erase_note(&i->note, flag);
|
||||
else {
|
||||
erase_note (&i->note, flag);
|
||||
else
|
||||
{
|
||||
*iptr = i->next;
|
||||
free(i->mesg);
|
||||
erase_note(&i->note, flag);
|
||||
free(i);
|
||||
free (i->mesg);
|
||||
erase_note (&i->note, flag);
|
||||
free (i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -163,6 +175,6 @@ event_delete_bynum(long start, unsigned num, erase_flag_e flag)
|
||||
iptr = &i->next;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
fputs(_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
fputs (_("FATAL ERROR in event_delete_bynum: no such event\n"), stderr);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
17
src/event.h
17
src/event.h
@ -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
|
||||
@ -32,7 +32,8 @@
|
||||
#define HRMIN_SIZE 6
|
||||
#define MESG_MAXSIZE 256
|
||||
|
||||
struct event_s {
|
||||
struct event_s
|
||||
{
|
||||
struct event_s *next;
|
||||
int id; /* event identifier */
|
||||
long day; /* seconds since 1 jan 1970 */
|
||||
@ -42,11 +43,11 @@ struct event_s {
|
||||
|
||||
extern struct event_s *eventlist;
|
||||
|
||||
struct event_s *event_new(char *, char *, long, int);
|
||||
unsigned event_inday(struct event_s *, long);
|
||||
void event_write(struct event_s *, FILE *);
|
||||
struct event_s *event_scan(FILE *, struct tm, int, char *);
|
||||
struct event_s *event_get(long, int);
|
||||
void event_delete_bynum(long, unsigned, erase_flag_e);
|
||||
struct event_s *event_new (char *, char *, long, int);
|
||||
unsigned event_inday (struct event_s *, long);
|
||||
void event_write (struct event_s *, FILE *);
|
||||
struct event_s *event_scan (FILE *, struct tm, int, char *);
|
||||
struct event_s *event_get (long, int);
|
||||
void event_delete_bynum (long, unsigned, erase_flag_e);
|
||||
|
||||
#endif /* CALCURSE_EVENT_H */
|
||||
|
266
src/help.c
266
src/help.c
@ -1,8 +1,8 @@
|
||||
/* $calcurse: help.c,v 1.21 2008/02/11 21:26:00 culot Exp $ */
|
||||
/* $calcurse: help.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
|
||||
|
||||
/*
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -35,7 +35,8 @@
|
||||
#include "utils.h"
|
||||
#include "notify.h"
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
HELP_MAIN,
|
||||
HELP_SAVE,
|
||||
HELP_EXPORT,
|
||||
@ -57,19 +58,22 @@ typedef enum {
|
||||
HELP_CREDITS,
|
||||
HELPSCREENS,
|
||||
NOPAGE
|
||||
} help_pages_e;
|
||||
}
|
||||
help_pages_e;
|
||||
|
||||
/* Returns the number of lines in an help text. */
|
||||
static int
|
||||
get_help_lines(char *text)
|
||||
get_help_lines (char *text)
|
||||
{
|
||||
int i;
|
||||
int nl = 0;
|
||||
|
||||
for (i = 0; text[i]; i++) {
|
||||
if (text[i] == '\n') nl++;
|
||||
for (i = 0; text[i]; i++)
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
nl++;
|
||||
}
|
||||
return nl + 1;
|
||||
return (nl + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -77,18 +81,18 @@ get_help_lines(char *text)
|
||||
* of lines that were written.
|
||||
*/
|
||||
static int
|
||||
write_help_pad(window_t *win, help_page_t *hpage)
|
||||
write_help_pad (window_t *win, help_page_t *hpage)
|
||||
{
|
||||
int nl_title = 0;
|
||||
int nl_text = 0;
|
||||
|
||||
nl_text = get_help_lines(hpage->text);
|
||||
nl_title = get_help_lines(hpage->title);
|
||||
erase_window_part(win->p, 0, 0, BUFSIZ, win->w);
|
||||
custom_apply_attr(win->p, ATTR_HIGHEST);
|
||||
mvwprintw(win->p, 0, 0, "%s", hpage->title);
|
||||
custom_remove_attr(win->p, ATTR_HIGHEST);
|
||||
mvwprintw(win->p, nl_title, 0, "%s", hpage->text);
|
||||
nl_text = get_help_lines (hpage->text);
|
||||
nl_title = get_help_lines (hpage->title);
|
||||
erase_window_part (win->p, 0, 0, BUFSIZ, win->w);
|
||||
custom_apply_attr (win->p, ATTR_HIGHEST);
|
||||
mvwprintw (win->p, 0, 0, "%s", hpage->title);
|
||||
custom_remove_attr (win->p, ATTR_HIGHEST);
|
||||
mvwprintw (win->p, nl_title, 0, "%s", hpage->text);
|
||||
return (nl_text + nl_title);
|
||||
}
|
||||
|
||||
@ -97,17 +101,17 @@ write_help_pad(window_t *win, help_page_t *hpage)
|
||||
* faster.
|
||||
*/
|
||||
static void
|
||||
help_wins_init(window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
help_wins_init (window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
{
|
||||
char label[BUFSIZ];
|
||||
|
||||
hwin->h = (notify_bar()) ? row - 3 : row - 2;
|
||||
hwin->p = newwin(hwin->h, col, 0, 0);
|
||||
hwin->h = (notify_bar ())? row - 3 : row - 2;
|
||||
hwin->p = newwin (hwin->h, col, 0, 0);
|
||||
hpad->w = col - 2 * PADOFFSET + 1;
|
||||
hpad->p = newpad(BUFSIZ, hpad->w);
|
||||
box(hwin->p, 0, 0);
|
||||
snprintf(label, BUFSIZ, _("CalCurse %s | help"), VERSION);
|
||||
wins_show(hwin->p, label);
|
||||
hpad->p = newpad (BUFSIZ, hpad->w);
|
||||
box (hwin->p, 0, 0);
|
||||
snprintf (label, BUFSIZ, _("CalCurse %s | help"), VERSION);
|
||||
wins_show (hwin->p, label);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -115,40 +119,40 @@ help_wins_init(window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
* size and placement.
|
||||
*/
|
||||
static void
|
||||
help_wins_reinit(window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
help_wins_reinit (window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
{
|
||||
delwin(hpad->p);
|
||||
delwin(hwin->p);
|
||||
wins_get_config();
|
||||
help_wins_init(hwin, hpad, PADOFFSET);
|
||||
delwin (hpad->p);
|
||||
delwin (hwin->p);
|
||||
wins_get_config ();
|
||||
help_wins_init (hwin, hpad, PADOFFSET);
|
||||
}
|
||||
|
||||
/* Reset the screen, needed when resizing terminal for example. */
|
||||
static void
|
||||
help_wins_reset(window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
help_wins_reset (window_t *hwin, window_t *hpad, const int PADOFFSET)
|
||||
{
|
||||
endwin();
|
||||
refresh();
|
||||
curs_set(0);
|
||||
delwin(win[STA].p);
|
||||
help_wins_reinit(hwin, hpad, PADOFFSET);
|
||||
win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
|
||||
keypad(win[STA].p, TRUE);
|
||||
if (notify_bar())
|
||||
notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y,
|
||||
win[NOT].x);
|
||||
status_bar();
|
||||
if (notify_bar())
|
||||
notify_update_bar();
|
||||
endwin ();
|
||||
refresh ();
|
||||
curs_set (0);
|
||||
delwin (win[STA].p);
|
||||
help_wins_reinit (hwin, hpad, PADOFFSET);
|
||||
win[STA].p = newwin (win[STA].h, win[STA].w, win[STA].y, win[STA].x);
|
||||
keypad (win[STA].p, TRUE);
|
||||
if (notify_bar ())
|
||||
notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
||||
status_bar ();
|
||||
if (notify_bar ())
|
||||
notify_update_bar ();
|
||||
}
|
||||
|
||||
/* Association between a key pressed and its corresponding help page. */
|
||||
static int
|
||||
wanted_page(int ch)
|
||||
wanted_page (int ch)
|
||||
{
|
||||
int page;
|
||||
|
||||
switch (ch) {
|
||||
switch (ch)
|
||||
{
|
||||
|
||||
case '?':
|
||||
page = HELP_MAIN;
|
||||
@ -158,13 +162,13 @@ wanted_page(int ch)
|
||||
page = HELP_FLAG;
|
||||
break;
|
||||
|
||||
case CTRL('r'):
|
||||
case CTRL('a'):
|
||||
case CTRL('t'):
|
||||
case CTRL('h'):
|
||||
case CTRL('j'):
|
||||
case CTRL('k'):
|
||||
case CTRL('l'):
|
||||
case CTRL ('r'):
|
||||
case CTRL ('a'):
|
||||
case CTRL ('t'):
|
||||
case CTRL ('h'):
|
||||
case CTRL ('j'):
|
||||
case CTRL ('k'):
|
||||
case CTRL ('l'):
|
||||
page = HELP_GENERAL;
|
||||
break;
|
||||
|
||||
@ -250,7 +254,7 @@ wanted_page(int ch)
|
||||
|
||||
/* Draws the help screen */
|
||||
void
|
||||
help_screen(void)
|
||||
help_screen (void)
|
||||
{
|
||||
window_t hwin;
|
||||
window_t hpad;
|
||||
@ -318,8 +322,9 @@ help_screen(void)
|
||||
hscr[HELP_VIEW].text =
|
||||
_("Pressing 'V' allows you to view the item you select in either the ToDo\n"
|
||||
"or Appointment panel.\n"
|
||||
"\nThis is usefull when an event description is longer than the available\n"
|
||||
"space to display it. If that is the case, the description will be\n"
|
||||
"\nThis is usefull when an event description is longer than the "
|
||||
"available\n space to display it. "
|
||||
"If that is the case, the description will be\n"
|
||||
"shortened and its end replaced by '...'. To be able to read the entire\n"
|
||||
"description, just press 'V' and a popup window will appear, containing\n"
|
||||
"the whole event.\n"
|
||||
@ -331,8 +336,8 @@ help_screen(void)
|
||||
_("Pressing 'Tab' allows you to switch between panels.\n"
|
||||
"The panel currently in use has its border colorized.\n"
|
||||
"\nSome actions are possible only if the right panel is selected.\n"
|
||||
"For example, if you want to add a task in the TODO list, you need first\n"
|
||||
"to press the 'Tab' key to get the TODO panel selected. Then you can\n"
|
||||
"For example, if you want to add a task in the TODO list, you need first"
|
||||
"\nto press the 'Tab' key to get the TODO panel selected. Then you can\n"
|
||||
"press 'A' to add your item.\n"
|
||||
"\nNotice that at the bottom of the screen the list of possible actions\n"
|
||||
"change while pressing 'Tab', so you always know what action can be\n"
|
||||
@ -355,34 +360,33 @@ help_screen(void)
|
||||
"\nIf the item to be deleted is recurrent, you will be asked if you\n"
|
||||
"wish to suppress all of the item occurences or just the one you\n"
|
||||
"selected.\n"
|
||||
"\nIf the general option 'confirm_delete' is set to 'YES', then you will\n"
|
||||
"be asked for confirmation before deleting the selected event.\n"
|
||||
"\nIf the general option 'confirm_delete' is set to 'YES', then you will"
|
||||
"\nbe asked for confirmation before deleting the selected event.\n"
|
||||
"Do not forget to save the calendar data to retrieve the modifications\n"
|
||||
"next time you launch Calcurse.");
|
||||
|
||||
hscr[HELP_ADD].title = _("Add:\n");
|
||||
hscr[HELP_ADD].text =
|
||||
_("Pressing 'A' allows you to add an item in either the ToDo or Appointment\n"
|
||||
"list, depending on which panel is selected when you press 'A'.\n"
|
||||
"\nTo enter a new item in the TODO list, you will need first to enter the\n"
|
||||
"description of this new item. Then you will be asked to specify the todo\n"
|
||||
"priority. This priority is represented by a number going from 9 for the\n"
|
||||
"lowest priority, to 1 for the highest one. It is still possible to\n"
|
||||
"change the item priority afterwards, by using the '+/-' keys inside the\n"
|
||||
"todo panel.\n"
|
||||
_("Pressing 'A' allows you to add an item in either the ToDo or Appointment"
|
||||
"\nlist, depending on which panel is selected when you press 'A'.\n"
|
||||
"\nTo enter a new item in the TODO list, you will need first to enter the"
|
||||
"\ndescription of this new item. Then you will be asked to specify the "
|
||||
"todo\npriority. This priority is represented by a number going from 9 "
|
||||
"for the\nlowest priority, to 1 for the highest one. It is still "
|
||||
"possible to\nchange the item priority afterwards, by using the '+/-' "
|
||||
"keys inside the\ntodo panel.\n"
|
||||
"\nIf the APPOINTMENT panel is selected while pressing 'A', you will be\n"
|
||||
"able to enter either a new appointment or a new all-day long event.\n"
|
||||
"To enter a new event, press [ENTER] instead of the item start time, and\n"
|
||||
"just fill in the event description.\n"
|
||||
"To enter a new event, press [ENTER] instead of the item start time, "
|
||||
"and\njust fill in the event description.\n"
|
||||
"To enter a new appointment to be added in the APPOINTMENT list, you\n"
|
||||
"will need to enter successively the time at which the appointment\n"
|
||||
"begins, the appointment length (either by specifying the duration in\n"
|
||||
"minutes, or the end time in [hh:mm] or [h:mm] format), and the\n"
|
||||
"description of the event.\n"
|
||||
"\nThe day at which occurs the event or appointment is the day currently\n"
|
||||
"selected in the calendar, so you need to move to the desired day before\n"
|
||||
"pressing 'A'.\n"
|
||||
"\nNotes:\n"
|
||||
"\nThe day at which occurs the event or appointment is the day currently"
|
||||
"\nselected in the calendar, so you need to move to the desired day "
|
||||
"before\npressing 'A'.\n" "\nNotes:\n"
|
||||
" o if an appointment lasts for such a long time that it continues\n"
|
||||
" on the next days, this event will be indicated on all the\n"
|
||||
" corresponding days, and the beginning or ending hour will be\n"
|
||||
@ -397,11 +401,11 @@ help_screen(void)
|
||||
hscr[HELP_EDIT].text =
|
||||
_("Pressing 'E' allows you to edit the item which is currently selected.\n"
|
||||
"Depending on the item type (appointment, event, or todo), and if it is\n"
|
||||
"repeated or not, you will be asked to choose one of the item properties\n"
|
||||
"to modify. An item property is one of the following: the start time, the\n"
|
||||
"end time, the description, or the item repetition.\n"
|
||||
"Once you have chosen the property you want to modify, you will be shown\n"
|
||||
"its actual value, and you will be able to change it as you like.\n"
|
||||
"repeated or not, you will be asked to choose one of the item properties"
|
||||
"\nto modify. An item property is one of the following: the start time, "
|
||||
"the\nend time, the description, or the item repetition.\n"
|
||||
"Once you have chosen the property you want to modify, you will be shown"
|
||||
"\nits actual value, and you will be able to change it as you like.\n"
|
||||
"\nNotes:\n"
|
||||
" o if you choose to edit the item repetition properties, you will\n"
|
||||
" be asked to re-enter all of the repetition characteristics\n"
|
||||
@ -428,8 +432,8 @@ help_screen(void)
|
||||
" o if none of the above environment variables is set, then\n"
|
||||
" '/usr/bin/vi' will be used.\n"
|
||||
"\nOnce the item note is edited and saved, quit your favorite editor.\n"
|
||||
"You will then go back to Calcurse, and the '>' sign will appear in front\n"
|
||||
"of the highlighted item, meaning there is a note attached to it.");
|
||||
"You will then go back to Calcurse, and the '>' sign will appear in front"
|
||||
"\nof the highlighted item, meaning there is a note attached to it.");
|
||||
|
||||
hscr[HELP_VNOTE].title = _("ViewNote:\n");
|
||||
hscr[HELP_VNOTE].text =
|
||||
@ -437,8 +441,9 @@ help_screen(void)
|
||||
"attached to an item (an item which owns a note has a '>' sign in front\n"
|
||||
"of it). This command only permits to view the note, not to\n"
|
||||
"edit it (to do so, use the 'EditNote' command, using the 'N' key).\n"
|
||||
"Once you highlighted an item with a note attached to it, and the 'N' key\n"
|
||||
"was pressed, you will be driven to an external pager to view that note.\n"
|
||||
"Once you highlighted an item with a note attached to it, and the 'N' key"
|
||||
"\nwas pressed, you will be driven to an external pager to view that "
|
||||
"note.\n"
|
||||
"The default pager is chosen the following way:\n"
|
||||
" o if the 'PAGER' environment variable is set, then this will be\n"
|
||||
" the default viewer to be called.\n"
|
||||
@ -450,22 +455,25 @@ help_screen(void)
|
||||
hscr[HELP_PRIORITY].title = _("Priority:\n");
|
||||
hscr[HELP_PRIORITY].text =
|
||||
_("Pressing '+' or '-' allows you to change the priority of the currently\n"
|
||||
"selected item in the ToDo list. Priorities are represented by the number\n"
|
||||
"appearing in front of the todo description. This number goes from 9 for\n"
|
||||
"the lowest priority to 1 for the highest priority. Todo having higher\n"
|
||||
"priorities are placed first (at the top) inside the todo panel.\n\n"
|
||||
"If you want to raise the priority of a todo item, you need to press '+'.\n"
|
||||
"In doing so, the number in front of this item will decrease, meaning its\n"
|
||||
"priority increases. The item position inside the todo panel may change,\n"
|
||||
"depending on the priority of the items above it.\n\n"
|
||||
"At the opposite, to lower a todo priority, press '-'. The todo position\n"
|
||||
"may also change depending on the priority of the items below.");
|
||||
"selected item in the ToDo list. Priorities are represented by the "
|
||||
"number\nappearing in front of the todo description. This number goes "
|
||||
"from 9 for\nthe lowest priority to 1 for the highest priority. "
|
||||
"Todo having higher\npriorities are placed first (at the top) inside the "
|
||||
"todo panel.\n\n"
|
||||
"If you want to raise the priority of a todo item, you need to press "
|
||||
"'+'.\n"
|
||||
"In doing so, the number in front of this item will decrease, "
|
||||
"meaning its\npriority increases. The item position inside the todo "
|
||||
"panel may change,\ndepending on the priority of the items above it.\n\n"
|
||||
"At the opposite, to lower a todo priority, press '-'. The todo position"
|
||||
"\nmay also change depending on the priority of the items below.");
|
||||
|
||||
hscr[HELP_REPEAT].title = _("Repeat:\n");
|
||||
hscr[HELP_REPEAT].text =
|
||||
_("Pressing 'R' allows you to repeat an event or an appointment. You must\n"
|
||||
"first select the item to be repeated by moving inside the appointment\n"
|
||||
"panel. Then pressing 'R' will lead you to a set of three questions, with\n"
|
||||
"panel. "
|
||||
"Then pressing 'R' will lead you to a set of three questions, with\n"
|
||||
"which you will be able to specify the repetition characteristics:\n\n"
|
||||
" o type: you can choose between a daily, weekly, monthly or\n"
|
||||
" yearly repetition by pressing 'D', 'W', 'M' or 'Y'\n"
|
||||
@ -479,8 +487,7 @@ help_screen(void)
|
||||
" o ending date: this specifies when to stop repeating the selected\n"
|
||||
" event or appointment. To indicate an endless \n"
|
||||
" repetition, enter '0' and the item will be repeated\n"
|
||||
" forever.\n"
|
||||
"\nNotes:\n"
|
||||
" forever.\n" "\nNotes:\n"
|
||||
" o repeated items are marked with an '*' inside the appointment\n"
|
||||
" panel, to be easily recognizable from non-repeated ones.\n"
|
||||
" o the 'Repeat' and 'Delete' command can be mixed to create\n"
|
||||
@ -490,25 +497,25 @@ help_screen(void)
|
||||
hscr[HELP_FLAG].title = _("Flag Item:\n");
|
||||
hscr[HELP_FLAG].text =
|
||||
_("Pressing '!' toggles an appointment's 'important' flag.\n\n"
|
||||
"If an item is flagged as important, an exclamation mark appears in front\n"
|
||||
"of it, and you will be warned if time gets closed to the appointment\n"
|
||||
"If an item is flagged as important, an exclamation mark appears in front"
|
||||
"\nof it, and you will be warned if time gets closed to the appointment\n"
|
||||
"start time.\n"
|
||||
"To customize the way one gets notified, the configuration submenu lets\n"
|
||||
"you choose the command launched to warn user of an upcoming appointment,\n"
|
||||
"and how long before it he gets notified.");
|
||||
"you choose the command launched to warn user of an upcoming appointment,"
|
||||
"\nand how long before it he gets notified.");
|
||||
|
||||
hscr[HELP_CONFIG].title = _("Config:\n");
|
||||
hscr[HELP_CONFIG].text =
|
||||
_("Pressing 'C' leads to the configuration submenu, from which you can\n"
|
||||
"select between color, layout, and general options.\n"
|
||||
"\nThe color submenu lets you choose the color theme.\n"
|
||||
"\nThe layout submenu lets you choose the Calcurse screen layout, in other\n"
|
||||
"words where to place the three different panels on the screen.\n"
|
||||
"\nThe general options submenu brings a screen with the different options\n"
|
||||
"which modifies the way Calcurse interacts with the user.\n"
|
||||
"\nThe layout submenu lets you choose the Calcurse screen layout, in other"
|
||||
"\nwords where to place the three different panels on the screen.\n"
|
||||
"\nThe general options submenu brings a screen with the different options"
|
||||
"\nwhich modifies the way Calcurse interacts with the user.\n"
|
||||
"\nThe notify submenu allows you to change the notify-bar settings.\n"
|
||||
"\nDo not forget to save the calendar data to retrieve your configuration\n"
|
||||
"next time you launch Calcurse.");
|
||||
"\nDo not forget to save the calendar data to retrieve your configuration"
|
||||
"\nnext time you launch Calcurse.");
|
||||
|
||||
hscr[HELP_GENERAL].title = _("General keybindings:\n");
|
||||
hscr[HELP_GENERAL].text =
|
||||
@ -539,7 +546,7 @@ help_screen(void)
|
||||
|
||||
hscr[HELP_CREDITS].title = _("Calcurse - text-based organizer");
|
||||
hscr[HELP_CREDITS].text =
|
||||
_("Copyright (c) 2004-2007 Frederic Culot\n"
|
||||
_("Copyright (c) 2004-2008 Frederic Culot\n"
|
||||
"\n"
|
||||
"This program is free software; you can redistribute it and/or modify\n"
|
||||
"it under the terms of the GNU General Public License as published by\n"
|
||||
@ -555,36 +562,38 @@ help_screen(void)
|
||||
|
||||
need_resize = 0;
|
||||
page = oldpage = HELP_MAIN;
|
||||
help_wins_init(&hwin, &hpad, PADOFFSET);
|
||||
help_wins_init (&hwin, &hpad, PADOFFSET);
|
||||
|
||||
/* Display the help screen related to user input. */
|
||||
while ( ch != 'q' ) {
|
||||
erase_window_part(hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
|
||||
|
||||
switch (ch) {
|
||||
while (ch != 'q')
|
||||
{
|
||||
erase_window_part (hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case KEY_RESIZE:
|
||||
help_wins_reset(&hwin, &hpad, PADOFFSET);
|
||||
help_wins_reset (&hwin, &hpad, PADOFFSET);
|
||||
first_line = 0;
|
||||
nl = write_help_pad(&hpad, &hscr[oldpage]);
|
||||
nl = write_help_pad (&hpad, &hscr[oldpage]);
|
||||
need_resize = 1;
|
||||
break;
|
||||
|
||||
case CTRL('n') :
|
||||
case CTRL ('n'):
|
||||
if (nl > (first_line + hwin.h - (PADOFFSET + 1)))
|
||||
first_line++;
|
||||
break;
|
||||
|
||||
case CTRL('p') :
|
||||
case CTRL ('p'):
|
||||
if (first_line > 0)
|
||||
first_line--;
|
||||
break;
|
||||
|
||||
default:
|
||||
page = wanted_page(ch);
|
||||
if (page != NOPAGE) {
|
||||
page = wanted_page (ch);
|
||||
if (page != NOPAGE)
|
||||
{
|
||||
first_line = 0;
|
||||
nl = write_help_pad(&hpad, &hscr[page]);
|
||||
nl = write_help_pad (&hpad, &hscr[page]);
|
||||
oldpage = page;
|
||||
}
|
||||
break;
|
||||
@ -592,7 +601,8 @@ help_screen(void)
|
||||
|
||||
/* Draw the scrollbar if necessary. */
|
||||
text_lines = hwin.h - (PADOFFSET + 1);
|
||||
if (nl > text_lines) {
|
||||
if (nl > text_lines)
|
||||
{
|
||||
float ratio = ((float) text_lines + 1) / ((float) nl);
|
||||
int sbar_length = (int) (ratio * text_lines);
|
||||
int highend = (int) (ratio * first_line);
|
||||
@ -600,21 +610,21 @@ help_screen(void)
|
||||
|
||||
if ((sbar_top + sbar_length) > hwin.h - 1)
|
||||
sbar_length = hwin.h - 1 - sbar_top;
|
||||
draw_scrollbar(hwin.p, sbar_top, col - 2,
|
||||
draw_scrollbar (hwin.p, sbar_top, col - 2,
|
||||
sbar_length, TITLELINES + 1, hwin.h - 1, true);
|
||||
}
|
||||
|
||||
wmove(win[STA].p, 0, 0);
|
||||
wnoutrefresh(hwin.p);
|
||||
pnoutrefresh(hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
|
||||
wmove (win[STA].p, 0, 0);
|
||||
wnoutrefresh (hwin.p);
|
||||
pnoutrefresh (hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
|
||||
hwin.h - 2, col - PADOFFSET);
|
||||
doupdate();
|
||||
ch = wgetch(win[STA].p);
|
||||
ch = tolower(ch);
|
||||
doupdate ();
|
||||
ch = wgetch (win[STA].p);
|
||||
ch = tolower (ch);
|
||||
}
|
||||
|
||||
delwin(hpad.p);
|
||||
delwin(hwin.p);
|
||||
delwin (hpad.p);
|
||||
delwin (hwin.p);
|
||||
if (need_resize)
|
||||
wins_reset();
|
||||
wins_reset ();
|
||||
}
|
||||
|
10
src/help.h
10
src/help.h
@ -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
|
||||
@ -27,11 +27,13 @@
|
||||
#ifndef CALCURSE_HELP_H
|
||||
#define CALCURSE_HELP_H
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
char *title;
|
||||
char *text;
|
||||
} help_page_t;
|
||||
}
|
||||
help_page_t;
|
||||
|
||||
void help_screen(void);
|
||||
void help_screen (void);
|
||||
|
||||
#endif /* CALCURSE_HELP_H */
|
||||
|
34
src/i18n.h
34
src/i18n.h
@ -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
|
||||
@ -32,23 +32,23 @@
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#if ENABLE_NLS
|
||||
#include <libintl.h>
|
||||
#undef _
|
||||
#define _(String) gettext(String)
|
||||
#ifdef gettext_noop
|
||||
#define N_(String) gettext_noop(String)
|
||||
#else
|
||||
#define N_(String) (String)
|
||||
#endif
|
||||
#include <libintl.h>
|
||||
#undef _
|
||||
#define _(String) gettext(String)
|
||||
#ifdef gettext_noop
|
||||
#define N_(String) gettext_noop(String)
|
||||
#else
|
||||
#define N_(String) (String)
|
||||
#endif
|
||||
#else /* NLS disabled */
|
||||
#define _(String) (String)
|
||||
#define N_(String) (String)
|
||||
#define textdomain(String) (String)
|
||||
#define gettext(String) (String)
|
||||
#define dgettext(String) (String)
|
||||
#define dcgettext(String) (String)
|
||||
#define bindtextdomain(String) (String)
|
||||
#define bind_textdomain_codeset(Domain,Codeset) (Codeset)
|
||||
#define _(String) (String)
|
||||
#define N_(String) (String)
|
||||
#define textdomain(String) (String)
|
||||
#define gettext(String) (String)
|
||||
#define dgettext(String) (String)
|
||||
#define dcgettext(String) (String)
|
||||
#define bindtextdomain(String) (String)
|
||||
#define bind_textdomain_codeset(Domain,Codeset) (Codeset)
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
#endif /* CALCURSE_I18N_H */
|
||||
|
26
src/io.h
26
src/io.h
@ -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
|
||||
* Copyright (c) 2004-2007 Frederic Culot
|
||||
* Copyright (c) 2004-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -29,19 +29,21 @@
|
||||
|
||||
#include "vars.h"
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
IO_EXPORT_NONINTERACTIVE,
|
||||
IO_EXPORT_INTERACTIVE,
|
||||
IO_EXPORT_NBMODES
|
||||
} export_mode_t;
|
||||
}
|
||||
export_mode_t;
|
||||
|
||||
void io_init(char *);
|
||||
void io_extract_data(char *, const char *, int);
|
||||
void io_save_cal(conf_t *);
|
||||
void io_load_app(void);
|
||||
void io_load_todo(void);
|
||||
int io_check_data_files(void);
|
||||
void io_startup_screen(bool, int);
|
||||
void io_export_data(export_mode_t, conf_t *);
|
||||
void io_init (char *);
|
||||
void io_extract_data (char *, const char *, int);
|
||||
void io_save_cal (conf_t *);
|
||||
void io_load_app (void);
|
||||
void io_load_todo (void);
|
||||
int io_check_data_files (void);
|
||||
void io_startup_screen (bool, int);
|
||||
void io_export_data (export_mode_t, conf_t *);
|
||||
|
||||
#endif /* CALCURSE_IO_H */
|
||||
|
522
src/notify.c
522
src/notify.c
@ -1,8 +1,8 @@
|
||||
/* $calcurse: notify.c,v 1.24 2008/02/10 16:29:50 culot Exp $ */
|
||||
/* $calcurse: notify.c,v 1.25 2008/04/12 21:14:03 culot Exp $ */
|
||||
|
||||
/*
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -40,47 +40,48 @@ static pthread_t notify_t_main;
|
||||
|
||||
/* Return 1 if we need to display the notify-bar, else 0. */
|
||||
int
|
||||
notify_bar(void)
|
||||
notify_bar (void)
|
||||
{
|
||||
int display_bar = 0;
|
||||
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
display_bar = (nbar->show) ? 1 : 0;
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
|
||||
return display_bar;
|
||||
return (display_bar);
|
||||
}
|
||||
|
||||
/* Initialize the nbar variable used to store notification options. */
|
||||
void
|
||||
notify_init_vars(void)
|
||||
notify_init_vars (void)
|
||||
{
|
||||
char *time_format = "%T";
|
||||
char *date_format = "%a %F";
|
||||
char *cmd = "printf '\\a'";
|
||||
|
||||
nbar = (struct nbar_s *) malloc(sizeof(struct nbar_s));
|
||||
pthread_mutex_init(&nbar->mutex, NULL);
|
||||
nbar = (struct nbar_s *) malloc (sizeof (struct nbar_s));
|
||||
pthread_mutex_init (&nbar->mutex, NULL);
|
||||
nbar->show = 1;
|
||||
nbar->cntdwn = 300;
|
||||
strncpy(nbar->datefmt, date_format, strlen(date_format) + 1);
|
||||
strncpy(nbar->timefmt, time_format, strlen(time_format) + 1);
|
||||
strncpy(nbar->cmd, cmd, strlen(cmd) + 1);
|
||||
strncpy (nbar->datefmt, date_format, strlen (date_format) + 1);
|
||||
strncpy (nbar->timefmt, time_format, strlen (time_format) + 1);
|
||||
strncpy (nbar->cmd, cmd, strlen (cmd) + 1);
|
||||
|
||||
if ((nbar->shell = getenv("SHELL")) == NULL)
|
||||
if ((nbar->shell = getenv ("SHELL")) == NULL)
|
||||
nbar->shell = "/bin/sh";
|
||||
}
|
||||
|
||||
/* Extract the appointment file name from the complete file path. */
|
||||
static void
|
||||
extract_aptsfile(void)
|
||||
extract_aptsfile (void)
|
||||
{
|
||||
char *file;
|
||||
|
||||
file = strrchr(path_apts, '/');
|
||||
file = strrchr (path_apts, '/');
|
||||
if (!file)
|
||||
notify->apts_file = path_apts;
|
||||
else {
|
||||
else
|
||||
{
|
||||
notify->apts_file = file;
|
||||
notify->apts_file++;
|
||||
}
|
||||
@ -92,23 +93,22 @@ extract_aptsfile(void)
|
||||
* number of columns, y and x are its coordinates).
|
||||
*/
|
||||
void
|
||||
notify_init_bar(void)
|
||||
notify_init_bar (void)
|
||||
{
|
||||
notify = (struct notify_vars_s *) malloc(sizeof(struct notify_vars_s));
|
||||
notify_app = (struct notify_app_s *)
|
||||
malloc(sizeof(struct notify_app_s));
|
||||
pthread_mutex_init(¬ify->mutex, NULL);
|
||||
pthread_mutex_init(¬ify_app->mutex, NULL);
|
||||
notify = (struct notify_vars_s *) malloc (sizeof (struct notify_vars_s));
|
||||
notify_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
|
||||
pthread_mutex_init (¬ify->mutex, NULL);
|
||||
pthread_mutex_init (¬ify_app->mutex, NULL);
|
||||
notify_app->got_app = 0;
|
||||
notify->win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
||||
extract_aptsfile();
|
||||
notify->win = newwin (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
||||
extract_aptsfile ();
|
||||
}
|
||||
|
||||
/* Stop the notify-bar main thread. */
|
||||
void
|
||||
notify_stop_main_thread(void)
|
||||
notify_stop_main_thread (void)
|
||||
{
|
||||
pthread_cancel(notify_t_main);
|
||||
pthread_cancel (notify_t_main);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,28 +117,26 @@ notify_stop_main_thread(void)
|
||||
* notification window.
|
||||
*/
|
||||
void
|
||||
notify_reinit_bar(int l, int c, int y, int x)
|
||||
notify_reinit_bar (int l, int c, int y, int x)
|
||||
{
|
||||
delwin(notify->win);
|
||||
notify->win = newwin(l, c, y, x);
|
||||
delwin (notify->win);
|
||||
notify->win = newwin (l, c, y, x);
|
||||
}
|
||||
|
||||
/* Launch user defined command as a notification. */
|
||||
static void
|
||||
launch_cmd(char *cmd, char *shell)
|
||||
launch_cmd (char *cmd, char *shell)
|
||||
{
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
pid = fork ();
|
||||
|
||||
if (pid < 0)
|
||||
ierror(_("FATAL ERROR in launch_cmd: could not fork"),
|
||||
IERROR_WARN);
|
||||
ierror (_("FATAL ERROR in launch_cmd: could not fork"), IERROR_WARN);
|
||||
else if (pid == 0) /* Child: launch user defined command */
|
||||
if (execlp(shell, shell, "-c", cmd, (char *)NULL) < 0)
|
||||
ierror(_("FATAL ERROR in launch_cmd: could not "
|
||||
"launch user command"),
|
||||
IERROR_WARN);
|
||||
if (execlp (shell, shell, "-c", cmd, (char *) NULL) < 0)
|
||||
ierror (_("FATAL ERROR in launch_cmd: could not "
|
||||
"launch user command"), IERROR_WARN);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -146,7 +144,7 @@ launch_cmd(char *cmd, char *shell)
|
||||
* for example.
|
||||
*/
|
||||
void
|
||||
notify_update_bar(void)
|
||||
notify_update_bar (void)
|
||||
{
|
||||
const int space = 3;
|
||||
int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
|
||||
@ -155,272 +153,291 @@ notify_update_bar(void)
|
||||
char buf[BUFSIZ];
|
||||
|
||||
date_pos = space;
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
pthread_mutex_lock (¬ify->mutex);
|
||||
|
||||
file_pos = strlen(notify->date) + strlen(notify->time) + 7 + 2*space;
|
||||
app_pos = file_pos + strlen(notify->apts_file) + 2 + space;
|
||||
file_pos = strlen (notify->date) + strlen (notify->time) + 7 + 2 * space;
|
||||
app_pos = file_pos + strlen (notify->apts_file) + 2 + space;
|
||||
txt_max_len = col - (app_pos + 12 + space);
|
||||
|
||||
custom_apply_attr(notify->win, ATTR_HIGHEST);
|
||||
wattron(notify->win, A_UNDERLINE | A_REVERSE);
|
||||
mvwhline(notify->win, 0, 0, ACS_HLINE, col);
|
||||
mvwprintw(notify->win, 0, date_pos, "[ %s | %s ]",
|
||||
custom_apply_attr (notify->win, ATTR_HIGHEST);
|
||||
wattron (notify->win, A_UNDERLINE | A_REVERSE);
|
||||
mvwhline (notify->win, 0, 0, ACS_HLINE, col);
|
||||
mvwprintw (notify->win, 0, date_pos, "[ %s | %s ]",
|
||||
notify->date, notify->time);
|
||||
mvwprintw(notify->win, 0, file_pos, "(%s)", notify->apts_file);
|
||||
mvwprintw (notify->win, 0, file_pos, "(%s)", notify->apts_file);
|
||||
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
if (notify_app->got_app) {
|
||||
if (strlen(notify_app->txt) > txt_max_len) {
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
if (notify_app->got_app)
|
||||
{
|
||||
if (strlen (notify_app->txt) > txt_max_len)
|
||||
{
|
||||
too_long = 1;
|
||||
strncpy(buf, notify_app->txt, txt_max_len - 3);
|
||||
strncpy (buf, notify_app->txt, txt_max_len - 3);
|
||||
buf[txt_max_len - 3] = '\0';
|
||||
}
|
||||
|
||||
time_left = notify_app->time - notify->time_in_sec;
|
||||
if (time_left > 0) {
|
||||
if (time_left > 0)
|
||||
{
|
||||
hours_left = (time_left / HOURINSEC);
|
||||
minutes_left = (time_left - hours_left * HOURINSEC) /
|
||||
MININSEC;
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
|
||||
if (time_left < nbar->cntdwn &&
|
||||
(notify_app->state & APOINT_NOTIFY))
|
||||
if (time_left < nbar->cntdwn && (notify_app->state & APOINT_NOTIFY))
|
||||
blinking = 1;
|
||||
else
|
||||
blinking = 0;
|
||||
|
||||
if (blinking)
|
||||
wattron(notify->win, A_BLINK);
|
||||
wattron (notify->win, A_BLINK);
|
||||
if (too_long)
|
||||
mvwprintw(notify->win, 0, app_pos,
|
||||
"> %02d:%02d :: %s.. <",
|
||||
mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s.. <",
|
||||
hours_left, minutes_left, buf);
|
||||
else
|
||||
mvwprintw(notify->win, 0, app_pos,
|
||||
"> %02d:%02d :: %s <",
|
||||
hours_left, minutes_left,
|
||||
notify_app->txt);
|
||||
mvwprintw (notify->win, 0, app_pos, "> %02d:%02d :: %s <",
|
||||
hours_left, minutes_left, notify_app->txt);
|
||||
if (blinking)
|
||||
wattroff(notify->win, A_BLINK);
|
||||
wattroff (notify->win, A_BLINK);
|
||||
|
||||
if (blinking &&
|
||||
!(notify_app->state & APOINT_NOTIFIED)) {
|
||||
if (blinking && !(notify_app->state & APOINT_NOTIFIED))
|
||||
{
|
||||
notify_app->state |= APOINT_NOTIFIED;
|
||||
launch_cmd(nbar->cmd, nbar->shell);
|
||||
launch_cmd (nbar->cmd, nbar->shell);
|
||||
}
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
} else {
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
notify_app->got_app = 0;
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
notify_check_next_app();
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
pthread_mutex_unlock (¬ify->mutex);
|
||||
notify_check_next_app ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
|
||||
wattroff(notify->win, A_UNDERLINE | A_REVERSE);
|
||||
custom_remove_attr(notify->win, ATTR_HIGHEST);
|
||||
wrefresh(notify->win);
|
||||
wattroff (notify->win, A_UNDERLINE | A_REVERSE);
|
||||
custom_remove_attr (notify->win, ATTR_HIGHEST);
|
||||
wrefresh (notify->win);
|
||||
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
pthread_mutex_unlock (¬ify->mutex);
|
||||
}
|
||||
|
||||
/* Update the notication bar content */
|
||||
static void *
|
||||
notify_main_thread(void *arg)
|
||||
notify_main_thread (void *arg)
|
||||
{
|
||||
const unsigned thread_sleep = 1;
|
||||
const unsigned check_app = MININSEC;
|
||||
int elapse= 0, got_app = 0;
|
||||
int elapse = 0, got_app = 0;
|
||||
struct tm *ntime;
|
||||
time_t ntimer;
|
||||
|
||||
elapse = 0;
|
||||
got_app = 0;
|
||||
|
||||
for (;;) {
|
||||
ntimer = time(NULL);
|
||||
ntime = localtime(&ntimer);
|
||||
pthread_mutex_lock(¬ify->mutex);
|
||||
for (;;)
|
||||
{
|
||||
ntimer = time (NULL);
|
||||
ntime = localtime (&ntimer);
|
||||
pthread_mutex_lock (¬ify->mutex);
|
||||
notify->time_in_sec = ntimer;
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strftime(notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime);
|
||||
strftime(notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
pthread_mutex_unlock(¬ify->mutex);
|
||||
notify_update_bar();
|
||||
sleep(thread_sleep);
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strftime (notify->time, NOTIFY_FIELD_LENGTH, nbar->timefmt, ntime);
|
||||
strftime (notify->date, NOTIFY_FIELD_LENGTH, nbar->datefmt, ntime);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
pthread_mutex_unlock (¬ify->mutex);
|
||||
notify_update_bar ();
|
||||
sleep (thread_sleep);
|
||||
elapse += thread_sleep;
|
||||
if (elapse >= check_app) {
|
||||
if (elapse >= check_app)
|
||||
{
|
||||
elapse = 0;
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
got_app = notify_app->got_app;
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
if (!got_app)
|
||||
notify_check_next_app();
|
||||
notify_check_next_app ();
|
||||
}
|
||||
}
|
||||
pthread_exit((void*) 0);
|
||||
pthread_exit ((void *) 0);
|
||||
}
|
||||
|
||||
/* Look for the next appointment within the next 24 hours. */
|
||||
static void *
|
||||
notify_thread_app(void *arg)
|
||||
notify_thread_app (void *arg)
|
||||
{
|
||||
struct notify_app_s *tmp_app;
|
||||
time_t current_time;
|
||||
|
||||
current_time = time(NULL);
|
||||
current_time = time (NULL);
|
||||
|
||||
/* Use a temporary structure not to lock the mutex for a too
|
||||
* long time while looking for next appointment. */
|
||||
tmp_app = (struct notify_app_s *) malloc(sizeof(struct notify_app_s));
|
||||
tmp_app = (struct notify_app_s *) malloc (sizeof (struct notify_app_s));
|
||||
tmp_app->time = current_time + DAYINSEC;
|
||||
tmp_app->got_app = 0;
|
||||
tmp_app->txt = NULL;
|
||||
tmp_app = recur_apoint_check_next(tmp_app, current_time, get_today());
|
||||
tmp_app = apoint_check_next(tmp_app, current_time);
|
||||
tmp_app = recur_apoint_check_next (tmp_app, current_time, get_today ());
|
||||
tmp_app = apoint_check_next (tmp_app, current_time);
|
||||
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
if (tmp_app->got_app) {
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
if (tmp_app->got_app)
|
||||
{
|
||||
notify_app->got_app = 1;
|
||||
notify_app->time = tmp_app->time;
|
||||
notify_app->txt = mycpy(tmp_app->txt);
|
||||
notify_app->txt = mycpy (tmp_app->txt);
|
||||
notify_app->state = tmp_app->state;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
notify_app->got_app = 0;
|
||||
}
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
|
||||
if (tmp_app->txt != NULL)
|
||||
free(tmp_app->txt);
|
||||
free(tmp_app);
|
||||
notify_update_bar();
|
||||
free (tmp_app->txt);
|
||||
free (tmp_app);
|
||||
notify_update_bar ();
|
||||
|
||||
pthread_exit((void*) 0);
|
||||
pthread_exit ((void *) 0);
|
||||
}
|
||||
|
||||
/* Launch the thread notify_thread_app to look for next appointment. */
|
||||
void
|
||||
notify_check_next_app(void)
|
||||
notify_check_next_app (void)
|
||||
{
|
||||
pthread_t notify_t_app;
|
||||
|
||||
pthread_create(¬ify_t_app, NULL, notify_thread_app, NULL);
|
||||
pthread_create (¬ify_t_app, NULL, notify_thread_app, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check if the newly created appointment is to be notified. */
|
||||
void
|
||||
notify_check_added(char *mesg, long start, char state)
|
||||
notify_check_added (char *mesg, long start, char state)
|
||||
{
|
||||
time_t current_time;
|
||||
int update_notify = 0;
|
||||
long gap;
|
||||
|
||||
current_time = time(NULL);
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
if (!notify_app->got_app) {
|
||||
current_time = time (NULL);
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
if (!notify_app->got_app)
|
||||
{
|
||||
gap = start - current_time;
|
||||
if (gap >= 0 && gap <= DAYINSEC)
|
||||
update_notify = 1;
|
||||
} else if (start < notify_app->time && start >= current_time) {
|
||||
}
|
||||
else if (start < notify_app->time && start >= current_time)
|
||||
{
|
||||
update_notify = 1;
|
||||
} else if (start == notify_app->time && state != notify_app->state)
|
||||
}
|
||||
else if (start == notify_app->time && state != notify_app->state)
|
||||
update_notify = 1;
|
||||
|
||||
if (update_notify) {
|
||||
if (update_notify)
|
||||
{
|
||||
notify_app->got_app = 1;
|
||||
notify_app->time = start;
|
||||
notify_app->txt = mycpy(mesg);
|
||||
notify_app->txt = mycpy (mesg);
|
||||
notify_app->state = state;
|
||||
}
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
notify_update_bar();
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
notify_update_bar ();
|
||||
}
|
||||
|
||||
/* Check if the newly repeated appointment is to be notified. */
|
||||
void
|
||||
notify_check_repeated(recur_apoint_llist_node_t *i)
|
||||
notify_check_repeated (recur_apoint_llist_node_t *i)
|
||||
{
|
||||
long real_app_time;
|
||||
int update_notify = 0;
|
||||
time_t current_time;
|
||||
|
||||
current_time = time(NULL);
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
if ((real_app_time = recur_item_inday(i->start, i->exc, i->rpt->type,
|
||||
i->rpt->freq, i->rpt->until, get_today()) > current_time)) {
|
||||
if (!notify_app->got_app) {
|
||||
current_time = time (NULL);
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
if ((real_app_time = recur_item_inday (i->start, i->exc, i->rpt->type,
|
||||
i->rpt->freq, i->rpt->until,
|
||||
get_today ()) > current_time))
|
||||
{
|
||||
if (!notify_app->got_app)
|
||||
{
|
||||
if (real_app_time - current_time <= DAYINSEC)
|
||||
update_notify = 1;
|
||||
} else if (real_app_time < notify_app->time &&
|
||||
real_app_time >= current_time) {
|
||||
}
|
||||
else if (real_app_time < notify_app->time &&
|
||||
real_app_time >= current_time)
|
||||
{
|
||||
update_notify = 1;
|
||||
} else if (real_app_time == notify_app->time &&
|
||||
}
|
||||
else if (real_app_time == notify_app->time &&
|
||||
i->state != notify_app->state)
|
||||
update_notify = 1;
|
||||
}
|
||||
if (update_notify) {
|
||||
if (update_notify)
|
||||
{
|
||||
notify_app->got_app = 1;
|
||||
notify_app->time = real_app_time;
|
||||
notify_app->txt = mycpy(i->mesg);
|
||||
notify_app->txt = mycpy (i->mesg);
|
||||
notify_app->state = i->state;
|
||||
}
|
||||
pthread_mutex_unlock(¬ify_app->mutex);
|
||||
notify_update_bar();
|
||||
pthread_mutex_unlock (¬ify_app->mutex);
|
||||
notify_update_bar ();
|
||||
}
|
||||
|
||||
int
|
||||
notify_same_item(long time)
|
||||
notify_same_item (long time)
|
||||
{
|
||||
int same = 0;
|
||||
|
||||
pthread_mutex_lock(&(notify_app->mutex));
|
||||
pthread_mutex_lock (&(notify_app->mutex));
|
||||
if (notify_app->got_app && notify_app->time == time)
|
||||
same = 1;
|
||||
pthread_mutex_unlock(&(notify_app->mutex));
|
||||
pthread_mutex_unlock (&(notify_app->mutex));
|
||||
|
||||
return same;
|
||||
return (same);
|
||||
}
|
||||
|
||||
int
|
||||
notify_same_recur_item(recur_apoint_llist_node_t *i)
|
||||
notify_same_recur_item (recur_apoint_llist_node_t *i)
|
||||
{
|
||||
int same = 0;
|
||||
long item_start = 0;
|
||||
|
||||
item_start = recur_item_inday(i->start, i->exc, i->rpt->type,
|
||||
i->rpt->freq, i->rpt->until, get_today());
|
||||
pthread_mutex_lock(¬ify_app->mutex);
|
||||
item_start = recur_item_inday (i->start, i->exc, i->rpt->type,
|
||||
i->rpt->freq, i->rpt->until, get_today ());
|
||||
pthread_mutex_lock (¬ify_app->mutex);
|
||||
if (notify_app->got_app && item_start == notify_app->time)
|
||||
same = 1;
|
||||
pthread_mutex_unlock(&(notify_app->mutex));
|
||||
pthread_mutex_unlock (&(notify_app->mutex));
|
||||
|
||||
return same;
|
||||
return (same);
|
||||
}
|
||||
|
||||
/* Launch the notify-bar main thread. */
|
||||
void
|
||||
notify_start_main_thread(void)
|
||||
notify_start_main_thread (void)
|
||||
{
|
||||
pthread_create(¬ify_t_main, NULL, notify_main_thread, NULL);
|
||||
notify_check_next_app();
|
||||
pthread_create (¬ify_t_main, NULL, notify_main_thread, NULL);
|
||||
notify_check_next_app ();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Print options related to the notify-bar. */
|
||||
static void
|
||||
notify_print_options(WINDOW *optwin, int col)
|
||||
notify_print_options (WINDOW *optwin, int col)
|
||||
{
|
||||
enum {SHOW, DATE, CLOCK, WARN, CMD, NB_OPT};
|
||||
enum
|
||||
{ SHOW, DATE, CLOCK, WARN, CMD, NB_OPT };
|
||||
|
||||
struct opt_s {
|
||||
struct opt_s
|
||||
{
|
||||
char name[BUFSIZ];
|
||||
char desc[BUFSIZ];
|
||||
char value[BUFSIZ];
|
||||
} opt[NB_OPT];
|
||||
}
|
||||
opt[NB_OPT];
|
||||
|
||||
int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol, maxlen;
|
||||
char buf[BUFSIZ];
|
||||
@ -431,72 +448,72 @@ notify_print_options(WINDOW *optwin, int col)
|
||||
y_offset = 3;
|
||||
maxcol = col - 2;
|
||||
|
||||
strncpy(opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
|
||||
strncpy(opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
|
||||
strncpy(opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
|
||||
strncpy(opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
|
||||
strncpy(opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
|
||||
strncpy (opt[SHOW].name, _("notify-bar_show = "), BUFSIZ);
|
||||
strncpy (opt[DATE].name, _("notify-bar_date = "), BUFSIZ);
|
||||
strncpy (opt[CLOCK].name, _("notify-bar_clock = "), BUFSIZ);
|
||||
strncpy (opt[WARN].name, _("notify-bar_warning = "), BUFSIZ);
|
||||
strncpy (opt[CMD].name, _("notify-bar_command = "), BUFSIZ);
|
||||
|
||||
strncpy(opt[SHOW].desc,
|
||||
_("(if set to YES, notify-bar will be displayed)"),
|
||||
BUFSIZ);
|
||||
strncpy(opt[DATE].desc,
|
||||
strncpy (opt[SHOW].desc,
|
||||
_("(if set to YES, notify-bar will be displayed)"), BUFSIZ);
|
||||
strncpy (opt[DATE].desc,
|
||||
_("(Format of the date to be displayed inside notify-bar)"),
|
||||
BUFSIZ);
|
||||
strncpy(opt[CLOCK].desc,
|
||||
strncpy (opt[CLOCK].desc,
|
||||
_("(Format of the time to be displayed inside notify-bar)"),
|
||||
BUFSIZ);
|
||||
strncpy(opt[WARN].desc,
|
||||
strncpy (opt[WARN].desc,
|
||||
_("(Warn user if an appointment is within next 'notify-bar_warning'"
|
||||
" seconds)"),
|
||||
BUFSIZ);
|
||||
strncpy(opt[CMD].desc,
|
||||
" seconds)"), BUFSIZ);
|
||||
strncpy (opt[CMD].desc,
|
||||
_("(Command used to notify user of an upcoming appointment)"),
|
||||
BUFSIZ);
|
||||
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
|
||||
strncpy(opt[DATE].value, nbar->datefmt, BUFSIZ);
|
||||
strncpy(opt[CLOCK].value, nbar->timefmt, BUFSIZ);
|
||||
snprintf(opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
|
||||
strncpy(opt[CMD].value, nbar->cmd, BUFSIZ);
|
||||
strncpy (opt[DATE].value, nbar->datefmt, BUFSIZ);
|
||||
strncpy (opt[CLOCK].value, nbar->timefmt, BUFSIZ);
|
||||
snprintf (opt[WARN].value, BUFSIZ, "%d", nbar->cntdwn);
|
||||
strncpy (opt[CMD].value, nbar->cmd, BUFSIZ);
|
||||
|
||||
l = strlen(opt[SHOW].name);
|
||||
l = strlen (opt[SHOW].name);
|
||||
x = x_pos + x_offset + l;
|
||||
mvwprintw(optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name);
|
||||
erase_window_part(optwin, x, y_pos, maxcol, y_pos);
|
||||
print_option_incolor(optwin, nbar->show, y_pos, x);
|
||||
mvwprintw(optwin, y_pos + 1, x_pos, opt[SHOW].desc);
|
||||
mvwprintw (optwin, y_pos, x_pos, "[1] %s", opt[SHOW].name);
|
||||
erase_window_part (optwin, x, y_pos, maxcol, y_pos);
|
||||
print_option_incolor (optwin, nbar->show, y_pos, x);
|
||||
mvwprintw (optwin, y_pos + 1, x_pos, opt[SHOW].desc);
|
||||
|
||||
for (i = 1; i < NB_OPT; i++) {
|
||||
l = strlen(opt[i].name);
|
||||
for (i = 1; i < NB_OPT; i++)
|
||||
{
|
||||
l = strlen (opt[i].name);
|
||||
y = y_pos + i * y_offset;
|
||||
x = x_pos + x_offset + l;
|
||||
maxlen = maxcol - x - 2;
|
||||
|
||||
mvwprintw(optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name);
|
||||
erase_window_part(optwin, x, y, maxcol, y);
|
||||
custom_apply_attr(optwin, ATTR_HIGHEST);
|
||||
if (strlen(opt[i].value) < maxlen)
|
||||
mvwprintw(optwin, y, x, "%s", opt[i].value);
|
||||
else {
|
||||
strncpy(buf, opt[i].value, maxlen - 1);
|
||||
mvwprintw (optwin, y, x_pos, "[%d] %s", i + 1, opt[i].name);
|
||||
erase_window_part (optwin, x, y, maxcol, y);
|
||||
custom_apply_attr (optwin, ATTR_HIGHEST);
|
||||
if (strlen (opt[i].value) < maxlen)
|
||||
mvwprintw (optwin, y, x, "%s", opt[i].value);
|
||||
else
|
||||
{
|
||||
strncpy (buf, opt[i].value, maxlen - 1);
|
||||
buf[maxlen - 1] = '\0';
|
||||
mvwprintw(optwin, y, x, "%s...", buf);
|
||||
mvwprintw (optwin, y, x, "%s...", buf);
|
||||
}
|
||||
custom_remove_attr(optwin, ATTR_HIGHEST);
|
||||
mvwprintw(optwin, y + 1, x_pos, opt[i].desc);
|
||||
custom_remove_attr (optwin, ATTR_HIGHEST);
|
||||
mvwprintw (optwin, y + 1, x_pos, opt[i].desc);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
wmove(win[STA].p, 1, 0);
|
||||
wnoutrefresh(optwin);
|
||||
doupdate();
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
wmove (win[STA].p, 1, 0);
|
||||
wnoutrefresh (optwin);
|
||||
doupdate ();
|
||||
}
|
||||
|
||||
/* Notify-bar configuration. */
|
||||
void
|
||||
notify_config_bar(void)
|
||||
notify_config_bar (void)
|
||||
{
|
||||
window_t conf_win;
|
||||
char label[BUFSIZ];
|
||||
@ -510,91 +527,96 @@ notify_config_bar(void)
|
||||
char *count_str =
|
||||
_("Enter the number of seconds (0 not to be warned before an appointment)");
|
||||
char *cmd_str = _("Enter the notification command ");
|
||||
int ch = 0 , change_win = 1;
|
||||
int ch = 0, change_win = 1;
|
||||
|
||||
buf = (char *)malloc(BUFSIZ);
|
||||
snprintf(label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
|
||||
custom_confwin_init(&conf_win, label);
|
||||
buf = (char *) malloc (BUFSIZ);
|
||||
snprintf (label, BUFSIZ, _("CalCurse %s | notify-bar options"), VERSION);
|
||||
custom_confwin_init (&conf_win, label);
|
||||
|
||||
while (ch != 'q') {
|
||||
while (ch != 'q')
|
||||
{
|
||||
if (change_win)
|
||||
custom_confwin_init(&conf_win, label);
|
||||
status_mesg(number_str, "");
|
||||
notify_print_options(conf_win.p, col);
|
||||
custom_confwin_init (&conf_win, label);
|
||||
status_mesg (number_str, "");
|
||||
notify_print_options (conf_win.p, col);
|
||||
*buf = '\0';
|
||||
ch = wgetch(win[STA].p);
|
||||
ch = wgetch (win[STA].p);
|
||||
|
||||
switch (ch) {
|
||||
switch (ch)
|
||||
{
|
||||
case KEY_RESIZE:
|
||||
endwin();
|
||||
refresh();
|
||||
curs_set(0);
|
||||
delwin(conf_win.p);
|
||||
custom_confwin_init(&conf_win, label);
|
||||
endwin ();
|
||||
refresh ();
|
||||
curs_set (0);
|
||||
delwin (conf_win.p);
|
||||
custom_confwin_init (&conf_win, label);
|
||||
break;
|
||||
case '1':
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
nbar->show = !nbar->show;
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
if (notify_bar())
|
||||
notify_start_main_thread();
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
if (notify_bar ())
|
||||
notify_start_main_thread ();
|
||||
else
|
||||
notify_stop_main_thread();
|
||||
delwin(conf_win.p);
|
||||
notify_stop_main_thread ();
|
||||
delwin (conf_win.p);
|
||||
change_win = 1;
|
||||
break;
|
||||
case '2':
|
||||
status_mesg(date_str, "");
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(buf, nbar->datefmt, strlen(nbar->datefmt) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(nbar->datefmt, buf, strlen(buf) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
status_mesg (date_str, "");
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (buf, nbar->datefmt, strlen (nbar->datefmt) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
|
||||
{
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (nbar->datefmt, buf, strlen (buf) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
}
|
||||
change_win = 0;
|
||||
break;
|
||||
case '3':
|
||||
status_mesg(time_str, "");
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(buf, nbar->timefmt, strlen(nbar->timefmt) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(nbar->timefmt, buf, strlen(buf) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
status_mesg (time_str, "");
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (buf, nbar->timefmt, strlen (nbar->timefmt) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
|
||||
{
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (nbar->timefmt, buf, strlen (buf) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
}
|
||||
change_win = 0;
|
||||
break;
|
||||
case '4':
|
||||
status_mesg(count_str, "");
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
printf(buf, "%d", nbar->cntdwn);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
|
||||
is_all_digit(buf) &&
|
||||
atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
nbar->cntdwn = atoi(buf);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
status_mesg (count_str, "");
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
printf (buf, "%d", nbar->cntdwn);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
if (updatestring (win[STA].p, &buf, 0, 1) == 0 &&
|
||||
is_all_digit (buf) && atoi (buf) >= 0 && atoi (buf) <= DAYINSEC)
|
||||
{
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
nbar->cntdwn = atoi (buf);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
}
|
||||
change_win = 0;
|
||||
break;
|
||||
case '5':
|
||||
status_mesg(cmd_str, "");
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(buf, nbar->cmd, strlen(nbar->cmd) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
|
||||
pthread_mutex_lock(&nbar->mutex);
|
||||
strncpy(nbar->cmd, buf, strlen(buf) + 1);
|
||||
pthread_mutex_unlock(&nbar->mutex);
|
||||
status_mesg (cmd_str, "");
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (buf, nbar->cmd, strlen (nbar->cmd) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
if (updatestring (win[STA].p, &buf, 0, 1) == 0)
|
||||
{
|
||||
pthread_mutex_lock (&nbar->mutex);
|
||||
strncpy (nbar->cmd, buf, strlen (buf) + 1);
|
||||
pthread_mutex_unlock (&nbar->mutex);
|
||||
}
|
||||
change_win = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
delwin(conf_win.p);
|
||||
free (buf);
|
||||
delwin (conf_win.p);
|
||||
}
|
||||
|
36
src/notify.h
36
src/notify.h
@ -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
|
||||
* Copyright (c) 2004-2007 Frederic Culot
|
||||
* Copyright (c) 2004-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -33,7 +33,8 @@
|
||||
|
||||
#define NOTIFY_FIELD_LENGTH 25
|
||||
|
||||
struct notify_vars_s {
|
||||
struct notify_vars_s
|
||||
{
|
||||
WINDOW *win;
|
||||
long time_in_sec;
|
||||
char *apts_file;
|
||||
@ -42,7 +43,8 @@ struct notify_vars_s {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
struct notify_app_s {
|
||||
struct notify_app_s
|
||||
{
|
||||
long time;
|
||||
int got_app;
|
||||
char *txt;
|
||||
@ -50,18 +52,18 @@ struct notify_app_s {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
int notify_bar(void);
|
||||
void notify_init_vars(void);
|
||||
void notify_init_bar(void);
|
||||
void notify_start_main_thread(void);
|
||||
void notify_stop_main_thread(void);
|
||||
void notify_reinit_bar(int, int, int, int);
|
||||
void notify_update_bar(void);
|
||||
void notify_check_next_app(void);
|
||||
void notify_check_added(char *, long, char);
|
||||
void notify_check_repeated(recur_apoint_llist_node_t *);
|
||||
int notify_same_item(long);
|
||||
int notify_same_recur_item(recur_apoint_llist_node_t *);
|
||||
void notify_config_bar(void);
|
||||
int notify_bar (void);
|
||||
void notify_init_vars (void);
|
||||
void notify_init_bar (void);
|
||||
void notify_start_main_thread (void);
|
||||
void notify_stop_main_thread (void);
|
||||
void notify_reinit_bar (int, int, int, int);
|
||||
void notify_update_bar (void);
|
||||
void notify_check_next_app (void);
|
||||
void notify_check_added (char *, long, char);
|
||||
void notify_check_repeated (recur_apoint_llist_node_t *);
|
||||
int notify_same_item (long);
|
||||
int notify_same_recur_item (recur_apoint_llist_node_t *);
|
||||
void notify_config_bar (void);
|
||||
|
||||
#endif /* CALCURSE_NOTIFY_H */
|
||||
|
679
src/recur.c
679
src/recur.c
File diff suppressed because it is too large
Load Diff
68
src/recur.h
68
src/recur.h
@ -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
|
||||
@ -27,26 +27,31 @@
|
||||
#ifndef CALCURSE_RECUR_H
|
||||
#define CALCURSE_RECUR_H
|
||||
|
||||
typedef enum { RECUR_NO,
|
||||
typedef enum
|
||||
{ RECUR_NO,
|
||||
RECUR_DAILY,
|
||||
RECUR_WEEKLY,
|
||||
RECUR_MONTHLY,
|
||||
RECUR_YEARLY,
|
||||
RECUR_TYPES
|
||||
} recur_types_t;
|
||||
}
|
||||
recur_types_t;
|
||||
|
||||
struct days_s {
|
||||
struct days_s
|
||||
{
|
||||
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 */
|
||||
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 days_s *exc; /* days when the item should not be repeated */
|
||||
@ -55,14 +60,18 @@ typedef struct recur_apoint_llist_node {
|
||||
char state; /* 8 bits to store item state */
|
||||
char *mesg; /* appointment description */
|
||||
char *note; /* note attached to appointment */
|
||||
} recur_apoint_llist_node_t;
|
||||
}
|
||||
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_t;
|
||||
}
|
||||
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 days_s *exc; /* days when the item should not be repeated */
|
||||
@ -75,27 +84,28 @@ struct recur_event_s {
|
||||
extern recur_apoint_llist_t *recur_alist_p;
|
||||
extern struct recur_event_s *recur_elist;
|
||||
|
||||
int recur_apoint_llist_init(void);
|
||||
char recur_def2char(recur_types_t);
|
||||
int recur_char2def(char);
|
||||
recur_apoint_llist_node_t *recur_apoint_scan(FILE *, struct tm, struct tm,
|
||||
int recur_apoint_llist_init (void);
|
||||
char recur_def2char (recur_types_t);
|
||||
int recur_char2def (char);
|
||||
recur_apoint_llist_node_t *recur_apoint_scan (FILE *, struct tm, struct tm,
|
||||
char, int, struct tm, char *,
|
||||
struct days_s *, char);
|
||||
struct recur_event_s *recur_event_scan(FILE *, struct tm, int, char,
|
||||
int, struct tm, char *, struct days_s *);
|
||||
void recur_save_data(FILE *);
|
||||
unsigned recur_item_inday(long, struct days_s *, int,
|
||||
int, long, long);
|
||||
void recur_event_erase(long, unsigned, unsigned,
|
||||
erase_flag_e);
|
||||
void recur_apoint_erase(long, unsigned, unsigned,
|
||||
erase_flag_e);
|
||||
void recur_repeat_item(conf_t *);
|
||||
struct days_s *recur_exc_scan(FILE *);
|
||||
struct notify_app_s *recur_apoint_check_next(struct notify_app_s *,
|
||||
struct recur_event_s *recur_event_scan (FILE *, struct tm, int, char,
|
||||
int, struct tm, char *,
|
||||
struct days_s *);
|
||||
void recur_save_data (FILE *);
|
||||
unsigned recur_item_inday (long, struct days_s *, int, int,
|
||||
long, long);
|
||||
recur_apoint_llist_node_t *recur_get_apoint(long, int);
|
||||
struct recur_event_s *recur_get_event(long, int);
|
||||
void recur_apoint_switch_notify(long, int);
|
||||
void recur_event_erase (long, unsigned, unsigned,
|
||||
erase_flag_e);
|
||||
void recur_apoint_erase (long, unsigned, unsigned,
|
||||
erase_flag_e);
|
||||
void recur_repeat_item (conf_t *);
|
||||
struct days_s *recur_exc_scan (FILE *);
|
||||
struct notify_app_s *recur_apoint_check_next (struct notify_app_s *,
|
||||
long, long);
|
||||
recur_apoint_llist_node_t *recur_get_apoint (long, int);
|
||||
struct recur_event_s *recur_get_event (long, int);
|
||||
void recur_apoint_switch_notify (long, int);
|
||||
|
||||
#endif /* CALCURSE_RECUR_H */
|
||||
|
44
src/sigs.c
44
src/sigs.c
@ -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
|
||||
* Copyright (c) 2007 Frederic Culot
|
||||
* Copyright (c) 2007-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -40,45 +40,49 @@
|
||||
* Also catch CTRL-C (SIGINT), and SIGWINCH to resize screen automatically.
|
||||
*/
|
||||
static void
|
||||
signal_handler(int sig)
|
||||
signal_handler (int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
switch (sig)
|
||||
{
|
||||
case SIGCHLD:
|
||||
while (waitpid(WAIT_MYPGRP, NULL, WNOHANG) > 0)
|
||||
while (waitpid (WAIT_MYPGRP, NULL, WNOHANG) > 0)
|
||||
;
|
||||
break;
|
||||
case SIGWINCH:
|
||||
clearok(curscr, TRUE);
|
||||
ungetch(KEY_RESIZE);
|
||||
clearok (curscr, TRUE);
|
||||
ungetch (KEY_RESIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Signal handling init. */
|
||||
void
|
||||
sigs_init(struct sigaction *sa)
|
||||
sigs_init (struct sigaction *sa)
|
||||
{
|
||||
sa->sa_handler = signal_handler;
|
||||
sa->sa_flags = 0;
|
||||
sigemptyset(&sa->sa_mask);
|
||||
if (sigaction(SIGCHLD, sa, NULL) != 0) {
|
||||
perror("sigaction");
|
||||
exit(EXIT_FAILURE);
|
||||
sigemptyset (&sa->sa_mask);
|
||||
if (sigaction (SIGCHLD, sa, NULL) != 0)
|
||||
{
|
||||
perror ("sigaction");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sa->sa_handler = signal_handler;
|
||||
sa->sa_flags = 0;
|
||||
sigemptyset(&sa->sa_mask);
|
||||
if (sigaction(SIGWINCH, sa, NULL) != 0) {
|
||||
perror("sigaction");
|
||||
exit(EXIT_FAILURE);
|
||||
sigemptyset (&sa->sa_mask);
|
||||
if (sigaction (SIGWINCH, sa, NULL) != 0)
|
||||
{
|
||||
perror ("sigaction");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
sa->sa_handler = SIG_IGN;
|
||||
sa->sa_flags = 0;
|
||||
sigemptyset(&(sa->sa_mask));
|
||||
if (sigaction(SIGINT, sa, NULL) != 0) {
|
||||
perror("sigaction");
|
||||
exit(EXIT_FAILURE);
|
||||
sigemptyset (&(sa->sa_mask));
|
||||
if (sigaction (SIGINT, sa, NULL) != 0)
|
||||
{
|
||||
perror ("sigaction");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
* Copyright (c) 2007 Frederic Culot
|
||||
* Copyright (c) 2007-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -27,6 +27,6 @@
|
||||
#ifndef CALCURSE_SIGS_H
|
||||
#define CALCURSE_SIGS_H
|
||||
|
||||
void sigs_init(struct sigaction *);
|
||||
void sigs_init (struct sigaction *);
|
||||
|
||||
#endif /* CALCURSE_SIGS_H */
|
||||
|
279
src/todo.c
279
src/todo.c
@ -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
|
||||
* Copyright (c) 2004-2007 Frederic Culot
|
||||
* Copyright (c) 2004-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -41,73 +41,74 @@ static char *msgsav;
|
||||
|
||||
/* Returns a structure containing the selected item. */
|
||||
static struct todo_s *
|
||||
todo_get_item(int item_number)
|
||||
todo_get_item (int item_number)
|
||||
{
|
||||
struct todo_s *o;
|
||||
int i;
|
||||
|
||||
o = todolist;
|
||||
for (i = 1; i < item_number; i++) {
|
||||
for (i = 1; i < item_number; i++)
|
||||
{
|
||||
o = o->next;
|
||||
}
|
||||
return o;
|
||||
return (o);
|
||||
}
|
||||
|
||||
/* Sets which todo is highlighted. */
|
||||
void
|
||||
todo_hilt_set(int highlighted)
|
||||
todo_hilt_set (int highlighted)
|
||||
{
|
||||
hilt = highlighted;
|
||||
}
|
||||
|
||||
void
|
||||
todo_hilt_decrease(void)
|
||||
todo_hilt_decrease (void)
|
||||
{
|
||||
hilt--;
|
||||
}
|
||||
|
||||
void
|
||||
todo_hilt_increase(void)
|
||||
todo_hilt_increase (void)
|
||||
{
|
||||
hilt++;
|
||||
}
|
||||
|
||||
/* Return which todo is highlighted. */
|
||||
int
|
||||
todo_hilt(void)
|
||||
todo_hilt (void)
|
||||
{
|
||||
return (hilt);
|
||||
}
|
||||
|
||||
/* Return the number of todos. */
|
||||
int
|
||||
todo_nb(void)
|
||||
todo_nb (void)
|
||||
{
|
||||
return (todos);
|
||||
}
|
||||
|
||||
/* Set the number of todos. */
|
||||
void
|
||||
todo_set_nb(int nb)
|
||||
todo_set_nb (int nb)
|
||||
{
|
||||
todos = nb;
|
||||
}
|
||||
|
||||
/* Set which one is the first todo to be displayed. */
|
||||
void
|
||||
todo_set_first(int nb)
|
||||
todo_set_first (int nb)
|
||||
{
|
||||
first = nb;
|
||||
}
|
||||
|
||||
void
|
||||
todo_first_increase(void)
|
||||
todo_first_increase (void)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
|
||||
void
|
||||
todo_first_decrease(void)
|
||||
todo_first_decrease (void)
|
||||
{
|
||||
first--;
|
||||
}
|
||||
@ -117,161 +118,172 @@ todo_first_decrease(void)
|
||||
* displayed.
|
||||
*/
|
||||
int
|
||||
todo_hilt_pos(void)
|
||||
todo_hilt_pos (void)
|
||||
{
|
||||
return (hilt - first);
|
||||
}
|
||||
|
||||
/* Return the last visited todo. */
|
||||
char *
|
||||
todo_saved_mesg(void)
|
||||
todo_saved_mesg (void)
|
||||
{
|
||||
return (msgsav);
|
||||
}
|
||||
|
||||
/* Request user to enter a new todo item. */
|
||||
void
|
||||
todo_new_item(void)
|
||||
todo_new_item (void)
|
||||
{
|
||||
int ch = 0;
|
||||
char *mesg = _("Enter the new ToDo item : ");
|
||||
char *mesg_id =
|
||||
_("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
|
||||
char *mesg_id = _("Enter the ToDo priority [1 (highest) - 9 (lowest)] :");
|
||||
char todo_input[BUFSIZ] = "";
|
||||
|
||||
status_mesg(mesg, "");
|
||||
if (getstring(win[STA].p, todo_input, BUFSIZ, 0, 1) ==
|
||||
GETSTRING_VALID) {
|
||||
while ( (ch < '1') || (ch > '9') ) {
|
||||
status_mesg(mesg_id, "");
|
||||
ch = wgetch(win[STA].p);
|
||||
status_mesg (mesg, "");
|
||||
if (getstring (win[STA].p, todo_input, BUFSIZ, 0, 1) == GETSTRING_VALID)
|
||||
{
|
||||
while ((ch < '1') || (ch > '9'))
|
||||
{
|
||||
status_mesg (mesg_id, "");
|
||||
ch = wgetch (win[STA].p);
|
||||
}
|
||||
todo_add(todo_input, ch - '0', NULL);
|
||||
todo_add (todo_input, ch - '0', NULL);
|
||||
todos++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add an item in the todo linked list. */
|
||||
struct todo_s *
|
||||
todo_add(char *mesg, int id, char *note)
|
||||
todo_add (char *mesg, int id, char *note)
|
||||
{
|
||||
struct todo_s *o, **i;
|
||||
o = (struct todo_s *) malloc(sizeof(struct todo_s));
|
||||
o->mesg = (char *) malloc(strlen(mesg) + 1);
|
||||
strncpy(o->mesg, mesg, strlen(mesg) + 1);
|
||||
o = (struct todo_s *) malloc (sizeof (struct todo_s));
|
||||
o->mesg = (char *) malloc (strlen (mesg) + 1);
|
||||
strncpy (o->mesg, mesg, strlen (mesg) + 1);
|
||||
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;
|
||||
for (;;) {
|
||||
if (*i == 0 || (*i)->id > id) {
|
||||
for (;;)
|
||||
{
|
||||
if (*i == 0 || (*i)->id > id)
|
||||
{
|
||||
o->next = *i;
|
||||
*i = o;
|
||||
break;
|
||||
}
|
||||
i = &(*i)->next;
|
||||
}
|
||||
return o;
|
||||
return (o);
|
||||
}
|
||||
|
||||
/* Delete a note previously attached to a todo item. */
|
||||
static void
|
||||
todo_delete_note_bynum(unsigned num)
|
||||
todo_delete_note_bynum (unsigned num)
|
||||
{
|
||||
unsigned n;
|
||||
struct todo_s *i, **iptr;
|
||||
|
||||
n = 0;
|
||||
iptr = &todolist;
|
||||
for (i = todolist; i != 0; i = i->next) {
|
||||
if (n == num) {
|
||||
for (i = todolist; i != 0; i = i->next)
|
||||
{
|
||||
if (n == num)
|
||||
{
|
||||
if (i->note == NULL)
|
||||
ierror(
|
||||
_("FATAL ERROR in todo_delete_note_bynum: "
|
||||
ierror (_("FATAL ERROR in todo_delete_note_bynum: "
|
||||
"no note attached\n"), IERROR_FATAL);
|
||||
erase_note(&i->note, ERASE_FORCE_ONLY_NOTE);
|
||||
erase_note (&i->note, ERASE_FORCE_ONLY_NOTE);
|
||||
return;
|
||||
}
|
||||
iptr = &i->next;
|
||||
n++;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
ierror(_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
|
||||
ierror (_("FATAL ERROR in todo_delete_note_bynum: no such todo\n"),
|
||||
IERROR_FATAL);
|
||||
exit(EXIT_FAILURE);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Delete an item from the todo linked list. */
|
||||
static void
|
||||
todo_delete_bynum(unsigned num, erase_flag_e flag)
|
||||
todo_delete_bynum (unsigned num, erase_flag_e flag)
|
||||
{
|
||||
unsigned n;
|
||||
struct todo_s *i, **iptr;
|
||||
|
||||
n = 0;
|
||||
iptr = &todolist;
|
||||
for (i = todolist; i != 0; i = i->next) {
|
||||
if (n == num) {
|
||||
for (i = todolist; i != 0; i = i->next)
|
||||
{
|
||||
if (n == num)
|
||||
{
|
||||
*iptr = i->next;
|
||||
free(i->mesg);
|
||||
free (i->mesg);
|
||||
if (i->note != NULL)
|
||||
erase_note(&i->note, flag);
|
||||
free(i);
|
||||
erase_note (&i->note, flag);
|
||||
free (i);
|
||||
return;
|
||||
}
|
||||
iptr = &i->next;
|
||||
n++;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
ierror(_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
|
||||
ierror (_("FATAL ERROR in todo_delete_bynum: no such todo\n"),
|
||||
IERROR_FATAL);
|
||||
exit(EXIT_FAILURE);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Delete an item from the ToDo list. */
|
||||
void
|
||||
todo_delete(conf_t *conf)
|
||||
todo_delete (conf_t *conf)
|
||||
{
|
||||
char *choices = "[y/n] ";
|
||||
char *del_todo_str = _("Do you really want to delete this task ?");
|
||||
char *erase_warning =
|
||||
_("This item has a note attached to it. "
|
||||
"Delete (t)odo or just its (n)ote ?");
|
||||
char *erase_choice =
|
||||
_("[t/n] ");
|
||||
char *erase_choice = _("[t/n] ");
|
||||
bool go_for_todo_del = false;
|
||||
int answer = 0, has_note;
|
||||
|
||||
if (conf->confirm_delete) {
|
||||
status_mesg(del_todo_str, choices);
|
||||
answer = wgetch(win[STA].p);
|
||||
if ( (answer == 'y') && (todos > 0) ) {
|
||||
if (conf->confirm_delete)
|
||||
{
|
||||
status_mesg (del_todo_str, choices);
|
||||
answer = wgetch (win[STA].p);
|
||||
if ((answer == 'y') && (todos > 0))
|
||||
{
|
||||
go_for_todo_del = true;
|
||||
} else {
|
||||
erase_status_bar();
|
||||
}
|
||||
else
|
||||
{
|
||||
erase_status_bar ();
|
||||
return;
|
||||
}
|
||||
} else
|
||||
if (todos > 0)
|
||||
}
|
||||
else if (todos > 0)
|
||||
go_for_todo_del = true;
|
||||
|
||||
if (go_for_todo_del == false) {
|
||||
erase_status_bar();
|
||||
if (go_for_todo_del == false)
|
||||
{
|
||||
erase_status_bar ();
|
||||
return;
|
||||
}
|
||||
|
||||
answer = 0;
|
||||
has_note = (todo_get_item(hilt)->note != NULL) ? 1 : 0;
|
||||
has_note = (todo_get_item (hilt)->note != NULL) ? 1 : 0;
|
||||
if (has_note == 0)
|
||||
answer = 't';
|
||||
|
||||
while (answer != 't' && answer != 'n' && answer != ESCAPE) {
|
||||
status_mesg(erase_warning, erase_choice);
|
||||
answer = wgetch(win[STA].p);
|
||||
while (answer != 't' && answer != 'n' && answer != ESCAPE)
|
||||
{
|
||||
status_mesg (erase_warning, erase_choice);
|
||||
answer = wgetch (win[STA].p);
|
||||
}
|
||||
|
||||
switch (answer) {
|
||||
switch (answer)
|
||||
{
|
||||
case 't':
|
||||
todo_delete_bynum(hilt - 1, ERASE_FORCE);
|
||||
todo_delete_bynum (hilt - 1, ERASE_FORCE);
|
||||
todos--;
|
||||
if (hilt > 1)
|
||||
hilt--;
|
||||
@ -281,10 +293,10 @@ todo_delete(conf_t *conf)
|
||||
first--;
|
||||
break;
|
||||
case 'n':
|
||||
todo_delete_note_bynum(hilt - 1);
|
||||
todo_delete_note_bynum (hilt - 1);
|
||||
break;
|
||||
default:
|
||||
erase_status_bar();
|
||||
erase_status_bar ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -294,30 +306,34 @@ todo_delete(conf_t *conf)
|
||||
* given todo_s item.
|
||||
*/
|
||||
static int
|
||||
todo_get_position(struct todo_s *i)
|
||||
todo_get_position (struct todo_s *i)
|
||||
{
|
||||
struct todo_s *o;
|
||||
int n = 1, found = 0;
|
||||
|
||||
for (o = todolist; o; o = o->next) {
|
||||
if (o == i) {
|
||||
for (o = todolist; o; o = o->next)
|
||||
{
|
||||
if (o == i)
|
||||
{
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
if (found) {
|
||||
return n;
|
||||
} else {
|
||||
fputs(_("FATAL ERROR in todo_get_position: todo not found\n"),
|
||||
stderr);
|
||||
exit(EXIT_FAILURE);
|
||||
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. */
|
||||
void
|
||||
todo_chg_priority(int action)
|
||||
todo_chg_priority (int action)
|
||||
{
|
||||
struct todo_s *backup;
|
||||
char backup_mesg[BUFSIZ];
|
||||
@ -325,43 +341,48 @@ todo_chg_priority(int action)
|
||||
char backup_note[NOTESIZ + 1];
|
||||
int do_chg = 1;
|
||||
|
||||
backup = todo_get_item(hilt);
|
||||
strncpy(backup_mesg, backup->mesg, strlen(backup->mesg) + 1);
|
||||
backup = todo_get_item (hilt);
|
||||
strncpy (backup_mesg, backup->mesg, strlen (backup->mesg) + 1);
|
||||
backup_id = backup->id;
|
||||
if (backup->note)
|
||||
strncpy(backup_note, backup->note, NOTESIZ + 1);
|
||||
strncpy (backup_note, backup->note, NOTESIZ + 1);
|
||||
else
|
||||
backup_note[0] = '\0';
|
||||
if (action == '+') {
|
||||
if (action == '+')
|
||||
{
|
||||
(backup_id > 1) ? backup_id-- : do_chg--;
|
||||
} else if (action == '-') {
|
||||
(backup_id < 9) ? backup_id++ : do_chg--;
|
||||
} else { /* NOTREACHED */
|
||||
fputs(_("FATAL ERROR in todo_chg_priority: no such action\n"),
|
||||
stderr);
|
||||
}
|
||||
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);
|
||||
else if (action == '-')
|
||||
{
|
||||
(backup_id < 9) ? backup_id++ : do_chg--;
|
||||
}
|
||||
else
|
||||
{ /* NOTREACHED */
|
||||
fputs (_("FATAL ERROR in todo_chg_priority: no such action\n"), stderr);
|
||||
}
|
||||
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. */
|
||||
void
|
||||
todo_edit_item(void)
|
||||
todo_edit_item (void)
|
||||
{
|
||||
struct todo_s *i;
|
||||
char *mesg = _("Enter the new ToDo description :");
|
||||
|
||||
status_mesg(mesg, "");
|
||||
i = todo_get_item(hilt);
|
||||
updatestring(win[STA].p, &i->mesg, 0, 1);
|
||||
status_mesg (mesg, "");
|
||||
i = todo_get_item (hilt);
|
||||
updatestring (win[STA].p, &i->mesg, 0, 1);
|
||||
}
|
||||
|
||||
/* Display todo items in the corresponding panel. */
|
||||
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)
|
||||
{
|
||||
WINDOW *w;
|
||||
@ -371,21 +392,22 @@ display_todo_item(int incolor, char *msg, int prio, int note, int len, int y,
|
||||
w = win[TOD].p;
|
||||
ch_note = (note) ? '>' : '.';
|
||||
if (incolor == 0)
|
||||
custom_apply_attr(w, ATTR_HIGHEST);
|
||||
if (strlen(msg) < len)
|
||||
mvwprintw(w, y, x, "%d%c %s", prio, ch_note, msg);
|
||||
else {
|
||||
strncpy(buf, msg, len - 1);
|
||||
custom_apply_attr (w, ATTR_HIGHEST);
|
||||
if (strlen (msg) < len)
|
||||
mvwprintw (w, y, x, "%d%c %s", prio, ch_note, msg);
|
||||
else
|
||||
{
|
||||
strncpy (buf, msg, len - 1);
|
||||
buf[len - 1] = '\0';
|
||||
mvwprintw(w, y, x, "%d%c %s...", prio, ch_note, buf);
|
||||
mvwprintw (w, y, x, "%d%c %s...", prio, ch_note, buf);
|
||||
}
|
||||
if (incolor == 0)
|
||||
custom_remove_attr(w, ATTR_HIGHEST);
|
||||
custom_remove_attr (w, ATTR_HIGHEST);
|
||||
}
|
||||
|
||||
/* Updates the ToDo panel. */
|
||||
void
|
||||
todo_update_panel(window_t *wintod, int which_pan)
|
||||
todo_update_panel (window_t *wintod, int which_pan)
|
||||
{
|
||||
struct todo_s *i;
|
||||
int len = wintod->w - 8;
|
||||
@ -398,23 +420,26 @@ todo_update_panel(window_t *wintod, int which_pan)
|
||||
int incolor = -1;
|
||||
|
||||
/* Print todo item in the panel. */
|
||||
erase_window_part(win[TOD].p, 1, title_lines, wintod->w - 2,
|
||||
wintod->h - 2);
|
||||
for (i = todolist; i != 0; i = i->next) {
|
||||
erase_window_part (win[TOD].p, 1, title_lines, wintod->w - 2, wintod->h - 2);
|
||||
for (i = todolist; i != 0; i = i->next)
|
||||
{
|
||||
num_todo++;
|
||||
t_realpos = num_todo - first;
|
||||
incolor = num_todo - hilt;
|
||||
if (incolor == 0)
|
||||
msgsav = i->mesg;
|
||||
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);
|
||||
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);
|
||||
y_offset = y_offset + todo_lines;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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));
|
||||
int highend = (int) (ratio * first);
|
||||
@ -423,43 +448,43 @@ todo_update_panel(window_t *wintod, int which_pan)
|
||||
|
||||
if ((sbar_top + sbar_length) > wintod->h - 1)
|
||||
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);
|
||||
}
|
||||
|
||||
wnoutrefresh(win[TOD].p);
|
||||
wnoutrefresh (win[TOD].p);
|
||||
}
|
||||
|
||||
/* Attach a note to a todo */
|
||||
void
|
||||
todo_edit_note(char *editor)
|
||||
todo_edit_note (char *editor)
|
||||
{
|
||||
struct todo_s *i;
|
||||
char fullname[BUFSIZ];
|
||||
char *filename;
|
||||
|
||||
i = todo_get_item(hilt);
|
||||
if (i->note == NULL) {
|
||||
if ((filename = new_tempfile(path_notes, NOTESIZ))
|
||||
!= NULL)
|
||||
i = todo_get_item (hilt);
|
||||
if (i->note == NULL)
|
||||
{
|
||||
if ((filename = new_tempfile (path_notes, NOTESIZ)) != NULL)
|
||||
i->note = filename;
|
||||
else
|
||||
return;
|
||||
}
|
||||
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note);
|
||||
wins_launch_external(fullname, editor);
|
||||
snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
|
||||
wins_launch_external (fullname, editor);
|
||||
}
|
||||
|
||||
/* View a note previously attached to a todo */
|
||||
void
|
||||
todo_view_note(char *pager)
|
||||
todo_view_note (char *pager)
|
||||
{
|
||||
struct todo_s *i;
|
||||
char fullname[BUFSIZ];
|
||||
|
||||
i = todo_get_item(hilt);
|
||||
i = todo_get_item (hilt);
|
||||
if (i->note == NULL)
|
||||
return;
|
||||
snprintf(fullname, BUFSIZ, "%s%s", path_notes, i->note);
|
||||
wins_launch_external(fullname, pager);
|
||||
snprintf (fullname, BUFSIZ, "%s%s", path_notes, i->note);
|
||||
wins_launch_external (fullname, pager);
|
||||
}
|
||||
|
45
src/todo.h
45
src/todo.h
@ -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
|
||||
* Copyright (c) 2004-2007 Frederic Culot
|
||||
* Copyright (c) 2004-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -29,7 +29,8 @@
|
||||
|
||||
#include "wins.h"
|
||||
|
||||
struct todo_s {
|
||||
struct todo_s
|
||||
{
|
||||
struct todo_s *next;
|
||||
char *mesg;
|
||||
int id;
|
||||
@ -38,24 +39,24 @@ struct todo_s {
|
||||
|
||||
extern struct todo_s *todolist;
|
||||
|
||||
void todo_hilt_set(int);
|
||||
void todo_hilt_decrease(void);
|
||||
void todo_hilt_increase(void);
|
||||
int todo_hilt(void);
|
||||
int todo_nb(void);
|
||||
void todo_set_nb(int);
|
||||
void todo_set_first(int);
|
||||
void todo_first_increase(void);
|
||||
void todo_first_decrease(void);
|
||||
int todo_hilt_pos(void);
|
||||
char *todo_saved_mesg(void);
|
||||
void todo_new_item(void);
|
||||
struct todo_s *todo_add(char *, int, char *);
|
||||
void todo_delete(conf_t *);
|
||||
void todo_chg_priority(int);
|
||||
void todo_edit_item(void);
|
||||
void todo_update_panel(window_t *, int);
|
||||
void todo_edit_note(char *);
|
||||
void todo_view_note(char *);
|
||||
void todo_hilt_set (int);
|
||||
void todo_hilt_decrease (void);
|
||||
void todo_hilt_increase (void);
|
||||
int todo_hilt (void);
|
||||
int todo_nb (void);
|
||||
void todo_set_nb (int);
|
||||
void todo_set_first (int);
|
||||
void todo_first_increase (void);
|
||||
void todo_first_decrease (void);
|
||||
int todo_hilt_pos (void);
|
||||
char *todo_saved_mesg (void);
|
||||
void todo_new_item (void);
|
||||
struct todo_s *todo_add (char *, int, char *);
|
||||
void todo_delete (conf_t *);
|
||||
void todo_chg_priority (int);
|
||||
void todo_edit_item (void);
|
||||
void todo_update_panel (window_t *, int);
|
||||
void todo_edit_note (char *);
|
||||
void todo_view_note (char *);
|
||||
|
||||
#endif /* CALCURSE_TODO_H */
|
||||
|
618
src/utils.c
618
src/utils.c
File diff suppressed because it is too large
Load Diff
86
src/utils.h
86
src/utils.h
@ -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
|
||||
@ -51,55 +51,61 @@
|
||||
#define GETSTRING_ESC 1 /* user pressed escape to cancel editing */
|
||||
#define GETSTRING_RET 2 /* return was pressed without entering any text */
|
||||
|
||||
typedef struct { /* structure defining a keybinding */
|
||||
typedef struct
|
||||
{ /* structure defining a keybinding */
|
||||
char *key;
|
||||
char *label;
|
||||
} binding_t;
|
||||
}
|
||||
binding_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
IERROR_FATAL,
|
||||
IERROR_WARN
|
||||
} ierror_sev_e;
|
||||
}
|
||||
ierror_sev_e;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
ERASE_DONT_FORCE,
|
||||
ERASE_FORCE,
|
||||
ERASE_FORCE_KEEP_NOTE,
|
||||
ERASE_FORCE_ONLY_NOTE
|
||||
} erase_flag_e;
|
||||
}
|
||||
erase_flag_e;
|
||||
|
||||
void exit_calcurse(int);
|
||||
void ierror(const char *, ierror_sev_e);
|
||||
void aerror(const char *, int, const char *);
|
||||
void status_mesg(char *, char *);
|
||||
void erase_status_bar(void);
|
||||
void erase_window_part(WINDOW *, int, int, int, int);
|
||||
WINDOW *popup(int, int, int, int, char *);
|
||||
void print_in_middle(WINDOW *, int, int, int, char *);
|
||||
int getstring(WINDOW *, char *, int, int, int);
|
||||
int updatestring(WINDOW *, char **, int, int);
|
||||
int is_all_digit(char *);
|
||||
void status_bar(void);
|
||||
long date2sec(date_t, unsigned, unsigned);
|
||||
char *date_sec2hour_str(long);
|
||||
char *date_sec2date_str(long, char *);
|
||||
void date_sec2ical_date(long, char *);
|
||||
void date_sec2ical_datetime(long, char *);
|
||||
long update_time_in_date(long, unsigned, unsigned);
|
||||
long get_sec_date(date_t);
|
||||
long min2sec(unsigned);
|
||||
int check_time(char *);
|
||||
void draw_scrollbar(WINDOW *, int, int, int, int, int, bool);
|
||||
void item_in_popup(char *, char *, char *, char *);
|
||||
void reset_status_page(void);
|
||||
void other_status_page(int);
|
||||
long get_today(void);
|
||||
long now(void);
|
||||
char *mycpy(const char *);
|
||||
long mystrtol(const char *);
|
||||
void print_option_incolor(WINDOW *, bool, int, int);
|
||||
char *new_tempfile(const char *, int);
|
||||
void erase_note(char **, erase_flag_e);
|
||||
int parse_date(char *, int, int *, int *, int *);
|
||||
void exit_calcurse (int);
|
||||
void ierror (const char *, ierror_sev_e);
|
||||
void aerror (const char *, int, const char *);
|
||||
void status_mesg (char *, char *);
|
||||
void erase_status_bar (void);
|
||||
void erase_window_part (WINDOW *, int, int, int, int);
|
||||
WINDOW *popup (int, int, int, int, char *);
|
||||
void print_in_middle (WINDOW *, int, int, int, char *);
|
||||
int getstring (WINDOW *, char *, int, int, int);
|
||||
int updatestring (WINDOW *, char **, int, int);
|
||||
int is_all_digit (char *);
|
||||
void status_bar (void);
|
||||
long date2sec (date_t, unsigned, unsigned);
|
||||
char *date_sec2hour_str (long);
|
||||
char *date_sec2date_str (long, char *);
|
||||
void date_sec2ical_date (long, char *);
|
||||
void date_sec2ical_datetime (long, char *);
|
||||
long update_time_in_date (long, unsigned, unsigned);
|
||||
long get_sec_date (date_t);
|
||||
long min2sec (unsigned);
|
||||
int check_time (char *);
|
||||
void draw_scrollbar (WINDOW *, int, int, int, int, int, bool);
|
||||
void item_in_popup (char *, char *, char *, char *);
|
||||
void reset_status_page (void);
|
||||
void other_status_page (int);
|
||||
long get_today (void);
|
||||
long now (void);
|
||||
char *mycpy (const char *);
|
||||
long mystrtol (const char *);
|
||||
void print_option_incolor (WINDOW *, bool, int, int);
|
||||
char *new_tempfile (const char *, int);
|
||||
void erase_note (char **, erase_flag_e);
|
||||
int parse_date (char *, int, int *, int *, int *);
|
||||
|
||||
#endif /* CALCURSE_UTILS_H */
|
||||
|
37
src/vars.c
37
src/vars.c
@ -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
|
||||
@ -45,8 +45,8 @@ bool colorize = false;
|
||||
* variables to store calendar names
|
||||
*/
|
||||
int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
char *monthnames[12] =
|
||||
{ N_("January"),
|
||||
char *monthnames[12] = {
|
||||
N_("January"),
|
||||
N_("February"),
|
||||
N_("March"),
|
||||
N_("April"),
|
||||
@ -57,17 +57,19 @@ char *monthnames[12] =
|
||||
N_("September"),
|
||||
N_("October"),
|
||||
N_("November"),
|
||||
N_("December") };
|
||||
N_("December")
|
||||
};
|
||||
|
||||
char *daynames[8] =
|
||||
{ N_("Sun"),
|
||||
char *daynames[8] = {
|
||||
N_("Sun"),
|
||||
N_("Mon"),
|
||||
N_("Tue"),
|
||||
N_("Wed"),
|
||||
N_("Thu"),
|
||||
N_("Fri"),
|
||||
N_("Sat"),
|
||||
N_("Sun") };
|
||||
N_("Sun")
|
||||
};
|
||||
|
||||
/*
|
||||
* variables to store data path names, which are initialized in
|
||||
@ -85,12 +87,11 @@ struct pad_s *apad;
|
||||
/* Variable to store notify-bar settings. */
|
||||
struct nbar_s *nbar;
|
||||
|
||||
|
||||
/*
|
||||
* Variables init
|
||||
*/
|
||||
void
|
||||
vars_init(conf_t *conf)
|
||||
vars_init (conf_t *conf)
|
||||
{
|
||||
char *PATH_VI = "/usr/bin/vi";
|
||||
char *PATH_LESS = "/usr/bin/less";
|
||||
@ -102,34 +103,34 @@ vars_init(conf_t *conf)
|
||||
conf->auto_save = true;
|
||||
conf->skip_system_dialogs = false;
|
||||
conf->skip_progress_bar = false;
|
||||
strncpy(conf->output_datefmt, "%D", 3);
|
||||
strncpy (conf->output_datefmt, "%D", 3);
|
||||
conf->input_datefmt = 1;
|
||||
|
||||
/* Default external editor and pager */
|
||||
ed = getenv("VISUAL");
|
||||
ed = getenv ("VISUAL");
|
||||
if (ed == NULL || ed[0] == '\0')
|
||||
ed = getenv("EDITOR");
|
||||
ed = getenv ("EDITOR");
|
||||
if (ed == NULL || ed[0] == '\0')
|
||||
ed = PATH_VI;
|
||||
conf->editor = ed;
|
||||
|
||||
pg = getenv("PAGER");
|
||||
pg = getenv ("PAGER");
|
||||
if (pg == NULL || pg[0] == '\0')
|
||||
pg = PATH_LESS;
|
||||
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 */
|
||||
apad = (struct pad_s *) malloc(sizeof(struct pad_s));
|
||||
apad = (struct pad_s *) malloc (sizeof (struct pad_s));
|
||||
apad->length = 1;
|
||||
apad->first_onscreen = 0;
|
||||
|
||||
/* Attribute definitions for color and non-color terminals */
|
||||
custom_init_attr();
|
||||
custom_init_attr ();
|
||||
|
||||
/* Start at the current date */
|
||||
calendar_init_slctd_day();
|
||||
calendar_init_slctd_day ();
|
||||
}
|
||||
|
16
src/vars.h
16
src/vars.h
@ -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
|
||||
@ -61,14 +61,16 @@
|
||||
#define DATEFMT_DESC(datefmt) (datefmt == 1 ? _("mm/dd/yyyy") : \
|
||||
(datefmt == 2 ? _("dd/mm/yyyy") : _("yyyy/mm/dd")))
|
||||
|
||||
struct pad_s {
|
||||
struct pad_s
|
||||
{
|
||||
int width;
|
||||
int length;
|
||||
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
|
||||
* becomes lesser than cntdwn */
|
||||
@ -80,7 +82,8 @@ struct nbar_s {
|
||||
};
|
||||
|
||||
/* General configuration variables */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
bool auto_save;
|
||||
bool confirm_quit;
|
||||
bool confirm_delete;
|
||||
@ -90,7 +93,8 @@ typedef struct {
|
||||
char *pager;
|
||||
char output_datefmt[BUFSIZ]; /* format for displaying date */
|
||||
int input_datefmt; /* format for reading date */
|
||||
} conf_t;
|
||||
}
|
||||
conf_t;
|
||||
|
||||
extern int col, row;
|
||||
extern bool colorize;
|
||||
@ -105,6 +109,6 @@ extern char path_notes[BUFSIZ];
|
||||
extern struct pad_s *apad;
|
||||
extern struct nbar_s *nbar;
|
||||
|
||||
void vars_init(conf_t *conf);
|
||||
void vars_init (conf_t *conf);
|
||||
|
||||
#endif /* CALCURSE_VARS_H */
|
||||
|
267
src/wins.c
267
src/wins.c
@ -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
|
||||
* Copyright (c) 2007 Frederic Culot
|
||||
* Copyright (c) 2007-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -42,42 +42,42 @@ static int layout;
|
||||
|
||||
/* Get the current layout. */
|
||||
int
|
||||
wins_layout(void)
|
||||
wins_layout (void)
|
||||
{
|
||||
return (layout);
|
||||
}
|
||||
|
||||
/* Set the current layout. */
|
||||
void
|
||||
wins_set_layout(int nb)
|
||||
wins_set_layout (int nb)
|
||||
{
|
||||
layout = nb;
|
||||
}
|
||||
|
||||
/* Initialize the selected window in calcurse's interface. */
|
||||
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. */
|
||||
window_e
|
||||
wins_slctd(void)
|
||||
wins_slctd (void)
|
||||
{
|
||||
return (slctd_win);
|
||||
}
|
||||
|
||||
/* Sets the selected window. */
|
||||
void
|
||||
wins_slctd_set(window_e window)
|
||||
wins_slctd_set (window_e window)
|
||||
{
|
||||
slctd_win = window;
|
||||
}
|
||||
|
||||
/* TAB key was hit in the interface, need to select next window. */
|
||||
void
|
||||
wins_slctd_next(void)
|
||||
wins_slctd_next (void)
|
||||
{
|
||||
if (slctd_win == TOD)
|
||||
slctd_win = CAL;
|
||||
@ -87,7 +87,7 @@ wins_slctd_next(void)
|
||||
|
||||
/* Create all the windows. */
|
||||
void
|
||||
wins_init(void)
|
||||
wins_init (void)
|
||||
{
|
||||
char label[BUFSIZ];
|
||||
|
||||
@ -95,27 +95,27 @@ wins_init(void)
|
||||
* Create the three main windows plus the status bar and the pad used to
|
||||
* display appointments and event.
|
||||
*/
|
||||
win[CAL].p = newwin(CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
|
||||
snprintf(label, BUFSIZ, _("Calendar"));
|
||||
wins_show(win[CAL].p, label);
|
||||
win[CAL].p = newwin (CALHEIGHT, CALWIDTH, win[CAL].y, win[CAL].x);
|
||||
snprintf (label, BUFSIZ, _("Calendar"));
|
||||
wins_show (win[CAL].p, label);
|
||||
|
||||
win[APP].p = newwin(win[APP].h, win[APP].w, win[APP].y, win[APP].x);
|
||||
snprintf(label, BUFSIZ, _("Appointments"));
|
||||
wins_show(win[APP].p, label);
|
||||
win[APP].p = newwin (win[APP].h, win[APP].w, win[APP].y, win[APP].x);
|
||||
snprintf (label, BUFSIZ, _("Appointments"));
|
||||
wins_show (win[APP].p, label);
|
||||
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);
|
||||
snprintf(label, BUFSIZ, _("ToDo"));
|
||||
wins_show(win[TOD].p, label);
|
||||
win[TOD].p = newwin (win[TOD].h, win[TOD].w, win[TOD].y, win[TOD].x);
|
||||
snprintf (label, BUFSIZ, _("ToDo"));
|
||||
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 */
|
||||
keypad(win[CAL].p, TRUE);
|
||||
keypad(win[APP].p, TRUE);
|
||||
keypad(win[TOD].p, TRUE);
|
||||
keypad(win[STA].p, TRUE);
|
||||
keypad (win[CAL].p, TRUE);
|
||||
keypad (win[APP].p, TRUE);
|
||||
keypad (win[TOD].p, TRUE);
|
||||
keypad (win[STA].p, TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -123,45 +123,44 @@ wins_init(void)
|
||||
* size and placement.
|
||||
*/
|
||||
void
|
||||
wins_reinit(void)
|
||||
wins_reinit (void)
|
||||
{
|
||||
delwin(win[STA].p);
|
||||
delwin(win[CAL].p);
|
||||
delwin(win[APP].p);
|
||||
delwin(apad->ptrwin);
|
||||
delwin(win[TOD].p);
|
||||
wins_get_config();
|
||||
wins_init();
|
||||
if (notify_bar())
|
||||
notify_reinit_bar(win[NOT].h, win[NOT].w, win[NOT].y,
|
||||
win[NOT].x);
|
||||
delwin (win[STA].p);
|
||||
delwin (win[CAL].p);
|
||||
delwin (win[APP].p);
|
||||
delwin (apad->ptrwin);
|
||||
delwin (win[TOD].p);
|
||||
wins_get_config ();
|
||||
wins_init ();
|
||||
if (notify_bar ())
|
||||
notify_reinit_bar (win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
|
||||
}
|
||||
|
||||
/* Show the window with a border and a label. */
|
||||
void
|
||||
wins_show(WINDOW * win, char *label)
|
||||
wins_show (WINDOW *win, char *label)
|
||||
{
|
||||
int startx, starty, height, width;
|
||||
|
||||
getbegyx(win, starty, startx);
|
||||
getmaxyx(win, height, width);
|
||||
getbegyx (win, starty, startx);
|
||||
getmaxyx (win, height, width);
|
||||
|
||||
box(win, 0, 0);
|
||||
mvwaddch(win, 2, 0, ACS_LTEE);
|
||||
mvwhline(win, 2, 1, ACS_HLINE, width - 2);
|
||||
mvwaddch(win, 2, width - 1, ACS_RTEE);
|
||||
box (win, 0, 0);
|
||||
mvwaddch (win, 2, 0, ACS_LTEE);
|
||||
mvwhline (win, 2, 1, ACS_HLINE, width - 2);
|
||||
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.
|
||||
*/
|
||||
void
|
||||
wins_get_config(void)
|
||||
wins_get_config (void)
|
||||
{
|
||||
/* Get the screen configuration */
|
||||
getmaxyx(stdscr, row, col);
|
||||
getmaxyx (stdscr, row, col);
|
||||
|
||||
/* fixed values for status, notification bars and calendar */
|
||||
win[STA].h = STATUSHEIGHT;
|
||||
@ -169,24 +168,30 @@ wins_get_config(void)
|
||||
win[STA].y = row - win[STA].h;
|
||||
win[STA].x = 0;
|
||||
|
||||
if (notify_bar()) {
|
||||
if (notify_bar ())
|
||||
{
|
||||
win[NOT].h = 1;
|
||||
win[NOT].w = col;
|
||||
win[NOT].y = win[STA].y - 1;
|
||||
win[NOT].x = 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{ /* APPOINTMENT is the biggest panel */
|
||||
win[APP].w = col - CALWIDTH;
|
||||
win[APP].h = row - (win[STA].h + win[NOT].h);
|
||||
win[TOD].w = CALWIDTH;
|
||||
win[TOD].h = row - (CALHEIGHT + win[STA].h + win[NOT].h);
|
||||
} else { /* TODO is the biggest panel */
|
||||
}
|
||||
else
|
||||
{ /* TODO is the biggest panel */
|
||||
win[TOD].w = col - CALWIDTH;
|
||||
win[TOD].h = row - (win[STA].h + win[NOT].h);
|
||||
win[APP].w = CALWIDTH;
|
||||
@ -194,7 +199,8 @@ wins_get_config(void)
|
||||
}
|
||||
|
||||
/* defining the layout */
|
||||
switch (layout) {
|
||||
switch (layout)
|
||||
{
|
||||
case 1:
|
||||
win[APP].y = 0;
|
||||
win[APP].x = 0;
|
||||
@ -264,50 +270,57 @@ wins_get_config(void)
|
||||
|
||||
/* draw panel border in color */
|
||||
static void
|
||||
border_color(WINDOW *window)
|
||||
border_color (WINDOW *window)
|
||||
{
|
||||
int color_attr = A_BOLD;
|
||||
int no_color_attr = A_BOLD;
|
||||
|
||||
if (colorize) {
|
||||
wattron(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
|
||||
box(window, 0, 0);
|
||||
} else {
|
||||
wattron(window, no_color_attr);
|
||||
box(window, 0, 0);
|
||||
if (colorize)
|
||||
{
|
||||
wattron (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
|
||||
box (window, 0, 0);
|
||||
}
|
||||
|
||||
if (colorize) {
|
||||
wattroff(window, color_attr | COLOR_PAIR(COLR_CUSTOM));
|
||||
} else {
|
||||
wattroff(window, no_color_attr);
|
||||
else
|
||||
{
|
||||
wattron (window, no_color_attr);
|
||||
box (window, 0, 0);
|
||||
}
|
||||
|
||||
wnoutrefresh(window);
|
||||
if (colorize)
|
||||
{
|
||||
wattroff (window, color_attr | COLOR_PAIR (COLR_CUSTOM));
|
||||
}
|
||||
else
|
||||
{
|
||||
wattroff (window, no_color_attr);
|
||||
}
|
||||
wnoutrefresh (window);
|
||||
}
|
||||
|
||||
/* draw panel border without any color */
|
||||
static void
|
||||
border_nocolor(WINDOW *window)
|
||||
border_nocolor (WINDOW *window)
|
||||
{
|
||||
int color_attr = A_BOLD;
|
||||
int no_color_attr = A_DIM;
|
||||
|
||||
if (colorize) {
|
||||
wattron(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
|
||||
} else {
|
||||
wattron(window, no_color_attr);
|
||||
if (colorize)
|
||||
{
|
||||
wattron (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
|
||||
}
|
||||
|
||||
box(window, 0, 0);
|
||||
|
||||
if (colorize) {
|
||||
wattroff(window, color_attr | COLOR_PAIR(COLR_DEFAULT));
|
||||
} else {
|
||||
wattroff(window, no_color_attr);
|
||||
else
|
||||
{
|
||||
wattron (window, no_color_attr);
|
||||
}
|
||||
|
||||
wnoutrefresh(window);
|
||||
box (window, 0, 0);
|
||||
if (colorize)
|
||||
{
|
||||
wattroff (window, color_attr | COLOR_PAIR (COLR_DEFAULT));
|
||||
}
|
||||
else
|
||||
{
|
||||
wattroff (window, no_color_attr);
|
||||
}
|
||||
wnoutrefresh (window);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -315,53 +328,53 @@ border_nocolor(WINDOW *window)
|
||||
* selected window.
|
||||
*/
|
||||
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);
|
||||
border_color (win[CAL].p);
|
||||
border_nocolor (win[APP].p);
|
||||
border_nocolor (win[TOD].p);
|
||||
break;
|
||||
|
||||
case APP:
|
||||
border_color(win[APP].p);
|
||||
border_nocolor(win[CAL].p);
|
||||
border_nocolor(win[TOD].p);
|
||||
border_color (win[APP].p);
|
||||
border_nocolor (win[CAL].p);
|
||||
border_nocolor (win[TOD].p);
|
||||
break;
|
||||
|
||||
case TOD:
|
||||
border_color(win[TOD].p);
|
||||
border_nocolor(win[APP].p);
|
||||
border_nocolor(win[CAL].p);
|
||||
border_color (win[TOD].p);
|
||||
border_nocolor (win[APP].p);
|
||||
border_nocolor (win[CAL].p);
|
||||
break;
|
||||
|
||||
default:
|
||||
ierror(_("FATAL ERROR in wins_update: no window selected\n"),
|
||||
ierror (_("FATAL ERROR in wins_update: no window selected\n"),
|
||||
IERROR_FATAL);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
apoint_update_panel(&win[APP], slctd_win);
|
||||
todo_update_panel(&win[TOD], slctd_win);
|
||||
calendar_update_panel(win[CAL].p);
|
||||
status_bar();
|
||||
if (notify_bar())
|
||||
notify_update_bar();
|
||||
wmove(win[STA].p, 0, 0);
|
||||
doupdate();
|
||||
apoint_update_panel (&win[APP], slctd_win);
|
||||
todo_update_panel (&win[TOD], slctd_win);
|
||||
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. */
|
||||
void
|
||||
wins_reset(void)
|
||||
wins_reset (void)
|
||||
{
|
||||
endwin();
|
||||
refresh();
|
||||
curs_set(0);
|
||||
wins_reinit();
|
||||
wins_update();
|
||||
endwin ();
|
||||
refresh ();
|
||||
curs_set (0);
|
||||
wins_reinit ();
|
||||
wins_update ();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -369,30 +382,32 @@ wins_reset(void)
|
||||
* file.
|
||||
*/
|
||||
void
|
||||
wins_launch_external(const char *file, const char *cmd)
|
||||
wins_launch_external (const char *file, const char *cmd)
|
||||
{
|
||||
char *p;
|
||||
int len;
|
||||
|
||||
len = strlen(file) + strlen(cmd) + 2; /* Beware of space between cmd and
|
||||
file. */
|
||||
p = (char *)malloc(sizeof(char) * len);
|
||||
if (snprintf(p, len, "%s %s", cmd, file) == -1) {
|
||||
free(p);
|
||||
/* Beware of space between cmd and file. */
|
||||
len = strlen (file) + strlen (cmd) + 2;
|
||||
|
||||
p = (char *) malloc (sizeof (char) * len);
|
||||
if (snprintf (p, len, "%s %s", cmd, file) == -1)
|
||||
{
|
||||
free (p);
|
||||
return;
|
||||
}
|
||||
if (notify_bar())
|
||||
notify_stop_main_thread();
|
||||
def_prog_mode();
|
||||
endwin();
|
||||
clear();
|
||||
refresh();
|
||||
system(p);
|
||||
reset_prog_mode();
|
||||
clearok(curscr, TRUE);
|
||||
curs_set(0);
|
||||
refresh();
|
||||
if (notify_bar())
|
||||
notify_start_main_thread();
|
||||
free(p);
|
||||
if (notify_bar ())
|
||||
notify_stop_main_thread ();
|
||||
def_prog_mode ();
|
||||
endwin ();
|
||||
clear ();
|
||||
refresh ();
|
||||
system (p);
|
||||
reset_prog_mode ();
|
||||
clearok (curscr, TRUE);
|
||||
curs_set (0);
|
||||
refresh ();
|
||||
if (notify_bar ())
|
||||
notify_start_main_thread ();
|
||||
free (p);
|
||||
}
|
||||
|
42
src/wins.h
42
src/wins.h
@ -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
|
||||
* Copyright (c) 2007 Frederic Culot
|
||||
* Copyright (c) 2007-2008 Frederic Culot
|
||||
*
|
||||
* 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
|
||||
@ -29,38 +29,42 @@
|
||||
|
||||
#include "vars.h"
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
CAL,
|
||||
APP,
|
||||
TOD,
|
||||
NOT,
|
||||
STA,
|
||||
NBWINS
|
||||
} window_e;
|
||||
}
|
||||
window_e;
|
||||
|
||||
/* Window properties */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
WINDOW *p; /* pointer to window */
|
||||
unsigned w; /* width */
|
||||
unsigned h; /* height */
|
||||
int x; /* x position */
|
||||
int y; /* y position */
|
||||
} window_t;
|
||||
}
|
||||
window_t;
|
||||
|
||||
extern window_t win[NBWINS];
|
||||
|
||||
int wins_layout(void);
|
||||
void wins_set_layout(int);
|
||||
void wins_slctd_init(void);
|
||||
window_e wins_slctd(void);
|
||||
void wins_slctd_set(window_e);
|
||||
void wins_slctd_next(void);
|
||||
void wins_init(void);
|
||||
void wins_reinit(void);
|
||||
void wins_show(WINDOW *, char *);
|
||||
void wins_get_config(void);
|
||||
void wins_update(void);
|
||||
void wins_reset(void);
|
||||
void wins_launch_external(const char *, const char *);
|
||||
int wins_layout (void);
|
||||
void wins_set_layout (int);
|
||||
void wins_slctd_init (void);
|
||||
window_e wins_slctd (void);
|
||||
void wins_slctd_set (window_e);
|
||||
void wins_slctd_next (void);
|
||||
void wins_init (void);
|
||||
void wins_reinit (void);
|
||||
void wins_show (WINDOW *, char *);
|
||||
void wins_get_config (void);
|
||||
void wins_update (void);
|
||||
void wins_reset (void);
|
||||
void wins_launch_external (const char *, const char *);
|
||||
|
||||
#endif /* CALCURSE_WINS_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user