Blame SOURCES/gnome-documents-getting-started.patch

408152
From e7f496a155da98fe6321b157b83c878001ea8fb8 Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Thu, 7 Dec 2017 20:11:39 +0100
408152
Subject: [PATCH 1/7] application: Insert the getting started PDF only when
408152
 showing a window
408152
408152
The startup is shared between the application and the search provider.
408152
There is no need to initialize the getting started PDF for the search
408152
provider, since it is only useful when the user runs the application.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/application.js | 6 +++---
408152
 1 file changed, 3 insertions(+), 3 deletions(-)
408152
408152
diff --git a/src/application.js b/src/application.js
408152
index 40506d48627b..73cb01767240 100644
408152
--- a/src/application.js
408152
+++ b/src/application.js
408152
@@ -488,9 +488,6 @@ var Application = new Lang.Class({
408152
               accels: ['<Primary>f'] }
408152
         ];
408152
 
408152
-        if (!this.isBooks)
408152
-            this._initGettingStarted();
408152
-
408152
         Utils.populateActionGroup(this, this._actionEntries, 'app');
408152
     },
408152
 
408152
@@ -498,6 +495,9 @@ var Application = new Lang.Class({
408152
         if (this._mainWindow)
408152
             return;
408152
 
408152
+        if (!this.isBooks)
408152
+            this._initGettingStarted();
408152
+
408152
         notificationManager = new Notifications.NotificationManager();
408152
         this._connectActionsToMode();
408152
         this._mainWindow = new MainWindow.MainWindow(this);
408152
-- 
408152
2.14.3
408152
408152
408152
From c98d19eaf7aeb20eea90d93ba1a0c9c112a2a3e7 Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Thu, 7 Dec 2017 20:53:10 +0100
408152
Subject: [PATCH 2/7] application: Make window creation complete asynchronously
408152
408152
Creating MainWindow starts the TrackerControllers. The getting started
408152
PDF needs to be located before that happens, to let the
408152
TrackerControllers include it in their queries. Since, locating the PDF
408152
is an asynchronous operation, the overall _createWindow method also
408152
needs to complete asynchronously.
408152
408152
This doesn't make any user-visible changes, but sets the stage for the
408152
subsequent patches.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/application.js | 81 ++++++++++++++++++++++++++++++++++++------------------
408152
 1 file changed, 54 insertions(+), 27 deletions(-)
408152
408152
diff --git a/src/application.js b/src/application.js
408152
index 73cb01767240..b80f22ddd03a 100644
408152
--- a/src/application.js
408152
+++ b/src/application.js
408152
@@ -491,9 +491,16 @@ var Application = new Lang.Class({
408152
         Utils.populateActionGroup(this, this._actionEntries, 'app');
408152
     },
408152
 
408152
-    _createWindow: function() {
408152
-        if (this._mainWindow)
408152
+    _createWindow: function(callback) {
408152
+        if (this._mainWindow) {
408152
+            Mainloop.idle_add(Lang.bind(this,
408152
+                function() {
408152
+                    callback();
408152
+                    return GLib.SOURCE_REMOVE;
408152
+                }));
408152
+
408152
             return;
408152
+        }
408152
 
408152
         if (!this.isBooks)
408152
             this._initGettingStarted();
408152
@@ -512,6 +519,20 @@ var Application = new Lang.Class({
408152
 
408152
         // start miners
408152
         this._startMiners();
408152
+
408152
+        Mainloop.idle_add(Lang.bind(this,
408152
+            function() {
408152
+                callback();
408152
+                return GLib.SOURCE_REMOVE;
408152
+            }));
408152
+    },
408152
+
408152
+    _presentWindow: function() {
408152
+        if (!this._mainWindow)
408152
+            throw(new Error('this._mainWindow == null'));
408152
+
408152
+        this._mainWindow.present_with_time(this._activationTimestamp);
408152
+        this._activationTimestamp = Gdk.CURRENT_TIME;
408152
     },
408152
 
408152
     vfunc_dbus_register: function(connection, path) {
408152
@@ -554,12 +575,14 @@ var Application = new Lang.Class({
408152
 
408152
     vfunc_activate: function() {
408152
         if (!this._mainWindow) {
408152
-            this._createWindow();
408152
-            modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
408152
+            this._createWindow(Lang.bind(this,
408152
+                function() {
408152
+                    modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
408152
+                    this._presentWindow();
408152
+                }));
408152
+        } else {
408152
+            this._presentWindow();
408152
         }
408152
-
408152
-        this._mainWindow.present_with_time(this._activationTimestamp);
408152
-        this._activationTimestamp = Gdk.CURRENT_TIME;
408152
     },
408152
 
408152
     _clearState: function() {
408152
@@ -598,22 +621,24 @@ var Application = new Lang.Class({
408152
     },
408152
 
408152
     _onActivateResult: function(provider, urn, terms, timestamp) {
408152
-        this._createWindow();
408152
-        modeController.setWindowMode(WindowMode.WindowMode.PREVIEW_EV);
408152
-
408152
-        let doc = documentManager.getItemById(urn);
408152
-        if (doc) {
408152
-            doActivate.apply(this, [doc]);
408152
-        } else {
408152
-            let job = new TrackerUtils.SingleItemJob(urn, queryBuilder);
408152
-            job.run(Query.QueryFlags.UNFILTERED, Lang.bind(this,
408152
-                function(cursor) {
408152
-                    if (cursor)
408152
-                        doc = documentManager.addDocumentFromCursor(cursor);
408152
+        this._createWindow(Lang.bind(this,
408152
+            function() {
408152
+                modeController.setWindowMode(WindowMode.WindowMode.PREVIEW_EV);
408152
 
408152
+                let doc = documentManager.getItemById(urn);
408152
+                if (doc) {
408152
                     doActivate.apply(this, [doc]);
408152
-                }));
408152
-        }
408152
+                } else {
408152
+                    let job = new TrackerUtils.SingleItemJob(urn, queryBuilder);
408152
+                    job.run(Query.QueryFlags.UNFILTERED, Lang.bind(this,
408152
+                        function(cursor) {
408152
+                            if (cursor)
408152
+                                doc = documentManager.addDocumentFromCursor(cursor);
408152
+
408152
+                            doActivate.apply(this, [doc]);
408152
+                        }));
408152
+                }
408152
+            }));
408152
 
408152
         function doActivate(doc) {
408152
             documentManager.setActiveItem(doc);
408152
@@ -637,13 +662,15 @@ var Application = new Lang.Class({
408152
     },
408152
 
408152
     _onLaunchSearch: function(provider, terms, timestamp) {
408152
-        this._createWindow();
408152
-        modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
408152
-        searchController.setString(terms.join(' '));
408152
-        this.change_action_state('search', GLib.Variant.new('b', true));
408152
+        this._createWindow(Lang.bind(this,
408152
+            function() {
408152
+                modeController.setWindowMode(WindowMode.WindowMode.DOCUMENTS);
408152
+                searchController.setString(terms.join(' '));
408152
+                this.change_action_state('search', GLib.Variant.new('b', true));
408152
 
408152
-        this._activationTimestamp = timestamp;
408152
-        this.activate();
408152
+                this._activationTimestamp = timestamp;
408152
+                this.activate();
408152
+            }));
408152
     },
408152
 
408152
     getScaleFactor: function() {
408152
-- 
408152
2.14.3
408152
408152
408152
From 935d00626f3a3481e9ae13c0eadb146c10d9625a Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Fri, 8 Dec 2017 17:13:52 +0100
408152
Subject: [PATCH 3/7] application: Tie the catch block more tightly to the
408152
 failure site
408152
408152
Having a lot of code inside a try statement makes it harder to follow
408152
the error handling logic. The catch statements are far away from the
408152
code that can throw an exception, so it is difficult to match them
408152
together. Let's reduce the size of the try blocks by only using them
408152
for fallible operations.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/application.js | 22 ++++++++++++----------
408152
 1 file changed, 12 insertions(+), 10 deletions(-)
408152
408152
diff --git a/src/application.js b/src/application.js
408152
index b80f22ddd03a..8f9b6276ac0a 100644
408152
--- a/src/application.js
408152
+++ b/src/application.js
408152
@@ -149,19 +149,21 @@ var Application = new Lang.Class({
408152
                 function(object, res) {
408152
                     try {
408152
                         let info = object.query_info_finish(res);
408152
-                        this.gettingStartedLocation = file.get_parent();
408152
-
408152
-                        manager.index_file_async(file, null,
408152
-                            function(object, res) {
408152
-                                try {
408152
-                                    manager.index_file_finish(res);
408152
-                                } catch (e) {
408152
-                                    log('Error indexing the getting started PDF: ' + e.message);
408152
-                                }
408152
-                            });
408152
                     } catch (e) {
408152
                         checkNextFile.apply(this);
408152
+                        return;
408152
                     }
408152
+
408152
+                    this.gettingStartedLocation = file.get_parent();
408152
+
408152
+                    manager.index_file_async(file, null,
408152
+                        function(object, res) {
408152
+                            try {
408152
+                                manager.index_file_finish(res);
408152
+                            } catch (e) {
408152
+                                log('Error indexing the getting started PDF: ' + e.message);
408152
+                            }
408152
+                        });
408152
                 }));
408152
         }
408152
 
408152
-- 
408152
2.14.3
408152
408152
408152
From 2362a9b4b6e518ccc04d6d6c6d16f837e3df038d Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Fri, 8 Dec 2017 17:29:56 +0100
408152
Subject: [PATCH 4/7] application: Shuffle some code around
408152
408152
Having the _initGettingStarted method take care of the isBooks
408152
condition will make it easier to chain it with the window creation.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/application.js | 6 ++++--
408152
 1 file changed, 4 insertions(+), 2 deletions(-)
408152
408152
diff --git a/src/application.js b/src/application.js
408152
index 8f9b6276ac0a..81ae382770df 100644
408152
--- a/src/application.js
408152
+++ b/src/application.js
408152
@@ -127,6 +127,9 @@ var Application = new Lang.Class({
408152
     },
408152
 
408152
     _initGettingStarted: function() {
408152
+        if (this.isBooks)
408152
+            return;
408152
+
408152
         let manager = TrackerControl.MinerManager.new_full(false);
408152
 
408152
         let languages = GLib.get_language_names();
408152
@@ -504,8 +507,7 @@ var Application = new Lang.Class({
408152
             return;
408152
         }
408152
 
408152
-        if (!this.isBooks)
408152
-            this._initGettingStarted();
408152
+        this._initGettingStarted();
408152
 
408152
         notificationManager = new Notifications.NotificationManager();
408152
         this._connectActionsToMode();
408152
-- 
408152
2.14.3
408152
408152
408152
From 4f5d1073d2049422b36c4b809a3f2ae6e8db3f4c Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Fri, 8 Dec 2017 17:36:49 +0100
408152
Subject: [PATCH 5/7] application: Create the window only after detecting the
408152
 PDF
408152
408152
This ensures that the TrackerControllers are started after the getting
408152
started PDF has been initialized, so that it can be included in their
408152
queries.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/application.js | 55 +++++++++++++++++++++++++++++++++---------------------
408152
 1 file changed, 34 insertions(+), 21 deletions(-)
408152
408152
diff --git a/src/application.js b/src/application.js
408152
index 81ae382770df..3c7110323dc3 100644
408152
--- a/src/application.js
408152
+++ b/src/application.js
408152
@@ -126,9 +126,16 @@ var Application = new Lang.Class({
408152
                              _("Show the version of the program"), null);
408152
     },
408152
 
408152
-    _initGettingStarted: function() {
408152
-        if (this.isBooks)
408152
+    _initGettingStarted: function(callback) {
408152
+        if (this.isBooks) {
408152
+            Mainloop.idle_add(Lang.bind(this,
408152
+                function() {
408152
+                    callback();
408152
+                    return GLib.SOURCE_REMOVE;
408152
+                }));
408152
+
408152
             return;
408152
+        }
408152
 
408152
         let manager = TrackerControl.MinerManager.new_full(false);
408152
 
408152
@@ -145,6 +152,7 @@ var Application = new Lang.Class({
408152
             let file = files.shift();
408152
             if (!file) {
408152
                 log('Can\'t find a valid getting started PDF document');
408152
+                callback();
408152
                 return;
408152
             }
408152
 
408152
@@ -166,11 +174,17 @@ var Application = new Lang.Class({
408152
                             } catch (e) {
408152
                                 log('Error indexing the getting started PDF: ' + e.message);
408152
                             }
408152
+
408152
+                            callback();
408152
                         });
408152
                 }));
408152
         }
408152
 
408152
-        checkNextFile.apply(this);
408152
+        Mainloop.idle_add(Lang.bind(this,
408152
+            function() {
408152
+                checkNextFile.apply(this);
408152
+                return GLib.SOURCE_REMOVE;
408152
+            }));
408152
     },
408152
 
408152
     _fullscreenCreateHook: function(action) {
408152
@@ -507,27 +521,26 @@ var Application = new Lang.Class({
408152
             return;
408152
         }
408152
 
408152
-        this._initGettingStarted();
408152
-
408152
-        notificationManager = new Notifications.NotificationManager();
408152
-        this._connectActionsToMode();
408152
-        this._mainWindow = new MainWindow.MainWindow(this);
408152
-        this._mainWindow.connect('destroy', Lang.bind(this, this._onWindowDestroy));
408152
-
408152
-        try {
408152
-            this._extractPriority = TrackerExtractPriority();
408152
-            this._extractPriority.SetRdfTypesRemote(['nfo:Document']);
408152
-        } catch (e) {
408152
-            log('Unable to connect to the tracker extractor: ' + e.toString());
408152
-        }
408152
+        this.hold();
408152
+        this._initGettingStarted(Lang.bind(this,
408152
+            function() {
408152
+                this.release();
408152
+                notificationManager = new Notifications.NotificationManager();
408152
+                this._connectActionsToMode();
408152
+                this._mainWindow = new MainWindow.MainWindow(this);
408152
+                this._mainWindow.connect('destroy', Lang.bind(this, this._onWindowDestroy));
408152
+
408152
+                try {
408152
+                    this._extractPriority = TrackerExtractPriority();
408152
+                    this._extractPriority.SetRdfTypesRemote(['nfo:Document']);
408152
+                } catch (e) {
408152
+                    log('Unable to connect to the tracker extractor: ' + e.toString());
408152
+                }
408152
 
408152
-        // start miners
408152
-        this._startMiners();
408152
+                // start miners
408152
+                this._startMiners();
408152
 
408152
-        Mainloop.idle_add(Lang.bind(this,
408152
-            function() {
408152
                 callback();
408152
-                return GLib.SOURCE_REMOVE;
408152
             }));
408152
     },
408152
 
408152
-- 
408152
2.14.3
408152
408152
408152
From 95a69188445605be846adb94054a792c09b5e997 Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Tue, 12 Dec 2017 16:35:22 +0100
408152
Subject: [PATCH 6/7] trackerController: Don't submit queries until started
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/trackerController.js | 4 ++++
408152
 1 file changed, 4 insertions(+)
408152
408152
diff --git a/src/trackerController.js b/src/trackerController.js
408152
index 05b7e89f1586..55f1343f1417 100644
408152
--- a/src/trackerController.js
408152
+++ b/src/trackerController.js
408152
@@ -283,6 +283,10 @@ const TrackerController = new Lang.Class({
408152
             return;
408152
 
408152
         this.sortBy = sortBy;
408152
+
408152
+        if (!this._isStarted)
408152
+            return;
408152
+
408152
         this._refreshInternal(RefreshFlags.RESET_OFFSET);
408152
     },
408152
 
408152
-- 
408152
2.14.3
408152
408152
408152
From 9e57889aeaa9d56ca61059012cccc37a9145f92c Mon Sep 17 00:00:00 2001
408152
From: Debarshi Ray <debarshir@gnome.org>
408152
Date: Fri, 8 Dec 2017 20:47:17 +0100
408152
Subject: [PATCH 7/7] trackerController: Assert against premature queries
408152
408152
The TrackerControllers are only supposed to issue their queries once
408152
all the pieces of the application that are necessary to formulate them
408152
have been initialized. This is indicated by the invocation of the start
408152
method. For example, if the queries are submitted before the detection
408152
of the getting started PDF has completed, then they won't have the
408152
path to PDF and it will be missing from the UI.
408152
408152
Throwing an exception forces one to think about the details surrounding
408152
each query submission path, as opposed to having the silently dropping
408152
the request.
408152
408152
https://bugzilla.gnome.org/show_bug.cgi?id=791518
408152
---
408152
 src/trackerController.js | 4 +++-
408152
 1 file changed, 3 insertions(+), 1 deletion(-)
408152
408152
diff --git a/src/trackerController.js b/src/trackerController.js
408152
index 55f1343f1417..e45f3a7fc5c3 100644
408152
--- a/src/trackerController.js
408152
+++ b/src/trackerController.js
408152
@@ -234,7 +234,8 @@ const TrackerController = new Lang.Class({
408152
     },
408152
 
408152
     _refreshInternal: function(flags) {
408152
-        this._isStarted = true;
408152
+        if (!this._isStarted)
408152
+            throw(new Error('!this._isStarted'));
408152
 
408152
         if (flags & RefreshFlags.RESET_OFFSET)
408152
             this._offsetController.resetOffset();
408152
@@ -294,6 +295,7 @@ const TrackerController = new Lang.Class({
408152
         if (this._isStarted)
408152
             return;
408152
 
408152
+        this._isStarted = true;
408152
         this._refreshInternal(RefreshFlags.NONE);
408152
     }
408152
 });
408152
-- 
408152
2.14.3
408152