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