+static void
+on_open (GApplication *app, GFile **files, gint n_files, gchar * hint,
+ gpointer ud)
+{
+ /* If the application is already open and we open another file
+ via xdg-open on GNU/Linux or via the file manager, then open is
+ called. Check if we already have a psppire window. */
+ if (find_psppire_window (app) == NULL)
+ post_initialise (app);
+
+ /* When a new data file is opened, then try to find an empty
+ data window which will then be replaced as in the open file
+ dialog */
+ GtkWindow *victim = find_empty_data_window (app);
+
+ gchar *file = g_file_get_parse_name (files[0]);
+ GtkWindow *x = psppire_preload_file (file, victim);
+ g_free (file);
+
+ wait_for_splash (app, x);
+}
+
+
+/* These are arguments which must be processed BEFORE the X server has been initialised */
+static void
+process_pre_start_arguments (int *argc, char ***argv)
+{
+ GOptionEntry oe[] = {
+ {"version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
+ show_version_and_exit, N_("Show version information and exit"), 0},
+ {NULL, 0, 0, 0, NULL, "", 0}
+ };
+
+ GOptionContext *oc = g_option_context_new ("");
+ g_option_context_set_help_enabled (oc, FALSE);
+ g_option_context_set_ignore_unknown_options (oc, FALSE);
+ g_option_context_add_main_entries (oc, oe, NULL);
+ g_option_context_parse (oc, argc, argv, NULL);
+ g_option_context_free (oc);
+}
+
+int
+main (int argc, char *argv[])
+{
+ /* Some operating systems need to munge the arguments. */
+ pre_initialisation (&argc, argv);
+
+ set_program_name (argv[0]);
+
+ GtkApplication *app =
+ gtk_application_new ("org.gnu.pspp", G_APPLICATION_HANDLES_OPEN);
+
+ process_pre_start_arguments (&argc, &argv);
+
+ GOptionEntry oe[] = {
+ {"no-splash", 'q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
+ N_("Do not display the splash screen"), 0},
+ {"no-unique", 'n', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
+ N_("Do not attempt single instance negotiation"), 0},
+ {NULL}
+ };
+
+ g_application_add_main_option_entries (G_APPLICATION (app), oe);
+
+ g_signal_connect (app, "startup", G_CALLBACK (on_startup), NULL);
+ g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
+ g_signal_connect (app, "handle-local-options",
+ G_CALLBACK (on_local_options), NULL);
+ g_signal_connect (app, "open", G_CALLBACK (on_open), NULL);
+
+ {
+ GSimpleAction *act_new_syntax = g_simple_action_new ("new-syntax", NULL);
+ g_signal_connect_swapped (act_new_syntax, "activate",
+ G_CALLBACK (create_syntax_window), NULL);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_new_syntax));
+ }
+
+ {
+ GSimpleAction *act_new_data = g_simple_action_new ("new-data", NULL);
+ g_signal_connect_swapped (act_new_data, "activate",
+ G_CALLBACK (create_data_window), NULL);
+ g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_new_data));
+ }
+
+ g_object_set (G_OBJECT (app), "register-session", TRUE, NULL);
+ return g_application_run (G_APPLICATION (app), argc, argv);