93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
import time
|
|
|
|
from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QStackedLayout, QWidget, QPushButton
|
|
from legendary.core import LegendaryCore
|
|
|
|
from Rare.utils.Dialogs.Login.BrowserLogin import BrowserLogin
|
|
from Rare.utils.Dialogs.Login.ImportWidget import ImportWidget
|
|
|
|
|
|
# Login Opportunities: Browser, Import
|
|
|
|
|
|
class LoginDialog(QDialog):
|
|
logged_in: bool = False
|
|
|
|
def __init__(self, core: LegendaryCore):
|
|
super(LoginDialog, self).__init__()
|
|
|
|
self.core = core
|
|
self.setWindowTitle("Rare - Login")
|
|
self.setGeometry(0, 0, 400, 600)
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
self.layout = QStackedLayout()
|
|
|
|
self.landing_widget = QWidget()
|
|
self.landing_layout = QVBoxLayout()
|
|
|
|
self.title = QLabel(f"<h1>{self.tr('Welcome to Rare')}</h1>")
|
|
self.landing_layout.addWidget(self.title)
|
|
self.info_text = QLabel(self.tr("Select one option to Login"))
|
|
self.landing_layout.addWidget(self.info_text)
|
|
|
|
self.browser_login = OptionWidget("Use Browser", "This opens your default webbrowser. Login and copy the text")
|
|
self.landing_layout.addWidget(self.browser_login)
|
|
self.browser_login.button.clicked.connect(lambda: self.layout.setCurrentIndex(1))
|
|
|
|
self.import_login = OptionWidget("Import from existing installation",
|
|
"Import an existing login session from an Epic Games Launcher installation. You will get logged out there")
|
|
self.import_login.button.clicked.connect(lambda: self.layout.setCurrentIndex(2))
|
|
self.landing_layout.addWidget(self.import_login)
|
|
|
|
self.close_button = QPushButton("Exit App")
|
|
self.close_button.clicked.connect(self.close)
|
|
self.landing_layout.addWidget(self.close_button)
|
|
|
|
self.landing_widget.setLayout(self.landing_layout)
|
|
self.layout.addWidget(self.landing_widget)
|
|
|
|
self.browser_widget = BrowserLogin(self.core)
|
|
self.browser_widget.success.connect(lambda: self.layout.setCurrentIndex(0))
|
|
self.browser_widget.success.connect(self.success)
|
|
self.layout.addWidget(self.browser_widget)
|
|
|
|
self.import_widget = ImportWidget()
|
|
self.layout.addWidget(self.import_widget)
|
|
|
|
self.layout.addWidget(LoginSuccessfulWidget())
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
def login(self):
|
|
self.exec_()
|
|
return self.logged_in
|
|
|
|
def success(self):
|
|
if self.core.login():
|
|
self.logged_in = True
|
|
self.layout.setCurrentIndex(3)
|
|
time.sleep(1)
|
|
self.close()
|
|
|
|
|
|
class OptionWidget(QWidget):
|
|
def __init__(self, btn_text: str, info_text: str):
|
|
super(OptionWidget, self).__init__()
|
|
self.layout = QVBoxLayout()
|
|
self.text = QLabel(info_text)
|
|
self.text.setWordWrap(True)
|
|
self.button = QPushButton(btn_text)
|
|
|
|
self.layout.addWidget(self.button)
|
|
self.layout.addWidget(self.text)
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
class LoginSuccessfulWidget(QWidget):
|
|
def __init__(self):
|
|
super(LoginSuccessfulWidget, self).__init__()
|
|
self.layout = QVBoxLayout()
|
|
self.layout.addWidget(QLabel("Login Successful"))
|
|
self.setLayout(self.layout) |