mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow FileIconProvider to load mimetypes icon from the config dir
This commit is contained in:
parent
2a56eaa2c7
commit
6429a45a07
@ -776,25 +776,27 @@ class FileIconProvider(QFileIconProvider):
|
|||||||
ICONS = EXT_MAP
|
ICONS = EXT_MAP
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QFileIconProvider.__init__(self)
|
super().__init__()
|
||||||
self.icons = {k:f'mimetypes/{v}.png' for k, v in self.ICONS.items()}
|
self.icons = {k:f'mimetypes/{v}.png' for k, v in self.ICONS.items()}
|
||||||
self.icons['calibre'] = I('lt.png', allow_user_override=False)
|
self.icons['calibre'] = I('lt.png', allow_user_override=False)
|
||||||
for i in ('dir', 'default', 'zero'):
|
for i in ('dir', 'default', 'zero'):
|
||||||
self.icons[i] = QIcon.ic(self.icons[i])
|
self.icons[i] = QIcon.ic(self.icons[i])
|
||||||
|
|
||||||
def key_from_ext(self, ext):
|
def key_from_ext(self, ext):
|
||||||
key = ext if ext in list(self.icons.keys()) else 'default'
|
key = ext if ext in self.icons else 'default'
|
||||||
if key == 'default' and ext.count('.') > 0:
|
if key == 'default' and ext.count('.') > 0:
|
||||||
ext = ext.rpartition('.')[2]
|
ext = ext.rpartition('.')[2]
|
||||||
key = ext if ext in list(self.icons.keys()) else 'default'
|
key = ext if ext in self.icons else 'default'
|
||||||
|
if key == 'default':
|
||||||
|
key = ext
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def cached_icon(self, key):
|
def cached_icon(self, key):
|
||||||
candidate = self.icons[key]
|
candidate = self.icons.get(key)
|
||||||
if isinstance(candidate, QIcon):
|
if isinstance(candidate, QIcon):
|
||||||
return candidate
|
return candidate
|
||||||
icon = QIcon.ic(candidate)
|
candidate = candidate or f'mimetypes/{key}.png'
|
||||||
self.icons[key] = icon
|
self.icons[key] = icon = QIcon.ic(candidate)
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
def icon_from_ext(self, ext):
|
def icon_from_ext(self, ext):
|
||||||
@ -803,10 +805,9 @@ class FileIconProvider(QFileIconProvider):
|
|||||||
|
|
||||||
def load_icon(self, fileinfo):
|
def load_icon(self, fileinfo):
|
||||||
key = 'default'
|
key = 'default'
|
||||||
icons = self.icons
|
|
||||||
if fileinfo.isSymLink():
|
if fileinfo.isSymLink():
|
||||||
if not fileinfo.exists():
|
if not fileinfo.exists():
|
||||||
return icons['zero']
|
return self.icons['zero']
|
||||||
fileinfo = QFileInfo(fileinfo.readLink())
|
fileinfo = QFileInfo(fileinfo.readLink())
|
||||||
if fileinfo.isDir():
|
if fileinfo.isDir():
|
||||||
key = 'dir'
|
key = 'dir'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user