Revert "Simplify code for managing multiple book info dialogs"

This reverts commit 5d6664b00250f9ce174a88cf0982e1a9dc774bf0.
This commit is contained in:
Charles Haley 2023-03-31 15:31:12 +01:00
parent 5f515131a5
commit ecb22f5e61
2 changed files with 36 additions and 20 deletions

View File

@ -23,45 +23,61 @@ class ShowBookDetailsAction(InterfaceAction):
def genesis(self):
self.qaction.triggered.connect(self.show_book_info)
self.memory = []
self.dialogs = [None, ]
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)
book_id = kwargs.get('book_id', None)
library_id = kwargs.get('library_id', None)
query = kwargs.get('query', None)
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():
# 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:
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)
except ValueError as e:
error_dialog(self.gui, _('Book not found'), str(e)).exec()
return
d.open_cover_with.connect(self.gui.bd_open_cover_with, type=Qt.ConnectionType.QueuedConnection)
self.dialogs[dn] = d
self.memory.append(d)
d.closed.connect(self.closed, type=Qt.ConnectionType.QueuedConnection)
d.show()
def shutting_down(self):
for d in self.memory:
d.close()
self.memory = []
for d in self.dialogs:
if d:
d.done(0)
def library_about_to_change(self, *args):
for d in self.memory:
if d.for_external_library:
d.close()
for i,d in enumerate(self.dialogs):
if i == 0:
continue
if d:
d.done(0)
def closed(self, d):
try:
d.closed.disconnect(self.closed)
self.dialogs[d.dialog_number] = None
self.memory.remove(d)
except ValueError:
pass

View File

@ -135,10 +135,10 @@ class BookInfo(QDialog):
closed = pyqtSignal(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):
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.marked = None
self.gui = parent
@ -179,7 +179,7 @@ class BookInfo(QDialog):
hl.setContentsMargins(0, 0, 0, 0)
l2.addLayout(hl, l2.rowCount(), 0, 1, -1)
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.clicked.connect(self.previous)
l2.addWidget(self.previous_button, l2.rowCount(), 0)
@ -218,7 +218,7 @@ class BookInfo(QDialog):
self.refresh(row, mi)
else:
self.view = view
if not self.for_external_library:
if dialog_number == 0:
self.slave_connected = True
self.view.model().new_bookdisplay_data.connect(self.slave)
self.refresh(row)
@ -245,9 +245,9 @@ class BookInfo(QDialog):
pass
def geometry_string(self, txt):
if self.for_external_library:
txt += '_' + 'for_external_library'
if self.dialog_number is None or self.dialog_number == 0:
return txt
return txt + '_' + str(self.dialog_number)
def sizeHint(self):
try:
@ -378,7 +378,7 @@ class BookInfo(QDialog):
# Indicates books was deleted from library, or row numbers have
# changed
return
if not self.for_external_library:
if self.dialog_number == 0:
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.setWindowTitle(mi.title + ' ' + _('(the current book)'))