mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book details panel: ALlow right clicking on a format to delete it.
This commit is contained in:
parent
890b0418ed
commit
aaba01d534
@ -139,6 +139,21 @@ class DeleteAction(InterfaceAction):
|
||||
return set([])
|
||||
return set(map(self.gui.library_view.model().id, rows))
|
||||
|
||||
def remove_format_by_id(self, book_id, fmt):
|
||||
title = self.gui.current_db.title(book_id, index_is_id=True)
|
||||
if not confirm('<p>'+(_(
|
||||
'The %(fmt)s format will be <b>permanently deleted</b> from '
|
||||
'%(title)s. Are you sure?')%dict(fmt=fmt, title=title))
|
||||
+'</p>', 'library_delete_specific_format', self.gui):
|
||||
return
|
||||
|
||||
self.gui.library_view.model().db.remove_format(book_id, fmt,
|
||||
index_is_id=True, notify=False)
|
||||
self.gui.library_view.model().refresh_ids([book_id])
|
||||
self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(),
|
||||
self.gui.library_view.currentIndex())
|
||||
self.gui.tags_view.recount()
|
||||
|
||||
def delete_selected_formats(self, *args):
|
||||
ids = self._get_selected_ids()
|
||||
if not ids:
|
||||
|
@ -5,8 +5,8 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from PyQt4.Qt import (QPixmap, QSize, QWidget, Qt, pyqtSignal, QUrl,
|
||||
QPropertyAnimation, QEasingCurve, QApplication, QFontInfo,
|
||||
from PyQt4.Qt import (QPixmap, QSize, QWidget, Qt, pyqtSignal, QUrl, QIcon,
|
||||
QPropertyAnimation, QEasingCurve, QApplication, QFontInfo, QAction,
|
||||
QSizePolicy, QPainter, QRect, pyqtProperty, QLayout, QPalette, QMenu)
|
||||
from PyQt4.QtWebKit import QWebView
|
||||
|
||||
@ -382,6 +382,7 @@ class CoverView(QWidget): # {{{
|
||||
class BookInfo(QWebView):
|
||||
|
||||
link_clicked = pyqtSignal(object)
|
||||
remove_format = pyqtSignal(int, object)
|
||||
|
||||
def __init__(self, vertical, parent=None):
|
||||
QWebView.__init__(self, parent)
|
||||
@ -395,6 +396,16 @@ class BookInfo(QWebView):
|
||||
palette.setBrush(QPalette.Base, Qt.transparent)
|
||||
self.page().setPalette(palette)
|
||||
self.css = P('templates/book_details.css', data=True).decode('utf-8')
|
||||
self.remove_format_action = QAction(QIcon(I('trash.png')),
|
||||
'', self)
|
||||
self.remove_format_action.current_fmt = None
|
||||
self.remove_format_action.triggered.connect(self.remove_format_triggerred)
|
||||
|
||||
def remove_format_triggerred(self):
|
||||
f = self.remove_format_action.current_fmt
|
||||
if f:
|
||||
book_id, fmt = f
|
||||
self.remove_format.emit(book_id, fmt)
|
||||
|
||||
def link_activated(self, link):
|
||||
self._link_clicked = True
|
||||
@ -420,6 +431,32 @@ class BookInfo(QWebView):
|
||||
else:
|
||||
ev.ignore()
|
||||
|
||||
def contextMenuEvent(self, ev):
|
||||
p = self.page()
|
||||
mf = p.mainFrame()
|
||||
r = mf.hitTestContent(ev.pos())
|
||||
url = unicode(r.linkUrl().toString()).strip()
|
||||
menu = p.createStandardContextMenu()
|
||||
ca = self.pageAction(p.Copy)
|
||||
for action in list(menu.actions()):
|
||||
if action is not ca:
|
||||
menu.removeAction(action)
|
||||
if not r.isNull() and url.startswith('format:'):
|
||||
parts = url.split(':')
|
||||
try:
|
||||
book_id, fmt = int(parts[1]), parts[2]
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
else:
|
||||
self.remove_format_action.current_fmt = (book_id, fmt)
|
||||
self.remove_format_action.setText(_('Delete the %s format')%parts[
|
||||
2])
|
||||
menu.addAction(self.remove_format_action)
|
||||
if len(menu.actions()) > 0:
|
||||
menu.exec_(ev.globalPos())
|
||||
|
||||
|
||||
# }}}
|
||||
|
||||
class DetailsLayout(QLayout): # {{{
|
||||
@ -513,6 +550,7 @@ class BookDetails(QWidget): # {{{
|
||||
show_book_info = pyqtSignal()
|
||||
open_containing_folder = pyqtSignal(int)
|
||||
view_specific_format = pyqtSignal(int, object)
|
||||
remove_specific_format = pyqtSignal(int, object)
|
||||
remote_file_dropped = pyqtSignal(object, object)
|
||||
files_dropped = pyqtSignal(object, object)
|
||||
cover_changed = pyqtSignal(object, object)
|
||||
@ -579,6 +617,7 @@ class BookDetails(QWidget): # {{{
|
||||
self.book_info = BookInfo(vertical, self)
|
||||
self._layout.addWidget(self.book_info)
|
||||
self.book_info.link_clicked.connect(self.handle_click)
|
||||
self.book_info.remove_format.connect(self.remove_specific_format)
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
def handle_click(self, link):
|
||||
|
@ -265,6 +265,8 @@ class LayoutMixin(object): # {{{
|
||||
type=Qt.QueuedConnection)
|
||||
self.book_details.open_containing_folder.connect(self.iactions['View'].view_folder_for_id)
|
||||
self.book_details.view_specific_format.connect(self.iactions['View'].view_format_by_id)
|
||||
self.book_details.remove_specific_format.connect(
|
||||
self.iactions['Remove Books'].remove_format_by_id)
|
||||
|
||||
m = self.library_view.model()
|
||||
if m.rowCount(None) > 0:
|
||||
|
Loading…
x
Reference in New Issue
Block a user