Applied patch #5653, which adds callbacks to dataset whenever its dictionary or
[pspp] / 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
26 #include "data-editor.h"
27 #include <libpspp/version.h>
28 #include <libpspp/copyleft.h>
29 #include <data/file-handle-def.h>
30 #include <data/format.h>
31 #include <data/storage-stream.h>
32 #include <data/settings.h>
33 #include <data/file-name.h>
34 #include <data/procedure.h>
35 #include <libpspp/getl.h>
36 #include <language/lexer/lexer.h>
37 #include <ui/flexifile.h>
38
39 #include <getopt.h>
40 #include <gtk/gtk.h>
41 #include <gtk/gtk.h>
42 #include <glade/glade.h>
43 #include "psppire-dict.h"
44 #include "psppire-var-store.h"
45 #include "psppire-data-store.h"
46 #include "helper.h"
47 #include "data-sheet.h"
48 #include "var-sheet.h"
49 #include "message-dialog.h"
50 #include "flexifile-factory.h"
51
52 PsppireDataStore *the_data_store = 0;
53
54
55 static bool parse_command_line (int *argc, char ***argv,
56                                 gchar **filename, GError **err);
57
58
59 PsppireVarStore *the_var_store = 0;
60
61 void create_icon_factory (void);
62
63 struct source_stream *the_source_stream ;
64 struct dataset * the_dataset = NULL;
65
66 static void
67 replace_dictionary (struct dictionary *d)
68 {
69   psppire_dict_replace_dictionary (the_data_store->dict,
70                                    d);
71 }
72
73
74 static void
75 replace_flexifile (struct case_source *s)
76 {
77   if ( NULL == s )
78     psppire_case_file_replace_flexifile (the_data_store->case_file,
79                                          (struct flexifile *) flexifile_create (0));
80   else
81     psppire_case_file_replace_flexifile (the_data_store->case_file,
82                                          (struct flexifile *)
83                                          storage_source_get_casefile (s));
84 }
85
86
87 int
88 main (int argc, char *argv[])
89 {
90   struct casefile_factory *factory;
91   PsppireDict *dictionary = 0;
92
93
94   gchar *filename=0;
95   GError *err = 0;
96   gchar *vers;
97
98   gtk_init (&argc, &argv);
99   if ( (vers = gtk_check_version (GTK_MAJOR_VERSION,
100                                  GTK_MINOR_VERSION,
101                                  GTK_MICRO_VERSION)) )
102     {
103       g_critical (vers);
104     }
105
106
107   /* gtk_init messes with the locale.
108      So unset the bits we want to control ourselves */
109   setlocale (LC_NUMERIC, "C");
110
111   bindtextdomain (PACKAGE, locale_dir);
112
113   textdomain (PACKAGE);
114
115   if ( ! parse_command_line (&argc, &argv, &filename, &err) )
116     {
117       g_clear_error (&err);
118       return 0;
119     }
120
121   glade_init ();
122
123   fmt_init ();
124   settings_init ();
125   fh_init ();
126   factory = flexifile_factory_create ();
127   the_source_stream = create_source_stream (
128                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
129                           );
130
131   the_dataset = create_dataset (factory,
132                                 replace_flexifile,
133                                 replace_dictionary);
134
135   message_dialog_init (the_source_stream);
136
137   dictionary = psppire_dict_new_from_dict (
138                                            dataset_dict (the_dataset)
139                                            );
140
141   bind_textdomain_codeset (PACKAGE, "UTF-8");
142
143   /* Create the model for the var_sheet */
144   the_var_store = psppire_var_store_new (dictionary);
145
146
147   the_data_store = psppire_data_store_new (dictionary);
148
149   proc_set_source (the_dataset,
150                    storage_source_create (the_data_store->case_file->flexifile)
151                    );
152
153   create_icon_factory ();
154
155   new_data_window (NULL, NULL);
156
157   /* start the event loop */
158   gtk_main ();
159
160   destroy_source_stream (the_source_stream);
161   message_dialog_done ();
162
163   settings_done ();
164
165   return 0;
166 }
167
168
169 /* Parses the command line specified by ARGC and ARGV as received by
170    main ().  Returns true if normal execution should proceed,
171    false if the command-line indicates that PSPP should exit. */
172 static bool
173 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
174 {
175   static struct option long_options[] =
176     {
177       {"help", no_argument, NULL, 'h'},
178       {"version", no_argument, NULL, 'V'},
179       {0, 0, 0, 0},
180     };
181
182   int c;
183
184   for (;;)
185     {
186       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
187       if (c == -1)
188         break;
189
190       switch (c)
191         {
192         case 'h':
193           g_print ("Usage: psppire {|--help|--version}\n");
194           return false;
195         case 'V':
196           g_print (version);
197           g_print ("\n");
198           g_print (legal);
199           return false;
200         default:
201           return false;
202         }
203     }
204
205   if ( optind < *argc)
206     {
207       *filename = (*argv)[optind];
208     }
209
210   return true;
211 }
212
213
214
215 void
216 create_icon_factory (void)
217 {
218   GtkIconFactory *factory = gtk_icon_factory_new ();
219
220   GtkIconSet *icon_set;
221
222   GdkPixbuf *pixbuf;
223
224   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/value-labels.png", 0);
225   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
226   g_object_unref (pixbuf);
227   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
228
229   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/weight-cases.png", 0);
230   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
231   g_object_unref (pixbuf);
232   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
233
234   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/goto-variable.png", 0);
235   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
236   g_object_unref (pixbuf);
237   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
238
239   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-variable.png", 0);
240   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
241   g_object_unref (pixbuf);
242   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
243
244   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-case.png", 0);
245   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
246   g_object_unref (pixbuf);
247   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
248
249   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/split-file.png", 0);
250   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
251   g_object_unref (pixbuf);
252   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
253
254   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/select-cases.png", 0);
255   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
256   g_object_unref (pixbuf);
257   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
258
259   gtk_icon_factory_add_default (factory);
260 }
261
262
263