Implemented data-store using a casefile instead of an array of cases.
[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 int 
75 main(int argc, char *argv[]) 
76 {
77
78   GtkWidget *data_editor ;
79   GtkSheet *var_sheet ; 
80   GtkSheet *data_sheet ;
81
82   gchar *filename=0;
83   GError *err = 0;
84
85   gtk_init(&argc, &argv);
86
87   /* gtk_init messes with the locale. 
88      So unset the bits we want to control ourselves */
89   setlocale (LC_NUMERIC, "C");
90
91   bindtextdomain (PACKAGE, locale_dir);
92
93   textdomain (PACKAGE);
94
95   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
96     {
97       g_clear_error(&err);
98       return 1;
99     }
100
101
102   glade_init();
103
104
105   settings_init();
106
107   /* 
108   set_pspp_locale("da_DK");
109   */
110
111   message_dialog_init();
112
113   the_dictionary = psppire_dict_new();
114
115   bind_textdomain_codeset(PACKAGE, "UTF-8");
116
117   /* Create the model for the var_sheet */
118   var_store = psppire_var_store_new(the_dictionary);
119
120   data_store = psppire_data_store_new(the_dictionary);
121
122   /* load the interface */
123   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
124
125   if ( !xml ) return 1;
126
127   data_editor = get_widget_assert(xml, "data_editor");
128   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), 
129                                 PKGDATADIR "/psppicon.png",0);
130
131   /* connect the signals in the interface */
132   glade_xml_signal_autoconnect(xml);
133
134   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
135   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
136
137   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
138   
139   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
140
141   if (filename)
142     gtk_init_add((GtkFunction)load_system_file, filename);
143   else
144     gtk_init_add((GtkFunction)clear_file, 0);
145
146   var_data_selection_init();
147
148   {
149   GList *helps = glade_xml_get_widget_prefix(xml, "help_button_");
150
151   GList *i;
152   for ( i = g_list_first(helps); i ; i = g_list_next(i))
153       g_signal_connect(GTK_WIDGET(i->data), "clicked", give_help, 0);
154   }
155
156
157   /* start the event loop */
158   gtk_main();
159
160   message_dialog_done();
161
162   settings_done();
163
164   return 0;
165 }
166
167
168 /* Parses the command line specified by ARGC and ARGV as received by
169    main().  Returns true if normal execution should proceed,
170    false if the command-line indicates that PSPP should exit. */
171 static bool
172 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
173 {
174   static struct option long_options[] =
175     {
176       {"help", no_argument, NULL, 'h'},
177       {"version", no_argument, NULL, 'V'},
178       {0, 0, 0, 0},
179     };
180
181   int c;
182
183   for (;;)
184     {
185       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
186       if (c == -1)
187         break;
188
189       switch (c)
190         {
191         case 'h':
192           g_printerr("Usage: psppire {|--help|--version}\n");
193           return false;
194         case 'V':
195           g_print(version);
196           g_print("\n");
197           g_print(legal);
198           return false;
199         default:
200           return false;
201         }
202     }
203
204   if ( optind < *argc) 
205     {
206       *filename = (*argv)[optind];
207     }
208
209   return true;
210 }
211
212