[gnome-nibbles/arnaudb/command-line: 7/10] Add --mute and --unmute options.



commit 148080891f14f1c6df5ffac019daf2292580c64a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jul 8 14:18:00 2020 +0200

    Add --mute and --unmute options.

 data/gnome-nibbles.6   |  9 +++++++++
 src/gnome-nibbles.vala | 18 +++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/data/gnome-nibbles.6 b/data/gnome-nibbles.6
index b4ccea8..936ff7b 100644
--- a/data/gnome-nibbles.6
+++ b/data/gnome-nibbles.6
@@ -44,6 +44,15 @@ Set number of players (1-4)
 .TP
 .B \-p, \-\-speed=NUMBER
 Set worms speed (4-1: 4 for slowest and 1 for fastest)
+.PP
+.B \-\-mute
+.br
+.B \-\-unmute
+.RS 7
+Turn off/on the sound;
+.br
+If the two options are given, the game is muted
+.RE
 .TP
 .B \-v, \-\-version
 Print release version and exit
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index a9cea7c..a18bd34 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -38,6 +38,7 @@ private class Nibbles : Gtk.Application
     private static int nibbles          = int.MIN;
     private static int players          = int.MIN;
     private static int speed            = int.MIN;
+    private static bool? sound          = null;
     private const OptionEntry[] option_entries =
     {
         /* Translators: command-line option description, see 'gnome-nibbles --help' */
@@ -52,6 +53,9 @@ private class Nibbles : Gtk.Application
         /* Translators: in the command-line options description, text to indicate the user should specify 
the start level, see 'gnome-nibbles --help' */
                                                                                     N_("NUMBER") },
 
+        /* Translators: command-line option description, see 'gnome-nibbles --help' */
+        { "mute",           0,   OptionFlags.NONE, OptionArg.NONE,  null,           N_("Turn off the 
sound"),                   null },
+
         /* Translators: command-line option description, see 'gnome-nibbles --help' */
         { "nibbles",        'n', OptionFlags.NONE, OptionArg.INT,   ref nibbles,    N_("Set number of 
nibbles (4-6)"),
 
@@ -70,6 +74,9 @@ private class Nibbles : Gtk.Application
         /* Translators: in the command-line options description, text to indicate the user should specify 
the worms speed, see 'gnome-nibbles --help' */
                                                                                     N_("NUMBER") },
 
+        /* Translators: command-line option description, see 'gnome-nibbles --help' */
+        { "unmute",         0,   OptionFlags.NONE, OptionArg.NONE,  null,           N_("Turn on the sound"), 
                   null },
+
         /* Translators: command-line option description, see 'gnome-nibbles --help' */
         { "version",        'v', OptionFlags.NONE, OptionArg.NONE,  null,           N_("Show release 
version"),                 null },
         {}
@@ -135,6 +142,11 @@ private class Nibbles : Gtk.Application
             return Posix.EXIT_FAILURE;
         }
 
+        if (options.contains ("mute"))
+            sound = false;
+        else if (options.contains ("unmute"))
+            sound = true;
+
         /* Activate */
         return -1;
     }
@@ -173,7 +185,8 @@ private class Nibbles : Gtk.Application
          || players_changed
          || speed != int.MIN
          || disable_fakes
-         || enable_fakes)
+         || enable_fakes
+         || sound != null)
         {
             GLib.Settings settings = new GLib.Settings ("org.gnome.Nibbles");
             if (nibbles_changed && players_changed)
@@ -200,6 +213,9 @@ private class Nibbles : Gtk.Application
                 settings.set_boolean ("fakes", false);
             else if (enable_fakes)
                 settings.set_boolean ("fakes", true);
+
+            if (sound != null)
+                settings.set_boolean ("sound", (!) sound);
         }
 
         window = new NibblesWindow (level == int.MIN ? 0 : level);


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