[gnome-documents] application: turn into a DBusActivatable service



commit 04d89d16cfb3e9fc54569333735e7d5761142cf7
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jan 20 15:26:59 2014 -0800

    application: turn into a DBusActivatable service
    
    Use the new DBusActivatable features in GtkApplication to turn
    gnome-documents into a DBus-activated service.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722662

 .gitignore                                         |    9 ++---
 configure.ac                                       |    1 -
 data/Makefile.am                                   |   11 +++---
 ...a.xml.in => org.gnome.Documents.appdata.xml.in} |    2 +-
 ...esktop.in.in => org.gnome.Documents.desktop.in} |    1 +
 ...ini => org.gnome.Documents.search-provider.ini} |    4 +-
 po/POTFILES.in                                     |    4 +-
 src/Makefile.am                                    |   24 +++++++-------
 src/application.js                                 |   35 ++++++++++++--------
 src/gnome-documents                                |    3 ++
 ...ome-documents.in => gnome-documents-service.in} |    0
 src/org.gnome.Documents.SearchProvider.service.in  |    3 --
 src/org.gnome.Documents.service.in                 |    3 ++
 src/shellSearchProvider.js                         |   19 +++-------
 14 files changed, 60 insertions(+), 59 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 225db6f..ee9203a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,9 +17,8 @@ config.log
 config.status
 config
 configure
-data/gnome-documents.appdata.xml
-data/gnome-documents.desktop
-data/gnome-documents.desktop.in
+data/org.gnome.Documents.appdata.xml
+data/org.gnome.Documents.desktop
 data/org.gnome.Documents.enums.xml
 data/org.gnome.documents.gschema.valid
 intltool-extract.in
@@ -47,11 +46,11 @@ src/Makefile
 src/Makefile.in
 src/gd-tracker-gdata-miner
 src/gd-tracker-zpj-miner
-src/gnome-documents
 src/gnome-documents-debug
+src/gnome-documents-service
 src/gnome-documents-search-provider
 src/path.js
-src/org.gnome.Documents.SearchProvider.service
+src/org.gnome.Documents.service
 src/gnome-documents.gresource
 stamp-h1
 xmldocs.make
diff --git a/configure.ac b/configure.ac
index 127878a..fc65e37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -113,7 +113,6 @@ libgd/Makefile
 src/Makefile
 data/Makefile
 data/icons/Makefile
-data/gnome-documents.desktop.in
 getting-started/Makefile
 man/Makefile
 po/Makefile.in
diff --git a/data/Makefile.am b/data/Makefile.am
index 524540f..d8fceee 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -2,21 +2,21 @@ SUBDIRS = icons
 
 appdatadir = $(datadir)/appdata
 appdata_DATA = $(appdata_in_files:.xml.in=.xml)
-appdata_in_files = gnome-documents.appdata.xml.in
+appdata_in_files = org.gnome.Documents.appdata.xml.in
 
 @INTLTOOL_XML_RULE@
 
 desktopdir = $(datadir)/applications
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
-desktop_in_files = gnome-documents.desktop.in
+desktop_in_files = org.gnome.Documents.desktop.in
 
 searchproviderdir = $(datadir)/gnome-shell/search-providers
-searchprovider_DATA = gnome-documents-search-provider.ini
+searchprovider_DATA = org.gnome.Documents.search-provider.ini
 
 @INTLTOOL_DESKTOP_RULE@
 
-check-local: gnome-documents.desktop
-       $(DESKTOP_FILE_VALIDATE) gnome-documents.desktop
+check-local: org.gnome.Documents.desktop
+       $(DESKTOP_FILE_VALIDATE) org.gnome.Documents.desktop
 
 gsettings_ENUM_NAMESPACE = org.gnome.Documents
 gsettings_ENUM_FILES = \
@@ -28,7 +28,6 @@ gsettings_SCHEMAS = org.gnome.documents.gschema.xml
 @GSETTINGS_RULES@
 
 EXTRA_DIST= \
-    gnome-documents.desktop \
     $(appdata_in_files) \
     $(desktop_in_files) \
     $(searchprovider_DATA) \
diff --git a/data/gnome-documents.appdata.xml.in b/data/org.gnome.Documents.appdata.xml.in
similarity index 95%
rename from data/gnome-documents.appdata.xml.in
rename to data/org.gnome.Documents.appdata.xml.in
index 85390dd..dd687cc 100644
--- a/data/gnome-documents.appdata.xml.in
+++ b/data/org.gnome.Documents.appdata.xml.in
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <application>
-  <id type="desktop">gnome-documents.desktop</id>
+  <id type="desktop">org.gnome.Documents.desktop</id>
   <licence>CC0</licence>
   <_name>Documents</_name>
   <_summary>A document manager application for GNOME</_summary>
