Make sheet spec page opaque
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 23 Jan 2013 20:35:03 +0000 (21:35 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 16 Feb 2013 14:03:20 +0000 (15:03 +0100)
src/ui/gui/page-assistant.c
src/ui/gui/page-file.c
src/ui/gui/page-sheet-spec.c
src/ui/gui/text-data-import-dialog.c
src/ui/gui/text-data-import-dialog.h

index e7dd02de2767c6502733110c6054fcf896e1d46b..c27d6c3472d2dd4be30921aa6d63f5ad7cf82fd5 100644 (file)
@@ -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);
index c52171dfa863ca5ce87da334526a7bcf6250e2f3..5254628bb8f96031a8faed732722234d1c1c5226 100644 (file)
@@ -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);
     }
index 4ba379df4227e25f3bdb0316b9a0637f475d5ba8..74593f2523112619a9a1482b2401543fa2f4c8fa 100644 (file)
 struct import_assistant;
 
 
-\f
 /* 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;
+}
index c2de780328d9462a8c1e88a7b5fbb84771640902..c9cee751915f773f0b291fc285f23eee1eef5cfc 100644 (file)
@@ -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);
 }
 
index b7268235fbe49f2bb5ed263f48ec4000bd7cc61a..be8c46e92d13b94ef1f05551d7044f5c4057e364 100644 (file)
@@ -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