Moved invalid location message to location

This commit is contained in:
GeoffreyCoulaud
2023-07-26 15:27:28 +02:00
parent 04d0e9e90e
commit fa8a15addf
9 changed files with 20 additions and 11 deletions

View File

@@ -101,5 +101,6 @@ class BottlesSource(URLExecutableSource):
"library.yml": LocationSubPath("library.yml"), "library.yml": LocationSubPath("library.yml"),
"data.yml": LocationSubPath("data.yml"), "data.yml": LocationSubPath("data.yml"),
}, },
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
) )
) )

View File

@@ -135,5 +135,6 @@ class FlatpakSource(Source):
"applications": LocationSubPath("exports/share/applications", True), "applications": LocationSubPath("exports/share/applications", True),
"icons": LocationSubPath("exports/share/icons", True), "icons": LocationSubPath("exports/share/icons", True),
}, },
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
) )
) )

View File

@@ -377,6 +377,7 @@ class HeroicSource(URLExecutableSource):
"config.json": LocationSubPath("config.json"), "config.json": LocationSubPath("config.json"),
"store_config.json": LocationSubPath("store/config.json"), "store_config.json": LocationSubPath("store/config.json"),
}, },
invalid_subtitle=Location.CONFIG_INVALID_SUBTITLE,
) )
) )

View File

@@ -97,5 +97,6 @@ class ItchSource(URLExecutableSource):
paths={ paths={
"butler.db": LocationSubPath("db/butler.db"), "butler.db": LocationSubPath("db/butler.db"),
}, },
invalid_subtitle=Location.CONFIG_INVALID_SUBTITLE,
) )
) )

View File

@@ -110,5 +110,6 @@ class LegendarySource(Source):
"installed.json": LocationSubPath("installed.json"), "installed.json": LocationSubPath("installed.json"),
"metadata": LocationSubPath("metadata", True), "metadata": LocationSubPath("metadata", True),
}, },
invalid_subtitle=Location.CONFIG_INVALID_SUBTITLE,
) )
) )

View File

@@ -29,9 +29,18 @@ class Location:
* When resolved, the schema is updated with the picked chosen * When resolved, the schema is updated with the picked chosen
""" """
# The variable is the name of the source
CACHE_INVALID_SUBTITLE = _("Select the {} cache directory.")
# The variable is the name of the source
CONFIG_INVALID_SUBTITLE = _("Select the {} configuration directory.")
# The variable is the name of the source
DATA_INVALID_SUBTITLE = _("Select the {} data directory.")
schema_key: str schema_key: str
candidates: Iterable[Candidate] candidates: Iterable[Candidate]
paths: Mapping[str, LocationSubPath] paths: Mapping[str, LocationSubPath]
invalid_subtitle: str
root: Path = None root: Path = None
def __init__( def __init__(
@@ -39,11 +48,13 @@ class Location:
schema_key: str, schema_key: str,
candidates: Iterable[Candidate], candidates: Iterable[Candidate],
paths: Mapping[str, LocationSubPath], paths: Mapping[str, LocationSubPath],
invalid_subtitle: str,
) -> None: ) -> None:
super().__init__() super().__init__()
self.schema_key = schema_key self.schema_key = schema_key
self.candidates = candidates self.candidates = candidates
self.paths = paths self.paths = paths
self.invalid_subtitle = invalid_subtitle
def check_candidate(self, candidate: Path) -> bool: def check_candidate(self, candidate: Path) -> bool:
"""Check if a candidate root has the necessary files and directories""" """Check if a candidate root has the necessary files and directories"""

View File

@@ -110,6 +110,7 @@ class LutrisSource(URLExecutableSource):
paths={ paths={
"pga.db": (False, "pga.db"), "pga.db": (False, "pga.db"),
}, },
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
), ),
Location( Location(
schema_key="lutris-cache-location", schema_key="lutris-cache-location",
@@ -121,6 +122,7 @@ class LutrisSource(URLExecutableSource):
paths={ paths={
"coverart": LocationSubPath("coverart", True), "coverart": LocationSubPath("coverart", True),
}, },
invalid_subtitle=Location.CACHE_INVALID_SUBTITLE,
), ),
) )

View File

@@ -132,5 +132,6 @@ class SteamSource(URLExecutableSource):
"libraryfolders.vdf": LocationSubPath("steamapps/libraryfolders.vdf"), "libraryfolders.vdf": LocationSubPath("steamapps/libraryfolders.vdf"),
"librarycache": LocationSubPath("appcache/librarycache", True), "librarycache": LocationSubPath("appcache/librarycache", True),
}, },
invalid_subtitle=Location.DATA_INVALID_SUBTITLE,
) )
) )

View File

@@ -351,20 +351,10 @@ class PreferencesWindow(Adw.PreferencesWindow):
# Bad picked location, inform user # Bad picked location, inform user
else: else:
title = _("Invalid Directory") title = _("Invalid Directory")
match location_name:
case "cache":
# The variable is the name of the source
subtitle_format = _("Select the {} cache directory.")
case "config":
# The variable is the name of the source
subtitle_format = _("Select the {} configuration directory.")
case "data":
# The variable is the name of the source
subtitle_format = _("Select the {} data directory.")
dialog = create_dialog( dialog = create_dialog(
self, self,
title, title,
subtitle_format.format(source.name), location.invalid_subtitle.format(source.name),
"choose_folder", "choose_folder",
_("Set Location"), _("Set Location"),
) )