diff --git a/data/gnome-documents.desktop.in.in b/data/org.gnome.Documents.desktop.in
similarity index 92%
rename from data/gnome-documents.desktop.in.in
rename to data/org.gnome.Documents.desktop.in
index 8c74bfd..d28ec7b 100644
--- a/data/gnome-documents.desktop.in.in
+++ b/data/org.gnome.Documents.desktop.in
@@ -6,6 +6,7 @@ Icon=gnome-documents
 Terminal=false
 Type=Application
 StartupNotify=true
+DBusActivatable=true
 OnlyShowIn=GNOME;
 Categories=GNOME;GTK;Utility;Core;
 _Keywords=Docs;PDF;Document;
diff --git a/data/gnome-documents-search-provider.ini b/data/org.gnome.Documents.search-provider.ini
similarity index 51%
rename from data/gnome-documents-search-provider.ini
rename to data/org.gnome.Documents.search-provider.ini
index ee40eee..5cd80d8 100644
--- a/data/gnome-documents-search-provider.ini
+++ b/data/org.gnome.Documents.search-provider.ini
@@ -1,5 +1,5 @@
 [Shell Search Provider]
-DesktopId=gnome-documents.desktop
-BusName=org.gnome.Documents.SearchProvider
+DesktopId=org.gnome.Documents.desktop
+BusName=org.gnome.Documents
 ObjectPath=/org/gnome/Documents/SearchProvider
 Version=2
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4b627ca..5b369e5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,6 @@
 [encoding: UTF-8]
-data/gnome-documents.appdata.xml.in
-data/gnome-documents.desktop.in.in
+data/org.gnome.Documents.appdata.xml.in
+data/org.gnome.Documents.desktop.in
 data/org.gnome.documents.gschema.xml
 src/application.js
 src/documents.js
diff --git a/src/Makefile.am b/src/Makefile.am
index 20b32e1..caa17ea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ pkglib_LTLIBRARIES =
 INTROSPECTION_GIRS =
 gir_DATA =
 typelib_DATA =
+bin_SCRIPTS =
 libexec_PROGRAMS =
 libexec_SCRIPTS =
 
@@ -55,25 +56,24 @@ typelib_DATA += $(gir_DATA:.gir=.typelib)
 
 CLEANFILES += $(gir_DATA) $(typelib_DATA)
 
-bin_SCRIPTS = gnome-documents
-
-gnome-documents: gnome-documents.in
+libexec_SCRIPTS += gnome-documents-service
+gnome-documents-service: gnome-documents-service.in
        $(AM_V_GEN) $(do_subst) $< > $@
        chmod +x $@
 
 CLEANFILES += \
-    gnome-documents
+    gnome-documents-service
 EXTRA_DIST += \
-    gnome-documents.in
-
-service_in_files = org.gnome.Documents.SearchProvider.service.in
+    gnome-documents-service.in
 
+service_in_files = org.gnome.Documents.service.in
 servicedir = $(datadir)/dbus-1/services
-service_DATA = $(service_in_files:.service.in=.service)
-
-%.service: %.service.in Makefile
-       $(AM_V_GEN) [ -d $(@D) ] || $(mkdir_p) $(@D) ; \
-                   sed -e "s|\ bindir\@|$(bindir)|" $< > $  tmp && mv $  tmp $@
+service_DATA = org.gnome.Documents.service
+org.gnome.Documents.service: org.gnome.Documents.service.in
+       $(AM_V_GEN) $(do_subst) $< > $@
 
 CLEANFILES += $(service_DATA)
 EXTRA_DIST += $(service_in_files)
