Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: introduce UISupportsLoginEvent protocol #745

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions feeluown/gui/components/avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from PyQt5.QtWidgets import QMenu, QAction
from PyQt5.QtGui import QPainter, QIcon, QPalette, QContextMenuEvent

from feeluown.library import NoUserLoggedIn
from feeluown.library import NoUserLoggedIn, UserModel
from feeluown.models.uri import reverse
from feeluown.utils.aio import run_afn, run_fn
from feeluown.gui.provider_ui import UISupportsLoginOrGoHome, ProviderUiItem
from feeluown.gui.provider_ui import UISupportsLoginOrGoHome, ProviderUiItem, \
UISupportsLoginEvent
from feeluown.gui.widgets import SelfPaintAbstractSquareButton
from feeluown.gui.drawers import PixmapDrawer, AvatarIconDrawer

Expand Down Expand Up @@ -70,8 +71,18 @@ def contextMenuEvent(self, e) -> None:

menu.exec_(e.globalPos())

def on_provider_ui_login_event(self, provider_ui, event):
if event in (1, 2):
run_afn(self.show_pvd_ui_current_user)
run_afn(
self._app.ui.sidebar.show_provider_current_user_playlists,
provider_ui.provider
)

def on_pvd_ui_selected(self, pvd_ui):
self._app.current_pvd_ui_mgr.set(pvd_ui)
if isinstance(pvd_ui, UISupportsLoginEvent):
pvd_ui.login_event.connect(self.on_provider_ui_login_event)
if isinstance(pvd_ui, UISupportsLoginOrGoHome):
pvd_ui.login_or_go_home()
run_afn(self.show_pvd_ui_current_user)
Expand Down Expand Up @@ -105,7 +116,7 @@ async def _show_provider_current_user(self, name):

if user is None:
return None
if user.avatar_url:
if isinstance(user, UserModel) and user.avatar_url:
img_data = await run_afn(self._app.img_mgr.get, user.avatar_url,
reverse(user))
if img_data:
Expand Down
17 changes: 17 additions & 0 deletions feeluown/gui/provider_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ def login_or_go_home(self):
...


@runtime_checkable
class UISupportsLoginEvent(Protocol):

@property
@abstractmethod
def login_event(self):
"""
event:
0: first login failed
1: first login ok
2: re-login ok

:return: Signal(provider_ui, event)
"""
...


@runtime_checkable
class UISupportsDiscovery(Protocol):

Expand Down
12 changes: 12 additions & 0 deletions feeluown/gui/uimain/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
)
from feeluown.collection import CollectionAlreadyExists, CollectionType
from feeluown.utils import aio
from feeluown.utils.reader import create_reader
from feeluown.utils.aio import run_fn
from feeluown.gui.widgets import (
DiscoveryButton,
HomeButton,
Expand Down Expand Up @@ -99,6 +101,16 @@ def sizeHint(self):
width = min(self._app.width() * 22 // 100, 240)
return QSize(width, size.height())

async def show_provider_current_user_playlists(self, provider):
self.p.playlists_con.show()
self._app.pl_uimgr.clear()

playlists = await run_fn(provider.current_user_list_playlists)
reader = await run_fn(provider.current_user_fav_create_playlists_rd)
fav_playlists = create_reader(reader).readall()
self._app.pl_uimgr.add(playlists)
self._app.pl_uimgr.add(fav_playlists, is_fav=True)


class _LeftPanel(QFrame):

Expand Down
9 changes: 9 additions & 0 deletions feeluown/library/provider_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ def get_current_user(self) -> UserModel:
"""


@runtime_checkable
class SupportsCurrentUserListPlaylists(Protocol):
@abstractmethod
def current_user_list_playlists(self):
"""
: raises NoUserLoggedIn:
"""


#
# Protocols for current user favorites/collections
#
Expand Down
Loading