Re-enabled the reset buttons
[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 struct assist_page
29 {
30   GtkWidget *page;
31 };
32
33 /* The file to be imported. */
34 struct file
35   {
36     char *file_name;        /* File name. */
37
38     /* Relevant only for text files */
39
40     gchar *encoding;        /* Encoding. */
41     unsigned long int total_lines; /* Number of lines in file. */
42     bool total_is_exact;    /* Is total_lines exact (or an estimate)? */
43
44     /* The first several lines of the file. */
45     struct string *lines;
46     size_t line_cnt;
47   };
48
49 /* The main body of the GTK+ assistant and related data. */
50 struct assistant
51   {
52     GtkBuilder *builder;
53     GtkAssistant *assistant;
54     GMainLoop *main_loop;
55     bool loop_done;
56     GtkWidget *paste_button;
57     GtkWidget *reset_button;
58     int response;
59     int watch_cursor;
60
61     GtkCellRenderer *prop_renderer;
62     GtkCellRenderer *fixed_renderer;
63   };
64
65 struct import_assistant
66   {
67     struct file file;
68     struct assistant asst;
69
70     struct intro_page *intro;
71     struct sheet_spec_page *sheet_spec;
72     struct first_line_page *first_line;
73     struct separators_page *separators;
74     struct formats_page *formats;
75
76     /* The columns produced. */
77     struct column *columns;     /* Information about each column. */
78     size_t column_cnt;          /* Number of columns. */
79
80     int skip_lines;             /* Number of initial lines to skip? */
81     bool variable_names;        /* Variable names above first line of data? */
82     struct dictionary *dict;
83
84     struct spreadsheet *spreadsheet;
85   };
86
87 struct column
88   {
89     /* Variable name for this column.  This is the variable name
90        used on the separators page; it can be overridden by the
91        user on the formats page. */
92     char *name;
93
94     /* Maximum length of any row in this column. */
95     size_t width;
96
97     /* Contents of this column: contents[row] is the contents for
98        the given row.
99
100        A null substring indicates a missing column for that row
101        (because the line contains an insufficient number of
102        separators).
103
104        contents[] elements may be substrings of the lines[]
105        strings that represent the whole lines of the file, to
106        save memory.  Other elements are dynamically allocated
107        with ss_alloc_substring. */
108     struct substring *contents;
109   };
110
111
112 GtkWidget * add_page_to_assistant (struct import_assistant *ia,
113                                    GtkWidget *page, GtkAssistantPageType type);
114
115 void text_data_import_assistant (PsppireDataWindow *);
116
117 /* FIXME: Should this be private to first line page ? */
118 void make_tree_view (const struct import_assistant *ia,
119                             size_t first_line,
120                             GtkTreeView **tree_view);
121
122 gint get_monospace_width (GtkTreeView *, GtkCellRenderer *,
123                                  size_t char_cnt);
124 gint get_string_width (GtkTreeView *, GtkCellRenderer *,
125                               const char *string);
126
127
128
129 void push_watch_cursor (struct import_assistant *);
130 void pop_watch_cursor (struct import_assistant *);
131
132
133 GtkTreeView *create_data_tree_view (bool input, GtkContainer *parent,
134                                            struct import_assistant *);
135
136 GtkTreeViewColumn *make_data_column (struct import_assistant *,
137                                             GtkTreeView *, bool input,
138                                             gint column_idx);
139
140
141 void  update_assistant (struct import_assistant *ia);
142
143 bool init_file (struct import_assistant *ia, GtkWindow *parent_window);
144 void destroy_file (struct import_assistant *ia);
145
146 void prepare_sheet_spec_page (struct import_assistant *ia);
147 void reset_sheet_spec_page (struct import_assistant *);
148 void post_sheet_spec_page (struct import_assistant *ia);
149
150 void prepare_first_line_page (struct import_assistant *ia);
151 void reset_first_line_page (struct import_assistant *);
152
153 void reset_intro_page (struct import_assistant *ia);
154
155 void prepare_separators_page (struct import_assistant *ia);
156 void reset_separators_page (struct import_assistant *);
157 void destroy_separators_page (struct import_assistant *ia);
158
159 void prepare_formats_page (struct import_assistant *ia);
160 void reset_formats_page (struct import_assistant *);
161 void destroy_formats_page (struct import_assistant *ia);
162
163 struct import_assistant * init_assistant (GtkWindow *);
164 void destroy_assistant (struct import_assistant *);
165
166
167 #endif