Added a basic output viewer.
[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 <assert.h>
20 #include <libintl.h>
21
22 #include "relocatable.h"
23
24 #include "data-editor.h"
25 #include "psppire.h"
26
27 #include <unistd.h>
28 #include <data/casereader.h>
29 #include <data/datasheet.h>
30 #include <data/file-handle-def.h>
31 #include <data/format.h>
32 #include <data/settings.h>
33 #include <data/file-name.h>
34 #include <data/procedure.h>
35 #include <libpspp/getl.h>
36 #include <language/lexer/lexer.h>
37 #include <libpspp/version.h>
38 #include <output/output.h>
39
40 #include <gtk/gtk.h>
41 #include <glade/glade.h>
42 #include "psppire-dict.h"
43 #include "psppire-var-store.h"
44 #include "psppire-data-store.h"
45 #include "helper.h"
46 #include "data-sheet.h"
47 #include "var-sheet.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 void
70 initialize (void)
71 {
72   PsppireDict *dictionary = 0;
73
74   /* gtk_init messes with the locale.
75      So unset the bits we want to control ourselves */
76   setlocale (LC_NUMERIC, "C");
77
78   bindtextdomain (PACKAGE, locale_dir);
79
80   textdomain (PACKAGE);
81
82   glade_init ();
83
84   fmt_init ();
85   fn_init ();
86   outp_init ();
87   settings_init ();
88   fh_init ();
89   the_source_stream =
90     create_source_stream (
91                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
92                           );
93
94   the_dataset = create_dataset (NULL, NULL);
95
96
97   message_dialog_init (the_source_stream);
98
99   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
100
101   bind_textdomain_codeset (PACKAGE, "UTF-8");
102
103   /* Create the model for the var_sheet */
104   the_var_store = psppire_var_store_new (dictionary);
105
106   the_data_store = psppire_data_store_new (dictionary);
107   replace_casereader (NULL);
108
109   create_icon_factory ();
110
111   outp_configure_driver_line (
112     ss_cstr ("gui:ascii:screen:squeeze=on headers=off top-margin=0 "
113              "bottom-margin=0 paginate=off length=50 "
114              "width=" OUTPUT_LINE_WIDTH_str " emphasis=none "
115              "output-file=\"" OUTPUT_FILE_NAME "\" append=yes"));
116
117   unlink (OUTPUT_FILE_NAME);
118
119   new_data_window (NULL, NULL);
120 }
121
122
123 void
124 de_initialize (void)
125 {
126   destroy_source_stream (the_source_stream);
127   message_dialog_done ();
128   settings_done ();
129   outp_done ();
130 }
131
132
133 #define PIXBUF_NEW_FROM_FILE(FILE) \
134   gdk_pixbuf_new_from_file (relocate (PKGDATADIR "/" FILE), 0)
135
136
137 static void
138 create_icon_factory (void)
139 {
140   GtkIconFactory *factory = gtk_icon_factory_new ();
141
142   GtkIconSet *icon_set;
143
144   GdkPixbuf *pixbuf;
145
146   pixbuf = PIXBUF_NEW_FROM_FILE ("value-labels.png");
147   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
148   g_object_unref (pixbuf);
149   gtk_icon_factory_add ( factory, "pspp-value-labels", icon_set);
150
151   pixbuf = PIXBUF_NEW_FROM_FILE ("weight-cases.png");
152   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
153   g_object_unref (pixbuf);
154   gtk_icon_factory_add ( factory, "pspp-weight-cases", icon_set);
155
156   pixbuf = PIXBUF_NEW_FROM_FILE ("goto-variable.png");
157   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
158   g_object_unref (pixbuf);
159   gtk_icon_factory_add ( factory, "pspp-goto-variable", icon_set);
160
161   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-variable.png");
162   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
163   g_object_unref (pixbuf);
164   gtk_icon_factory_add ( factory, "pspp-insert-variable", icon_set);
165
166   pixbuf = PIXBUF_NEW_FROM_FILE ("insert-case.png");
167   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
168   g_object_unref (pixbuf);
169   gtk_icon_factory_add ( factory, "pspp-insert-case", icon_set);
170
171   pixbuf = PIXBUF_NEW_FROM_FILE ("split-file.png");
172   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
173   g_object_unref (pixbuf);
174   gtk_icon_factory_add ( factory, "pspp-split-file", icon_set);
175
176   pixbuf = PIXBUF_NEW_FROM_FILE ("select-cases.png");
177   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
178   g_object_unref (pixbuf);
179   gtk_icon_factory_add ( factory, "pspp-select-cases", icon_set);
180
181   pixbuf = PIXBUF_NEW_FROM_FILE ("recent-dialogs.png");
182   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
183   g_object_unref (pixbuf);
184   gtk_icon_factory_add ( factory, "pspp-recent-dialogs", icon_set);
185
186   pixbuf = PIXBUF_NEW_FROM_FILE ("nominal.png");
187   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
188   g_object_unref (pixbuf);
189   gtk_icon_factory_add ( factory, "var-nominal", icon_set);
190
191   pixbuf = PIXBUF_NEW_FROM_FILE ("ordinal.png");
192   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
193   g_object_unref (pixbuf);
194   gtk_icon_factory_add ( factory, "var-ordinal", icon_set);
195
196   pixbuf = PIXBUF_NEW_FROM_FILE ("scale.png");
197   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
198   g_object_unref (pixbuf);
199   gtk_icon_factory_add ( factory, "var-scale", icon_set);
200
201   pixbuf = PIXBUF_NEW_FROM_FILE ("string.png");
202   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
203   g_object_unref (pixbuf);
204   gtk_icon_factory_add ( factory, "var-string", icon_set);
205
206   pixbuf = PIXBUF_NEW_FROM_FILE ("date-scale.png");
207   icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
208   g_object_unref (pixbuf);
209   gtk_icon_factory_add ( factory, "var-date-scale", icon_set);
210
211
212   gtk_icon_factory_add_default (factory);
213 }
214