[aisleriot] Port to GtkApplication



commit bc2ac2e9e0419b11ec964a5e9ba638f7ed6863b5
Author: William Jon McCann <william jon mccann gmail com>
Date:   Sun Mar 3 21:46:34 2013 -0500

    Port to GtkApplication
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679715

 src/Makefile.am   |    2 +
 src/application.c |  314 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/application.h |   52 +++++++++
 src/sol.c         |  144 ++-----------------------
 src/window.c      |  162 +++++++---------------------
 src/window.h      |   11 ++-
 6 files changed, 422 insertions(+), 263 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 44593ad..9e9f8de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,8 @@ DOC_MODULE = aisleriot
 bin_PROGRAMS = sol
 
 sol_SOURCES = \
+       application.c \
+       application.h \
        ar-clock.c \
        ar-clock.h \
        ar-cursor.c     \
diff --git a/src/application.c b/src/application.c
new file mode 100644
index 0000000..42a906e
--- /dev/null
+++ b/src/application.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright © 1998, 2001, 2003, 2006 Jonathan Blandford <jrb alum mit edu>
+ * Copyright © 2007 Christian Persch
+ * Copyright © 2007 Andreas Røsdal <andreasr gnome org>
+ * Copyright © 2013 William Jon McCann
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#ifdef HAVE_CLUTTER
+#include <cogl/cogl.h>
+#include <clutter/clutter.h>
+#include <clutter-gtk/clutter-gtk.h>
+#endif
+
+#include "ar-debug.h"
+#include "ar-stock.h"
+#include "ar-sound.h"
+#include "ar-string-utils.h"
+
+#include "conf.h"
+#include "window.h"
+#include "game.h"
+#include "util.h"
+
+#include "application.h"
+
+struct _AisleriotApplicationPrivate
+{
+  AisleriotWindow *window;
+  char *variation;
+  gint seed; /* unused */
+  gboolean freecell; /* unused */
+};
+
+G_DEFINE_TYPE (AisleriotApplication, aisleriot_application, GTK_TYPE_APPLICATION)
+
+static void
+add_main_options (AisleriotApplication *self,
+                  GOptionContext *context)
+{
+  const GOptionEntry aisleriot_options[] = {
+    { "variation", 'v', 0, G_OPTION_ARG_STRING, &self->priv->variation,
+      N_("Select the game type to play"), N_("NAME") },
+
+    /* Ignored option, for backward compat with saved session */
+    { "freecell", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &self->priv->freecell,
+      NULL, NULL },
+    { "seed", 's', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &self->priv->seed,
+      NULL, NULL },
+
+    { NULL }
+  };
+
+  g_option_context_add_main_entries (context,
+                                     aisleriot_options,
+                                     GETTEXT_PACKAGE);
+}
+
+static void
+about_activated (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       user_data)
+{
+  GtkApplication *application = user_data;
+  GtkWindow *window;
+
+  window = gtk_application_get_active_window (application);
+  aisleriot_window_show_about_dialog (AISLERIOT_WINDOW (window));
+}
+
+static void
+help_activated (GSimpleAction *action,
+                GVariant      *parameter,
+                gpointer       user_data)
+{
+  GtkApplication *application = user_data;
+  GtkWindow *window;
+  const char *game_module;
+
+  window = gtk_application_get_active_window (application);
+  game_module = aisleriot_window_get_game_module (AISLERIOT_WINDOW (window));
+  aisleriot_show_help (GTK_WIDGET (window), game_module);
+}
+
+static void
+aisleriot_application_quit (GSimpleAction *simple,
+                            GVariant *parameter,
+                            gpointer user_data)
+{
+  AisleriotApplication *self = AISLERIOT_APPLICATION (user_data);
+
+  gtk_widget_destroy (GTK_WIDGET (self->priv->window));
+}
+
+static int
+aisleriot_application_command_line (GApplication *application,
+                                    GApplicationCommandLine *command_line)
+{
+  AisleriotApplication *self = AISLERIOT_APPLICATION (application);
+  int argc;
+  char **argv;
+  int retval = 0;
+  GOptionContext *context;
+  GError *error = NULL;
+
+  argv = g_application_command_line_get_arguments (command_line, &argc);
+
+  context = g_option_context_new (NULL);
+
+  add_main_options (self, context);
+
+  g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+  g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+#ifdef HAVE_CLUTTER
+  g_option_context_add_group (context, cogl_get_option_group ());
+  g_option_context_add_group (context, clutter_get_option_group_without_init ());
+  g_option_context_add_group (context, gtk_clutter_get_option_group ());
+#endif /* HAVE_CLUTTER */
+
+  retval = g_option_context_parse (context, &argc, &argv, &error);
+  g_option_context_free (context);
+
+  if (!retval)
+    {
+      g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+               error->message, argv[0]);
+      g_error_free (error);
+      return retval;
+    }
+
+  g_strfreev (argv);
+
+  /* If we are asked for a specific game, check that it is valid. */
+  if (self->priv->variation != NULL) {
+    char *game_module = NULL;
+
+    if (self->priv->variation[0] != '\0') {
+      game_module = ar_filename_to_game_module (self->priv->variation);
+    }
+
+    g_free (self->priv->variation);
+    self->priv->variation = game_module;
+  }
+
+  if (self->priv->variation == NULL) {
+    char *pref;
+
+    pref = ar_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), 
DEFAULT_VARIATION);
+    self->priv->variation = ar_filename_to_game_module (pref);
+    g_free (pref);
+  }
+
+  g_assert (self->priv->variation != NULL);
+
+
+  aisleriot_window_set_game_module (self->priv->window, self->priv->variation, NULL);
+
+  gtk_widget_show (GTK_WIDGET (self->priv->window));
+
+  return retval;
+}
+
+
+static void
+aisleriot_application_activate (GApplication *application)
+{
+  AisleriotApplication *self = AISLERIOT_APPLICATION (application);
+
+  gtk_window_present (GTK_WINDOW (self->priv->window));
+}
+
+static void
+aisleriot_application_startup (GApplication *application)
+{
+  AisleriotApplication *self = AISLERIOT_APPLICATION (application);
+  GMenu *menu;
+  GMenu *section;
+  GSimpleAction *action;
+
+  G_APPLICATION_CLASS (aisleriot_application_parent_class)->startup (application);
+
+  aisleriot_conf_init ();
+  ar_sound_enable (FALSE);
+  ar_stock_init ();
+
+  action = g_simple_action_new ("help", NULL);
+  g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
+  g_signal_connect (action, "activate", G_CALLBACK (help_activated), self);
+  g_object_unref (action);
+
+  action = g_simple_action_new ("about", NULL);
+  g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
+  g_signal_connect (action, "activate", G_CALLBACK (about_activated), self);
+  g_object_unref (action);
+
+  action = g_simple_action_new ("quit", NULL);
+  g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
+  g_signal_connect (action, "activate", G_CALLBACK (aisleriot_application_quit), self);
+  g_object_unref (action);
+
+  menu = g_menu_new ();
+
+  section = g_menu_new ();
+  g_menu_append (section, _("Help"), "app.help");
+  g_menu_append (section, _("About"), "app.about");
+  g_menu_append (section, _("Quit"), "app.quit");
+
+  g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+
+  gtk_application_set_app_menu (GTK_APPLICATION (application),
+                                G_MENU_MODEL (menu));
+
+  gtk_application_add_accelerator (GTK_APPLICATION (application),
+                                   "F1", "app.help", NULL);
+
+  gtk_window_set_default_icon_name ("gnome-aisleriot");
+
+  self->priv->window = AISLERIOT_WINDOW (aisleriot_window_new (GTK_APPLICATION (application)));
+}
+
+static void
+aisleriot_application_shutdown (GApplication *application)
+{
+  g_settings_sync ();
+
+  G_APPLICATION_CLASS (aisleriot_application_parent_class)->shutdown (application);
+}
+
+static GObject *
+aisleriot_application_constructor (GType type,
+                                   guint n_construct_params,
+                                   GObjectConstructParam *construct_params)
+{
+  static GObject *self = NULL;
+
+  if (self == NULL)
+    {
+      self = G_OBJECT_CLASS (aisleriot_application_parent_class)->constructor (type,
+                                                                        n_construct_params,
+                                                                        construct_params);
+      g_object_add_weak_pointer (self, (gpointer) &self);
+      return self;
+    }
+
+  return g_object_ref (self);
+}
+
+
+static void
+aisleriot_application_dispose (GObject *object)
+{
+  AisleriotApplication *self = AISLERIOT_APPLICATION (object);
+
+  G_OBJECT_CLASS (aisleriot_application_parent_class)->dispose (object);
+
+  g_free (self->priv->variation);
+  self->priv->variation = NULL;
+}
+
+
+static void
+aisleriot_application_init (AisleriotApplication *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            AISLERIOT_TYPE_APPLICATION,
+                                            AisleriotApplicationPrivate);
+}
+
+
+static void
+aisleriot_application_class_init (AisleriotApplicationClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GApplicationClass *application_class = G_APPLICATION_CLASS (class);
+
+  object_class->constructor = aisleriot_application_constructor;
+  object_class->dispose = aisleriot_application_dispose;
+  application_class->activate = aisleriot_application_activate;
+  application_class->startup = aisleriot_application_startup;
+  application_class->shutdown = aisleriot_application_shutdown;
+  application_class->command_line = aisleriot_application_command_line;
+
+  g_type_class_add_private (class, sizeof (AisleriotApplicationPrivate));
+}
+
+GtkApplication *
+aisleriot_application_new (void)
+{
+  return g_object_new (AISLERIOT_TYPE_APPLICATION,
+                       "application-id", "org.gnome.Aisleriot",
+                       "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
+                       NULL);
+}
diff --git a/src/application.h b/src/application.h
new file mode 100644
index 0000000..3b94c42
--- /dev/null
+++ b/src/application.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2013 William Jon McCann
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef AISLERIOT_APPLICATION_H
+#define AISLERIOT_APPLICATION_H
+
+#include <gtk/gtk.h>
+
+#include "game.h"
+
+G_BEGIN_DECLS
+
+#define AISLERIOT_TYPE_APPLICATION         (aisleriot_application_get_type ())
+#define AISLERIOT_APPLICATION(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), AISLERIOT_TYPE_APPLICATION, 
AisleriotApplication))
+#define AISLERIOT_APPLICATION_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), AISLERIOT_TYPE_APPLICATION, 
AisleriotApplicationClass))
+#define AISLERIOT_IS_APPLICATION(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), AISLERIOT_TYPE_APPLICATION))
+#define AISLERIOT_IS_APPLICATION_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), AISLERIOT_TYPE_APPLICATION))
+#define AISLERIOT_APPLICATION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), AISLERIOT_TYPE_APPLICATION, 
AisleriotApplicationClass))
+
+typedef struct _AisleriotApplication        AisleriotApplication;
+typedef struct _AisleriotApplicationPrivate  AisleriotApplicationPrivate;
+
+struct _AisleriotApplication {
+  GtkApplication parent_instance;
+
+  /*< private >*/
+  AisleriotApplicationPrivate *priv;
+};
+
+typedef GtkApplicationClass AisleriotApplicationClass;
+
+GType aisleriot_application_get_type (void);
+
+GtkApplication *aisleriot_application_new (void);
+
+G_END_DECLS
+
+#endif /* !AISLERIOT_APPLICATION_H */
diff --git a/src/sol.c b/src/sol.c
index 17b9c9d..62c69d6 100644
--- a/src/sol.c
+++ b/src/sol.c
@@ -19,154 +19,24 @@
 
 #include <config.h>
 
