Skip to content

Commit

Permalink
EOSGroup: Use UI membership instead of double inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
loathingKernel committed Sep 3, 2023
1 parent 25f0567 commit 5f0547e
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 138 deletions.
104 changes: 54 additions & 50 deletions rare/components/tabs/games/integrations/eos_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from rare.models.install import InstallOptionsModel
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
from rare.ui.components.tabs.games.integrations.eos_widget import Ui_EosWidget
from rare.utils.misc import icon

logger = getLogger("EOS")
logger = getLogger("EpicOverlay")


def get_wine_prefixes() -> List[str]:
Expand Down Expand Up @@ -42,83 +43,86 @@ def run(self) -> None:
self.signals.update_available.emit(self.core.overlay_update_available)


class EOSGroup(QGroupBox, Ui_EosWidget):
class EOSGroup(QGroupBox):
def __init__(self, parent=None):
super(EOSGroup, self).__init__(parent=parent)
self.setupUi(self)
self.ui = Ui_EosWidget()
self.ui.setupUi(self)
# lk: set object names for CSS properties
self.install_button.setObjectName("InstallButton")
self.uninstall_button.setObjectName("UninstallButton")
self.ui.install_button.setObjectName("InstallButton")
self.ui.install_button.setIcon(icon("ri.install-line"))
self.ui.uninstall_button.setObjectName("UninstallButton")
self.ui.uninstall_button.setIcon(icon("ri.uninstall-line"))

self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()

self.prefix_enabled = False

self.enabled_cb.stateChanged.connect(self.change_enable)
self.uninstall_button.clicked.connect(self.uninstall_overlay)
self.ui.enabled_cb.stateChanged.connect(self.change_enable)
self.ui.uninstall_button.clicked.connect(self.uninstall_overlay)

self.update_button.setVisible(False)
self.ui.update_button.setVisible(False)
self.overlay = self.core.lgd.get_overlay_install_info()

self.signals.application.overlay_installed.connect(self.overlay_installation_finished)
self.signals.application.prefix_updated.connect(self.update_prefixes)

self.update_check_button.clicked.connect(self.check_for_update)
self.install_button.clicked.connect(self.install_overlay)
self.update_button.clicked.connect(lambda: self.install_overlay(True))
self.ui.update_check_button.clicked.connect(self.check_for_update)
self.ui.install_button.clicked.connect(self.install_overlay)
self.ui.update_button.clicked.connect(lambda: self.install_overlay(True))

if self.overlay: # installed
self.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
self.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")
self.overlay_stack.setCurrentIndex(0)
self.ui.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
self.ui.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")
self.ui.overlay_stack.setCurrentIndex(0)
else:
self.overlay_stack.setCurrentIndex(1)
self.enable_frame.setDisabled(True)
self.ui.overlay_stack.setCurrentIndex(1)
self.ui.enable_frame.setDisabled(True)

if platform.system() == "Windows":
self.current_prefix = None
self.select_pfx_combo.setVisible(False)
self.ui.select_pfx_combo.setVisible(False)
else:
self.current_prefix = os.path.expanduser("~/.wine") \
if os.path.exists(os.path.expanduser("~/.wine")) \
else None
pfxs = get_wine_prefixes()
for pfx in pfxs:
self.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))
self.ui.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))
if not pfxs:
self.enable_frame.setDisabled(True)
self.ui.enable_frame.setDisabled(True)
else:
self.select_pfx_combo.setCurrentIndex(0)
self.ui.select_pfx_combo.setCurrentIndex(0)

self.select_pfx_combo.currentIndexChanged.connect(self.update_select_combo)
self.ui.select_pfx_combo.currentIndexChanged.connect(self.update_select_combo)
if pfxs:
self.update_select_combo(None)

self.enabled_info_label.setText("")
self.ui.enabled_info_label.setText("")

self.threadpool = QThreadPool.globalInstance()

def update_prefixes(self):
logger.debug("Updated prefixes")
pfxs = get_wine_prefixes() # returns /home/whatever
self.select_pfx_combo.clear()
self.ui.select_pfx_combo.clear()

for pfx in pfxs:
self.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))
self.ui.select_pfx_combo.addItem(pfx.replace(os.path.expanduser("~/"), "~/"))

if self.current_prefix in pfxs:
self.select_pfx_combo.setCurrentIndex(
self.select_pfx_combo.findText(self.current_prefix.replace(os.path.expanduser("~/"), "~/")))
self.ui.select_pfx_combo.setCurrentIndex(
self.ui.select_pfx_combo.findText(self.current_prefix.replace(os.path.expanduser("~/"), "~/")))

def check_for_update(self):
def worker_finished(update_available):
self.update_button.setVisible(update_available)
self.update_check_button.setDisabled(False)
self.ui.update_button.setVisible(update_available)
self.ui.update_check_button.setDisabled(False)
if not update_available:
self.update_check_button.setText(self.tr("No update available"))
self.ui.update_check_button.setText(self.tr("No update available"))

self.update_check_button.setDisabled(True)
self.ui.update_check_button.setDisabled(True)
worker = CheckForUpdateWorker()
worker.signals.update_available.connect(worker_finished)
QThreadPool.globalInstance().start(worker)
Expand All @@ -131,18 +135,18 @@ def overlay_installation_finished(self):
QMessageBox.warning(self, "Error", self.tr("Something went wrong, when installing overlay"))
return

