Fixed bug reporting the significance of paired value t-test.
[pspp-builds.git] / src / ui / gui / main.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 #include <gtk/gtk.h>
19 #include "psppire.h"
20 #include "progname.h"
21 #include <stdlib.h>
22 #include <getopt.h>
23 #include <gl/relocatable.h>
24
25 #include <libpspp/version.h>
26 #include <libpspp/copyleft.h>
27
28 static gboolean parse_command_line (int *argc, char ***argv, gchar **filename,
29                                     gboolean *show_splash, GError **err);
30
31
32
33 static GtkWidget *
34 create_splash_window (void)
35 {
36   GtkWidget *splash ;
37   GtkWidget *image;
38
39   gtk_window_set_auto_startup_notification (FALSE);
40
41   splash = gtk_window_new (GTK_WINDOW_POPUP);
42
43   gtk_window_set_position (GTK_WINDOW (splash),
44                            GTK_WIN_POS_CENTER_ALWAYS);
45
46   gtk_window_set_type_hint (GTK_WINDOW (splash),
47                             GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
48
49   image = gtk_image_new_from_file (relocate (PKGDATADIR "/splash.png"));
50
51   gtk_container_add (GTK_CONTAINER (splash), image);
52
53   gtk_widget_show (image);
54
55   return splash;
56 }
57
58 static gboolean
59 hide_splash_window (gpointer data)
60 {
61   GtkWidget *splash = data;
62   gtk_widget_destroy (splash);
63   gtk_window_set_auto_startup_notification (TRUE);
64   return FALSE;
65 }
66
67
68 static gboolean
69 quit_one_loop (gpointer data)
70 {
71   gtk_main_quit ();
72   return FALSE;
73 }
74
75
76 static gboolean
77 run_inner_loop (gpointer data)
78 {
79   initialize ();
80
81   g_timeout_add (500, hide_splash_window, data);
82
83   gtk_main ();
84
85   de_initialize ();
86
87   return FALSE;
88 }
89
90
91
92 int
93 main (int argc, char *argv[])
94 {
95   GtkWidget *splash_window;
96   gchar *filename = 0;
97   gboolean show_splash = TRUE;
98   GError *err = 0;
99   const gchar *vers;
100
101   set_program_name (argv[0]);
102
103   if ( ! gtk_parse_args (&argc, &argv) )
104     {
105       perror ("Error parsing arguments");
106       exit (1);
107     }
108
109   if ( (vers = gtk_check_version (GTK_MAJOR_VERSION,
110                                  GTK_MINOR_VERSION,
111                                  GTK_MICRO_VERSION)) )
112     {
113       g_critical (vers);
114     }
115
116   /* Deal with options like --version, --help etc */
117   if ( ! parse_command_line (&argc, &argv, &filename, &show_splash, &err) )
118     {
119       g_clear_error (&err);
120       return 0;
121     }
122
123   gdk_init (&argc, &argv);
124
125   splash_window = create_splash_window ();
126   if ( show_splash )
127     gtk_widget_show (splash_window);
128
129   g_idle_add (quit_one_loop, 0);
130
131   gtk_quit_add (0, run_inner_loop, splash_window);
132   gtk_main ();
133
134
135   return 0;
136 }
137
138
139 /* Parses the command line specified by ARGC and ARGV as received by
140    main ().  Returns true if normal execution should proceed,
141    false if the command-line indicates that PSPP should exit. */
142 static gboolean
143 parse_command_line (int *argc, char ***argv, gchar **filename,
144                     gboolean *show_splash, GError **err)
145 {
146
147   static struct option long_options[] =
148     {
149       {"help", no_argument, NULL, 'h'},
150       {"version", no_argument, NULL, 'V'},
151       {"no-splash", no_argument, NULL, 'q'},
152       {0, 0, 0, 0},
153     };
154
155   int c;
156
157   for (;;)
158     {
159       c = getopt_long (*argc, *argv, "hVq", long_options, NULL);
160       if (c == -1)
161         break;
162
163       switch (c)
164         {
165         case 'h':
166           g_print ("Usage: psppire {|--help|--version|--no-splash}\n");
167           return FALSE;
168         case 'V':
169           g_print (version);
170           g_print ("\n");
171           g_print (legal);
172           return FALSE;
173         case 'q':
174           *show_splash = FALSE;
175           break;
176         default:
177           return FALSE;
178         }
179     }
180
181   if ( optind < *argc)
182     {
183       *filename = (*argv)[optind];
184     }
185
186   return TRUE;
187 }