-#include <string.h>
-
 #include <libguile.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
 
-#include <gtk/gtk.h>
-
-#ifdef HAVE_CLUTTER
-#include <cogl/cogl.h>
-#include <clutter/clutter.h>
-#include <clutter-gtk/clutter-gtk.h>
-#endif
-
-#include "ar-debug.h"
-#include "ar-stock.h"
 #include "ar-runtime.h"
-#include "ar-sound.h"
-
-#include "ar-string-utils.h"
-#include "conf.h"
-#include "window.h"
-#include "game.h"
-#include "util.h"
-
-#if 0
-/* String reserve */
-N_("Solitaire")
-N_("GNOME Solitaire")
-N_("About Solitaire")
-#endif /* 0 */
-
-typedef struct {
-  AisleriotWindow *window;
-  char *variation;
-  gint seed; /* unused */
-  gboolean freecell;
-} AppData;
-
-static void
-add_main_options (GOptionContext *option_context,
-                  AppData *data)
-{
-  const GOptionEntry aisleriot_options[] = {
-    { "variation", 'v', 0, G_OPTION_ARG_STRING, &data->variation,
-      N_("Select the game type to play"), N_("NAME") },
-    { "freecell", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &data->freecell,
-      NULL, NULL },
-
-    /* Ignored option, for backward compat with saved session */
-    { "seed", 's', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &data->seed,
-      NULL, NULL },
 
-    { NULL }
-  };
-
-  g_option_context_add_main_entries (option_context,
-                                    aisleriot_options, GETTEXT_PACKAGE);
-}
+#include "application.h"
 
 static void
 main_prog (void *closure, int argc, char *argv[])
 {
-  AppData data;
-  GOptionContext *option_context;
-  GError *error = NULL;
-  gboolean retval;
-
-  memset (&data, 0, sizeof (AppData));
-
-  option_context = g_option_context_new (NULL);
-  g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE);
-
-  add_main_options (option_context, &data);
-
-  ar_sound_enable (FALSE);
-
-  g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
-
-#ifdef HAVE_CLUTTER
-  g_option_context_add_group (option_context, cogl_get_option_group ());
-  g_option_context_add_group (option_context, clutter_get_option_group_without_init ());
-  g_option_context_add_group (option_context, gtk_clutter_get_option_group ());
-#endif /* HAVE_CLUTTER */
-
-  retval = g_option_context_parse (option_context, &argc, &argv, &error);
-  g_option_context_free (option_context);
-
-  if (!retval) {
-    g_printerr ("%s\n", error->message);
-    g_error_free (error);
-    goto cleanup;
-  }
+  GtkApplication *application;
+  int status;
 
