1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2004, 2005, 2006, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation
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.
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.
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/>. */
19 #include "ui/gui/psppire.h"
24 #include "language/lexer/include-path.h"
25 #include "libpspp/argv-parser.h"
26 #include "libpspp/array.h"
27 #include "libpspp/assertion.h"
28 #include "libpspp/cast.h"
29 #include "libpspp/copyleft.h"
30 #include "libpspp/str.h"
31 #include "libpspp/string-array.h"
32 #include "libpspp/version.h"
33 #include "ui/source-init-opts.h"
34 #include "ui/gui/psppire-syntax-window.h"
35 #include "ui/gui/psppire-data-window.h"
36 #include "ui/gui/psppire-output-window.h"
38 #include "gl/configmake.h"
39 #include "gl/progname.h"
40 #include "gl/relocatable.h"
41 #include "gl/version-etc.h"
42 #include "gl/xalloc.h"
45 #define _(msgid) gettext (msgid)
46 #define N_(msgid) msgid
51 show_version_and_exit ()
53 version_etc (stdout, "psppire", PACKAGE_NAME, PACKAGE_VERSION,
54 "Ben Pfaff", "John Darrington", "Jason Stover", NULL_SENTINEL);
64 init_prepare (GSource * source, gint * timeout_)
70 init_check (GSource * source)
76 init_dispatch (GSource * ss, GSourceFunc callback, gpointer user_data)
78 struct init_source *is = (struct init_source *) ss;
80 bool finished = initialize (is);
85 g_main_loop_quit (is->loop);
92 static GSourceFuncs init_funcs =
93 { init_prepare, init_check, init_dispatch, NULL };
97 GtkWidget *wsplash = 0;
98 gint64 start_time = 0;
102 create_splash_window (void)
104 GtkWidget *sp = gtk_window_new (GTK_WINDOW_TOPLEVEL);
106 const gchar *filename = PKGDATADIR "/splash.png";
107 const char *relocated_filename = relocate (filename);
108 GtkWidget *l = gtk_image_new_from_file (relocated_filename);
109 if (filename != relocated_filename)
110 free (CONST_CAST (char *, relocated_filename));
112 gtk_container_add (GTK_CONTAINER (sp), l);
113 gtk_window_set_type_hint (GTK_WINDOW (sp),
114 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
115 gtk_window_set_position (GTK_WINDOW (sp), GTK_WIN_POS_CENTER);
116 gtk_window_set_skip_pager_hint (GTK_WINDOW (sp), TRUE);
117 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (sp), TRUE);
118 gtk_window_set_focus_on_map (GTK_WINDOW (sp), FALSE);
119 gtk_window_set_accept_focus (GTK_WINDOW (sp), FALSE);
122 hints.max_height = 100;
123 hints.max_width = 200;
124 gtk_window_set_geometry_hints (GTK_WINDOW (sp),
125 NULL, &hints, GDK_HINT_MAX_SIZE);
128 gtk_window_set_gravity (GTK_WINDOW (sp), GDK_GRAVITY_CENTER);
130 gtk_window_set_modal (GTK_WINDOW (sp), TRUE);
131 gtk_window_set_decorated (GTK_WINDOW (sp), FALSE);
132 gtk_window_set_keep_above (GTK_WINDOW (sp), TRUE);
133 gtk_widget_show_all (sp);
139 on_local_options (GApplication * application,
140 GVariantDict * options, gpointer user_data)
144 g_variant_dict_lookup_value (options, "no-unique",
145 G_VARIANT_TYPE_BOOLEAN);
148 GApplicationFlags flags = g_application_get_flags (application);
149 flags |= G_APPLICATION_NON_UNIQUE;
150 g_application_set_flags (application, flags);
156 g_variant_dict_lookup_value (options, "no-splash",
157 G_VARIANT_TYPE_BOOLEAN);
161 start_time = g_get_monotonic_time ();
170 on_startup (GApplication * app, gpointer ud)
172 GMainContext *context = g_main_context_new ();
176 wsplash = create_splash_window ();
177 gtk_application_add_window (GTK_APPLICATION (app),
178 GTK_WINDOW (wsplash));
181 GMainLoop *loop = g_main_loop_new (context, FALSE);
183 GSource *ss = g_source_new (&init_funcs, sizeof (struct init_source));
185 ((struct init_source *) ss)->loop = loop;
186 ((struct init_source *) ss)->state = 0;
188 g_source_set_priority (ss, G_PRIORITY_DEFAULT);
190 g_source_attach (ss, context);
191 g_main_loop_run (loop);
196 post_initialise (GApplication * app)
198 register_selection_functions ();
199 psppire_output_window_setup ();
201 GSimpleAction *quit = g_simple_action_new ("quit", NULL);
202 g_signal_connect_swapped (quit, "activate", G_CALLBACK (psppire_quit), app);
203 g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (quit));
207 #define SPLASH_DURATION 1000
210 destroy_splash (gpointer ud)
212 GtkWidget *sp = GTK_WIDGET (ud);
213 gtk_widget_destroy (sp);
215 return G_SOURCE_REMOVE;
220 wait_for_splash (GApplication *app, GtkWindow *x)
224 gtk_window_set_transient_for (GTK_WINDOW (wsplash), x);
225 gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (wsplash));
226 gtk_window_set_keep_above (GTK_WINDOW (wsplash), TRUE);
227 gtk_window_present (GTK_WINDOW (wsplash));
229 /* Remove the splash screen after SPLASH_DURATION milliseconds */
230 gint64 elapsed_time = (g_get_monotonic_time () - start_time) / 1000;
231 if (SPLASH_DURATION - elapsed_time <= 0)
232 destroy_splash (wsplash);
234 g_timeout_add (SPLASH_DURATION - elapsed_time, destroy_splash, wsplash);
240 on_activate (GApplication * app, gpointer ud)
242 post_initialise (app);
244 GtkWindow *x = create_data_window ();
245 gtk_application_add_window (GTK_APPLICATION (app), x);
247 wait_for_splash (app, x);
252 on_open (GApplication *app, GFile **files, gint n_files, gchar * hint,
255 post_initialise (app);
257 gchar *file = g_file_get_parse_name (files[0]);
258 GtkWindow *x = psppire_preload_file (file);
261 wait_for_splash (app, x);
265 /* These are arguments which must be processed BEFORE the X server has been initialised */
267 process_pre_start_arguments (int *argc, char ***argv)
269 GOptionEntry oe[] = {
270 {"version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
271 show_version_and_exit, N_("Show version information and exit"), 0},
275 GOptionContext *oc = g_option_context_new ("");
276 g_option_context_set_help_enabled (oc, FALSE);
277 g_option_context_set_ignore_unknown_options (oc, FALSE);
278 g_option_context_add_main_entries (oc, oe, NULL);
279 g_option_context_parse (oc, argc, argv, NULL);
284 main (int argc, char *argv[])
286 set_program_name (argv[0]);
288 GtkApplication *app =
289 gtk_application_new ("gnu.pspp", G_APPLICATION_HANDLES_OPEN);
291 process_pre_start_arguments (&argc, &argv);
293 GOptionEntry oe[] = {
294 {"no-splash", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
295 N_("Do not display the splash screen"), 0},
296 {"no-unique", 'n', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
297 N_("Do not attempt single instance negotiation"), 0},
301 g_application_add_main_option_entries (G_APPLICATION (app), oe);
303 g_signal_connect (app, "startup", G_CALLBACK (on_startup), NULL);
304 g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
305 g_signal_connect (app, "handle-local-options",
306 G_CALLBACK (on_local_options), NULL);
307 g_signal_connect (app, "open", G_CALLBACK (on_open), NULL);
310 GSimpleAction *act_new_syntax = g_simple_action_new ("new-syntax", NULL);
311 g_signal_connect_swapped (act_new_syntax, "activate",
312 G_CALLBACK (create_syntax_window), NULL);
313 g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_new_syntax));
317 GSimpleAction *act_new_data = g_simple_action_new ("new-data", NULL);
318 g_signal_connect_swapped (act_new_data, "activate",
319 G_CALLBACK (create_data_window), NULL);
320 g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_new_data));
323 return g_application_run (G_APPLICATION (app), argc, argv);