[gnome-music/wip/jfelder/tracker-not-found-view: 3/3] app: Display an empty view when tracker cannot be found



commit cd3ade27b16833a8b41c007b1e42fff28867ef79
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Jan 30 11:26:44 2019 +0100

    app: Display an empty view when tracker cannot be found
    
    This new empty view is displayed if Tracker is not installed on the
    system.
    This occurs when the application cannot open a TrackerSparqlConnection
    or if the songs_available query cannot be executed.
    
    Closes: #165

 gnomemusic/grilo.py           | 20 +++++++++++++++-----
 gnomemusic/trackerwrapper.py  | 34 ++++++++++++++++++++++++++++++----
 gnomemusic/views/emptyview.py | 16 +++++++++++++++-
 gnomemusic/window.py          |  4 +++-
 4 files changed, 63 insertions(+), 11 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 2d58425e..0a81f641 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -30,7 +30,7 @@ gi.require_version('Grl', '0.3')
 from gi.repository import GLib, GObject
 from gnomemusic.query import Query
 from gnomemusic import log
-from gnomemusic.tracker import TrackerWrapper
+from gnomemusic.trackerwrapper import TrackerWrapper
 import logging
 import os
 os.environ['GRL_PLUGIN_RANKS'] = ("grl-local-metadata:5,"
@@ -82,6 +82,7 @@ class Grilo(GObject.GObject):
 
     sources = GObject.Property()
     cover_sources = GObject.Property(type=bool, default=False)
+    tracker_available = GObject.Property(type=bool, default=False)
 
     def __repr__(self):
         return '<Grilo>'
@@ -124,8 +125,12 @@ class Grilo(GObject.GObject):
 
         self.registry = Grl.Registry.get_default()
 
-        tracker_wrapper = TrackerWrapper()
-        self.tracker_sparql = tracker_wrapper.props.tracker
+        self._tracker_wrapper = TrackerWrapper()
+        self.tracker_sparql = self._tracker_wrapper.props.tracker
+        self._tracker_wrapper.bind_property(
+            "tracker-available", self, "tracker-available",
+            GObject.BindingFlags.BIDIRECTIONAL |
+            GObject.BindingFlags.SYNC_CREATE)
 
         self._find_sources()
 
@@ -500,6 +505,7 @@ class Grilo(GObject.GObject):
                 cursor = conn.query_finish(res)
             except GLib.Error as err:
                 logger.warning("Error: {}, {}".format(err.__class__, err))
+                self.props.tracker_available = False
                 callback(False)
                 return
 
@@ -507,8 +513,12 @@ class Grilo(GObject.GObject):
 
         # TODO: currently just checks tracker, should work with any
         # queryable supported Grilo source.
-        self.tracker_sparql.query_async(Query.all_songs_count(), None,
-                                        songs_query_cb, None)
+        if not self.props.tracker_available:
+            callback(False)
+            return
+
+        self.tracker_sparql.query_async(
+            Query.all_songs_count(), None, songs_query_cb, None)
 
 
 grilo = Grilo()
diff --git a/gnomemusic/trackerwrapper.py b/gnomemusic/trackerwrapper.py
index 2283ff15..66cb57df 100644
--- a/gnomemusic/trackerwrapper.py
+++ b/gnomemusic/trackerwrapper.py
@@ -33,15 +33,41 @@ class TrackerWrapper(GObject.GObject):
 
     def __init__(self):
         super().__init__()
-        self._tracker = None
         try:
             self._tracker = Tracker.SparqlConnection.get(None)
+            self._tracker_available = True
         except Exception as e:
-            from sys import exit
+            self._tracker = None
+            self._tracker_available = False
             logger.error(
-                "Cannot connect to tracker, error {}\nExiting".format(str(e)))
-            exit(1)
+                "Cannot connect to tracker, error {}\n".format(str(e)))
 
     @GObject.Property(type=object, flags=GObject.ParamFlags.READABLE)
     def tracker(self):
         return self._tracker
+
+    @GObject.Property(type=bool, default=False)
+    def tracker_available(self):
+        """Get Tracker availability.
+
+        Tracker is available if is SparqlConnection has been opened and
+        if a query can be
+
+        :returns: tracker availability
+        :rtype: bool
+        """
+        return self._tracker_available
+
+    @tracker_available.setter
+    def tracker_available(self, value):
+        """Set Tracker availability.
+
+        If a SparqlConnection has not been opened, Tracker availability
+        cannot be set to True.
+
+        :param bool value: new value
+        """
+        if self._tracker is None:
+            self._tracker_available = False
+        else:
+            self._tracker_available = value
diff --git a/gnomemusic/views/emptyview.py b/gnomemusic/views/emptyview.py
index ff31654d..e15ee658 100644
--- a/gnomemusic/views/emptyview.py
+++ b/gnomemusic/views/emptyview.py
@@ -48,6 +48,7 @@ class EmptyView(Gtk.Stack):
         INITIAL = 0
         EMPTY = 1
         SEARCH = 2
+        NO_TRACKER = 3
 
     __gtype_name__ = "EmptyView"
 
@@ -72,7 +73,7 @@ class EmptyView(Gtk.Stack):
 
         self._state = EmptyView.State.INITIAL
 
-    @GObject.Property(type=int, default=0, minimum=0, maximum=2)
+    @GObject.Property(type=int, default=0, minimum=0, maximum=3)
     def state(self):
         """Get the state of the empty view
 
@@ -94,6 +95,8 @@ class EmptyView(Gtk.Stack):
             self._set_empty_state()
         elif self._state == EmptyView.State.SEARCH:
             self._set_search_state()
+        elif self._state == EmptyView.State.NO_TRACKER:
+            self._set_no_tracker_state()
         self.show_all()
 
     @log
@@ -118,3 +121,14 @@ class EmptyView(Gtk.Stack):
         self._main_label.props.label = _("No music found")
         self._icon.props.margin_bottom = 18
         self._information_label.props.label = _("Try a different search")
+
+    @log
+    def _set_no_tracker_state(self):
+        self._main_label.props.margin_bottom = 12
+        self._main_label.props.label = _(
+            "GNOME Music could not connect to Tracker")
+        self._icon.props.margin_bottom = 18
+        self._information_label.props.label = _(
+            "Your music files cannot be indexed without Tracker running")
+
+        self._icon.props.icon_name = "dialog-error-symbolic"
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 539642a4..dd20b350 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -201,7 +201,9 @@ class Window(Gtk.ApplicationWindow):
     def _switch_to_empty_view(self):
         did_initial_state = self._settings.get_boolean('did-initial-state')
 
-        if did_initial_state:
+        if not grilo.props.tracker_available:
+            self.views[View.EMPTY].props.state = EmptyView.State.NO_TRACKER
+        elif did_initial_state:
             self.views[View.EMPTY].props.state = EmptyView.State.EMPTY
         else:
             self.views[View.EMPTY].props.state = EmptyView.State.INITIAL


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