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

Improve the login dialog #335

Merged
merged 17 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0d62965
Dialogs: Make titles uniform
loathingKernel Dec 11, 2023
8c83f8a
InstallDialog: Add install_dir_edit widget without using an extra layout
loathingKernel Dec 11, 2023
64e9e31
BrowserLogin: Improve instructions
loathingKernel Dec 11, 2023
e188cee
BrowserLogin: Add privacy note
loathingKernel Dec 11, 2023
0ec80e5
LoginDialog: Set minimum size in a way that avoids resizing on changi…
loathingKernel Dec 11, 2023
60383d2
IndicatorLineEdit: Remove hint label
loathingKernel Dec 11, 2023
8e1a3c8
LoginDialog: Calculate a fixed height for the login stack based on width
loathingKernel Dec 11, 2023
3ce62fa
InstallDialog: Properly find the the row when `inserting install_dir_…
loathingKernel Dec 11, 2023
b5a18f2
ImportGroup: Properly find the row when inserting `path_edit` and `ap…
loathingKernel Dec 11, 2023
d563421
EGLSyncGroup: Properly find the correct rows to insert widgets
loathingKernel Dec 11, 2023
6c0a929
GameSettings: Properly find row to insert widgets.
loathingKernel Dec 11, 2023
0ef2497
QtRequests: Handle multiple requests concurrently and use caching
loathingKernel Dec 12, 2023
83dd118
ShopWidget: The shop is broken, set it only show the free games and t…
loathingKernel Dec 12, 2023
490f0dc
Shop: Rename module to `store`
loathingKernel Dec 12, 2023
9de5627
SideTabContainer: Set size policy for the container scrollarea contai…
loathingKernel Apr 10, 2023
f361828
Lgndr: Replace `_installed_lock` with a non-thread-local instance.
loathingKernel Dec 13, 2023
90acf4b
Lgndr: Make the decorator compatible with python 3.9
loathingKernel Dec 13, 2023
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
7 changes: 5 additions & 2 deletions rare/components/dialogs/install_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PyQt5.QtCore import Qt, QThreadPool, QSettings, QCoreApplication
from PyQt5.QtCore import pyqtSignal, pyqtSlot
from PyQt5.QtGui import QCloseEvent, QKeyEvent, QShowEvent
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox, QLayout, QWidget, QVBoxLayout
from PyQt5.QtWidgets import QDialog, QFileDialog, QCheckBox, QLayout, QWidget, QVBoxLayout, QFormLayout
from legendary.utils.selective_dl import get_sdl_appname

from rare.models.game import RareGame
Expand Down Expand Up @@ -85,7 +85,10 @@ def __init__(self, rgame: RareGame, options: InstallOptionsModel, parent=None):
save_func=self.save_install_edit,
parent=self,
)
self.ui.install_dir_layout.addWidget(self.install_dir_edit)
self.ui.install_dialog_layout.setWidget(
self.ui.install_dialog_layout.getWidgetPosition(self.ui.install_dir_label)[0],
QFormLayout.FieldRole, self.install_dir_edit
)

if self.options.update:
self.ui.install_dir_label.setEnabled(False)
Expand Down
24 changes: 22 additions & 2 deletions rare/components/dialogs/login/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import getLogger

from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QLayout, QDialog, QMessageBox, QFrame
from legendary.core import LegendaryCore

Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, core: LegendaryCore, parent=None):
self.args = ArgumentsSingleton()

self.login_stack = SlidingStackedWidget(parent=self)
self.login_stack.setMinimumSize(480, 180)
self.login_stack.setMinimumWidth(480)
self.ui.login_stack_layout.addWidget(self.login_stack)

self.landing_page = LandingPage(self.login_stack)
Expand All @@ -65,6 +65,26 @@ def __init__(self, core: LegendaryCore, parent=None):
self.import_page.success.connect(self.login_successful)
self.import_page.changed.connect(lambda: self.ui.next_button.setEnabled(self.import_page.is_valid()))