-  g_set_application_name (data.freecell ? _("FreeCell Solitaire") : _("AisleRiot"));
-
-  aisleriot_conf_init ();
-
-  /* If we are asked for a specific game, check that it is valid. */
-  if (!data.freecell &&
-      data.variation != NULL) {
-    char *game_module = NULL;
-
-    if (data.variation[0] != '\0') {
-      game_module = ar_filename_to_game_module (data.variation);
-    }
-
-    g_free (data.variation);
-    data.variation = game_module;
-  }
-
-  if (!data.freecell && !data.variation) {
-    char *pref;
-
-    pref = ar_conf_get_string_with_default (NULL, aisleriot_conf_get_key (CONF_VARIATION), 
DEFAULT_VARIATION);
-    data.variation = ar_filename_to_game_module (pref);
-    g_free (pref);
-  }
-
-  g_assert (data.variation != NULL || data.freecell);
-
-  ar_stock_init ();
-
-  gtk_window_set_default_icon_name (data.freecell ? "gnome-freecell" : "gnome-aisleriot");
-
-  data.window = AISLERIOT_WINDOW (aisleriot_window_new (data.freecell));
-  g_signal_connect (data.window, "destroy",
-                   G_CALLBACK (gtk_main_quit), NULL);
-
-  if (data.freecell) {
-    aisleriot_window_set_game_module (data.window, FREECELL_VARIATION, NULL);
-  } else {
-    aisleriot_window_set_game_module (data.window, data.variation, NULL);
-  }
-
-  gtk_window_present (GTK_WINDOW (data.window));
-
-  gtk_main ();
-
-  aisleriot_conf_shutdown ();
-
-cleanup:
-  g_free (data.variation);
-
-  g_settings_sync ();
-
-  ar_runtime_shutdown ();
+  application = aisleriot_application_new ();
+  status = g_application_run (G_APPLICATION (application), argc, argv);
+  g_object_unref (application);
 }
 
 int
