From e7a293cb280ff3be8fee80c29866f82693157982 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Sun, 12 Jul 2020 11:12:44 -0600 Subject: [PATCH] Closes #203: disable genre, year search types in Albums tab if API version < 1.10.1 --- sublime/adapters/adapter_base.py | 1 - sublime/adapters/filesystem/adapter.py | 1 - sublime/adapters/manager.py | 11 +--------- sublime/adapters/subsonic/adapter.py | 28 +++++++++++++++----------- sublime/ui/albums.py | 6 ++++++ 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/sublime/adapters/adapter_base.py b/sublime/adapters/adapter_base.py index 01cf6f0..b2f95b6 100644 --- a/sublime/adapters/adapter_base.py +++ b/sublime/adapters/adapter_base.py @@ -469,7 +469,6 @@ class Adapter(abc.ABC): :returns: A set of :class:`AlbumSearchQuery.Type` objects. """ - # TODO (#203): use this return set() @property diff --git a/sublime/adapters/filesystem/adapter.py b/sublime/adapters/filesystem/adapter.py index e071179..fc595e0 100644 --- a/sublime/adapters/filesystem/adapter.py +++ b/sublime/adapters/filesystem/adapter.py @@ -136,7 +136,6 @@ class FilesystemAdapter(CachingAdapter): return self._can_get_key(KEYS.GENRES) supported_schemes = ("file",) - # TODO (#203) supported_artist_query_types = { AlbumSearchQuery.Type.RANDOM, AlbumSearchQuery.Type.NEWEST, diff --git a/sublime/adapters/manager.py b/sublime/adapters/manager.py index 2fef9ec..fec7904 100644 --- a/sublime/adapters/manager.py +++ b/sublime/adapters/manager.py @@ -553,19 +553,10 @@ class AdapterManager: @staticmethod def get_supported_artist_query_types() -> Set[AlbumSearchQuery.Type]: assert AdapterManager._instance - - supported_artist_query_types: Set[AlbumSearchQuery.Type] = set() - supported_artist_query_types.union( + return ( AdapterManager._instance.ground_truth_adapter.supported_artist_query_types ) - if caching_adapter := AdapterManager._instance.caching_adapter: - supported_artist_query_types.union( - caching_adapter.supported_artist_query_types - ) - - return supported_artist_query_types - R = TypeVar("R") @staticmethod diff --git a/sublime/adapters/subsonic/adapter.py b/sublime/adapters/subsonic/adapter.py index bfd5ed8..55574f7 100644 --- a/sublime/adapters/subsonic/adapter.py +++ b/sublime/adapters/subsonic/adapter.py @@ -313,18 +313,22 @@ class SubsonicAdapter(Adapter): self._schemes = (urlparse(self.hostname)[0],) return self._schemes - # TODO (#203) make this way smarter - supported_artist_query_types = { - AlbumSearchQuery.Type.RANDOM, - AlbumSearchQuery.Type.NEWEST, - AlbumSearchQuery.Type.FREQUENT, - AlbumSearchQuery.Type.RECENT, - AlbumSearchQuery.Type.STARRED, - AlbumSearchQuery.Type.ALPHABETICAL_BY_NAME, - AlbumSearchQuery.Type.ALPHABETICAL_BY_ARTIST, - AlbumSearchQuery.Type.YEAR_RANGE, - AlbumSearchQuery.Type.GENRE, - } + @property + def supported_artist_query_types(self) -> Set[AlbumSearchQuery.Type]: + supported = { + AlbumSearchQuery.Type.RANDOM, + AlbumSearchQuery.Type.NEWEST, + AlbumSearchQuery.Type.FREQUENT, + AlbumSearchQuery.Type.RECENT, + AlbumSearchQuery.Type.STARRED, + AlbumSearchQuery.Type.ALPHABETICAL_BY_NAME, + AlbumSearchQuery.Type.ALPHABETICAL_BY_ARTIST, + } + if self.version_at_least("1.10.1"): + supported.add(AlbumSearchQuery.Type.YEAR_RANGE) + supported.add(AlbumSearchQuery.Type.GENRE) + + return supported # Helper mothods for making requests # ================================================================================== diff --git a/sublime/ui/albums.py b/sublime/ui/albums.py index f39693c..368bfed 100644 --- a/sublime/ui/albums.py +++ b/sublime/ui/albums.py @@ -230,6 +230,12 @@ class AlbumsPanel(Gtk.Box): def update(self, app_config: AppConfiguration = None, force: bool = False): self.updating_query = True + supported_type_strings = { + _to_type(t) for t in AdapterManager.get_supported_artist_query_types() + } + for i, el in enumerate(self.sort_type_combo_store): + self.sort_type_combo_store[i][2] = el[0] in supported_type_strings + # (En|Dis)able getting genres. self.sort_type_combo_store[1][2] = AdapterManager.can_get_genres()