# # NOTE: The real problem is that the BrowserLogin page has a huge QLabel with word-wrapping enabled.
# # That forces the whole form to vertically expand instead of horizontally. Since the form is not shown
# # on the first page, the internal Qt calculation for the size of that form calculates it by expanding it
# # vertically. Once the form becomes visible, the correct calculation takes place and that is why the
# # dialog reduces in height. To avoid that, calculate the bounding size of all forms and set it as the
# # minumum size
# self.login_stack.setMinimumSize(
# self.landing_page.sizeHint().expandedTo(
# self.browser_page.sizeHint().expandedTo(self.import_page.sizeHint())
# )
# )

self.login_stack.setFixedHeight(
max(
self.landing_page.heightForWidth(self.login_stack.minimumWidth()),
self.browser_page.heightForWidth(self.login_stack.minimumWidth()),
self.import_page.heightForWidth(self.login_stack.minimumWidth()),
)
)

self.ui.next_button.setEnabled(False)
self.ui.back_button.setEnabled(False)

Expand Down
13 changes: 8 additions & 5 deletions rare/components/dialogs/login/browser_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from PyQt5.QtCore import pyqtSignal, QUrl
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QFrame, qApp
from PyQt5.QtWidgets import QFrame, qApp, QFormLayout, QLineEdit
from legendary.core import LegendaryCore
from legendary.utils import webview_login

Expand All @@ -31,11 +31,14 @@ def __init__(self, core: LegendaryCore, parent=None):
self.sid_edit = IndicatorLineEdit(
placeholder=self.tr("Insert authorizationCode here"), edit_func=self.text_changed, parent=self
)
self.sid_edit.line_edit.setEchoMode(QLineEdit.Password)
self.ui.link_text.setText(self.login_url)
self.ui.copy_button.setIcon(icon("mdi.content-copy", "fa.copy"))
self.ui.copy_button.clicked.connect(self.copy_link)

self.ui.sid_layout.addWidget(self.sid_edit)
self.ui.form_layout.setWidget(
self.ui.form_layout.getWidgetPosition(self.ui.sid_label)[0],
QFormLayout.FieldRole, self.sid_edit
)

self.ui.open_button.clicked.connect(self.open_browser)
self.sid_edit.textChanged.connect(self.changed.emit)
Expand Down Expand Up @@ -68,7 +71,7 @@ def do_login(self):
auth_code = self.sid_edit.text()
try:
if self.core.auth_code(auth_code):
logger.info(f"Successfully logged in as {self.core.lgd.userdata['displayName']}")
logger.info("Successfully logged in as %s", self.core.lgd.userdata['displayName'])
self.success.emit()
else:
self.ui.status_label.setText(self.tr("Login failed."))
Expand All @@ -82,7 +85,7 @@ def open_browser(self):
QDesktopServices.openUrl(QUrl(self.login_url))
else:
if webview_login.do_webview_login(callback_code=self.core.auth_ex_token):
logger.info("Successfully logged in as " f"{self.core.lgd.userdata['displayName']}")
logger.info("Successfully logged in as %s", {self.core.lgd.userdata['displayName']})
self.success.emit()
else:
logger.warning("Failed to login through browser.")
12 changes: 5 additions & 7 deletions rare/components/dialogs/login/import_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
class ImportLogin(QFrame):
success = pyqtSignal()
changed = pyqtSignal()

# FIXME: Use pathspec instead of duplicated code
if os.name == "nt":
localappdata = os.path.expandvars("%LOCALAPPDATA%")
else:
Expand Down Expand Up @@ -45,10 +47,6 @@ def __init__(self, core: LegendaryCore, parent=None):
if programdata_path := self.core.egl.programdata_path:
if wine_pfx := programdata_path.split("drive_c")[0]:
self.ui.prefix_combo.addItem(wine_pfx)
self.ui.info_label.setText(
self.tr("Please select the Wine prefix where Epic Games Launcher is installed. ")
+ self.ui.info_label.text()
)
prefixes = self.get_wine_prefixes()
if len(prefixes):
self.ui.prefix_combo.addItems(prefixes)
Expand Down Expand Up @@ -97,15 +95,15 @@ def do_login(self):
if os.name == "nt":
pass
else:
logger.info(f'Using EGL appdata path at "{self.egl_appdata}"')
logger.info("Using EGL appdata path at %s", {self.egl_appdata})
self.core.egl.appdata_path = self.egl_appdata
try:
if self.core.auth_import():
logger.info(f"Logged in as {self.core.lgd.userdata['displayName']}")
logger.info("Logged in as %s", {self.core.lgd.userdata['displayName']})
self.success.emit()
else:
self.ui.status_label.setText(self.tr("Login failed."))
logger.warning("Failed to import existing session.")
except Exception as e:
self.ui.status_label.setText(self.tr("Login failed. {}").format(str(e)))
logger.warning(f"Failed to import existing session: {e}")
logger.warning("Failed to import existing session: %s", e)
5 changes: 1 addition & 4 deletions rare/components/tabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .games import GamesTab
from .settings import SettingsTab
from .settings.debug import DebugSettings
from .shop import Shop
from .store import Shop
from .tab_widgets import MainTabBar, TabButtonWidget


