mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit metadata dialog: Add an action to open the book's folder to the context menu of the formats list. Fixes #2083583 [[Enhancement] Action to open the Book folder when you right click the format in Edit metadata window](https://bugs.launchpad.net/calibre/+bug/2083583)
This commit is contained in:
parent
bad1a15d0e
commit
3b6dfdeaa5
@ -5,7 +5,7 @@
|
|||||||
from time import monotonic
|
from time import monotonic
|
||||||
from typing import NamedTuple, Tuple
|
from typing import NamedTuple, Tuple
|
||||||
|
|
||||||
from qt.core import QObject, QTimer
|
from qt.core import QObject, QTimer, pyqtSignal
|
||||||
|
|
||||||
from calibre.db.constants import DATA_FILE_PATTERN
|
from calibre.db.constants import DATA_FILE_PATTERN
|
||||||
|
|
||||||
@ -23,6 +23,7 @@ class ExtraFiles(NamedTuple):
|
|||||||
|
|
||||||
class ExtraFilesWatcher(QObject):
|
class ExtraFilesWatcher(QObject):
|
||||||
|
|
||||||
|
books_changed = pyqtSignal(object)
|
||||||
WATCH_FOR = 300 # seconds
|
WATCH_FOR = 300 # seconds
|
||||||
TICK_INTERVAL = 1 # seconds
|
TICK_INTERVAL = 1 # seconds
|
||||||
|
|
||||||
@ -86,4 +87,6 @@ class ExtraFilesWatcher(QObject):
|
|||||||
|
|
||||||
def refresh_gui(self, book_ids):
|
def refresh_gui(self, book_ids):
|
||||||
lv = self.gui.library_view
|
lv = self.gui.library_view
|
||||||
lv.model().refresh_ids(frozenset(book_ids), current_row=lv.currentIndex().row())
|
book_ids = frozenset(book_ids)
|
||||||
|
lv.model().refresh_ids(book_ids, current_row=lv.currentIndex().row())
|
||||||
|
self.books_changed.emit(book_ids)
|
||||||
|
@ -858,6 +858,7 @@ class FormatList(_FormatList):
|
|||||||
restore_fmt = pyqtSignal(object)
|
restore_fmt = pyqtSignal(object)
|
||||||
view_fmt = pyqtSignal(object)
|
view_fmt = pyqtSignal(object)
|
||||||
edit_fmt = pyqtSignal(object)
|
edit_fmt = pyqtSignal(object)
|
||||||
|
open_book_folder = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
_FormatList.__init__(self, parent)
|
_FormatList.__init__(self, parent)
|
||||||
@ -873,28 +874,30 @@ class FormatList(_FormatList):
|
|||||||
originals = [self.item(x).ext.upper() for x in range(self.count())]
|
originals = [self.item(x).ext.upper() for x in range(self.count())]
|
||||||
originals = [x for x in originals if x.startswith('ORIGINAL_')]
|
originals = [x for x in originals if x.startswith('ORIGINAL_')]
|
||||||
|
|
||||||
if item or originals:
|
self.cm = cm = QMenu(self)
|
||||||
self.cm = cm = QMenu(self)
|
|
||||||
|
|
||||||
if item:
|
if item:
|
||||||
action = ViewAction(item, cm)
|
action = ViewAction(item, cm)
|
||||||
action.view_fmt.connect(self.view_fmt, type=Qt.ConnectionType.QueuedConnection)
|
action.view_fmt.connect(self.view_fmt, type=Qt.ConnectionType.QueuedConnection)
|
||||||
|
cm.addAction(action)
|
||||||
|
|
||||||
|
if item.ext.upper() in EDIT_SUPPORTED:
|
||||||
|
action = EditAction(item, cm)
|
||||||
|
action.edit_fmt.connect(self.edit_fmt, type=Qt.ConnectionType.QueuedConnection)
|
||||||
cm.addAction(action)
|
cm.addAction(action)
|
||||||
|
|
||||||
if item.ext.upper() in EDIT_SUPPORTED:
|
if item and originals:
|
||||||
action = EditAction(item, cm)
|
cm.addSeparator()
|
||||||
action.edit_fmt.connect(self.edit_fmt, type=Qt.ConnectionType.QueuedConnection)
|
|
||||||
cm.addAction(action)
|
|
||||||
|
|
||||||
if item and originals:
|
for fmt in originals:
|
||||||
cm.addSeparator()
|
action = OrigAction(fmt, cm)
|
||||||
|
action.restore_fmt.connect(self.restore_fmt)
|
||||||
for fmt in originals:
|
cm.addAction(action)
|
||||||
action = OrigAction(fmt, cm)
|
ac = QAction(_('Open book folder'), cm)
|
||||||
action.restore_fmt.connect(self.restore_fmt)
|
ac.triggered.connect(self.open_book_folder)
|
||||||
cm.addAction(action)
|
cm.addAction(ac)
|
||||||
cm.popup(event.globalPos())
|
cm.popup(event.globalPos())
|
||||||
event.accept()
|
event.accept()
|
||||||
|
|
||||||
def remove_format(self, fmt):
|
def remove_format(self, fmt):
|
||||||
for i in range(self.count()):
|
for i in range(self.count()):
|
||||||
@ -959,6 +962,7 @@ class FormatsManager(QWidget):
|
|||||||
self.formats.formats_dropped.connect(self.formats_dropped)
|
self.formats.formats_dropped.connect(self.formats_dropped)
|
||||||
self.formats.restore_fmt.connect(self.restore_fmt)
|
self.formats.restore_fmt.connect(self.restore_fmt)
|
||||||
self.formats.view_fmt.connect(self.show_format)
|
self.formats.view_fmt.connect(self.show_format)
|
||||||
|
self.formats.open_book_folder.connect(self.open_book_folder)
|
||||||
self.formats.edit_fmt.connect(self.edit_format)
|
self.formats.edit_fmt.connect(self.edit_format)
|
||||||
self.formats.delete_format.connect(self.remove_format)
|
self.formats.delete_format.connect(self.remove_format)
|
||||||
self.formats.itemDoubleClicked.connect(self.show_format)
|
self.formats.itemDoubleClicked.connect(self.show_format)
|
||||||
@ -1093,6 +1097,9 @@ class FormatsManager(QWidget):
|
|||||||
def show_format(self, item, *args):
|
def show_format(self, item, *args):
|
||||||
self.dialog.do_view_format(item.path, item.ext)
|
self.dialog.do_view_format(item.path, item.ext)
|
||||||
|
|
||||||
|
def open_book_folder(self, *a):
|
||||||
|
self.dialog.do_open_book_folder()
|
||||||
|
|
||||||
def edit_format(self, item, *args):
|
def edit_format(self, item, *args):
|
||||||
from calibre.gui2.widgets import BusyCursor
|
from calibre.gui2.widgets import BusyCursor
|
||||||
with BusyCursor():
|
with BusyCursor():
|
||||||
|
@ -399,6 +399,10 @@ class MetadataSingleDialogBase(QDialog):
|
|||||||
else:
|
else:
|
||||||
self.view_format.emit(self.book_id, fmt)
|
self.view_format.emit(self.book_id, fmt)
|
||||||
|
|
||||||
|
def do_open_book_folder(self):
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
get_gui().iactions['View'].view_folder_for_id(self.book_id)
|
||||||
|
|
||||||
def do_edit_format(self, path, fmt):
|
def do_edit_format(self, path, fmt):
|
||||||
if self.was_data_edited:
|
if self.was_data_edited:
|
||||||
from calibre.gui2.tweak_book import tprefs
|
from calibre.gui2.tweak_book import tprefs
|
||||||
@ -1330,11 +1334,15 @@ def edit_metadata(db, row_list, current_row, parent=None, view_slot=None, edit_s
|
|||||||
if cls not in editors:
|
if cls not in editors:
|
||||||
cls = 'default'
|
cls = 'default'
|
||||||
d = editors[cls](db, parent, editing_multiple=editing_multiple)
|
d = editors[cls](db, parent, editing_multiple=editing_multiple)
|
||||||
|
if hasattr(parent, 'extra_files_watcher'):
|
||||||
|
conn = parent.extra_files_watcher.books_changed.connect(d.update_data_files_button)
|
||||||
try:
|
try:
|
||||||
d.start(row_list, current_row, view_slot=view_slot, edit_slot=edit_slot,
|
d.start(row_list, current_row, view_slot=view_slot, edit_slot=edit_slot,
|
||||||
set_current_callback=set_current_callback)
|
set_current_callback=set_current_callback)
|
||||||
return d.changed, d.rows_to_refresh
|
return d.changed, d.rows_to_refresh
|
||||||
finally:
|
finally:
|
||||||
|
if hasattr(parent, 'extra_files_watcher'):
|
||||||
|
parent.extra_files_watcher.disconnect(conn)
|
||||||
# possible workaround for bug reports of occasional ghost edit metadata dialog on windows
|
# possible workaround for bug reports of occasional ghost edit metadata dialog on windows
|
||||||
d.deleteLater()
|
d.deleteLater()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user