Oops
[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/format.h>
34 #include <data/settings.h>
35 #include <data/file-name.h>
36 #include <data/procedure.h>
37 #include <libpspp/getl.h>
38 #include <language/lexer/lexer.h>
39 #include <libpspp/version.h>
40 #include <output/output.h>
41 #include <output/journal.h>
42
43 #include <gtk/gtk.h>
44 #include <glade/glade.h>
45 #include "psppire-dict.h"
46 #include "psppire-var-store.h"
47 #include "psppire-data-store.h"
48 #include "helper.h"
49 #include "data-sheet.h"
50 #include "var-sheet.h"
51 #include "message-dialog.h"
52
53 #include "output-viewer.h"
54
55 PsppireDataStore *the_data_store = 0;
56 PsppireVarStore *the_var_store = 0;
57
58 static void create_icon_factory (void);
59
60 struct source_stream *the_source_stream ;
61 struct dataset * the_dataset = NULL;
62
63
64 static void
65 replace_casereader (struct casereader *s)
66 {
67   PsppireCaseFile *pcf = psppire_case_file_new (s);
68
69   psppire_data_store_set_case_file (the_data_store, pcf);
70 }
71
72 #define _(msgid) gettext (msgid)
73 #define N_(msgid) msgid
74
75
76 void
77 initialize (void)
78 {
79   PsppireDict *dictionary = 0;
80
81   /* gtk_init messes with the locale.
82      So unset the bits we want to control ourselves */
83   setlocale (LC_NUMERIC, "C");
84
85   bindtextdomain (PACKAGE, locale_dir);
86
87
88   glade_init ();
89
90   gsl_set_error_handler_off ();
91   fmt_init ();
92   fn_init ();
93   outp_init ();
94   settings_init (&viewer_width, &viewer_length);
95   fh_init ();
96   the_source_stream =
97     create_source_stream (
98                           fn_getenv_default ("STAT_INCLUDE_PATH", include_path)
99                           );
100
101   the_dataset = create_dataset ();
102
103
104   message_dialog_init (the_source_stream);
105
106   dictionary = psppire_dict_new_from_dict (dataset_dict (the_dataset));
107
108   bind_textdomain_codeset (PACKAGE, "UTF-8");
109
110   /* Create the model for the var_sheet */
111   the_var_store = psppire_var_store_new (dictionary);
112
113   the_data_store = psppire_data_store_new (dictionary);
114   replace_casereader (NULL);
115
116   create_icon_factory ();
117
118   outp_configure_driver_line (
119     ss_cstr ("gui:ascii:screen:squeeze=on headers=off top-margin=0 "
120              "bottom-margin=0 paginate=off length=auto width=auto "
121              "emphasis=none "
122              "output-file=\"" OUTPUT_FILE_NAME "\" append=yes"));
123
124   unlink (OUTPUT_FILE_NAME);
125
126   journal_enable ();
127   textdomain (PACKAGE);
128
129   new_data_window (NULL, NULL);
130 }
131
132
133 void
134 de_initialize (void)
135 {
136   destroy_source_stream (the_source_stream);
137   message_dialog_done ();
138   settings_done ();
139   outp_done ();
140 }
141
142
143
144 struct icon_info
145 {
146   const char *file_name;
147   const gchar *id;
148 };
149
150
151 static const struct icon_info icons[] =
152   {
153     {PKGDATADIR "/value-labels.png",    "pspp-value-labels"},
154     {PKGDATADIR "/weight-cases.png",    "pspp-weight-cases"},
155     {PKGDATADIR "/goto-variable.png",   "pspp-goto-variable"},
156     {PKGDATADIR "/insert-variable.png", "pspp-insert-variable"},
157     {PKGDATADIR "/insert-case.png",     "pspp-insert-case"},
158     {PKGDATADIR "/split-file.png",      "pspp-split-file"},
159     {PKGDATADIR "/select-cases.png",    "pspp-select-cases"},
160     {PKGDATADIR "/recent-dialogs.png",  "pspp-recent-dialogs"},
161     {PKGDATADIR "/nominal.png",         "var-nominal"},
162     {PKGDATADIR "/ordinal.png",         "var-ordinal"},
163     {PKGDATADIR "/scale.png",           "var-scale"},
164     {PKGDATADIR "/string.png",          "var-string"},
165     {PKGDATADIR "/date-scale.png",      "var-date-scale"}
166   };
167
168 static void
169 create_icon_factory (void)
170 {
171   gint i;
172   GtkIconFactory *factory = gtk_icon_factory_new ();
173
174   for (i = 0 ; i < sizeof (icons) / sizeof(icons[0]); ++i)
175     {
176       GError *err = NULL;
177       GdkPixbuf *pixbuf =
178         gdk_pixbuf_new_from_file (relocate (icons[i].file_name), &err);
179
180       if ( pixbuf )
181         {
182           GtkIconSet *icon_set = gtk_icon_set_new_from_pixbuf (pixbuf);
183           g_object_unref (pixbuf);
184           gtk_icon_factory_add ( factory, icons[i].id, icon_set);
185         }
186       else
187         {
188           g_warning ("Cannot create icon: %s", err->message);
189           g_clear_error (&err);
190         }
191     }
192
193
194   {
195     /* Create our own "pspp-stock-reset" item, using the
196        GTK_STOCK_REFRESH icon set */
197
198     GtkStockItem items[] = {
199       {"pspp-stock-reset", N_("_Reset"), 0, 0, PACKAGE},
200       {"pspp-stock-select", N_("_Select"), 0, 0, PACKAGE}
201     };
202
203
204     gtk_stock_add (items, 2);
205     gtk_icon_factory_add (factory, "pspp-stock-reset", 
206                           gtk_icon_factory_lookup_default (GTK_STOCK_REFRESH)
207                           );
208
209     gtk_icon_factory_add (factory, "pspp-stock-select", 
210                           gtk_icon_factory_lookup_default (GTK_STOCK_INDEX)
211                           );
212   }
213
214   gtk_icon_factory_add_default (factory);
215 }
216