""" The YouTube account indicator ============================= SageTube can use browser cookies to reach a signed-in YouTube: the account feed, age-restricted and members-only videos, and premium formats. All of that worked -- but the only way to switch it on was Downloads tab -> Custom Options -> the "Login with Cookies" tab, and Downloads is one tab among five. The three features that need it (the Feed's account mode, Search, Browse) had no route to it at all, and `show_cookie_login_dialog()` existed with no caller anywhere in the codebase. So this is a button in the tab bar's corner, visible from every tab, that says whether cookies are active and opens the existing dialog. Nothing about the cookie handling itself changes; it just became findable. """ from typing import Optional from PySide6.QtCore import Qt, Signal from PySide6.QtWidgets import QPushButton, QWidget from . import ytsage_icons as icons from . import ytsage_theme as theme from ..utils.ytsage_config_manager import ConfigManager from ..utils.ytsage_localization import _ class AccountStatusButton(QPushButton): """Shows the cookie state and opens the login dialog when pressed.""" loginRequested = Signal() def __init__(self, parent: Optional[QWidget] = None) -> None: super().__init__(parent) self.setObjectName("accountStatusButton") self.setCursor(Qt.CursorShape.PointingHandCursor) # Not a call to action -- it sits in the chrome, so it should not # compete with the accent-coloured buttons in the pages. self.setStyleSheet( f""" QPushButton#accountStatusButton {{ background-color: transparent; color: {theme.TEXT_MUTED}; border: 1px solid {theme.BORDER}; border-radius: 4px; padding: 5px 12px; margin: 4px 8px 4px 4px; font-weight: normal; }} QPushButton#accountStatusButton:hover {{ color: {theme.TEXT}; background-color: {theme.SURFACE_HOVER}; border-color: {theme.BORDER_STRONG}; }} QPushButton#accountStatusButton:pressed {{ background-color: {theme.BORDER}; }} """ ) self.clicked.connect(self.loginRequested) self.refresh() def refresh(self) -> None: """Re-read the cookie config and restate what it says.""" active = bool(ConfigManager.get("cookie_active")) if not active: self.setIcon(icons.icon("user", theme.TEXT_MUTED)) self.setText(_("account.signed_out")) self.setToolTip(_("account.signed_out_tooltip")) return if (ConfigManager.get("cookie_source") or "browser") == "file": source = _("account.source_file") else: browser = ConfigManager.get("cookie_browser") or "?" profile = ConfigManager.get("cookie_browser_profile") source = f"{browser}:{profile}" if profile else str(browser) self.setIcon(icons.icon("user-check", theme.TEXT)) self.setText(_("account.signed_in", source=source)) self.setToolTip(_("account.signed_in_tooltip", source=source))