218f9249b4596dd8d24a9271b14ff734e049eadb
[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 #define _(msgid) gettext (msgid)
58 #define N_(msgid) msgid
59
60 static void
61 give_help (void)
62 {
63   static struct msg m = {
64     MSG_GENERAL,
65     MSG_NOTE,
66     {0, -1},
67     0,
68   };
69
70   if (! m.text)
71     m.text=g_strdup (_("Sorry. The help system hasn't yet been implemented."));
72
73   popup_message (&m);
74 }
75
76 PsppireVarStore *the_var_store = 0;
77
78 void create_icon_factory (void);
79
80 struct source_stream *the_source_stream ;
81 struct dataset * the_dataset = NULL;
82
83
84 int
85 main (int argc, char *argv[])
86 {
87   struct casefile_factory *factory;
88   PsppireDict *dictionary = 0;
89
90
91   gchar *filename=0;
92   GError *err = 0;
93   gchar *vers;
94
95   gtk_init (&argc, &argv);
96   if ( (vers = gtk_check_version (GTK_MAJOR_VERSION,
97                                  GTK_MINOR_VERSION,
98                                  GTK_MICRO_VERSION)) )
99     {
100       g_critical (vers);
101     }
102
103
104   /* gtk_init messes with the locale.
105      So unset the bits we want to control ourselves */
106   setlocale (LC_NUMERIC, "C");
107
108   bindtextdomain (PACKAGE, locale_dir);
109
110   textdomain (PACKAGE);
111
112   if ( ! parse_command_line (&argc, &argv, &filename, &err) )
113     {
114       g_clear_error (&err);
115       return 0;
116     }
117
118   glade_init ();
119
120   fmt_init ();
121   settings_init ();
122   fh_init ();
123   factory = flexifile_factory_create ();
124   the_source_stream = create_source_stream (
125                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
126                           );
127
128   the_dataset = create_dataset (factory);
129
130   message_dialog_init (the_source_stream);
131
132   dictionary =
133     psppire_dict_new_from_dict (
134                                 dataset_dict (the_dataset)
135                                 );
136
137   bind_textdomain_codeset (PACKAGE, "UTF-8");
138
139   /* Create the model for the var_sheet */
140   the_var_store = psppire_var_store_new (dictionary);
141
142
143   the_data_store = psppire_data_store_new (dictionary);
144
145   create_icon_factory ();
146
147 #if 0
148   /* load the interface */
149   data_editor_xml = glade_xml_new (PKGDATADIR "/data-editor.glade", NULL, NULL);
150
151   if ( !data_editor_xml ) return 1;
152
153   data_editor = get_widget_assert (data_editor_xml, "data_editor");
154
155   /* connect the signals in the interface */
156   glade_xml_signal_autoconnect (data_editor_xml);
157
158   var_sheet  = GTK_SHEET(get_widget_assert (data_editor_xml, "variable_sheet"));
159   data_sheet = GTK_SHEET(get_widget_assert (data_editor_xml, "data_sheet"));
160
161   gtk_sheet_set_model (var_sheet, G_SHEET_MODEL(the_var_store));
162
163   gtk_sheet_set_model (data_sheet, G_SHEET_MODEL(the_data_store));
164
165   var_data_selection_init ();
166
167   {
168   GList *helps = glade_xml_get_widget_prefix (data_editor_xml, "help_button_");
169
170   GList *i;
171   for ( i = g_list_first (helps); i ; i = g_list_next (i))
172       g_signal_connect (GTK_WIDGET(i->data), "clicked", give_help, 0);
173   }
174
175 #endif
176
177   new_data_window (NULL, NULL);
178
179   /* start the event loop */
180   gtk_main ();
181
182   destroy_source_stream (the_source_stream);
183   message_dialog_done ();
184
185   settings_done ();
186
187   return 0;
188 }
189
190
191 /* Parses the command line specified by ARGC and ARGV as received by
192    main ().  Returns true if normal execution should proceed,
193    false if the command-line indicates that PSPP should exit. */
194 static bool
195 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
196 {
197   static struct option long_options[] =
198     {
199       {"help", no_argument, NULL, 'h'},
200       {"version", no_argument, NULL, 'V'},
201       {0, 0, 0, 0},
202     };
203
204   int c;
205
206   for (;;)
207     {
208       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
209       if (c == -1)
210         break;
211
212       switch (c)
213         {
214         case 'h':
215           g_print ("Usage: psppire {|--help|--version}\n");
216           return false;
217         case 'V':
218           g_print (version);
219           g_print ("\n");
220           g_print (legal);
221           return false;
222         default:
223           return false;
224         }
225     }
226
227   if ( optind < *argc)
228     {
229       *filename = (*argv)[optind];
230     }
231
232   return true;
233 }
234
235
236
237 void
238 create_icon_factory (void)
239 {
240   GtkIconFactory *factory = gtk_icon_factory_new ();
241
242   GtkIconSet *icon_set;
243
244   GdkPixbuf *pixbuf;
245
246   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/value-labels.png", 0);
247   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
248   g_object_unref (pixbuf);
249   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
250
251   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/weight-cases.png", 0);
252   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
253   g_object_unref (pixbuf);
254   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
255
256   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/goto-variable.png", 0);
257   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
258   g_object_unref (pixbuf);
259   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
260
261   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-variable.png", 0);
262   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
263   g_object_unref (pixbuf);
264   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
265
266   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-case.png", 0);
267   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
268   g_object_unref (pixbuf);
269   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
270
271   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/split-file.png", 0);
272   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
273   g_object_unref (pixbuf);
274   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
275
276   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/select-cases.png", 0);
277   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
278   g_object_unref (pixbuf);
279   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
280
281   gtk_icon_factory_add_default (factory);
282 }