Minor i18n 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 #include <assert.h>
23 #include <libintl.h>
24
25 #include <libpspp/version.h>
26 #include <libpspp/copyleft.h>
27 #include <data/settings.h>
28
29 #include <getopt.h>
30 #include <gtk/gtk.h>
31 #include <gtk/gtk.h>
32 #include <glade/glade.h>
33 #include "menu-actions.h"
34 #include "psppire-dict.h"
35 #include "psppire-var-store.h"
36 #include "psppire-data-store.h"
37
38 #include "helper.h"
39 #include "data-sheet.h"
40 #include "var-sheet.h"
41 #include "psppire-case-array.h"
42 #include "message-dialog.h"
43
44 GladeXML *xml;
45
46
47 PsppireDict *the_dictionary = 0;
48 PsppireCaseArray *the_cases = 0;
49
50
51 PsppireDataStore *data_store = 0;
52
53
54 static bool parse_command_line (int *argc, char ***argv, 
55                                 gchar **filename, GError **err);
56
57
58 #define _(msgid) gettext (msgid)
59 #define N_(msgid) msgid
60
61 static void
62 give_help(void)
63 {
64   static struct msg m = {
65     MSG_GENERAL, 
66     MSG_NOTE,
67     {0, -1},
68     0, 
69   };
70
71   if (! m.text) 
72     m.text=g_strdup(_("Sorry. The help system hasn't yet been implemented."));
73
74   popup_message(&m);
75 }
76
77 int 
78 main(int argc, char *argv[]) 
79 {
80   PsppireVarStore *var_store ;
81   GtkWidget *data_editor ;
82   GtkSheet *var_sheet ; 
83   GtkSheet *data_sheet ;
84
85   gchar *filename=0;
86   GError *err = 0;
87
88   gtk_init(&argc, &argv);
89
90   /* gtk_init messes with the locale. 
91      So unset the bits we want to control ourselves */
92   setlocale (LC_NUMERIC, "C");
93
94   bindtextdomain (PACKAGE, locale_dir);
95   textdomain (PACKAGE);
96
97   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
98     {
99       g_clear_error(&err);
100       return 1;
101     }
102
103   glade_init();
104
105
106   settings_init();
107
108   
109
110   /* 
111   set_pspp_locale("da_DK");
112   */
113
114   message_dialog_init();
115
116   the_dictionary = psppire_dict_new();
117
118   /* Create the model for the var_sheet */
119   var_store = psppire_var_store_new(the_dictionary);
120
121   /* Create the model for the data sheet */
122   the_cases = psppire_case_array_new(100000, 20);
123
124   data_store = psppire_data_store_new(the_dictionary, the_cases);
125
126   /* load the interface */
127   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
128
129   if ( !xml ) return 1;
130
131   data_editor = get_widget_assert(xml, "data_editor");
132   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), 
133                                 PKGDATADIR "/psppicon.png",0);
134
135   /* connect the signals in the interface */
136   glade_xml_signal_autoconnect(xml);
137
138   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
139   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
140
141   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
142   
143   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
144
145   if (filename)
146     gtk_init_add((GtkFunction)load_system_file, filename);
147   else
148     gtk_init_add((GtkFunction)clear_file, 0);
149
150   var_data_selection_init();
151
152   {
153   GList *helps = glade_xml_get_widget_prefix(xml, "help_button_");
154
155   GList *i;
156   for ( i = g_list_first(helps); i ; i = g_list_next(i))
157       g_signal_connect(GTK_WIDGET(i->data), "clicked", give_help, 0);
158   }
159
160
161   /* start the event loop */
162   gtk_main();
163
164   message_dialog_done();
165
166   settings_done();
167
168   return 0;
169 }
170
171
172 /* Parses the command line specified by ARGC and ARGV as received by
173    main().  Returns true if normal execution should proceed,
174    false if the command-line indicates that PSPP should exit. */
175 static bool
176 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
177 {
178   static struct option long_options[] =
179     {
180       {"help", no_argument, NULL, 'h'},
181       {"version", no_argument, NULL, 'V'},
182       {0, 0, 0, 0},
183     };
184
185   int c;
186
187   for (;;)
188     {
189       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
190       if (c == -1)
191         break;
192
193       switch (c)
194         {
195         case 'h':
196           g_printerr("Usage: psppire {|--help|--version}\n");
197           return false;
198         case 'V':
199           g_print(version);
200           g_print("\n");
201           g_print(legal);
202           return false;
203         default:
204           return false;
205         }
206     }
207
208   if ( optind < *argc) 
209     {
210       *filename = (*argv)[optind];
211     }
212
213   return true;
214 }
215
216