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