Fix library/bookmark info panel, save indicator, DB migration

- Migrate library_meta to add tag_categories column
- Info panel always updates (not gated on isVisible)
- Library info shows status bar with score/rating
- Save indicator: changed elif to if so Saved always triggers
- Bookmark info panel always populated
This commit is contained in:
pax 2026-04-05 16:58:22 -05:00
parent 29ffe0be7a
commit 87c42f806e
2 changed files with 40 additions and 39 deletions

View File

@ -164,6 +164,14 @@ class Database:
self._conn.execute("ALTER TABLE favorites ADD COLUMN folder TEXT") self._conn.execute("ALTER TABLE favorites ADD COLUMN folder TEXT")
self._conn.commit() self._conn.commit()
self._conn.execute("CREATE INDEX IF NOT EXISTS idx_favorites_folder ON favorites(folder)") self._conn.execute("CREATE INDEX IF NOT EXISTS idx_favorites_folder ON favorites(folder)")
# Add tag_categories to library_meta if missing
tables = {r[0] for r in self._conn.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()}
if "library_meta" in tables:
cur = self._conn.execute("PRAGMA table_info(library_meta)")
cols = {row[1] for row in cur.fetchall()}
if "tag_categories" not in cols:
self._conn.execute("ALTER TABLE library_meta ADD COLUMN tag_categories TEXT DEFAULT ''")
self._conn.commit()
def close(self) -> None: def close(self) -> None:
if self._conn: if self._conn:

View File

@ -1114,54 +1114,47 @@ class BooruApp(QMainWindow):
if evicted: if evicted:
log.info(f"Auto-evicted {evicted} cached files") log.info(f"Auto-evicted {evicted} cached files")
def _set_library_info(self, path: str) -> None:
"""Update info panel with library metadata for the given file."""
stem = Path(path).stem
if not stem.isdigit():
return
meta = self._db.get_library_meta(int(stem))
if meta:
from ..core.api.base import Post
p = Post(
id=int(stem), file_url=meta.get("file_url", ""),
preview_url=None, tags=meta.get("tags", ""),
score=meta.get("score", 0), rating=meta.get("rating"),
source=meta.get("source"), tag_categories=meta.get("tag_categories", {}),
)
self._info_panel.set_post(p)
info = f"#{p.id} score:{p.score} [{p.rating}] {Path(path).suffix.lstrip('.').upper()}"
self._status.showMessage(info)
def _on_library_selected(self, path: str) -> None: def _on_library_selected(self, path: str) -> None:
self._set_preview_media(path, Path(path).name) self._set_preview_media(path, Path(path).name)
self._update_fullscreen(path, Path(path).name) self._update_fullscreen(path, Path(path).name)
# Show metadata in info panel self._set_library_info(path)
stem = Path(path).stem
if stem.isdigit() and self._info_panel.isVisible():
meta = self._db.get_library_meta(int(stem))
if meta:
from ..core.api.base import Post
p = Post(
id=int(stem), file_url=meta.get("file_url", ""),
preview_url=None, tags=meta.get("tags", ""),
score=meta.get("score", 0), rating=meta.get("rating"),
source=meta.get("source"), tag_categories=meta.get("tag_categories", {}),
)
self._info_panel.set_post(p)
def _on_library_activated(self, path: str) -> None: def _on_library_activated(self, path: str) -> None:
self._set_preview_media(path, Path(path).name) self._set_preview_media(path, Path(path).name)
self._update_fullscreen(path, Path(path).name) self._update_fullscreen(path, Path(path).name)
stem = Path(path).stem self._set_library_info(path)
if stem.isdigit() and self._info_panel.isVisible():
meta = self._db.get_library_meta(int(stem))
if meta:
from ..core.api.base import Post
p = Post(
id=int(stem), file_url=meta.get("file_url", ""),
preview_url=None, tags=meta.get("tags", ""),
score=meta.get("score", 0), rating=meta.get("rating"),
source=meta.get("source"), tag_categories=meta.get("tag_categories", {}),
)
self._info_panel.set_post(p)
def _on_bookmark_selected(self, fav) -> None: def _on_bookmark_selected(self, fav) -> None:
self._status.showMessage(f"Bookmark #{fav.post_id}") self._status.showMessage(f"Bookmark #{fav.post_id}")
# Show bookmark tags in info panel # Show bookmark tags in info panel
if self._info_panel.isVisible(): from ..core.api.base import Post
from ..core.api.base import Post meta = self._db.get_library_meta(fav.post_id)
# Try library metadata for categories cats = meta.get("tag_categories", {}) if meta else {}
meta = self._db.get_library_meta(fav.post_id) p = Post(
cats = meta.get("tag_categories", {}) if meta else {} id=fav.post_id, file_url=fav.file_url or "",
p = Post( preview_url=fav.preview_url, tags=fav.tags or "",
id=fav.post_id, file_url=fav.file_url or "", score=fav.score or 0, rating=fav.rating,
preview_url=fav.preview_url, tags=fav.tags or "", source=fav.source, tag_categories=cats,
score=fav.score or 0, rating=fav.rating, )
source=fav.source, tag_categories=cats, self._info_panel.set_post(p)
)
self._info_panel.set_post(p)
self._on_bookmark_activated(fav) self._on_bookmark_activated(fav)
def _on_bookmark_activated(self, fav) -> None: def _on_bookmark_activated(self, fav) -> None:
@ -2069,12 +2062,12 @@ class BooruApp(QMainWindow):
self._run_async(_fav) self._run_async(_fav)
def _on_bookmark_done(self, index: int, msg: str) -> None: def _on_bookmark_done(self, index: int, msg: str) -> None:
self._status.showMessage(msg) self._status.showMessage(f"{len(self._posts)} results — {msg}")
thumbs = self._grid._thumbs thumbs = self._grid._thumbs
if 0 <= index < len(thumbs): if 0 <= index < len(thumbs):
if "Saved" in msg: if "Saved" in msg:
thumbs[index].set_saved_locally(True) thumbs[index].set_saved_locally(True)
elif "Bookmarked" in msg: if "Bookmarked" in msg:
thumbs[index].set_bookmarked(True) thumbs[index].set_bookmarked(True)
self._update_fullscreen_state() self._update_fullscreen_state()