11 try: |
11 try: |
12 str = unicode # __IGNORE_EXCEPTION__ |
12 str = unicode # __IGNORE_EXCEPTION__ |
13 except NameError: |
13 except NameError: |
14 pass |
14 pass |
15 |
15 |
16 from PyQt5.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, QTimer, \ |
16 from PyQt5.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, QTimer |
17 qVersion |
|
18 from PyQt5.QtGui import QColor, QPalette, QLinearGradient, QIcon |
17 from PyQt5.QtGui import QColor, QPalette, QLinearGradient, QIcon |
19 from PyQt5.QtWidgets import QDialog, QApplication |
18 from PyQt5.QtWidgets import QDialog, QApplication |
20 try: |
|
21 from PyQt5.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ |
|
22 except ImportError: |
|
23 QSslCertificate = None # __IGNORE_WARNING__ |
|
24 from PyQt5.QtWebEngineWidgets import QWebEnginePage |
19 from PyQt5.QtWebEngineWidgets import QWebEnginePage |
25 |
20 |
26 from E5Gui.E5LineEdit import E5LineEdit |
21 from E5Gui.E5LineEdit import E5LineEdit |
27 from E5Gui.E5LineEditButton import E5LineEditButton |
22 from E5Gui.E5LineEditButton import E5LineEditButton |
28 |
23 |
29 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
24 from WebBrowser.WebBrowserWindow import WebBrowserWindow |
30 |
25 |
31 from .FavIconLabel import FavIconLabel |
26 from .FavIconLabel import FavIconLabel |
32 ##from .SslLabel import SslLabel |
|
33 ## |
|
34 import UI.PixmapCache |
27 import UI.PixmapCache |
35 import Preferences |
28 import Preferences |
36 import Utilities |
|
37 |
29 |
38 |
30 |
39 class UrlBar(E5LineEdit): |
31 class UrlBar(E5LineEdit): |
40 """ |
32 """ |
41 Class implementing a line edit for entering URLs. |
33 Class implementing a line edit for entering URLs. |
59 self.__bmInactiveIcon = QIcon( |
51 self.__bmInactiveIcon = QIcon( |
60 self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) |
52 self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) |
61 |
53 |
62 self.__favicon = FavIconLabel(self) |
54 self.__favicon = FavIconLabel(self) |
63 self.addWidget(self.__favicon, E5LineEdit.LeftSide) |
55 self.addWidget(self.__favicon, E5LineEdit.LeftSide) |
64 |
|
65 # TODO: SSL |
|
66 ## self.__sslLabel = SslLabel(self) |
|
67 ## self.addWidget(self.__sslLabel, E5LineEdit.LeftSide) |
|
68 ## self.__sslLabel.setVisible(False) |
|
69 |
56 |
70 self.__rssButton = E5LineEditButton(self) |
57 self.__rssButton = E5LineEditButton(self) |
71 self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) |
58 self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) |
72 self.addWidget(self.__rssButton, E5LineEdit.RightSide) |
59 self.addWidget(self.__rssButton, E5LineEdit.RightSide) |
73 self.__rssButton.setVisible(False) |
60 self.__rssButton.setVisible(False) |
106 |
93 |
107 self.__browser.urlChanged.connect(self.__browserUrlChanged) |
94 self.__browser.urlChanged.connect(self.__browserUrlChanged) |
108 self.__browser.loadProgress.connect(self.update) |
95 self.__browser.loadProgress.connect(self.update) |
109 self.__browser.loadFinished.connect(self.__loadFinished) |
96 self.__browser.loadFinished.connect(self.__loadFinished) |
110 self.__browser.loadStarted.connect(self.__loadStarted) |
97 self.__browser.loadStarted.connect(self.__loadStarted) |
111 |
|
112 # TODO: SSL |
|
113 ## self.__sslLabel.clicked.connect(self.__browser.page().showSslInfo) |
|
114 |
98 |
115 def browser(self): |
99 def browser(self): |
116 """ |
100 """ |
117 Public method to get the associated browser. |
101 Public method to get the associated browser. |
118 |
102 |
137 |
121 |
138 def __loadStarted(self): |
122 def __loadStarted(self): |
139 """ |
123 """ |
140 Private slot to perform actions before the page is loaded. |
124 Private slot to perform actions before the page is loaded. |
141 """ |
125 """ |
142 pass |
|
143 # TODO: SSL |
|
144 ## self.__sslLabel.setVisible(False) |
|
145 self.__bookmarkButton.setVisible(False) |
126 self.__bookmarkButton.setVisible(False) |
146 self.__rssButton.setVisible(False) |
127 self.__rssButton.setVisible(False) |
147 |
128 |
148 def __checkBookmark(self): |
129 def __checkBookmark(self): |
149 """ |
130 """ |
176 self.__checkBookmark() |
157 self.__checkBookmark() |
177 self.__bookmarkButton.setVisible(True) |
158 self.__bookmarkButton.setVisible(True) |
178 |
159 |
179 if ok: |
160 if ok: |
180 QTimer.singleShot(0, self.__setRssButton) |
161 QTimer.singleShot(0, self.__setRssButton) |
181 |
|
182 # TODO: SSL certificate stuff (if possible) |
|
183 ## if ok and \ |
|
184 ## self.__browser.url().scheme() == "https" and \ |
|
185 ## QSslCertificate is not None: |
|
186 ## sslInfo = self.__browser.page().getSslCertificate() |
|
187 ## if sslInfo is not None: |
|
188 ## org = Utilities.decodeString(", ".join( |
|
189 ## sslInfo.subjectInfo(QSslCertificate.Organization))) |
|
190 ## if org == "": |
|
191 ## cn = Utilities.decodeString(", ".join( |
|
192 ## sslInfo.subjectInfo( |
|
193 ## QSslCertificate.CommonName))) |
|
194 ## if cn != "": |
|
195 ## org = cn.split(".", 1)[1] |
|
196 ## if org == "": |
|
197 ## org = self.tr("Unknown") |
|
198 ## self.__sslLabel.setText(" {0} ".format(org)) |
|
199 ## self.__sslLabel.setVisible(True) |
|
200 ## valid = not sslInfo.isBlacklisted() |
|
201 ## if valid: |
|
202 ## config = self.__browser.page().getSslConfiguration() |
|
203 ## if config is None or config.sessionCipher().isNull(): |
|
204 ## valid = False |
|
205 ## self.__sslLabel.setValidity(valid) |
|
206 ## return |
|
207 ## |
|
208 ## self.__sslLabel.setVisible(False) |
|
209 ## except RuntimeError: |
|
210 ## pass |
|
211 |
162 |
212 def __textChanged(self, txt): |
163 def __textChanged(self, txt): |
213 """ |
164 """ |
214 Private slot to handle changes of the text. |
165 Private slot to handle changes of the text. |
215 |
166 |
270 if self.__browser is not None: |
221 if self.__browser is not None: |
271 p = self.palette() |
222 p = self.palette() |
272 progress = self.__browser.progress() |
223 progress = self.__browser.progress() |
273 if progress == 0 or progress == 100: |
224 if progress == 0 or progress == 100: |
274 if self.__browser.url().scheme() == "https": |
225 if self.__browser.url().scheme() == "https": |
275 ## if QSslCertificate is not None: |
|
276 ## if self.__browser.page().hasValidSslInfo(): |
|
277 ## backgroundColor = Preferences.getWebBrowser( |
|
278 ## "SaveUrlColor") |
|
279 ## else: |
|
280 backgroundColor = Preferences.getWebBrowser( |
226 backgroundColor = Preferences.getWebBrowser( |
281 "SaveUrlColor") |
227 "SaveUrlColor") |
282 p.setBrush(QPalette.Base, backgroundColor) |
228 p.setBrush(QPalette.Base, backgroundColor) |
283 p.setBrush(QPalette.Text, foregroundColor) |
229 p.setBrush(QPalette.Text, foregroundColor) |
284 else: |
230 else: |
285 if self.__browser.url().scheme() == "https": |
231 if self.__browser.url().scheme() == "https": |
286 ## if QSslCertificate is not None: |
|
287 ## if self.__browser.page().hasValidSslInfo(): |
|
288 ## backgroundColor = Preferences.getWebBrowser( |
|
289 ## "SaveUrlColor") |
|
290 ## else: |
|
291 backgroundColor = Preferences.getWebBrowser( |
232 backgroundColor = Preferences.getWebBrowser( |
292 "SaveUrlColor") |
233 "SaveUrlColor") |
293 highlight = QApplication.palette().color(QPalette.Highlight) |
234 highlight = QApplication.palette().color(QPalette.Highlight) |
294 r = (highlight.red() + 2 * backgroundColor.red()) // 3 |
235 r = (highlight.red() + 2 * backgroundColor.red()) // 3 |
295 g = (highlight.green() + 2 * backgroundColor.green()) // 3 |
236 g = (highlight.green() + 2 * backgroundColor.green()) // 3 |