3560dbf634e8f107a971fddf88e8740d11b9cd45
[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 int 
58 main(int argc, char *argv[]) 
59 {
60   PsppireVarStore *var_store ;
61   GtkWidget *data_editor ;
62   GtkSheet *var_sheet ; 
63   GtkSheet *data_sheet ;
64
65   gchar *filename=0;
66   GError *err = 0;
67
68   gtk_init(&argc, &argv);
69
70   /* gtk_init messes with the locale. 
71      So unset the bits we want to control ourselves */
72   setlocale (LC_NUMERIC, "C");
73
74   bindtextdomain (PACKAGE, locale_dir);
75   textdomain (PACKAGE);
76
77   if ( ! parse_command_line(&argc, &argv, &filename, &err) ) 
78     {
79       g_clear_error(&err);
80       return 1;
81     }
82
83   glade_init();
84
85
86   settings_init();
87
88   
89
90   /* 
91   set_pspp_locale("da_DK");
92   */
93
94   message_dialog_init();
95
96   the_dictionary = psppire_dict_new();
97
98   /* Create the model for the var_sheet */
99   var_store = psppire_var_store_new(the_dictionary);
100
101   /* Create the model for the data sheet */
102   the_cases = psppire_case_array_new(100000, 20);
103
104   data_store = psppire_data_store_new(the_dictionary, the_cases);
105
106   /* load the interface */
107   xml = glade_xml_new(PKGDATADIR "/psppire.glade", NULL, NULL);
108
109   if ( !xml ) return 1;
110
111   data_editor = get_widget_assert(xml, "data_editor");
112   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), 
113                                 PKGDATADIR "/psppicon.png",0);
114
115   /* connect the signals in the interface */
116   glade_xml_signal_autoconnect(xml);
117
118   var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
119   data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
120
121   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
122   
123   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
124
125   if (filename)
126     gtk_init_add((GtkFunction)load_system_file, filename);
127   else
128     gtk_init_add((GtkFunction)clear_file, 0);
129
130   var_data_selection_init();
131
132   /* start the event loop */
133   gtk_main();
134
135   message_dialog_done();
136
137   settings_done();
138
139   return 0;
140 }
141
142
143 /* Parses the command line specified by ARGC and ARGV as received by
144    main().  Returns true if normal execution should proceed,
145    false if the command-line indicates that PSPP should exit. */
146 static bool
147 parse_command_line (int *argc, char ***argv, gchar **filename, GError **err)
148 {
149   static struct option long_options[] =
150     {
151       {"help", no_argument, NULL, 'h'},
152       {"version", no_argument, NULL, 'V'},
153       {0, 0, 0, 0},
154     };
155
156   int c;
157
158   for (;;)
159     {
160       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
161       if (c == -1)
162         break;
163
164       switch (c)
165         {
166         case 'h':
167           g_printerr("Usage: psppire {|--help|--version}\n");
168           return false;
169         case 'V':
170           g_print(version);
171           g_print("\n");
172           g_print(legal);
173           return false;
174         default:
175           return false;
176         }
177     }
178
179   if ( optind < *argc) 
180     {
181       *filename = (*argv)[optind];
182     }
183
184   return true;
185 }