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