7 """ |
7 """ |
8 Module implementing the helpbrowser using QWebView. |
8 Module implementing the helpbrowser using QWebView. |
9 """ |
9 """ |
10 |
10 |
11 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, QUrl, \ |
11 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QObject, QT_TRANSLATE_NOOP, QUrl, \ |
12 QBuffer, QIODevice, QByteArray, QFileInfo, Qt, QTimer, QEvent, QRect |
12 QBuffer, QIODevice, QFileInfo, Qt, QTimer, QEvent, QRect, QFile |
13 from PyQt4.QtGui import qApp, QDesktopServices, QStyle, QMenu, QApplication, \ |
13 from PyQt4.QtGui import qApp, QDesktopServices, QStyle, QMenu, QApplication, \ |
14 QInputDialog, QLineEdit, QClipboard, QMouseEvent, QLabel, QToolTip, QColor, \ |
14 QInputDialog, QLineEdit, QClipboard, QMouseEvent, QLabel, QToolTip, QColor, \ |
15 QPalette, QFrame, QPrinter, QPrintDialog, QDialog |
15 QPalette, QFrame, QPrinter, QPrintDialog, QDialog |
16 from PyQt4 import QtWebKit |
16 from PyQt4 import QtWebKit |
17 from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings |
17 from PyQt4.QtWebKit import QWebView, QWebPage, QWebSettings |
280 element.setAttribute("style", "display:none;") |
279 element.setAttribute("style", "display:none;") |
281 return False |
280 return False |
282 else: |
281 else: |
283 # the whole page is blocked |
282 # the whole page is blocked |
284 rule = info.errorString.replace("AdBlockRule:", "") |
283 rule = info.errorString.replace("AdBlockRule:", "") |
285 html = adblockPage_html |
|
286 title = self.trUtf8("Content blocked by AdBlock Plus") |
284 title = self.trUtf8("Content blocked by AdBlock Plus") |
287 pixmap = UI.PixmapCache.getPixmap("adBlockPlus16.png") |
285 message = self.trUtf8("Blocked by rule: <i>{0}</i>").format(rule) |
288 imageBuffer = QBuffer() |
286 |
289 imageBuffer.open(QIODevice.ReadWrite) |
287 htmlFile = QFile(":/html/adblockPage.html") |
290 if pixmap.save(imageBuffer, "PNG"): |
288 htmlFile.open(QFile.ReadOnly) |
291 html = html.replace("@FAVICON@", |
289 html = htmlFile.readAll() |
292 str(imageBuffer.buffer().toBase64(), |
290 html = html.replace("@FAVICON@", "qrc:icons/adBlockPlus16.png") |
293 encoding="ascii")) |
291 html = html.replace("@IMAGE@", "qrc:icons/adBlockPlus64.png") |
294 pixmap = UI.PixmapCache.getPixmap("adBlockPlus64.png") |
292 html = html.replace("@TITLE@", title.encode("utf8")) |
295 imageBuffer = QBuffer() |
293 html = html.replace("@MESSAGE@", message.encode("utf8")) |
296 imageBuffer.open(QIODevice.ReadWrite) |
294 errorPage.content = html |
297 if pixmap.save(imageBuffer, "PNG"): |
|
298 html = html.replace("@IMAGE@", |
|
299 str(imageBuffer.buffer().toBase64(), |
|
300 encoding="ascii")) |
|
301 errorPage.content = QByteArray(html.format( |
|
302 title, |
|
303 self.trUtf8("Blocked by rule: <i>{0}</i>").format(rule) |
|
304 ).encode("utf8")) |
|
305 return True |
295 return True |
306 |
296 |
307 html = notFoundPage_html |
|
308 title = self.trUtf8("Error loading page: {0}").format(urlString) |
297 title = self.trUtf8("Error loading page: {0}").format(urlString) |
|
298 htmlFile = QFile(":/html/notFoundPage.html") |
|
299 htmlFile.open(QFile.ReadOnly) |
|
300 html = htmlFile.readAll() |
309 pixmap = qApp.style()\ |
301 pixmap = qApp.style()\ |
310 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
302 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
311 .pixmap(48, 48) |
303 .pixmap(48, 48) |
312 imageBuffer = QBuffer() |
304 imageBuffer = QBuffer() |
313 imageBuffer.open(QIODevice.ReadWrite) |
305 imageBuffer.open(QIODevice.ReadWrite) |
314 if pixmap.save(imageBuffer, "PNG"): |
306 if pixmap.save(imageBuffer, "PNG"): |
315 html = html.replace("@IMAGE@", |
307 html = html.replace("@IMAGE@", imageBuffer.buffer().toBase64()) |
316 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
|
317 pixmap = qApp.style()\ |
308 pixmap = qApp.style()\ |
318 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
309 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
319 .pixmap(16, 16) |
310 .pixmap(16, 16) |
320 imageBuffer = QBuffer() |
311 imageBuffer = QBuffer() |
321 imageBuffer.open(QIODevice.ReadWrite) |
312 imageBuffer.open(QIODevice.ReadWrite) |
322 if pixmap.save(imageBuffer, "PNG"): |
313 if pixmap.save(imageBuffer, "PNG"): |
323 html = html.replace("@FAVICON@", |
314 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) |
324 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
315 html = html.replace("@TITLE@", title.encode("utf8")) |
325 errorPage.content = QByteArray(html.format( |
316 html = html.replace("@H1@", info.errorString.encode("utf8")) |
326 title, |
317 html = html.replace("@H2@", self.trUtf8("When connecting to: {0}.")\ |
327 info.errorString, |
318 .format(urlString).encode("utf8")) |
328 self.trUtf8("When connecting to: {0}.").format(urlString), |
319 html = html.replace("@LI-1@", |
329 self.trUtf8("Check the address for errors such as " |
320 self.trUtf8("Check the address for errors such as " |
330 "<b>ww</b>.example.org instead of " |
321 "<b>ww</b>.example.org instead of " |
331 "<b>www</b>.example.org"), |
322 "<b>www</b>.example.org").encode("utf8")) |
|
323 html = html.replace("@LI-2@", |
332 self.trUtf8("If the address is correct, try checking the network " |
324 self.trUtf8("If the address is correct, try checking the network " |
333 "connection."), |
325 "connection.").encode("utf8")) |
|
326 html = html.replace("@LI-3@", |
334 self.trUtf8("If your computer or network is protected by a firewall " |
327 self.trUtf8("If your computer or network is protected by a firewall " |
335 "or proxy, make sure that the browser is permitted to " |
328 "or proxy, make sure that the browser is permitted to " |
336 "access the network."), |
329 "access the network.").encode("utf8")) |
|
330 html = html.replace("@LI-4@", |
337 self.trUtf8("If your cache policy is set to offline browsing," |
331 self.trUtf8("If your cache policy is set to offline browsing," |
338 "only pages in the local cache are available."), |
332 "only pages in the local cache are available.")\ |
339 self.trUtf8("Try Again") |
333 .encode("utf8")) |
340 ).encode("utf8")) |
334 html = html.replace("@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |
|
335 errorPage.content = html |
341 return True |
336 return True |
342 except AttributeError: |
337 except AttributeError: |
343 pass |
338 pass |
344 |
339 |
345 return QWebPage.extension(self, extension, option, output) |
340 return QWebPage.extension(self, extension, option, output) |
1609 data = reply.readAll() |
1604 data = reply.readAll() |
1610 if contentSniff(data): |
1605 if contentSniff(data): |
1611 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl) |
1606 notFoundFrame.setHtml(str(data, encoding="utf-8"), replyUrl) |
1612 return |
1607 return |
1613 |
1608 |
1614 html = notFoundPage_html |
|
1615 urlString = bytes(replyUrl.toEncoded()).decode() |
1609 urlString = bytes(replyUrl.toEncoded()).decode() |
1616 title = self.trUtf8("Error loading page: {0}").format(urlString) |
1610 title = self.trUtf8("Error loading page: {0}").format(urlString) |
|
1611 htmlFile = QFile(":/html/notFoundPage.html") |
|
1612 htmlFile.open(QFile.ReadOnly) |
|
1613 html = htmlFile.readAll() |
1617 pixmap = qApp.style()\ |
1614 pixmap = qApp.style()\ |
1618 .standardIcon(QStyle.SP_MessageBoxWarning, None, self)\ |
1615 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
1619 .pixmap(32, 32) |
1616 .pixmap(48, 48) |
1620 imageBuffer = QBuffer() |
1617 imageBuffer = QBuffer() |
1621 imageBuffer.open(QIODevice.ReadWrite) |
1618 imageBuffer.open(QIODevice.ReadWrite) |
1622 if pixmap.save(imageBuffer, "PNG"): |
1619 if pixmap.save(imageBuffer, "PNG"): |
1623 html = html.replace("IMAGE_BINARY_DATA_HERE", |
1620 html = html.replace("@IMAGE@", imageBuffer.buffer().toBase64()) |
1624 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
1621 pixmap = qApp.style()\ |
1625 html = html.format( |
1622 .standardIcon(QStyle.SP_MessageBoxWarning, None, self.parent())\ |
1626 title, |
1623 .pixmap(16, 16) |
1627 reply.errorString(), |
1624 imageBuffer = QBuffer() |
1628 self.trUtf8("When connecting to: {0}.").format(urlString), |
1625 imageBuffer.open(QIODevice.ReadWrite) |
1629 self.trUtf8("Check the address for errors such as <b>ww</b>.example.org " |
1626 if pixmap.save(imageBuffer, "PNG"): |
1630 "instead of <b>www</b>.example.org"), |
1627 html = html.replace("@FAVICON@", imageBuffer.buffer().toBase64()) |
|
1628 html = html.replace("@TITLE@", title.encode("utf8")) |
|
1629 html = html.replace("@H1@", reply.errorString().encode("utf8")) |
|
1630 html = html.replace("@H2@", self.trUtf8("When connecting to: {0}.")\ |
|
1631 .format(urlString).encode("utf8")) |
|
1632 html = html.replace("@LI-1@", |
|
1633 self.trUtf8("Check the address for errors such as " |
|
1634 "<b>ww</b>.example.org instead of " |
|
1635 "<b>www</b>.example.org").encode("utf8")) |
|
1636 html = html.replace("@LI-2@", |
1631 self.trUtf8("If the address is correct, try checking the network " |
1637 self.trUtf8("If the address is correct, try checking the network " |
1632 "connection."), |
1638 "connection.").encode("utf8")) |
1633 self.trUtf8("If your computer or network is protected by a firewall or " |
1639 html = html.replace("@LI-3@", |
1634 "proxy, make sure that the browser is permitted to access " |
1640 self.trUtf8("If your computer or network is protected by a firewall " |
1635 "the network."), |
1641 "or proxy, make sure that the browser is permitted to " |
|
1642 "access the network.").encode("utf8")) |
|
1643 html = html.replace("@LI-4@", |
1636 self.trUtf8("If your cache policy is set to offline browsing," |
1644 self.trUtf8("If your cache policy is set to offline browsing," |
1637 "only pages in the local cache are available."), |
1645 "only pages in the local cache are available.")\ |
1638 self.trUtf8("Try Again") |
1646 .encode("utf8")) |
1639 ) |
1647 html = html.replace("@BUTTON@", self.trUtf8("Try Again").encode("utf8")) |
1640 notFoundFrame.setHtml(html, replyUrl) |
1648 notFoundFrame.setHtml(bytes(html).decode("utf8"), replyUrl) |
1641 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title()) |
1649 self.mw.historyManager().removeHistoryEntry(replyUrl, self.title()) |
1642 self.loadFinished.emit(False) |
1650 self.loadFinished.emit(False) |
1643 |
1651 |
1644 def __downloadRequested(self, request): |
1652 def __downloadRequested(self, request): |
1645 """ |
1653 """ |