10 |
10 |
11 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject |
11 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject |
12 from PyQt5.QtGui import QIcon, QPixmap, QImage |
12 from PyQt5.QtGui import QIcon, QPixmap, QImage |
13 from PyQt5.QtNetwork import QNetworkRequest, QSslConfiguration |
13 from PyQt5.QtNetwork import QNetworkRequest, QSslConfiguration |
14 |
14 |
|
15 try: |
|
16 from PyQt5.QtNetwork import QSslConfiguration # __IGNORE_WARNING__ |
|
17 SSL_AVAILABLE = True |
|
18 except ImportError: |
|
19 SSL_AVAILABLE = False |
|
20 |
15 import WebBrowser.WebBrowserWindow |
21 import WebBrowser.WebBrowserWindow |
16 |
22 |
17 |
23 |
18 class WebIconLoader(QObject): |
24 class WebIconLoader(QObject): |
19 """ |
25 """ |
20 Class implementing a loader for web site icons. |
26 Class implementing a loader for web site icons. |
21 |
27 |
22 @signal iconLoaded(icon) emitted when the icon has been loaded |
28 @signal iconLoaded(icon) emitted when the icon has been loaded |
23 @signal sslConfiguration(config) emitted to pass the SSL data |
29 @signal sslConfiguration(config) emitted to pass the SSL data |
|
30 @signal clearSslConfiguration() emitted to clear stored SSL data |
24 """ |
31 """ |
25 iconLoaded = pyqtSignal(QIcon) |
32 iconLoaded = pyqtSignal(QIcon) |
26 sslConfiguration = pyqtSignal(QSslConfiguration) |
33 if SSL_AVAILABLE: |
|
34 sslConfiguration = pyqtSignal(QSslConfiguration) |
|
35 clearSslConfiguration = pyqtSignal() |
27 |
36 |
28 def __init__(self, url, parent=None): |
37 def __init__(self, url, parent=None): |
29 """ |
38 """ |
30 Constructor |
39 Constructor |
31 |
40 |
50 # ignore any errors and emit an empty icon in this case |
59 # ignore any errors and emit an empty icon in this case |
51 data = self.__reply.readAll() |
60 data = self.__reply.readAll() |
52 icon = QIcon(QPixmap.fromImage(QImage.fromData(data))) |
61 icon = QIcon(QPixmap.fromImage(QImage.fromData(data))) |
53 self.iconLoaded.emit(icon) |
62 self.iconLoaded.emit(icon) |
54 |
63 |
55 # TODO: extract SSL data as a by-product |
64 if SSL_AVAILABLE: |
56 if self.__reply.url().scheme().lower() == "https": |
65 if self.__reply.url().scheme().lower() == "https": |
57 sslConfiguration = self.__reply.sslConfiguration() |
66 sslConfiguration = self.__reply.sslConfiguration() |
58 self.sslConfiguration.emit(sslConfiguration) |
67 self.sslConfiguration.emit(sslConfiguration) |
|
68 else: |
|
69 self.clearSslConfiguration.emit() |
59 |
70 |
60 self.__reply.deleteLater() |
71 self.__reply.deleteLater() |
61 self.__reply = None |
72 self.__reply = None |