[gnome-games/glines-vala] glines: begin the port to vala
- From: Thomas Hindoe Paaboel Andersen <thomashpa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/glines-vala] glines: begin the port to vala
- Date: Thu, 17 May 2012 23:01:49 +0000 (UTC)
commit 22183c18d6179c621433222c7eccc22a41ffba83
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date: Fri May 18 01:01:39 2012 +0200
glines: begin the port to vala
configure.ac | 7 +-
glines/data/Makefile.am | 3 +-
glines/data/glines.ui | 4 +-
glines/src/Makefile.am | 32 +-
glines/src/config.vapi | 9 +
glines/src/glines-application.vala | 146 ++++
glines/src/glines.c | 1624 ------------------------------------
glines/src/glines.gresource.xml.in | 7 +
glines/src/glines.h | 47 -
glines/src/main.vala | 40 +
10 files changed, 237 insertions(+), 1682 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6440d08..a5372a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,7 +117,7 @@ need_gmenu=no
for game in $gamelist; do
case $game in
- glchess|gnomine|gnotravex|iagno|lightsoff|mahjongg|quadrapassel) need_vala=yes ;;
+ glchess|glines|gnomine|gnotravex|iagno|lightsoff|mahjongg|quadrapassel) need_vala=yes ;;
*) ;;
esac
case $game in
@@ -282,6 +282,10 @@ PKG_CHECK_MODULES([GIO],[gio-2.0 >= $GIO_REQUIRED])
m4_ifdef([GLIB_GSETTINGS],[GLIB_GSETTINGS([],[:])])
+# GResources
+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
+AC_SUBST(GLIB_COMPILE_RESOURCES)
+
# Check for SQLite
have_sqlite=no
@@ -515,6 +519,7 @@ glines/data/Makefile
glines/data/icons/Makefile
glines/data/glines.desktop.in
glines/src/Makefile
+glines/src/glines.gresource.xml
glines/help/Makefile
lightsoff/Makefile
lightsoff/src/Makefile
diff --git a/glines/data/Makefile.am b/glines/data/Makefile.am
index ed28c78..c2344ca 100644
--- a/glines/data/Makefile.am
+++ b/glines/data/Makefile.am
@@ -1,7 +1,6 @@
SUBDIRS = icons
-uidir = $(datadir)/glines/
-ui_DATA = \
+dist_noinst_DATA = \
glines.ui \
glines-preferences.ui
diff --git a/glines/data/glines.ui b/glines/data/glines.ui
index 561f9a3..426b771 100644
--- a/glines/data/glines.ui
+++ b/glines/data/glines.ui
@@ -2,7 +2,7 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkAccelGroup" id="accelgroup"/>
- <object class="GtkWindow" id="glines_window">
+ <object class="GtkApplicationWindow" id="glines_window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Five or more</property>
<property name="default_width">320</property>
@@ -19,7 +19,7 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar" id="menubar">
- <property name="visible">True</property>
+ <property name="visible">False</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="game_menu_item">
diff --git a/glines/src/Makefile.am b/glines/src/Makefile.am
index a1345ad..40627bd 100644
--- a/glines/src/Makefile.am
+++ b/glines/src/Makefile.am
@@ -1,16 +1,22 @@
bin_PROGRAMS = glines
-glines_SOURCES = \
- glines.c \
- glines.h
+BUILT_SOURCES = glines-resources.c
+
+glines_SOURCES = \
+ config.vapi \
+ main.vala \
+ glines-application.vala \
+ $(BUILT_SOURCES)
glines_CPPFLAGS = \
-I$(top_srcdir) \
$(AM_CPPFLAGS)
glines_CFLAGS = \
- -DDATA_DIRECTORY=\"$(datadir)/glines\" \
+ -I$(top_srcdir)/libgames-support \
+ -DPKGDATADIR=\"$(datadir)/glines\" \
-DLOCALEDIR=\"$(datadir)/locale\" \
+ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
$(GMODULE_CFLAGS) \
$(GTK_CFLAGS) \
$(RSVG_CFLAGS) \
@@ -19,11 +25,25 @@ glines_CFLAGS = \
glines_LDADD = \
$(top_builddir)/libgames-support/libgames-support.la \
$(GMODULE_LIBS) \
- $(GTK_LIBS) \
+ $(GTK_LIBS) \
$(RSVG_LIBS) \
- $(INTLLIBS) \
+ $(INTLLIBS) \
-lm
+glines_VALAFLAGS = \
+ --pkg posix \
+ --pkg gtk+-3.0 \
+ --pkg gmodule-2.0 \
+ --vapidir $(top_srcdir)/libgames-support \
+ --pkg GnomeGamesSupport-1.0
+
+glines-resources.c: glines.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies glines.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source glines.gresource.xml
+
+EXTRA_DIST = \
+ glines.gresource.xml
+
+
install-exec-hook:
-if test "$(setgid)" = "true"; then \
chgrp $(scores_group) $(DESTDIR)$(bindir)/glines && chmod 2555 $(DESTDIR)$(bindir)/glines ;\
diff --git a/glines/src/config.vapi b/glines/src/config.vapi
new file mode 100644
index 0000000..0d7e06c
--- /dev/null
+++ b/glines/src/config.vapi
@@ -0,0 +1,9 @@
+[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config
+{
+ public const string PKGDATADIR;
+ public const string LOCALEDIR;
+ public const string GETTEXT_PACKAGE;
+ public const string VERSION;
+}
+
diff --git a/glines/src/glines-application.vala b/glines/src/glines-application.vala
new file mode 100644
index 0000000..3d19201
--- /dev/null
+++ b/glines/src/glines-application.vala
@@ -0,0 +1,146 @@
+namespace Glines
+{
+ public class GlinesApp : Gtk.Application
+ {
+ private Gtk.ApplicationWindow window;
+ private Settings settings;
+ private Gtk.Builder builder;
+ private GnomeGamesSupport.Scores highscores;
+
+ private Gtk.Dialog preferences_dialog;
+
+ private const GLib.ActionEntry[] action_entries =
+ {
+ { "new-game", new_game_cb },
+ { "scores", scores_cb },
+ { "preferences", preferences_cb },
+ { "help", help_cb },
+ { "about", about_cb },
+ { "quit", quit_cb }
+ };
+
+ private const GnomeGamesSupport.ScoresCategory scorecats[] =
+ {
+ { "Small", NC_("board size", "Small") },
+ { "Medium", NC_("board size", "Medium") },
+ { "Large", NC_("board size", "Large") }
+ };
+
+ private const string[] authors = { "Thomas Andersen <phomes gmail com>", "Robert Szokovacs <szo appaloosacorp hu>", "Szabolcs B\xc3\xa1n <shooby gnome hu>" };
+ private const string[] documenters = { "Tiffany Antopolski", "Lanka Rathnayaka" };
+
+ public GlinesApp ()
+ {
+ Object (application_id: "org.gnome.glines", flags: ApplicationFlags.FLAGS_NONE);
+
+ add_action_entries (action_entries, this);
+ }
+
+ protected override void startup ()
+ {
+ base.startup ();
+
+ settings = new Settings ("org.gnome.glines");
+
+ highscores = new GnomeGamesSupport.Scores ("glines", scorecats, "board size", null, 0, GnomeGamesSupport.ScoreStyle.PLAIN_DESCENDING);
+
+ builder = new Gtk.Builder ();
+ try
+ {
+ builder.add_from_resource ("/org/gnome/glines/ui/glines.ui");
+ builder.add_from_resource ("/org/gnome/glines/ui/glines-preferences.ui");
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Could not load UI: %s", e.message);
+ }
+
+ var menu = new Menu ();
+
+ var section = new Menu ();
+ menu.append_section (null, section);
+ section.append (_("_New Game"), "app.new-game");
+ section.append (_("_Scores"), "app.scores");
+ section.append (_("_Preferences"), "app.preferences");
+
+ section = new Menu ();
+ menu.append_section (null, section);
+ section.append (_("_Help"), "app.help");
+ section.append (_("_About"), "app.about");
+
+ section = new Menu ();
+ menu.append_section (null, section);
+ section.append (_("_Quit"), "app.quit");
+ set_app_menu (menu);
+
+ window = (Gtk.ApplicationWindow) builder.get_object ("glines_window");
+ add_window (window);
+ }
+
+ public override void activate ()
+ {
+ window.present ();
+ }
+
+ private void new_game_cb ()
+ {
+ stdout.printf ("new game\n");
+ }
+
+ private void scores_cb ()
+ {
+ stdout.printf ("FIXME: Showing scores does not currently work\n");
+
+ var scores_dialog = new GnomeGamesSupport.ScoresDialog (window, highscores, _("GNOME Five or More"));
+ scores_dialog.set_category_description (_("_Board size:"));
+ scores_dialog.run ();
+ scores_dialog.destroy ();
+ }
+
+ private void preferences_cb ()
+ {
+ stdout.printf ("preferences\n");
+ if (preferences_dialog == null)
+ preferences_dialog = (Gtk.Dialog) builder.get_object ("preferences_dialog");
+
+ preferences_dialog.run();
+ preferences_dialog.destroy ();
+ }
+
+ private void help_cb ()
+ {
+ try
+ {
+ Gtk.show_uri (window.get_screen (), "ghelp:glines", Gtk.get_current_event_time ());
+ }
+ catch (GLib.Error e)
+ {
+ GLib.warning ("Unable to open help: %s", e.message);
+ }
+ }
+
+ private void about_cb ()
+ {
+ Gtk.show_about_dialog (window,
+ "program-name", _("Five or More"),
+ "logo-icon-name", "glines",
+ "version", Config.VERSION,
+ "comments", _("GNOME port of the once-popular Color Lines game.\n\nFive or More is a part of GNOME Games."),
+ "copyright", "Copyright \xc2\xa9 1997-2012 Free Software Foundation, Inc.",
+ "license-type", Gtk.License.GPL_3_0,
+ "wrap-license", false,
+ "authors", authors,
+ //FIXME: "documenters", documenters,
+ "translator-credits", _("translator-credits"),
+ "website", "http://www.gnome.org/projects/gnome-games/",
+ "website-label", _("GNOME Games web site"),
+ null);
+ }
+
+ private void quit_cb ()
+ {
+ window.destroy ();
+ }
+ }
+}
+
diff --git a/glines/src/glines.gresource.xml.in b/glines/src/glines.gresource.xml.in
new file mode 100644
index 0000000..0ecb6ef
--- /dev/null
+++ b/glines/src/glines.gresource.xml.in
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/glines/ui">
+ <file alias="glines.ui" preprocess="xml-stripblanks">@top_srcdir@/glines/data/glines.ui</file>
+ <file alias="glines-preferences.ui" preprocess="xml-stripblanks">@top_srcdir@/glines/data/glines-preferences.ui</file>
+ </gresource>
+</gresources>
diff --git a/glines/src/main.vala b/glines/src/main.vala
new file mode 100644
index 0000000..461e30e
--- /dev/null
+++ b/glines/src/main.vala
@@ -0,0 +1,40 @@
+private static bool show_version;
+
+private static const OptionEntry[] options =
+{
+ { "version", 'v', 0, OptionArg.NONE, ref show_version,
+ /* Help string for command line --version flag */
+ N_("Show release version"), null},
+ { null }
+};
+
+public static int main (string[] args)
+{
+ Gtk.init (ref args);
+
+ var c = new OptionContext (/* Arguments and description for --help text */
+ _("[FILE] - Play Glines"));
+ c.add_main_entries (options, Config.GETTEXT_PACKAGE);
+ c.add_group (Gtk.get_option_group (true));
+ try
+ {
+ c.parse (ref args);
+ }
+ catch (Error e)
+ {
+ stderr.printf ("%s\n", e.message);
+ stderr.printf (/* Text printed out when an unknown command-line argument provided */
+ _("Run '%s --help' to see a full list of available command line options."), args[0]);
+ stderr.printf ("\n");
+ return Posix.EXIT_FAILURE;
+ }
+ if (show_version)
+ {
+ /* Note, not translated so can be easily parsed */
+ stderr.printf ("glines %s\n", Config.VERSION);
+ return Posix.EXIT_SUCCESS;
+ }
+
+ var app = new Glines.GlinesApp ();
+ return app.run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]