[gnome-music/wip/jfelder/grilo-reload-tracker-source: 3/4] coregrilo: Replace tracker source if the plugin is already loaded



commit 7230d4eb52582d1c3d832efb73ff55c4317445d6
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Feb 19 16:36:10 2020 +0100

    coregrilo: Replace tracker source if the plugin is already loaded
    
    All grilo plugins are loaded at startup. However, TrackerWrapper may
    not be available yet. In that case, GrlTrackerWrapper is not
    created. Once TrackerWrapper becomes available, all grilo plugins are
    loaded again in order to instantiate GrlTrackerWrapper.
    
    However, TrackerWrapper may become available while the first tracker
    source is added. In that case, GrlTrackerWrapper is instantiated with a first source
    but a second source will be created by the second load_all_plugins
    call (a new tracker source is created everytime the tracker plugin is
    activated). Then, GrlTrackerWrapper won't get any notification because
    they will be associated with the second source and not the first one.
    
    This issue is fixed by replacing the GrlTrackerWrapper source
    everytime a new tracker source is created.

 gnomemusic/coregrilo.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 957f0a74..8809e6c2 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -138,14 +138,17 @@ class CoreGrilo(GObject.GObject):
 
         new_state = self._tracker_wrapper.props.tracker_available
         if (source.props.source_id == "grl-tracker-source"
-                and source.props.source_id not in self._wrappers.keys()
                 and self._tracker_wrapper.location_filter() is not None
                 and new_state == TrackerState.AVAILABLE):
-            new_wrapper = GrlTrackerWrapper(
-                source, self._coremodel, self._application, self,
-                self._tracker_wrapper)
-            self._wrappers[source.props.source_id] = new_wrapper
-            self._log.debug("Adding wrapper {}".format(new_wrapper))
+            if source.props.source_id not in self._wrappers.keys():
+                new_wrapper = GrlTrackerWrapper(
+                    source, self._coremodel, self._application, self,
+                    self._tracker_wrapper)
+                self._wrappers[source.props.source_id] = new_wrapper
+                self._log.debug("Adding wrapper {}".format(new_wrapper))
+            else:
+                grl_tracker_wrapper = self._wrappers[source.props.source_id]
+                grl_tracker_wrapper.props.source = source
         elif (source.props.source_id not in self._search_wrappers.keys()
                 and source.props.source_id not in self._wrappers.keys()
                 and source.props.source_id != "grl-tracker-source"


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