[gnome-sudoku] Use GApplication command line processing
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku] Use GApplication command line processing
- Date: Sun, 1 Jun 2014 00:18:43 +0000 (UTC)
commit ea6bbc1014b048714235e5ef0cb437da181b120f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sat May 31 16:37:38 2014 -0500
Use GApplication command line processing
configure.ac | 6 ++++--
src/gnome-sudoku.vala | 41 +++++++++++++++++++++++++++++++++--------
src/main.vala | 43 +------------------------------------------
3 files changed, 38 insertions(+), 52 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0e79284..6a5e184 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AM_SILENT_RULES([yes])
AM_MAINTAINER_MODE([enable])
GNOME_MAINTAINER_MODE_DEFINES
-AM_PROG_VALAC([0.22.0])
+AM_PROG_VALAC([0.24.0])
AM_PROG_CC_C_O
GLIB_GSETTINGS
@@ -15,10 +15,12 @@ dnl ###########################################################################
dnl Dependencies
dnl ###########################################################################
+GLIB_REQUIRED=2.40.0
GTK_REQUIRED=3.13.0
PKG_CHECK_MODULES(GNOME_SUDOKU, [
- gio-2.0
+ glib-2.0 >= $GLIB_REQUIRED
+ gio-2.0 >= $GLIB_REQUIRED
gtk+-3.0 >= $GTK_REQUIRED
gee-0.8
json-glib-1.0
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 0d2c866..b2a617c 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -28,7 +28,7 @@ public class Sudoku : Gtk.Application
private SimpleAction undo_action;
private SimpleAction redo_action;
- private bool show_possibilities;
+ private bool show_possibilities = false;
private const GLib.ActionEntry action_entries[] =
{
@@ -43,10 +43,40 @@ public class Sudoku : Gtk.Application
{"quit", quit_cb }
};
- public Sudoku (bool show_possibilities = false)
+ private static const OptionEntry[] option_entries =
+ {
+ { "version", 'v', 0, OptionArg.NONE, null,
+ /* Help string for command line --version flag */
+ N_("Show release version"), null},
+
+ { "show-possible-values", 's', 0, OptionArg.NONE, null,
+ /* Help string for command line --show-possible flag */
+ N_("Show the possible values for each cell"), null},
+
+ { null }
+ };
+
+ public Sudoku ()
{
Object (application_id: "org.gnome.sudoku", flags: ApplicationFlags.FLAGS_NONE);
- this.show_possibilities = show_possibilities;
+ add_main_option_entries (option_entries);
+ }
+
+ protected override int handle_local_options (GLib.VariantDict options)
+ {
+ if (options.contains ("version"))
+ {
+ /* Not translated so can be easily parsed */
+ stderr.printf ("gnome-sudoku %s\n", VERSION);
+ return Posix.EXIT_SUCCESS;
+ }
+ else if (options.contains ("show-possible-values"))
+ {
+ show_possibilities = true;
+ }
+
+ /* Activate */
+ return -1;
}
protected override void startup ()
@@ -127,12 +157,7 @@ public class Sudoku : Gtk.Application
undo_action.set_enabled (false);
redo_action.set_enabled (false);
- var show_warnings = false;
-
if (view != null) {
- show_possibilities = view.show_possibilities;
- show_warnings = view.show_warnings;
-
grid_box.remove (view);
controls_box.remove (number_picker);
}
diff --git a/src/main.vala b/src/main.vala
index ab993a2..5f75830 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -16,48 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-private static bool show_version;
-private static bool show_possibilities;
-
-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},
-
- { "show-possible-values", 's', 0, OptionArg.NONE, ref show_possibilities,
- /* Help string for command line --show-possible flag */
- N_("Show the possible values for each cell"), null},
-
- { null }
-};
-
public static int main (string[] args)
{
- var c = new OptionContext (/* Arguments and description for --help text */
- _("[FILE] - Play Sudoku"));
- c.add_main_entries (options, 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 ("gnome-sudoku %s\n", VERSION);
- return Posix.EXIT_SUCCESS;
- }
-
- var app = new Sudoku (show_possibilities);
-
- return app.run ();
+ return new Sudoku ().run (args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]