6 """ |
6 """ |
7 Module implementing the URL bar widget. |
7 Module implementing the URL bar widget. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, qVersion |
10 from PyQt4.QtCore import pyqtSlot, Qt, QPointF, QUrl, QDateTime, qVersion |
11 from PyQt4.QtGui import QColor, QPalette, QLinearGradient, QIcon, QDialog, QApplication |
11 from PyQt4.QtGui import QColor, QPalette, QLinearGradient, QIcon, QDialog, \ |
|
12 QApplication |
12 try: |
13 try: |
13 from PyQt4.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ |
14 from PyQt4.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ |
14 except ImportError: |
15 except ImportError: |
15 QSslCertificate = None # __IGNORE_WARNING__ |
16 QSslCertificate = None # __IGNORE_WARNING__ |
16 from PyQt4.QtWebKit import QWebSettings, QWebPage |
17 from PyQt4.QtWebKit import QWebSettings, QWebPage |
47 self.__browser = None |
48 self.__browser = None |
48 self.__privateMode = QWebSettings.globalSettings().testAttribute( |
49 self.__privateMode = QWebSettings.globalSettings().testAttribute( |
49 QWebSettings.PrivateBrowsingEnabled) |
50 QWebSettings.PrivateBrowsingEnabled) |
50 |
51 |
51 self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16.png") |
52 self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16.png") |
52 self.__bmInactiveIcon = QIcon(self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) |
53 self.__bmInactiveIcon = QIcon( |
|
54 self.__bmActiveIcon.pixmap(16, 16, QIcon.Disabled)) |
53 |
55 |
54 self.__favicon = FavIconLabel(self) |
56 self.__favicon = FavIconLabel(self) |
55 self.addWidget(self.__favicon, E5LineEdit.LeftSide) |
57 self.addWidget(self.__favicon, E5LineEdit.LeftSide) |
56 |
58 |
57 self.__sslLabel = SslLabel(self) |
59 self.__sslLabel = SslLabel(self) |
58 self.addWidget(self.__sslLabel, E5LineEdit.LeftSide) |
60 self.addWidget(self.__sslLabel, E5LineEdit.LeftSide) |
59 self.__sslLabel.setVisible(False) |
61 self.__sslLabel.setVisible(False) |
60 |
62 |
61 self.__privacyButton = E5LineEditButton(self) |
63 self.__privacyButton = E5LineEditButton(self) |
62 self.__privacyButton.setIcon(UI.PixmapCache.getIcon("privateBrowsing.png")) |
64 self.__privacyButton.setIcon( |
|
65 UI.PixmapCache.getIcon("privateBrowsing.png")) |
63 self.addWidget(self.__privacyButton, E5LineEdit.RightSide) |
66 self.addWidget(self.__privacyButton, E5LineEdit.RightSide) |
64 self.__privacyButton.setVisible(self.__privateMode) |
67 self.__privacyButton.setVisible(self.__privateMode) |
65 |
68 |
66 self.__rssButton = E5LineEditButton(self) |
69 self.__rssButton = E5LineEditButton(self) |
67 self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) |
70 self.__rssButton.setIcon(UI.PixmapCache.getIcon("rss16.png")) |
82 self.__rssButton.clicked[()].connect(self.__rssClicked) |
85 self.__rssButton.clicked[()].connect(self.__rssClicked) |
83 self.__clearButton.clicked[()].connect(self.clear) |
86 self.__clearButton.clicked[()].connect(self.clear) |
84 self.__mw.privacyChanged.connect(self.__privacyButton.setVisible) |
87 self.__mw.privacyChanged.connect(self.__privacyButton.setVisible) |
85 self.textChanged.connect(self.__textChanged) |
88 self.textChanged.connect(self.__textChanged) |
86 |
89 |
87 Helpviewer.HelpWindow.HelpWindow.bookmarksManager().entryChanged.connect( |
90 Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ |
88 self.__bookmarkChanged) |
91 .entryChanged.connect(self.__bookmarkChanged) |
89 Helpviewer.HelpWindow.HelpWindow.bookmarksManager().entryAdded.connect( |
92 Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ |
90 self.__bookmarkChanged) |
93 .entryAdded.connect(self.__bookmarkChanged) |
91 Helpviewer.HelpWindow.HelpWindow.bookmarksManager().entryRemoved.connect( |
94 Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ |
92 self.__bookmarkChanged) |
95 .entryRemoved.connect(self.__bookmarkChanged) |
93 Helpviewer.HelpWindow.HelpWindow.speedDial().pagesChanged.connect( |
96 Helpviewer.HelpWindow.HelpWindow.speedDial().pagesChanged.connect( |
94 self.__bookmarkChanged) |
97 self.__bookmarkChanged) |
95 |
98 |
96 def setBrowser(self, browser): |
99 def setBrowser(self, browser): |
97 """ |
100 """ |
176 self.__browser.url().scheme() == "https" and \ |
179 self.__browser.url().scheme() == "https" and \ |
177 QSslCertificate is not None: |
180 QSslCertificate is not None: |
178 sslInfo = self.__browser.page().getSslCertificate() |
181 sslInfo = self.__browser.page().getSslCertificate() |
179 if sslInfo is not None: |
182 if sslInfo is not None: |
180 if qVersion() >= "5.0.0": |
183 if qVersion() >= "5.0.0": |
181 org = Utilities.decodeString( |
184 org = Utilities.decodeString(", ".join( |
182 ", ".join(sslInfo.subjectInfo(QSslCertificate.Organization))) |
185 sslInfo.subjectInfo(QSslCertificate.Organization))) |
183 else: |
186 else: |
184 org = Utilities.decodeString( |
187 org = Utilities.decodeString( |
185 sslInfo.subjectInfo(QSslCertificate.Organization)) |
188 sslInfo.subjectInfo(QSslCertificate.Organization)) |
186 if org == "": |
189 if org == "": |
187 if qVersion() >= "5.0.0": |
190 if qVersion() >= "5.0.0": |
188 cn = Utilities.decodeString(", ".join( |
191 cn = Utilities.decodeString(", ".join( |
189 sslInfo.subjectInfo(QSslCertificate.CommonName))) |
192 sslInfo.subjectInfo( |
|
193 QSslCertificate.CommonName))) |
190 else: |
194 else: |
191 cn = Utilities.decodeString( |
195 cn = Utilities.decodeString( |
192 sslInfo.subjectInfo(QSslCertificate.CommonName)) |
196 sslInfo.subjectInfo( |
|
197 QSslCertificate.CommonName)) |
193 if cn != "": |
198 if cn != "": |
194 org = cn.split(".", 1)[1] |
199 org = cn.split(".", 1)[1] |
195 if org == "": |
200 if org == "": |
196 org = self.trUtf8("Unknown") |
201 org = self.trUtf8("Unknown") |
197 self.__sslLabel.setText(" {0} ".format(org)) |
202 self.__sslLabel.setText(" {0} ".format(org)) |
242 |
247 |
243 def __showBookmarkInfo(self): |
248 def __showBookmarkInfo(self): |
244 """ |
249 """ |
245 Private slot to show a dialog with some bookmark info. |
250 Private slot to show a dialog with some bookmark info. |
246 """ |
251 """ |
247 from .BookmarkActionSelectionDialog import BookmarkActionSelectionDialog |
252 from .BookmarkActionSelectionDialog import \ |
|
253 BookmarkActionSelectionDialog |
248 url = self.__browser.url() |
254 url = self.__browser.url() |
249 dlg = BookmarkActionSelectionDialog(url) |
255 dlg = BookmarkActionSelectionDialog(url) |
250 if dlg.exec_() == QDialog.Accepted: |
256 if dlg.exec_() == QDialog.Accepted: |
251 action = dlg.getAction() |
257 action = dlg.getAction() |
252 if action == BookmarkActionSelectionDialog.AddBookmark: |
258 if action == BookmarkActionSelectionDialog.AddBookmark: |
288 progress = self.__browser.progress() |
294 progress = self.__browser.progress() |
289 if progress == 0 or progress == 100: |
295 if progress == 0 or progress == 100: |
290 if self.__browser.url().scheme() == "https": |
296 if self.__browser.url().scheme() == "https": |
291 if QSslCertificate is not None: |
297 if QSslCertificate is not None: |
292 if self.__browser.page().hasValidSslInfo(): |
298 if self.__browser.page().hasValidSslInfo(): |
293 backgroundColor = Preferences.getHelp("SaveUrlColor") |
299 backgroundColor = Preferences.getHelp( |
|
300 "SaveUrlColor") |
294 else: |
301 else: |
295 backgroundColor = Preferences.getHelp("SaveUrlColor") |
302 backgroundColor = Preferences.getHelp("SaveUrlColor") |
296 p.setBrush(QPalette.Base, backgroundColor) |
303 p.setBrush(QPalette.Base, backgroundColor) |
297 p.setBrush(QPalette.Text, foregroundColor) |
304 p.setBrush(QPalette.Text, foregroundColor) |
298 else: |
305 else: |
299 if self.__browser.url().scheme() == "https": |
306 if self.__browser.url().scheme() == "https": |
300 if QSslCertificate is not None: |
307 if QSslCertificate is not None: |
301 if self.__browser.page().hasValidSslInfo(): |
308 if self.__browser.page().hasValidSslInfo(): |
302 backgroundColor = Preferences.getHelp("SaveUrlColor") |
309 backgroundColor = Preferences.getHelp( |
|
310 "SaveUrlColor") |
303 else: |
311 else: |
304 backgroundColor = Preferences.getHelp("SaveUrlColor") |
312 backgroundColor = Preferences.getHelp("SaveUrlColor") |
305 highlight = QApplication.palette().color(QPalette.Highlight) |
313 highlight = QApplication.palette().color(QPalette.Highlight) |
306 r = (highlight.red() + 2 * backgroundColor.red()) // 3 |
314 r = (highlight.red() + 2 * backgroundColor.red()) // 3 |
307 g = (highlight.green() + 2 * backgroundColor.green()) // 3 |
315 g = (highlight.green() + 2 * backgroundColor.green()) // 3 |
308 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 |
316 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 |
309 |
317 |
310 loadingColor = QColor(r, g, b) |
318 loadingColor = QColor(r, g, b) |
311 if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20: |
319 if abs(loadingColor.lightness() - |
|
320 backgroundColor.lightness()) < 20: |
312 # special handling for special color schemes (e.g Gaia) |
321 # special handling for special color schemes (e.g Gaia) |
313 r = (2 * highlight.red() + backgroundColor.red()) // 3 |
322 r = (2 * highlight.red() + backgroundColor.red()) // 3 |
314 g = (2 * highlight.green() + backgroundColor.green()) // 3 |
323 g = (2 * highlight.green() + backgroundColor.green()) // 3 |
315 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 |
324 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 |
316 loadingColor = QColor(r, g, b) |
325 loadingColor = QColor(r, g, b) |
317 |
326 |
318 gradient = QLinearGradient(QPointF(0, 0), QPointF(self.width(), 0)) |
327 gradient = QLinearGradient( |
|
328 QPointF(0, 0), QPointF(self.width(), 0)) |
319 gradient.setColorAt(0, loadingColor) |
329 gradient.setColorAt(0, loadingColor) |
320 gradient.setColorAt(progress / 100 - 0.000001, loadingColor) |
330 gradient.setColorAt(progress / 100 - 0.000001, loadingColor) |
321 gradient.setColorAt(progress / 100, backgroundColor) |
331 gradient.setColorAt(progress / 100, backgroundColor) |
322 p.setBrush(QPalette.Base, gradient) |
332 p.setBrush(QPalette.Base, gradient) |
323 |
333 |
364 Protected method to handle key presses. |
374 Protected method to handle key presses. |
365 |
375 |
366 @param evt reference to the key press event (QKeyEvent) |
376 @param evt reference to the key press event (QKeyEvent) |
367 """ |
377 """ |
368 if evt.key() == Qt.Key_Escape and self.__browser is not None: |
378 if evt.key() == Qt.Key_Escape and self.__browser is not None: |
369 self.setText(str(self.__browser.url().toEncoded(), encoding="utf-8")) |
379 self.setText( |
|
380 str(self.__browser.url().toEncoded(), encoding="utf-8")) |
370 self.selectAll() |
381 self.selectAll() |
371 return |
382 return |
372 |
383 |
373 currentText = self.text().strip() |
384 currentText = self.text().strip() |
374 if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \ |
385 if evt.key() in [Qt.Key_Enter, Qt.Key_Return] and \ |
375 not currentText.lower().startswith("http://"): |
386 not currentText.lower().startswith("http://"): |
376 append = "" |
387 append = "" |
377 if evt.modifiers() == Qt.KeyboardModifiers(Qt.ControlModifier): |
388 if evt.modifiers() == Qt.KeyboardModifiers(Qt.ControlModifier): |
378 append = ".com" |
389 append = ".com" |
379 elif evt.modifiers() == \ |
390 elif evt.modifiers() == Qt.KeyboardModifiers( |
380 Qt.KeyboardModifiers(Qt.ControlModifier | Qt.ShiftModifier): |
391 Qt.ControlModifier | Qt.ShiftModifier): |
381 append = ".org" |
392 append = ".org" |
382 elif evt.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
393 elif evt.modifiers() == Qt.KeyboardModifiers(Qt.ShiftModifier): |
383 append = ".net" |
394 append = ".net" |
384 |
395 |
385 if append != "": |
396 if append != "": |