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



commit 6c5194a1ca6e813e56df709897c4468c7afd6abd
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 | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 29805fd6..80e635ca 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -125,18 +125,22 @@ 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 TrackerWrapper.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
+            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
+                print("wrapper", new_wrapper)
+            else:
+                grl_tracker_wrapper = self._wrappers[source.props.source_id]
+                registry.unregister_source(grl_tracker_wrapper.props.source)
+                grl_tracker_wrapper.props.source = source
         # elif source.props.source_id[:10] == "grl-dleyna":
         #     new_wrapper = GrlDLeynaWrapper(
         #         source, self._coremodel, self._coreselection, self)
         #     self._wrappers.append(new_wrapper)
-            print("wrapper", new_wrapper)
         elif (source.props.source_id not in self._search_wrappers.keys()
                 and source.props.source_id not in self._wrappers.keys()
                 and source.get_supported_media() & Grl.MediaType.AUDIO


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