mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book detail view: When showing device replace path with click to open link as well
This commit is contained in:
parent
e01da87c2b
commit
3853b6bdbe
@ -10,12 +10,31 @@ import os
|
|||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
from calibre.customize import FileTypePlugin
|
from calibre.customize import FileTypePlugin
|
||||||
|
from calibre.utils.zipfile import ZipFile, stringFileHeader
|
||||||
|
|
||||||
def is_comic(list_of_names):
|
def is_comic(list_of_names):
|
||||||
extensions = set([x.rpartition('.')[-1].lower() for x in list_of_names])
|
extensions = set([x.rpartition('.')[-1].lower() for x in list_of_names])
|
||||||
comic_extensions = set(['jpg', 'jpeg', 'png'])
|
comic_extensions = set(['jpg', 'jpeg', 'png'])
|
||||||
return len(extensions - comic_extensions) == 0
|
return len(extensions - comic_extensions) == 0
|
||||||
|
|
||||||
|
def archive_type(stream):
|
||||||
|
try:
|
||||||
|
pos = stream.tell()
|
||||||
|
except:
|
||||||
|
pos = 0
|
||||||
|
id_ = stream.read(4)
|
||||||
|
ans = None
|
||||||
|
if id_ == stringFileHeader:
|
||||||
|
ans = 'zip'
|
||||||
|
elif id_.startswith('Rar'):
|
||||||
|
ans = 'rar'
|
||||||
|
try:
|
||||||
|
stream.seek(pos)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
class ArchiveExtract(FileTypePlugin):
|
class ArchiveExtract(FileTypePlugin):
|
||||||
name = 'Archive Extract'
|
name = 'Archive Extract'
|
||||||
author = 'Kovid Goyal'
|
author = 'Kovid Goyal'
|
||||||
@ -31,7 +50,6 @@ class ArchiveExtract(FileTypePlugin):
|
|||||||
if is_rar:
|
if is_rar:
|
||||||
from calibre.libunrar import extract_member, names
|
from calibre.libunrar import extract_member, names
|
||||||
else:
|
else:
|
||||||
from calibre.utils.zipfile import ZipFile
|
|
||||||
zf = ZipFile(archive, 'r')
|
zf = ZipFile(archive, 'r')
|
||||||
|
|
||||||
if is_rar:
|
if is_rar:
|
||||||
|
@ -9,7 +9,7 @@ import os, collections
|
|||||||
|
|
||||||
from PyQt4.Qt import QLabel, QPixmap, QSize, QWidget, Qt, pyqtSignal, \
|
from PyQt4.Qt import QLabel, QPixmap, QSize, QWidget, Qt, pyqtSignal, \
|
||||||
QVBoxLayout, QScrollArea, QPropertyAnimation, QEasingCurve, \
|
QVBoxLayout, QScrollArea, QPropertyAnimation, QEasingCurve, \
|
||||||
QSizePolicy, QPainter, QRect, pyqtProperty
|
QSizePolicy, QPainter, QRect, pyqtProperty, QDesktopServices, QUrl
|
||||||
|
|
||||||
from calibre import fit_image, prepare_string_for_xml
|
from calibre import fit_image, prepare_string_for_xml
|
||||||
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
||||||
@ -42,7 +42,6 @@ def render_rows(data):
|
|||||||
txt = prepare_string_for_xml(txt)
|
txt = prepare_string_for_xml(txt)
|
||||||
if 'id' in data:
|
if 'id' in data:
|
||||||
if key == _('Path'):
|
if key == _('Path'):
|
||||||
txt = '...'+os.sep+os.sep.join(txt.split(os.sep)[-2:])
|
|
||||||
txt = u'<a href="path:%s">%s</a>'%(data['id'],
|
txt = u'<a href="path:%s">%s</a>'%(data['id'],
|
||||||
_('Click to open'))
|
_('Click to open'))
|
||||||
if key == _('Formats') and txt and txt != _('None'):
|
if key == _('Formats') and txt and txt != _('None'):
|
||||||
@ -50,6 +49,11 @@ def render_rows(data):
|
|||||||
fmts = [u'<a href="format:%s:%s">%s</a>' % (data['id'], x, x) for x
|
fmts = [u'<a href="format:%s:%s">%s</a>' % (data['id'], x, x) for x
|
||||||
in fmts]
|
in fmts]
|
||||||
txt = ', '.join(fmts)
|
txt = ', '.join(fmts)
|
||||||
|
else:
|
||||||
|
if key == _('Path'):
|
||||||
|
txt = u'<a href="devpath:%s">%s</a>'%(txt,
|
||||||
|
_('Click to open'))
|
||||||
|
|
||||||
rows.append((key, txt))
|
rows.append((key, txt))
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
@ -150,6 +154,7 @@ class Label(QLabel):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QLabel.__init__(self)
|
QLabel.__init__(self)
|
||||||
|
self.setTextFormat(Qt.RichText)
|
||||||
self.setText('')
|
self.setText('')
|
||||||
self.setWordWrap(True)
|
self.setWordWrap(True)
|
||||||
self.linkActivated.connect(self.link_activated)
|
self.linkActivated.connect(self.link_activated)
|
||||||
@ -249,9 +254,13 @@ class BookDetails(QWidget):
|
|||||||
typ, _, val = link.partition(':')
|
typ, _, val = link.partition(':')
|
||||||
if typ == 'path':
|
if typ == 'path':
|
||||||
self.open_containing_folder.emit(int(val))
|
self.open_containing_folder.emit(int(val))
|
||||||
if typ == 'format':
|
elif typ == 'format':
|
||||||
id_, fmt = val.split(':')
|
id_, fmt = val.split(':')
|
||||||
self.view_specific_format.emit(int(id_), fmt)
|
self.view_specific_format.emit(int(id_), fmt)
|
||||||
|
elif typ == 'devpath':
|
||||||
|
path = os.path.dirname(val)
|
||||||
|
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
|
||||||
|
|
||||||
|
|
||||||
def mouseReleaseEvent(self, ev):
|
def mouseReleaseEvent(self, ev):
|
||||||
ev.accept()
|
ev.accept()
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
|
|
||||||
from PyQt4.Qt import QStatusBar, QLabel, QWidget, QHBoxLayout, QPixmap, \
|
from PyQt4.Qt import QStatusBar, QLabel, QWidget, QHBoxLayout, QPixmap, \
|
||||||
QSizePolicy, QScrollArea, Qt, QSize, pyqtSignal, \
|
QSizePolicy, QScrollArea, Qt, QSize, pyqtSignal, \
|
||||||
QPropertyAnimation, QEasingCurve
|
QPropertyAnimation, QEasingCurve, QDesktopServices, QUrl
|
||||||
|
|
||||||
|
|
||||||
from calibre import fit_image, preferred_encoding, isosx
|
from calibre import fit_image, preferred_encoding, isosx
|
||||||
@ -231,9 +231,13 @@ class StatusBar(QStatusBar, StatusBarInterface, BookDetailsInterface):
|
|||||||
typ, _, val = link.partition(':')
|
typ, _, val = link.partition(':')
|
||||||
if typ == 'path':
|
if typ == 'path':
|
||||||
self.open_containing_folder.emit(int(val))
|
self.open_containing_folder.emit(int(val))
|
||||||
if typ == 'format':
|
elif typ == 'format':
|
||||||
id_, fmt = val.split(':')
|
id_, fmt = val.split(':')
|
||||||
self.view_specific_format.emit(int(id_), fmt)
|
self.view_specific_format.emit(int(id_), fmt)
|
||||||
|
elif typ == 'devpath':
|
||||||
|
path = os.path.dirname(val)
|
||||||
|
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
|
||||||
|
|
||||||
|
|
||||||
def resizeEvent(self, ev):
|
def resizeEvent(self, ev):
|
||||||
self.resized.emit(self.size())
|
self.resized.emit(self.size())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user