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