Configurable library directory in Settings > Paths

Browse button to pick a custom library save directory.
Applied on startup via set_library_dir(). Restart required.
This commit is contained in:
pax 2026-04-05 02:01:44 -05:00
parent c9fe8fa8a0
commit f8582e83fa
3 changed files with 36 additions and 1 deletions

View File

@ -39,9 +39,20 @@ def thumbnails_dir() -> Path:
return path
_library_dir_override: Path | None = None
def set_library_dir(path: Path | None) -> None:
global _library_dir_override
_library_dir_override = path
def saved_dir() -> Path:
"""Return the saved images directory."""
path = data_dir() / "saved"
if _library_dir_override:
path = _library_dir_override
else:
path = data_dir() / "saved"
path.mkdir(parents=True, exist_ok=True)
return path

View File

@ -205,6 +205,11 @@ class BooruApp(QMainWindow):
self.resize(1200, 800)
self._db = Database()
# Apply custom library directory if set
lib_dir = self._db.get_setting("library_dir")
if lib_dir:
from ..core.config import set_library_dir
set_library_dir(Path(lib_dir))
self._current_site: Site | None = None
self._posts: list[Post] = []
self._current_page = 1

View File

@ -307,6 +307,18 @@ class SettingsDialog(QDialog):
layout.addLayout(form)
# Library directory (editable)
lib_row = QHBoxLayout()
from ..core.config import saved_dir
current_lib = self._db.get_setting("library_dir") or str(saved_dir())
self._library_dir = QLineEdit(current_lib)
lib_row.addWidget(self._library_dir, stretch=1)
browse_lib_btn = QPushButton("Browse...")
browse_lib_btn.clicked.connect(self._browse_library_dir)
lib_row.addWidget(browse_lib_btn)
layout.addWidget(QLabel("Library directory (restart required):"))
layout.addLayout(lib_row)
open_btn = QPushButton("Open Data Folder")
open_btn.clicked.connect(self._open_data_folder)
layout.addWidget(open_btn)
@ -554,6 +566,12 @@ class SettingsDialog(QDialog):
except Exception as e:
QMessageBox.warning(self, "Error", str(e))
def _browse_library_dir(self) -> None:
from PySide6.QtWidgets import QFileDialog
path = QFileDialog.getExistingDirectory(self, "Select Library Directory", self._library_dir.text())
if path:
self._library_dir.setText(path)
def _open_data_folder(self) -> None:
from PySide6.QtGui import QDesktopServices
from PySide6.QtCore import QUrl
@ -628,6 +646,7 @@ class SettingsDialog(QDialog):
self._db.set_setting("default_score", str(self._default_score.value()))
self._db.set_setting("preload_thumbnails", "1" if self._preload.isChecked() else "0")
self._db.set_setting("prefetch_adjacent", "1" if self._prefetch.isChecked() else "0")
self._db.set_setting("library_dir", self._library_dir.text().strip())
self._db.set_setting("max_cache_mb", str(self._max_cache.value()))
self._db.set_setting("auto_evict", "1" if self._auto_evict.isChecked() else "0")
self._db.set_setting("clear_cache_on_exit", "1" if self._clear_on_exit.isChecked() else "0")