+
+bin_SCRIPTS += gnome-documents
+EXTRA_DIST += gnome-documents
diff --git a/src/application.js b/src/application.js
index 78d7c5f..7ad087b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -103,8 +103,12 @@ const Application = new Lang.Class({
         GLib.set_application_name(_("Documents"));
 
         this.parent({ application_id: 'org.gnome.Documents',
-                      flags: Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
+                      flags: Gio.ApplicationFlags.IS_SERVICE,
                       inactivity_timeout: 12000 });
+
+        this._searchProvider = new ShellSearchProvider.ShellSearchProvider();
+        this._searchProvider.connect('activate-result', Lang.bind(this, this._onActivateResult));
+        this._searchProvider.connect('launch-search', Lang.bind(this, this._onLaunchSearch));
     },
 
     _initGettingStarted: function() {
@@ -385,12 +389,10 @@ const Application = new Lang.Class({
         }
 
         connectionQueue = new TrackerController.TrackerConnectionQueue();
-        this._searchProvider = new ShellSearchProvider.ShellSearchProvider();
-        this._searchProvider.connect('activate-result', Lang.bind(this, this._onActivateResult));
-        this._searchProvider.connect('launch-search', Lang.bind(this, this._onLaunchSearch));
 
         // now init application components
         Search.initSearch(imports.application);
+        Search.initSearch(imports.shellSearchProvider);
 
         changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
         documentManager = new Documents.DocumentManager();
@@ -498,22 +500,27 @@ const Application = new Lang.Class({
         this._startMiners();
     },
 
-    vfunc_activate: function() {
-        if (this._mainWindow) {
-            this._mainWindow.window.present_with_time(this._activationTimestamp);
-            this._activationTimestamp = Gdk.CURRENT_TIME;
-        }
+    vfunc_dbus_register: function(connection, path) {
+        this.parent(connection, path);
+
+        this._searchProvider.export(connection);
+        return true;
+    },
+
+    vfunc_dbus_unregister: function(connection, path) {
+        this._searchProvider.unexport(connection);
+
+        this.parent(connection, path);
     },
 
-    vfunc_command_line: function(cmdline) {
-        let args = cmdline.get_arguments();
-        if (args.indexOf('--no-default-window') == -1) {
+    vfunc_activate: function() {
+        if (!this._mainWindow) {
             this._createWindow();
             modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
         }
 
-        this.activate();
-        return 0;
+        this._mainWindow.window.present_with_time(this._activationTimestamp);
+        this._activationTimestamp = Gdk.CURRENT_TIME;
     },
 
     _clearState: function() {
diff --git a/src/gnome-documents b/src/gnome-documents
new file mode 100755
index 0000000..22daa2f
--- /dev/null
+++ b/src/gnome-documents
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+gapplication launch org.gnome.Documents
diff --git a/src/gnome-documents.in b/src/gnome-documents-service.in
similarity index 100%
rename from src/gnome-documents.in
rename to src/gnome-documents-service.in
diff --git a/src/org.gnome.Documents.service.in b/src/org.gnome.Documents.service.in
new file mode 100644
index 0000000..cb32a6e
--- /dev/null
+++ b/src/org.gnome.Documents.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Documents
+Exec= libexecdir@/gnome-documents-service
diff --git a/src/shellSearchProvider.js b/src/shellSearchProvider.js
index 35961cb..8bdf211 100644
--- a/src/shellSearchProvider.js
+++ b/src/shellSearchProvider.js
@@ -48,7 +48,6 @@ let searchController = null;
 let sourceManager = null;
 
 const SEARCH_PROVIDER_IFACE = 'org.gnome.Shell.SearchProvider2';
-const SEARCH_PROVIDER_NAME  = 'org.gnome.Documents.SearchProvider';
 const SEARCH_PROVIDER_PATH  = '/org/gnome/Documents/SearchProvider';
 
 const _SHELL_SEARCH_ICON_SIZE = 128;
@@ -361,23 +360,17 @@ const ShellSearchProvider = new Lang.Class({
     Name: 'ShellSearchProvider',
 
     _init: function() {
-        Application.application.hold();
-        Gio.DBus.own_name(Gio.BusType.SESSION,
-                          SEARCH_PROVIDER_NAME,
-                          Gio.BusNameOwnerFlags.NONE,
-                          Lang.bind(this, this._onBusAcquired),
-                          null, null);
-
+        this._impl = Gio.DBusExportedObject.wrapJSObject(SearchProviderIface, this);
         this._cache = {};
         this._cancellable = new Gio.Cancellable();
+    },
 
-        Search.initSearch(imports.shellSearchProvider);
+    export: function(connection) {
+        return this._impl.export(connection, SEARCH_PROVIDER_PATH);
     },
 
-    _onBusAcquired: function() {
-        let dbusImpl = Gio.DBusExportedObject.wrapJSObject(SearchProviderIface, this);
-        dbusImpl.export(Gio.DBus.session, SEARCH_PROVIDER_PATH);
-        Application.application.release();
+    unexport: function(connection) {
+        return this._impl.unexport_from_connection(connection);
     },
 
     _returnMetasFromCache: function(ids, invocation) {


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