5 |
5 |
6 """ |
6 """ |
7 Module implementing a scheme handler for the eric: scheme. |
7 Module implementing a scheme handler for the eric: scheme. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import ( |
10 from PyQt5.QtCore import pyqtSignal, QBuffer, QIODevice, QUrlQuery, QMutex |
11 pyqtSignal, QByteArray, QBuffer, QIODevice, QUrlQuery, QMutex |
|
12 ) |
|
13 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler |
11 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler |
14 |
12 |
15 from E5Gui.E5Application import e5App |
13 from E5Gui.E5Application import e5App |
16 |
14 |
17 from E5Utilities.E5MutexLocker import E5MutexLocker |
15 from E5Utilities.E5MutexLocker import E5MutexLocker |
18 |
16 |
19 from ..Tools.WebBrowserTools import ( |
17 from ..Tools.WebBrowserTools import ( |
20 getHtmlPage, getJavascript, pixmapFileToDataUrl |
18 getHtmlPage, getJavascript, pixmapFileToDataUrl |
21 ) |
19 ) |
22 |
20 |
|
21 _SupportedPages = [ |
|
22 "adblock", # error page for URLs blocked by AdBlock |
|
23 "home", "start", "startpage", # eric home page |
|
24 "speeddial", # eric speeddial |
|
25 ] |
|
26 |
23 |
27 |
24 class EricSchemeHandler(QWebEngineUrlSchemeHandler): |
28 class EricSchemeHandler(QWebEngineUrlSchemeHandler): |
25 """ |
29 """ |
26 Class implementing a scheme handler for the eric: scheme. |
30 Class implementing a scheme handler for the eric: scheme. |
27 """ |
31 """ |
28 SupportedPages = [ |
|
29 "adblock", # error page for URLs blocked by AdBlock |
|
30 "home", "start", "startpage", # eric home page |
|
31 "speeddial", # eric speeddial |
|
32 ] |
|
33 |
|
34 def __init__(self, parent=None): |
32 def __init__(self, parent=None): |
35 """ |
33 """ |
36 Constructor |
34 Constructor |
37 |
35 |
38 @param parent reference to the parent object |
36 @param parent reference to the parent object |
47 Public method handling the URL request. |
45 Public method handling the URL request. |
48 |
46 |
49 @param job URL request job |
47 @param job URL request job |
50 @type QWebEngineUrlRequestJob |
48 @type QWebEngineUrlRequestJob |
51 """ |
49 """ |
52 if job.requestUrl().path() in self.SupportedPages: |
50 reply = EricSchemeReply(job) |
53 reply = EricSchemeReply(job) |
51 reply.closed.connect(lambda: self.__replyClosed(reply)) |
54 reply.closed.connect(lambda: self.__replyClosed(reply)) |
52 self.__replies.append(reply) |
55 self.__replies.append(reply) |
53 job.reply(b"text/html", reply) |
56 job.reply(b"text/html", reply) |
|
57 else: |
|
58 job.reply(QByteArray(), QBuffer()) |
|
59 |
54 |
60 def __replyClosed(self, reply): |
55 def __replyClosed(self, reply): |
61 """ |
56 """ |
62 Private slot handling the closed signal of a reply. |
57 Private slot handling the closed signal of a reply. |
63 |
58 |
112 elif self.__pageName in ["home", "start", "startpage"]: |
107 elif self.__pageName in ["home", "start", "startpage"]: |
113 contents = self.__startPage() |
108 contents = self.__startPage() |
114 elif self.__pageName == "speeddial": |
109 elif self.__pageName == "speeddial": |
115 contents = self.__speedDialPage() |
110 contents = self.__speedDialPage() |
116 else: |
111 else: |
117 contents = "" |
112 contents = self.__errorPage() |
118 |
113 |
119 self.__buffer.setData(contents.encode("utf-8")) |
114 self.__buffer.setData(contents.encode("utf-8")) |
120 self.__buffer.open(QIODevice.ReadOnly) |
115 self.__buffer.open(QIODevice.ReadOnly) |
121 self.open(QIODevice.ReadOnly) |
116 self.open(QIODevice.ReadOnly) |
122 |
117 |
170 "@FAVICON@", pixmapFileToDataUrl("adBlockPlus16.png", True)) |
165 "@FAVICON@", pixmapFileToDataUrl("adBlockPlus16.png", True)) |
171 page = page.replace( |
166 page = page.replace( |
172 "@IMAGE@", pixmapFileToDataUrl("adBlockPlus64.png", True)) |
167 "@IMAGE@", pixmapFileToDataUrl("adBlockPlus64.png", True)) |
173 page = page.replace("@TITLE@", title) |
168 page = page.replace("@TITLE@", title) |
174 page = page.replace("@MESSAGE@", message) |
169 page = page.replace("@MESSAGE@", message) |
|
170 |
|
171 return page |
|
172 |
|
173 def __errorPage(self): |
|
174 """ |
|
175 Private method to build the Error page. |
|
176 |
|
177 @return built Error page |
|
178 @rtype str |
|
179 """ |
|
180 page = getHtmlPage("ericErrorPage.html") |
|
181 page = page.replace( |
|
182 "@FAVICON@", pixmapFileToDataUrl("ericWeb16.png", True)) |
|
183 page = page.replace( |
|
184 "@IMAGE@", pixmapFileToDataUrl("ericWeb32.png", True)) |
|
185 page = page.replace( |
|
186 "@TITLE@", self.tr("Error accessing eric: URL")) |
|
187 page = page.replace( |
|
188 "@MESSAGE@", self.tr( |
|
189 "The special URL <strong>{0}</strong> is not supported." |
|
190 " Please use one of these." |
|
191 ).format(self.__job.requestUrl().toDisplayString()) |
|
192 ) |
|
193 page = page.replace( |
|
194 "@ERICLIST@", "<br/>".join([ |
|
195 '<a href="eric:{0}">{0}</a>'.format(u) |
|
196 for u in sorted(_SupportedPages) |
|
197 ]) |
|
198 ) |
175 |
199 |
176 return page |
200 return page |
177 |
201 |
178 def __startPage(self): |
202 def __startPage(self): |
179 """ |
203 """ |