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