1
0
Fork 0
mirror of synced 2024-07-03 13:40:47 +12:00
Rare/rare/components/tabs/settings/widgets/linux.py

95 lines
3.7 KiB
Python
Raw Normal View History

import os
import shutil
2021-02-20 06:09:00 +13:00
from logging import getLogger
2021-11-11 07:00:15 +13:00
from PyQt5.QtWidgets import QFileDialog, QWidget
2021-02-20 06:09:00 +13:00
from rare.components.tabs.settings.widgets.dxvk import DxvkSettings
from rare.components.tabs.settings.widgets.mangohud import MangoHudSettings
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
from rare.ui.components.tabs.settings.linux import Ui_LinuxSettings
from rare.widgets.indicator_edit import PathEdit, IndicatorReasonsCommon
2021-02-20 06:09:00 +13:00
logger = getLogger("LinuxSettings")
2021-02-20 00:57:55 +13:00
class LinuxSettings(QWidget):
def __init__(self, name=None, parent=None):
super(LinuxSettings, self).__init__(parent=parent)
self.ui = Ui_LinuxSettings()
self.ui.setupUi(self)
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
self.name = name if name is not None else "default"
2021-05-02 08:15:42 +12:00
# Wine prefix
self.wine_prefix = PathEdit(
self.load_prefix(),
file_mode=QFileDialog.DirectoryOnly,
edit_func=lambda path: (os.path.isdir(path) or not path, path, IndicatorReasonsCommon.DIR_NOT_EXISTS),
2021-12-24 22:09:50 +13:00
save_func=self.save_prefix,
)
self.ui.prefix_layout.addWidget(self.wine_prefix)
2021-02-20 06:09:00 +13:00
# Wine executable
self.wine_exec = PathEdit(
self.load_setting(self.name, "wine_executable"),
file_mode=QFileDialog.ExistingFile,
name_filters=["wine", "wine64"],
edit_func=lambda text: (os.path.exists(text) or not text, text, IndicatorReasonsCommon.DIR_NOT_EXISTS),
2021-12-24 22:09:50 +13:00
save_func=lambda text: self.save_setting(
text, section=self.name, setting="wine_executable"
),
)
self.ui.exec_layout.addWidget(self.wine_exec)
2021-02-20 06:09:00 +13:00
# dxvk
self.dxvk = DxvkSettings()
self.ui.linux_layout.addWidget(self.dxvk)
self.dxvk.load_settings(self.name)
self.mangohud = MangoHudSettings()
self.ui.linux_layout.addWidget(self.mangohud)
self.mangohud.load_settings(self.name)
if not shutil.which("mangohud"):
self.mangohud.setDisabled(True)
self.mangohud.setToolTip(self.tr("Mangohud is not installed or not in path"))
def load_prefix(self) -> str:
2021-12-24 22:09:50 +13:00
return self.load_setting(
f"{self.name}.env",
"WINEPREFIX",
fallback=self.load_setting(self.name, "wine_prefix"),
)
def save_prefix(self, text: str):
2021-12-24 22:09:50 +13:00
self.save_setting(text, f"{self.name}.env", "WINEPREFIX")
self.save_setting(text, self.name, "wine_prefix")
self.signals.application.prefix_updated.emit()
def load_setting(self, section: str, setting: str, fallback: str = ""):
return self.core.lgd.config.get(section, setting, fallback=fallback)
def save_setting(self, text: str, section: str, setting: str):
if text:
if section not in self.core.lgd.config.sections():
self.core.lgd.config.add_section(section)
logger.debug(f"Added {f'[{section}]'} configuration section")
self.core.lgd.config.set(section, setting, text)
logger.debug(f"Set {setting} in {f'[{section}]'} to {text}")
2021-02-20 06:09:00 +13:00
else:
if self.core.lgd.config.has_section(
2021-12-24 22:09:50 +13:00
section
) and self.core.lgd.config.has_option(section, setting):
self.core.lgd.config.remove_option(section, setting)
logger.debug(f"Unset {setting} from {f'[{section}]'}")
if not self.core.lgd.config[section]:
self.core.lgd.config.remove_section(section)
logger.debug(f"Removed {f'[{section}]'} configuration section")
self.core.lgd.save_config()