|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a scheme access handler for Python resources. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import QFile, QByteArray |
|
13 |
|
14 import Utilities |
|
15 |
|
16 from .SchemeAccessHandler import SchemeAccessHandler |
|
17 |
|
18 |
|
19 class EricAccessHandler(SchemeAccessHandler): |
|
20 """ |
|
21 Class implementing a scheme access handler for Python resources. |
|
22 """ |
|
23 _homePage = None |
|
24 _speedDialPage = None |
|
25 |
|
26 def createRequest(self, op, request, outgoingData=None): |
|
27 """ |
|
28 Public method to create a request. |
|
29 |
|
30 @param op the operation to be performed |
|
31 (QNetworkAccessManager.Operation) |
|
32 @param request reference to the request object (QNetworkRequest) |
|
33 @param outgoingData reference to an IODevice containing data to be sent |
|
34 (QIODevice) |
|
35 @return reference to the created reply object (QNetworkReply) |
|
36 """ |
|
37 from .NetworkReply import NetworkReply |
|
38 from .NetworkProtocolUnknownErrorReply import \ |
|
39 NetworkProtocolUnknownErrorReply |
|
40 |
|
41 if request.url().toString() == "eric:home": |
|
42 return NetworkReply(request, self.__createHomePage(), |
|
43 "text/html", self.parent()) |
|
44 elif request.url().toString() == "eric:speeddial": |
|
45 return NetworkReply(request, self.__createSpeedDialPage(), |
|
46 "text/html", self.parent()) |
|
47 |
|
48 return NetworkProtocolUnknownErrorReply("eric", self.parent()) |
|
49 |
|
50 def __createHomePage(self): |
|
51 """ |
|
52 Private method to create the Home page. |
|
53 |
|
54 @return prepared home page (QByteArray) |
|
55 """ |
|
56 if self._homePage is None: |
|
57 htmlFile = QFile(":/html/startPage.html") |
|
58 htmlFile.open(QFile.ReadOnly) |
|
59 html = htmlFile.readAll() |
|
60 |
|
61 html.replace("@IMAGE@", b"qrc:icons/ericWeb32.png") |
|
62 html.replace("@FAVICON@", b"qrc:icons/ericWeb16.png") |
|
63 |
|
64 self._homePage = html |
|
65 |
|
66 return QByteArray(self._homePage) |
|
67 |
|
68 def __createSpeedDialPage(self): |
|
69 """ |
|
70 Private method to create the Speeddial page. |
|
71 |
|
72 @return prepared speeddial page (QByteArray) |
|
73 """ |
|
74 if self._speedDialPage is None: |
|
75 htmlFile = QFile(":/html/speeddialPage.html") |
|
76 htmlFile.open(QFile.ReadOnly) |
|
77 html = bytes(htmlFile.readAll()).decode() |
|
78 |
|
79 html = html.replace("@FAVICON@", "qrc:icons/ericWeb16.png") |
|
80 html = html.replace("@IMG_PLUS@", "qrc:icons/plus.png") |
|
81 html = html.replace("@IMG_CLOSE@", "qrc:icons/close.png") |
|
82 html = html.replace("@IMG_EDIT@", "qrc:icons/edit.png") |
|
83 html = html.replace("@IMG_RELOAD@", "qrc:icons/reload.png") |
|
84 html = html.replace("@IMG_SETTINGS@", "qrc:icons/setting.png") |
|
85 html = html.replace("@LOADING-IMG@", "qrc:icons/loading.gif") |
|
86 html = html.replace("@BOX-BORDER@", |
|
87 "qrc:icons/box-border-small.png") |
|
88 |
|
89 html = html.replace("@JQUERY@", "qrc:javascript/jquery.js") |
|
90 html = html.replace("@JQUERY-UI@", "qrc:javascript/jquery-ui.js") |
|
91 |
|
92 html = html.replace("@SITE-TITLE@", self.tr("Speed Dial")) |
|
93 html = html.replace("@URL@", self.tr("URL")) |
|
94 html = html.replace("@TITLE@", self.tr("Title")) |
|
95 html = html.replace("@APPLY@", self.tr("Apply")) |
|
96 html = html.replace("@CLOSE@", self.tr("Close")) |
|
97 html = html.replace("@NEW-PAGE@", self.tr("New Page")) |
|
98 html = html.replace("@TITLE-EDIT@", self.tr("Edit")) |
|
99 html = html.replace("@TITLE-REMOVE@", self.tr("Remove")) |
|
100 html = html.replace("@TITLE-RELOAD@", self.tr("Reload")) |
|
101 html = html.replace("@TITLE-WARN@", |
|
102 self.tr("Are you sure to remove this" |
|
103 " speed dial?")) |
|
104 html = html.replace("@TITLE-WARN-REL@", |
|
105 self.tr("Are you sure you want to reload" |
|
106 " all speed dials?")) |
|
107 html = html.replace("@TITLE-FETCHTITLE@", |
|
108 self.tr("Load title from page")) |
|
109 html = html.replace("@SETTINGS-TITLE@", |
|
110 self.tr("Speed Dial Settings")) |
|
111 html = html.replace("@ADD-TITLE@", self.tr("Add New Page")) |
|
112 html = html.replace("@TXT_NRROWS@", |
|
113 self.tr("Maximum pages in a row:")) |
|
114 html = html.replace("@TXT_SDSIZE@", |
|
115 self.tr("Change size of pages:")) |
|
116 |
|
117 self._speedDialPage = Utilities.html_uencode(html) |
|
118 |
|
119 import Helpviewer.HelpWindow |
|
120 html = QByteArray(self._speedDialPage.encode("utf-8")) |
|
121 dial = Helpviewer.HelpWindow.HelpWindow.speedDial() |
|
122 |
|
123 html.replace("@INITIAL-SCRIPT@", dial.initialScript().encode("utf-8")) |
|
124 html.replace("@ROW-PAGES@", str(dial.pagesInRow()).encode("utf-8")) |
|
125 html.replace("@SD-SIZE@", str(dial.sdSize()).encode("utf-8")) |
|
126 |
|
127 return html |