import flag and 'i' keybinding added

This commit is contained in:
Frederic Culot 2008-09-21 08:05:52 +00:00
parent 96b858b8bc
commit 7ddfcccee0
9 changed files with 163 additions and 105 deletions

View File

@ -1,3 +1,17 @@
2008-09-21 Frederic Culot <frederic@culot.org>
* src/utils.c (status_bar): 'I' keybinding added to import data
* src/help.c (help_screen, wanted_page): import function help text
added
* src/args.c (usage, help_arg, parse_args): import flag added
* src/io.c (io_save_cal): ui mode (command line or curses mode)
taken into account
* src/utils.h: DISPLAY macro renamed into ERROR_MSG
2008-09-20 Frederic Culot <frederic@culot.org>
* src/io.c (io_import_data): temporary log file created to store

View File

@ -1,4 +1,4 @@
/* $calcurse: args.c,v 1.39 2008/09/15 20:40:22 culot Exp $ */
/* $calcurse: args.c,v 1.40 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -48,7 +48,7 @@ static void
usage ()
{
char *arg_usage =
_("Usage: calcurse [-h|-v] [-N] [-an] [-t[num]] [-x[format]]\n"
_("Usage: calcurse [-h|-v] [-N] [-an] [-t[num]] [-i<file>] [-x[format]]\n"
" [-d <date>|<num>] [-s[date]] [-r[range]]\n"
" [-c<file> | -D<dir>]\n");
fputs (arg_usage, stdout);
@ -103,6 +103,8 @@ help_arg ()
" print events and appointments for <date> or <num> upcoming days and"
"\n\texit. To specify both a starting date and a range, use the\n"
"\t'--startday' and the '--range' option.\n"
"\n -i <file>, --import <file>\n"
" import the icalendar data contained in <file>. \n"
"\n -n, --next\n"
" print next appointment within upcoming 24 hours "
"and exit. Also given\n\tis the remaining time before this "
@ -573,21 +575,22 @@ parse_args (int argc, char **argv, conf_t *conf)
int dflag = 0; /* -d: print appointments for a specified days */
int Dflag = 0; /* -D: specify data directory to use */
int hflag = 0; /* -h: print help text */
int iflag = 0; /* -i: import data */
int nflag = 0; /* -n: print next appointment */
int Nflag = 0; /* -N: also print note content with apps and todos */
int rflag = 0; /* -r: specify the range of days to consider */
int sflag = 0; /* -s: specify the first day to consider */
int tflag = 0; /* -t: print todo list */
int vflag = 0; /* -v: print version number */
int xflag = 0; /* -x: export data to iCalendar format */
int xflag = 0; /* -x: export data */
int tnum = 0, xfmt = 0;
int non_interactive = 0, multiple_flag = 0, load_data = 0;
int no_file = 1;
char *ddate = "", *cfile = NULL, *range = NULL, *startday = NULL;
char *datadir = NULL;
char *datadir = NULL, *ifile = NULL;
static char *optstr = "hvnNax::t::d:c:r:s:D:";
static char *optstr = "hvnNax::t::d:c:r:s:D:i:";
struct option longopts[] = {
{"appointment", no_argument, NULL, 'a'},
@ -595,6 +598,7 @@ parse_args (int argc, char **argv, conf_t *conf)
{"day", required_argument, NULL, 'd'},
{"directory", required_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'},
{"import", required_argument, NULL, 'i'},
{"next", no_argument, NULL, 'n'},
{"note", no_argument, NULL, 'N'},
{"range", required_argument, NULL, 'r'},
@ -633,6 +637,12 @@ parse_args (int argc, char **argv, conf_t *conf)
case 'h':
hflag = 1;
break;
case 'i':
iflag = 1;
multiple_flag++;
load_data++;
ifile = optarg;
break;
case 'n':
nflag = 1;
multiple_flag++;
@ -746,9 +756,20 @@ parse_args (int argc, char **argv, conf_t *conf)
{
io_init (cfile, datadir);
no_file = io_check_data_files ();
if (dflag || aflag || nflag || xflag || rflag || sflag)
if (dflag || aflag || nflag || iflag || xflag || rflag || sflag)
io_load_app ();
}
if (iflag)
{
notify_init_vars ();
vars_init (conf);
custom_load_conf (conf, 0);
io_load_todo ();
io_import_data (IO_MODE_NONINTERACTIVE, IO_IMPORT_ICAL, conf,
ifile);
io_save_cal (IO_MODE_NONINTERACTIVE, conf);
non_interactive = 1;
}
if (xflag)
{
notify_init_vars ();

View File

@ -1,4 +1,4 @@
/* $calcurse: calcurse.c,v 1.67 2008/09/20 12:47:06 culot Exp $ */
/* $calcurse: calcurse.c,v 1.68 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -379,13 +379,13 @@ main (int argc, char **argv)
case 'S':
case 's': /* Save function */
io_save_cal (&conf);
io_save_cal (IO_MODE_INTERACTIVE, &conf);
break;
case 'I':
case 'i': /* Import function */
erase_status_bar ();
io_import_data (IO_MODE_INTERACTIVE, IO_IMPORT_ICAL, &conf);
io_import_data (IO_MODE_INTERACTIVE, IO_IMPORT_ICAL, &conf, NULL);
do_storage = true;
break;
@ -513,7 +513,7 @@ main (int argc, char **argv)
case ('Q'): /* Quit calcurse :( */
case ('q'):
if (conf.auto_save)
io_save_cal (&conf);
io_save_cal (IO_MODE_INTERACTIVE, &conf);
if (conf.confirm_quit)
{

View File

@ -1,4 +1,4 @@
/* $calcurse: custom.c,v 1.22 2008/04/19 21:05:15 culot Exp $ */
/* $calcurse: custom.c,v 1.23 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -191,7 +191,7 @@ custom_init_attr (void)
/* Apply window attribute */
void
custom_apply_attr (WINDOW * win, int attr_num)
custom_apply_attr (WINDOW *win, int attr_num)
{
if (colorize)
wattron (win, attr.color[attr_num]);
@ -201,7 +201,7 @@ custom_apply_attr (WINDOW * win, int attr_num)
/* Remove window attribute */
void
custom_remove_attr (WINDOW * win, int attr_num)
custom_remove_attr (WINDOW *win, int attr_num)
{
if (colorize)
wattroff (win, attr.color[attr_num]);
@ -211,7 +211,7 @@ custom_remove_attr (WINDOW * win, int attr_num)
/* Load the user configuration. */
void
custom_load_conf (conf_t * conf, int background)
custom_load_conf (conf_t *conf, int background)
{
FILE *data_file;
char *mesg_line1 = _("Failed to open config file");

View File

@ -1,4 +1,4 @@
/* $calcurse: help.c,v 1.28 2008/08/11 18:08:45 culot Exp $ */
/* $calcurse: help.c,v 1.29 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -39,6 +39,7 @@ typedef enum
{
HELP_MAIN,
HELP_SAVE,
HELP_IMPORT,
HELP_EXPORT,
HELP_DISPLACEMENT,
HELP_VIEW,
@ -183,6 +184,10 @@ wanted_page (int ch)
page = HELP_SAVE;
break;
case 'i':
page = HELP_IMPORT;
break;
case 'x':
page = HELP_EXPORT;
break;
@ -299,6 +304,24 @@ help_screen (void)
"\nIn the config menu, you can choose to save the Calcurse data\n"
"automatically before quitting.");
hscr[HELP_IMPORT].title = _("Import:\n");
hscr[HELP_IMPORT].text =
_("Pressing 'I' allows you to import data from an icalendar file.\n"
"You are asked to enter the file name from which to load ical items.\n\n"
"At the end of the import process, and if the general option\n"
"'skip_system_dialogs' is not set to 'yes', a report indicating how\n"
"many items were imported is shown.\n"
"This report contains the total number of lines read, the number of\n"
"appointments, events and todo items which were successfully imported,\n"
"together with the number of items for which problems occured and that\n"
"were skipped, if any.\n\n"
"If one or more items could not be imported, one has the possibility to\n"
"read the import process report in order to identify which problems\n"
"occured.\n"
"In this report is shown one item per line, with the line in the input\n"
"stream at which this item begins, together with the description of why\n"
"the item could not be imported.\n");
hscr[HELP_EXPORT].title = _("Export:\n");
hscr[HELP_EXPORT].text =
_("Pressing 'X' leads to the export submenu, from which you can choose\n"

137
src/io.c
View File

@ -1,4 +1,4 @@
/* $calcurse: io.c,v 1.36 2008/09/20 12:47:06 culot Exp $ */
/* $calcurse: io.c,v 1.37 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -723,7 +723,7 @@ io_extract_data (char *dst_data, const char *org, int len)
/* Save the calendar data */
void
io_save_cal (conf_t *conf)
io_save_cal (io_mode_t mode, conf_t *conf)
{
FILE *data_file;
struct event_s *k;
@ -745,7 +745,7 @@ io_save_cal (conf_t *conf)
char *enter = _("Press [ENTER] to continue");
bool show_bar = false;
if (!conf->skip_progress_bar)
if (mode == IO_MODE_INTERACTIVE && !conf->skip_progress_bar)
show_bar = true;
/* Save the user configuration. */
@ -753,8 +753,8 @@ io_save_cal (conf_t *conf)
if (show_bar)
progress_bar (PROGRESS_BAR_SAVE, 0);
data_file = fopen (path_conf, "w");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
if (data_file == NULL)
ERROR_MSG (access_pb);
else
{
custom_color_theme_name (theme_name);
@ -806,7 +806,8 @@ io_save_cal (conf_t *conf)
fprintf (data_file, "layout=\n");
fprintf (data_file, "%d\n", wins_layout ());
pthread_mutex_lock (&nbar->mutex);
if (mode == IO_MODE_INTERACTIVE)
pthread_mutex_lock (&nbar->mutex);
fprintf (data_file,
"\n# If this option is set to yes, "
"notify-bar will be displayed :\n");
@ -847,7 +848,8 @@ io_save_cal (conf_t *conf)
fprintf (data_file, "input_datefmt=\n");
fprintf (data_file, "%d\n", conf->input_datefmt);
pthread_mutex_unlock (&nbar->mutex);
if (mode == IO_MODE_INTERACTIVE)
pthread_mutex_unlock (&nbar->mutex);
fclose (data_file);
}
@ -856,8 +858,8 @@ io_save_cal (conf_t *conf)
if (show_bar)
progress_bar (PROGRESS_BAR_SAVE, 1);
data_file = fopen (path_todo, "w");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
if (data_file == NULL)
ERROR_MSG (access_pb);
else
{
for (i = todolist; i != 0; i = i->next)
@ -878,16 +880,18 @@ io_save_cal (conf_t *conf)
if (show_bar)
progress_bar (PROGRESS_BAR_SAVE, 2);
data_file = fopen (path_apts, "w");
if (data_file == (FILE *) 0)
status_mesg (access_pb, "");
if (data_file == NULL)
ERROR_MSG (access_pb);
else
{
recur_save_data (data_file);
pthread_mutex_lock (&(alist_p->mutex));
if (mode == IO_MODE_INTERACTIVE)
pthread_mutex_lock (&(alist_p->mutex));
for (j = alist_p->root; j != 0; j = j->next)
apoint_write (j, data_file);
pthread_mutex_unlock (&(alist_p->mutex));
if (mode == IO_MODE_INTERACTIVE)
pthread_mutex_unlock (&(alist_p->mutex));
for (k = eventlist; k != 0; k = k->next)
event_write (k, data_file);
@ -895,7 +899,7 @@ io_save_cal (conf_t *conf)
}
/* Print a message telling data were saved */
if (!conf->skip_system_dialogs)
if (mode == IO_MODE_INTERACTIVE && !conf->skip_system_dialogs)
{
status_mesg (save_success, enter);
wgetch (win[STA].p);
@ -2142,16 +2146,17 @@ get_import_stream (export_type_t type)
* and is cleared at the end.
*/
void
io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
io_import_data (io_mode_t mode, import_type_t type, conf_t *conf,
char *stream_name)
{
const char *logprefix = "/tmp/calcurse_log.";
const string_t vevent = STRING_BUILD ("BEGIN:VEVENT");
const string_t vtodo = STRING_BUILD ("BEGIN:VTODO");
char *success = _("The data were successfully imported");
char *enter = _("Press [ENTER] to continue");
char *lines_read = _("Number of lines read: %04d ");
char *proc_report = _("Import process report: %04d lines read ");
char *lines_stats =
_("(apoints: %d / events: %d / todos: %d / skipped: %d)\r");
_("%d apps / %d events / %d todos / %d skipped ");
char *lines_stats_interactive =
_("%d apps / %d events / %d todos / %d skipped ([ENTER] to continue)");
char *logname, flogname[BUFSIZ], buf[BUFSIZ];
FILE *stream = NULL, *logfd;
float ical_version;
@ -2164,7 +2169,10 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
switch (mode)
{
case IO_MODE_NONINTERACTIVE:
stream = stdin;
stream = fopen (stream_name, "r");
EXIT_IF (stream == NULL,
_("FATAL ERROR: the input file cannot be accessed, "
"Aborting..."));
break;
case IO_MODE_INTERACTIVE:
stream = get_import_stream (type);
@ -2177,43 +2185,26 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
if (stream == NULL)
return;
logname = new_tempfile (logprefix, NOTESIZ);
RETURN_IF (logname == NULL,
_("Warning: could not create new note file to store "
"description. Aborting...\n"));
snprintf (flogname, BUFSIZ, "%s%s", logprefix, logname);
logfd = fopen (flogname, "w");
RETURN_IF (logfd == NULL,
_("Warning: could not open temporary log file, Aborting..."));
bzero (&stats, sizeof stats);
ical_version = ical_chk_header (stream, &stats.lines);
RETURN_IF (ical_version < 0,
_("Warning: ical header malformed, wrong version number. "
"Aborting..."));
logname = new_tempfile (logprefix, NOTESIZ);
RETURN_IF (logname == NULL,
_("Warning: could not create new note file to store "
"description. Aborting...\n"));
snprintf (flogname, BUFSIZ, "%s%s", logprefix, logname);
logfd = fopen (flogname, "w");
RETURN_IF (logfd == NULL,
_("Warning: could not open temporary log file, Aborting..."));
ical_log_init (logfd, ical_version);
while (fgets (buf, BUFSIZ, stream) != NULL)
{
stats.lines++;
str_toupper (buf);
if (mode == IO_MODE_INTERACTIVE)
{
char read[BUFSIZ], stat[BUFSIZ];
snprintf (read, BUFSIZ, lines_read, stats.lines);
snprintf (stat, BUFSIZ, lines_stats, stats.apoints, stats.events,
stats.todos, stats.skipped);
status_mesg (read, stat);
}
else
{
printf (lines_read, stats.lines);
printf (lines_stats,
stats.lines, stats.apoints, stats.events, stats.todos,
stats.skipped);
}
if (strncmp (buf, vevent.str, vevent.len) == 0)
{
ical_read_event (stream, logfd, &stats.events, &stats.apoints,
@ -2228,6 +2219,24 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
if (stream != stdin)
fclose (stream);
if (mode == IO_MODE_INTERACTIVE && !conf->skip_system_dialogs)
{
char read[BUFSIZ], stat[BUFSIZ];
snprintf (read, BUFSIZ, proc_report, stats.lines);
snprintf (stat, BUFSIZ, lines_stats_interactive, stats.apoints,
stats.events, stats.todos, stats.skipped);
status_mesg (read, stat);
wgetch (win[STA].p);
}
else if (mode == IO_MODE_NONINTERACTIVE)
{
printf (proc_report, stats.lines);
printf ("\n");
printf (lines_stats, stats.lines, stats.apoints, stats.events,
stats.todos, stats.skipped);
}
/* User has the choice to look at the log file if some items could not be
imported.
*/
@ -2236,47 +2245,37 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
{
char *view_log = _("Some items could not be imported, see log file ?");
char *choices = "[y/n] ";
int answer;
int ans;
if (mode == IO_MODE_NONINTERACTIVE)
{
fprintf (stdout, "\n%s %s", view_log, choices);
do
{
answer = scanf ("%d", &answer);
if (answer == 'y')
{
char cmd[BUFSIZ];
int ans;
snprintf (cmd, BUFSIZ, "%s %s", conf->pager, flogname);
system (cmd);
}
printf ("\n%s %s", view_log, choices);
ans = fgetc (stdin);
if (ans == 'y')
{
char cmd[BUFSIZ];
snprintf (cmd, BUFSIZ, "%s %s", conf->pager, flogname);
system (cmd);
}
while (answer != 'y' && answer != 'n');
}
else
{
status_mesg (view_log, choices);
do
{
answer = wgetch (win[STA].p);
if (answer == 'y')
ans = wgetch (win[STA].p);
if (ans == 'y')
{
wins_launch_external (flogname, conf->pager);
}
}
while (answer != 'y' && answer != 'n');
while (ans != 'y' && ans != 'n');
erase_status_bar ();
}
}
else
{
if (!conf->skip_system_dialogs && mode == IO_MODE_INTERACTIVE)
{
status_mesg (success, enter);
wgetch (win[STA].p);
}
}
EXIT_IF (unlink (flogname) != 0,
_("Warning: could not erase temporary log file, Aborting..."));
free (logname);

View File

@ -1,4 +1,4 @@
/* $calcurse: io.h,v 1.14 2008/09/20 12:47:06 culot Exp $ */
/* $calcurse: io.h,v 1.15 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -51,13 +51,13 @@ typedef enum
void io_init (char *, char *);
void io_extract_data (char *, const char *, int);
void io_save_cal (conf_t *);
void io_save_cal (io_mode_t, 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 (io_mode_t, export_type_t, conf_t *);
void io_export_bar (void);
void io_import_data (io_mode_t, import_type_t, conf_t *);
void io_import_data (io_mode_t, import_type_t, conf_t *, char *);
#endif /* CALCURSE_IO_H */

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.c,v 1.50 2008/09/20 12:47:06 culot Exp $ */
/* $calcurse: utils.c,v 1.51 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -445,6 +445,7 @@ status_bar (void)
binding_t quit = { " Q", _("Quit") };
binding_t save = { " S", _("Save") };
binding_t export = { " X", _("Export") };
binding_t import = { " I", _("Import") };
binding_t add = { " A", _("Add Item") };
binding_t del = { " D", _("Del Item") };
binding_t edit = { " E", _("Edit Itm") };
@ -472,16 +473,16 @@ status_bar (void)
binding_t *binding[TOTAL_CMDS] = {
/* calendar keys */
&help, &quit, &save, &export, &day, &week, &weekb, &weeke, &tab,
&togo, &conf, &othr, &appt, &todo, &eday, &ewek, &draw, &today, &othr,
&help, &quit, &save, &tab, &import, &export, &day, &week, &weekb, &weeke,
&togo, &othr, &conf, &draw, &appt, &todo, &eday, &ewek, &today, &othr,
/* appointment keys */
&help, &quit, &save, &export, &add, &del, &edit, &view, &rept,
&updn, &flag, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
&conf, &togo, &tab, &draw, &today, &othr,
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
&rept, &othr, &updn, &flag, &enote, &vnote, &appt, &todo, &eday, &ewek,
&conf, &togo, &draw, &othr, &today, &othr,
/* todo keys */
&help, &quit, &save, &export, &add, &del, &edit, &view, &prio,
&updn, &tab, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
&conf, &togo, &draw, &today, &othr
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
&prio, &othr, &updn, &conf, &enote, &vnote, &appt, &todo, &eday, &ewek,
&togo, &draw, &today, &othr
};
/* Total length of a command. */

View File

@ -1,4 +1,4 @@
/* $calcurse: utils.h,v 1.34 2008/09/20 12:47:06 culot Exp $ */
/* $calcurse: utils.h,v 1.35 2008/09/21 08:06:43 culot Exp $ */
/*
* Calcurse - text-based organizer
@ -32,7 +32,7 @@
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define DISPLAY(...) do { \
#define ERROR_MSG(...) do { \
char msg[BUFSIZ]; \
\
snprintf (msg, BUFSIZ, __VA_ARGS__); \
@ -43,7 +43,7 @@
} while (0)
#define EXIT(...) do { \
DISPLAY(__VA_ARGS__); \
ERROR_MSG(__VA_ARGS__); \
if (ui_mode == UI_CURSES) \
exit_calcurse (EXIT_FAILURE); \
else \
@ -53,7 +53,7 @@
#define EXIT_IF(cond, ...) do { \
if ((cond)) \
{ \
DISPLAY(__VA_ARGS__); \
ERROR_MSG(__VA_ARGS__); \
if (ui_mode == UI_CURSES) \
exit_calcurse (EXIT_FAILURE); \
else \
@ -64,7 +64,7 @@
#define RETURN_IF(cond, ...) do { \
if ((cond)) \
{ \
DISPLAY(__VA_ARGS__); \
ERROR_MSG(__VA_ARGS__); \
return; \
} \
} while (0)
@ -72,7 +72,7 @@
#define RETVAL_IF(cond, val, ...) do { \
if ((cond)) \
{ \
DISPLAY(__VA_ARGS__); \
ERROR_MSG(__VA_ARGS__); \
return (val); \
} \
} while (0)
@ -83,9 +83,9 @@
#define SPC 32 /* ASCII code for white space */
#define NB_CAL_CMDS 19 /* number of commands while in cal view */
#define NB_APP_CMDS 24 /* same thing while in appointment view */
#define NB_TOD_CMDS 23 /* same thing while in todo view */
#define NB_CAL_CMDS 20 /* number of commands while in cal view */
#define NB_APP_CMDS 26 /* same thing while in appointment view */
#define NB_TOD_CMDS 24 /* same thing while in todo view */
#define TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
#define CMDS_PER_LINE 6 /* max number of commands per line */