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