351 html = html.replace("@TITLE@", title.encode("utf8")) |
351 html = html.replace("@TITLE@", title.encode("utf8")) |
352 html = html.replace("@H1@", info.errorString.encode("utf8")) |
352 html = html.replace("@H1@", info.errorString.encode("utf8")) |
353 html = html.replace( |
353 html = html.replace( |
354 "@H2@", self.trUtf8("When connecting to: {0}.")\ |
354 "@H2@", self.trUtf8("When connecting to: {0}.")\ |
355 .format(urlString).encode("utf8")) |
355 .format(urlString).encode("utf8")) |
356 html = html.replace("@LI-1@", |
356 html = html.replace( |
|
357 "@LI-1@", |
357 self.trUtf8("Check the address for errors such as " |
358 self.trUtf8("Check the address for errors such as " |
358 "<b>ww</b>.example.org instead of " |
359 "<b>ww</b>.example.org instead of " |
359 "<b>www</b>.example.org").encode("utf8")) |
360 "<b>www</b>.example.org").encode("utf8")) |
360 html = html.replace("@LI-2@", |
361 html = html.replace( |
|
362 "@LI-2@", |
361 self.trUtf8( |
363 self.trUtf8( |
362 "If the address is correct, try checking the network " |
364 "If the address is correct, try checking the network " |
363 "connection.").encode("utf8")) |
365 "connection.").encode("utf8")) |
364 html = html.replace("@LI-3@", |
366 html = html.replace( |
|
367 "@LI-3@", |
365 self.trUtf8( |
368 self.trUtf8( |
366 "If your computer or network is protected by a firewall " |
369 "If your computer or network is protected by a firewall " |
367 "or proxy, make sure that the browser is permitted to " |
370 "or proxy, make sure that the browser is permitted to " |
368 "access the network.").encode("utf8")) |
371 "access the network.").encode("utf8")) |
369 html = html.replace("@LI-4@", |
372 html = html.replace( |
|
373 "@LI-4@", |
370 self.trUtf8("If your cache policy is set to offline browsing," |
374 self.trUtf8("If your cache policy is set to offline browsing," |
371 "only pages in the local cache are available.")\ |
375 "only pages in the local cache are available.")\ |
372 .encode("utf8")) |
376 .encode("utf8")) |
373 html = html.replace( |
377 html = html.replace( |
374 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |
378 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |
830 started = QDesktopServices.openUrl(name) |
834 started = QDesktopServices.openUrl(name) |
831 if not started: |
835 if not started: |
832 E5MessageBox.critical( |
836 E5MessageBox.critical( |
833 self, |
837 self, |
834 self.trUtf8("eric5 Web Browser"), |
838 self.trUtf8("eric5 Web Browser"), |
835 self.trUtf8("""<p>Could not start a viewer""" |
839 self.trUtf8( |
836 """ for file <b>{0}</b>.</p>""").format(name.path())) |
840 """<p>Could not start a viewer""" |
|
841 """ for file <b>{0}</b>.</p>""") |
|
842 .format(name.path())) |
837 return |
843 return |
838 elif name.scheme() in ["mailto"]: |
844 elif name.scheme() in ["mailto"]: |
839 started = QDesktopServices.openUrl(name) |
845 started = QDesktopServices.openUrl(name) |
840 if not started: |
846 if not started: |
841 E5MessageBox.critical( |
847 E5MessageBox.critical( |
842 self, |
848 self, |
843 self.trUtf8("eric5 Web Browser"), |
849 self.trUtf8("eric5 Web Browser"), |
844 self.trUtf8("""<p>Could not start an application""" |
850 self.trUtf8( |
845 """ for URL <b>{0}</b>.</p>""").format(name.toString())) |
851 """<p>Could not start an application""" |
|
852 """ for URL <b>{0}</b>.</p>""") |
|
853 .format(name.toString())) |
846 return |
854 return |
847 elif name.scheme() == "javascript": |
855 elif name.scheme() == "javascript": |
848 scriptSource = QUrl.fromPercentEncoding(name.toString( |
856 scriptSource = QUrl.fromPercentEncoding(name.toString( |
849 QUrl.FormattingOptions(QUrl.TolerantMode | QUrl.RemoveScheme))) |
857 QUrl.FormattingOptions(QUrl.TolerantMode | QUrl.RemoveScheme))) |
850 self.page().mainFrame().evaluateJavaScript(scriptSource) |
858 self.page().mainFrame().evaluateJavaScript(scriptSource) |
1062 menu = QMenu(self) |
1072 menu = QMenu(self) |
1063 |
1073 |
1064 frameAtPos = self.page().frameAt(evt.pos()) |
1074 frameAtPos = self.page().frameAt(evt.pos()) |
1065 hit = self.page().mainFrame().hitTestContent(evt.pos()) |
1075 hit = self.page().mainFrame().hitTestContent(evt.pos()) |
1066 if not hit.linkUrl().isEmpty(): |
1076 if not hit.linkUrl().isEmpty(): |
1067 menu.addAction(UI.PixmapCache.getIcon("openNewTab.png"), |
1077 menu.addAction( |
|
1078 UI.PixmapCache.getIcon("openNewTab.png"), |
1068 self.trUtf8("Open Link in New Tab\tCtrl+LMB"), |
1079 self.trUtf8("Open Link in New Tab\tCtrl+LMB"), |
1069 self.__openLinkInNewTab).setData(hit.linkUrl()) |
1080 self.__openLinkInNewTab).setData(hit.linkUrl()) |
1070 menu.addSeparator() |
1081 menu.addSeparator() |
1071 menu.addAction(UI.PixmapCache.getIcon("download.png"), |
1082 menu.addAction( |
|
1083 UI.PixmapCache.getIcon("download.png"), |
1072 self.trUtf8("Save Lin&k"), self.__downloadLink) |
1084 self.trUtf8("Save Lin&k"), self.__downloadLink) |
1073 menu.addAction(UI.PixmapCache.getIcon("bookmark22.png"), |
1085 menu.addAction( |
|
1086 UI.PixmapCache.getIcon("bookmark22.png"), |
1074 self.trUtf8("Bookmark this Link"), self.__bookmarkLink)\ |
1087 self.trUtf8("Bookmark this Link"), self.__bookmarkLink)\ |
1075 .setData(hit.linkUrl()) |
1088 .setData(hit.linkUrl()) |
1076 menu.addSeparator() |
1089 menu.addSeparator() |
1077 menu.addAction(UI.PixmapCache.getIcon("editCopy.png"), |
1090 menu.addAction( |
|
1091 UI.PixmapCache.getIcon("editCopy.png"), |
1078 self.trUtf8("Copy Link to Clipboard"), self.__copyLink) |
1092 self.trUtf8("Copy Link to Clipboard"), self.__copyLink) |
1079 menu.addAction( |
1093 menu.addAction( |
1080 UI.PixmapCache.getIcon("mailSend.png"), |
1094 UI.PixmapCache.getIcon("mailSend.png"), |
1081 self.trUtf8("Send Link"), |
1095 self.trUtf8("Send Link"), |
1082 self.__sendLink).setData(hit.linkUrl()) |
1096 self.__sendLink).setData(hit.linkUrl()) |
1088 self.__virusTotal).setData(hit.linkUrl()) |
1102 self.__virusTotal).setData(hit.linkUrl()) |
1089 |
1103 |
1090 if not hit.imageUrl().isEmpty(): |
1104 if not hit.imageUrl().isEmpty(): |
1091 if not menu.isEmpty(): |
1105 if not menu.isEmpty(): |
1092 menu.addSeparator() |
1106 menu.addSeparator() |
1093 menu.addAction(UI.PixmapCache.getIcon("openNewTab.png"), |
1107 menu.addAction( |
|
1108 UI.PixmapCache.getIcon("openNewTab.png"), |
1094 self.trUtf8("Open Image in New Tab"), |
1109 self.trUtf8("Open Image in New Tab"), |
1095 self.__openLinkInNewTab).setData(hit.imageUrl()) |
1110 self.__openLinkInNewTab).setData(hit.imageUrl()) |
1096 menu.addSeparator() |
1111 menu.addSeparator() |
1097 menu.addAction(UI.PixmapCache.getIcon("download.png"), |
1112 menu.addAction( |
|
1113 UI.PixmapCache.getIcon("download.png"), |
1098 self.trUtf8("Save Image"), self.__downloadImage) |
1114 self.trUtf8("Save Image"), self.__downloadImage) |
1099 menu.addAction( |
1115 menu.addAction( |
1100 self.trUtf8("Copy Image to Clipboard"), self.__copyImage) |
1116 self.trUtf8("Copy Image to Clipboard"), self.__copyImage) |
1101 menu.addAction(UI.PixmapCache.getIcon("editCopy.png"), |
1117 menu.addAction( |
|
1118 UI.PixmapCache.getIcon("editCopy.png"), |
1102 self.trUtf8("Copy Image Location to Clipboard"), |
1119 self.trUtf8("Copy Image Location to Clipboard"), |
1103 self.__copyLocation).setData(hit.imageUrl().toString()) |
1120 self.__copyLocation).setData(hit.imageUrl().toString()) |
1104 menu.addAction( |
1121 menu.addAction( |
1105 UI.PixmapCache.getIcon("mailSend.png"), |
1122 UI.PixmapCache.getIcon("mailSend.png"), |
1106 self.trUtf8("Send Image Link"), |
1123 self.trUtf8("Send Image Link"), |
1107 self.__sendLink).setData(hit.imageUrl()) |
1124 self.__sendLink).setData(hit.imageUrl()) |
1108 menu.addSeparator() |
1125 menu.addSeparator() |
1109 menu.addAction(UI.PixmapCache.getIcon("adBlockPlus.png"), |
1126 menu.addAction( |
|
1127 UI.PixmapCache.getIcon("adBlockPlus.png"), |
1110 self.trUtf8("Block Image"), self.__blockImage)\ |
1128 self.trUtf8("Block Image"), self.__blockImage)\ |
1111 .setData(hit.imageUrl().toString()) |
1129 .setData(hit.imageUrl().toString()) |
1112 if Preferences.getHelp("VirusTotalEnabled") and \ |
1130 if Preferences.getHelp("VirusTotalEnabled") and \ |
1113 Preferences.getHelp("VirusTotalServiceKey") != "": |
1131 Preferences.getHelp("VirusTotalServiceKey") != "": |
1114 menu.addAction( |
1132 menu.addAction( |
1143 else: |
1161 else: |
1144 menu.addAction( |
1162 menu.addAction( |
1145 UI.PixmapCache.getIcon("audioVolumeMuted.png"), |
1163 UI.PixmapCache.getIcon("audioVolumeMuted.png"), |
1146 self.trUtf8("Mute"), self.__muteMedia) |
1164 self.trUtf8("Mute"), self.__muteMedia) |
1147 menu.addSeparator() |
1165 menu.addSeparator() |
1148 menu.addAction(UI.PixmapCache.getIcon("editCopy.png"), |
1166 menu.addAction( |
|
1167 UI.PixmapCache.getIcon("editCopy.png"), |
1149 self.trUtf8("Copy Media Address to Clipboard"), |
1168 self.trUtf8("Copy Media Address to Clipboard"), |
1150 self.__copyLocation).setData(videoUrl.toString()) |
1169 self.__copyLocation).setData(videoUrl.toString()) |
1151 menu.addAction(UI.PixmapCache.getIcon("mailSend.png"), |
1170 menu.addAction( |
|
1171 UI.PixmapCache.getIcon("mailSend.png"), |
1152 self.trUtf8("Send Media Address"), self.__sendLink)\ |
1172 self.trUtf8("Send Media Address"), self.__sendLink)\ |
1153 .setData(videoUrl) |
1173 .setData(videoUrl) |
1154 menu.addAction(UI.PixmapCache.getIcon("download.png"), |
1174 menu.addAction( |
|
1175 UI.PixmapCache.getIcon("download.png"), |
1155 self.trUtf8("Save Media"), self.__downloadMedia)\ |
1176 self.trUtf8("Save Media"), self.__downloadMedia)\ |
1156 .setData(videoUrl) |
1177 .setData(videoUrl) |
1157 |
1178 |
1158 if element.tagName().lower() in ["input", "textarea"]: |
1179 if element.tagName().lower() in ["input", "textarea"]: |
1159 if menu.isEmpty(): |
1180 if menu.isEmpty(): |
1194 if frameAtPos and self.page().mainFrame() != frameAtPos: |
1215 if frameAtPos and self.page().mainFrame() != frameAtPos: |
1195 self.__clickedFrame = frameAtPos |
1216 self.__clickedFrame = frameAtPos |
1196 fmenu = QMenu(self.trUtf8("This Frame")) |
1217 fmenu = QMenu(self.trUtf8("This Frame")) |
1197 frameUrl = self.__clickedFrame.url() |
1218 frameUrl = self.__clickedFrame.url() |
1198 if frameUrl.isValid(): |
1219 if frameUrl.isValid(): |
1199 fmenu.addAction(self.trUtf8("Show &only this frame"), |
1220 fmenu.addAction( |
|
1221 self.trUtf8("Show &only this frame"), |
1200 self.__loadClickedFrame) |
1222 self.__loadClickedFrame) |
1201 fmenu.addAction(UI.PixmapCache.getIcon("openNewTab.png"), |
1223 fmenu.addAction( |
|
1224 UI.PixmapCache.getIcon("openNewTab.png"), |
1202 self.trUtf8("Show in new &tab"), |
1225 self.trUtf8("Show in new &tab"), |
1203 self.__openLinkInNewTab).setData(self.__clickedFrame.url()) |
1226 self.__openLinkInNewTab).setData(self.__clickedFrame.url()) |
1204 fmenu.addSeparator() |
1227 fmenu.addSeparator() |
1205 fmenu.addAction(UI.PixmapCache.getIcon("print.png"), |
1228 fmenu.addAction( |
|
1229 UI.PixmapCache.getIcon("print.png"), |
1206 self.trUtf8("&Print"), self.__printClickedFrame) |
1230 self.trUtf8("&Print"), self.__printClickedFrame) |
1207 fmenu.addAction(UI.PixmapCache.getIcon("printPreview.png"), |
1231 fmenu.addAction( |
|
1232 UI.PixmapCache.getIcon("printPreview.png"), |
1208 self.trUtf8("Print Preview"), self.__printPreviewClickedFrame) |
1233 self.trUtf8("Print Preview"), self.__printPreviewClickedFrame) |
1209 fmenu.addAction(UI.PixmapCache.getIcon("printPdf.png"), |
1234 fmenu.addAction( |
|
1235 UI.PixmapCache.getIcon("printPdf.png"), |
1210 self.trUtf8("Print as PDF"), self.__printPdfClickedFrame) |
1236 self.trUtf8("Print as PDF"), self.__printPdfClickedFrame) |
1211 fmenu.addSeparator() |
1237 fmenu.addSeparator() |
1212 fmenu.addAction(UI.PixmapCache.getIcon("zoomIn.png"), |
1238 fmenu.addAction( |
|
1239 UI.PixmapCache.getIcon("zoomIn.png"), |
1213 self.trUtf8("Zoom &in"), self.__zoomInClickedFrame) |
1240 self.trUtf8("Zoom &in"), self.__zoomInClickedFrame) |
1214 fmenu.addAction(UI.PixmapCache.getIcon("zoomReset.png"), |
1241 fmenu.addAction( |
|
1242 UI.PixmapCache.getIcon("zoomReset.png"), |
1215 self.trUtf8("Zoom &reset"), self.__zoomResetClickedFrame) |
1243 self.trUtf8("Zoom &reset"), self.__zoomResetClickedFrame) |
1216 fmenu.addAction(UI.PixmapCache.getIcon("zoomOut.png"), |
1244 fmenu.addAction( |
|
1245 UI.PixmapCache.getIcon("zoomOut.png"), |
1217 self.trUtf8("Zoom &out"), self.__zoomOutClickedFrame) |
1246 self.trUtf8("Zoom &out"), self.__zoomOutClickedFrame) |
1218 fmenu.addSeparator() |
1247 fmenu.addSeparator() |
1219 fmenu.addAction(self.trUtf8("Show frame so&urce"), |
1248 fmenu.addAction( |
|
1249 self.trUtf8("Show frame so&urce"), |
1220 self.__showClickedFrameSource) |
1250 self.__showClickedFrameSource) |
1221 |
1251 |
1222 menu.addMenu(fmenu) |
1252 menu.addMenu(fmenu) |
1223 menu.addSeparator() |
1253 menu.addSeparator() |
1224 |
1254 |
1225 menu.addAction(UI.PixmapCache.getIcon("bookmark22.png"), |
1255 menu.addAction( |
|
1256 UI.PixmapCache.getIcon("bookmark22.png"), |
1226 self.trUtf8("Bookmark this Page"), self.addBookmark) |
1257 self.trUtf8("Bookmark this Page"), self.addBookmark) |
1227 menu.addAction(UI.PixmapCache.getIcon("mailSend.png"), |
1258 menu.addAction( |
|
1259 UI.PixmapCache.getIcon("mailSend.png"), |
1228 self.trUtf8("Send Page Link"), self.__sendLink).setData(self.url()) |
1260 self.trUtf8("Send Page Link"), self.__sendLink).setData(self.url()) |
1229 menu.addSeparator() |
1261 menu.addSeparator() |
1230 self.__userAgentMenu = UserAgentMenu(self.trUtf8("User Agent"), |
1262 self.__userAgentMenu = UserAgentMenu(self.trUtf8("User Agent"), |
1231 url=self.url()) |
1263 url=self.url()) |
1232 menu.addMenu(self.__userAgentMenu) |
1264 menu.addMenu(self.__userAgentMenu) |
1262 |
1294 |
1263 menu.addSeparator() |
1295 menu.addSeparator() |
1264 |
1296 |
1265 from .HelpLanguagesDialog import HelpLanguagesDialog |
1297 from .HelpLanguagesDialog import HelpLanguagesDialog |
1266 languages = Preferences.toList( |
1298 languages = Preferences.toList( |
1267 Preferences.Prefs.settings.value("Help/AcceptLanguages", |
1299 Preferences.Prefs.settings.value( |
|
1300 "Help/AcceptLanguages", |
1268 HelpLanguagesDialog.defaultAcceptLanguages())) |
1301 HelpLanguagesDialog.defaultAcceptLanguages())) |
1269 if languages: |
1302 if languages: |
1270 language = languages[0] |
1303 language = languages[0] |
1271 langCode = language.split("[")[1][:2] |
1304 langCode = language.split("[")[1][:2] |
1272 googleTranslatorUrl = QUrl( |
1305 googleTranslatorUrl = QUrl( |
1273 "http://translate.google.com/#auto|{0}|{1}".format( |
1306 "http://translate.google.com/#auto|{0}|{1}".format( |
1274 langCode, self.selectedText())) |
1307 langCode, self.selectedText())) |
1275 menu.addAction(UI.PixmapCache.getIcon("translate.png"), |
1308 menu.addAction( |
|
1309 UI.PixmapCache.getIcon("translate.png"), |
1276 self.trUtf8("Google Translate"), self.__openLinkInNewTab)\ |
1310 self.trUtf8("Google Translate"), self.__openLinkInNewTab)\ |
1277 .setData(googleTranslatorUrl) |
1311 .setData(googleTranslatorUrl) |
1278 wiktionaryUrl = QUrl( |
1312 wiktionaryUrl = QUrl( |
1279 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" |
1313 "http://{0}.wiktionary.org/wiki/Special:Search?search={1}" |
1280 .format(langCode, self.selectedText())) |
1314 .format(langCode, self.selectedText())) |
1281 menu.addAction(UI.PixmapCache.getIcon("wikipedia.png"), |
1315 menu.addAction( |
|
1316 UI.PixmapCache.getIcon("wikipedia.png"), |
1282 self.trUtf8("Dictionary"), self.__openLinkInNewTab)\ |
1317 self.trUtf8("Dictionary"), self.__openLinkInNewTab)\ |
1283 .setData(wiktionaryUrl) |
1318 .setData(wiktionaryUrl) |
1284 menu.addSeparator() |
1319 menu.addSeparator() |
1285 |
1320 |
1286 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) |
1321 guessedUrl = QUrl.fromUserInput(self.selectedText().strip()) |
1296 element.attribute("type", "text") == "text": |
1331 element.attribute("type", "text") == "text": |
1297 menu.addAction(self.trUtf8("Add to web search toolbar"), |
1332 menu.addAction(self.trUtf8("Add to web search toolbar"), |
1298 self.__addSearchEngine).setData(element) |
1333 self.__addSearchEngine).setData(element) |
1299 menu.addSeparator() |
1334 menu.addSeparator() |
1300 |
1335 |
1301 menu.addAction(UI.PixmapCache.getIcon("webInspector.png"), |
1336 menu.addAction( |
|
1337 UI.PixmapCache.getIcon("webInspector.png"), |
1302 self.trUtf8("Web Inspector..."), self.__webInspector) |
1338 self.trUtf8("Web Inspector..."), self.__webInspector) |
1303 |
1339 |
1304 menu.exec_(evt.globalPos()) |
1340 menu.exec_(evt.globalPos()) |
1305 |
1341 |
1306 def __isUrlValid(self, url): |
1342 def __isUrlValid(self, url): |
1913 imageBuffer.open(QIODevice.ReadWrite) |
1949 imageBuffer.open(QIODevice.ReadWrite) |
1914 if pixmap.save(imageBuffer, "PNG"): |
1950 if pixmap.save(imageBuffer, "PNG"): |
1915 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) |
1951 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) |
1916 html = html.replace("@TITLE@", title.encode("utf8")) |
1952 html = html.replace("@TITLE@", title.encode("utf8")) |
1917 html = html.replace("@H1@", reply.errorString().encode("utf8")) |
1953 html = html.replace("@H1@", reply.errorString().encode("utf8")) |
1918 html = html.replace("@H2@", self.trUtf8("When connecting to: {0}.")\ |
1954 html = html.replace( |
1919 .format(urlString).encode("utf8")) |
1955 "@H2@", self.trUtf8("When connecting to: {0}.")\ |
1920 html = html.replace("@LI-1@", |
1956 .format(urlString).encode("utf8")) |
|
1957 html = html.replace( |
|
1958 "@LI-1@", |
1921 self.trUtf8("Check the address for errors such as " |
1959 self.trUtf8("Check the address for errors such as " |
1922 "<b>ww</b>.example.org instead of " |
1960 "<b>ww</b>.example.org instead of " |
1923 "<b>www</b>.example.org").encode("utf8")) |
1961 "<b>www</b>.example.org").encode("utf8")) |
1924 html = html.replace("@LI-2@", |
1962 html = html.replace( |
|
1963 "@LI-2@", |
1925 self.trUtf8("If the address is correct, try checking the network " |
1964 self.trUtf8("If the address is correct, try checking the network " |
1926 "connection.").encode("utf8")) |
1965 "connection.").encode("utf8")) |
1927 html = html.replace("@LI-3@", |
1966 html = html.replace( |
|
1967 "@LI-3@", |
1928 self.trUtf8( |
1968 self.trUtf8( |
1929 "If your computer or network is protected by a firewall " |
1969 "If your computer or network is protected by a firewall " |
1930 "or proxy, make sure that the browser is permitted to " |
1970 "or proxy, make sure that the browser is permitted to " |
1931 "access the network.").encode("utf8")) |
1971 "access the network.").encode("utf8")) |
1932 html = html.replace("@LI-4@", |
1972 html = html.replace( |
|
1973 "@LI-4@", |
1933 self.trUtf8("If your cache policy is set to offline browsing," |
1974 self.trUtf8("If your cache policy is set to offline browsing," |
1934 "only pages in the local cache are available.")\ |
1975 "only pages in the local cache are available.")\ |
1935 .encode("utf8")) |
1976 .encode("utf8")) |
1936 html = html.replace( |
1977 html = html.replace( |
1937 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |
1978 "@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |