Fixed a lot of internationalisation issues.
[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 /*
22  * Initial main.c file generated by Glade. Edit as required.
23  * Glade will not overwrite this file.
24  */
25
26 #include <assert.h>
27 #include <libintl.h>
28
29 #include <libpspp/version.h>
30 #include <libpspp/copyleft.h>
31 #include <getopt.h>
32 #include <gtk/gtk.h>
33 #include <gtk/gtk.h>
34 #include <glade/glade.h>
35 #include "menu-actions.h"
36 #include "psppire-dict.h"
37 #include "psppire-var-store.h"
38 #include "psppire-data-store.h"
39
40 #include "helper.h"
41 #include "data-sheet.h"
42 #include "var-sheet.h"
43 #include "psppire-case-array.h"
44 #include "message-dialog.h"
45
46 GladeXML *xml;
47
48
49 PsppireDict *the_dictionary = 0;
50 PsppireCaseArray *the_cases = 0;
51
52
53 PsppireDataStore *data_store = 0;
54
55
56 static bool parse_command_line (int *argc, char ***argv, 
57                                 gchar **filename, GError **err);
58
59 static void
60 i18n_init (void) 
61 {
62 #if ENABLE_NLS
63 #if HAVE_LC_MESSAGES
64   setlocale (LC_MESSAGES, "");
65 #endif
66   setlocale (LC_MONETARY, "");
67   bindtextdomain (PACKAGE, locale_dir);
68   textdomain (PACKAGE);
69 #endif /* ENABLE_NLS */
70 }
71
72
73 int 
74 main(int argc, char *argv[]) 
75 {
76   PsppireVarStore *var_store ;
77   GtkWidget *data_editor ;
78   GtkSheet *var_sheet ; 
79   GtkSheet *data_sheet ;
80
81   gchar *filename=0;
82   GError *err = 0;
83
84   gtk_init(&argc, &argv);
85
86   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
87     {
88       g_clear_error(&err);
89       return 1;
90     }
91
92
93   glade_init();
94
95   i18n_init();
96
97   message_dialog_init();
98
99   the_dictionary = psppire_dict_new();
100
101   /* Create the model for the var_sheet */
102   var_store = psppire_var_store_new(the_dictionary);
103
104   /* Create the model for the data sheet */
105   the_cases = psppire_case_array_new(100000, 20);
106
107   data_store = psppire_data_store_new(the_dictionary, the_cases);
108
109   /* load the interface */
110   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
111
112   if ( !xml ) return 1;
113
114   data_editor = get_widget_assert(xml, "data_editor");
115   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), 
116                                 PKGDATADIR "/psppicon.png",0);
117
118   /* connect the signals in the interface */
119   glade_xml_signal_autoconnect(xml);
120
121   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
122   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
123
124   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
125   
126   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
127
128   gtk_init_add(callbacks_on_init, 0);
129
130   if (filename)
131     gtk_init_add((GtkFunction)load_system_file, filename);
132
133   /* start the event loop */
134   gtk_main();
135
136   message_dialog_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_printerr("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 }