[gnome-documents/wip/getting-started: 2/3] Set up watches for the getting started document



commit 4153fe66daba156eb6be3de87a04bcd35e3ee942
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Feb 26 23:41:50 2013 -0500

    Set up watches for the getting started document

 configure.ac        |    1 +
 src/Makefile-lib.am |    1 +
 src/application.js  |   45 +++++++++++++++++++++++++++++++++++++++++++++
 src/lib/gd-utils.c  |   37 +++++++++++++++++++++++++++++++++++++
 src/lib/gd-utils.h  |   10 ++++++++++
 src/search.js       |    8 +++++++-
 6 files changed, 101 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8ca3e1f..18a15b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,7 @@ PKG_CHECK_MODULES(DOCUMENTS,
                   gtk+-3.0 >= $GTK_MIN_VERSION
                   libsoup-2.4 >= $SOUP_MIN_VERSION
                   gnome-desktop-3.0
+                  tracker-miner-0.16 >= $TRACKER_MIN_VERSION
                   tracker-sparql-0.16 >= $TRACKER_MIN_VERSION
                   goa-1.0 >= $GOA_MIN_VERSION
                   libgdata >= $GDATA_MIN_VERSION
diff --git a/src/Makefile-lib.am b/src/Makefile-lib.am
index 51347b5..6b7385f 100644
--- a/src/Makefile-lib.am
+++ b/src/Makefile-lib.am
@@ -63,6 +63,7 @@ GdPrivate_1_0_gir_INCLUDES = \
    Gtk-3.0 \
    EvinceDocument-3.0 \
    EvinceView-3.0 \
+   TrackerMiner-0.16 \
    Zpj-0.0
 
 GdPrivate_1_0_gir_FILES = \
diff --git a/src/application.js b/src/application.js
index e691c05..8ef5419 100644
--- a/src/application.js
+++ b/src/application.js
@@ -34,12 +34,14 @@ imports.gi.versions.EvinceDocument = '3.0';
 imports.gi.versions.Goa = '1.0';
 
 const EvDoc = imports.gi.EvinceDocument;
+const GdPrivate = imports.gi.GdPrivate;
 const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
 const Goa = imports.gi.Goa;
 const Gtk = imports.gi.Gtk;
 const GLib = imports.gi.GLib;
 const Tracker = imports.gi.Tracker;
+const TrackerMiner = imports.gi.TrackerMiner;
 
 const ChangeMonitor = imports.changeMonitor;
 const Documents = imports.documents;
@@ -103,6 +105,48 @@ const Application = new Lang.Class({
                       inactivity_timeout: 12000 });
     },
 
+    _initGettingStarted: function() {
+        let manager = TrackerMiner.MinerManager.new_full(false);
+
+        let languages = GLib.get_language_names();
+        let files = languages.map(
+            function(language) {
+                return Gio.File.new_for_path(Path.RESOURCE_DIR + '/getting-started/' + language +
+                    '/gnome-documents-getting-started.pdf');
+            });
+
+        this.gettingStartedLocation = Gio.File.new_for_path(Path.RESOURCE_DIR + '/getting-started');
+
+        function checkNextFile(obj) {
+            let file = files.shift();
+            if (!file) {
+                log('Can\'t find a valid getting started PDF document');
+                return;
+            }
+
+            file.query_info_async('standard::type', Gio.FileQueryInfoFlags.NONE, 0, null, Lang.bind(this,
+                function(object, res) {
+                    try {
+                        let info = object.query_info_finish(res);
+                        this.gettingStartedLocation = file.get_parent();
+
+                        GdPrivate.tracker_miner_manager_index_file_async(manager, file,
+                            function(object, res) {
+                                try {
+                                    GdPrivate.tracker_miner_manager_index_file_finish(object, res);
+                                } catch (e) {
+                                    log('Error indexing the getting started PDF: ' + e.message);
+                                }
+                            });
+                    } catch (e) {
+                        checkNextFile.apply(this);
+                    }
+                }));
+        }
+
+        checkNextFile.apply(this);
+    },
+
     _fullscreenCreateHook: function(action) {
         modeController.connect('can-fullscreen-changed', Lang.bind(this,
             function() {
@@ -420,6 +464,7 @@ const Application = new Lang.Class({
 
         this._initActions();
         this._initAppMenu();
+        this._initGettingStarted();
     },
 
     _createWindow: function() {
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index f9e3dab..eb5d4cd 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -434,3 +434,40 @@ gd_ev_view_find_changed (EvView *view,
                         ev_job_find_get_results (job),
                         page);
 }
+
+static void
+miner_manager_index_file_thread (GTask *task,
+                                 gpointer source_object,
+                                 gpointer task_data,
+                                 GCancellable *cancellable)
+{
+  TrackerMinerManager *manager = source_object;
+  GFile *file = task_data;
+  GError *error = NULL;
+
+  tracker_miner_manager_index_file (manager, file, &error);
+  if (error != NULL)
+    g_task_return_error (task, error);
+  else
+    g_task_return_boolean (task, TRUE);
+}
+
+void
+gd_tracker_miner_manager_index_file_async (TrackerMinerManager *manager,
+                                           GFile *file,
+                                           GAsyncReadyCallback callback,
+                                           gpointer user_data)
+{
+  GTask *task = g_task_new (manager, NULL, callback, user_data);
+  g_task_set_task_data (task, g_object_ref (file), (GDestroyNotify) g_object_unref);
+  g_task_run_in_thread (task, miner_manager_index_file_thread);
+  g_object_unref (task);
+}
+
+gboolean
+gd_tracker_miner_manager_index_file_finish (TrackerMinerManager *manager,
+                                            GAsyncResult *result,
+                                            GError **error)
+{
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index eb2aa32..fe0bb6a 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -24,6 +24,7 @@
 
 #include <gtk/gtk.h>
 #include <evince-view.h>
+#include <libtracker-miner/tracker-miner.h>
 
 void gd_queue_thumbnail_job_for_file_async (GFile *file,
                                             GAsyncReadyCallback callback,
@@ -53,5 +54,14 @@ void gd_ev_view_find_changed (EvView *view,
                               EvJobFind *job,
                               gint page);
 
+void gd_tracker_miner_manager_index_file_async (TrackerMinerManager *manager,
+                                                GFile *file,
+                                                GAsyncReadyCallback callback,
+                                                gpointer user_data);
+
+gboolean gd_tracker_miner_manager_index_file_finish (TrackerMinerManager *manager,
+                                                     GAsyncResult *result,
+                                                     GError **error);
+
 #endif /* __GD_UTILS_H__ */
                                   
diff --git a/src/search.js b/src/search.js
index bbe7a52..1fb0380 100644
--- a/src/search.js
+++ b/src/search.js
@@ -307,6 +307,10 @@ const Source = new Lang.Class({
         this.builtin = params.builtin;
     },
 
+    _getGettingStartedLocations: function() {
+        return Application.application.gettingStartedLocation;
+    },
+
     _getTrackerLocations: function() {
         let settings = new Gio.Settings({ schema: TRACKER_SCHEMA });
         let locations = settings.get_strv(TRACKER_KEY_RECURSIVE_DIRECTORIES);
@@ -351,7 +355,9 @@ const Source = new Lang.Class({
 
     _buildFilterLocal: function() {
         let locations = this._getBuiltinLocations();
-        locations = locations.concat(this._getTrackerLocations());
+        locations = locations.concat(
+            this._getTrackerLocations(),
+            this._getGettingStartedLocations());
 
         let filters = [];
         locations.forEach(Lang.bind(this,


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