Removed my authorship lines.
[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 <libpspp/version.h>
26 #include <libpspp/copyleft.h>
27 #include <data/format.h>
28 #include <data/settings.h>
29 #include <data/file-name.h>
30 #include <libpspp/getl.h>
31
32 #include <getopt.h>
33 #include <gtk/gtk.h>
34 #include <gtk/gtk.h>
35 #include <glade/glade.h>
36 #include "menu-actions.h"
37 #include "psppire-dict.h"
38 #include "psppire-var-store.h"
39 #include "psppire-data-store.h"
40 #include "helper.h"
41 #include "data-sheet.h"
42 #include "var-sheet.h"
43 #include "message-dialog.h"
44
45 GladeXML *xml;
46
47
48 PsppireDict *the_dictionary = 0;
49
50 PsppireDataStore *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 *var_store = 0;
77
78 void create_icon_factory (void);
79
80 static struct source_stream *the_source_stream ;
81
82 int 
83 main(int argc, char *argv[]) 
84 {
85
86   GtkWidget *data_editor ;
87   GtkSheet *var_sheet ; 
88   GtkSheet *data_sheet ;
89
90   gchar *filename=0;
91   GError *err = 0;
92   gchar *vers;
93
94   gtk_init(&argc, &argv);
95   if ( (vers = gtk_check_version(GTK_MAJOR_VERSION, 
96                                  GTK_MINOR_VERSION, 
97                                  GTK_MICRO_VERSION)) )
98     {
99       g_critical(vers);
100     }
101         
102
103   /* gtk_init messes with the locale. 
104      So unset the bits we want to control ourselves */
105   setlocale (LC_NUMERIC, "C");
106
107   bindtextdomain (PACKAGE, locale_dir);
108
109   textdomain (PACKAGE);
110
111   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
112     {
113       g_clear_error(&err);
114       return 0;
115     }
116
117   glade_init();
118
119   fmt_init();
120   settings_init();
121   the_source_stream = create_source_stream (
122                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
123                           );
124
125   message_dialog_init (the_source_stream);
126
127   the_dictionary = psppire_dict_new();
128
129   bind_textdomain_codeset(PACKAGE, "UTF-8");
130
131   /* Create the model for the var_sheet */
132   var_store = psppire_var_store_new(the_dictionary);
133
134   data_store = psppire_data_store_new(the_dictionary);
135
136   create_icon_factory();
137
138   /* load the interface */
139   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
140
141   if ( !xml ) return 1;
142
143   data_editor = get_widget_assert(xml, "data_editor");
144   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor),
145                                 PKGDATADIR "/psppicon.png",0);
146
147   /* connect the signals in the interface */
148   glade_xml_signal_autoconnect(xml);
149
150   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
151   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
152
153   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
154
155   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
156
157   if (filename)
158     gtk_init_add((GtkFunction)load_system_file, filename);
159   else
160     gtk_init_add((GtkFunction)clear_file, 0);
161
162   var_data_selection_init();
163
164   {
165   GList *helps = glade_xml_get_widget_prefix(xml, "help_button_");
166
167   GList *i;
168   for ( i = g_list_first(helps); i ; i = g_list_next(i))
169       g_signal_connect(GTK_WIDGET(i->data), "clicked", give_help, 0);
170   }
171
172
173   /* start the event loop */
174   gtk_main();
175
176   destroy_source_stream (the_source_stream);
177   message_dialog_done();
178
179   settings_done();
180
181   return 0;
182 }
183
184
185 /* Parses the command line specified by ARGC and ARGV as received by
186    main().  Returns true if normal execution should proceed,
187    false if the command-line indicates that PSPP should exit. */
188 static bool
189 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
190 {
191   static struct option long_options[] =
192     {
193       {"help", no_argument, NULL, 'h'},
194       {"version", no_argument, NULL, 'V'},
195       {0, 0, 0, 0},
196     };
197
198   int c;
199
200   for (;;)
201     {
202       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
203       if (c == -1)
204         break;
205
206       switch (c)
207         {
208         case 'h':
209           g_print ("Usage: psppire {|--help|--version}\n");
210           return false;
211         case 'V':
212           g_print (version);
213           g_print ("\n");
214           g_print (legal);
215           return false;
216         default:
217           return false;
218         }
219     }
220
221   if ( optind < *argc) 
222     {
223       *filename = (*argv)[optind];
224     }
225
226   return true;
227 }
228
229
230
231 void 
232 create_icon_factory (void)
233 {
234   GtkIconFactory *factory = gtk_icon_factory_new();
235
236   GtkIconSet *icon_set;
237   
238   GdkPixbuf *pixbuf;
239
240   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/value-labels.png", 0);
241   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
242   g_object_unref (pixbuf);
243   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
244
245   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/weight-cases.png", 0);
246   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
247   g_object_unref (pixbuf);
248   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
249
250   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/goto-variable.png", 0);
251   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
252   g_object_unref (pixbuf);
253   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
254
255   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-variable.png", 0);
256   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
257   g_object_unref (pixbuf);
258   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
259
260   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-case.png", 0);
261   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
262   g_object_unref (pixbuf);
263   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
264
265   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/split-file.png", 0);
266   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
267   g_object_unref (pixbuf);
268   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
269
270   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/select-cases.png", 0);
271   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
272   g_object_unref (pixbuf);
273   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
274
275   gtk_icon_factory_add_default (factory);
276 }