From 10b90dcc743e3c3e65e3fd41582dc791761aaf7b Mon Sep 17 00:00:00 2001 From: Andrew Arneson Date: Sun, 2 Jun 2024 23:53:42 -0600 Subject: [PATCH] Bugfix for recent library re-creating a library at the last library location. (#238) * Prevent Automatic opening of a Library if the ".TagStudio" folder has been deleted. If the library no longer has a `.TagStudio` folder clear the Last_Library value * Add disabling recent libraries that are missing or have missing `.TagStudio` folders * Fix bug where this would crash if an empty library was passed * Grabbed the wrong color --- tagstudio/src/core/enums.py | 2 ++ tagstudio/src/qt/ts_qt.py | 8 ++++++++ tagstudio/src/qt/widgets/preview_panel.py | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/core/enums.py b/tagstudio/src/core/enums.py index a0c626bf..d61fe5aa 100644 --- a/tagstudio/src/core/enums.py +++ b/tagstudio/src/core/enums.py @@ -15,3 +15,5 @@ class Theme(str, enum.Enum): COLOR_BG = "#65000000" COLOR_HOVER = "#65AAAAAA" COLOR_PRESSED = "#65EEEEEE" + COLOR_DISABLED = "#65F39CAA" + COLOR_DISABLED_BG = "#65440D12" diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index a4d8f2f2..684e3867 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -525,6 +525,14 @@ class QtDriver(QObject): elif self.settings.value(SettingItems.START_LOAD_LAST, True, type=bool): lib = self.settings.value(SettingItems.LAST_LIBRARY) + # TODO: Remove this check if the library is no longer saved with files + if lib and not (Path(lib) / TS_FOLDER_NAME).exists(): + logging.error( + f"[QT DRIVER] {TS_FOLDER_NAME} folder in {lib} does not exist." + ) + self.settings.setValue(SettingItems.LAST_LIBRARY, "") + lib = None + if lib: self.splash.showMessage( f'Opening Library "{lib}"...', diff --git a/tagstudio/src/qt/widgets/preview_panel.py b/tagstudio/src/qt/widgets/preview_panel.py index 876558ac..a595aa8c 100644 --- a/tagstudio/src/qt/widgets/preview_panel.py +++ b/tagstudio/src/qt/widgets/preview_panel.py @@ -30,7 +30,7 @@ from humanfriendly import format_size from src.core.enums import SettingItems, Theme from src.core.library import Entry, ItemType, Library -from src.core.constants import VIDEO_TYPES, IMAGE_TYPES, RAW_IMAGE_TYPES +from src.core.constants import VIDEO_TYPES, IMAGE_TYPES, RAW_IMAGE_TYPES, TS_FOLDER_NAME from src.qt.helpers.file_opener import FileOpenerLabel, FileOpenerHelper, open_file from src.qt.modals.add_field import AddFieldModal from src.qt.widgets.thumb_renderer import ThumbRenderer @@ -298,6 +298,7 @@ class PreviewPanel(QWidget): "}" f"QPushButton::hover{{background-color:{Theme.COLOR_HOVER.value};}}" f"QPushButton::pressed{{background-color:{Theme.COLOR_PRESSED.value};}}" + f"QPushButton::disabled{{background-color:{Theme.COLOR_DISABLED_BG.value};}}" ) ) btn.setCursor(Qt.CursorShape.PointingHandCursor) @@ -306,6 +307,11 @@ class PreviewPanel(QWidget): button = QPushButton(text=cut_val) button.setObjectName(f"path{item_key}") + lib = Path(full_val) + if not lib.exists() or not (lib / TS_FOLDER_NAME).exists(): + button.setDisabled(True) + button.setToolTip("Location is missing") + def open_library_button_clicked(path): return lambda: self.driver.open_library(Path(path))