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