Make sheet spec page opaque
[pspp] / src / ui / gui / text-data-import-dialog.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2008, 2010, 2011, 2013  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17 #ifndef TEXT_DATA_IMPORT_DIALOG_H
18 #define TEXT_DATA_IMPORT_DIALOG_H
19
20 #include <glib-object.h>
21 #include "ui/gui/psppire-data-window.h"
22 #include "data/spreadsheet-reader.h"
23
24 #include "libpspp/str.h"
25
26 enum { MAX_PREVIEW_LINES = 1000 }; /* Max number of lines to read. */
27
28 /* The file to be imported. */
29 struct file
30   {
31     char *file_name;        /* File name. */
32
33     /* Relevant only for text files */
34
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)? */
38
39     /* The first several lines of the file. */
40     struct string *lines;
41     size_t line_cnt;
42   };
43
44 /* The main body of the GTK+ assistant and related data. */
45 struct assistant
46   {
47     GtkBuilder *builder;
48     GtkAssistant *assistant;
49     GMainLoop *main_loop;
50     GtkWidget *paste_button;
51     GtkWidget *reset_button;
52     int response;
53     int watch_cursor;
54
55     GtkCellRenderer *prop_renderer;
56     GtkCellRenderer *fixed_renderer;
57   };
58
59
60
61 /* Page where the user chooses the first line of data. */
62 struct first_line_page
63   {
64     int skip_lines;    /* Number of initial lines to skip? */
65     bool variable_names; /* Variable names above first line of data? */
66
67     GtkWidget *page;
68     GtkTreeView *tree_view;
69     GtkWidget *variable_names_cb;
70   };
71
72
73 /* Page where the user chooses field separators. */
74 struct separators_page
75   {
76     /* How to break lines into columns. */
77     struct string separators;   /* Field separators. */
78     struct string quotes;       /* Quote characters. */
79     bool escape;                /* Doubled quotes yield a quote mark? */
80
81     /* The columns produced thereby. */
82     struct column *columns;     /* Information about each column. */
83     size_t column_cnt;          /* Number of columns. */
84
85     GtkWidget *page;
86     GtkWidget *custom_cb;
87     GtkWidget *custom_entry;
88     GtkWidget *quote_cb;
89     GtkWidget *quote_combo;
90     GtkEntry *quote_entry;
91     GtkWidget *escape_cb;
92     GtkTreeView *fields_tree_view;
93   };
94
95 /* Page where the user verifies and adjusts input formats. */
96 struct formats_page
97   {
98     struct dictionary *dict;
99
100     GtkWidget *page;
101     GtkTreeView *data_tree_view;
102     PsppireDict *psppire_dict;
103     struct variable **modified_vars;
104     size_t modified_var_cnt;
105   };
106
107
108 struct import_assistant
109   {
110     struct file file;
111     struct assistant asst;
112
113     struct intro_page *intro;
114     struct sheet_spec_page *sheet_spec;
115     struct first_line_page *first_line;
116     struct separators_page *separators;
117     struct formats_page *formats;
118   };
119
120
121
122
123 struct column
124   {
125     /* Variable name for this column.  This is the variable name
126        used on the separators page; it can be overridden by the
127        user on the formats page. */
128     char *name;
129
130     /* Maximum length of any row in this column. */
131     size_t width;
132
133     /* Contents of this column: contents[row] is the contents for
134        the given row.
135
136        A null substring indicates a missing column for that row
137        (because the line contains an insufficient number of
138        separators).
139
140        contents[] elements may be substrings of the lines[]
141        strings that represent the whole lines of the file, to
142        save memory.  Other elements are dynamically allocated
143        with ss_alloc_substring. */
144     struct substring *contents;
145   };
146
147
148 GtkWidget * add_page_to_assistant (struct import_assistant *ia,
149                                    GtkWidget *page, GtkAssistantPageType type);
150
151 void text_data_import_assistant (PsppireDataWindow *);
152
153 /* FIXME: Should this be private to first line page ? */
154 void make_tree_view (const struct import_assistant *ia,
155                             size_t first_line,
156                             GtkTreeView **tree_view);
157
158 gint get_monospace_width (GtkTreeView *, GtkCellRenderer *,
159                                  size_t char_cnt);
160 gint get_string_width (GtkTreeView *, GtkCellRenderer *,
161                               const char *string);
162
163
164
165 void push_watch_cursor (struct import_assistant *);
166 void pop_watch_cursor (struct import_assistant *);
167
168
169 GtkTreeView *create_data_tree_view (bool input, GtkContainer *parent,
170                                            struct import_assistant *);
171
172 GtkTreeViewColumn *make_data_column (struct import_assistant *,
173                                             GtkTreeView *, bool input,
174                                             gint column_idx);
175
176
177 void  update_assistant (struct import_assistant *ia);
178
179 bool init_file (struct import_assistant *ia, GtkWindow *parent_window);
180 void destroy_file (struct import_assistant *ia);
181
182
183 void init_sheet_spec_page (struct import_assistant *);
184 void prepare_sheet_spec_page (struct import_assistant *ia);
185 void reset_sheet_spec_page (struct import_assistant *);
186 void post_sheet_spec_page (struct import_assistant *ia);
187
188 void init_first_line_page (struct import_assistant *ia);
189 void prepare_first_line_page (struct import_assistant *ia);
190 void reset_first_line_page (struct import_assistant *);
191
192 void init_separators_page (struct import_assistant *ia);
193 void prepare_separators_page (struct import_assistant *ia);
194 void reset_separators_page (struct import_assistant *);
195 void destroy_separators_page (struct import_assistant *ia);
196
197 void init_formats_page (struct import_assistant *ia);
198 void prepare_formats_page (struct import_assistant *ia);
199 void reset_formats_page (struct import_assistant *);
200 void destroy_formats_page (struct import_assistant *ia);
201
202 struct import_assistant * init_assistant (GtkWindow *);
203 void destroy_assistant (struct import_assistant *);
204
205
206 #endif