mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle loading of dual mode icons missing from user "any" themes
This commit is contained in:
parent
121b7eb7f2
commit
4a7d0227b8
@ -165,7 +165,15 @@ class IconResourceManager:
|
||||
q = os.path.join(self.override_icon_path, name)
|
||||
if os.path.exists(q):
|
||||
return QIcon(q)
|
||||
return QIcon.fromTheme(os.path.splitext(name.replace('\\', '__').replace('/', '__'))[0])
|
||||
icon_name = os.path.splitext(name.replace('\\', '__').replace('/', '__'))[0]
|
||||
ans = QIcon.fromTheme(icon_name)
|
||||
if ans.isNull():
|
||||
if 'user-any' in QIcon.themeName():
|
||||
tc = 'dark' if QApplication.instance().is_dark_theme else 'light'
|
||||
q = QIcon(f':/icons/calibre-default-{tc}/images/{name}')
|
||||
if not q.isNull():
|
||||
ans = q
|
||||
return ans
|
||||
|
||||
def set_theme(self):
|
||||
current = QIcon.themeName()
|
||||
|
@ -12,6 +12,7 @@ import math
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from contextlib import suppress
|
||||
from functools import lru_cache
|
||||
from io import BytesIO
|
||||
from itertools import count
|
||||
@ -468,12 +469,9 @@ def get_cover(metadata):
|
||||
etag_file, cover_file = map(path, 'etag jpg'.split())
|
||||
|
||||
def safe_read(path):
|
||||
try:
|
||||
with suppress(FileNotFoundError):
|
||||
with open(path, 'rb') as f:
|
||||
return f.read()
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
return b''
|
||||
etag, cached = safe_read(etag_file), safe_read(cover_file)
|
||||
etag = etag.decode('utf-8')
|
||||
|
@ -157,7 +157,15 @@ int CalibreStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW
|
||||
}
|
||||
|
||||
QIcon CalibreStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption * option, const QWidget * widget) const {
|
||||
if (icon_map.contains(standardIcon)) return QIcon::fromTheme(icon_map.value(standardIcon));
|
||||
if (icon_map.contains(standardIcon)) {
|
||||
QIcon ans = QIcon::fromTheme(icon_map.value(standardIcon));
|
||||
if (ans.isNull() && QIcon::themeName().contains("user-any")) {
|
||||
const bool is_dark_theme = QApplication::instance()->property("is_dark_theme").toBool();
|
||||
QIcon q(QString(":/icons/calibre-default-%1/images/%2.png").arg(is_dark_theme ? "dark" : "light").arg(icon_map.value(standardIcon)));
|
||||
if (!q.isNull()) ans = q;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
return QProxyStyle::standardIcon(standardIcon, option, widget);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user