1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2010, 2011, 2013 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef TEXT_DATA_IMPORT_DIALOG_H
18 #define TEXT_DATA_IMPORT_DIALOG_H
20 #include <glib-object.h>
21 #include "ui/gui/psppire-data-window.h"
22 #include "data/spreadsheet-reader.h"
24 #include "libpspp/str.h"
26 enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
28 /* The file to be imported. */
31 char *file_name; /* File name. */
33 /* Relevant only for text files */
35 gchar *encoding; /* Encoding. */
36 unsigned long int total_lines; /* Number of lines in file. */
37 bool total_is_exact; /* Is total_lines exact (or an estimate)? */
39 /* The first several lines of the file. */
44 /* The main body of the GTK+ assistant and related data. */
48 GtkAssistant *assistant;
50 GtkWidget *paste_button;
51 GtkWidget *reset_button;
55 GtkCellRenderer *prop_renderer;
56 GtkCellRenderer *fixed_renderer;
62 /* Page where the user chooses the first line of data. */
63 struct first_line_page
65 int skip_lines; /* Number of initial lines to skip? */
66 bool variable_names; /* Variable names above first line of data? */
69 GtkTreeView *tree_view;
70 GtkWidget *variable_names_cb;
74 /* Page where the user verifies and adjusts input formats. */
77 struct dictionary *dict;
80 GtkTreeView *data_tree_view;
81 PsppireDict *psppire_dict;
82 struct variable **modified_vars;
83 size_t modified_var_cnt;
87 struct import_assistant
90 struct assistant asst;
92 struct intro_page *intro;
93 struct sheet_spec_page *sheet_spec;
94 struct first_line_page *first_line;
95 struct separators_page *separators;
96 struct formats_page *formats;
98 /* The columns produced. */
99 struct column *columns; /* Information about each column. */
100 size_t column_cnt; /* Number of columns. */
108 /* Variable name for this column. This is the variable name
109 used on the separators page; it can be overridden by the
110 user on the formats page. */
113 /* Maximum length of any row in this column. */
116 /* Contents of this column: contents[row] is the contents for
119 A null substring indicates a missing column for that row
120 (because the line contains an insufficient number of
123 contents[] elements may be substrings of the lines[]
124 strings that represent the whole lines of the file, to
125 save memory. Other elements are dynamically allocated
126 with ss_alloc_substring. */
127 struct substring *contents;
131 GtkWidget * add_page_to_assistant (struct import_assistant *ia,
132 GtkWidget *page, GtkAssistantPageType type);
134 void text_data_import_assistant (PsppireDataWindow *);
136 /* FIXME: Should this be private to first line page ? */
137 void make_tree_view (const struct import_assistant *ia,
139 GtkTreeView **tree_view);
141 gint get_monospace_width (GtkTreeView *, GtkCellRenderer *,
143 gint get_string_width (GtkTreeView *, GtkCellRenderer *,
148 void push_watch_cursor (struct import_assistant *);
149 void pop_watch_cursor (struct import_assistant *);
152 GtkTreeView *create_data_tree_view (bool input, GtkContainer *parent,
153 struct import_assistant *);
155 GtkTreeViewColumn *make_data_column (struct import_assistant *,
156 GtkTreeView *, bool input,
160 void update_assistant (struct import_assistant *ia);
162 bool init_file (struct import_assistant *ia, GtkWindow *parent_window);
163 void destroy_file (struct import_assistant *ia);
166 void init_sheet_spec_page (struct import_assistant *);
167 void prepare_sheet_spec_page (struct import_assistant *ia);
168 void reset_sheet_spec_page (struct import_assistant *);
169 void post_sheet_spec_page (struct import_assistant *ia);
171 void init_first_line_page (struct import_assistant *ia);
172 void prepare_first_line_page (struct import_assistant *ia);
173 void reset_first_line_page (struct import_assistant *);
175 void init_separators_page (struct import_assistant *ia);
176 void prepare_separators_page (struct import_assistant *ia);
177 void reset_separators_page (struct import_assistant *);
178 void destroy_separators_page (struct import_assistant *ia);
180 void init_formats_page (struct import_assistant *ia);
181 void prepare_formats_page (struct import_assistant *ia);
182 void reset_formats_page (struct import_assistant *);
183 void destroy_formats_page (struct import_assistant *ia);
185 struct import_assistant * init_assistant (GtkWindow *);
186 void destroy_assistant (struct import_assistant *);