self.overlay_stack.setCurrentIndex(0)
self.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
self.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")
self.ui.overlay_stack.setCurrentIndex(0)
self.ui.installed_version_lbl.setText(f"<b>{self.overlay.version}</b>")
self.ui.installed_path_lbl.setText(f"<b>{self.overlay.install_path}</b>")

self.update_button.setVisible(False)
self.ui.update_button.setVisible(False)

self.enable_frame.setEnabled(True)
self.ui.enable_frame.setEnabled(True)

def update_select_combo(self, i: None):
if i is None:
i = self.select_pfx_combo.currentIndex()
prefix = os.path.expanduser(self.select_pfx_combo.itemText(i))
i = self.ui.select_pfx_combo.currentIndex()
prefix = os.path.expanduser(self.ui.select_pfx_combo.itemText(i))
if platform.system() != "Windows" and not os.path.exists(prefix):
return
self.current_prefix = prefix
Expand All @@ -151,10 +155,10 @@ def update_select_combo(self, i: None):
overlay_enabled = False
if reg_paths['overlay_path'] and self.core.is_overlay_install(reg_paths['overlay_path']):
overlay_enabled = True
self.enabled_cb.setChecked(overlay_enabled)
self.ui.enabled_cb.setChecked(overlay_enabled)

def change_enable(self):
enabled = self.enabled_cb.isChecked()
enabled = self.ui.enabled_cb.isChecked()
if not enabled:
try:
eos.remove_registry_entries(self.current_prefix)
Expand All @@ -164,7 +168,7 @@ def change_enable(self):
"Failed to disable Overlay. Probably it is installed by Epic Games Launcher"))
return
logger.info("Disabled Epic Overlay")
self.enabled_info_label.setText(self.tr("Disabled"))
self.ui.enabled_info_label.setText(self.tr("Disabled"))
else:
if not self.overlay:
available_installs = self.core.search_overlay_installs(self.current_prefix)
Expand All @@ -177,7 +181,7 @@ def change_enable(self):

if not self.core.is_overlay_install(path):
logger.error(f'Not a valid Overlay installation: {path}')
self.select_pfx_combo.removeItem(self.select_pfx_combo.currentIndex())
self.ui.select_pfx_combo.removeItem(self.ui.select_pfx_combo.currentIndex())
return

path = os.path.normpath(path)
Expand All @@ -202,24 +206,24 @@ def change_enable(self):
QMessageBox.warning(self, "Error", self.tr(
"Failed to enable EOS overlay. Maybe it is already installed by Epic Games Launcher"))
return
self.enabled_info_label.setText(self.tr("Enabled"))
self.ui.enabled_info_label.setText(self.tr("Enabled"))
logger.info(f'Enabled overlay at: {path}')

def update_checkbox(self):
reg_paths = eos.query_registry_entries(self.current_prefix)
enabled = False
if reg_paths['overlay_path'] and self.core.is_overlay_install(reg_paths['overlay_path']):
enabled = True
self.enabled_cb.setChecked(enabled)
self.ui.enabled_cb.setChecked(enabled)

def install_overlay(self, update=False):
base_path = os.path.join(
self.core.lgd.config.get("Legendary", "install_dir", fallback=os.path.expanduser("~/legendary")),".overlay"
self.core.lgd.config.get("Legendary", "install_dir", fallback=os.path.expanduser("~/legendary")), ".overlay"
)
if update:
if not self.overlay:
self.overlay_stack.setCurrentIndex(1)
self.enable_frame.setDisabled(True)
self.ui.overlay_stack.setCurrentIndex(1)
self.ui.enable_frame.setDisabled(True)
QMessageBox.warning(self, "Warning", self.tr("Overlay is not installed. Could not update"))
return
base_path = self.overlay.install_path
Expand All @@ -233,7 +237,7 @@ def install_overlay(self, update=False):
def uninstall_overlay(self):
if not self.core.is_overlay_installed():
logger.error('No legendary-managed overlay installation found.')
self.overlay_stack.setCurrentIndex(1)
self.ui.overlay_stack.setCurrentIndex(1)
return

if QMessageBox.No == QMessageBox.question(
Expand All @@ -244,14 +248,14 @@ def uninstall_overlay(self):
if platform.system() == "Windows":
eos.remove_registry_entries(None)
else:
for prefix in [self.select_pfx_combo.itemText(i) for i in range(self.select_pfx_combo.count())]:
for prefix in [self.ui.select_pfx_combo.itemText(i) for i in range(self.ui.select_pfx_combo.count())]:
logger.info(f"Removing registry entries from {prefix}")
try:
eos.remove_registry_entries(os.path.expanduser(prefix))
except Exception as e:
logger.warning(f"{prefix}: {e}")

self.core.remove_overlay_install()
self.overlay_stack.setCurrentIndex(1)
self.ui.overlay_stack.setCurrentIndex(1)

self.enable_frame.setDisabled(True)
self.ui.enable_frame.setDisabled(True)
Loading

0 comments on commit 5f0547e

Please sign in to comment.