[sushi/wip/cosimoc/no-clutter: 50/50] Use generated skeleton to export DBus interface



commit 6f6b2540af3e6e93683b1062e73ebba3bebe3766
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 17 11:29:33 2019 -0700

    Use generated skeleton to export DBus interface
    
    Generate a small GDBus library for the interface and use that, instead
    of hardcoding the interface XML in code.

 meson.build           |  3 ++-
 src/meson.build       | 27 +++++++++++++++++++++++++++
 src/ui/application.js | 31 ++++++++++++++-----------------
 3 files changed, 43 insertions(+), 18 deletions(-)
---
diff --git a/meson.build b/meson.build
index 6440c06..836ae68 100644
--- a/meson.build
+++ b/meson.build
@@ -2,7 +2,7 @@ project(
   'org.gnome.NautilusPreviewer',
   'c',
   version: '3.32.0',
-  meson_version: '>=0.42.0'
+  meson_version: '>=0.46.0'
 )
 
 epoxy_dep = dependency('epoxy')
@@ -10,6 +10,7 @@ evince_document_dep = dependency('evince-document-3.0')
 evince_view_dep = dependency('evince-view-3.0')
 freetype_dep = dependency('freetype2')
 gdk_pixbuf_dep = dependency('gdk-pixbuf-2.0', version: '>=2.23.0')
+gio_unix_dep = dependency('gio-unix-2.0', version: '>=2.29.14')
 gjs_dep = dependency('gjs-1.0', version: '>=1.38.0')
 glib_dep = dependency('glib-2.0', version: '>=2.29.14')
 gstreamer_dep = dependency('gstreamer-1.0')
diff --git a/src/meson.build b/src/meson.build
index a6fd150..6f7a728 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -40,6 +40,33 @@ sushi_src_resources = gnome.compile_resources(
     install_dir: pkgdatadir,
 )
 
+nautilus_previewer_dbus_sources = gnome.gdbus_codegen(
+    'nautilus-previewer-dbus',
+    sources: 'org.gnome.NautilusPreviewer.xml',
+    interface_prefix : 'org.gnome.',
+    annotations: ['org.gnome.NautilusPreviewer', 'org.gtk.GDBus.C.Name', 'NautilusPreviewerDBus']
+)
+
+nautilus_previewer_dbus_lib = shared_library(
+    'nautilus-previewer-dbus-1.0',
+    nautilus_previewer_dbus_sources,
+    version: meson.project_version(),
+    dependencies: [gio_unix_dep],
+    install: true,
+    install_dir: pkglibdir
+)
+
+gnome.generate_gir(
+    nautilus_previewer_dbus_lib,
+    sources: nautilus_previewer_dbus_sources,
+    namespace: 'NautilusPreviewerDBus',
+    nsversion: '1.0',
+    includes: ['Gio-2.0'],
+    install: true,
+    install_dir_gir: join_paths(pkgdatadir, 'gir-1.0'),
+    install_dir_typelib: join_paths(pkglibdir, 'girepository-1.0')
+)
+
 conf = configuration_data()
 conf.set('GJS', gjs.path())
 conf.set('PACKAGE_NAME', meson.project_name())
diff --git a/src/ui/application.js b/src/ui/application.js
index 20523cc..ccb7eda 100644
--- a/src/ui/application.js
+++ b/src/ui/application.js
@@ -23,24 +23,10 @@
  *
  */
 
-const {Gdk, Gio, GLib, GObject, Gtk} = imports.gi;
+const {Gdk, Gio, GObject, Gtk, NautilusPreviewerDBus} = imports.gi;
 
 const MainWindow = imports.ui.mainWindow;
 
-const SUSHI_DBUS_PATH = '/org/gnome/NautilusPreviewer';
-
-const SushiIface = '<node> \
-<interface name="org.gnome.NautilusPreviewer"> \
-<method name="ShowFile"> \
-    <arg type="s" direction="in" name="uri" /> \
-    <arg type="i" direction="in" name="xid" /> \
-    <arg type="b" direction="in" name="closeIfAlreadyShown" /> \
-</method> \
-<method name="Close"> \
-</method> \
-</interface> \
-</node>';
-
 var Application = GObject.registerClass(class Application extends Gtk.Application {
     vfunc_startup() {
         super.vfunc_startup();
@@ -49,12 +35,23 @@ var Application = GObject.registerClass(class Application extends Gtk.Applicatio
     }
 
     vfunc_dbus_register(connection, path) {
-        this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(SushiIface, this);
-        this._dbusImpl.export(connection, SUSHI_DBUS_PATH);
+        this._skeleton = new NautilusPreviewerDBus.Skeleton();
+        try {
+            this._skeleton.export(connection, path);
+        } catch (e) {
+            logError(e, 'Failed to export NautilusPreviewer DBus interface');
+        }
 
         return super.vfunc_dbus_register(connection, path);
     }
 
+    vfunc_dbus_unregister(connection, path) {
+        if (this._skeleton && this._skeleton.has_connection(connection))
+            this._skeleton.unexport_from_connection(connection);
+
+        return super.vfunc_dbus_unregister(connection, path);
+    }
+
     vfunc_activate() {
     }
 


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