Move interaction functions to a separate file
This is a first step to clean up several compilation units and separate the front end from back-end operations. All functions that require user interaction are moved to a new compilation unit "interaction.c". Also, following things are adjusted to the new layout: * Make day_item_get_*() and a few other functions public, so that it can be accessed from the new compilation unit. * Use apoint_hilt(), todo_hilt(), etc. instead of directly accessing static variables. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
144
src/apoint.c
144
src/apoint.c
@@ -135,150 +135,6 @@ struct apoint *apoint_new(char *mesg, char *note, long start, long dur,
|
||||
return apt;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an item in either the appointment or the event list,
|
||||
* depending if the start time is entered or not.
|
||||
*/
|
||||
void apoint_add(void)
|
||||
{
|
||||
#define LTIME 6
|
||||
#define LDUR 12
|
||||
const char *mesg_1 =
|
||||
_("Enter start time ([hh:mm]), leave blank for an all-day event : ");
|
||||
const char *mesg_2 =
|
||||
_
|
||||
("Enter end time ([hh:mm]) or duration ([+hh:mm], [+xxxdxxhxxm] or [+mm]) : ");
|
||||
const char *mesg_3 = _("Enter description :");
|
||||
const char *format_message_1 =
|
||||
_("You entered an invalid start time, should be [hh:mm]");
|
||||
const char *format_message_2 =
|
||||
_
|
||||
("Invalid end time/duration, should be [hh:mm], [+hh:mm], [+xxxdxxhxxm] or [+mm]");
|
||||
const char *enter_str = _("Press [Enter] to continue");
|
||||
int Id = 1;
|
||||
char item_time[LDUR] = "";
|
||||
char item_mesg[BUFSIZ] = "";
|
||||
long apoint_start;
|
||||
unsigned heures, minutes;
|
||||
unsigned apoint_duration;
|
||||
unsigned end_h, end_m;
|
||||
int is_appointment = 1;
|
||||
|
||||
/* Get the starting time */
|
||||
for (;;) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (parse_time(item_time, &heures, &minutes) == 1)
|
||||
break;
|
||||
else {
|
||||
status_mesg(format_message_1, enter_str);
|
||||
wgetch(win[STA].p);
|
||||
}
|
||||
} else
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if an event or appointment is entered,
|
||||
* depending on the starting time, and record the
|
||||
* corresponding item.
|
||||
*/
|
||||
if (is_appointment) { /* Get the appointment duration */
|
||||
item_time[0] = '\0';
|
||||
for (;;) {
|
||||
status_mesg(mesg_2, "");
|
||||
if (getstring(win[STA].p, item_time, LDUR, 0, 1) != GETSTRING_ESC) {
|
||||
if (*item_time == '+' && parse_duration(item_time + 1,
|
||||
&apoint_duration) == 1)
|
||||
break;
|
||||
else if (parse_time(item_time, &end_h, &end_m) == 1) {
|
||||
if (end_h < heures || ((end_h == heures) && (end_m < minutes))) {
|
||||
apoint_duration = MININSEC - minutes + end_m
|
||||
+ (24 + end_h - (heures + 1)) * MININSEC;
|
||||
} else {
|
||||
apoint_duration = MININSEC - minutes
|
||||
+ end_m + (end_h - (heures + 1)) * MININSEC;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
status_mesg(format_message_2, enter_str);
|
||||
wgetch(win[STA].p);
|
||||
}
|
||||
} else
|
||||
return;
|
||||
}
|
||||
} 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_new(item_mesg, 0L, apoint_start, min2sec(apoint_duration), 0L);
|
||||
if (notify_bar())
|
||||
notify_check_added(item_mesg, apoint_start, 0L);
|
||||
} else
|
||||
event_new(item_mesg, 0L, date2sec(*calendar_get_slctd_day(), 0, 0), Id);
|
||||
|
||||
if (hilt == 0)
|
||||
hilt++;
|
||||
}
|
||||
wins_erase_status_bar();
|
||||
}
|
||||
|
||||
/* Delete an item from the appointment list. */
|
||||
void apoint_delete(unsigned *nb_events, unsigned *nb_apoints)
|
||||
{
|
||||
const char *del_app_str = _("Do you really want to delete this item ?");
|
||||
long date;
|
||||
int nb_items = *nb_apoints + *nb_events;
|
||||
int to_be_removed = 0;
|
||||
|
||||
date = calendar_get_slctd_day_sec();
|
||||
|
||||
if (nb_items == 0)
|
||||
return;
|
||||
|
||||
if (conf.confirm_delete) {
|
||||
if (status_ask_bool(del_app_str) != 1) {
|
||||
wins_erase_status_bar();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (nb_items != 0) {
|
||||
switch (day_erase_item(date, hilt, ERASE_DONT_FORCE)) {
|
||||
case EVNT:
|
||||
case RECUR_EVNT:
|
||||
(*nb_events)--;
|
||||
to_be_removed = 1;
|
||||
break;
|
||||
case APPT:
|
||||
case RECUR_APPT:
|
||||
(*nb_apoints)--;
|
||||
to_be_removed = 3;
|
||||
break;
|
||||
case 0:
|
||||
return;
|
||||
default:
|
||||
EXIT(_("no such type"));
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
if (hilt > 1)
|
||||
hilt--;
|
||||
if (apad.first_onscreen >= to_be_removed)
|
||||
apad.first_onscreen = apad.first_onscreen - to_be_removed;
|
||||
if (nb_items == 1)
|
||||
hilt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cut an item, so that it can be pasted somewhere else later. */
|
||||
int apoint_cut(unsigned *nb_events, unsigned *nb_apoints)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user