[gnome-taquin] Make D-Bus activatable.



commit 1fbb415cb14dfc90f1ae5d094ebb2aa8612e9429
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Oct 26 19:28:48 2019 +0200

    Make D-Bus activatable.
    
    I hope.

 data/meson.build                 | 14 ++++++++++++++
 data/org.gnome.Taquin.desktop.in |  7 ++++---
 data/org.gnome.Taquin.service.in |  3 +++
 meson.build                      |  8 +++++---
 src/taquin-main.vala             | 27 ++++++++++++++++++++++++++-
 5 files changed, 52 insertions(+), 7 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 02e2577..9eb1c79 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -7,6 +7,20 @@ install_data(
     install_dir: soundsdir
 )
 
+# Make D-Bus activatable
+service_conf = configuration_data()
+service_conf.set('bindir', bindir)
+
+service = project_id + '.service'
+
+configure_file(
+  input: service + '.in',
+  output: service,
+  install: true,
+  install_dir: join_paths(datadir, 'dbus-1', 'services'),
+  configuration: service_conf
+)
+
 # Desktop file
 desktop_file = i18n.merge_file(
     input: '@0  desktop in'.format(project_id),
diff --git a/data/org.gnome.Taquin.desktop.in b/data/org.gnome.Taquin.desktop.in
index 981720c..37d9046 100644
--- a/data/org.gnome.Taquin.desktop.in
+++ b/data/org.gnome.Taquin.desktop.in
@@ -13,14 +13,15 @@ Terminal=false
 Type=Application
 Categories=GNOME;GTK;Game;LogicGame;
 StartupNotify=true
-Actions=Fifteen;Sixteen;
+DBusActivatable=true
+Actions=fifteen;sixteen;
 
-[Desktop Action Fifteen]
+[Desktop Action fifteen]
 # Translators: an action Name, as defined in the desktop file spec; name of the traditional Taquin game
 Name=15-Puzzle
 Exec=gnome-taquin --fifteen
 
-[Desktop Action Sixteen]
+[Desktop Action sixteen]
 # Translators: an action Name, as defined in the desktop file spec; name of the alternative game
 Name=16-Puzzle
 Exec=gnome-taquin --sixteen
diff --git a/data/org.gnome.Taquin.service.in b/data/org.gnome.Taquin.service.in
new file mode 100644
index 0000000..a813941
--- /dev/null
+++ b/data/org.gnome.Taquin.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Taquin
+Exec=@bindir@/gnome-taquin --gapplication-service
diff --git a/meson.build b/meson.build
index dffe775..5f79811 100644
--- a/meson.build
+++ b/meson.build
@@ -27,9 +27,11 @@ glib_compile_schema = find_program('glib-compile-schemas', required: true)
 
 add_global_arguments('-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name()), language: 'c')
 
-pkgdatadir = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
-localedir = join_paths(get_option('prefix'), get_option('localedir'))
-soundsdir = join_paths(pkgdatadir, 'sounds')
+localedir   = join_paths(get_option('prefix'), get_option('localedir'))
+datadir     = join_paths(get_option('prefix'), get_option('datadir'))
+bindir      = join_paths(get_option('prefix'), get_option('bindir'))
+pkgdatadir  = join_paths(datadir, meson.project_name())
+soundsdir   = join_paths(pkgdatadir, 'sounds')
 
 conf = configuration_data ()
 conf.set_quoted('VERSION', meson.project_version())
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 10c9475..88c2d37 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -72,6 +72,10 @@ private class Taquin : Gtk.Application, BaseApplication
 
     private const GLib.ActionEntry [] action_entries =
     {
+        /* these two are for actions defined in the desktop file, when using D-Bus activation */
+        {"fifteen", play_fifteen_game},
+        {"sixteen", play_sixteen_game},
+
         /* TODO SimpleActionChangeStateCallback is deprecated...
         {"change-size", null, "s", null, null, change_size_cb},     
http://valadoc.org/#!api=gio-2.0/GLib.SimpleActionChangeStateCallback
         {"change-theme", null, "s", null, null, change_theme_cb},   see comments about window.add_action 
(settings.create_action (…)) */
@@ -215,11 +219,32 @@ private class Taquin : Gtk.Application, BaseApplication
             init_sound ();
 
         add_window (window);
-        start_game ();
     }
 
     protected override void activate ()
     {
+        if (game == null)
+            start_game ();
+        window.present ();
+    }
+
+    private void play_fifteen_game ()
+    {
+        if (game == null)
+        {
+            settings.set_string ("type", "fifteen");
+            start_game ();
+        }
+        window.present ();
+    }
+
+    private void play_sixteen_game ()
+    {
+        if (game == null)
+        {
+            settings.set_string ("type", "sixteen");
+            start_game ();
+        }
         window.present ();
     }
 


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