314 |
314 |
315 from .PageThumbnailer import PageThumbnailer |
315 from .PageThumbnailer import PageThumbnailer |
316 thumbnailer = PageThumbnailer(self) |
316 thumbnailer = PageThumbnailer(self) |
317 thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) |
317 thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) |
318 thumbnailer.setLoadTitle(loadTitle) |
318 thumbnailer.setLoadTitle(loadTitle) |
319 thumbnailer.thumbnailCreated.connect(self.__thumbnailCreated) |
319 thumbnailer.thumbnailCreated.connect( |
|
320 lambda imag: self.__thumbnailCreated(imag, thumbnailer)) |
320 self.__thumbnailers.append(thumbnailer) |
321 self.__thumbnailers.append(thumbnailer) |
321 |
322 |
322 thumbnailer.start() |
323 thumbnailer.start() |
323 |
324 |
324 @pyqtSlot(str) |
325 @pyqtSlot(str) |
386 |
387 |
387 @return speed dial size (integer) |
388 @return speed dial size (integer) |
388 """ |
389 """ |
389 return self.__speedDialSize |
390 return self.__speedDialSize |
390 |
391 |
391 def __thumbnailCreated(self, image): |
392 def __thumbnailCreated(self, image, thumbnailer): |
392 """ |
393 """ |
393 Private slot to handle the creation of a thumbnail image. |
394 Private slot to handle the creation of a thumbnail image. |
394 |
395 |
395 @param image thumbnail image (QPixmap) |
396 @param image thumbnail image |
396 """ |
397 @type QPixmap |
397 from .PageThumbnailer import PageThumbnailer |
398 @param thumbnailer reference to the page thumbnailer |
398 thumbnailer = self.sender() |
399 @type PageThumbnailer |
399 if not isinstance(thumbnailer, PageThumbnailer) or \ |
400 """ |
400 thumbnailer not in self.__thumbnailers: |
401 if thumbnailer in self.__thumbnailers: |
401 return |
402 loadTitle = thumbnailer.loadTitle() |
402 |
403 title = thumbnailer.title() |
403 loadTitle = thumbnailer.loadTitle() |
404 url = thumbnailer.url().toString() |
404 title = thumbnailer.title() |
405 fileName = self.__imageFileName(url) |
405 url = thumbnailer.url().toString() |
406 |
406 fileName = self.__imageFileName(url) |
407 if image.isNull(): |
407 |
408 fileName = "qrc:icons/brokenPage.png" |
408 if image.isNull(): |
409 title = self.tr("Unable to load") |
409 fileName = "qrc:icons/brokenPage.png" |
410 loadTitle = True |
410 title = self.tr("Unable to load") |
411 page = self.pageForUrl(thumbnailer.url()) |
411 loadTitle = True |
412 page.broken = True |
412 page = self.pageForUrl(thumbnailer.url()) |
413 else: |
413 page.broken = True |
414 if not image.save(fileName): |
414 else: |
415 qWarning( |
415 if not image.save(fileName): |
416 "SpeedDial.__thumbnailCreated: Cannot save thumbnail" |
416 qWarning( |
417 " to {0}".format(fileName)) |
417 "SpeedDial.__thumbnailCreated: Cannot save thumbnail" |
418 |
418 " to {0}".format(fileName)) |
419 fileName = QUrl.fromLocalFile(fileName).toString() |
419 |
420 |
420 fileName = QUrl.fromLocalFile(fileName).toString() |
421 self.__regenerateScript = True |
421 |
422 |
422 self.__regenerateScript = True |
423 for frame in self.__cleanFrames(): |
423 |
424 frame.evaluateJavaScript("setImageToUrl('{0}', '{1}');".format( |
424 for frame in self.__cleanFrames(): |
425 url, fileName)) |
425 frame.evaluateJavaScript("setImageToUrl('{0}', '{1}');".format( |
426 if loadTitle: |
426 url, fileName)) |
427 frame.evaluateJavaScript( |
427 if loadTitle: |
428 "setTitleToUrl('{0}', '{1}');".format( |
428 frame.evaluateJavaScript("setTitleToUrl('{0}', '{1}');".format( |
429 url, Utilities.html_uencode(title))) |
429 url, Utilities.html_uencode(title))) |
430 |
430 |
431 thumbnailer.deleteLater() |
431 thumbnailer.deleteLater() |
432 self.__thumbnailers.remove(thumbnailer) |
432 self.__thumbnailers.remove(thumbnailer) |
|
433 |
433 |
434 def __cleanFrames(self): |
434 def __cleanFrames(self): |
435 """ |
435 """ |
436 Private method to clean all frames. |
436 Private method to clean all frames. |
437 |
437 |