Only update the image in CoverImageWidget if the url matches the current url

This fixes an issue causing the first issue cover to show when using the auto-identify feature
Fixes #455
This commit is contained in:
Timmy Welch 2023-04-25 01:59:24 -07:00
parent c07e1c4168
commit d3ff40c249
No known key found for this signature in database
4 changed files with 16 additions and 12 deletions

View File

@ -60,7 +60,7 @@ class CoverImageWidget(QtWidgets.QWidget):
URLMode = 1
DataMode = 3
image_fetch_complete = QtCore.pyqtSignal(QtCore.QByteArray)
image_fetch_complete = QtCore.pyqtSignal(str, QtCore.QByteArray)
def __init__(
self,
@ -201,7 +201,7 @@ class CoverImageWidget(QtWidgets.QWidget):
elif self.mode in [CoverImageWidget.AltCoverMode, CoverImageWidget.URLMode]:
self.load_url()
elif self.mode == CoverImageWidget.DataMode:
self.cover_remote_fetch_complete(self.imageData)
self.cover_remote_fetch_complete("", self.imageData)
else:
self.load_page()
@ -238,7 +238,9 @@ class CoverImageWidget(QtWidgets.QWidget):
self.cover_fetcher.fetch(self.url_list[self.imageIndex])
# called when the image is done loading from internet
def cover_remote_fetch_complete(self, image_data: bytes) -> None:
def cover_remote_fetch_complete(self, url: str, image_data: bytes) -> None:
if url and url not in self.url_list:
return
img = get_qimage_from_data(image_data)
self.current_pixmap = QtGui.QPixmap.fromImage(img)
self.set_display_pixmap()

View File

@ -41,7 +41,7 @@ class ImageFetcherException(Exception):
...
def fetch_complete(image_data: bytes | QtCore.QByteArray) -> None:
def fetch_complete(url: str, image_data: bytes | QtCore.QByteArray) -> None:
...
@ -79,22 +79,22 @@ class ImageFetcher:
# first look in the DB
image_data = self.get_image_from_cache(url)
# Async for retrieving covers seems to work well
if blocking: # if blocking or not qt_available:
if blocking or not qt_available:
if not image_data:
try:
image_data = requests.get(url, headers={"user-agent": "comictagger/" + ctversion.version}).content
# save the image to the cache
self.add_image_to_cache(self.fetched_url, image_data)
except Exception as e:
logger.exception("Fetching url failed: %s")
raise ImageFetcherException("Network Error!") from e
# save the image to the cache
self.add_image_to_cache(self.fetched_url, image_data)
ImageFetcher.image_fetch_complete(url, image_data)
return image_data
if qt_available:
# if we found it, just emit the signal asap
if image_data:
ImageFetcher.image_fetch_complete(QtCore.QByteArray(image_data))
ImageFetcher.image_fetch_complete(url, QtCore.QByteArray(image_data))
return b""
# didn't find it. look online
@ -110,9 +110,9 @@ class ImageFetcher:
image_data = reply.readAll()
# save the image to the cache
self.add_image_to_cache(self.fetched_url, image_data)
self.add_image_to_cache(reply.request().url().toString(), image_data)
ImageFetcher.image_fetch_complete(image_data)
ImageFetcher.image_fetch_complete(reply.request().url().toString(), image_data)
def create_image_db(self) -> None:
# this will wipe out any existing version

View File

@ -106,7 +106,7 @@ class IssueSelectionWindow(QtWidgets.QDialog):
# now that the list has been sorted, find the initial record, and
# select it
if self.initial_id is None:
if not self.initial_id:
self.twList.selectRow(0)
else:
for r in range(0, self.twList.rowCount()):

View File

@ -326,6 +326,8 @@ class SeriesSelectionWindow(QtWidgets.QDialog):
self.issue_number = selector.issue_number
self.issue_id = selector.issue_id
self.accept()
else:
self.imageWidget.update_content()
def select_by_id(self) -> None:
for r in range(0, self.twList.rowCount()):