WebBrowser/Network/EricSchemeHandler.py

Sun, 11 Feb 2018 16:04:47 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Feb 2018 16:04:47 +0100
changeset 6134
cb0985e8da91
parent 6127
128d9567a533
child 6507
54054456ca58
permissions
-rw-r--r--

Introduced a navigation bar button to open the downloads manager window.

4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6048
82ad8ec9548c Updated copyright for 2018.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5664
diff changeset
3 # Copyright (c) 2016 - 2018 Detlev Offenbach <detlev@die-offenbachs.de>
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a scheme handler for the eric: scheme.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
12 from PyQt5.QtCore import pyqtSignal, QByteArray, QBuffer, QIODevice, \
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
13 QTextStream, QUrlQuery
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
14 from PyQt5.QtWidgets import qApp
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from ..Tools.WebBrowserTools import readAllFileContents
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4885
diff changeset
19
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class EricSchemeHandler(QWebEngineUrlSchemeHandler):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing a scheme handler for the eric: scheme.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 SupportedPages = [
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 "adblock", # error page for URLs blocked by AdBlock
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
26 "home", "start", "startpage", # eric home page
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
27 "speeddial", # eric speeddial
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ]
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def __init__(self, parent=None):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param parent reference to the parent object
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type QObject
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 super(EricSchemeHandler, self).__init__(parent)
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
38
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
39 self.__replies = []
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 def requestStarted(self, job):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 Public method handling the URL request.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param job URL request job
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @type QWebEngineUrlRequestJob
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 if job.requestUrl().path() in self.SupportedPages:
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
49 reply = EricSchemeReply(job)
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 reply.closed.connect(lambda: self.__replyClosed(reply))
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
51 self.__replies.append(reply)
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
52 job.reply(b"text/html", reply)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 else:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 job.reply(QByteArray(), QBuffer())
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 # job.fail(QWebEngineUrlRequestJob.UrlNotFound)
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
56
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 def __replyClosed(self, reply):
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
58 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
59 Private slot handling the closed signal of a reply.
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
61 @param reply reference to the network reply
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
62 @type EricSchemeReply
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
63 """
6120
4c60a21ce6dd Continued removing the use of QObject.sender().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
64 if reply in self.__replies:
5605
1950fe1a32c4 Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
65 self.__replies.remove(reply)
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 class EricSchemeReply(QIODevice):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Class implementing a reply for a requested eric: page.
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
71
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
72 @signal closed emitted to signal that the web engine has read
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
73 the data
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
75 closed = pyqtSignal()
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
76
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
77 _speedDialPage = ""
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
78
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def __init__(self, job, parent=None):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Constructor
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param job reference to the URL request
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @type QWebEngineUrlRequestJob
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @param parent reference to the parent object
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @type QObject
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 super(EricSchemeReply, self).__init__(parent)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.__loaded = False
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__job = job
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__pageName = self.__job.requestUrl().path()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 self.__buffer = QBuffer()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.open(QIODevice.ReadOnly)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__buffer.open(QIODevice.ReadWrite)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__loadPage()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def __loadPage(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Private method to load the requested page.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 if self.__loaded:
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 return
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 stream = QTextStream(self.__buffer)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 stream.setCodec("utf-8")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 if self.__pageName == "adblock":
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 stream << self.__adBlockPage()
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
112 elif self.__pageName in ["home", "start", "startpage"]:
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
113 stream << self.__startPage()
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
114 elif self.__pageName == "speeddial":
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
115 stream << self.__speedDialPage()
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 stream.flush()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.__buffer.reset()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__loaded = True
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 def bytesAvailable(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 Public method to get the number of available bytes.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @return number of available bytes
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @rtype int
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 return self.__buffer.bytesAvailable()
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def readData(self, maxlen):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Public method to retrieve data from the reply object.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @param maxlen maximum number of bytes to read (integer)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @return string containing the data (bytes)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 return self.__buffer.read(maxlen)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
4859
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
139 def close(self):
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
140 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
141 Public method used to cloase the reply.
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
142 """
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
143 super(EricSchemeReply, self).close()
36c4b21c9f7b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4858
diff changeset
144 self.closed.emit()
4858
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def __adBlockPage(self):
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Private method to build the AdBlock page.
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 @return built AdBlock page
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @rtype str
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 query = QUrlQuery(self.__job.requestUrl())
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 rule = query.queryItemValue("rule")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 subscription = query.queryItemValue("subscription")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 title = self.tr("Content blocked by AdBlock Plus")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 message = self.tr(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 "Blocked by rule: <i>{0} ({1})</i>").format(rule, subscription)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 page = readAllFileContents(":/html/adblockPage.html")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 page = page.replace(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 "@FAVICON@", "qrc:icons/adBlockPlus16.png")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 page = page.replace(
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 "@IMAGE@", "qrc:icons/adBlockPlus64.png")
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 page = page.replace("@TITLE@", title)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 page = page.replace("@MESSAGE@", message)
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
19dff9c9cf26 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 return page
4861
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
169
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
170 def __startPage(self):
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
171 """
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
172 Private method to build the Start page.
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
173
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
174 @return built Start page
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
175 @rtype str
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
176 """
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
177 page = readAllFileContents(":/html/startPage.html")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
178 page = page.replace("@FAVICON@", "qrc:icons/ericWeb16.png")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
179 page = page.replace("@IMAGE@", "qrc:icons/ericWeb32.png")
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
180 page = page.replace("@TITLE@",
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
181 self.tr("Welcome to eric6 Web Browser!"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
182 page = page.replace("@ERIC_LINK@", self.tr("About eric6"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
183 page = page.replace("@HEADER_TITLE@", self.tr("eric6 Web Browser"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
184 page = page.replace("@SUBMIT@", self.tr("Search!"))
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
185 if qApp.isLeftToRight():
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
186 ltr = "LTR"
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
187 else:
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
188 ltr = "RTL"
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
189 page = page.replace("@QT_LAYOUT_DIRECTION@", ltr)
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
190
d419f153925d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4859
diff changeset
191 return page
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
192
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
193 def __speedDialPage(self):
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
194 """
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
195 Private method to create the Speeddial page.
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
196
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
197 @return prepared speeddial page (QByteArray)
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
198 """
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
199 if not self._speedDialPage:
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
200 page = readAllFileContents(":/html/speeddialPage.html")
5664
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
201 page = page.replace("@FAVICON@", "qrc:icons/ericWeb16.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
202 page = page.replace("@IMG_PLUS@", "qrc:icons/plus.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
203 page = page.replace("@IMG_CLOSE@", "qrc:icons/close.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
204 page = page.replace("@IMG_EDIT@", "qrc:icons/edit.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
205 page = page.replace("@IMG_RELOAD@", "qrc:icons/reload.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
206 page = page.replace("@IMG_SETTINGS@", "qrc:icons/setting.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
207 page = page.replace("@LOADING-IMG@", "qrc:icons/loading.gif")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
208 page = page.replace("@BOX-BORDER@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
209 "qrc:icons/box-border-small.png")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
210
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
211 page = page.replace("@JQUERY@", "qrc:javascript/jquery.js")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
212 page = page.replace("@JQUERY-UI@", "qrc:javascript/jquery-ui.js")
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
213
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
214 page = page.replace("@SITE-TITLE@", self.tr("Speed Dial"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
215 page = page.replace("@URL@", self.tr("URL"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
216 page = page.replace("@TITLE@", self.tr("Title"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
217 page = page.replace("@APPLY@", self.tr("Apply"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
218 page = page.replace("@CLOSE@", self.tr("Close"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
219 page = page.replace("@NEW-PAGE@", self.tr("New Page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
220 page = page.replace("@TITLE-EDIT@", self.tr("Edit"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
221 page = page.replace("@TITLE-REMOVE@", self.tr("Remove"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
222 page = page.replace("@TITLE-RELOAD@", self.tr("Reload"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
223 page = page.replace("@TITLE-WARN@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
224 self.tr("Are you sure to remove this"
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
225 " speed dial?"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
226 page = page.replace("@TITLE-WARN-REL@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
227 self.tr("Are you sure you want to reload"
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
228 " all speed dials?"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
229 page = page.replace("@TITLE-FETCHTITLE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
230 self.tr("Load title from page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
231 page = page.replace("@SETTINGS-TITLE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
232 self.tr("Speed Dial Settings"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
233 page = page.replace("@ADD-TITLE@", self.tr("Add New Page"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
234 page = page.replace("@TXT_NRROWS@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
235 self.tr("Maximum pages in a row:"))
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
236 page = page.replace("@TXT_SDSIZE@",
9b318fcb1ee2 Removed some code complexity issues detected by the new complexity checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5605
diff changeset
237 self.tr("Change size of pages:"))
6127
128d9567a533 Some improvements of the Web Browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6120
diff changeset
238 page = page.replace("@JAVASCRIPT_DISABLED@",
6134
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
239 self.tr("SpeedDial requires enabled"
cb0985e8da91 Introduced a navigation bar button to open the downloads manager window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6127
diff changeset
240 " JavaScript."))
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
241
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
242 self._speedDialPage = page
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
243
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
244 from WebBrowser.WebBrowserWindow import WebBrowserWindow
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
245 dial = WebBrowserWindow.speedDial()
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
246 page = (
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
247 self._speedDialPage
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
248 .replace("@INITIAL-SCRIPT@", dial.initialScript())
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
249 .replace("@ROW-PAGES@", str(dial.pagesInRow()))
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
250 .replace("@SD-SIZE@", str(dial.sdSize()))
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
251 )
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
252
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4861
diff changeset
253 return page

eric ide

mercurial