18 |
18 |
19 import Preferences |
19 import Preferences |
20 import Utilities |
20 import Utilities |
21 import UI.PixmapCache |
21 import UI.PixmapCache |
22 |
22 |
23 from DownloadDialog import DownloadDialog |
23 from .DownloadDialog import DownloadDialog |
24 from HelpWebSearchWidget import HelpWebSearchWidget |
24 from .HelpWebSearchWidget import HelpWebSearchWidget |
25 from Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
25 from .Bookmarks.AddBookmarkDialog import AddBookmarkDialog |
26 from JavaScriptResources import fetchLinks_js |
26 from .JavaScriptResources import fetchLinks_js |
27 from HTMLResources import notFoundPage_html |
27 from .HTMLResources import notFoundPage_html |
28 import Helpviewer.HelpWindow |
28 import Helpviewer.HelpWindow |
29 |
29 |
30 from Network.NetworkAccessManagerProxy import NetworkAccessManagerProxy |
30 from .Network.NetworkAccessManagerProxy import NetworkAccessManagerProxy |
31 |
31 |
32 from OpenSearch.OpenSearchEngineAction import OpenSearchEngineAction |
32 from .OpenSearch.OpenSearchEngineAction import OpenSearchEngineAction |
33 |
33 |
34 ########################################################################################## |
34 ########################################################################################## |
35 |
35 |
36 class JavaScriptExternalObject(QObject): |
36 class JavaScriptExternalObject(QObject): |
37 """ |
37 """ |
106 Public method to get the search URL for the given search term. |
106 Public method to get the search URL for the given search term. |
107 |
107 |
108 @param searchStr search term (string) |
108 @param searchStr search term (string) |
109 @return search URL (string) |
109 @return search URL (string) |
110 """ |
110 """ |
111 return unicode( |
111 return bytes( |
112 HelpWebSearchWidget.openSearchManager().currentEngine()\ |
112 HelpWebSearchWidget.openSearchManager().currentEngine()\ |
113 .searchUrl(searchStr).toEncoded()) |
113 .searchUrl(searchStr).toEncoded()).decode() |
114 |
114 |
115 ########################################################################################## |
115 ########################################################################################## |
116 |
116 |
117 class HelpWebPage(QWebPage): |
117 class HelpWebPage(QWebPage): |
118 """ |
118 """ |
499 Protected method to handle wheel events. |
499 Protected method to handle wheel events. |
500 |
500 |
501 @param evt reference to the wheel event (QWheelEvent) |
501 @param evt reference to the wheel event (QWheelEvent) |
502 """ |
502 """ |
503 if evt.modifiers() & Qt.ControlModifier: |
503 if evt.modifiers() & Qt.ControlModifier: |
504 degrees = evt.delta() / 8 |
504 degrees = evt.delta() // 8 |
505 steps = degrees / 15 |
505 steps = degrees // 15 |
506 self.__currentZoom += steps * 10 |
506 self.__currentZoom += steps * 10 |
507 self.__applyZoom() |
507 self.__applyZoom() |
508 evt.accept() |
508 evt.accept() |
509 return |
509 return |
510 |
510 |
706 def __addBookmark(self): |
706 def __addBookmark(self): |
707 """ |
707 """ |
708 Private slot to bookmark the current link. |
708 Private slot to bookmark the current link. |
709 """ |
709 """ |
710 dlg = AddBookmarkDialog() |
710 dlg = AddBookmarkDialog() |
711 dlg.setUrl(unicode(self.url().toEncoded())) |
711 dlg.setUrl(bytes(self.url().toEncoded()).decode()) |
712 dlg.setTitle(self.title()) |
712 dlg.setTitle(self.title()) |
713 dlg.exec_() |
713 dlg.exec_() |
714 |
714 |
715 def keyPressEvent(self, evt): |
715 def keyPressEvent(self, evt): |
716 """ |
716 """ |
849 if reply.error() == QNetworkReply.NoError: |
849 if reply.error() == QNetworkReply.NoError: |
850 if reply.url().isEmpty(): |
850 if reply.url().isEmpty(): |
851 return |
851 return |
852 header = reply.header(QNetworkRequest.ContentLengthHeader) |
852 header = reply.header(QNetworkRequest.ContentLengthHeader) |
853 size = header |
853 size = header |
854 if ok and size == 0: |
854 if size == 0: |
855 return |
855 return |
856 |
856 |
857 if requestFilename is None: |
857 if requestFilename is None: |
858 requestFilename = Preferences.getUI("RequestDownloadFilename") |
858 requestFilename = Preferences.getUI("RequestDownloadFilename") |
859 dlg = DownloadDialog(reply, requestFilename, self.page(), download) |
859 dlg = DownloadDialog(reply, requestFilename, self.page(), download) |
864 replyUrl = reply.url() |
864 replyUrl = reply.url() |
865 if replyUrl.isEmpty(): |
865 if replyUrl.isEmpty(): |
866 return |
866 return |
867 |
867 |
868 html = notFoundPage_html |
868 html = notFoundPage_html |
869 urlString = unicode(replyUrl.toEncoded()) |
869 urlString = bytes(replyUrl.toEncoded()).decode() |
870 title = self.trUtf8("Error loading page: {0}").format(urlString) |
870 title = self.trUtf8("Error loading page: {0}").format(urlString) |
871 pixmap = qApp.style()\ |
871 pixmap = qApp.style()\ |
872 .standardIcon(QStyle.SP_MessageBoxWarning, None, self)\ |
872 .standardIcon(QStyle.SP_MessageBoxWarning, None, self)\ |
873 .pixmap(32, 32) |
873 .pixmap(32, 32) |
874 imageBuffer = QBuffer() |
874 imageBuffer = QBuffer() |
875 imageBuffer.open(QIODevice.ReadWrite) |
875 imageBuffer.open(QIODevice.ReadWrite) |
876 if pixmap.save(imageBuffer, "PNG"): |
876 if pixmap.save(imageBuffer, "PNG"): |
877 html.replace("IMAGE_BINARY_DATA_HERE", |
877 html.replace("IMAGE_BINARY_DATA_HERE", |
878 unicode(imageBuffer.buffer().toBase64())) |
878 str(imageBuffer.buffer().toBase64())) |
879 html = html.format( |
879 html = html.format( |
880 title, |
880 title, |
881 reply.errorString(), |
881 reply.errorString(), |
882 self.trUtf8("When connecting to: {0}.").format(urlString), |
882 self.trUtf8("When connecting to: {0}.").format(urlString), |
883 self.trUtf8("Check the address for errors such as <b>ww</b>.example.org " |
883 self.trUtf8("Check the address for errors such as <b>ww</b>.example.org " |