10 import os |
10 import os |
11 |
11 |
12 from PyQt4.QtCore import * |
12 from PyQt4.QtCore import * |
13 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
13 from PyQt4.QtNetwork import QNetworkRequest, QNetworkReply |
14 from PyQt4.QtGui import QMessageBox |
14 from PyQt4.QtGui import QMessageBox |
|
15 |
|
16 from E5Gui import E5MessageBox |
15 |
17 |
16 from .AdBlockRule import AdBlockRule |
18 from .AdBlockRule import AdBlockRule |
17 |
19 |
18 import Helpviewer.HelpWindow |
20 import Helpviewer.HelpWindow |
19 |
21 |
197 """ |
199 """ |
198 fileName = self.rulesFileName() |
200 fileName = self.rulesFileName() |
199 f = QFile(fileName) |
201 f = QFile(fileName) |
200 if f.exists(): |
202 if f.exists(): |
201 if not f.open(QIODevice.ReadOnly): |
203 if not f.open(QIODevice.ReadOnly): |
202 QMessageBox.warning(None, |
204 E5MessageBox.warning(None, |
203 self.trUtf8("Load subscription rules"), |
205 self.trUtf8("Load subscription rules"), |
204 self.trUtf8("""Unable to open adblock file '{0}' for reading.""")\ |
206 self.trUtf8("""Unable to open adblock file '{0}' for reading.""")\ |
205 .format(fileName)) |
207 .format(fileName)) |
206 else: |
208 else: |
207 textStream = QTextStream(f) |
209 textStream = QTextStream(f) |
208 header = textStream.readLine(1024) |
210 header = textStream.readLine(1024) |
209 if not header.startswith("[Adblock"): |
211 if not header.startswith("[Adblock"): |
210 QMessageBox.warning(None, |
212 E5MessageBox.warning(None, |
211 self.trUtf8("Load subscription rules"), |
213 self.trUtf8("Load subscription rules"), |
212 self.trUtf8("""Adblock file '{0}' does not start""" |
214 self.trUtf8("""Adblock file '{0}' does not start""" |
213 """ with [Adblock.""")\ |
215 """ with [Adblock.""")\ |
214 .format(fileName)) |
216 .format(fileName)) |
215 f.close() |
217 f.close() |
258 redirect = reply.attribute(QNetworkRequest.RedirectionTargetAttribute) or QUrl() |
260 redirect = reply.attribute(QNetworkRequest.RedirectionTargetAttribute) or QUrl() |
259 reply.close() |
261 reply.close() |
260 self.__downloading = None |
262 self.__downloading = None |
261 |
263 |
262 if reply.error() != QNetworkReply.NoError: |
264 if reply.error() != QNetworkReply.NoError: |
263 QMessageBox.warning(None, |
265 E5MessageBox.warning(None, |
264 self.trUtf8("Downloading subscription rules"), |
266 self.trUtf8("Downloading subscription rules"), |
265 self.trUtf8("""<p>Subscription rules could not be downloaded.</p>""" |
267 self.trUtf8("""<p>Subscription rules could not be downloaded.</p>""" |
266 """<p>Error: {0}</p>""").format(reply.errorString())) |
268 """<p>Error: {0}</p>""").format(reply.errorString())) |
267 return |
269 return |
268 |
270 |
272 Helpviewer.HelpWindow.HelpWindow.networkAccessManager().get(request) |
274 Helpviewer.HelpWindow.HelpWindow.networkAccessManager().get(request) |
273 self.__downloading.finished[()].connect(self.__rulesDownloaded) |
275 self.__downloading.finished[()].connect(self.__rulesDownloaded) |
274 return |
276 return |
275 |
277 |
276 if response.isEmpty(): |
278 if response.isEmpty(): |
277 QMessageBox.warning(None, |
279 E5MessageBox.warning(None, |
278 self.trUtf8("Downloading subscription rules"), |
280 self.trUtf8("Downloading subscription rules"), |
279 self.trUtf8("""Got empty subscription rules.""")) |
281 self.trUtf8("""Got empty subscription rules.""")) |
280 return |
282 return |
281 |
283 |
282 fileName = self.rulesFileName() |
284 fileName = self.rulesFileName() |
283 f = QFile(fileName) |
285 f = QFile(fileName) |
284 if not f.open(QIODevice.ReadWrite): |
286 if not f.open(QIODevice.ReadWrite): |
285 QMessageBox.warning(None, |
287 E5MessageBox.warning(None, |
286 self.trUtf8("Downloading subscription rules"), |
288 self.trUtf8("Downloading subscription rules"), |
287 self.trUtf8("""Unable to open adblock file '{0}' for writing.""")\ |
289 self.trUtf8("""Unable to open adblock file '{0}' for writing.""")\ |
288 .file(fileName)) |
290 .file(fileName)) |
289 return |
291 return |
290 f.write(response) |
292 f.write(response) |
301 if not fileName: |
303 if not fileName: |
302 return |
304 return |
303 |
305 |
304 f = QFile(fileName) |
306 f = QFile(fileName) |
305 if not f.open(QIODevice.ReadWrite | QIODevice.Truncate): |
307 if not f.open(QIODevice.ReadWrite | QIODevice.Truncate): |
306 QMessageBox.warning(None, |
308 E5MessageBox.warning(None, |
307 self.trUtf8("Saving subscription rules"), |
309 self.trUtf8("Saving subscription rules"), |
308 self.trUtf8("""Unable to open adblock file '{0}' for writing.""")\ |
310 self.trUtf8("""Unable to open adblock file '{0}' for writing.""")\ |
309 .format(fileName)) |
311 .format(fileName)) |
310 return |
312 return |
311 |
313 |