13 except NameError: |
13 except NameError: |
14 pass |
14 pass |
15 |
15 |
16 import os |
16 import os |
17 import shutil |
17 import shutil |
|
18 import sys |
18 |
19 |
19 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \ |
20 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QByteArray, QSize, QTimer, \ |
20 QUrl, QThread, QTextCodec |
21 QUrl, QThread, QTextCodec, QProcess |
21 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics, \ |
22 from PyQt5.QtGui import QDesktopServices, QKeySequence, QFont, QFontMetrics, \ |
22 QIcon |
23 QIcon |
23 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \ |
24 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QSizePolicy, QDockWidget, \ |
24 QComboBox, QLabel, QSplitter, QMenu, QToolButton, QLineEdit, \ |
25 QComboBox, QLabel, QSplitter, QMenu, QToolButton, QLineEdit, \ |
25 QApplication, QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QAction, \ |
26 QApplication, QWhatsThis, QDialog, QHBoxLayout, QProgressBar, QAction, \ |
57 |
58 |
58 from .Tools import Scripts, WebBrowserTools, WebIconProvider |
59 from .Tools import Scripts, WebBrowserTools, WebIconProvider |
59 |
60 |
60 from .ZoomManager import ZoomManager |
61 from .ZoomManager import ZoomManager |
61 |
62 |
|
63 from eric6config import getConfig |
|
64 |
62 |
65 |
63 class WebBrowserWindow(E5MainWindow): |
66 class WebBrowserWindow(E5MainWindow): |
64 """ |
67 """ |
65 Class implementing the web browser main window. |
68 Class implementing the web browser main window. |
66 |
69 |
68 @signal zoomTextOnlyChanged(bool) emitted after the zoom text only setting |
71 @signal zoomTextOnlyChanged(bool) emitted after the zoom text only setting |
69 was changed |
72 was changed |
70 """ |
73 """ |
71 ## zoomTextOnlyChanged = pyqtSignal(bool) |
74 ## zoomTextOnlyChanged = pyqtSignal(bool) |
72 webBrowserClosed = pyqtSignal() |
75 webBrowserClosed = pyqtSignal() |
73 ## privacyChanged = pyqtSignal(bool) |
|
74 |
76 |
75 BrowserWindows = [] |
77 BrowserWindows = [] |
76 |
78 |
77 ## maxMenuFilePathLen = 75 |
79 ## maxMenuFilePathLen = 75 |
78 ## |
80 ## |
79 _fromEric = False |
81 _fromEric = False |
80 UseQtHelp = QTHELP_AVAILABLE |
82 UseQtHelp = QTHELP_AVAILABLE |
|
83 _isPrivate = False |
81 |
84 |
82 _webProfile = None |
85 _webProfile = None |
83 _networkManager = None |
86 _networkManager = None |
84 ## _cookieJar = None |
87 ## _cookieJar = None |
85 ## _helpEngine = None |
88 ## _helpEngine = None |
98 _featurePermissionManager = None |
101 _featurePermissionManager = None |
99 _flashCookieManager = None |
102 _flashCookieManager = None |
100 |
103 |
101 def __init__(self, home, path, parent, name, fromEric=False, |
104 def __init__(self, home, path, parent, name, fromEric=False, |
102 initShortcutsOnly=False, searchWord=None, |
105 initShortcutsOnly=False, searchWord=None, |
103 private=False): |
106 private=False, settingsDir=""): |
104 """ |
107 """ |
105 Constructor |
108 Constructor |
106 |
109 |
107 @param home the URL to be shown (string) |
110 @param home the URL to be shown (string) |
108 @param path the path of the working dir (usually '.') (string) |
111 @param path the path of the working dir (usually '.') (string) |
112 eric6 (boolean) |
115 eric6 (boolean) |
113 @keyparam initShortcutsOnly flag indicating to just initialize the |
116 @keyparam initShortcutsOnly flag indicating to just initialize the |
114 keyboard shortcuts (boolean) |
117 keyboard shortcuts (boolean) |
115 @keyparam searchWord word to search for (string) |
118 @keyparam searchWord word to search for (string) |
116 @keyparam private flag indicating a private browsing window (bool) |
119 @keyparam private flag indicating a private browsing window (bool) |
|
120 @keyparam settingsDir directory to be used for the settings files (str) |
117 """ |
121 """ |
118 super(WebBrowserWindow, self).__init__(parent) |
122 super(WebBrowserWindow, self).__init__(parent) |
119 self.setObjectName(name) |
123 self.setObjectName(name) |
120 self.setWindowTitle(self.tr("eric6 Web Browser")) |
124 self.setWindowTitle(self.tr("eric6 Web Browser")) |
121 |
125 |
|
126 self.__settingsDir = settingsDir |
122 self.__fromEric = fromEric |
127 self.__fromEric = fromEric |
123 WebBrowserWindow._fromEric = fromEric |
128 WebBrowserWindow._fromEric = fromEric |
124 self.__initShortcutsOnly = initShortcutsOnly |
129 self.__initShortcutsOnly = initShortcutsOnly |
125 self.setWindowIcon(UI.PixmapCache.getIcon("ericWeb.png")) |
130 self.setWindowIcon(UI.PixmapCache.getIcon("ericWeb.png")) |
126 |
131 |
127 self.__mHistory = [] |
132 self.__mHistory = [] |
128 self.__lastConfigurationPageName = "" |
133 self.__lastConfigurationPageName = "" |
129 |
134 |
130 self.__isPrivate = private |
135 WebBrowserWindow._isPrivate = private |
131 |
136 |
132 self.__eventMouseButtons = Qt.NoButton |
137 self.__eventMouseButtons = Qt.NoButton |
133 self.__eventKeyboardModifiers = Qt.NoModifier |
138 self.__eventKeyboardModifiers = Qt.NoModifier |
134 |
139 |
135 if self.__initShortcutsOnly: |
140 if self.__initShortcutsOnly: |
526 QKeySequence(self.tr("Ctrl+N", "File|New Window")), |
531 QKeySequence(self.tr("Ctrl+N", "File|New Window")), |
527 0, self, 'webbrowser_file_new_window') |
532 0, self, 'webbrowser_file_new_window') |
528 self.newAct.setStatusTip(self.tr('Open a new web browser window')) |
533 self.newAct.setStatusTip(self.tr('Open a new web browser window')) |
529 self.newAct.setWhatsThis(self.tr( |
534 self.newAct.setWhatsThis(self.tr( |
530 """<b>New Window</b>""" |
535 """<b>New Window</b>""" |
531 """<p>This opens a new web browser window.</p>""" |
536 """<p>This opens a new web browser window in the current""" |
|
537 """ privacy mode.</p>""" |
532 )) |
538 )) |
533 if not self.__initShortcutsOnly: |
539 if not self.__initShortcutsOnly: |
534 self.newAct.triggered.connect(self.newWindow) |
540 self.newAct.triggered.connect(self.newWindow) |
535 self.__actions.append(self.newAct) |
541 self.__actions.append(self.newAct) |
536 |
542 |
537 # TODO: Private Window |
543 self.newPrivateAct = E5Action( |
|
544 self.tr('New Private Window'), |
|
545 UI.PixmapCache.getIcon("privateMode.png"), |
|
546 self.tr('New &Private Window'), |
|
547 QKeySequence(self.tr("Ctrl+Shift+P", "File|New Private Window")), |
|
548 0, self, 'webbrowser_file_new_private_window') |
|
549 self.newPrivateAct.setStatusTip(self.tr( |
|
550 'Open a new private web browser window')) |
|
551 self.newPrivateAct.setWhatsThis(self.tr( |
|
552 """<b>New Private Window</b>""" |
|
553 """<p>This opens a new private web browser window by starting""" |
|
554 """ a new web browser instance in private mode.</p>""" |
|
555 )) |
|
556 if not self.__initShortcutsOnly: |
|
557 self.newPrivateAct.triggered.connect(self.newPrivateWindow) |
|
558 self.__actions.append(self.newPrivateAct) |
538 |
559 |
539 self.openAct = E5Action( |
560 self.openAct = E5Action( |
540 self.tr('Open File'), |
561 self.tr('Open File'), |
541 UI.PixmapCache.getIcon("open.png"), |
562 UI.PixmapCache.getIcon("open.png"), |
542 self.tr('&Open File'), |
563 self.tr('&Open File'), |
725 )) |
746 )) |
726 if not self.__initShortcutsOnly: |
747 if not self.__initShortcutsOnly: |
727 self.closeAllAct.triggered.connect( |
748 self.closeAllAct.triggered.connect( |
728 self.__tabWidget.closeAllBrowsers) |
749 self.__tabWidget.closeAllBrowsers) |
729 self.__actions.append(self.closeAllAct) |
750 self.__actions.append(self.closeAllAct) |
730 |
|
731 # TODO: Private Browsing |
|
732 ## self.privateBrowsingAct = E5Action( |
|
733 ## self.tr('Private Browsing'), |
|
734 ## UI.PixmapCache.getIcon("privateBrowsing.png"), |
|
735 ## self.tr('Private &Browsing'), |
|
736 ## 0, 0, self, 'webbrowser_file_private_browsing') |
|
737 ## self.privateBrowsingAct.setStatusTip(self.tr('Private Browsing')) |
|
738 ## self.privateBrowsingAct.setWhatsThis(self.tr( |
|
739 ## """<b>Private Browsing</b>""" |
|
740 ## """<p>Enables private browsing. In this mode no history is""" |
|
741 ## """ recorded anymore.</p>""" |
|
742 ## )) |
|
743 ## if not self.__initShortcutsOnly: |
|
744 ## self.privateBrowsingAct.triggered.connect( |
|
745 ## self.__privateBrowsing) |
|
746 ## self.privateBrowsingAct.setCheckable(True) |
|
747 ## self.__actions.append(self.privateBrowsingAct) |
|
748 |
751 |
749 self.exitAct = E5Action( |
752 self.exitAct = E5Action( |
750 self.tr('Quit'), |
753 self.tr('Quit'), |
751 UI.PixmapCache.getIcon("exit.png"), |
754 UI.PixmapCache.getIcon("exit.png"), |
752 self.tr('&Quit'), |
755 self.tr('&Quit'), |
1747 |
1750 |
1748 menu = mb.addMenu(self.tr('&File')) |
1751 menu = mb.addMenu(self.tr('&File')) |
1749 menu.setTearOffEnabled(True) |
1752 menu.setTearOffEnabled(True) |
1750 menu.addAction(self.newTabAct) |
1753 menu.addAction(self.newTabAct) |
1751 menu.addAction(self.newAct) |
1754 menu.addAction(self.newAct) |
|
1755 menu.addAction(self.newPrivateAct) |
1752 menu.addAction(self.openAct) |
1756 menu.addAction(self.openAct) |
1753 menu.addAction(self.openTabAct) |
1757 menu.addAction(self.openTabAct) |
1754 menu.addSeparator() |
1758 menu.addSeparator() |
1755 ## menu.addAction(self.saveAsAct) |
1759 ## menu.addAction(self.saveAsAct) |
1756 menu.addAction(self.savePageScreenAct) |
1760 menu.addAction(self.savePageScreenAct) |
1916 filetb = self.addToolBar(self.tr("File")) |
1920 filetb = self.addToolBar(self.tr("File")) |
1917 filetb.setObjectName("FileToolBar") |
1921 filetb.setObjectName("FileToolBar") |
1918 filetb.setIconSize(UI.Config.ToolBarIconSize) |
1922 filetb.setIconSize(UI.Config.ToolBarIconSize) |
1919 filetb.addAction(self.newTabAct) |
1923 filetb.addAction(self.newTabAct) |
1920 filetb.addAction(self.newAct) |
1924 filetb.addAction(self.newAct) |
|
1925 filetb.addAction(self.newPrivateAct) |
1921 filetb.addAction(self.openAct) |
1926 filetb.addAction(self.openAct) |
1922 filetb.addAction(self.openTabAct) |
1927 filetb.addAction(self.openTabAct) |
1923 filetb.addSeparator() |
1928 filetb.addSeparator() |
1924 ## filetb.addAction(self.saveAsAct) |
1929 ## filetb.addAction(self.saveAsAct) |
1925 filetb.addAction(self.savePageScreenAct) |
1930 filetb.addAction(self.savePageScreenAct) |
2147 @pyqtSlot() |
2152 @pyqtSlot() |
2148 def newWindow(self, link=None): |
2153 def newWindow(self, link=None): |
2149 """ |
2154 """ |
2150 Public slot called to open a new web browser window. |
2155 Public slot called to open a new web browser window. |
2151 |
2156 |
2152 @param link file to be displayed in the new window (string or QUrl) |
2157 @param link URL to be displayed in the new window |
|
2158 @type str or QUrl |
2153 """ |
2159 """ |
2154 if link is None: |
2160 if link is None: |
2155 linkName = "" |
2161 linkName = "" |
2156 elif isinstance(link, QUrl): |
2162 elif isinstance(link, QUrl): |
2157 linkName = link.toString() |
2163 linkName = link.toString() |
2158 else: |
2164 else: |
2159 linkName = link |
2165 linkName = link |
2160 h = WebBrowserWindow(linkName, ".", self.parent(), "webbrowser", |
2166 h = WebBrowserWindow(linkName, ".", self.parent(), "webbrowser", |
2161 self.__fromEric) |
2167 self.__fromEric, private=self.isPrivate()) |
2162 h.show() |
2168 h.show() |
2163 |
2169 |
2164 # TODO: Private Window |
2170 @pyqtSlot() |
|
2171 def newPrivateWindow(self, link=None): |
|
2172 """ |
|
2173 Public slot called to open a new private web browser window. |
|
2174 |
|
2175 |
|
2176 @param link URL to be displayed in the new window |
|
2177 @type str or QUrl |
|
2178 """ |
|
2179 if link is None: |
|
2180 linkName = "" |
|
2181 elif isinstance(link, QUrl): |
|
2182 linkName = link.toString() |
|
2183 else: |
|
2184 linkName = link |
|
2185 |
|
2186 applPath = os.path.join(getConfig("ericDir"), "eric6_browser.py") |
|
2187 args = [] |
|
2188 args.append(applPath) |
|
2189 args.append("--config={0}".format(Utilities.getConfigDir())) |
|
2190 if self.__settingsDir: |
|
2191 args.append("--settings={0}".format(self.__settingsDir)) |
|
2192 args.append("--private") |
|
2193 if linkName: |
|
2194 args.append(linkName) |
|
2195 |
|
2196 if not os.path.isfile(applPath) or \ |
|
2197 not QProcess.startDetached(sys.executable, args): |
|
2198 E5MessageBox.critical( |
|
2199 self, |
|
2200 self.tr('New Private Window'), |
|
2201 self.tr( |
|
2202 '<p>Could not start the process.<br>' |
|
2203 'Ensure that it is available as <b>{0}</b>.</p>' |
|
2204 ).format(applPath), |
|
2205 self.tr('OK')) |
2165 |
2206 |
2166 def __openFile(self): |
2207 def __openFile(self): |
2167 """ |
2208 """ |
2168 Private slot called to open a file. |
2209 Private slot called to open a file. |
2169 """ |
2210 """ |
2634 def __selectAll(self): |
2675 def __selectAll(self): |
2635 """ |
2676 """ |
2636 Private slot to handle the select all action. |
2677 Private slot to handle the select all action. |
2637 """ |
2678 """ |
2638 self.currentBrowser().selectAll() |
2679 self.currentBrowser().selectAll() |
2639 # TODO: Private Browsing |
2680 |
2640 ## |
2681 @classmethod |
2641 ## def __privateBrowsing(self): |
2682 def isPrivate(cls): |
2642 ## """ |
|
2643 ## Private slot to switch private browsing. |
|
2644 ## """ |
|
2645 ## settings = QWebSettings.globalSettings() |
|
2646 ## pb = settings.testAttribute(QWebSettings.PrivateBrowsingEnabled) |
|
2647 ## if not pb: |
|
2648 ## txt = self.tr( |
|
2649 ## """<b>Are you sure you want to turn on private""" |
|
2650 ## """ browsing?</b><p>When private browsing is turned on,""" |
|
2651 ## """ web pages are not added to the history, searches""" |
|
2652 ## """ are not added to the list of recent searches and""" |
|
2653 ## """ web site icons and cookies are not stored.""" |
|
2654 ## """ HTML5 offline storage will be deactivated.""" |
|
2655 ## """ Until you close the window, you can still click""" |
|
2656 ## """ the Back and Forward buttons to return to the""" |
|
2657 ## """ web pages you have opened.</p>""") |
|
2658 ## res = E5MessageBox.yesNo(self, "", txt) |
|
2659 ## if res: |
|
2660 ## self.setPrivateMode(True) |
|
2661 ## else: |
|
2662 ## self.setPrivateMode(False) |
|
2663 ## |
|
2664 ## def setPrivateMode(self, on): |
|
2665 ## """ |
|
2666 ## Public method to set the privacy mode. |
|
2667 ## |
|
2668 ## @param on flag indicating the privacy state (boolean) |
|
2669 ## """ |
|
2670 ## QWebSettings.globalSettings().setAttribute( |
|
2671 ## QWebSettings.PrivateBrowsingEnabled, on) |
|
2672 ## if on: |
|
2673 ## self.__setIconDatabasePath(False) |
|
2674 ## else: |
|
2675 ## self.__setIconDatabasePath(True) |
|
2676 ## self.privateBrowsingAct.setChecked(on) |
|
2677 ## self.privacyChanged.emit(on) |
|
2678 |
|
2679 def isPrivate(self): |
|
2680 """ |
2683 """ |
2681 Public method to check the private browsing mode. |
2684 Public method to check the private browsing mode. |
2682 |
2685 |
2683 @return flag indicating private browsing mode |
2686 @return flag indicating private browsing mode |
2684 @rtype bool |
2687 @rtype bool |
2685 """ |
2688 """ |
2686 return self.__isPrivate |
2689 return cls._isPrivate |
2687 |
2690 |
2688 def currentBrowser(self): |
2691 def currentBrowser(self): |
2689 """ |
2692 """ |
2690 Public method to get a reference to the current web browser. |
2693 Public method to get a reference to the current web browser. |
2691 |
2694 |