[gnome-games] gnotravex: make better use of GtkApplication
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] gnotravex: make better use of GtkApplication
- Date: Thu, 22 Dec 2011 19:57:19 +0000 (UTC)
commit 3086addfa27b77321b0bf064eaa5539397f8cb15
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Dec 19 22:34:58 2011 -0500
gnotravex: make better use of GtkApplication
One feature of GtkApplication is application uniqueness. This means
that when the application is started for the second time, the first one
is focused rather than creating a second window.
For this reason, we should avoid doing all of the setup work for the
application until we are sure that we are going to be the first
instance. That's what the startup() virtual function is for.
The activate() virtual function runs each time we are invoked (for the
first time, or also in the future). We can use this to present the
window.
Finally, the newly-introduced shutdown() function does the opposite of
startup().
gnotravex/src/gnotravex.vala | 65 ++++++++++++++++++++---------------------
1 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/gnotravex/src/gnotravex.vala b/gnotravex/src/gnotravex.vala
index c620dfe..21931e1 100644
--- a/gnotravex/src/gnotravex.vala
+++ b/gnotravex/src/gnotravex.vala
@@ -80,14 +80,44 @@ public class Gnotravex : Gtk3.Application
" <toolitem action='LeaveFullscreen'/>" +
" </toolbar>" +
"</ui>";
-
+
public Gnotravex ()
{
Object (application_id: "org.gnome.gnotravex", flags: ApplicationFlags.FLAGS_NONE);
+ }
+
+ protected override void startup ()
+ {
+ base.startup ();
+
+ if (!GnomeGamesSupport.runtime_init ("gnotravex"))
+ Posix.exit (Posix.EXIT_FAILURE);
+
+#if ENABLE_SETGID
+ GnomeGamesSupport.setgid_io_init ();
+#endif
+
+ Environment.set_application_name (_("Tetravex"));
+ GnomeGamesSupport.stock_init ();
+ Gtk.Window.set_default_icon_name ("gnome-tetravex");
settings = new Settings ("org.gnome.gnotravex");
highscores = new GnomeGamesSupport.Scores ("gnotravex", scorecats, null, null, 0, GnomeGamesSupport.ScoreStyle.TIME_ASCENDING);
+ }
+
+ protected override void shutdown () {
+ GnomeGamesSupport.runtime_shutdown ();
+
+ base.shutdown ();
+ }
+
+ protected override void activate ()
+ {
+ if (window != null) {
+ window.present ();
+ return;
+ }
window = new Gtk.Window ();
window.title = _("Tetravex");
@@ -178,10 +208,7 @@ public class Gnotravex : Gtk3.Application
time_box.pack_start (clock, false, false, 0);
new_game ();
- }
- public override void activate ()
- {
window.show ();
}
@@ -362,35 +389,7 @@ public class Gnotravex : Gtk3.Application
public static int main (string[] args)
{
- if (!GnomeGamesSupport.runtime_init ("gnotravex"))
- return Posix.EXIT_FAILURE;
-
-#if ENABLE_SETGID
- GnomeGamesSupport.setgid_io_init ();
-#endif
-
- var context = new OptionContext ("");
- context.set_translation_domain (GETTEXT_PACKAGE);
- context.add_group (Gtk.get_option_group (true));
- try
- {
- context.parse (ref args);
- }
- catch (Error e)
- {
- stderr.printf ("%s\n", e.message);
- return Posix.EXIT_FAILURE;
- }
-
- Environment.set_application_name (_("Tetravex"));
- GnomeGamesSupport.stock_init ();
- Gtk.Window.set_default_icon_name ("gnome-tetravex");
-
var app = new Gnotravex ();
- var result = app.run ();
-
- GnomeGamesSupport.runtime_shutdown ();
-
- return result;
+ return app.run (args);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]