[polari/wip/fmuellner/tracker: 9/9] logManager: Try to start chatlog miner if not running



commit c5f2ec87aa11bb44297a9084ca0ba93160996d79
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 28 02:41:31 2016 +0200

    logManager: Try to start chatlog miner if not running

 configure.ac      |    1 +
 src/logManager.js |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 98cb082..c4e39a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,6 +53,7 @@ AX_CHECK_GIRS_GJS([Secret], [1])
 AX_CHECK_GIRS_GJS([Soup], [2.4])
 AX_CHECK_GIRS_GJS([TelepathyGLib], [0.12])
 AX_CHECK_GIRS_GJS([Tracker], [1.0])
+AX_CHECK_GIRS_GJS([TrackerControl], [1.0])
 
 AC_PROG_LN_S
 
diff --git a/src/logManager.js b/src/logManager.js
index 34aba40..71b5117 100644
--- a/src/logManager.js
+++ b/src/logManager.js
@@ -1,8 +1,14 @@
 const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const Tracker = imports.gi.Tracker;
+const TrackerControl = imports.gi.TrackerControl;
 const Tp = imports.gi.TelepathyGLib;
 
+const Utils = imports.utils;
+
+const CHATLOG_MINER_NAME = Tracker.DBUS_SERVICE + '.Miner.Chatlog';
+const CHATLOG_MINER_PATH = '/' + CHATLOG_MINER_NAME.replace('.', '/', 'g');
+
 let _logManager = null;
 
 function getDefault() {
@@ -195,9 +201,40 @@ const _LogManager = new Lang.Class({
     Name: 'LogManager',
 
     _init: function() {
+        this._ensureChatlogMiner();
         this._connection = Tracker.SparqlConnection.get(null);
     },
 
+    _ensureChatlogMiner: function() {
+        let running = false;
+        try {
+            let manager = TrackerControl.MinerManager.new_full(false);
+            [running,] = manager.get_status(CHATLOG_MINER_NAME);
+        } catch(e) {
+            Utils.debug('Unable to create MinerManager: ' + e.message);
+        }
+
+        if (running) {
+            Utils.debug('Detected running chatlog miner.');
+            return;
+        }
+
+       let flags = Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
+                   Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS;
+       Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION, flags, null,
+                                 CHATLOG_MINER_NAME, CHATLOG_MINER_PATH,
+                                 Tracker.DBUS_SERVICE + '.Miner',
+                                 null, (o, res) => {
+           let miner = null;
+           try {
+               miner = Gio.DBusProxy.new_for_bus_finish(res);
+               Utils.debug('Started chatlog miner.');
+           } catch(e) {
+               log('Failed to start chatlog miner: ' + e.message);
+           }
+       });
+    },
+
     query: function(sparql, cancellable, callback) {
         let query = new GenericQuery(this._connection);
         query.run(sparql, cancellable, callback);


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