Expand Down Expand Up @@ -86,9 +86,6 @@ def mouse_clicked(self, index):
if index == self.games_index:
self.games_tab.setCurrentWidget(self.games_tab.games_page)

if not self.args.offline and index == self.store_index:
self.store_tab.load()

def resizeEvent(self, event):
self.tab_bar.setMinimumWidth(self.width())
super(MainTabWidget, self).resizeEvent(event)
Expand Down
1 change: 1 addition & 0 deletions rare/components/tabs/games/game_info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def keyPressEvent(self, e: QKeyEvent):
class GameMetadataView(QTreeView, SideTabContents):
def __init__(self, parent=None):
super(GameMetadataView, self).__init__(parent=parent)
self.implements_scrollarea = True
self.setColumnWidth(0, 300)
self.setWordWrap(True)
self.model = QJsonModel()
Expand Down
5 changes: 2 additions & 3 deletions rare/components/tabs/games/game_info/game_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ def __init__(self, parent=None):
parent=self
)
self.ui.launch_settings_layout.insertRow(
int(self.ui.launch_settings_layout.indexOf(self.ui.launch_params)/2) + 1,
QLabel(self.tr("Override executable"), self),
self.override_exe_edit
self.ui.launch_settings_layout.getWidgetPosition(self.ui.launch_params)[0] + 1,
QLabel(self.tr("Override executable"), self), self.override_exe_edit
)

self.ui.game_settings_layout.setAlignment(Qt.AlignTop)
Expand Down
18 changes: 10 additions & 8 deletions rare/components/tabs/games/integrations/egl_sync_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from PyQt5.QtCore import Qt, QThreadPool, QRunnable, pyqtSlot, pyqtSignal
from PyQt5.QtGui import QShowEvent
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox, QFrame, QLabel
from PyQt5.QtWidgets import QGroupBox, QListWidgetItem, QFileDialog, QMessageBox, QFrame, QFormLayout
from legendary.models.egl import EGLManifest
from legendary.models.game import InstalledGame

Expand Down Expand Up @@ -39,25 +39,27 @@ def __init__(self, parent=None):
save_func=self.egl_path_edit_save_cb,
parent=self,
)
self.ui.egl_path_edit_layout.addWidget(self.egl_path_edit)
self.ui.egl_sync_layout.setWidget(
self.ui.egl_sync_layout.getWidgetPosition(self.ui.egl_path_edit_label)[0],
QFormLayout.FieldRole, self.egl_path_edit
)

self.egl_path_info_label = QLabel(self.tr("Estimated path"), self)
self.egl_path_info = ElideLabel(parent=self)
self.egl_path_info.setProperty("infoLabel", 1)
self.ui.egl_sync_layout.insertRow(
self.ui.egl_sync_layout.indexOf(self.ui.egl_path_edit_label) + 1,
self.egl_path_info_label, self.egl_path_info
self.ui.egl_sync_layout.setWidget(
self.ui.egl_sync_layout.getWidgetPosition(self.ui.egl_path_info_label)[0],
QFormLayout.FieldRole, self.egl_path_info
)

if platform.system() == "Windows":
self.ui.egl_path_edit_label.setEnabled(False)
self.egl_path_edit.setEnabled(False)
self.egl_path_info_label.setEnabled(False)
self.ui.egl_path_info_label.setEnabled(False)
self.egl_path_info.setEnabled(False)
else:
self.egl_path_edit.textChanged.connect(self.egl_path_changed)
if self.core.egl.programdata_path:
self.egl_path_info_label.setEnabled(True)
self.ui.egl_path_info_label.setEnabled(True)
self.egl_path_info.setEnabled(True)

self.ui.egl_sync_check.setChecked(self.core.egl_sync_enabled)
Expand Down
6 changes: 4 additions & 2 deletions rare/components/tabs/games/integrations/import_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def __init__(self, parent=None):
)
self.path_edit.textChanged.connect(self.path_changed)
self.ui.import_layout.setWidget(
self.ui.import_layout.indexOf(self.ui.path_edit_label), QFormLayout.FieldRole, self.path_edit
self.ui.import_layout.getWidgetPosition(self.ui.path_edit_label)[0],
QFormLayout.FieldRole, self.path_edit
)

