c575534c060a44eca7ef4f54b58109e39abb501c
[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 PsppireVarStore *the_var_store = 0;
57
58 static void create_icon_factory (void);
59
60 struct source_stream *the_source_stream ;
61 struct dataset * the_dataset = NULL;
62
63 static void
64 replace_dictionary (struct dictionary *d)
65 {
66   psppire_dict_replace_dictionary (the_data_store->dict, d);
67 }
68
69
70 static void
71 replace_flexifile (struct case_source *s)
72 {
73   if ( NULL == s )
74     psppire_case_file_replace_flexifile (the_data_store->case_file,
75                                          (struct flexifile *) flexifile_create (0));
76   else
77     {
78       if ( ! case_source_is_class (s, &storage_source_class))
79         return ;
80
81       psppire_case_file_replace_flexifile (the_data_store->case_file,
82                                            (struct flexifile *)
83                                            storage_source_get_casefile (s));
84     }
85 }
86
87
88
89 void
90 initialize (void)
91 {
92   struct casefile_factory *factory;
93   PsppireDict *dictionary = 0;
94
95   /* gtk_init messes with the locale.
96      So unset the bits we want to control ourselves */
97   setlocale (LC_NUMERIC, "C");
98
99   bindtextdomain (PACKAGE, locale_dir);
100
101   textdomain (PACKAGE);
102
103   glade_init ();
104
105   fmt_init ();
106   settings_init ();
107   fh_init ();
108   factory = flexifile_factory_create ();
109   the_source_stream =
110     create_source_stream (
111                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
112                           );
113
114   the_dataset = create_dataset (factory,
115                                 replace_flexifile,
116                                 replace_dictionary);
117
118   message_dialog_init (the_source_stream);
119
120   dictionary = psppire_dict_new_from_dict (
121                                            dataset_dict (the_dataset)
122                                            );
123
124   bind_textdomain_codeset (PACKAGE, "UTF-8");
125
126
127   /* Create the model for the var_sheet */
128   the_var_store = psppire_var_store_new (dictionary);
129
130
131   the_data_store = psppire_data_store_new (dictionary);
132
133   proc_set_source (the_dataset,
134                    storage_source_create (the_data_store->case_file->flexifile)
135                    );
136
137   create_icon_factory ();
138
139   new_data_window (NULL, NULL);
140 }
141
142
143 void
144 de_initialize (void)
145 {
146   destroy_source_stream (the_source_stream);
147   message_dialog_done ();
148   settings_done ();
149 }
150
151
152 #define PIXBUF_NEW_FROM_FILE(FILE) \
153   gdk_pixbuf_new_from_file (relocate (PKGDATADIR "/" FILE), 0)
154
155
156 static void
157 create_icon_factory (void)
158 {
159   GtkIconFactory *factory = gtk_icon_factory_new ();
160
161   GtkIconSet *icon_set;
162
163   GdkPixbuf *pixbuf;
164
165   pixbuf = PIXBUF_NEW_FROM_FILE ("value-labels.png");
166   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
167   g_object_unref (pixbuf);
168   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
169
170   pixbuf = PIXBUF_NEW_FROM_FILE ("weight-cases.png");
171   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
172   g_object_unref (pixbuf);
173   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
174
175   pixbuf = PIXBUF_NEW_FROM_FILE ("goto-variable.png");
176   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
177   g_object_unref (pixbuf);
178   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
179
180   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-variable.png");
181   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
182   g_object_unref (pixbuf);
183   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
184
185   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-case.png");
186   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
187   g_object_unref (pixbuf);
188   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
189
190   pixbuf = PIXBUF_NEW_FROM_FILE ("split-file.png");
191   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
192   g_object_unref (pixbuf);
193   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
194
195   pixbuf = PIXBUF_NEW_FROM_FILE ("select-cases.png");
196   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
197   g_object_unref (pixbuf);
198   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
199
200   pixbuf = PIXBUF_NEW_FROM_FILE ("recent-dialogs.png");
201   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
202   g_object_unref (pixbuf);
203   gtk_icon_factory_add ( factory, "pspp-recent-dialogs", icon_set);
204
205   pixbuf = PIXBUF_NEW_FROM_FILE ("nominal.png");
206   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
207   g_object_unref (pixbuf);
208   gtk_icon_factory_add ( factory, "var-nominal", icon_set);
209
210   pixbuf = PIXBUF_NEW_FROM_FILE ("ordinal.png");
211   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
212   g_object_unref (pixbuf);
213   gtk_icon_factory_add ( factory, "var-ordinal", icon_set);
214
215   pixbuf = PIXBUF_NEW_FROM_FILE ("scale.png");
216   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
217   g_object_unref (pixbuf);
218   gtk_icon_factory_add ( factory, "var-scale", icon_set);
219
220   pixbuf = PIXBUF_NEW_FROM_FILE ("string.png");
221   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
222   g_object_unref (pixbuf);
223   gtk_icon_factory_add ( factory, "var-string", icon_set);
224
225   pixbuf = PIXBUF_NEW_FROM_FILE ("date-scale.png");
226   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
227   g_object_unref (pixbuf);
228   gtk_icon_factory_add ( factory, "var-date-scale", icon_set);
229
230
231   gtk_icon_factory_add_default (factory);
232 }
233