Skip to content

Commit

Permalink
gui: introduce UISupportsDiscovery protocol (feeluown#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven authored and mokurin000 committed Jan 11, 2024
1 parent 06a4e5e commit ad2cea1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 16 additions & 1 deletion feeluown/gui/provider_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import abstractmethod, ABC
from typing import TYPE_CHECKING, runtime_checkable, Protocol, Dict, Optional, List

from PyQt5.QtCore import pyqtSignal, QObject

from feeluown.library import ProviderV2
from feeluown.gui.widgets.provider import ProvidersModel
from feeluown.utils.dispatch import Signal
Expand All @@ -17,6 +19,14 @@ def login_or_go_home(self):
...


@runtime_checkable
class UISupportsDiscovery(Protocol):

@abstractmethod
def discovery(self):
...


class AbstractProviderUi(ABC):
"""Abstract base class for provider ui."""

Expand All @@ -33,9 +43,12 @@ def provider(self) -> ProviderV2:
...


class CurrentProviderUiManager:
class CurrentProviderUiManager(QObject):

changed = pyqtSignal([object, object])

def __init__(self, app: 'GuiApp'):
super().__init__(parent=app)
self._app = app
self._current: Optional[AbstractProviderUi] = None

Expand All @@ -48,7 +61,9 @@ def get(self):

def set(self, provider_ui: AbstractProviderUi):
self._current_item = None
old = self._current
self._current = provider_ui
self.changed.emit(provider_ui, old)

def get_either(self):
return self._current or self._current_item
Expand Down
9 changes: 9 additions & 0 deletions feeluown/gui/uimain/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
PlusButton,
TriagleButton,
)
from feeluown.gui.provider_ui import UISupportsDiscovery
from feeluown.gui.widgets.playlists import PlaylistsView
from feeluown.gui.components import CollectionListView
from feeluown.gui.widgets.my_music import MyMusicView
from feeluown.gui.helpers import disconnect_slots_if_has

if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp
Expand Down Expand Up @@ -166,6 +168,8 @@ def __init__(self, app: 'GuiApp', parent=None):
self.collections_con.create_btn.clicked.connect(
self.popup_collection_adding_dialog)
self.playlists_con.create_btn.clicked.connect(self._create_playlist)
self._app.current_pvd_ui_mgr.changed.connect(
self.on_current_pvd_ui_changed)

def popup_collection_adding_dialog(self):
dialog = QDialog(self)
Expand Down Expand Up @@ -273,3 +277,8 @@ def do():
QMessageBox.Yes | QMessageBox.No, self)
box.accepted.connect(do)
box.open()

def on_current_pvd_ui_changed(self, pvd_ui, _):
disconnect_slots_if_has(self.discovery_btn)
if isinstance(pvd_ui, UISupportsDiscovery):
self.discovery_btn.clicked.connect(pvd_ui.discovery)

0 comments on commit ad2cea1

Please sign in to comment.