self.app_name_edit = IndicatorLineEdit(
Expand All @@ -209,7 +210,8 @@ def __init__(self, parent=None):
)
self.app_name_edit.textChanged.connect(self.app_name_changed)
self.ui.import_layout.setWidget(
self.ui.import_layout.indexOf(self.ui.app_name_label), QFormLayout.FieldRole, self.app_name_edit
self.ui.import_layout.getWidgetPosition(self.ui.app_name_label)[0],
QFormLayout.FieldRole, self.app_name_edit
)

self.ui.import_folder_check.stateChanged.connect(self.import_folder_changed)
Expand Down
4 changes: 2 additions & 2 deletions rare/components/tabs/settings/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from rare import __version__, __codename__
from rare.ui.components.tabs.settings.about import Ui_About
from rare.utils.qt_requests import QtRequestManager
from rare.utils.qt_requests import QtRequests

logger = getLogger("About")

Expand All @@ -34,7 +34,7 @@ def __init__(self, parent=None):
self.ui.open_browser.setVisible(False)
self.ui.open_browser.setEnabled(False)

self.manager = QtRequestManager("json")
self.manager = QtRequests(parent=self)
self.manager.get(
"https://api.github.com/repos/RareDevs/Rare/releases/latest",
self.update_available_finished,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from PyQt5.QtGui import QShowEvent, QHideEvent
from PyQt5.QtWidgets import QStackedWidget, QTabWidget
from legendary.core import LegendaryCore

Expand Down Expand Up @@ -26,7 +27,7 @@ def __init__(self, core: LegendaryCore):
self.shop = ShopWidget(cache_dir(), self.core, self.api_core)
self.wishlist_widget = Wishlist(self.api_core)

self.store_tabs = QTabWidget()
self.store_tabs = QTabWidget(parent=self)
self.store_tabs.addTab(self.shop, self.tr("Games"))
self.store_tabs.addTab(self.wishlist_widget, self.tr("Wishlist"))

Expand All @@ -50,15 +51,23 @@ def __init__(self, core: LegendaryCore):
self.api_core.update_wishlist.connect(self.update_wishlist)
self.wishlist_widget.update_wishlist_signal.connect(self.update_wishlist)

def showEvent(self, a0: QShowEvent) -> None:
if a0.spontaneous() or self.init:
return super().showEvent(a0)
self.shop.load()
self.wishlist_widget.update_wishlist()
self.init = True
return super().showEvent(a0)

def hideEvent(self, a0: QHideEvent) -> None:
if a0.spontaneous():
return super().hideEvent(a0)
# TODO: Implement store unloading
return super().hideEvent(a0)

def update_wishlist(self):
self.shop.update_wishlist()

def load(self):
if not self.init:
self.init = True
self.shop.load()
self.wishlist_widget.update_wishlist()

def show_game_info(self, data):
self.info.update_game(data)
self.setCurrentIndex(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
QGridLayout,
)

from rare.components.tabs.store.shop_models import ShopGame
from rare.shared import LegendaryCoreSingleton
from rare.components.tabs.shop.shop_models import ShopGame
from rare.ui.components.tabs.store.shop_game_info import Ui_shop_info
from rare.utils.extra_widgets import ImageLabel
from rare.utils.misc import icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PyQt5.QtNetwork import QNetworkAccessManager
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout

from rare.components.tabs.shop.shop_models import ImageUrlModel
from rare.components.tabs.store.shop_models import ImageUrlModel
from rare.ui.components.tabs.store.wishlist_widget import Ui_WishlistWidget
from rare.utils.extra_widgets import ImageLabel
from rare.utils.misc import icon
Expand Down
Loading