[gnumeric] Add error dialog to sc import.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Add error dialog to sc import.
- Date: Fri, 8 Oct 2010 16:14:44 +0000 (UTC)
commit 812da7b43175fdee24ea6bf8db41c717f93f12f8
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Fri Oct 8 10:12:59 2010 -0600
Add error dialog to sc import.
2010-10-08 Andreas J. Guelzow <aguelzow pyrshep ca>
* sc.c (ScParseState): add fields
(sc_go_error_info_new_vprintf): new
(sc_warning): new; replace all g_warnings with calls to sc_warning
(sc_sheet_cell_fetch): change first argument and change all call
(sc_file_open): initalize and finalize new fields of ScParseState
NEWS | 2 +-
plugins/sc/ChangeLog | 8 ++++
plugins/sc/sc.c | 109 +++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 100 insertions(+), 19 deletions(-)
---
diff --git a/NEWS b/NEWS
index 701620b..493834d 100644
--- a/NEWS
+++ b/NEWS
@@ -10,7 +10,7 @@ Andreas:
rather than index. [#629333]
* Fix manual pagebreak handling when printing. [#631570]
* Add menu items to remove and add manual page breaks.
- * Permit the sc import of tables with many rows and columns.
+ * Improve the sc import.
--------------------------------------------------------------------------
Gnumeric 1.10.11
diff --git a/plugins/sc/ChangeLog b/plugins/sc/ChangeLog
index ae15757..f86a0d0 100644
--- a/plugins/sc/ChangeLog
+++ b/plugins/sc/ChangeLog
@@ -1,3 +1,11 @@
+2010-10-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * sc.c (ScParseState): add fields
+ (sc_go_error_info_new_vprintf): new
+ (sc_warning): new; replace all g_warnings with calls to sc_warning
+ (sc_sheet_cell_fetch): change first argument and change all call
+ (sc_file_open): initalize and finalize new fields of ScParseState
+
2010-10-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* sc.c: pass all calls to sheet_cell_fetch via sc_sheet_cell_fetch
diff --git a/plugins/sc/sc.c b/plugins/sc/sc.c
index c13b735..49e7c19 100644
--- a/plugins/sc/sc.c
+++ b/plugins/sc/sc.c
@@ -2,8 +2,22 @@
/*
* sc.c - file import of SC/xspread files
* Copyright 1999 Jeff Garzik <jgarzik mandrakesoft com>
+ * Copyright (C) 2010 Andreas J. Guelzow <aguelzow pyrshep ca> All Rights Reserved
*
* With some code from sylk.c
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+ * USA
*/
#include <gnumeric-config.h>
@@ -44,6 +58,8 @@ typedef struct {
Sheet *sheet;
GIConv converter;
GnmConventions *convs;
+ GOIOContext *context; /* The IOcontext managing things */
+ char *last_error;
} ScParseState;
typedef enum {
@@ -52,10 +68,67 @@ typedef enum {
RIGHTSTRING
} sc_string_cmd_t;
+
+static GOErrorInfo *sc_go_error_info_new_vprintf (GOSeverity severity,
+ char const *msg_format, ...)
+ G_GNUC_PRINTF (2, 3);
+
+static GOErrorInfo *
+sc_go_error_info_new_vprintf (GOSeverity severity,
+ char const *msg_format, ...)
+{
+ va_list args;
+ GOErrorInfo *ei;
+
+ va_start (args, msg_format);
+ ei = go_error_info_new_vprintf (severity, msg_format, args);
+ va_end (args);
+
+ return ei;
+}
+
+static gboolean sc_warning (ScParseState *state, char const *fmt, ...)
+ G_GNUC_PRINTF (2, 3);
+
+static gboolean
+sc_warning (ScParseState *state, char const *fmt, ...)
+{
+ char *msg;
+ char *detail;
+ va_list args;
+
+ va_start (args, fmt);
+ detail = g_strdup_vprintf (fmt, args);
+ va_end (args);
+
+ if (IS_SHEET (state->sheet))
+ msg = g_strdup_printf (_("On worksheet %s:"),state->sheet->name_quoted);
+ else
+ msg = g_strdup (_("General SC import error"));
+
+ if (0 != go_str_compare (msg, state->last_error)) {
+ GOErrorInfo *ei = sc_go_error_info_new_vprintf
+ (GO_WARNING, "%s", msg);
+
+ go_io_error_info_set (state->context, ei);
+ g_free (state->last_error);
+ state->last_error = msg;
+ } else
+ g_free (msg);
+
+ go_error_info_add_details
+ (state->context->info->data,
+ sc_go_error_info_new_vprintf (GO_WARNING, "%s", detail));
+
+ g_free (detail);
+
+ return FALSE; /* convenience */
+}
+
static GnmCell *
-sc_sheet_cell_fetch (Sheet *sheet, int col, int row)
+sc_sheet_cell_fetch (ScParseState *state, int col, int row)
{
- GnmSheetSize const *size = gnm_sheet_get_size (sheet);
+ GnmSheetSize const *size = gnm_sheet_get_size (state->sheet);
gboolean err = FALSE;
if (col >= size->max_cols
@@ -68,18 +141,18 @@ sc_sheet_cell_fetch (Sheet *sheet, int col, int row)
gnm_sheet_suggest_size (&cols_needed, &rows_needed);
goundo = gnm_sheet_resize
- (sheet, cols_needed, rows_needed, NULL, &err);
+ (state->sheet, cols_needed, rows_needed, NULL, &err);
if (goundo) g_object_unref (goundo);
}
if (err) {
- g_warning (_("The cell in row %i and column %i is beyond "
- "Gnumeric's maximum sheet size."),
+ sc_warning (state, _("The cell in row %i and column %i is beyond "
+ "Gnumeric's maximum sheet size."),
row, col);
return NULL;
} else
- return sheet_cell_fetch (sheet, col, row);
+ return sheet_cell_fetch (state->sheet, col, row);
}
@@ -231,7 +304,7 @@ sc_parse_label (ScParseState *state, char const *cmd, char const *str,
tmpout--;
*tmpout = 0;
- cell = sc_sheet_cell_fetch (state->sheet, pos->col, pos->row);
+ cell = sc_sheet_cell_fetch (state, pos->col, pos->row);
if (!cell)
goto err_out;
@@ -257,7 +330,7 @@ sc_parse_label (ScParseState *state, char const *cmd, char const *str,
#if 0
static GSList *
-sc_parse_cell_name_list (Sheet *sheet, char const *cell_name_str,
+sc_parse_cell_name_list (ScParseState *state, char const *cell_name_str,
int *error_flag)
{
char *buf;
@@ -266,8 +339,8 @@ sc_parse_cell_name_list (Sheet *sheet, char const *cell_name_str,
GnmCellPos pos;
int i, n;
- g_return_val_if_fail (sheet != NULL, NULL);
- g_return_val_if_fail (IS_SHEET (sheet), NULL);
+ g_return_val_if_fail (state->sheet != NULL, NULL);
+ g_return_val_if_fail (IS_SHEET (state->sheet), NULL);
g_return_val_if_fail (cell_name_str != NULL, NULL);
g_return_val_if_fail (error_flag != NULL, NULL);
@@ -285,7 +358,7 @@ sc_parse_cell_name_list (Sheet *sheet, char const *cell_name_str,
return NULL;
}
- cell = sc_sheet_cell_fetch (sheet, pos.col, pos.row);
+ cell = sc_sheet_cell_fetch (state, pos.col, pos.row);
if (cell != NULL)
cells = g_slist_append (cells, (gpointer) cell);
n = 0;
@@ -416,7 +489,7 @@ sc_parse_let (ScParseState *state, char const *cmd, char const *str,
g_return_val_if_fail (cmd, FALSE);
g_return_val_if_fail (str, FALSE);
- cell = sc_sheet_cell_fetch (state->sheet, pos->col, pos->row);
+ cell = sc_sheet_cell_fetch (state, pos->col, pos->row);
if (!cell)
return FALSE;
@@ -424,7 +497,7 @@ sc_parse_let (ScParseState *state, char const *cmd, char const *str,
parse_pos_init_cell (&pp, cell));
if (!texpr) {
- g_warning ("cannot parse cmd='%s', str='%s', col=%d, row=%d.",
+ sc_warning (state, _("Unable to parse cmd='%s', str='%s', col=%d, row=%d."),
cmd, str, pos->col, pos->row);
return TRUE;
}
@@ -460,7 +533,7 @@ sc_parse_define (ScParseState *state, char const *cmd, char const *str,
texpr = sc_parse_expr (state, str,
parse_pos_init (&pp, NULL, state->sheet, 0, 0));
if (!texpr) {
- g_warning ("cannot parse cmd='%s', str='%s'.", cmd, str);
+ sc_warning (state, "Unable to parse cmd='%s', str='%s'.", cmd, str);
goto out;
}
@@ -533,11 +606,8 @@ sc_parse_line (ScParseState *state, char *buf)
}
}
-#if 1
- g_warning ("sc importer: unhandled directive: '%-.*s'",
+ sc_warning (state, "Unhandled directive: '%-.*s'",
cmdlen, buf);
-#endif
-
return TRUE;
}
@@ -645,6 +715,8 @@ sc_file_open (GOFileOpener const *fo, GOIOContext *io_context,
state.converter = g_iconv_open ("UTF-8", "ISO-8859-1");
state.convs = sc_conventions ();
+ state.context = io_context;
+ state.last_error = NULL;
state.textline = (GsfInputTextline *) gsf_input_textline_new (input);
error = sc_parse_sheet (&state);
if (error != NULL) {
@@ -654,6 +726,7 @@ sc_file_open (GOFileOpener const *fo, GOIOContext *io_context,
g_object_unref (G_OBJECT (state.textline));
g_iconv_close (state.converter);
gnm_conventions_unref (state.convs);
+ g_free (state.last_error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]