import flag and 'i' keybinding added
This commit is contained in:
parent
96b858b8bc
commit
7ddfcccee0
14
ChangeLog
14
ChangeLog
@ -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>
|
2008-09-20 Frederic Culot <frederic@culot.org>
|
||||||
|
|
||||||
* src/io.c (io_import_data): temporary log file created to store
|
* src/io.c (io_import_data): temporary log file created to store
|
||||||
|
33
src/args.c
33
src/args.c
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -48,7 +48,7 @@ static void
|
|||||||
usage ()
|
usage ()
|
||||||
{
|
{
|
||||||
char *arg_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"
|
" [-d <date>|<num>] [-s[date]] [-r[range]]\n"
|
||||||
" [-c<file> | -D<dir>]\n");
|
" [-c<file> | -D<dir>]\n");
|
||||||
fputs (arg_usage, stdout);
|
fputs (arg_usage, stdout);
|
||||||
@ -103,6 +103,8 @@ help_arg ()
|
|||||||
" print events and appointments for <date> or <num> upcoming days and"
|
" 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"
|
"\n\texit. To specify both a starting date and a range, use the\n"
|
||||||
"\t'--startday' and the '--range' option.\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"
|
"\n -n, --next\n"
|
||||||
" print next appointment within upcoming 24 hours "
|
" print next appointment within upcoming 24 hours "
|
||||||
"and exit. Also given\n\tis the remaining time before this "
|
"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: print appointments for a specified days */
|
||||||
int Dflag = 0; /* -D: specify data directory to use */
|
int Dflag = 0; /* -D: specify data directory to use */
|
||||||
int hflag = 0; /* -h: print help text */
|
int hflag = 0; /* -h: print help text */
|
||||||
|
int iflag = 0; /* -i: import data */
|
||||||
int nflag = 0; /* -n: print next appointment */
|
int nflag = 0; /* -n: print next appointment */
|
||||||
int Nflag = 0; /* -N: also print note content with apps and todos */
|
int Nflag = 0; /* -N: also print note content with apps and todos */
|
||||||
int rflag = 0; /* -r: specify the range of days to consider */
|
int rflag = 0; /* -r: specify the range of days to consider */
|
||||||
int sflag = 0; /* -s: specify the first day to consider */
|
int sflag = 0; /* -s: specify the first day to consider */
|
||||||
int tflag = 0; /* -t: print todo list */
|
int tflag = 0; /* -t: print todo list */
|
||||||
int vflag = 0; /* -v: print version number */
|
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 tnum = 0, xfmt = 0;
|
||||||
int non_interactive = 0, multiple_flag = 0, load_data = 0;
|
int non_interactive = 0, multiple_flag = 0, load_data = 0;
|
||||||
int no_file = 1;
|
int no_file = 1;
|
||||||
char *ddate = "", *cfile = NULL, *range = NULL, *startday = NULL;
|
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[] = {
|
struct option longopts[] = {
|
||||||
{"appointment", no_argument, NULL, 'a'},
|
{"appointment", no_argument, NULL, 'a'},
|
||||||
@ -595,6 +598,7 @@ parse_args (int argc, char **argv, conf_t *conf)
|
|||||||
{"day", required_argument, NULL, 'd'},
|
{"day", required_argument, NULL, 'd'},
|
||||||
{"directory", required_argument, NULL, 'D'},
|
{"directory", required_argument, NULL, 'D'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{"import", required_argument, NULL, 'i'},
|
||||||
{"next", no_argument, NULL, 'n'},
|
{"next", no_argument, NULL, 'n'},
|
||||||
{"note", no_argument, NULL, 'N'},
|
{"note", no_argument, NULL, 'N'},
|
||||||
{"range", required_argument, NULL, 'r'},
|
{"range", required_argument, NULL, 'r'},
|
||||||
@ -633,6 +637,12 @@ parse_args (int argc, char **argv, conf_t *conf)
|
|||||||
case 'h':
|
case 'h':
|
||||||
hflag = 1;
|
hflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
iflag = 1;
|
||||||
|
multiple_flag++;
|
||||||
|
load_data++;
|
||||||
|
ifile = optarg;
|
||||||
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nflag = 1;
|
nflag = 1;
|
||||||
multiple_flag++;
|
multiple_flag++;
|
||||||
@ -746,9 +756,20 @@ parse_args (int argc, char **argv, conf_t *conf)
|
|||||||
{
|
{
|
||||||
io_init (cfile, datadir);
|
io_init (cfile, datadir);
|
||||||
no_file = io_check_data_files ();
|
no_file = io_check_data_files ();
|
||||||
if (dflag || aflag || nflag || xflag || rflag || sflag)
|
if (dflag || aflag || nflag || iflag || xflag || rflag || sflag)
|
||||||
io_load_app ();
|
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)
|
if (xflag)
|
||||||
{
|
{
|
||||||
notify_init_vars ();
|
notify_init_vars ();
|
||||||
|
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -379,13 +379,13 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
case 'S':
|
case 'S':
|
||||||
case 's': /* Save function */
|
case 's': /* Save function */
|
||||||
io_save_cal (&conf);
|
io_save_cal (IO_MODE_INTERACTIVE, &conf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
case 'i': /* Import function */
|
case 'i': /* Import function */
|
||||||
erase_status_bar ();
|
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;
|
do_storage = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -513,7 +513,7 @@ main (int argc, char **argv)
|
|||||||
case ('Q'): /* Quit calcurse :( */
|
case ('Q'): /* Quit calcurse :( */
|
||||||
case ('q'):
|
case ('q'):
|
||||||
if (conf.auto_save)
|
if (conf.auto_save)
|
||||||
io_save_cal (&conf);
|
io_save_cal (IO_MODE_INTERACTIVE, &conf);
|
||||||
|
|
||||||
if (conf.confirm_quit)
|
if (conf.confirm_quit)
|
||||||
{
|
{
|
||||||
|
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -191,7 +191,7 @@ custom_init_attr (void)
|
|||||||
|
|
||||||
/* Apply window attribute */
|
/* Apply window attribute */
|
||||||
void
|
void
|
||||||
custom_apply_attr (WINDOW * win, int attr_num)
|
custom_apply_attr (WINDOW *win, int attr_num)
|
||||||
{
|
{
|
||||||
if (colorize)
|
if (colorize)
|
||||||
wattron (win, attr.color[attr_num]);
|
wattron (win, attr.color[attr_num]);
|
||||||
@ -201,7 +201,7 @@ custom_apply_attr (WINDOW * win, int attr_num)
|
|||||||
|
|
||||||
/* Remove window attribute */
|
/* Remove window attribute */
|
||||||
void
|
void
|
||||||
custom_remove_attr (WINDOW * win, int attr_num)
|
custom_remove_attr (WINDOW *win, int attr_num)
|
||||||
{
|
{
|
||||||
if (colorize)
|
if (colorize)
|
||||||
wattroff (win, attr.color[attr_num]);
|
wattroff (win, attr.color[attr_num]);
|
||||||
@ -211,7 +211,7 @@ custom_remove_attr (WINDOW * win, int attr_num)
|
|||||||
|
|
||||||
/* Load the user configuration. */
|
/* Load the user configuration. */
|
||||||
void
|
void
|
||||||
custom_load_conf (conf_t * conf, int background)
|
custom_load_conf (conf_t *conf, int background)
|
||||||
{
|
{
|
||||||
FILE *data_file;
|
FILE *data_file;
|
||||||
char *mesg_line1 = _("Failed to open config file");
|
char *mesg_line1 = _("Failed to open config file");
|
||||||
|
25
src/help.c
25
src/help.c
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -39,6 +39,7 @@ typedef enum
|
|||||||
{
|
{
|
||||||
HELP_MAIN,
|
HELP_MAIN,
|
||||||
HELP_SAVE,
|
HELP_SAVE,
|
||||||
|
HELP_IMPORT,
|
||||||
HELP_EXPORT,
|
HELP_EXPORT,
|
||||||
HELP_DISPLACEMENT,
|
HELP_DISPLACEMENT,
|
||||||
HELP_VIEW,
|
HELP_VIEW,
|
||||||
@ -183,6 +184,10 @@ wanted_page (int ch)
|
|||||||
page = HELP_SAVE;
|
page = HELP_SAVE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
page = HELP_IMPORT;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
page = HELP_EXPORT;
|
page = HELP_EXPORT;
|
||||||
break;
|
break;
|
||||||
@ -299,6 +304,24 @@ help_screen (void)
|
|||||||
"\nIn the config menu, you can choose to save the Calcurse data\n"
|
"\nIn the config menu, you can choose to save the Calcurse data\n"
|
||||||
"automatically before quitting.");
|
"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].title = _("Export:\n");
|
||||||
hscr[HELP_EXPORT].text =
|
hscr[HELP_EXPORT].text =
|
||||||
_("Pressing 'X' leads to the export submenu, from which you can choose\n"
|
_("Pressing 'X' leads to the export submenu, from which you can choose\n"
|
||||||
|
121
src/io.c
121
src/io.c
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -723,7 +723,7 @@ io_extract_data (char *dst_data, const char *org, int len)
|
|||||||
|
|
||||||
/* Save the calendar data */
|
/* Save the calendar data */
|
||||||
void
|
void
|
||||||
io_save_cal (conf_t *conf)
|
io_save_cal (io_mode_t mode, conf_t *conf)
|
||||||
{
|
{
|
||||||
FILE *data_file;
|
FILE *data_file;
|
||||||
struct event_s *k;
|
struct event_s *k;
|
||||||
@ -745,7 +745,7 @@ io_save_cal (conf_t *conf)
|
|||||||
char *enter = _("Press [ENTER] to continue");
|
char *enter = _("Press [ENTER] to continue");
|
||||||
bool show_bar = false;
|
bool show_bar = false;
|
||||||
|
|
||||||
if (!conf->skip_progress_bar)
|
if (mode == IO_MODE_INTERACTIVE && !conf->skip_progress_bar)
|
||||||
show_bar = true;
|
show_bar = true;
|
||||||
|
|
||||||
/* Save the user configuration. */
|
/* Save the user configuration. */
|
||||||
@ -753,8 +753,8 @@ io_save_cal (conf_t *conf)
|
|||||||
if (show_bar)
|
if (show_bar)
|
||||||
progress_bar (PROGRESS_BAR_SAVE, 0);
|
progress_bar (PROGRESS_BAR_SAVE, 0);
|
||||||
data_file = fopen (path_conf, "w");
|
data_file = fopen (path_conf, "w");
|
||||||
if (data_file == (FILE *) 0)
|
if (data_file == NULL)
|
||||||
status_mesg (access_pb, "");
|
ERROR_MSG (access_pb);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
custom_color_theme_name (theme_name);
|
custom_color_theme_name (theme_name);
|
||||||
@ -806,6 +806,7 @@ io_save_cal (conf_t *conf)
|
|||||||
fprintf (data_file, "layout=\n");
|
fprintf (data_file, "layout=\n");
|
||||||
fprintf (data_file, "%d\n", wins_layout ());
|
fprintf (data_file, "%d\n", wins_layout ());
|
||||||
|
|
||||||
|
if (mode == IO_MODE_INTERACTIVE)
|
||||||
pthread_mutex_lock (&nbar->mutex);
|
pthread_mutex_lock (&nbar->mutex);
|
||||||
fprintf (data_file,
|
fprintf (data_file,
|
||||||
"\n# If this option is set to yes, "
|
"\n# If this option is set to yes, "
|
||||||
@ -847,6 +848,7 @@ io_save_cal (conf_t *conf)
|
|||||||
fprintf (data_file, "input_datefmt=\n");
|
fprintf (data_file, "input_datefmt=\n");
|
||||||
fprintf (data_file, "%d\n", conf->input_datefmt);
|
fprintf (data_file, "%d\n", conf->input_datefmt);
|
||||||
|
|
||||||
|
if (mode == IO_MODE_INTERACTIVE)
|
||||||
pthread_mutex_unlock (&nbar->mutex);
|
pthread_mutex_unlock (&nbar->mutex);
|
||||||
|
|
||||||
fclose (data_file);
|
fclose (data_file);
|
||||||
@ -856,8 +858,8 @@ io_save_cal (conf_t *conf)
|
|||||||
if (show_bar)
|
if (show_bar)
|
||||||
progress_bar (PROGRESS_BAR_SAVE, 1);
|
progress_bar (PROGRESS_BAR_SAVE, 1);
|
||||||
data_file = fopen (path_todo, "w");
|
data_file = fopen (path_todo, "w");
|
||||||
if (data_file == (FILE *) 0)
|
if (data_file == NULL)
|
||||||
status_mesg (access_pb, "");
|
ERROR_MSG (access_pb);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = todolist; i != 0; i = i->next)
|
for (i = todolist; i != 0; i = i->next)
|
||||||
@ -878,15 +880,17 @@ io_save_cal (conf_t *conf)
|
|||||||
if (show_bar)
|
if (show_bar)
|
||||||
progress_bar (PROGRESS_BAR_SAVE, 2);
|
progress_bar (PROGRESS_BAR_SAVE, 2);
|
||||||
data_file = fopen (path_apts, "w");
|
data_file = fopen (path_apts, "w");
|
||||||
if (data_file == (FILE *) 0)
|
if (data_file == NULL)
|
||||||
status_mesg (access_pb, "");
|
ERROR_MSG (access_pb);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
recur_save_data (data_file);
|
recur_save_data (data_file);
|
||||||
|
|
||||||
|
if (mode == IO_MODE_INTERACTIVE)
|
||||||
pthread_mutex_lock (&(alist_p->mutex));
|
pthread_mutex_lock (&(alist_p->mutex));
|
||||||
for (j = alist_p->root; j != 0; j = j->next)
|
for (j = alist_p->root; j != 0; j = j->next)
|
||||||
apoint_write (j, data_file);
|
apoint_write (j, data_file);
|
||||||
|
if (mode == IO_MODE_INTERACTIVE)
|
||||||
pthread_mutex_unlock (&(alist_p->mutex));
|
pthread_mutex_unlock (&(alist_p->mutex));
|
||||||
|
|
||||||
for (k = eventlist; k != 0; k = k->next)
|
for (k = eventlist; k != 0; k = k->next)
|
||||||
@ -895,7 +899,7 @@ io_save_cal (conf_t *conf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print a message telling data were saved */
|
/* 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);
|
status_mesg (save_success, enter);
|
||||||
wgetch (win[STA].p);
|
wgetch (win[STA].p);
|
||||||
@ -2142,16 +2146,17 @@ get_import_stream (export_type_t type)
|
|||||||
* and is cleared at the end.
|
* and is cleared at the end.
|
||||||
*/
|
*/
|
||||||
void
|
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 char *logprefix = "/tmp/calcurse_log.";
|
||||||
const string_t vevent = STRING_BUILD ("BEGIN:VEVENT");
|
const string_t vevent = STRING_BUILD ("BEGIN:VEVENT");
|
||||||
const string_t vtodo = STRING_BUILD ("BEGIN:VTODO");
|
const string_t vtodo = STRING_BUILD ("BEGIN:VTODO");
|
||||||
char *success = _("The data were successfully imported");
|
char *proc_report = _("Import process report: %04d lines read ");
|
||||||
char *enter = _("Press [ENTER] to continue");
|
|
||||||
char *lines_read = _("Number of lines read: %04d ");
|
|
||||||
char *lines_stats =
|
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];
|
char *logname, flogname[BUFSIZ], buf[BUFSIZ];
|
||||||
FILE *stream = NULL, *logfd;
|
FILE *stream = NULL, *logfd;
|
||||||
float ical_version;
|
float ical_version;
|
||||||
@ -2164,7 +2169,10 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
|
|||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case IO_MODE_NONINTERACTIVE:
|
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;
|
break;
|
||||||
case IO_MODE_INTERACTIVE:
|
case IO_MODE_INTERACTIVE:
|
||||||
stream = get_import_stream (type);
|
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)
|
if (stream == NULL)
|
||||||
return;
|
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);
|
bzero (&stats, sizeof stats);
|
||||||
ical_version = ical_chk_header (stream, &stats.lines);
|
ical_version = ical_chk_header (stream, &stats.lines);
|
||||||
RETURN_IF (ical_version < 0,
|
RETURN_IF (ical_version < 0,
|
||||||
_("Warning: ical header malformed, wrong version number. "
|
_("Warning: ical header malformed, wrong version number. "
|
||||||
"Aborting..."));
|
"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);
|
ical_log_init (logfd, ical_version);
|
||||||
|
|
||||||
while (fgets (buf, BUFSIZ, stream) != NULL)
|
while (fgets (buf, BUFSIZ, stream) != NULL)
|
||||||
{
|
{
|
||||||
stats.lines++;
|
stats.lines++;
|
||||||
str_toupper (buf);
|
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)
|
if (strncmp (buf, vevent.str, vevent.len) == 0)
|
||||||
{
|
{
|
||||||
ical_read_event (stream, logfd, &stats.events, &stats.apoints,
|
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)
|
if (stream != stdin)
|
||||||
fclose (stream);
|
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
|
/* User has the choice to look at the log file if some items could not be
|
||||||
imported.
|
imported.
|
||||||
*/
|
*/
|
||||||
@ -2236,15 +2245,15 @@ 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 *view_log = _("Some items could not be imported, see log file ?");
|
||||||
char *choices = "[y/n] ";
|
char *choices = "[y/n] ";
|
||||||
int answer;
|
int ans;
|
||||||
|
|
||||||
if (mode == IO_MODE_NONINTERACTIVE)
|
if (mode == IO_MODE_NONINTERACTIVE)
|
||||||
{
|
{
|
||||||
fprintf (stdout, "\n%s %s", view_log, choices);
|
int ans;
|
||||||
do
|
|
||||||
{
|
printf ("\n%s %s", view_log, choices);
|
||||||
answer = scanf ("%d", &answer);
|
ans = fgetc (stdin);
|
||||||
if (answer == 'y')
|
if (ans == 'y')
|
||||||
{
|
{
|
||||||
char cmd[BUFSIZ];
|
char cmd[BUFSIZ];
|
||||||
|
|
||||||
@ -2252,31 +2261,21 @@ io_import_data (io_mode_t mode, import_type_t type, conf_t *conf)
|
|||||||
system (cmd);
|
system (cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (answer != 'y' && answer != 'n');
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
status_mesg (view_log, choices);
|
status_mesg (view_log, choices);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
answer = wgetch (win[STA].p);
|
ans = wgetch (win[STA].p);
|
||||||
if (answer == 'y')
|
if (ans == 'y')
|
||||||
{
|
{
|
||||||
wins_launch_external (flogname, conf->pager);
|
wins_launch_external (flogname, conf->pager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (answer != 'y' && answer != 'n');
|
while (ans != 'y' && ans != 'n');
|
||||||
erase_status_bar ();
|
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,
|
EXIT_IF (unlink (flogname) != 0,
|
||||||
_("Warning: could not erase temporary log file, Aborting..."));
|
_("Warning: could not erase temporary log file, Aborting..."));
|
||||||
free (logname);
|
free (logname);
|
||||||
|
6
src/io.h
6
src/io.h
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -51,13 +51,13 @@ typedef enum
|
|||||||
|
|
||||||
void io_init (char *, char *);
|
void io_init (char *, char *);
|
||||||
void io_extract_data (char *, const char *, int);
|
void io_extract_data (char *, const char *, int);
|
||||||
void io_save_cal (conf_t *);
|
void io_save_cal (io_mode_t, conf_t *);
|
||||||
void io_load_app (void);
|
void io_load_app (void);
|
||||||
void io_load_todo (void);
|
void io_load_todo (void);
|
||||||
int io_check_data_files (void);
|
int io_check_data_files (void);
|
||||||
void io_startup_screen (bool, int);
|
void io_startup_screen (bool, int);
|
||||||
void io_export_data (io_mode_t, export_type_t, conf_t *);
|
void io_export_data (io_mode_t, export_type_t, conf_t *);
|
||||||
void io_export_bar (void);
|
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 */
|
#endif /* CALCURSE_IO_H */
|
||||||
|
19
src/utils.c
19
src/utils.c
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -445,6 +445,7 @@ status_bar (void)
|
|||||||
binding_t quit = { " Q", _("Quit") };
|
binding_t quit = { " Q", _("Quit") };
|
||||||
binding_t save = { " S", _("Save") };
|
binding_t save = { " S", _("Save") };
|
||||||
binding_t export = { " X", _("Export") };
|
binding_t export = { " X", _("Export") };
|
||||||
|
binding_t import = { " I", _("Import") };
|
||||||
binding_t add = { " A", _("Add Item") };
|
binding_t add = { " A", _("Add Item") };
|
||||||
binding_t del = { " D", _("Del Item") };
|
binding_t del = { " D", _("Del Item") };
|
||||||
binding_t edit = { " E", _("Edit Itm") };
|
binding_t edit = { " E", _("Edit Itm") };
|
||||||
@ -472,16 +473,16 @@ status_bar (void)
|
|||||||
|
|
||||||
binding_t *binding[TOTAL_CMDS] = {
|
binding_t *binding[TOTAL_CMDS] = {
|
||||||
/* calendar keys */
|
/* calendar keys */
|
||||||
&help, &quit, &save, &export, &day, &week, &weekb, &weeke, &tab,
|
&help, &quit, &save, &tab, &import, &export, &day, &week, &weekb, &weeke,
|
||||||
&togo, &conf, &othr, &appt, &todo, &eday, &ewek, &draw, &today, &othr,
|
&togo, &othr, &conf, &draw, &appt, &todo, &eday, &ewek, &today, &othr,
|
||||||
/* appointment keys */
|
/* appointment keys */
|
||||||
&help, &quit, &save, &export, &add, &del, &edit, &view, &rept,
|
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
|
||||||
&updn, &flag, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
|
&rept, &othr, &updn, &flag, &enote, &vnote, &appt, &todo, &eday, &ewek,
|
||||||
&conf, &togo, &tab, &draw, &today, &othr,
|
&conf, &togo, &draw, &othr, &today, &othr,
|
||||||
/* todo keys */
|
/* todo keys */
|
||||||
&help, &quit, &save, &export, &add, &del, &edit, &view, &prio,
|
&help, &quit, &save, &tab, &import, &export, &add, &del, &edit, &view,
|
||||||
&updn, &tab, &othr, &enote, &vnote, &appt, &todo, &eday, &ewek,
|
&prio, &othr, &updn, &conf, &enote, &vnote, &appt, &todo, &eday, &ewek,
|
||||||
&conf, &togo, &draw, &today, &othr
|
&togo, &draw, &today, &othr
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Total length of a command. */
|
/* Total length of a command. */
|
||||||
|
18
src/utils.h
18
src/utils.h
@ -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
|
* Calcurse - text-based organizer
|
||||||
@ -32,7 +32,7 @@
|
|||||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||||
|
|
||||||
#define DISPLAY(...) do { \
|
#define ERROR_MSG(...) do { \
|
||||||
char msg[BUFSIZ]; \
|
char msg[BUFSIZ]; \
|
||||||
\
|
\
|
||||||
snprintf (msg, BUFSIZ, __VA_ARGS__); \
|
snprintf (msg, BUFSIZ, __VA_ARGS__); \
|
||||||
@ -43,7 +43,7 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define EXIT(...) do { \
|
#define EXIT(...) do { \
|
||||||
DISPLAY(__VA_ARGS__); \
|
ERROR_MSG(__VA_ARGS__); \
|
||||||
if (ui_mode == UI_CURSES) \
|
if (ui_mode == UI_CURSES) \
|
||||||
exit_calcurse (EXIT_FAILURE); \
|
exit_calcurse (EXIT_FAILURE); \
|
||||||
else \
|
else \
|
||||||
@ -53,7 +53,7 @@
|
|||||||
#define EXIT_IF(cond, ...) do { \
|
#define EXIT_IF(cond, ...) do { \
|
||||||
if ((cond)) \
|
if ((cond)) \
|
||||||
{ \
|
{ \
|
||||||
DISPLAY(__VA_ARGS__); \
|
ERROR_MSG(__VA_ARGS__); \
|
||||||
if (ui_mode == UI_CURSES) \
|
if (ui_mode == UI_CURSES) \
|
||||||
exit_calcurse (EXIT_FAILURE); \
|
exit_calcurse (EXIT_FAILURE); \
|
||||||
else \
|
else \
|
||||||
@ -64,7 +64,7 @@
|
|||||||
#define RETURN_IF(cond, ...) do { \
|
#define RETURN_IF(cond, ...) do { \
|
||||||
if ((cond)) \
|
if ((cond)) \
|
||||||
{ \
|
{ \
|
||||||
DISPLAY(__VA_ARGS__); \
|
ERROR_MSG(__VA_ARGS__); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -72,7 +72,7 @@
|
|||||||
#define RETVAL_IF(cond, val, ...) do { \
|
#define RETVAL_IF(cond, val, ...) do { \
|
||||||
if ((cond)) \
|
if ((cond)) \
|
||||||
{ \
|
{ \
|
||||||
DISPLAY(__VA_ARGS__); \
|
ERROR_MSG(__VA_ARGS__); \
|
||||||
return (val); \
|
return (val); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -83,9 +83,9 @@
|
|||||||
|
|
||||||
#define SPC 32 /* ASCII code for white space */
|
#define SPC 32 /* ASCII code for white space */
|
||||||
|
|
||||||
#define NB_CAL_CMDS 19 /* number of commands while in cal view */
|
#define NB_CAL_CMDS 20 /* number of commands while in cal view */
|
||||||
#define NB_APP_CMDS 24 /* same thing while in appointment view */
|
#define NB_APP_CMDS 26 /* same thing while in appointment view */
|
||||||
#define NB_TOD_CMDS 23 /* same thing while in todo 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 TOTAL_CMDS NB_CAL_CMDS + NB_APP_CMDS + NB_TOD_CMDS
|
||||||
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
|
#define NB_PANELS 3 /* 3 panels: CALENDAR, APPOINTMENT, TODO */
|
||||||
#define CMDS_PER_LINE 6 /* max number of commands per line */
|
#define CMDS_PER_LINE 6 /* max number of commands per line */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user