Skip to content

Commit

Permalink
Use different icons for failed downloads and available resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
bohning committed Nov 23, 2024
1 parent 59b7d6d commit 30ea796
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
Binary file added src/usdb_syncer/gui/resources/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/usdb_syncer/gui/resources/download-cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/usdb_syncer/gui/resources/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
<file>control-play-local.png</file>
<file>control-play.png</file>
<file>cover.png</file>
<file>cross.png</file>
<file>database.png</file>
<file>document-export.png</file>
<file>document-import.png</file>
<file>download-cloud.png</file>
<file>drawer.png</file>
<file>drive-download.png</file>
<file>edge.png</file>
Expand Down
44 changes: 26 additions & 18 deletions src/usdb_syncer/gui/song_table/table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from PySide6.QtGui import QIcon

from usdb_syncer import SongId, events, utils
from usdb_syncer import SongId, events, settings, utils
from usdb_syncer.gui.song_table.column import Column
from usdb_syncer.usdb_song import DownloadStatus, UsdbSong

Expand Down Expand Up @@ -190,24 +190,12 @@ def _decoration_data(song: UsdbSong, column: int) -> QIcon | None:
return None
action = "pause" if song.is_playing else "play"
return icon(f":/icons/control-{action}{suffix}.png")
case Column.TXT:
return icon(":/icons/tick.png", bool(song.sync_meta and song.sync_meta.txt))
case Column.TXT | Column.VIDEO | Column.COVER | Column.BACKGROUND:
resource = col.name.lower()
return file_icon(song, resource)
case Column.AUDIO:
return icon(
":/icons/tick.png", bool(song.sync_meta and song.sync_meta.audio)
)
case Column.VIDEO:
return icon(
":/icons/tick.png", bool(song.sync_meta and song.sync_meta.video)
)
case Column.COVER:
return icon(
":/icons/tick.png", bool(song.sync_meta and song.sync_meta.cover)
)
case Column.BACKGROUND:
return icon(
":/icons/tick.png", bool(song.sync_meta and song.sync_meta.background)
)
resource = col.name.lower()
return file_icon(song, resource, Column.VIDEO.name.lower())
case Column.PINNED:
return icon(
":/icons/pin.png", bool(song.sync_meta and song.sync_meta.pinned)
Expand All @@ -216,6 +204,14 @@ def _decoration_data(song: UsdbSong, column: int) -> QIcon | None:
assert_never(unreachable)


def has_local_file(song: UsdbSong, resource: str) -> bool:
return bool(song.sync_meta and getattr(song.sync_meta, resource))


def has_meta_tag(song: UsdbSong, resource: str) -> bool:
return bool(song.sync_meta and getattr(song.sync_meta.meta_tags, resource, None))


@cache
def rating_str(rating: int) -> str:
return rating * "★"
Expand All @@ -231,3 +227,15 @@ def yes_no_str(yes: bool) -> str:
@cache
def icon(resource: str, yes: bool = True) -> QIcon | None:
return QIcon(resource) if yes else None


def file_icon(
song: UsdbSong, resource1: str, resource2: str | None = None
) -> QIcon | None:
if has_local_file(song, resource1):
return icon(":/icons/tick.png")
if has_meta_tag(song, resource1) or (resource2 and has_meta_tag(song, resource2)):
if getattr(settings, f"get_{resource1}")():
return icon(":/icons/cross.png")
return icon(":/icons/download-cloud.png")
return None

0 comments on commit 30ea796

Please sign in to comment.