src/eric7/WebBrowser/UrlBar/UrlBar.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
9 9
10 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QDateTime, QTimer, QPoint 10 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QDateTime, QTimer, QPoint
11 from PyQt6.QtGui import QColor, QPalette, QIcon 11 from PyQt6.QtGui import QColor, QPalette, QIcon
12 from PyQt6.QtWidgets import QDialog, QApplication, QLineEdit 12 from PyQt6.QtWidgets import QDialog, QApplication, QLineEdit
13 from PyQt6.QtWebEngineCore import QWebEnginePage 13 from PyQt6.QtWebEngineCore import QWebEnginePage
14
14 try: 15 try:
15 from PyQt6.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__ 16 from PyQt6.QtNetwork import QSslCertificate # __IGNORE_EXCEPTION__
16 except ImportError: 17 except ImportError:
17 QSslCertificate = None # __IGNORE_WARNING__ 18 QSslCertificate = None # __IGNORE_WARNING__
18 19
19 from EricWidgets.EricLineEdit import EricClearableLineEdit, EricLineEditSide 20 from EricWidgets.EricLineEdit import EricClearableLineEdit, EricLineEditSide
20 21
21 from WebBrowser.WebBrowserWindow import WebBrowserWindow 22 from WebBrowser.WebBrowserWindow import WebBrowserWindow
22 23
32 33
33 class UrlBar(EricClearableLineEdit): 34 class UrlBar(EricClearableLineEdit):
34 """ 35 """
35 Class implementing a line edit for entering URLs. 36 Class implementing a line edit for entering URLs.
36 """ 37 """
38
37 def __init__(self, mainWindow, parent=None): 39 def __init__(self, mainWindow, parent=None):
38 """ 40 """
39 Constructor 41 Constructor
40 42
41 @param mainWindow reference to the main window 43 @param mainWindow reference to the main window
42 @type WebBrowserWindow 44 @type WebBrowserWindow
43 @param parent reference to the parent widget 45 @param parent reference to the parent widget
44 @type WebBrowserView 46 @type WebBrowserView
45 """ 47 """
46 super().__init__(parent) 48 super().__init__(parent)
47 self.setPlaceholderText(self.tr("Enter the URL here.")) 49 self.setPlaceholderText(self.tr("Enter the URL here."))
48 self.setWhatsThis(self.tr("Enter the URL here.")) 50 self.setWhatsThis(self.tr("Enter the URL here."))
49 51
50 self.__mw = mainWindow 52 self.__mw = mainWindow
51 self.__browser = None 53 self.__browser = None
52 self.__privateMode = WebBrowserWindow.isPrivate() 54 self.__privateMode = WebBrowserWindow.isPrivate()
53 55
54 self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16") 56 self.__bmActiveIcon = UI.PixmapCache.getIcon("bookmark16")
55 self.__bmInactiveIcon = QIcon( 57 self.__bmInactiveIcon = QIcon(
56 self.__bmActiveIcon.pixmap(16, 16, QIcon.Mode.Disabled)) 58 self.__bmActiveIcon.pixmap(16, 16, QIcon.Mode.Disabled)
57 59 )
60
58 self.__safeBrowsingLabel = SafeBrowsingLabel(self) 61 self.__safeBrowsingLabel = SafeBrowsingLabel(self)
59 self.addWidget(self.__safeBrowsingLabel, EricLineEditSide.LEFT) 62 self.addWidget(self.__safeBrowsingLabel, EricLineEditSide.LEFT)
60 self.__safeBrowsingLabel.setVisible(False) 63 self.__safeBrowsingLabel.setVisible(False)
61 64
62 self.__favicon = FavIconLabel(self) 65 self.__favicon = FavIconLabel(self)
63 self.addWidget(self.__favicon, EricLineEditSide.LEFT) 66 self.addWidget(self.__favicon, EricLineEditSide.LEFT)
64 67
65 self.__sslLabel = SslLabel(self) 68 self.__sslLabel = SslLabel(self)
66 self.addWidget(self.__sslLabel, EricLineEditSide.LEFT) 69 self.addWidget(self.__sslLabel, EricLineEditSide.LEFT)
67 self.__sslLabel.setVisible(False) 70 self.__sslLabel.setVisible(False)
68 71
69 self.__rssAction = self.addAction( 72 self.__rssAction = self.addAction(
70 UI.PixmapCache.getIcon("rss16"), 73 UI.PixmapCache.getIcon("rss16"), QLineEdit.ActionPosition.TrailingPosition
71 QLineEdit.ActionPosition.TrailingPosition) 74 )
72 self.__rssAction.setVisible(False) 75 self.__rssAction.setVisible(False)
73 76
74 self.__bookmarkAction = self.addAction( 77 self.__bookmarkAction = self.addAction(
75 self.__bmInactiveIcon, 78 self.__bmInactiveIcon, QLineEdit.ActionPosition.TrailingPosition
76 QLineEdit.ActionPosition.TrailingPosition) 79 )
77 self.__bookmarkAction.setVisible(False) 80 self.__bookmarkAction.setVisible(False)
78 81
79 self.__safeBrowsingLabel.clicked.connect(self.__showThreatInfo) 82 self.__safeBrowsingLabel.clicked.connect(self.__showThreatInfo)
80 self.__bookmarkAction.triggered.connect(self.__showBookmarkInfo) 83 self.__bookmarkAction.triggered.connect(self.__showBookmarkInfo)
81 self.__rssAction.triggered.connect(self.__rssTriggered) 84 self.__rssAction.triggered.connect(self.__rssTriggered)
82 85
83 self.__mw.bookmarksManager().entryChanged.connect( 86 self.__mw.bookmarksManager().entryChanged.connect(self.__bookmarkChanged)
84 self.__bookmarkChanged) 87 self.__mw.bookmarksManager().entryAdded.connect(self.__bookmarkChanged)
85 self.__mw.bookmarksManager().entryAdded.connect( 88 self.__mw.bookmarksManager().entryRemoved.connect(self.__bookmarkChanged)
86 self.__bookmarkChanged) 89 self.__mw.speedDial().pagesChanged.connect(self.__bookmarkChanged)
87 self.__mw.bookmarksManager().entryRemoved.connect( 90
88 self.__bookmarkChanged)
89 self.__mw.speedDial().pagesChanged.connect(
90 self.__bookmarkChanged)
91
92 def setBrowser(self, browser): 91 def setBrowser(self, browser):
93 """ 92 """
94 Public method to set the browser connection. 93 Public method to set the browser connection.
95 94
96 @param browser reference to the browser widget 95 @param browser reference to the browser widget
97 @type WebBrowserView 96 @type WebBrowserView
98 """ 97 """
99 self.__browser = browser 98 self.__browser = browser
100 self.__favicon.setBrowser(browser) 99 self.__favicon.setBrowser(browser)
101 100
102 self.__browser.urlChanged.connect(self.__browserUrlChanged) 101 self.__browser.urlChanged.connect(self.__browserUrlChanged)
103 self.__browser.loadProgress.connect(self.__loadProgress) 102 self.__browser.loadProgress.connect(self.__loadProgress)
104 self.__browser.loadFinished.connect(self.__loadFinished) 103 self.__browser.loadFinished.connect(self.__loadFinished)
105 self.__browser.loadStarted.connect(self.__loadStarted) 104 self.__browser.loadStarted.connect(self.__loadStarted)
106 105
107 self.__browser.safeBrowsingBad.connect( 106 self.__browser.safeBrowsingBad.connect(self.__safeBrowsingLabel.setThreatInfo)
108 self.__safeBrowsingLabel.setThreatInfo) 107
109
110 self.__sslLabel.clicked.connect(self.__browser.page().showSslInfo) 108 self.__sslLabel.clicked.connect(self.__browser.page().showSslInfo)
111 self.__browser.page().sslConfigurationChanged.connect( 109 self.__browser.page().sslConfigurationChanged.connect(
112 self.__sslConfigurationChanged) 110 self.__sslConfigurationChanged
113 111 )
112
114 def browser(self): 113 def browser(self):
115 """ 114 """
116 Public method to get the associated browser. 115 Public method to get the associated browser.
117 116
118 @return reference to the associated browser 117 @return reference to the associated browser
119 @rtype WebBrowserView 118 @rtype WebBrowserView
120 """ 119 """
121 return self.__browser 120 return self.__browser
122 121
123 @pyqtSlot(QUrl) 122 @pyqtSlot(QUrl)
124 def __browserUrlChanged(self, url): 123 def __browserUrlChanged(self, url):
125 """ 124 """
126 Private slot to handle a URL change of the associated browser. 125 Private slot to handle a URL change of the associated browser.
127 126
128 @param url new URL of the browser 127 @param url new URL of the browser
129 @type QUrl 128 @type QUrl
130 """ 129 """
131 strUrl = url.toString() 130 strUrl = url.toString()
132 if strUrl in ["eric:speeddial", "eric:home", 131 if strUrl in ["eric:speeddial", "eric:home", "about:blank", "about:config"]:
133 "about:blank", "about:config"]:
134 strUrl = "" 132 strUrl = ""
135 133
136 if self.text() != strUrl: 134 if self.text() != strUrl:
137 self.setText(strUrl) 135 self.setText(strUrl)
138 self.setCursorPosition(0) 136 self.setCursorPosition(0)
139 137
140 @pyqtSlot() 138 @pyqtSlot()
141 def __checkBookmark(self): 139 def __checkBookmark(self):
142 """ 140 """
143 Private slot to check the current URL for the bookmarked state. 141 Private slot to check the current URL for the bookmarked state.
144 """ 142 """
145 manager = self.__mw.bookmarksManager() 143 manager = self.__mw.bookmarksManager()
146 if manager.bookmarkForUrl(self.__browser.url()) is not None: 144 if manager.bookmarkForUrl(self.__browser.url()) is not None:
147 self.__bookmarkAction.setIcon(self.__bmActiveIcon) 145 self.__bookmarkAction.setIcon(self.__bmActiveIcon)
148 bookmarks = manager.bookmarksForUrl(self.__browser.url()) 146 bookmarks = manager.bookmarksForUrl(self.__browser.url())
149 from WebBrowser.Bookmarks.BookmarkNode import BookmarkNode 147 from WebBrowser.Bookmarks.BookmarkNode import BookmarkNode
148
150 for bookmark in bookmarks: 149 for bookmark in bookmarks:
151 manager.setTimestamp(bookmark, BookmarkNode.TsVisited, 150 manager.setTimestamp(
152 QDateTime.currentDateTime()) 151 bookmark, BookmarkNode.TsVisited, QDateTime.currentDateTime()
152 )
153 elif self.__mw.speedDial().pageForUrl(self.__browser.url()).url != "": 153 elif self.__mw.speedDial().pageForUrl(self.__browser.url()).url != "":
154 self.__bookmarkAction.setIcon(self.__bmActiveIcon) 154 self.__bookmarkAction.setIcon(self.__bmActiveIcon)
155 else: 155 else:
156 self.__bookmarkAction.setIcon(self.__bmInactiveIcon) 156 self.__bookmarkAction.setIcon(self.__bmInactiveIcon)
157 157
158 @pyqtSlot() 158 @pyqtSlot()
159 def __loadStarted(self): 159 def __loadStarted(self):
160 """ 160 """
161 Private slot to perform actions before the page is loaded. 161 Private slot to perform actions before the page is loaded.
162 """ 162 """
163 self.__bookmarkAction.setVisible(False) 163 self.__bookmarkAction.setVisible(False)
164 self.__rssAction.setVisible(False) 164 self.__rssAction.setVisible(False)
165 self.__sslLabel.setVisible(False) 165 self.__sslLabel.setVisible(False)
166 166
167 @pyqtSlot(int) 167 @pyqtSlot(int)
168 def __loadProgress(self, progress): 168 def __loadProgress(self, progress):
169 """ 169 """
170 Private slot to track the load progress. 170 Private slot to track the load progress.
171 171
172 @param progress load progress in percent 172 @param progress load progress in percent
173 @type int 173 @type int
174 """ 174 """
175 foregroundColor = QApplication.palette().color(QPalette.ColorRole.Text) 175 foregroundColor = QApplication.palette().color(QPalette.ColorRole.Text)
176 176
177 backgroundColor = ( 177 backgroundColor = (
178 Preferences.getWebBrowser("PrivateModeUrlColor") 178 Preferences.getWebBrowser("PrivateModeUrlColor")
179 if self.__privateMode else 179 if self.__privateMode
180 QApplication.palette().color(QPalette.ColorRole.Base) 180 else QApplication.palette().color(QPalette.ColorRole.Base)
181 ) 181 )
182 182
183 if not self.__browser.getSafeBrowsingStatus(): 183 if not self.__browser.getSafeBrowsingStatus():
184 # malicious web site 184 # malicious web site
185 backgroundColor = Preferences.getWebBrowser( 185 backgroundColor = Preferences.getWebBrowser("MaliciousUrlColor")
186 "MaliciousUrlColor")
187 elif self.__browser.url().scheme() == "https": 186 elif self.__browser.url().scheme() == "https":
188 if WebBrowserWindow.networkManager().isInsecureHost( 187 if WebBrowserWindow.networkManager().isInsecureHost(
189 self.__browser.url().host() 188 self.__browser.url().host()
190 ): 189 ):
191 backgroundColor = Preferences.getWebBrowser( 190 backgroundColor = Preferences.getWebBrowser("InsecureUrlColor")
192 "InsecureUrlColor")
193 else: 191 else:
194 backgroundColor = Preferences.getWebBrowser( 192 backgroundColor = Preferences.getWebBrowser("SecureUrlColor")
195 "SecureUrlColor") 193
196
197 if progress in (0, 100): 194 if progress in (0, 100):
198 styleSheet = ( 195 styleSheet = (
199 f"color: {foregroundColor.name()}; " 196 f"color: {foregroundColor.name()}; "
200 f"background-color: {backgroundColor.name()};" 197 f"background-color: {backgroundColor.name()};"
201 ) 198 )
202 else: 199 else:
203 highlight = QApplication.palette().color( 200 highlight = QApplication.palette().color(QPalette.ColorRole.Highlight)
204 QPalette.ColorRole.Highlight)
205 r = (highlight.red() + 2 * backgroundColor.red()) // 3 201 r = (highlight.red() + 2 * backgroundColor.red()) // 3
206 g = (highlight.green() + 2 * backgroundColor.green()) // 3 202 g = (highlight.green() + 2 * backgroundColor.green()) // 3
207 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3 203 b = (highlight.blue() + 2 * backgroundColor.blue()) // 3
208 204
209 loadingColor = QColor(r, g, b) 205 loadingColor = QColor(r, g, b)
210 if abs(loadingColor.lightness() - 206 if abs(loadingColor.lightness() - backgroundColor.lightness()) < 20:
211 backgroundColor.lightness()) < 20:
212 r = (2 * highlight.red() + backgroundColor.red()) // 3 207 r = (2 * highlight.red() + backgroundColor.red()) // 3
213 g = (2 * highlight.green() + backgroundColor.green()) // 3 208 g = (2 * highlight.green() + backgroundColor.green()) // 3
214 b = (2 * highlight.blue() + backgroundColor.blue()) // 3 209 b = (2 * highlight.blue() + backgroundColor.blue()) // 3
215 loadingColor = QColor(r, g, b) 210 loadingColor = QColor(r, g, b)
216 211
217 styleSheet = ( 212 styleSheet = (
218 f"color: {foregroundColor.name()}; " 213 f"color: {foregroundColor.name()}; "
219 f"background-color: qlineargradient(" 214 f"background-color: qlineargradient("
220 f"spread: pad, x1: 0, y1: 0, x2: 1, y2: 0, " 215 f"spread: pad, x1: 0, y1: 0, x2: 1, y2: 0, "
221 f"stop: 0 {loadingColor.name()}, " 216 f"stop: 0 {loadingColor.name()}, "
222 f"stop: {progress / 100.0 - 0.001} {loadingColor.name()}, " 217 f"stop: {progress / 100.0 - 0.001} {loadingColor.name()}, "
223 f"stop: {progress / 100.0 + 0.001} {backgroundColor.name()}, " 218 f"stop: {progress / 100.0 + 0.001} {backgroundColor.name()}, "
224 f"stop: 1 {backgroundColor.name()});" 219 f"stop: 1 {backgroundColor.name()});"
225 ) 220 )
226 221
227 self.setStyleSheet(styleSheet) 222 self.setStyleSheet(styleSheet)
228 self.repaint() 223 self.repaint()
229 224
230 @pyqtSlot(bool) 225 @pyqtSlot(bool)
231 def __loadFinished(self, ok): 226 def __loadFinished(self, ok):
232 """ 227 """
233 Private slot to set some data after the page was loaded. 228 Private slot to set some data after the page was loaded.
234 229
235 @param ok flag indicating a successful load 230 @param ok flag indicating a successful load
236 @type bool 231 @type bool
237 """ 232 """
238 if self.__browser.url().scheme() in ["eric", "about"]: 233 if self.__browser.url().scheme() in ["eric", "about"]:
239 self.__bookmarkAction.setVisible(False) 234 self.__bookmarkAction.setVisible(False)
240 else: 235 else:
241 self.__checkBookmark() 236 self.__checkBookmark()
242 self.__bookmarkAction.setVisible(True) 237 self.__bookmarkAction.setVisible(True)
243 238
244 self.__browserUrlChanged(self.__browser.url()) 239 self.__browserUrlChanged(self.__browser.url())
245 self.__safeBrowsingLabel.setVisible( 240 self.__safeBrowsingLabel.setVisible(not self.__browser.getSafeBrowsingStatus())
246 not self.__browser.getSafeBrowsingStatus()) 241
247
248 if ok: 242 if ok:
249 QTimer.singleShot(0, self.__setRssButton) 243 QTimer.singleShot(0, self.__setRssButton)
250 244
251 @pyqtSlot() 245 @pyqtSlot()
252 def preferencesChanged(self): 246 def preferencesChanged(self):
253 """ 247 """
254 Public slot to handle a change of preferences. 248 Public slot to handle a change of preferences.
255 """ 249 """
256 self.update() 250 self.update()
257 251
258 @pyqtSlot() 252 @pyqtSlot()
259 def __showBookmarkInfo(self): 253 def __showBookmarkInfo(self):
260 """ 254 """
261 Private slot to show a dialog with some bookmark info. 255 Private slot to show a dialog with some bookmark info.
262 """ 256 """
263 from .BookmarkActionSelectionDialog import ( 257 from .BookmarkActionSelectionDialog import BookmarkActionSelectionDialog
264 BookmarkActionSelectionDialog 258
265 )
266 url = self.__browser.url() 259 url = self.__browser.url()
267 dlg = BookmarkActionSelectionDialog(url) 260 dlg = BookmarkActionSelectionDialog(url)
268 if dlg.exec() == QDialog.DialogCode.Accepted: 261 if dlg.exec() == QDialog.DialogCode.Accepted:
269 action = dlg.getAction() 262 action = dlg.getAction()
270 if action == BookmarkActionSelectionDialog.AddBookmark: 263 if action == BookmarkActionSelectionDialog.AddBookmark:
271 self.__browser.addBookmark() 264 self.__browser.addBookmark()
272 elif action == BookmarkActionSelectionDialog.EditBookmark: 265 elif action == BookmarkActionSelectionDialog.EditBookmark:
273 bookmark = ( 266 bookmark = self.__mw.bookmarksManager().bookmarkForUrl(url)
274 self.__mw.bookmarksManager().bookmarkForUrl(url)
275 )
276 from .BookmarkInfoDialog import BookmarkInfoDialog 267 from .BookmarkInfoDialog import BookmarkInfoDialog
268
277 dlg = BookmarkInfoDialog(bookmark, self.__browser) 269 dlg = BookmarkInfoDialog(bookmark, self.__browser)
278 dlg.exec() 270 dlg.exec()
279 elif action == BookmarkActionSelectionDialog.AddSpeeddial: 271 elif action == BookmarkActionSelectionDialog.AddSpeeddial:
280 self.__mw.speedDial().addPage( 272 self.__mw.speedDial().addPage(url, self.__browser.title())
281 url, self.__browser.title())
282 elif action == BookmarkActionSelectionDialog.RemoveSpeeddial: 273 elif action == BookmarkActionSelectionDialog.RemoveSpeeddial:
283 self.__mw.speedDial().removePage(url) 274 self.__mw.speedDial().removePage(url)
284 275
285 @pyqtSlot() 276 @pyqtSlot()
286 def __bookmarkChanged(self): 277 def __bookmarkChanged(self):
287 """ 278 """
288 Private slot to handle bookmark or speed dial changes. 279 Private slot to handle bookmark or speed dial changes.
289 """ 280 """
290 self.__checkBookmark() 281 self.__checkBookmark()
291 282
292 def focusOutEvent(self, evt): 283 def focusOutEvent(self, evt):
293 """ 284 """
294 Protected method to handle focus out event. 285 Protected method to handle focus out event.
295 286
296 @param evt reference to the focus event 287 @param evt reference to the focus event
297 @type QFocusEvent 288 @type QFocusEvent
298 """ 289 """
299 if self.text() == "" and self.__browser is not None: 290 if self.text() == "" and self.__browser is not None:
300 self.__browserUrlChanged(self.__browser.url()) 291 self.__browserUrlChanged(self.__browser.url())
301 super().focusOutEvent(evt) 292 super().focusOutEvent(evt)
302 293
303 def mousePressEvent(self, evt): 294 def mousePressEvent(self, evt):
304 """ 295 """
305 Protected method called by a mouse press event. 296 Protected method called by a mouse press event.
306 297
307 @param evt reference to the mouse event 298 @param evt reference to the mouse event
308 @type QMouseEvent 299 @type QMouseEvent
309 """ 300 """
310 if evt.button() == Qt.MouseButton.XButton1: 301 if evt.button() == Qt.MouseButton.XButton1:
311 self.__mw.currentBrowser().triggerPageAction( 302 self.__mw.currentBrowser().triggerPageAction(QWebEnginePage.WebAction.Back)
312 QWebEnginePage.WebAction.Back)
313 elif evt.button() == Qt.MouseButton.XButton2: 303 elif evt.button() == Qt.MouseButton.XButton2:
314 self.__mw.currentBrowser().triggerPageAction( 304 self.__mw.currentBrowser().triggerPageAction(
315 QWebEnginePage.WebAction.Forward) 305 QWebEnginePage.WebAction.Forward
306 )
316 else: 307 else:
317 super().mousePressEvent(evt) 308 super().mousePressEvent(evt)
318 309
319 def mouseDoubleClickEvent(self, evt): 310 def mouseDoubleClickEvent(self, evt):
320 """ 311 """
321 Protected method to handle mouse double click events. 312 Protected method to handle mouse double click events.
322 313
323 @param evt reference to the mouse event 314 @param evt reference to the mouse event
324 @type QMouseEvent 315 @type QMouseEvent
325 """ 316 """
326 if evt.button() == Qt.MouseButton.LeftButton: 317 if evt.button() == Qt.MouseButton.LeftButton:
327 self.selectAll() 318 self.selectAll()
328 else: 319 else:
329 super().mouseDoubleClickEvent(evt) 320 super().mouseDoubleClickEvent(evt)
330 321
331 def keyPressEvent(self, evt): 322 def keyPressEvent(self, evt):
332 """ 323 """
333 Protected method to handle key presses. 324 Protected method to handle key presses.
334 325
335 @param evt reference to the key press event 326 @param evt reference to the key press event
336 @type QKeyEvent 327 @type QKeyEvent
337 """ 328 """
338 if evt.key() == Qt.Key.Key_Escape: 329 if evt.key() == Qt.Key.Key_Escape:
339 if self.__browser is not None: 330 if self.__browser is not None:
340 self.setText( 331 self.setText(str(self.__browser.url().toEncoded(), encoding="utf-8"))
341 str(self.__browser.url().toEncoded(), encoding="utf-8"))
342 self.selectAll() 332 self.selectAll()
343 completer = self.completer() 333 completer = self.completer()
344 if completer: 334 if completer:
345 completer.popup().hide() 335 completer.popup().hide()
346 return 336 return
347 337
348 currentText = self.text().strip() 338 currentText = self.text().strip()
349 if ( 339 if evt.key() in [
350 evt.key() in [Qt.Key.Key_Enter, Qt.Key.Key_Return] and 340 Qt.Key.Key_Enter,
351 not currentText.lower().startswith(("http://", "https://")) 341 Qt.Key.Key_Return,
352 ): 342 ] and not currentText.lower().startswith(("http://", "https://")):
353 append = "" 343 append = ""
354 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier: 344 if evt.modifiers() == Qt.KeyboardModifier.ControlModifier:
355 append = ".com" 345 append = ".com"
356 elif ( 346 elif evt.modifiers() == (
357 evt.modifiers() == ( 347 Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.ShiftModifier
358 Qt.KeyboardModifier.ControlModifier |
359 Qt.KeyboardModifier.ShiftModifier
360 )
361 ): 348 ):
362 append = ".org" 349 append = ".org"
363 elif evt.modifiers() == Qt.KeyboardModifier.ShiftModifier: 350 elif evt.modifiers() == Qt.KeyboardModifier.ShiftModifier:
364 append = ".net" 351 append = ".net"
365 352
366 if append != "": 353 if append != "":
367 url = QUrl("http://www." + currentText) 354 url = QUrl("http://www." + currentText)
368 host = url.host() 355 host = url.host()
369 if not host.lower().endswith(append): 356 if not host.lower().endswith(append):
370 host += append 357 host += append
371 url.setHost(host) 358 url.setHost(host)
372 self.setText(url.toString()) 359 self.setText(url.toString())
373 360
374 super().keyPressEvent(evt) 361 super().keyPressEvent(evt)
375 362
376 def dragEnterEvent(self, evt): 363 def dragEnterEvent(self, evt):
377 """ 364 """
378 Protected method to handle drag enter events. 365 Protected method to handle drag enter events.
379 366
380 @param evt reference to the drag enter event 367 @param evt reference to the drag enter event
381 @type QDragEnterEvent 368 @type QDragEnterEvent
382 """ 369 """
383 mimeData = evt.mimeData() 370 mimeData = evt.mimeData()
384 if mimeData.hasUrls() or mimeData.hasText(): 371 if mimeData.hasUrls() or mimeData.hasText():
385 evt.acceptProposedAction() 372 evt.acceptProposedAction()
386 373
387 super().dragEnterEvent(evt) 374 super().dragEnterEvent(evt)
388 375
389 def dropEvent(self, evt): 376 def dropEvent(self, evt):
390 """ 377 """
391 Protected method to handle drop events. 378 Protected method to handle drop events.
392 379
393 @param evt reference to the drop event 380 @param evt reference to the drop event
394 @type QDropEvent 381 @type QDropEvent
395 """ 382 """
396 mimeData = evt.mimeData() 383 mimeData = evt.mimeData()
397 384
398 url = QUrl() 385 url = QUrl()
399 if mimeData.hasUrls(): 386 if mimeData.hasUrls():
400 url = mimeData.urls()[0] 387 url = mimeData.urls()[0]
401 elif mimeData.hasText(): 388 elif mimeData.hasText():
402 url = QUrl.fromEncoded(mimeData.text().encode("utf-8"), 389 url = QUrl.fromEncoded(
403 QUrl.ParsingMode.TolerantMode) 390 mimeData.text().encode("utf-8"), QUrl.ParsingMode.TolerantMode
404 391 )
392
405 if url.isEmpty() or not url.isValid(): 393 if url.isEmpty() or not url.isValid():
406 super().dropEvent(evt) 394 super().dropEvent(evt)
407 return 395 return
408 396
409 self.setText(str(url.toEncoded(), encoding="utf-8")) 397 self.setText(str(url.toEncoded(), encoding="utf-8"))
410 self.selectAll() 398 self.selectAll()
411 399
412 evt.acceptProposedAction() 400 evt.acceptProposedAction()
413 401
414 @pyqtSlot() 402 @pyqtSlot()
415 def __setRssButton(self): 403 def __setRssButton(self):
416 """ 404 """
417 Private slot to show the RSS button. 405 Private slot to show the RSS button.
418 """ 406 """
419 self.__rssAction.setVisible(self.__browser.checkRSS()) 407 self.__rssAction.setVisible(self.__browser.checkRSS())
420 408
421 @pyqtSlot() 409 @pyqtSlot()
422 def __rssTriggered(self): 410 def __rssTriggered(self):
423 """ 411 """
424 Private slot to handle clicking the RSS icon. 412 Private slot to handle clicking the RSS icon.
425 """ 413 """
426 from WebBrowser.Feeds.FeedsDialog import FeedsDialog 414 from WebBrowser.Feeds.FeedsDialog import FeedsDialog
415
427 feeds = self.__browser.getRSS() 416 feeds = self.__browser.getRSS()
428 dlg = FeedsDialog(feeds, self.__browser) 417 dlg = FeedsDialog(feeds, self.__browser)
429 dlg.exec() 418 dlg.exec()
430 419
431 @pyqtSlot(QPoint) 420 @pyqtSlot(QPoint)
432 def __showThreatInfo(self, pos): 421 def __showThreatInfo(self, pos):
433 """ 422 """
434 Private slot to show the threat info widget. 423 Private slot to show the threat info widget.
435 424
436 @param pos position to show the info at 425 @param pos position to show the info at
437 @type QPoint 426 @type QPoint
438 """ 427 """
439 threatInfo = self.__safeBrowsingLabel.getThreatInfo() 428 threatInfo = self.__safeBrowsingLabel.getThreatInfo()
440 if threatInfo: 429 if threatInfo:
441 from WebBrowser.SafeBrowsing.SafeBrowsingInfoWidget import ( 430 from WebBrowser.SafeBrowsing.SafeBrowsingInfoWidget import (
442 SafeBrowsingInfoWidget 431 SafeBrowsingInfoWidget,
443 ) 432 )
433
444 widget = SafeBrowsingInfoWidget(threatInfo, self.__browser) 434 widget = SafeBrowsingInfoWidget(threatInfo, self.__browser)
445 widget.showAt(pos) 435 widget.showAt(pos)
446 436
447 @pyqtSlot() 437 @pyqtSlot()
448 def __sslConfigurationChanged(self): 438 def __sslConfigurationChanged(self):
449 """ 439 """
450 Private slot to handle a change of the associated web page SSL 440 Private slot to handle a change of the associated web page SSL
451 configuration. 441 configuration.
452 """ 442 """
453 sslConfiguration = self.__browser.page().getSslConfiguration() 443 sslConfiguration = self.__browser.page().getSslConfiguration()
454 if sslConfiguration is not None and QSslCertificate is not None: 444 if sslConfiguration is not None and QSslCertificate is not None:
455 sslCertificate = self.__browser.page().getSslCertificate() 445 sslCertificate = self.__browser.page().getSslCertificate()
456 if sslCertificate is not None: 446 if sslCertificate is not None:
457 org = Utilities.decodeString(", ".join( 447 org = Utilities.decodeString(
458 sslCertificate.subjectInfo( 448 ", ".join(
459 QSslCertificate.SubjectInfo.Organization))) 449 sslCertificate.subjectInfo(
450 QSslCertificate.SubjectInfo.Organization
451 )
452 )
453 )
460 if org == "": 454 if org == "":
461 cn = Utilities.decodeString(", ".join( 455 cn = Utilities.decodeString(
462 sslCertificate.subjectInfo( 456 ", ".join(
463 QSslCertificate.SubjectInfo.CommonName))) 457 sslCertificate.subjectInfo(
458 QSslCertificate.SubjectInfo.CommonName
459 )
460 )
461 )
464 if cn != "": 462 if cn != "":
465 org = cn.split(".", 1)[1] 463 org = cn.split(".", 1)[1]
466 if org == "": 464 if org == "":
467 org = self.tr("Unknown") 465 org = self.tr("Unknown")
468 self.__sslLabel.setText(" {0} ".format(org)) 466 self.__sslLabel.setText(" {0} ".format(org))

eric ide

mercurial