Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / gui / psppire.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2004, 2005, 2006  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <locale.h>
20 #include <assert.h>
21 #include <libintl.h>
22 #include <gsl/gsl_errno.h>
23
24 #include "relocatable.h"
25
26 #include "data-editor.h"
27 #include "psppire.h"
28
29 #include <unistd.h>
30 #include <data/casereader.h>
31 #include <data/datasheet.h>
32 #include <data/file-handle-def.h>
33 #include <data/settings.h>
34 #include <data/file-name.h>
35 #include <data/procedure.h>
36 #include <libpspp/getl.h>
37 #include <language/lexer/lexer.h>
38 #include <libpspp/version.h>
39 #include <output/output.h>
40 #include <output/journal.h>
41
42 #include <gtk/gtk.h>
43 #include <glade/glade.h>
44 #include "psppire-dict.h"
45 #include "psppire-var-store.h"
46 #include "psppire-data-store.h"
47 #include "helper.h"
48 #include "message-dialog.h"
49
50 #include "output-viewer.h"
51
52 PsppireDataStore *the_data_store = 0;
53 PsppireVarStore *the_var_store = 0;
54
55 static void create_icon_factory (void);
56
57 struct source_stream *the_source_stream ;
58 struct dataset * the_dataset = NULL;
59
60
61 static void
62 replace_casereader (struct casereader *s)
63 {
64   PsppireCaseFile *pcf = psppire_case_file_new (s);
65
66   psppire_data_store_set_case_file (the_data_store, pcf);
67 }
68
69 #define _(msgid) gettext (msgid)
70 #define N_(msgid) msgid
71
72
73 void
74 initialize (void)
75 {
76   PsppireDict *dictionary = 0;
77
78   /* gtk_init messes with the locale.
79      So unset the bits we want to control ourselves */
80   setlocale (LC_NUMERIC, "C");
81
82   bindtextdomain (PACKAGE, locale_dir);
83
84
85   glade_init ();
86
87   gsl_set_error_handler_off ();
88   fn_init ();
89   outp_init ();
90   settings_init (&viewer_width, &viewer_length);
91   fh_init ();
92   the_source_stream =
93     create_source_stream (
94                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
95                           );
96
97   the_dataset = create_dataset ();
98
99
100   message_dialog_init (the_source_stream);
101
102   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
103
104   bind_textdomain_codeset (PACKAGE, "UTF-8");
105
106   /* Create the model for the var_sheet */
107   the_var_store = psppire_var_store_new (dictionary);
108
109   the_data_store = psppire_data_store_new (dictionary);
110   replace_casereader (NULL);
111
112   create_icon_factory ();
113
114   {
115     const char *filename = output_file_name ();
116
117     struct string config_string;
118
119     ds_init_empty (&config_string);
120
121     ds_put_format (&config_string,
122                    "gui:ascii:screen:squeeze=on headers=off top-margin=0 "
123                    "bottom-margin=0 paginate=off length=auto width=auto "
124                    "emphasis=none "
125                    "output-file=\"%s\" append=yes", filename);
126
127     outp_configure_driver_line (ds_ss (&config_string));
128
129     unlink (filename);
130
131     ds_destroy (&config_string);
132   }
133
134   journal_enable ();
135   textdomain (PACKAGE);
136
137   new_data_window (NULL, NULL);
138 }
139
140
141 void
142 de_initialize (void)
143 {
144   destroy_source_stream (the_source_stream);
145   message_dialog_done ();
146   settings_done ();
147   outp_done ();
148 }
149
150
151
152 struct icon_info
153 {
154   const char *file_name;
155   const gchar *id;
156 };
157
158
159 static const struct icon_info icons[] =
160   {
161     {PKGDATADIR "/value-labels.png",    "pspp-value-labels"},
162     {PKGDATADIR "/weight-cases.png",    "pspp-weight-cases"},
163     {PKGDATADIR "/goto-variable.png",   "pspp-goto-variable"},
164     {PKGDATADIR "/insert-variable.png", "pspp-insert-variable"},
165     {PKGDATADIR "/insert-case.png",     "pspp-insert-case"},
166     {PKGDATADIR "/split-file.png",      "pspp-split-file"},
167     {PKGDATADIR "/select-cases.png",    "pspp-select-cases"},
168     {PKGDATADIR "/recent-dialogs.png",  "pspp-recent-dialogs"},
169     {PKGDATADIR "/nominal.png",         "var-nominal"},
170     {PKGDATADIR "/ordinal.png",         "var-ordinal"},
171     {PKGDATADIR "/scale.png",           "var-scale"},
172     {PKGDATADIR "/string.png",          "var-string"},
173     {PKGDATADIR "/date-scale.png",      "var-date-scale"}
174   };
175
176 static void
177 create_icon_factory (void)
178 {
179   gint i;
180   GtkIconFactory *factory = gtk_icon_factory_new ();
181
182   for (i = 0 ; i < sizeof (icons) / sizeof(icons[0]); ++i)
183     {
184       GError *err = NULL;
185       GdkPixbuf *pixbuf =
186         gdk_pixbuf_new_from_file (relocate (icons[i].file_name), &err);
187
188       if ( pixbuf )
189         {
190           GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
191           g_object_unref (pixbuf);
192           gtk_icon_factory_add ( factory, icons[i].id, icon_set);
193         }
194       else
195         {
196           g_warning ("Cannot create icon: %s", err->message);
197           g_clear_error (&err);
198         }
199     }
200
201   {
202     /* Create our own "pspp-stock-reset" item, using the
203        GTK_STOCK_REFRESH icon set */
204
205     GtkStockItem items[] = {
206       {"pspp-stock-reset", N_("_Reset"), 0, 0, PACKAGE},
207       {"pspp-stock-select", N_("_Select"), 0, 0, PACKAGE}
208     };
209
210
211     gtk_stock_add (items, 2);
212     gtk_icon_factory_add (factory, "pspp-stock-reset", 
213                           gtk_icon_factory_lookup_default (GTK_STOCK_REFRESH)
214                           );
215
216     gtk_icon_factory_add (factory, "pspp-stock-select", 
217                           gtk_icon_factory_lookup_default (GTK_STOCK_INDEX)
218                           );
219   }
220
221   gtk_icon_factory_add_default (factory);
222 }
223