mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Book details panel: Add Manage authors/series/tags/etc. to the menu when right clicking on the item
This commit is contained in:
parent
faca264f18
commit
72c82aeb05
@ -69,6 +69,23 @@ def create_search_internet_menu(callback, author=None):
|
|||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
def is_category(field):
|
||||||
|
from calibre.db.categories import find_categories
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
gui = get_gui()
|
||||||
|
fm = gui.current_db.field_metadata
|
||||||
|
return field in {x[0] for x in find_categories(fm) if fm.is_custom_field(x[0])}
|
||||||
|
|
||||||
|
|
||||||
|
def init_manage_action(ac, field, value):
|
||||||
|
from calibre.library.field_metadata import category_icon_map
|
||||||
|
ic = category_icon_map.get(field) or 'blank.png'
|
||||||
|
ac.setIcon(QIcon(I(ic)))
|
||||||
|
ac.setText(_('Manage %s') % value)
|
||||||
|
ac.current_fmt = field, value
|
||||||
|
return ac
|
||||||
|
|
||||||
|
|
||||||
def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=None): # {{{
|
def render_html(mi, css, vertical, widget, all_fields=False, render_data_func=None): # {{{
|
||||||
table, comment_fields = (render_data_func or render_data)(mi, all_fields=all_fields,
|
table, comment_fields = (render_data_func or render_data)(mi, all_fields=all_fields,
|
||||||
use_roman_numbers=config['use_roman_numerals_for_series_number'])
|
use_roman_numbers=config['use_roman_numerals_for_series_number'])
|
||||||
@ -230,10 +247,7 @@ def details_context_menu_event(view, ev, book_info): # {{{
|
|||||||
ac.setText(t)
|
ac.setText(t)
|
||||||
menu.addAction(ac)
|
menu.addAction(ac)
|
||||||
if author is not None:
|
if author is not None:
|
||||||
ac = book_info.manage_author_action
|
menu.addAction(init_manage_action(book_info.manage_action, 'authors', author))
|
||||||
ac.current_fmt = author
|
|
||||||
ac.setText(_('Manage %s') % author)
|
|
||||||
menu.addAction(ac)
|
|
||||||
if hasattr(book_info, 'search_internet'):
|
if hasattr(book_info, 'search_internet'):
|
||||||
menu.sia = sia = create_search_internet_menu(book_info.search_internet, author)
|
menu.sia = sia = create_search_internet_menu(book_info.search_internet, author)
|
||||||
menu.addMenu(sia)
|
menu.addMenu(sia)
|
||||||
@ -247,6 +261,9 @@ def details_context_menu_event(view, ev, book_info): # {{{
|
|||||||
except Exception:
|
except Exception:
|
||||||
field = value = book_id = None
|
field = value = book_id = None
|
||||||
if field:
|
if field:
|
||||||
|
if author is None and (
|
||||||
|
field in ('tags', 'series', 'publisher') or is_category(field)):
|
||||||
|
menu.addAction(init_manage_action(book_info.manage_action, field, value))
|
||||||
ac = book_info.remove_item_action
|
ac = book_info.remove_item_action
|
||||||
ac.data = (field, value, book_id)
|
ac.data = (field, value, book_id)
|
||||||
ac.setText(_('Remove %s from this book') % value)
|
ac.setText(_('Remove %s from this book') % value)
|
||||||
@ -481,7 +498,7 @@ class BookInfo(QWebView):
|
|||||||
compare_format = pyqtSignal(int, object)
|
compare_format = pyqtSignal(int, object)
|
||||||
set_cover_format = pyqtSignal(int, object)
|
set_cover_format = pyqtSignal(int, object)
|
||||||
copy_link = pyqtSignal(object)
|
copy_link = pyqtSignal(object)
|
||||||
manage_author = pyqtSignal(object)
|
manage_category = pyqtSignal(object, object)
|
||||||
open_fmt_with = pyqtSignal(int, object, object)
|
open_fmt_with = pyqtSignal(int, object, object)
|
||||||
|
|
||||||
def __init__(self, vertical, parent=None):
|
def __init__(self, vertical, parent=None):
|
||||||
@ -500,7 +517,7 @@ class BookInfo(QWebView):
|
|||||||
for x, icon in [
|
for x, icon in [
|
||||||
('remove_format', 'trash.png'), ('save_format', 'save.png'),
|
('remove_format', 'trash.png'), ('save_format', 'save.png'),
|
||||||
('restore_format', 'edit-undo.png'), ('copy_link','edit-copy.png'),
|
('restore_format', 'edit-undo.png'), ('copy_link','edit-copy.png'),
|
||||||
('manage_author', 'user_profile.png'), ('compare_format', 'diff.png'),
|
('compare_format', 'diff.png'),
|
||||||
('set_cover_format', 'default_cover.png'),
|
('set_cover_format', 'default_cover.png'),
|
||||||
]:
|
]:
|
||||||
ac = QAction(QIcon(I(icon)), '', self)
|
ac = QAction(QIcon(I(icon)), '', self)
|
||||||
@ -508,6 +525,9 @@ class BookInfo(QWebView):
|
|||||||
ac.current_url = None
|
ac.current_url = None
|
||||||
ac.triggered.connect(getattr(self, '%s_triggerred'%x))
|
ac.triggered.connect(getattr(self, '%s_triggerred'%x))
|
||||||
setattr(self, '%s_action'%x, ac)
|
setattr(self, '%s_action'%x, ac)
|
||||||
|
self.manage_action = QAction(self)
|
||||||
|
self.manage_action.current_fmt = self.manage_action.current_url = None
|
||||||
|
self.manage_action.triggered.connect(self.manage_action_triggered)
|
||||||
self.remove_item_action = ac = QAction(QIcon(I('minus.png')), '...', self)
|
self.remove_item_action = ac = QAction(QIcon(I('minus.png')), '...', self)
|
||||||
ac.data = (None, None, None)
|
ac.data = (None, None, None)
|
||||||
ac.triggered.connect(self.remove_item_triggered)
|
ac.triggered.connect(self.remove_item_triggered)
|
||||||
@ -545,8 +565,9 @@ class BookInfo(QWebView):
|
|||||||
def copy_link_triggerred(self):
|
def copy_link_triggerred(self):
|
||||||
self.context_action_triggered('copy_link')
|
self.context_action_triggered('copy_link')
|
||||||
|
|
||||||
def manage_author_triggerred(self):
|
def manage_action_triggered(self):
|
||||||
self.manage_author.emit(self.manage_author_action.current_fmt)
|
if self.manage_action.current_fmt:
|
||||||
|
self.manage_category.emit(*self.manage_action.current_fmt)
|
||||||
|
|
||||||
def link_activated(self, link):
|
def link_activated(self, link):
|
||||||
self._link_clicked = True
|
self._link_clicked = True
|
||||||
@ -696,7 +717,7 @@ class BookDetails(QWidget): # {{{
|
|||||||
open_cover_with = pyqtSignal(object, object)
|
open_cover_with = pyqtSignal(object, object)
|
||||||
cover_removed = pyqtSignal(object)
|
cover_removed = pyqtSignal(object)
|
||||||
view_device_book = pyqtSignal(object)
|
view_device_book = pyqtSignal(object)
|
||||||
manage_author = pyqtSignal(object)
|
manage_category = pyqtSignal(object, object)
|
||||||
open_fmt_with = pyqtSignal(int, object, object)
|
open_fmt_with = pyqtSignal(int, object, object)
|
||||||
|
|
||||||
# Drag 'n drop {{{
|
# Drag 'n drop {{{
|
||||||
@ -772,7 +793,7 @@ class BookDetails(QWidget): # {{{
|
|||||||
self.book_info.set_cover_format.connect(self.set_cover_from_format)
|
self.book_info.set_cover_format.connect(self.set_cover_from_format)
|
||||||
self.book_info.compare_format.connect(self.compare_specific_format)
|
self.book_info.compare_format.connect(self.compare_specific_format)
|
||||||
self.book_info.copy_link.connect(self.copy_link)
|
self.book_info.copy_link.connect(self.copy_link)
|
||||||
self.book_info.manage_author.connect(self.manage_author)
|
self.book_info.manage_category.connect(self.manage_category)
|
||||||
self.setCursor(Qt.PointingHandCursor)
|
self.setCursor(Qt.PointingHandCursor)
|
||||||
|
|
||||||
def search_internet(self, data):
|
def search_internet(self, data):
|
||||||
|
@ -655,7 +655,7 @@ class LayoutMixin(object): # {{{
|
|||||||
type=Qt.QueuedConnection)
|
type=Qt.QueuedConnection)
|
||||||
self.book_details.view_device_book.connect(
|
self.book_details.view_device_book.connect(
|
||||||
self.iactions['View'].view_device_book)
|
self.iactions['View'].view_device_book)
|
||||||
self.book_details.manage_author.connect(lambda author:self.do_author_sort_edit(self, author, select_sort=False, select_link=False))
|
self.book_details.manage_category.connect(self.manage_category_triggerred)
|
||||||
self.book_details.compare_specific_format.connect(self.compare_format)
|
self.book_details.compare_specific_format.connect(self.compare_format)
|
||||||
|
|
||||||
m = self.library_view.model()
|
m = self.library_view.model()
|
||||||
@ -665,6 +665,13 @@ class LayoutMixin(object): # {{{
|
|||||||
self.library_view.currentIndex())
|
self.library_view.currentIndex())
|
||||||
self.library_view.setFocus(Qt.OtherFocusReason)
|
self.library_view.setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
|
def manage_category_triggerred(self, field, value):
|
||||||
|
if field and value:
|
||||||
|
if field == 'authors':
|
||||||
|
self.do_author_sort_edit(self, value, select_sort=False, select_link=False)
|
||||||
|
elif field:
|
||||||
|
self.do_tags_list_edit(value, field)
|
||||||
|
|
||||||
def toggle_grid_view(self, show):
|
def toggle_grid_view(self, show):
|
||||||
self.library_view.alternate_views.show_view('grid' if show else None)
|
self.library_view.alternate_views.show_view('grid' if show else None)
|
||||||
self.sort_sep.setVisible(show)
|
self.sort_sep.setVisible(show)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user