eric6/Helpviewer/AdBlock/AdBlockAccessHandler.py

branch
maintenance
changeset 7286
7eb04391adf7
parent 7226
babe80d84a3e
parent 7285
1ff497f33f31
child 7287
1c17f2191bdd
equal deleted inserted replaced
7226:babe80d84a3e 7286:7eb04391adf7
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 AdBlock URLs.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import QByteArray
13 from PyQt5.QtNetwork import QNetworkAccessManager
14
15 from E5Gui import E5MessageBox
16
17 from Helpviewer.Network.SchemeAccessHandler import SchemeAccessHandler
18 from Helpviewer.Network.EmptyNetworkReply import EmptyNetworkReply
19
20 from Globals import qVersionTuple
21
22
23 class AdBlockAccessHandler(SchemeAccessHandler):
24 """
25 Class implementing a scheme access handler for AdBlock URLs.
26 """
27 def createRequest(self, op, request, outgoingData=None):
28 """
29 Public method to create a request.
30
31 @param op the operation to be performed
32 (QNetworkAccessManager.Operation)
33 @param request reference to the request object (QNetworkRequest)
34 @param outgoingData reference to an IODevice containing data to be sent
35 (QIODevice)
36 @return reference to the created reply object (QNetworkReply)
37 """
38 if op != QNetworkAccessManager.GetOperation:
39 return None
40
41 url = request.url()
42 if url.path() != "subscribe":
43 return None
44
45 if qVersionTuple() >= (5, 0, 0):
46 from PyQt5.QtCore import QUrlQuery, QUrl
47 title = QUrl.fromPercentEncoding(
48 QByteArray(QUrlQuery(url).queryItemValue("title").encode()))
49 else:
50 from PyQt5.QtCore import QUrl
51 title = QUrl.fromPercentEncoding(
52 url.encodedQueryItemValue(b"title"))
53 if not title:
54 return None
55 res = E5MessageBox.yesNo(
56 None,
57 self.tr("Subscribe?"),
58 self.tr(
59 """<p>Subscribe to this AdBlock subscription?</p>"""
60 """<p>{0}</p>""").format(title))
61 if res:
62 from .AdBlockSubscription import AdBlockSubscription
63 import Helpviewer.HelpWindow
64
65 dlg = Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
66 .showDialog()
67 subscription = AdBlockSubscription(
68 url, False,
69 Helpviewer.HelpWindow.HelpWindow.adBlockManager())
70 Helpviewer.HelpWindow.HelpWindow.adBlockManager()\
71 .addSubscription(subscription)
72 dlg.addSubscription(subscription, False)
73 dlg.setFocus()
74 dlg.raise_()
75
76 return EmptyNetworkReply(self.parent())

eric ide

mercurial