WebBrowser/WebBrowserWindow.py

branch
QtWebEngine
changeset 4733
ae291a307ea6
parent 4732
5ac4fc1dfc20
child 4734
ce0b1f024da9
equal deleted inserted replaced
4732:5ac4fc1dfc20 4733:ae291a307ea6
1188 )) 1188 ))
1189 if not self.__initShortcutsOnly: 1189 if not self.__initShortcutsOnly:
1190 self.pageSourceAct.triggered.connect(self.__showPageSource) 1190 self.pageSourceAct.triggered.connect(self.__showPageSource)
1191 self.__actions.append(self.pageSourceAct) 1191 self.__actions.append(self.pageSourceAct)
1192 self.addAction(self.pageSourceAct) 1192 self.addAction(self.pageSourceAct)
1193 ## 1193
1194 ## self.fullScreenAct = E5Action( 1194 self.fullScreenAct = E5Action(
1195 ## self.tr('Full Screen'), 1195 self.tr('Full Screen'),
1196 ## UI.PixmapCache.getIcon("windowFullscreen.png"), 1196 UI.PixmapCache.getIcon("windowFullscreen.png"),
1197 ## self.tr('&Full Screen'), 1197 self.tr('&Full Screen'),
1198 ## QKeySequence(self.tr('F11')), 0, 1198 QKeySequence(self.tr('F11')), 0,
1199 ## self, 'webbrowser_view_full_scree') 1199 self, 'webbrowser_view_full_scree')
1200 ## if not self.__initShortcutsOnly: 1200 if not self.__initShortcutsOnly:
1201 ## self.fullScreenAct.triggered.connect(self.__viewFullScreen) 1201 self.fullScreenAct.triggered.connect(self.__viewFullScreen)
1202 ## self.__actions.append(self.fullScreenAct) 1202 self.__actions.append(self.fullScreenAct)
1203 ## self.addAction(self.fullScreenAct) 1203 self.addAction(self.fullScreenAct)
1204 1204
1205 self.nextTabAct = E5Action( 1205 self.nextTabAct = E5Action(
1206 self.tr('Show next tab'), 1206 self.tr('Show next tab'),
1207 self.tr('Show next tab'), 1207 self.tr('Show next tab'),
1208 QKeySequence(self.tr('Ctrl+Alt+Tab')), 0, 1208 QKeySequence(self.tr('Ctrl+Alt+Tab')), 0,
1244 """ with your prefered values.</p>""" 1244 """ with your prefered values.</p>"""
1245 )) 1245 ))
1246 if not self.__initShortcutsOnly: 1246 if not self.__initShortcutsOnly:
1247 self.prefAct.triggered.connect(self.__showPreferences) 1247 self.prefAct.triggered.connect(self.__showPreferences)
1248 self.__actions.append(self.prefAct) 1248 self.__actions.append(self.prefAct)
1249 1249
1250 # TODO: Languages
1250 ## self.acceptedLanguagesAct = E5Action( 1251 ## self.acceptedLanguagesAct = E5Action(
1251 ## self.tr('Languages'), 1252 ## self.tr('Languages'),
1252 ## UI.PixmapCache.getIcon("flag.png"), 1253 ## UI.PixmapCache.getIcon("flag.png"),
1253 ## self.tr('&Languages...'), 0, 0, 1254 ## self.tr('&Languages...'), 0, 0,
1254 ## self, 'webbrowser_accepted_languages') 1255 ## self, 'webbrowser_accepted_languages')
1293 ## if not self.__initShortcutsOnly: 1294 ## if not self.__initShortcutsOnly:
1294 ## self.flashCookiesAct.triggered.connect( 1295 ## self.flashCookiesAct.triggered.connect(
1295 ## self.__showFlashCookiesManagement) 1296 ## self.__showFlashCookiesManagement)
1296 ## self.__actions.append(self.flashCookiesAct) 1297 ## self.__actions.append(self.flashCookiesAct)
1297 1298
1299 # TODO: Offline Storage
1298 ## self.offlineStorageAct = E5Action( 1300 ## self.offlineStorageAct = E5Action(
1299 ## self.tr('Offline Storage'), 1301 ## self.tr('Offline Storage'),
1300 ## UI.PixmapCache.getIcon("preferences-html5.png"), 1302 ## UI.PixmapCache.getIcon("preferences-html5.png"),
1301 ## self.tr('Offline &Storage...'), 0, 0, 1303 ## self.tr('Offline &Storage...'), 0, 0,
1302 ## self, 'webbrowser_offline_storage') 1304 ## self, 'webbrowser_offline_storage')
1309 ## if not self.__initShortcutsOnly: 1311 ## if not self.__initShortcutsOnly:
1310 ## self.offlineStorageAct.triggered.connect( 1312 ## self.offlineStorageAct.triggered.connect(
1311 ## self.__showOfflineStorageConfiguration) 1313 ## self.__showOfflineStorageConfiguration)
1312 ## self.__actions.append(self.offlineStorageAct) 1314 ## self.__actions.append(self.offlineStorageAct)
1313 1315
1316 # TODO: PIM
1314 ## self.personalDataAct = E5Action( 1317 ## self.personalDataAct = E5Action(
1315 ## self.tr('Personal Information'), 1318 ## self.tr('Personal Information'),
1316 ## UI.PixmapCache.getIcon("pim.png"), 1319 ## UI.PixmapCache.getIcon("pim.png"),
1317 ## self.tr('Personal Information...'), 1320 ## self.tr('Personal Information...'),
1318 ## 0, 0, 1321 ## 0, 0,
1327 ## if not self.__initShortcutsOnly: 1330 ## if not self.__initShortcutsOnly:
1328 ## self.personalDataAct.triggered.connect( 1331 ## self.personalDataAct.triggered.connect(
1329 ## self.__showPersonalInformationDialog) 1332 ## self.__showPersonalInformationDialog)
1330 ## self.__actions.append(self.personalDataAct) 1333 ## self.__actions.append(self.personalDataAct)
1331 1334
1335 # TODO: GreaseMonkey
1332 ## self.greaseMonkeyAct = E5Action( 1336 ## self.greaseMonkeyAct = E5Action(
1333 ## self.tr('GreaseMonkey Scripts'), 1337 ## self.tr('GreaseMonkey Scripts'),
1334 ## UI.PixmapCache.getIcon("greaseMonkey.png"), 1338 ## UI.PixmapCache.getIcon("greaseMonkey.png"),
1335 ## self.tr('GreaseMonkey Scripts...'), 1339 ## self.tr('GreaseMonkey Scripts...'),
1336 ## 0, 0, 1340 ## 0, 0,
1488 ## if not self.__initShortcutsOnly: 1492 ## if not self.__initShortcutsOnly:
1489 ## self.reindexDocumentationAct.triggered.connect( 1493 ## self.reindexDocumentationAct.triggered.connect(
1490 ## self.__searchEngine.reindexDocumentation) 1494 ## self.__searchEngine.reindexDocumentation)
1491 ## self.__actions.append(self.reindexDocumentationAct) 1495 ## self.__actions.append(self.reindexDocumentationAct)
1492 1496
1497 # TODO: Clear Private Data
1493 ## self.clearPrivateDataAct = E5Action( 1498 ## self.clearPrivateDataAct = E5Action(
1494 ## self.tr('Clear private data'), 1499 ## self.tr('Clear private data'),
1495 ## self.tr('&Clear private data'), 1500 ## self.tr('&Clear private data'),
1496 ## 0, 0, 1501 ## 0, 0,
1497 ## self, 'webbrowser_clear_private_data') 1502 ## self, 'webbrowser_clear_private_data')
1504 ## )) 1509 ## ))
1505 ## if not self.__initShortcutsOnly: 1510 ## if not self.__initShortcutsOnly:
1506 ## self.clearPrivateDataAct.triggered.connect( 1511 ## self.clearPrivateDataAct.triggered.connect(
1507 ## self.__clearPrivateData) 1512 ## self.__clearPrivateData)
1508 ## self.__actions.append(self.clearPrivateDataAct) 1513 ## self.__actions.append(self.clearPrivateDataAct)
1509 1514 ##
1510 ## self.clearIconsAct = E5Action( 1515 ## self.clearIconsAct = E5Action(
1511 ## self.tr('Clear icons database'), 1516 ## self.tr('Clear icons database'),
1512 ## self.tr('Clear &icons database'), 1517 ## self.tr('Clear &icons database'),
1513 ## 0, 0, 1518 ## 0, 0,
1514 ## self, 'webbrowser_clear_icons_db') 1519 ## self, 'webbrowser_clear_icons_db')
1800 menu.addAction(self.zoomOutAct) 1805 menu.addAction(self.zoomOutAct)
1801 ## if self.zoomTextOnlyAct is not None: 1806 ## if self.zoomTextOnlyAct is not None:
1802 ## menu.addAction(self.zoomTextOnlyAct) 1807 ## menu.addAction(self.zoomTextOnlyAct)
1803 menu.addSeparator() 1808 menu.addSeparator()
1804 menu.addAction(self.pageSourceAct) 1809 menu.addAction(self.pageSourceAct)
1805 ## menu.addAction(self.fullScreenAct) 1810 menu.addAction(self.fullScreenAct)
1806 self.__textEncodingMenu = menu.addMenu( 1811 self.__textEncodingMenu = menu.addMenu(
1807 self.tr("Text Encoding")) 1812 self.tr("Text Encoding"))
1808 self.__textEncodingMenu.aboutToShow.connect( 1813 self.__textEncodingMenu.aboutToShow.connect(
1809 self.__aboutToShowTextEncodingMenu) 1814 self.__aboutToShowTextEncodingMenu)
1810 self.__textEncodingMenu.triggered.connect(self.__setTextEncoding) 1815 self.__textEncodingMenu.triggered.connect(self.__setTextEncoding)
1963 viewtb.setObjectName("ViewToolBar") 1968 viewtb.setObjectName("ViewToolBar")
1964 viewtb.setIconSize(UI.Config.ToolBarIconSize) 1969 viewtb.setIconSize(UI.Config.ToolBarIconSize)
1965 viewtb.addAction(self.zoomInAct) 1970 viewtb.addAction(self.zoomInAct)
1966 viewtb.addAction(self.zoomResetAct) 1971 viewtb.addAction(self.zoomResetAct)
1967 viewtb.addAction(self.zoomOutAct) 1972 viewtb.addAction(self.zoomOutAct)
1968 ## viewtb.addSeparator() 1973 viewtb.addSeparator()
1969 ## viewtb.addAction(self.fullScreenAct) 1974 viewtb.addAction(self.fullScreenAct)
1970 1975
1971 findtb = self.addToolBar(self.tr("Find")) 1976 findtb = self.addToolBar(self.tr("Find"))
1972 findtb.setObjectName("FindToolBar") 1977 findtb.setObjectName("FindToolBar")
1973 findtb.setIconSize(UI.Config.ToolBarIconSize) 1978 findtb.setIconSize(UI.Config.ToolBarIconSize)
1974 findtb.addAction(self.findAct) 1979 findtb.addAction(self.findAct)
2316 def __addBookmark(self): 2321 def __addBookmark(self):
2317 """ 2322 """
2318 Private slot called to add the displayed file to the bookmarks. 2323 Private slot called to add the displayed file to the bookmarks.
2319 """ 2324 """
2320 view = self.currentBrowser() 2325 view = self.currentBrowser()
2321 url = bytes(view.url().toEncoded()).decode() 2326 urlStr = bytes(view.url().toEncoded()).decode()
2322 title = view.title() 2327 title = view.title()
2328
2329 script = Scripts.getAllMetaAttributes()
2330 view.page().runJavaScript(
2331 script,
2332 lambda res: self.__addBookmarkCallback(urlStr, title, res))
2333
2334 def __addBookmarkCallback(self, url, title, res):
2335 """
2336 Private callback method of __addBookmark().
2337
2338 @param url URL for the bookmark
2339 @type str
2340 @param title title for the bookmark
2341 @type str
2342 @param res result of the JavaScript
2343 @type list
2344 """
2323 description = "" 2345 description = ""
2324 meta = view.page().mainFrame().metaData() 2346 for meta in res:
2325 if "description" in meta: 2347 if meta["name"] == "description":
2326 description = meta["description"][0] 2348 description = meta["content"]
2327 2349
2328 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog 2350 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog
2329 dlg = AddBookmarkDialog() 2351 dlg = AddBookmarkDialog()
2330 dlg.setUrl(url) 2352 dlg.setUrl(url)
2331 dlg.setTitle(title) 2353 dlg.setTitle(title)
2369 2391
2370 folder = dlg.addedNode() 2392 folder = dlg.addedNode()
2371 if folder is None: 2393 if folder is None:
2372 return 2394 return
2373 2395
2396 for view in self.__tabWidget.browsers():
2397 urlStr = bytes(view.url().toEncoded()).decode()
2398 title = view.title()
2399
2400 script = Scripts.getAllMetaAttributes()
2401 view.page().runJavaScript(
2402 script,
2403 lambda res: self.__bookmarkAllCallback(folder, urlStr,
2404 title, res))
2405
2406 def __bookmarkAllCallback(self, folder, url, title, res):
2407 """
2408 Private callback method of __addBookmark().
2409
2410 @param folder reference to the bookmarks folder
2411 @type BookmarkNode
2412 @param url URL for the bookmark
2413 @type str
2414 @param title title for the bookmark
2415 @type str
2416 @param res result of the JavaScript
2417 @type list
2418 """
2419 description = ""
2420 for meta in res:
2421 if meta["name"] == "description":
2422 description = meta["content"]
2423
2374 from .Bookmarks.BookmarkNode import BookmarkNode 2424 from .Bookmarks.BookmarkNode import BookmarkNode
2375 for browser in self.__tabWidget.browsers(): 2425 bookmark = BookmarkNode(BookmarkNode.Bookmark)
2376 bookmark = BookmarkNode(BookmarkNode.Bookmark) 2426 bookmark.url = url
2377 bookmark.url = bytes(browser.url().toEncoded()).decode() 2427 bookmark.title = title
2378 bookmark.title = browser.title() 2428 bookmark.desc = description
2379 meta = browser.page().mainFrame().metaData() 2429
2380 if "description" in meta: 2430 self.bookmarksManager().addBookmark(folder, bookmark)
2381 bookmark.desc = meta["description"][0]
2382
2383 self.bookmarksManager().addBookmark(folder, bookmark)
2384 2431
2385 def __find(self): 2432 def __find(self):
2386 """ 2433 """
2387 Private slot to handle the find action. 2434 Private slot to handle the find action.
2388 2435
2563 ## """ 2610 ## """
2564 ## QWebSettings.globalSettings().setAttribute( 2611 ## QWebSettings.globalSettings().setAttribute(
2565 ## QWebSettings.ZoomTextOnly, textOnly) 2612 ## QWebSettings.ZoomTextOnly, textOnly)
2566 ## self.zoomTextOnlyChanged.emit(textOnly) 2613 ## self.zoomTextOnlyChanged.emit(textOnly)
2567 ## 2614 ##
2568 # TODO: Full Screen 2615 def __viewFullScreen(self):
2569 ## def __viewFullScreen(self): 2616 """
2570 ## """ 2617 Private slot called to toggle fullscreen mode.
2571 ## Private slot called to toggle fullscreen mode. 2618 """
2572 ## """ 2619 if self.__isFullScreen():
2573 ## if self.__isFullScreen(): 2620 # TODO: Full Screen - web pages need to be toggled separately (Qt 5.6)
2574 ## # switch back to normal 2621 # switch back to normal
2575 ## self.setWindowState(self.windowState() & ~Qt.WindowFullScreen) 2622 self.setWindowState(self.windowState() & ~Qt.WindowFullScreen)
2576 ## self.menuBar().show() 2623 self.menuBar().show()
2577 ## self.fullScreenAct.setIcon( 2624 self.fullScreenAct.setIcon(
2578 ## UI.PixmapCache.getIcon("windowFullscreen.png")) 2625 UI.PixmapCache.getIcon("windowFullscreen.png"))
2579 ## self.fullScreenAct.setIconText(self.tr('Full Screen')) 2626 self.fullScreenAct.setIconText(self.tr('Full Screen'))
2580 ## else: 2627 else:
2581 ## # switch to full screen 2628 # switch to full screen
2582 ## self.setWindowState(self.windowState() | Qt.WindowFullScreen) 2629 self.setWindowState(self.windowState() | Qt.WindowFullScreen)
2583 ## self.menuBar().hide() 2630 self.menuBar().hide()
2584 ## self.fullScreenAct.setIcon( 2631 self.fullScreenAct.setIcon(
2585 ## UI.PixmapCache.getIcon("windowRestore.png")) 2632 UI.PixmapCache.getIcon("windowRestore.png"))
2586 ## self.fullScreenAct.setIconText(self.tr('Restore Window')) 2633 self.fullScreenAct.setIconText(self.tr('Restore Window'))
2634 # TODO: Full Screen - web pages need to be toggled separately (Qt 5.6)
2587 2635
2588 def __isFullScreen(self): 2636 def __isFullScreen(self):
2589 """ 2637 """
2590 Private method to determine, if the window is in full screen mode. 2638 Private method to determine, if the window is in full screen mode.
2591 2639
2721 # TODO: Preferences dialog 2769 # TODO: Preferences dialog
2722 def __showPreferences(self): 2770 def __showPreferences(self):
2723 """ 2771 """
2724 Private slot to set the preferences. 2772 Private slot to set the preferences.
2725 """ 2773 """
2774 # TODO: Preferences
2726 ## from Preferences.ConfigurationDialog import ConfigurationDialog 2775 ## from Preferences.ConfigurationDialog import ConfigurationDialog
2727 ## dlg = ConfigurationDialog( 2776 ## dlg = ConfigurationDialog(
2728 ## self, 'Configuration', True, fromEric=self.__fromEric, 2777 ## self, 'Configuration', True, fromEric=self.__fromEric,
2729 ## displayMode=ConfigurationDialog.WebBrowserMode) 2778 ## displayMode=ConfigurationDialog.WebBrowserMode)
2730 ## dlg.preferencesChanged.connect(self.preferencesChanged) 2779 ## dlg.preferencesChanged.connect(self.preferencesChanged)
2750 self.setStyle(Preferences.getUI("Style"), 2799 self.setStyle(Preferences.getUI("Style"),
2751 Preferences.getUI("StyleSheet")) 2800 Preferences.getUI("StyleSheet"))
2752 2801
2753 self.__initWebEngineSettings() 2802 self.__initWebEngineSettings()
2754 2803
2804 # TODO: NetworkManager
2755 ## self.networkAccessManager().preferencesChanged() 2805 ## self.networkAccessManager().preferencesChanged()
2756 ## 2806 ##
2807 # TODO: History
2757 ## self.historyManager().preferencesChanged() 2808 ## self.historyManager().preferencesChanged()
2758 ## 2809 ##
2759 self.__tabWidget.preferencesChanged() 2810 self.__tabWidget.preferencesChanged()
2760 2811
2812 # TODO: OpenSearch
2761 ## self.searchEdit.preferencesChanged() 2813 ## self.searchEdit.preferencesChanged()
2762 ## 2814 ##
2815 # TODO: VirusTotal
2763 ## self.__virusTotal.preferencesChanged() 2816 ## self.__virusTotal.preferencesChanged()
2764 ## if not Preferences.getWebBrowser("VirusTotalEnabled") or \ 2817 ## if not Preferences.getWebBrowser("VirusTotalEnabled") or \
2765 ## Preferences.getWebBrowser("VirusTotalServiceKey") == "": 2818 ## Preferences.getWebBrowser("VirusTotalServiceKey") == "":
2766 ## self.virustotalScanCurrentAct.setEnabled(False) 2819 ## self.virustotalScanCurrentAct.setEnabled(False)
2767 ## self.virustotalIpReportAct.setEnabled(False) 2820 ## self.virustotalIpReportAct.setEnabled(False)
2776 Public slot to handle the change of the master password. 2829 Public slot to handle the change of the master password.
2777 2830
2778 @param oldPassword current master password (string) 2831 @param oldPassword current master password (string)
2779 @param newPassword new master password (string) 2832 @param newPassword new master password (string)
2780 """ 2833 """
2834 # TODO: PasswordManager
2781 ## from Preferences.ConfigurationDialog import ConfigurationDialog 2835 ## from Preferences.ConfigurationDialog import ConfigurationDialog
2782 ## self.passwordManager().masterPasswordChanged(oldPassword, newPassword) 2836 ## self.passwordManager().masterPasswordChanged(oldPassword, newPassword)
2783 ## if self.__fromEric and isinstance(self.sender(), ConfigurationDialog): 2837 ## if self.__fromEric and isinstance(self.sender(), ConfigurationDialog):
2784 ## # we were called from our local configuration dialog 2838 ## # we were called from our local configuration dialog
2785 ## Preferences.convertPasswords(oldPassword, newPassword) 2839 ## Preferences.convertPasswords(oldPassword, newPassword)

eric ide

mercurial