06b1488762f9ba195e98210291b9041619996b51
[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/casereader.h>
33 #include <data/datasheet.h>
34 #include <data/file-handle-def.h>
35 #include <data/format.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 <libpspp/version.h>
42
43 #include <gtk/gtk.h>
44 #include <glade/glade.h>
45 #include "psppire-dict.h"
46 #include "psppire-var-store.h"
47 #include "psppire-data-store.h"
48 #include "helper.h"
49 #include "data-sheet.h"
50 #include "var-sheet.h"
51 #include "message-dialog.h"
52
53 PsppireDataStore *the_data_store = 0;
54 PsppireVarStore *the_var_store = 0;
55
56 static void create_icon_factory (void);
57
58 struct source_stream *the_source_stream ;
59 struct dataset * the_dataset = NULL;
60
61 static void
62 replace_dictionary (struct dictionary *d)
63 {
64   psppire_dict_replace_dictionary (the_data_store->dict, d);
65 }
66
67
68 static void
69 replace_casereader (struct casereader *s)
70 {
71   PsppireCaseFile *pcf = psppire_case_file_new (s);
72
73   psppire_data_store_set_case_file (the_data_store, pcf);
74 }
75
76 void
77 initialize (void)
78 {
79   PsppireDict *dictionary = 0;
80
81   /* gtk_init messes with the locale.
82      So unset the bits we want to control ourselves */
83   setlocale (LC_NUMERIC, "C");
84
85   bindtextdomain (PACKAGE, locale_dir);
86
87   textdomain (PACKAGE);
88
89   glade_init ();
90
91   fmt_init ();
92   settings_init ();
93   fh_init ();
94   the_source_stream =
95     create_source_stream (
96                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
97                           );
98
99   the_dataset = create_dataset (replace_casereader,
100                                 replace_dictionary);
101
102
103
104   message_dialog_init (the_source_stream);
105
106   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
107
108
109   bind_textdomain_codeset (PACKAGE, "UTF-8");
110
111
112   /* Create the model for the var_sheet */
113   the_var_store = psppire_var_store_new (dictionary);
114
115   the_data_store = psppire_data_store_new (dictionary);
116   replace_casereader (NULL);
117
118
119   create_icon_factory ();
120
121   new_data_window (NULL, NULL);
122 }
123
124
125 void
126 de_initialize (void)
127 {
128   destroy_source_stream (the_source_stream);
129   message_dialog_done ();
130   settings_done ();
131 }
132
133
134 #define PIXBUF_NEW_FROM_FILE(FILE) \
135   gdk_pixbuf_new_from_file (relocate (PKGDATADIR "/" FILE), 0)
136
137
138 static void
139 create_icon_factory (void)
140 {
141   GtkIconFactory *factory = gtk_icon_factory_new ();
142
143   GtkIconSet *icon_set;
144
145   GdkPixbuf *pixbuf;
146
147   pixbuf = PIXBUF_NEW_FROM_FILE ("value-labels.png");
148   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
149   g_object_unref (pixbuf);
150   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
151
152   pixbuf = PIXBUF_NEW_FROM_FILE ("weight-cases.png");
153   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
154   g_object_unref (pixbuf);
155   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
156
157   pixbuf = PIXBUF_NEW_FROM_FILE ("goto-variable.png");
158   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
159   g_object_unref (pixbuf);
160   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
161
162   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-variable.png");
163   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
164   g_object_unref (pixbuf);
165   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
166
167   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-case.png");
168   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
169   g_object_unref (pixbuf);
170   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
171
172   pixbuf = PIXBUF_NEW_FROM_FILE ("split-file.png");
173   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
174   g_object_unref (pixbuf);
175   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
176
177   pixbuf = PIXBUF_NEW_FROM_FILE ("select-cases.png");
178   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
179   g_object_unref (pixbuf);
180   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
181
182   pixbuf = PIXBUF_NEW_FROM_FILE ("recent-dialogs.png");
183   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
184   g_object_unref (pixbuf);
185   gtk_icon_factory_add ( factory, "pspp-recent-dialogs", icon_set);
186
187   pixbuf = PIXBUF_NEW_FROM_FILE ("nominal.png");
188   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
189   g_object_unref (pixbuf);
190   gtk_icon_factory_add ( factory, "var-nominal", icon_set);
191
192   pixbuf = PIXBUF_NEW_FROM_FILE ("ordinal.png");
193   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
194   g_object_unref (pixbuf);
195   gtk_icon_factory_add ( factory, "var-ordinal", icon_set);
196
197   pixbuf = PIXBUF_NEW_FROM_FILE ("scale.png");
198   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
199   g_object_unref (pixbuf);
200   gtk_icon_factory_add ( factory, "var-scale", icon_set);
201
202   pixbuf = PIXBUF_NEW_FROM_FILE ("string.png");
203   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
204   g_object_unref (pixbuf);
205   gtk_icon_factory_add ( factory, "var-string", icon_set);
206
207   pixbuf = PIXBUF_NEW_FROM_FILE ("date-scale.png");
208   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
209   g_object_unref (pixbuf);
210   gtk_icon_factory_add ( factory, "var-date-scale", icon_set);
211
212
213   gtk_icon_factory_add_default (factory);
214 }
215