19 |
19 |
20 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \ |
20 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \ |
21 QUrl, QTextCodec, QProcess, QEvent, qVersion |
21 QUrl, QTextCodec, QProcess, QEvent, qVersion |
22 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics |
22 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics |
23 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \ |
23 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \ |
24 QComboBox, QLabel, QSplitter, QMenu, QToolButton, QLineEdit, \ |
24 QComboBox, QLabel, QMenu, QToolButton, QLineEdit, QApplication, \ |
25 QApplication, QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QAction, \ |
25 QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QInputDialog |
26 QInputDialog |
|
27 from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEnginePage, \ |
26 from PyQt5.QtWebEngineWidgets import QWebEngineSettings, QWebEnginePage, \ |
28 QWebEngineProfile, QWebEngineScript |
27 QWebEngineProfile, QWebEngineScript |
29 try: |
28 try: |
30 from PyQt5.QtHelp import QHelpEngine, QHelpEngineCore, QHelpSearchQuery |
29 from PyQt5.QtHelp import QHelpEngine, QHelpEngineCore, QHelpSearchQuery |
31 QTHELP_AVAILABLE = True |
30 QTHELP_AVAILABLE = True |
178 from .WebBrowserTabWidget import WebBrowserTabWidget |
177 from .WebBrowserTabWidget import WebBrowserTabWidget |
179 from .AdBlock.AdBlockIcon import AdBlockIcon |
178 from .AdBlock.AdBlockIcon import AdBlockIcon |
180 from .StatusBar.JavaScriptIcon import JavaScriptIcon |
179 from .StatusBar.JavaScriptIcon import JavaScriptIcon |
181 from .StatusBar.ImagesIcon import ImagesIcon |
180 from .StatusBar.ImagesIcon import ImagesIcon |
182 from .VirusTotal.VirusTotalApi import VirusTotalAPI |
181 from .VirusTotal.VirusTotalApi import VirusTotalAPI |
|
182 from .Navigation.NavigationBar import NavigationBar |
|
183 from .Navigation.NavigationContainer import NavigationContainer |
|
184 from .Bookmarks.BookmarksToolBar import BookmarksToolBar |
183 |
185 |
184 if not self.__fromEric: |
186 if not self.__fromEric: |
185 self.setStyle(Preferences.getUI("Style"), |
187 self.setStyle(Preferences.getUI("Style"), |
186 Preferences.getUI("StyleSheet")) |
188 Preferences.getUI("StyleSheet")) |
187 |
189 |
216 self.__zoomWidget.setValue) |
218 self.__zoomWidget.setValue) |
217 self.__tabWidget.browserClosed.connect(self.webBrowserClosed) |
219 self.__tabWidget.browserClosed.connect(self.webBrowserClosed) |
218 self.__tabWidget.browserOpened.connect(self.webBrowserOpened) |
220 self.__tabWidget.browserOpened.connect(self.webBrowserOpened) |
219 |
221 |
220 self.__searchWidget = SearchWidget(self, self) |
222 self.__searchWidget = SearchWidget(self, self) |
|
223 |
|
224 self.__setIconDatabasePath() |
|
225 |
|
226 bookmarksModel = self.bookmarksManager().bookmarksModel() |
|
227 self.__bookmarksToolBar = BookmarksToolBar(self, bookmarksModel, |
|
228 self) |
|
229 self.__bookmarksToolBar.setIconSize(UI.Config.ToolBarIconSize) |
|
230 self.__bookmarksToolBar.openUrl.connect(self.openUrl) |
|
231 self.__bookmarksToolBar.newTab.connect(self.openUrlNewTab) |
|
232 self.__bookmarksToolBar.newWindow.connect(self.openUrlNewWindow) |
|
233 |
|
234 self.__navigationBar = NavigationBar(self) |
|
235 |
|
236 self.__navigationContainer = NavigationContainer(self) |
|
237 self.__navigationContainer.addWidget(self.__navigationBar) |
|
238 self.__navigationContainer.addWidget(self.__bookmarksToolBar) |
|
239 |
221 centralWidget = QWidget() |
240 centralWidget = QWidget() |
222 layout = QVBoxLayout() |
241 layout = QVBoxLayout() |
223 layout.setContentsMargins(1, 1, 1, 1) |
242 layout.setContentsMargins(1, 1, 1, 1) |
|
243 layout.setSpacing(0) |
|
244 layout.addWidget(self.__navigationContainer) |
224 layout.addWidget(self.__tabWidget) |
245 layout.addWidget(self.__tabWidget) |
225 layout.addWidget(self.__searchWidget) |
246 layout.addWidget(self.__searchWidget) |
226 self.__tabWidget.setSizePolicy( |
247 self.__tabWidget.setSizePolicy( |
227 QSizePolicy.Preferred, QSizePolicy.Expanding) |
248 QSizePolicy.Preferred, QSizePolicy.Expanding) |
228 centralWidget.setLayout(layout) |
249 centralWidget.setLayout(layout) |
872 UI.PixmapCache.getIcon("home.png"), |
892 UI.PixmapCache.getIcon("home.png"), |
873 self.tr('&Home'), |
893 self.tr('&Home'), |
874 QKeySequence(self.tr("Ctrl+Home", "Go|Home")), |
894 QKeySequence(self.tr("Ctrl+Home", "Go|Home")), |
875 0, self, 'webbrowser_go_home') |
895 0, self, 'webbrowser_go_home') |
876 self.homeAct.setStatusTip(self.tr( |
896 self.homeAct.setStatusTip(self.tr( |
877 'Move to the initial help screen')) |
897 'Move to the initial screen')) |
878 self.homeAct.setWhatsThis(self.tr( |
898 self.homeAct.setWhatsThis(self.tr( |
879 """<b>Home</b>""" |
899 """<b>Home</b>""" |
880 """<p>Moves to the initial screen.</p>""" |
900 """<p>Moves to the initial screen.</p>""" |
881 )) |
901 )) |
882 if not self.__initShortcutsOnly: |
902 if not self.__initShortcutsOnly: |
1249 self.fullScreenAct = E5Action( |
1269 self.fullScreenAct = E5Action( |
1250 self.tr('Full Screen'), |
1270 self.tr('Full Screen'), |
1251 UI.PixmapCache.getIcon("windowFullscreen.png"), |
1271 UI.PixmapCache.getIcon("windowFullscreen.png"), |
1252 self.tr('&Full Screen'), |
1272 self.tr('&Full Screen'), |
1253 QKeySequence(self.tr('F11')), 0, |
1273 QKeySequence(self.tr('F11')), 0, |
1254 self, 'webbrowser_view_full_scree') |
1274 self, 'webbrowser_view_full_screen') |
1255 if not self.__initShortcutsOnly: |
1275 if not self.__initShortcutsOnly: |
1256 self.fullScreenAct.triggered.connect(self.__viewFullScreen) |
1276 self.fullScreenAct.triggered.connect(self.toggleFullScreen) |
1257 self.__actions.append(self.fullScreenAct) |
1277 self.__actions.append(self.fullScreenAct) |
1258 self.addAction(self.fullScreenAct) |
1278 self.addAction(self.fullScreenAct) |
1259 |
1279 |
1260 self.nextTabAct = E5Action( |
1280 self.nextTabAct = E5Action( |
1261 self.tr('Show next tab'), |
1281 self.tr('Show next tab'), |
2068 helptb.setIconSize(UI.Config.ToolBarIconSize) |
2088 helptb.setIconSize(UI.Config.ToolBarIconSize) |
2069 helptb.addAction(self.whatsThisAct) |
2089 helptb.addAction(self.whatsThisAct) |
2070 self.__toolbars.append(helptb) |
2090 self.__toolbars.append(helptb) |
2071 |
2091 |
2072 self.addToolBarBreak() |
2092 self.addToolBarBreak() |
2073 |
|
2074 gotb = self.addToolBar(self.tr("Go")) |
|
2075 gotb.setObjectName("GoToolBar") |
|
2076 gotb.setIconSize(UI.Config.ToolBarIconSize) |
|
2077 gotb.addAction(self.backAct) |
|
2078 gotb.addAction(self.forwardAct) |
|
2079 gotb.addAction(self.reloadAct) |
|
2080 gotb.addAction(self.stopAct) |
|
2081 gotb.addAction(self.homeAct) |
|
2082 gotb.addSeparator() |
|
2083 |
|
2084 self.__navigationSplitter = QSplitter(gotb) |
|
2085 self.__navigationSplitter.addWidget(self.__tabWidget.stackedUrlBar()) |
|
2086 |
|
2087 from .WebBrowserWebSearchWidget import WebBrowserWebSearchWidget |
|
2088 self.searchEdit = WebBrowserWebSearchWidget(self) |
|
2089 sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) |
|
2090 sizePolicy.setHorizontalStretch(2) |
|
2091 sizePolicy.setVerticalStretch(0) |
|
2092 self.searchEdit.setSizePolicy(sizePolicy) |
|
2093 self.searchEdit.search.connect(self.__linkActivated) |
|
2094 self.__navigationSplitter.addWidget(self.searchEdit) |
|
2095 gotb.addWidget(self.__navigationSplitter) |
|
2096 |
|
2097 self.__navigationSplitter.setSizePolicy( |
|
2098 QSizePolicy.Expanding, QSizePolicy.Maximum) |
|
2099 self.__navigationSplitter.setCollapsible(0, False) |
|
2100 |
|
2101 self.backMenu = QMenu(self) |
|
2102 self.backMenu.aboutToShow.connect(self.__showBackMenu) |
|
2103 self.backMenu.triggered.connect(self.__navigationMenuActionTriggered) |
|
2104 backButton = gotb.widgetForAction(self.backAct) |
|
2105 backButton.setMenu(self.backMenu) |
|
2106 backButton.setPopupMode(QToolButton.MenuButtonPopup) |
|
2107 |
|
2108 self.forwardMenu = QMenu(self) |
|
2109 self.forwardMenu.aboutToShow.connect(self.__showForwardMenu) |
|
2110 self.forwardMenu.triggered.connect( |
|
2111 self.__navigationMenuActionTriggered) |
|
2112 forwardButton = gotb.widgetForAction(self.forwardAct) |
|
2113 forwardButton.setMenu(self.forwardMenu) |
|
2114 forwardButton.setPopupMode(QToolButton.MenuButtonPopup) |
|
2115 |
|
2116 self.__toolbars.append(gotb) |
|
2117 self.__gotb = gotb |
|
2118 |
|
2119 from .Bookmarks.BookmarksToolBar import BookmarksToolBar |
|
2120 bookmarksModel = self.bookmarksManager().bookmarksModel() |
|
2121 self.bookmarksToolBar = BookmarksToolBar(self, bookmarksModel, self) |
|
2122 self.bookmarksToolBar.setObjectName("BookmarksToolBar") |
|
2123 self.bookmarksToolBar.setIconSize(UI.Config.ToolBarIconSize) |
|
2124 self.bookmarksToolBar.openUrl.connect(self.openUrl) |
|
2125 self.bookmarksToolBar.newTab.connect(self.openUrlNewTab) |
|
2126 self.bookmarksToolBar.newWindow.connect(self.openUrlNewWindow) |
|
2127 self.addToolBarBreak() |
|
2128 self.addToolBar(self.bookmarksToolBar) |
|
2129 self.__toolbars.append(self.bookmarksToolBar) |
|
2130 |
|
2131 self.addToolBarBreak() |
|
2132 vttb = self.addToolBar(self.tr("VirusTotal")) |
2093 vttb = self.addToolBar(self.tr("VirusTotal")) |
2133 vttb.setObjectName("VirusTotalToolBar") |
2094 vttb.setObjectName("VirusTotalToolBar") |
2134 vttb.setIconSize(UI.Config.ToolBarIconSize) |
2095 vttb.setIconSize(UI.Config.ToolBarIconSize) |
2135 vttb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) |
2096 vttb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) |
2136 self.virustotalScanCurrentAct = vttb.addAction( |
2097 self.virustotalScanCurrentAct = vttb.addAction( |
2375 Public slot called when backward references are available. |
2336 Public slot called when backward references are available. |
2376 |
2337 |
2377 @param b flag indicating availability of the backwards action (boolean) |
2338 @param b flag indicating availability of the backwards action (boolean) |
2378 """ |
2339 """ |
2379 self.backAct.setEnabled(b) |
2340 self.backAct.setEnabled(b) |
|
2341 self.__navigationBar.backButton().setEnabled(b) |
2380 |
2342 |
2381 def setForwardAvailable(self, b): |
2343 def setForwardAvailable(self, b): |
2382 """ |
2344 """ |
2383 Public slot called when forward references are available. |
2345 Public slot called when forward references are available. |
2384 |
2346 |
2385 @param b flag indicating the availability of the forwards action |
2347 @param b flag indicating the availability of the forwards action |
2386 (boolean) |
2348 (boolean) |
2387 """ |
2349 """ |
2388 self.forwardAct.setEnabled(b) |
2350 self.forwardAct.setEnabled(b) |
|
2351 self.__navigationBar.forwardButton().setEnabled(b) |
2389 |
2352 |
2390 def setLoadingActions(self, b): |
2353 def setLoadingActions(self, b): |
2391 """ |
2354 """ |
2392 Public slot to set the loading dependent actions. |
2355 Public slot to set the loading dependent actions. |
2393 |
2356 |
2394 @param b flag indicating the loading state to consider (boolean) |
2357 @param b flag indicating the loading state to consider (boolean) |
2395 """ |
2358 """ |
2396 self.reloadAct.setEnabled(not b) |
2359 self.reloadAct.setEnabled(not b) |
2397 self.stopAct.setEnabled(b) |
2360 self.stopAct.setEnabled(b) |
|
2361 |
|
2362 self.__navigationBar.reloadButton().setEnabled(not b) |
|
2363 self.__navigationBar.stopButton().setEnabled(b) |
2398 |
2364 |
2399 def __addBookmark(self): |
2365 def __addBookmark(self): |
2400 """ |
2366 """ |
2401 Private slot called to add the displayed file to the bookmarks. |
2367 Private slot called to add the displayed file to the bookmarks. |
2402 """ |
2368 """ |
2603 self.__searchEngine.cancelSearching() |
2569 self.__searchEngine.cancelSearching() |
2604 |
2570 |
2605 if self.__helpInstaller: |
2571 if self.__helpInstaller: |
2606 self.__helpInstaller.stop() |
2572 self.__helpInstaller.stop() |
2607 |
2573 |
2608 self.searchEdit.saveSearches() |
2574 self.__navigationBar.searchEdit().saveSearches() |
2609 |
2575 |
2610 self.__tabWidget.closeAllBrowsers(shutdown=True) |
2576 self.__tabWidget.closeAllBrowsers(shutdown=True) |
2611 |
2577 |
2612 state = self.saveState() |
2578 state = self.saveState() |
2613 Preferences.setWebBrowser("WebBrowserState", state) |
2579 Preferences.setWebBrowser("WebBrowserState", state) |
2691 Private slot called to handle the zoom reset action. |
2657 Private slot called to handle the zoom reset action. |
2692 """ |
2658 """ |
2693 self.currentBrowser().zoomReset() |
2659 self.currentBrowser().zoomReset() |
2694 self.__zoomWidget.setValue(self.currentBrowser().zoomValue()) |
2660 self.__zoomWidget.setValue(self.currentBrowser().zoomValue()) |
2695 |
2661 |
2696 def __viewFullScreen(self): |
2662 def toggleFullScreen(self): |
2697 """ |
2663 """ |
2698 Private slot called to toggle fullscreen mode. |
2664 Public slot called to toggle the full screen mode. |
2699 """ |
2665 """ |
2700 if self.__htmlFullScreen: |
2666 if self.__htmlFullScreen: |
2701 self.currentBrowser().triggerPageAction( |
2667 self.currentBrowser().triggerPageAction( |
2702 QWebEnginePage.ExitFullScreen) |
2668 QWebEnginePage.ExitFullScreen) |
2703 return |
2669 return |
2718 self.__htmlFullScreen = True |
2684 self.__htmlFullScreen = True |
2719 |
2685 |
2720 def isFullScreenNavigationVisible(self): |
2686 def isFullScreenNavigationVisible(self): |
2721 """ |
2687 """ |
2722 Public method to check, if full screen navigation is active. |
2688 Public method to check, if full screen navigation is active. |
2723 """ |
2689 |
2724 # TODO: change this to navigation widget |
2690 @return flag indicating visibility of the navigation container in full |
2725 return self.isFullScreen() and self.__gotb.isVisible() |
2691 screen mode |
|
2692 @rtype bool |
|
2693 """ |
|
2694 return self.isFullScreen() and self.__navigationContainer.isVisible() |
2726 |
2695 |
2727 def showFullScreenNavigation(self): |
2696 def showFullScreenNavigation(self): |
2728 """ |
2697 """ |
2729 Public slot to show full screen navigation. |
2698 Public slot to show full screen navigation. |
2730 """ |
2699 """ |
3304 Private slot to show the Settings menu. |
3271 Private slot to show the Settings menu. |
3305 """ |
3272 """ |
3306 self.editMessageFilterAct.setEnabled( |
3273 self.editMessageFilterAct.setEnabled( |
3307 E5ErrorMessage.messageHandlerInstalled()) |
3274 E5ErrorMessage.messageHandlerInstalled()) |
3308 |
3275 |
3309 def __showBackMenu(self): |
|
3310 """ |
|
3311 Private slot showing the backwards navigation menu. |
|
3312 """ |
|
3313 self.backMenu.clear() |
|
3314 history = self.currentBrowser().history() |
|
3315 historyCount = history.count() |
|
3316 backItems = history.backItems(historyCount) |
|
3317 for index in range(len(backItems) - 1, -1, -1): |
|
3318 item = backItems[index] |
|
3319 act = QAction(self) |
|
3320 act.setData(-1 * (index + 1)) |
|
3321 icon = WebBrowserWindow.icon(item.url()) |
|
3322 act.setIcon(icon) |
|
3323 act.setText(item.title()) |
|
3324 self.backMenu.addAction(act) |
|
3325 |
|
3326 def __showForwardMenu(self): |
|
3327 """ |
|
3328 Private slot showing the forwards navigation menu. |
|
3329 """ |
|
3330 self.forwardMenu.clear() |
|
3331 history = self.currentBrowser().history() |
|
3332 historyCount = history.count() |
|
3333 forwardItems = history.forwardItems(historyCount) |
|
3334 for index in range(len(forwardItems)): |
|
3335 item = forwardItems[index] |
|
3336 act = QAction(self) |
|
3337 act.setData(index + 1) |
|
3338 icon = WebBrowserWindow.icon(item.url()) |
|
3339 act.setIcon(icon) |
|
3340 act.setText(item.title()) |
|
3341 self.forwardMenu.addAction(act) |
|
3342 |
|
3343 def __navigationMenuActionTriggered(self, act): |
|
3344 """ |
|
3345 Private slot to go to the selected page. |
|
3346 |
|
3347 @param act reference to the action selected in the navigation menu |
|
3348 (QAction) |
|
3349 """ |
|
3350 offset = act.data() |
|
3351 history = self.currentBrowser().history() |
|
3352 historyCount = history.count() |
|
3353 if offset < 0: |
|
3354 # go back |
|
3355 history.goToItem(history.backItems(historyCount)[-1 * offset - 1]) |
|
3356 else: |
|
3357 # go forward |
|
3358 history.goToItem(history.forwardItems(historyCount)[offset - 1]) |
|
3359 |
|
3360 def __clearPrivateData(self): |
3276 def __clearPrivateData(self): |
3361 """ |
3277 """ |
3362 Private slot to clear the private data. |
3278 Private slot to clear the private data. |
3363 """ |
3279 """ |
3364 from .WebBrowserClearPrivateDataDialog import \ |
3280 from .WebBrowserClearPrivateDataDialog import \ |
4078 # enter full screen mode |
3994 # enter full screen mode |
4079 self.__windowStates = evt.oldState() |
3995 self.__windowStates = evt.oldState() |
4080 self.__toolbarStates = self.saveState() |
3996 self.__toolbarStates = self.saveState() |
4081 self.menuBar().hide() |
3997 self.menuBar().hide() |
4082 self.statusBar().hide() |
3998 self.statusBar().hide() |
|
3999 self.__searchWidget.hide() |
|
4000 self.__tabWidget.tabBar().hide() |
4083 for toolbar in self.__toolbars: |
4001 for toolbar in self.__toolbars: |
4084 toolbar.hide() |
4002 toolbar.hide() |
4085 self.__tabWidget.tabBar().hide() |
4003 self.__navigationBar.exitFullScreenButton().setVisible(True) |
4086 self.__searchWidget.hide() |
4004 self.__navigationContainer.hide() |
4087 ## self.fullScreenAct.setIcon( |
|
4088 ## UI.PixmapCache.getIcon("windowRestore.png")) |
|
4089 ## self.fullScreenAct.setIconText(self.tr('Restore Window')) |
|
4090 |
4005 |
4091 elif bool(evt.oldState() & Qt.WindowFullScreen) and \ |
4006 elif bool(evt.oldState() & Qt.WindowFullScreen) and \ |
4092 not bool(self.windowState() & Qt.WindowFullScreen): |
4007 not bool(self.windowState() & Qt.WindowFullScreen): |
4093 # leave full screen mode |
4008 # leave full screen mode |
4094 self.setWindowState(self.__windowStates) |
4009 self.setWindowState(self.__windowStates) |
4095 self.__htmlFullScreen = False |
4010 self.__htmlFullScreen = False |
4096 self.menuBar().show() |
4011 self.menuBar().show() |
4097 self.statusBar().show() |
4012 self.statusBar().show() |
4098 self.restoreState(self.__toolbarStates) |
4013 self.restoreState(self.__toolbarStates) |
4099 self.__tabWidget.tabBar().show() |
4014 self.__tabWidget.tabBar().show() |
4100 ## self.fullScreenAct.setIcon( |
4015 self.__navigationBar.exitFullScreenButton().setVisible(False) |
4101 ## UI.PixmapCache.getIcon("windowFullscreen.png")) |
4016 self.__navigationContainer.show() |
4102 ## self.fullScreenAct.setIconText(self.tr('Full Screen')) |
|
4103 |
4017 |
4104 if self.__hideNavigationTimer: |
4018 if self.__hideNavigationTimer: |
4105 self.__hideNavigationTimer.stop() |
4019 self.__hideNavigationTimer.stop() |
4106 |
4020 |
4107 return super(WebBrowserWindow, self).event(evt) |
4021 return super(WebBrowserWindow, self).event(evt) |