From: John Darrington Date: Wed, 23 Jan 2013 20:35:03 +0000 (+0100) Subject: Make sheet spec page opaque X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47324b542f10e961a72d711314f6abc7c83a59de;p=pspp Make sheet spec page opaque --- diff --git a/src/ui/gui/page-assistant.c b/src/ui/gui/page-assistant.c index e7dd02de27..c27d6c3472 100644 --- a/src/ui/gui/page-assistant.c +++ b/src/ui/gui/page-assistant.c @@ -72,15 +72,15 @@ static void close_assistant (struct import_assistant *, int response); struct import_assistant * init_assistant (GtkWindow *parent_window) { - struct import_assistant *ia = NULL; - ia = xzalloc (sizeof *ia); + struct import_assistant *ia = xzalloc (sizeof *ia); struct assistant *a = &ia->asst; a->builder = builder_new ("text-data-import.ui"); a->assistant = GTK_ASSISTANT (gtk_assistant_new ()); + ia->sheet_spec = sheet_spec_page_create (ia); ia->intro = intro_page_create (ia); - ia->sheet_spec = xzalloc (sizeof *ia->sheet_spec); + ia->first_line = xzalloc (sizeof *ia->first_line); ia->separators = xzalloc (sizeof *ia->separators); ia->formats = xzalloc (sizeof *ia->formats); diff --git a/src/ui/gui/page-file.c b/src/ui/gui/page-file.c index c52171dfa8..5254628bb8 100644 --- a/src/ui/gui/page-file.c +++ b/src/ui/gui/page-file.c @@ -66,63 +66,8 @@ struct import_assistant; /* Choose a file */ static char *choose_file (GtkWindow *parent_window, gchar **encodingp); -enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */ -/* - Update IA according to the contents of DICT and CREADER. - CREADER will be destroyed by this function. -*/ -void -update_assistant (struct import_assistant *ia) -{ - struct sheet_spec_page *ssp = ia->sheet_spec; - - struct file *file = &ia->file; - struct separators_page *sepp = ia->separators; - int rows = 0; - if (ssp->dict) - { - struct ccase *c; - int col; - - - sepp->column_cnt = dict_get_var_cnt (ssp->dict); - sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns)); - for (col = 0; col < sepp->column_cnt ; ++col) - { - const struct variable *var = dict_get_var (ssp->dict, col); - sepp->columns[col].name = xstrdup (var_get_name (var)); - sepp->columns[col].contents = NULL; - } - - for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c)) - { - rows++; - for (col = 0; col < sepp->column_cnt ; ++col) - { - char *ss; - const struct variable *var = dict_get_var (ssp->dict, col); - - sepp->columns[col].contents = xrealloc (sepp->columns[col].contents, - sizeof (struct substring) * rows); - - ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), - var_get_print_format (var)); - - sepp->columns[col].contents[rows - 1] = ss_cstr (ss); - } - - if (rows > MAX_PREVIEW_LINES) - { - case_unref (c); - break; - } - } - } - - file->line_cnt = rows; -} /* Obtains the file to import from the user and initializes IA's @@ -139,6 +84,7 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window) struct sheet_spec_page *ssp = ia->sheet_spec; struct spreadsheet_read_info sri; struct spreadsheet_read_options opts; + struct spreadsheet *spreadsheet = NULL; file->lines = NULL; file->file_name = choose_file (parent_window, &file->encoding); @@ -152,13 +98,13 @@ init_file (struct import_assistant *ia, GtkWindow *parent_window) sri.read_names = true; sri.asw = -1; - if (ssp->spreadsheet == NULL) - ssp->spreadsheet = gnumeric_probe (file->file_name); + if (spreadsheet == NULL) + spreadsheet = gnumeric_probe (file->file_name); - if (ssp->spreadsheet == NULL) - ssp->spreadsheet = ods_probe (file->file_name); + if (spreadsheet == NULL) + spreadsheet = ods_probe (file->file_name); - if (ssp->spreadsheet) + if (spreadsheet) { // update_assistant (ia); } diff --git a/src/ui/gui/page-sheet-spec.c b/src/ui/gui/page-sheet-spec.c index 4ba379df42..74593f2523 100644 --- a/src/ui/gui/page-sheet-spec.c +++ b/src/ui/gui/page-sheet-spec.c @@ -64,20 +64,35 @@ struct import_assistant; - /* The "sheet-spec" page of the assistant. */ +/* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */ +struct sheet_spec_page + { + GtkWidget *page; + struct casereader *reader; + struct dictionary *dict; + struct spreadsheet *spreadsheet; + + struct spreadsheet_read_info sri; + struct spreadsheet_read_options opts; + }; + + + + /* Initializes IA's sheet_spec substructure. */ -void -init_sheet_spec_page (struct import_assistant *ia) +struct sheet_spec_page * +sheet_spec_page_create (struct import_assistant *ia) { GtkBuilder *builder = ia->asst.builder; - struct sheet_spec_page *p = ia->sheet_spec; + struct sheet_spec_page *p = xzalloc (sizeof (*p)); p->page = add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"), GTK_ASSISTANT_PAGE_INTRO); + return p; } /* Prepares IA's sheet_spec page. */ @@ -182,3 +197,58 @@ post_sheet_spec_page (struct import_assistant *ia) } } + +/* + Update IA according to the contents of DICT and CREADER. + CREADER will be destroyed by this function. +*/ +void +update_assistant (struct import_assistant *ia) +{ + struct sheet_spec_page *ssp = ia->sheet_spec; + // struct file *file = &ia->file; + struct separators_page *sepp = ia->separators; + int rows = 0; + + + if (ssp->dict) + { + struct ccase *c; + int col; + + sepp->column_cnt = dict_get_var_cnt (ssp->dict); + sepp->columns = xcalloc (sepp->column_cnt, sizeof (*sepp->columns)); + for (col = 0; col < sepp->column_cnt ; ++col) + { + const struct variable *var = dict_get_var (ssp->dict, col); + sepp->columns[col].name = xstrdup (var_get_name (var)); + sepp->columns[col].contents = NULL; + } + + for (; (c = casereader_read (ssp->reader)) != NULL; case_unref (c)) + { + rows++; + for (col = 0; col < sepp->column_cnt ; ++col) + { + char *ss; + const struct variable *var = dict_get_var (ssp->dict, col); + + sepp->columns[col].contents = xrealloc (sepp->columns[col].contents, + sizeof (struct substring) * rows); + + ss = data_out (case_data (c, var), dict_get_encoding (ssp->dict), + var_get_print_format (var)); + + sepp->columns[col].contents[rows - 1] = ss_cstr (ss); + } + + if (rows > MAX_PREVIEW_LINES) + { + case_unref (c); + break; + } + } + } + + // file->line_cnt = rows; +} diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index c2de780328..c9cee75191 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -81,15 +81,8 @@ text_data_import_assistant (PsppireDataWindow *dw) } ssp = ia->sheet_spec; - if (ssp->spreadsheet == NULL) - { - init_first_line_page (ia); - init_separators_page (ia); - } - else - { - init_sheet_spec_page (ia); - } + init_first_line_page (ia); + init_separators_page (ia); init_formats_page (ia); @@ -111,11 +104,8 @@ text_data_import_assistant (PsppireDataWindow *dw) break; } - if (ssp->spreadsheet == NULL) - { - destroy_formats_page (ia); - destroy_separators_page (ia); - } + destroy_formats_page (ia); + destroy_separators_page (ia); destroy_assistant (ia); destroy_file (ia); @@ -214,6 +204,7 @@ generate_syntax (const struct import_assistant *ia) struct string s = DS_EMPTY_INITIALIZER; +#if 0 if (ssp->spreadsheet == NULL) { size_t var_cnt; @@ -267,11 +258,10 @@ generate_syntax (const struct import_assistant *ia) apply_dict (ia->formats->dict, &s); } else + { const struct sheet_spec_page *ssp = ia->sheet_spec; - printf ("%s:%d %p %d\n", __FILE__, __LINE__, ssp->spreadsheet, ssp->spreadsheet->type); - syntax_gen_pspp (&s, "GET DATA" "\n /TYPE=%ss" @@ -300,6 +290,7 @@ generate_syntax (const struct import_assistant *ia) syntax_gen_pspp (&s, "."); } +#endif return ds_cstr (&s); } diff --git a/src/ui/gui/text-data-import-dialog.h b/src/ui/gui/text-data-import-dialog.h index b7268235fb..be8c46e92d 100644 --- a/src/ui/gui/text-data-import-dialog.h +++ b/src/ui/gui/text-data-import-dialog.h @@ -23,6 +23,8 @@ #include "libpspp/str.h" +enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */ + /* The file to be imported. */ struct file { @@ -55,18 +57,6 @@ struct assistant }; -/* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */ -struct sheet_spec_page - { - GtkWidget *page; - struct casereader *reader; - struct dictionary *dict; - struct spreadsheet *spreadsheet; - - struct spreadsheet_read_info sri; - struct spreadsheet_read_options opts; - }; - /* Page where the user chooses the first line of data. */ struct first_line_page