@@ -182,5 +52,7 @@ main (int argc, char *argv[])
 
   scm_boot_guile (argc, argv, main_prog, NULL); /* no return */
 
+  ar_runtime_shutdown ();
+
   return 0;
 }
diff --git a/src/window.c b/src/window.c
index 166484d..8d89916 100644
--- a/src/window.c
+++ b/src/window.c
@@ -143,7 +143,6 @@ struct _AisleriotWindowPrivate
   guint load_idle_id;
 
   guint changing_game_type : 1;
-  guint freecell_mode : 1;
   guint toolbar_visible : 1;
   guint statusbar_visible : 1;
   guint fullscreen : 1;
@@ -154,11 +153,6 @@ enum {
   OPTION_RADIOMENU
 };
 
-enum {
-  PROP_0,
-  PROP_FREECELL_MODE
-};
-
 /* Game Over dialogue */
 
 enum {
@@ -357,11 +351,9 @@ redo_cb (GtkAction *action,
   aisleriot_game_redo_move (priv->game);
 }
 
-static void
-help_about_cb (GtkAction *action,
-               AisleriotWindow *window)
+void
+aisleriot_window_show_about_dialog (AisleriotWindow * window)
 {
-  AisleriotWindowPrivate *priv = window->priv;
   const char *authors[] = {
     _("Main game:"),
     "Jonathan Blandford <jrb redhat com>",
@@ -407,21 +399,17 @@ help_about_cb (GtkAction *action,
 
   char *licence;
 
-  licence = ar_get_licence (priv->freecell_mode ? _("FreeCell Solitaire") : ("AisleRiot"));
+  licence = ar_get_licence ("AisleRiot");
 
   gtk_show_about_dialog (GTK_WINDOW (window),
                          "program-name",
-                            priv->freecell_mode ? _("FreeCell Solitaire")
-                                                : _("AisleRiot"),
+                         _("AisleRiot"),
                          "version", VERSION,
-                         "title", priv->freecell_mode ? _("About FreeCell Solitaire")
-                                                      : _("About AisleRiot"),
+                         "title", _("About AisleRiot"),
                          "comments",
-                         priv->freecell_mode ?
-                           NULL :
-                           _("AisleRiot provides a rule-based solitaire "
-                             "card engine that allows many different "
-                             "games to be played."),
+                         _("AisleRiot provides a rule-based solitaire "
+                           "card engine that allows many different "
+                           "games to be played."),
                          "copyright", "Copyright © 1998-2006 Jonathan Blandford\n"
                                       "Copyright © 2007, 2008, 2009, 2010, 2011, 2012 Christian Persch",
                          "license", licence,
@@ -429,8 +417,7 @@ help_about_cb (GtkAction *action,
                          "artists", artists,
                          "documenters", documenters,
                          "translator-credits", _("translator-credits"),
-                         "logo-icon-name", priv->freecell_mode ? "gnome-freecell"
-                                                               : "gnome-aisleriot",
+                         "logo-icon-name", "gnome-aisleriot",
                          "website", "http://www.gnome.org/projects/gnome-games/";,
                          "website-label", _("GNOME Games web site"),
                          "wrap-license", TRUE,
@@ -439,6 +426,13 @@ help_about_cb (GtkAction *action,
 }
 
 static void
+help_about_cb (GtkAction *action,
+               AisleriotWindow *window)
+{
+  aisleriot_window_show_about_dialog (window);
+}
+
+static void
 restart_game (GtkAction *action,
               AisleriotWindow *window)
 {
@@ -1194,17 +1188,12 @@ static void
 add_recently_played_game (AisleriotWindow *window,
                           const char *game_module)
 {
-  AisleriotWindowPrivate *priv = window->priv;
   char **recent_games, **new_recent;
   gsize i, n_recent = 0, n_new_recent = 0;
 
   if (!game_module)
     return;
 
-  /* Don't store the game type in freecell mode */
-  if (priv->freecell_mode)
-    return;
-
   recent_games = ar_conf_get_string_list (NULL, aisleriot_conf_get_key (CONF_RECENT_GAMES), &n_recent, NULL);
 
   if (recent_games == NULL) {
@@ -1600,10 +1589,7 @@ game_type_changed_cb (AisleriotGame *game,
   g_object_set (priv->action[ACTION_HELP_GAME], "label", game_name, NULL);
   g_object_set (priv->action[ACTION_OPTIONS_MENU], "label", game_name, NULL);
 
-  /* In freecell mode, we've already set the title to something different */
-  if (!priv->freecell_mode) {
-    gtk_window_set_title (GTK_WINDOW (window), game_name);
-  }
+  gtk_window_set_title (GTK_WINDOW (window), game_name);
 
   g_free (game_name);
 
@@ -1845,36 +1831,6 @@ screen_changed_cb (GtkWidget *widget,
 #endif /* HAVE_CLUTTER || ENABLE_SOUND */
 }
 
-/*
- * aisleriot_window_set_freecell_mode:
- * @window:
- *
- * Sets @window to FreeCell mode. In FreeCell mode,
- * the window is using the FreeCell variation, and doesn't allow
- * changing the game type.
- */
-static void
-aisleriot_window_set_freecell_mode (AisleriotWindow *window,
-                                    gboolean freecell_mode)
-{
-  AisleriotWindowPrivate *priv = window->priv;
-  GtkAction *action;
-
-  priv->freecell_mode = freecell_mode != FALSE;
-
-  if (freecell_mode) {
-    /* Inhibit game changing */
-    action = gtk_action_group_get_action (priv->action_group, "Select");
-    gtk_action_set_visible (action, FALSE);
-    action = gtk_action_group_get_action (priv->action_group, "RecentMenu");
-    gtk_action_set_visible (action, FALSE);
-
-    gtk_window_set_title (GTK_WINDOW (window), _("Freecell Solitaire"));
-  } else {
-    gtk_window_set_title (GTK_WINDOW (window), _("AisleRiot"));
-  }
-}
-
 static void
 board_status_message_cb (AisleriotBoard *board,
                          const char *status_message,
@@ -1920,7 +1876,7 @@ embed_size_allocate_cb (ArClutterEmbed *embed,
 
 /* Class implementation */
 
-G_DEFINE_TYPE (AisleriotWindow, aisleriot_window, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE (AisleriotWindow, aisleriot_window, GTK_TYPE_APPLICATION_WINDOW)
 
 static void
 aisleriot_window_style_set (GtkWidget *widget,
@@ -2451,23 +2407,6 @@ aisleriot_window_finalize (GObject *object)
 }
 
 static void
-aisleriot_window_set_property (GObject      *object,
-                               guint         property_id,
-                               const GValue *value,
-                               GParamSpec   *pspec)
-{
-  AisleriotWindow *window = AISLERIOT_WINDOW (object);
-
-  switch (property_id) {
-    case PROP_FREECELL_MODE:
-      aisleriot_window_set_freecell_mode (window, g_value_get_boolean (value));
-      break;
-
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-  }
-}
-static void
 aisleriot_window_class_init (AisleriotWindowClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -2475,26 +2414,11 @@ aisleriot_window_class_init (AisleriotWindowClass *klass)
 
   gobject_class->dispose = aisleriot_window_dispose;
   gobject_class->finalize = aisleriot_window_finalize;
-  gobject_class->set_property = aisleriot_window_set_property;
 
   widget_class->window_state_event = aisleriot_window_state_event;
   widget_class->style_set = aisleriot_window_style_set;
 
   g_type_class_add_private (gobject_class, sizeof (AisleriotWindowPrivate));
-
-  /**
-   * AisleriotWindow:freecell-mode:
-   *
-   * Whether the window is in freecell mode.
-   */
-  g_object_class_install_property
-    (gobject_class,
-     PROP_FREECELL_MODE,
-     g_param_spec_boolean ("freecell-mode", NULL, NULL,
-                           FALSE,
-                           G_PARAM_WRITABLE |
-                           G_PARAM_CONSTRUCT_ONLY |
-                           G_PARAM_STATIC_STRINGS));
 }
 
 /* public API */
@@ -2505,10 +2429,10 @@ aisleriot_window_class_init (AisleriotWindowClass *klass)
  * Returns: a new #AisleriotWindow
  */
 GtkWidget *
-aisleriot_window_new (gboolean freecell_mode)
+aisleriot_window_new (GtkApplication *application)
 {
   return g_object_new (AISLERIOT_TYPE_WINDOW,
-                       "freecell-mode", freecell_mode,
+                       "application", application,
                        NULL);
 }
 
@@ -2560,6 +2484,7 @@ load_idle_cb (LoadIdleData *data)
   AisleriotWindowPrivate *priv = data->window->priv;
   GError *error = NULL;
   GRand *rand;
+  char *pref;
 
   if (!aisleriot_game_load_game (priv->game, data->game_module, &error)) {
     GtkWidget *dialog;
@@ -2575,26 +2500,19 @@ load_idle_cb (LoadIdleData *data)
                                      name);
     g_free (name);
 
-    if (priv->freecell_mode ||
-        strcmp (data->game_module, DEFAULT_VARIATION) == 0) {
-      /* Loading freecell/the fallback game failed; all we can do is exit */
-      g_signal_connect_swapped (dialog, "response",
-                                G_CALLBACK (gtk_widget_destroy), data->window);
-    } else {
-      gtk_message_dialog_format_secondary_text
-        (GTK_MESSAGE_DIALOG (dialog),
-         "%s\n\n%s",
-         _("Aisleriot cannot find the last game you played."),
-         _("This usually occurs when you run an older version of Aisleriot "
-           "which does not have the game you last played. "
-           "The default game, Klondike, is being started instead."));
-
-      /* FIXME: add @error->message to a textview in a Detailed… expander */
-      g_printerr ("Scheme exception:\n-- 8< --\n%s\n-- >8 --\n", error->message);
-
-      g_signal_connect (dialog, "response",
-                        G_CALLBACK (load_error_response_cb), data->window);
-    }
+    gtk_message_dialog_format_secondary_text
+      (GTK_MESSAGE_DIALOG (dialog),
+       "%s\n\n%s",
+       _("Aisleriot cannot find the last game you played."),
+       _("This usually occurs when you run an older version of Aisleriot "
+         "which does not have the game you last played. "
+         "The default game, Klondike, is being started instead."));
+
+    /* FIXME: add @error->message to a textview in a Detailed… expander */
+    g_printerr ("Scheme exception:\n-- 8< --\n%s\n-- >8 --\n", error->message);
+
+    g_signal_connect (dialog, "response",
+                      G_CALLBACK (load_error_response_cb), data->window);
 
     g_error_free (error);
 
@@ -2604,15 +2522,11 @@ load_idle_cb (LoadIdleData *data)
   }
 
   /* Now that we know we can successfully load this variation,
-   * store it in conf, except when we're running in freecell mode.
+   * store it in conf
    */
-  if (!priv->freecell_mode) {
-    char *pref;
-
-    pref = g_strconcat (data->game_module, ".scm", NULL);
-    ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), pref);
-    g_free (pref);
-  }
+  pref = g_strconcat (data->game_module, ".scm", NULL);
+  ar_conf_set_string (NULL, aisleriot_conf_get_key (CONF_VARIATION), pref);
+  g_free (pref);
 
   rand = data->rand;
   data->rand = NULL;
diff --git a/src/window.h b/src/window.h
index d67b659..5a26b2e 100644
--- a/src/window.h
+++ b/src/window.h
@@ -33,19 +33,22 @@ G_BEGIN_DECLS
 
 typedef struct _AisleriotWindow                AisleriotWindow;
 typedef struct _AisleriotWindowPrivate  AisleriotWindowPrivate;
+typedef struct _AisleriotWindowClass    AisleriotWindowClass;
 
 struct _AisleriotWindow {
-  GtkWindow parent_instance;
+  GtkApplicationWindow parent_instance;
 
   /*< private >*/
   AisleriotWindowPrivate *priv;
 };
 
-typedef GtkWindowClass AisleriotWindowClass;
+struct _AisleriotWindowClass {
+  GtkApplicationWindowClass base_class;
+};
 
 GType aisleriot_window_get_type (void);
 
-GtkWidget *aisleriot_window_new (gboolean freecell_mode);
+GtkWidget *aisleriot_window_new (GtkApplication *application);
 
 GtkUIManager *aisleriot_window_get_ui_manager (AisleriotWindow *window);
 
@@ -58,6 +61,8 @@ void aisleriot_window_set_game_module (AisleriotWindow * window,
 
 const char *aisleriot_window_get_game_module (AisleriotWindow *window);
 
+void aisleriot_window_show_about_dialog (AisleriotWindow * window);
+
 G_END_DECLS
 
 #endif /* !AISLERIOT_WINDOW_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]