84489c073c983a47b4cd033fea84b9b8c3cdc791
[pspp-builds.git] / src / ui / gui / psppire.c
1 /*
2    PSPPIRE --- A Graphical User Interface for PSPP
3    Copyright (C) 2004, 2005, 2006  Free Software Foundation
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #include <config.h>
21
22 #include <assert.h>
23 #include <libintl.h>
24
25 #include "relocatable.h"
26
27 #include "data-editor.h"
28
29 #include "psppire.h"
30
31
32 #include <data/file-handle-def.h>
33 #include <data/format.h>
34 #include <data/storage-stream.h>
35 #include <data/case-source.h>
36 #include <data/settings.h>
37 #include <data/file-name.h>
38 #include <data/procedure.h>
39 #include <libpspp/getl.h>
40 #include <language/lexer/lexer.h>
41 #include <ui/flexifile.h>
42 #include <libpspp/version.h>
43
44 #include <gtk/gtk.h>
45 #include <glade/glade.h>
46 #include "psppire-dict.h"
47 #include "psppire-var-store.h"
48 #include "psppire-data-store.h"
49 #include "helper.h"
50 #include "data-sheet.h"
51 #include "var-sheet.h"
52 #include "message-dialog.h"
53 #include "flexifile-factory.h"
54
55 PsppireDataStore *the_data_store = 0;
56
57
58 static bool parse_command_line (int *argc, char ***argv,
59                                 gchar **filename,
60                                 gboolean *show_splash,
61                                 GError **err);
62
63
64 PsppireVarStore *the_var_store = 0;
65
66 static void create_icon_factory (void);
67
68 struct source_stream *the_source_stream ;
69 struct dataset * the_dataset = NULL;
70
71 static void
72 replace_dictionary (struct dictionary *d)
73 {
74   psppire_dict_replace_dictionary (the_data_store->dict, d);
75 }
76
77
78 static void
79 replace_flexifile (struct case_source *s)
80 {
81   if ( NULL == s )
82     psppire_case_file_replace_flexifile (the_data_store->case_file,
83                                          (struct flexifile *) flexifile_create (0));
84   else
85     {
86       if ( ! case_source_is_class (s, &storage_source_class))
87         return ;
88
89       psppire_case_file_replace_flexifile (the_data_store->case_file,
90                                            (struct flexifile *)
91                                            storage_source_get_casefile (s));
92     }
93 }
94
95
96
97 void
98 initialize (void)
99 {
100   struct casefile_factory *factory;
101   PsppireDict *dictionary = 0;
102
103   /* gtk_init messes with the locale.
104      So unset the bits we want to control ourselves */
105   setlocale (LC_NUMERIC, "C");
106
107   bindtextdomain (PACKAGE, locale_dir);
108
109   textdomain (PACKAGE);
110
111   glade_init ();
112
113   fmt_init ();
114   settings_init ();
115   fh_init ();
116   factory = flexifile_factory_create ();
117   the_source_stream =
118     create_source_stream (
119                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
120                           );
121
122   the_dataset = create_dataset (factory,
123                                 replace_flexifile,
124                                 replace_dictionary);
125
126   message_dialog_init (the_source_stream);
127
128   dictionary = psppire_dict_new_from_dict (
129                                            dataset_dict (the_dataset)
130                                            );
131
132   bind_textdomain_codeset (PACKAGE, "UTF-8");
133
134
135   /* Create the model for the var_sheet */
136   the_var_store = psppire_var_store_new (dictionary);
137
138
139   the_data_store = psppire_data_store_new (dictionary);
140
141   proc_set_source (the_dataset,
142                    storage_source_create (the_data_store->case_file->flexifile)
143                    );
144
145   create_icon_factory ();
146
147   new_data_window (NULL, NULL);
148 }
149
150
151 void
152 de_initialize (void)
153 {
154   destroy_source_stream (the_source_stream);
155   message_dialog_done ();
156   settings_done ();
157 }
158
159
160 #define PIXBUF_NEW_FROM_FILE(FILE) \
161   gdk_pixbuf_new_from_file (relocate (PKGDATADIR "/" FILE), 0)
162
163
164 static void
165 create_icon_factory (void)
166 {
167   GtkIconFactory *factory = gtk_icon_factory_new ();
168
169   GtkIconSet *icon_set;
170
171   GdkPixbuf *pixbuf;
172
173   pixbuf = PIXBUF_NEW_FROM_FILE ("value-labels.png");
174   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
175   g_object_unref (pixbuf);
176   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
177
178   pixbuf = PIXBUF_NEW_FROM_FILE ("weight-cases.png");
179   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
180   g_object_unref (pixbuf);
181   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
182
183   pixbuf = PIXBUF_NEW_FROM_FILE ("goto-variable.png");
184   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
185   g_object_unref (pixbuf);
186   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
187
188   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-variable.png");
189   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
190   g_object_unref (pixbuf);
191   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
192
193   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-case.png");
194   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
195   g_object_unref (pixbuf);
196   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
197
198   pixbuf = PIXBUF_NEW_FROM_FILE ("split-file.png");
199   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
200   g_object_unref (pixbuf);
201   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
202
203   pixbuf = PIXBUF_NEW_FROM_FILE ("select-cases.png");
204   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
205   g_object_unref (pixbuf);
206   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
207
208   pixbuf = PIXBUF_NEW_FROM_FILE ("recent-dialogs.png");
209   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
210   g_object_unref (pixbuf);
211   gtk_icon_factory_add ( factory, "pspp-recent-dialogs", icon_set);
212
213   pixbuf = PIXBUF_NEW_FROM_FILE ("nominal.png");
214   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
215   g_object_unref (pixbuf);
216   gtk_icon_factory_add ( factory, "var-nominal", icon_set);
217
218   pixbuf = PIXBUF_NEW_FROM_FILE ("ordinal.png");
219   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
220   g_object_unref (pixbuf);
221   gtk_icon_factory_add ( factory, "var-ordinal", icon_set);
222
223   pixbuf = PIXBUF_NEW_FROM_FILE ("scale.png");
224   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
225   g_object_unref (pixbuf);
226   gtk_icon_factory_add ( factory, "var-scale", icon_set);
227
228   pixbuf = PIXBUF_NEW_FROM_FILE ("string.png");
229   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
230   g_object_unref (pixbuf);
231   gtk_icon_factory_add ( factory, "var-string", icon_set);
232
233   pixbuf = PIXBUF_NEW_FROM_FILE ("date-scale.png");
234   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
235   g_object_unref (pixbuf);
236   gtk_icon_factory_add ( factory, "var-date-scale", icon_set);
237
238
239   gtk_icon_factory_add_default (factory);
240 }
241