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"
33 /* The file to be imported. */
36 char *file_name; /* File name. */
40 /* Relevant only for text files */
42 gchar *encoding; /* Encoding. */
43 unsigned long int total_lines; /* Number of lines in file. */
44 bool total_is_exact; /* Is total_lines exact (or an estimate)? */
46 /* The first several lines of the file. */
51 /* The main body of the GTK+ assistant and related data. */
55 GtkAssistant *assistant;
57 GtkWidget *paste_button;
58 GtkWidget *reset_button;
62 GtkCellRenderer *prop_renderer;
63 GtkCellRenderer *fixed_renderer;
67 /* The sheet_spec page of the assistant (only relevant for spreadsheet imports). */
68 struct sheet_spec_page
71 struct casereader *reader;
72 struct dictionary *dict;
74 struct spreadsheet_read_info sri;
75 struct spreadsheet_read_options opts;
79 /* The introduction page of the assistant. */
83 GtkWidget *all_cases_button;
84 GtkWidget *n_cases_button;
85 GtkWidget *n_cases_spin;
86 GtkWidget *percent_button;
87 GtkWidget *percent_spin;
90 /* Page where the user chooses the first line of data. */
91 struct first_line_page
93 int skip_lines; /* Number of initial lines to skip? */
94 bool variable_names; /* Variable names above first line of data? */
97 GtkTreeView *tree_view;
98 GtkWidget *variable_names_cb;
102 /* Page where the user chooses field separators. */
103 struct separators_page
105 /* How to break lines into columns. */
106 struct string separators; /* Field separators. */
107 struct string quotes; /* Quote characters. */
108 bool escape; /* Doubled quotes yield a quote mark? */
110 /* The columns produced thereby. */
111 struct column *columns; /* Information about each column. */
112 size_t column_cnt; /* Number of columns. */
115 GtkWidget *custom_cb;
116 GtkWidget *custom_entry;
118 GtkWidget *quote_combo;
119 GtkEntry *quote_entry;
120 GtkWidget *escape_cb;
121 GtkTreeView *fields_tree_view;
124 /* Page where the user verifies and adjusts input formats. */
127 struct dictionary *dict;
130 GtkTreeView *data_tree_view;
131 PsppireDict *psppire_dict;
132 struct variable **modified_vars;
133 size_t modified_var_cnt;
137 struct import_assistant
140 struct assistant asst;
141 struct intro_page intro;
142 struct sheet_spec_page sheet_spec;
143 struct first_line_page first_line;
144 struct separators_page separators;
145 struct formats_page formats;
153 /* Variable name for this column. This is the variable name
154 used on the separators page; it can be overridden by the
155 user on the formats page. */
158 /* Maximum length of any row in this column. */
161 /* Contents of this column: contents[row] is the contents for
164 A null substring indicates a missing column for that row
165 (because the line contains an insufficient number of
168 contents[] elements may be substrings of the lines[]
169 strings that represent the whole lines of the file, to
170 save memory. Other elements are dynamically allocated
171 with ss_alloc_substring. */
172 struct substring *contents;
176 GtkWidget * add_page_to_assistant (struct import_assistant *ia,
177 GtkWidget *page, GtkAssistantPageType type);
179 void text_data_import_assistant (PsppireDataWindow *);
181 /* FIXME: Should this be private to first line page ? */
182 void make_tree_view (const struct import_assistant *ia,
184 GtkTreeView **tree_view);
186 gint get_monospace_width (GtkTreeView *, GtkCellRenderer *,
188 gint get_string_width (GtkTreeView *, GtkCellRenderer *,
193 void push_watch_cursor (struct import_assistant *);
194 void pop_watch_cursor (struct import_assistant *);
197 GtkTreeView *create_data_tree_view (bool input, GtkContainer *parent,
198 struct import_assistant *);
200 GtkTreeViewColumn *make_data_column (struct import_assistant *,
201 GtkTreeView *, bool input,
205 void update_assistant (struct import_assistant *ia);
208 bool init_file (struct import_assistant *ia, GtkWindow *parent_window);
209 void destroy_file (struct import_assistant *ia);
212 void init_intro_page (struct import_assistant *);
213 void reset_intro_page (struct import_assistant *);
215 void init_sheet_spec_page (struct import_assistant *);
216 void reset_sheet_spec_page (struct import_assistant *);
217 void post_sheet_spec_page (struct import_assistant *ia);
219 void init_first_line_page (struct import_assistant *ia);
220 void prepare_first_line_page (struct import_assistant *ia);
221 void reset_first_line_page (struct import_assistant *);
223 void init_separators_page (struct import_assistant *ia);
224 void prepare_separators_page (struct import_assistant *ia);
225 void reset_separators_page (struct import_assistant *);
226 void destroy_separators_page (struct import_assistant *ia);
228 void init_formats_page (struct import_assistant *ia);
229 void prepare_formats_page (struct import_assistant *ia);
230 void reset_formats_page (struct import_assistant *);
231 void destroy_formats_page (struct import_assistant *ia);
233 void init_assistant (struct import_assistant *, GtkWindow *);
234 void destroy_assistant (struct import_assistant *);