Fixed the refresh button on the dialogs.
[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 "progname.h"
26 #include "relocatable.h"
27
28 #include "data-editor.h"
29
30 #include <libpspp/version.h>
31 #include <libpspp/copyleft.h>
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
43 #include <getopt.h>
44 #include <gtk/gtk.h>
45 #include <gtk/gtk.h>
46 #include <glade/glade.h>
47 #include "psppire-dict.h"
48 #include "psppire-var-store.h"
49 #include "psppire-data-store.h"
50 #include "helper.h"
51 #include "data-sheet.h"
52 #include "var-sheet.h"
53 #include "message-dialog.h"
54 #include "flexifile-factory.h"
55
56 PsppireDataStore *the_data_store = 0;
57
58
59 static bool parse_command_line (int *argc, char ***argv,
60                                 gchar **filename, GError **err);
61
62
63 PsppireVarStore *the_var_store = 0;
64
65 void create_icon_factory (void);
66
67 struct source_stream *the_source_stream ;
68 struct dataset * the_dataset = NULL;
69
70 static void
71 replace_dictionary (struct dictionary *d)
72 {
73   psppire_dict_replace_dictionary (the_data_store->dict,
74                                    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 int
97 main (int argc, char *argv[])
98 {
99   struct casefile_factory *factory;
100   PsppireDict *dictionary = 0;
101
102   gchar *filename=0;
103   GError *err = 0;
104   gchar *vers;
105
106   set_program_name (argv[0]);
107
108   if ( ! gtk_parse_args (&argc, &argv) )
109     {
110       perror ("Error parsing arguments");
111       exit (1);
112     }
113
114   if ( (vers = gtk_check_version (GTK_MAJOR_VERSION,
115                                  GTK_MINOR_VERSION,
116                                  GTK_MICRO_VERSION)) )
117     {
118       g_critical (vers);
119     }
120
121
122   /* gtk_init messes with the locale.
123      So unset the bits we want to control ourselves */
124   setlocale (LC_NUMERIC, "C");
125
126   bindtextdomain (PACKAGE, locale_dir);
127
128   textdomain (PACKAGE);
129
130   if ( ! parse_command_line (&argc, &argv, &filename, &err) )
131     {
132       g_clear_error (&err);
133       return 0;
134     }
135
136   glade_init ();
137
138   fmt_init ();
139   settings_init ();
140   fh_init ();
141   factory = flexifile_factory_create ();
142   the_source_stream = create_source_stream (
143                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
144                           );
145
146   the_dataset = create_dataset (factory,
147                                 replace_flexifile,
148                                 replace_dictionary);
149
150   message_dialog_init (the_source_stream);
151
152   dictionary = psppire_dict_new_from_dict (
153                                            dataset_dict (the_dataset)
154                                            );
155
156   bind_textdomain_codeset (PACKAGE, "UTF-8");
157
158   gdk_init (&argc, &argv);
159
160   /* Create the model for the var_sheet */
161   the_var_store = psppire_var_store_new (dictionary);
162
163
164   the_data_store = psppire_data_store_new (dictionary);
165
166   proc_set_source (the_dataset,
167                    storage_source_create (the_data_store->case_file->flexifile)
168                    );
169
170   create_icon_factory ();
171
172   new_data_window (NULL, NULL);
173
174   /* start the event loop */
175   gtk_main ();
176
177   destroy_source_stream (the_source_stream);
178   message_dialog_done ();
179
180   settings_done ();
181
182   return 0;
183 }
184
185
186 /* Parses the command line specified by ARGC and ARGV as received by
187    main ().  Returns true if normal execution should proceed,
188    false if the command-line indicates that PSPP should exit. */
189 static bool
190 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
191 {
192   static struct option long_options[] =
193     {
194       {"help", no_argument, NULL, 'h'},
195       {"version", no_argument, NULL, 'V'},
196       {0, 0, 0, 0},
197     };
198
199   int c;
200
201   for (;;)
202     {
203       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
204       if (c == -1)
205         break;
206
207       switch (c)
208         {
209         case 'h':
210           g_print ("Usage: psppire {|--help|--version}\n");
211           return false;
212         case 'V':
213           g_print (version);
214           g_print ("\n");
215           g_print (legal);
216           return false;
217         default:
218           return false;
219         }
220     }
221
222   if ( optind < *argc)
223     {
224       *filename = (*argv)[optind];
225     }
226
227   return true;
228 }
229
230 #define PIXBUF_NEW_FROM_FILE(FILE) \
231   gdk_pixbuf_new_from_file (relocate (PKGDATADIR "/" FILE), 0)
232
233
234 void
235 create_icon_factory (void)
236 {
237   GtkIconFactory *factory = gtk_icon_factory_new ();
238
239   GtkIconSet *icon_set;
240
241   GdkPixbuf *pixbuf;
242
243   pixbuf = PIXBUF_NEW_FROM_FILE ("value-labels.png");
244   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
245   g_object_unref (pixbuf);
246   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
247
248   pixbuf = PIXBUF_NEW_FROM_FILE ("weight-cases.png");
249   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
250   g_object_unref (pixbuf);
251   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
252
253   pixbuf = PIXBUF_NEW_FROM_FILE ("goto-variable.png");
254   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
255   g_object_unref (pixbuf);
256   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
257
258   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-variable.png");
259   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
260   g_object_unref (pixbuf);
261   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
262
263   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-case.png");
264   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
265   g_object_unref (pixbuf);
266   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
267
268   pixbuf = PIXBUF_NEW_FROM_FILE ("split-file.png");
269   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
270   g_object_unref (pixbuf);
271   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
272
273   pixbuf = PIXBUF_NEW_FROM_FILE ("select-cases.png");
274   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
275   g_object_unref (pixbuf);
276   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
277
278   pixbuf = PIXBUF_NEW_FROM_FILE ("recent-dialogs.png");
279   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
280   g_object_unref (pixbuf);
281   gtk_icon_factory_add ( factory, "pspp-recent-dialogs", icon_set);
282
283
284
285   gtk_icon_factory_add_default (factory);
286 }
287