1f510e24cdf90e180579502ed24b46f0de043b96
[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    Written by John Darrington
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA. */
20
21 #include <config.h>
22
23 #include <assert.h>
24 #include <libintl.h>
25
26 #include <libpspp/version.h>
27 #include <libpspp/copyleft.h>
28 #include <data/settings.h>
29
30 #include <getopt.h>
31 #include <gtk/gtk.h>
32 #include <gtk/gtk.h>
33 #include <glade/glade.h>
34 #include "menu-actions.h"
35 #include "psppire-dict.h"
36 #include "psppire-var-store.h"
37 #include "psppire-data-store.h"
38 #include "helper.h"
39 #include "data-sheet.h"
40 #include "var-sheet.h"
41 #include "message-dialog.h"
42
43 GladeXML *xml;
44
45
46 PsppireDict *the_dictionary = 0;
47
48 PsppireDataStore *data_store = 0;
49
50
51 static bool parse_command_line (int *argc, char ***argv, 
52                                 gchar **filename, GError **err);
53
54
55 #define _(msgid) gettext (msgid)
56 #define N_(msgid) msgid
57
58 static void
59 give_help(void)
60 {
61   static struct msg m = {
62     MSG_GENERAL, 
63     MSG_NOTE,
64     {0, -1},
65     0, 
66   };
67
68   if (! m.text) 
69     m.text=g_strdup(_("Sorry. The help system hasn't yet been implemented."));
70
71   popup_message(&m);
72 }
73
74 PsppireVarStore *var_store = 0;
75
76 void create_icon_factory (void);
77
78 int 
79 main(int argc, char *argv[]) 
80 {
81
82   GtkWidget *data_editor ;
83   GtkSheet *var_sheet ; 
84   GtkSheet *data_sheet ;
85
86   gchar *filename=0;
87   GError *err = 0;
88   gchar *vers;
89
90   gtk_init(&argc, &argv);
91   if ( (vers = gtk_check_version(GTK_MAJOR_VERSION, 
92                                  GTK_MINOR_VERSION, 
93                                  GTK_MICRO_VERSION)) )
94     {
95       g_critical(vers);
96     }
97         
98
99   /* gtk_init messes with the locale. 
100      So unset the bits we want to control ourselves */
101   setlocale (LC_NUMERIC, "C");
102
103   bindtextdomain (PACKAGE, locale_dir);
104
105   textdomain (PACKAGE);
106
107   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
108     {
109       g_clear_error(&err);
110       return 0;
111     }
112
113   glade_init();
114
115
116
117   settings_init();
118
119   message_dialog_init();
120
121   the_dictionary = psppire_dict_new();
122
123   bind_textdomain_codeset(PACKAGE, "UTF-8");
124
125   /* Create the model for the var_sheet */
126   var_store = psppire_var_store_new(the_dictionary);
127
128   data_store = psppire_data_store_new(the_dictionary);
129
130   create_icon_factory();
131
132   /* load the interface */
133   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
134
135   if ( !xml ) return 1;
136
137   data_editor = get_widget_assert(xml, "data_editor");
138   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), 
139                                 PKGDATADIR "/psppicon.png",0);
140
141   /* connect the signals in the interface */
142   glade_xml_signal_autoconnect(xml);
143
144   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
145   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
146
147   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
148   
149   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
150
151   if (filename)
152     gtk_init_add((GtkFunction)load_system_file, filename);
153   else
154     gtk_init_add((GtkFunction)clear_file, 0);
155
156   var_data_selection_init();
157
158   {
159   GList *helps = glade_xml_get_widget_prefix(xml, "help_button_");
160
161   GList *i;
162   for ( i = g_list_first(helps); i ; i = g_list_next(i))
163       g_signal_connect(GTK_WIDGET(i->data), "clicked", give_help, 0);
164   }
165
166
167   /* start the event loop */
168   gtk_main();
169
170   message_dialog_done();
171
172   settings_done();
173
174   return 0;
175 }
176
177
178 /* Parses the command line specified by ARGC and ARGV as received by
179    main().  Returns true if normal execution should proceed,
180    false if the command-line indicates that PSPP should exit. */
181 static bool
182 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
183 {
184   static struct option long_options[] =
185     {
186       {"help", no_argument, NULL, 'h'},
187       {"version", no_argument, NULL, 'V'},
188       {0, 0, 0, 0},
189     };
190
191   int c;
192
193   for (;;)
194     {
195       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
196       if (c == -1)
197         break;
198
199       switch (c)
200         {
201         case 'h':
202           g_print ("Usage: psppire {|--help|--version}\n");
203           return false;
204         case 'V':
205           g_print (version);
206           g_print ("\n");
207           g_print (legal);
208           return false;
209         default:
210           return false;
211         }
212     }
213
214   if ( optind < *argc) 
215     {
216       *filename = (*argv)[optind];
217     }
218
219   return true;
220 }
221
222
223
224 void 
225 create_icon_factory (void)
226 {
227   GtkIconFactory *factory = gtk_icon_factory_new();
228
229   GtkIconSet *icon_set;
230   
231   GdkPixbuf *pixbuf;
232
233   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/value-labels.png", 0);
234   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
235   g_object_unref (pixbuf);
236   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
237
238   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/weight-cases.png", 0);
239   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
240   g_object_unref (pixbuf);
241   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
242
243   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/goto-variable.png", 0);
244   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
245   g_object_unref (pixbuf);
246   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
247
248   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-variable.png", 0);
249   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
250   g_object_unref (pixbuf);
251   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
252
253   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/insert-case.png", 0);
254   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
255   g_object_unref (pixbuf);
256   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
257
258   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/split-file.png", 0);
259   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
260   g_object_unref (pixbuf);
261   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
262
263   pixbuf = gdk_pixbuf_new_from_file (PKGDATADIR "/select-cases.png", 0);
264   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
265   g_object_unref (pixbuf);
266   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
267
268   gtk_icon_factory_add_default (factory);
269 }