mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Revert "Simplify code for managing multiple book info dialogs"
This reverts commit 5d6664b00250f9ce174a88cf0982e1a9dc774bf0.
This commit is contained in:
parent
5f515131a5
commit
ecb22f5e61
@ -23,45 +23,61 @@ class ShowBookDetailsAction(InterfaceAction):
|
|||||||
def genesis(self):
|
def genesis(self):
|
||||||
self.qaction.triggered.connect(self.show_book_info)
|
self.qaction.triggered.connect(self.show_book_info)
|
||||||
self.memory = []
|
self.memory = []
|
||||||
|
self.dialogs = [None, ]
|
||||||
|
|
||||||
def show_book_info(self, *args, **kwargs):
|
def show_book_info(self, *args, **kwargs):
|
||||||
|
if self.gui.current_view() is not self.gui.library_view:
|
||||||
|
error_dialog(self.gui, _('No detailed info available'),
|
||||||
|
_('No detailed information is available for books '
|
||||||
|
'on the device.')).exec()
|
||||||
|
return
|
||||||
library_path = kwargs.get('library_path', None)
|
library_path = kwargs.get('library_path', None)
|
||||||
book_id = kwargs.get('book_id', None)
|
book_id = kwargs.get('book_id', None)
|
||||||
library_id = kwargs.get('library_id', None)
|
library_id = kwargs.get('library_id', None)
|
||||||
query = kwargs.get('query', None)
|
query = kwargs.get('query', None)
|
||||||
index = self.gui.library_view.currentIndex()
|
index = self.gui.library_view.currentIndex()
|
||||||
if self.gui.current_view() is not self.gui.library_view and not library_path:
|
|
||||||
error_dialog(self.gui, _('No detailed info available'),
|
|
||||||
_('No detailed information is available for books '
|
|
||||||
'on the device.')).exec()
|
|
||||||
return
|
|
||||||
if library_path or index.isValid():
|
if library_path or index.isValid():
|
||||||
|
# Window #0 is slaved to changes in the book list. As such
|
||||||
|
# it must not be used for details from other libraries.
|
||||||
|
for dn,v in enumerate(self.dialogs):
|
||||||
|
if dn == 0 and library_path:
|
||||||
|
continue
|
||||||
|
if v is None:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.dialogs.append(None)
|
||||||
|
dn += 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
d = BookInfo(self.gui, self.gui.library_view, index,
|
d = BookInfo(self.gui, self.gui.library_view, index,
|
||||||
self.gui.book_details.handle_click,
|
self.gui.book_details.handle_click, dialog_number=dn,
|
||||||
library_id=library_id, library_path=library_path, book_id=book_id, query=query)
|
library_id=library_id, library_path=library_path, book_id=book_id, query=query)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
error_dialog(self.gui, _('Book not found'), str(e)).exec()
|
error_dialog(self.gui, _('Book not found'), str(e)).exec()
|
||||||
return
|
return
|
||||||
|
|
||||||
d.open_cover_with.connect(self.gui.bd_open_cover_with, type=Qt.ConnectionType.QueuedConnection)
|
d.open_cover_with.connect(self.gui.bd_open_cover_with, type=Qt.ConnectionType.QueuedConnection)
|
||||||
|
self.dialogs[dn] = d
|
||||||
self.memory.append(d)
|
self.memory.append(d)
|
||||||
d.closed.connect(self.closed, type=Qt.ConnectionType.QueuedConnection)
|
d.closed.connect(self.closed, type=Qt.ConnectionType.QueuedConnection)
|
||||||
d.show()
|
d.show()
|
||||||
|
|
||||||
def shutting_down(self):
|
def shutting_down(self):
|
||||||
for d in self.memory:
|
for d in self.dialogs:
|
||||||
d.close()
|
if d:
|
||||||
self.memory = []
|
d.done(0)
|
||||||
|
|
||||||
def library_about_to_change(self, *args):
|
def library_about_to_change(self, *args):
|
||||||
for d in self.memory:
|
for i,d in enumerate(self.dialogs):
|
||||||
if d.for_external_library:
|
if i == 0:
|
||||||
d.close()
|
continue
|
||||||
|
if d:
|
||||||
|
d.done(0)
|
||||||
|
|
||||||
def closed(self, d):
|
def closed(self, d):
|
||||||
try:
|
try:
|
||||||
d.closed.disconnect(self.closed)
|
d.closed.disconnect(self.closed)
|
||||||
|
self.dialogs[d.dialog_number] = None
|
||||||
self.memory.remove(d)
|
self.memory.remove(d)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
@ -135,10 +135,10 @@ class BookInfo(QDialog):
|
|||||||
closed = pyqtSignal(object)
|
closed = pyqtSignal(object)
|
||||||
open_cover_with = pyqtSignal(object, object)
|
open_cover_with = pyqtSignal(object, object)
|
||||||
|
|
||||||
def __init__(self, parent, view, row, link_delegate,
|
def __init__(self, parent, view, row, link_delegate, dialog_number=None,
|
||||||
library_id=None, library_path=None, book_id=None, query=None):
|
library_id=None, library_path=None, book_id=None, query=None):
|
||||||
QDialog.__init__(self, None, flags=Qt.WindowType.Window)
|
QDialog.__init__(self, None, flags=Qt.WindowType.Window)
|
||||||
self.for_external_library = bool(library_path)
|
self.dialog_number = dialog_number
|
||||||
self.library_id = library_id
|
self.library_id = library_id
|
||||||
self.marked = None
|
self.marked = None
|
||||||
self.gui = parent
|
self.gui = parent
|
||||||
@ -179,7 +179,7 @@ class BookInfo(QDialog):
|
|||||||
hl.setContentsMargins(0, 0, 0, 0)
|
hl.setContentsMargins(0, 0, 0, 0)
|
||||||
l2.addLayout(hl, l2.rowCount(), 0, 1, -1)
|
l2.addLayout(hl, l2.rowCount(), 0, 1, -1)
|
||||||
hl.addWidget(self.fit_cover), hl.addStretch()
|
hl.addWidget(self.fit_cover), hl.addStretch()
|
||||||
if not self.for_external_library:
|
if self.dialog_number == 0:
|
||||||
self.previous_button = QPushButton(QIcon.ic('previous.png'), _('&Previous'), self)
|
self.previous_button = QPushButton(QIcon.ic('previous.png'), _('&Previous'), self)
|
||||||
self.previous_button.clicked.connect(self.previous)
|
self.previous_button.clicked.connect(self.previous)
|
||||||
l2.addWidget(self.previous_button, l2.rowCount(), 0)
|
l2.addWidget(self.previous_button, l2.rowCount(), 0)
|
||||||
@ -218,7 +218,7 @@ class BookInfo(QDialog):
|
|||||||
self.refresh(row, mi)
|
self.refresh(row, mi)
|
||||||
else:
|
else:
|
||||||
self.view = view
|
self.view = view
|
||||||
if not self.for_external_library:
|
if dialog_number == 0:
|
||||||
self.slave_connected = True
|
self.slave_connected = True
|
||||||
self.view.model().new_bookdisplay_data.connect(self.slave)
|
self.view.model().new_bookdisplay_data.connect(self.slave)
|
||||||
self.refresh(row)
|
self.refresh(row)
|
||||||
@ -245,9 +245,9 @@ class BookInfo(QDialog):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def geometry_string(self, txt):
|
def geometry_string(self, txt):
|
||||||
if self.for_external_library:
|
if self.dialog_number is None or self.dialog_number == 0:
|
||||||
txt += '_' + 'for_external_library'
|
return txt
|
||||||
return txt
|
return txt + '_' + str(self.dialog_number)
|
||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
try:
|
try:
|
||||||
@ -378,7 +378,7 @@ class BookInfo(QDialog):
|
|||||||
# Indicates books was deleted from library, or row numbers have
|
# Indicates books was deleted from library, or row numbers have
|
||||||
# changed
|
# changed
|
||||||
return
|
return
|
||||||
if not self.for_external_library:
|
if self.dialog_number == 0:
|
||||||
self.previous_button.setEnabled(False if row == 0 else True)
|
self.previous_button.setEnabled(False if row == 0 else True)
|
||||||
self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True)
|
self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True)
|
||||||
self.setWindowTitle(mi.title + ' ' + _('(the current book)'))
|
self.setWindowTitle(mi.title + ' ' + _('(the current book)'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user