Helpviewer/AdBlock/AdBlockSubscription.py

changeset 3035
36e9f388958b
parent 3034
7ce719013078
child 3060
5883ce99ee12
child 3160
209a07d7e401
equal deleted inserted replaced
3034:7ce719013078 3035:36e9f388958b
268 E5MessageBox.warning( 268 E5MessageBox.warning(
269 None, 269 None,
270 self.trUtf8("Load subscription rules"), 270 self.trUtf8("Load subscription rules"),
271 self.trUtf8( 271 self.trUtf8(
272 """Unable to open adblock file '{0}' for reading.""") 272 """Unable to open adblock file '{0}' for reading.""")
273 .format(fileName)) 273 .format(fileName))
274 else: 274 else:
275 textStream = QTextStream(f) 275 textStream = QTextStream(f)
276 header = textStream.readLine(1024) 276 header = textStream.readLine(1024)
277 if not header.startswith("[Adblock"): 277 if not header.startswith("[Adblock"):
278 E5MessageBox.warning( 278 E5MessageBox.warning(
279 None, 279 None,
280 self.trUtf8("Load subscription rules"), 280 self.trUtf8("Load subscription rules"),
281 self.trUtf8("""AdBlock file '{0}' does not start""" 281 self.trUtf8("""AdBlock file '{0}' does not start"""
282 """ with [Adblock.""") 282 """ with [Adblock.""")
283 .format(fileName)) 283 .format(fileName))
284 f.close() 284 f.close()
285 f.remove() 285 f.remove()
286 self.__lastUpdate = QDateTime() 286 self.__lastUpdate = QDateTime()
287 else: 287 else:
288 from .AdBlockRule import AdBlockRule 288 from .AdBlockRule import AdBlockRule
377 None, 377 None,
378 self.trUtf8("Downloading subscription rules"), 378 self.trUtf8("Downloading subscription rules"),
379 self.trUtf8( 379 self.trUtf8(
380 """<p>Subscription rules could not be""" 380 """<p>Subscription rules could not be"""
381 """ downloaded.</p><p>Error: {0}</p>""") 381 """ downloaded.</p><p>Error: {0}</p>""")
382 .format(reply.errorString())) 382 .format(reply.errorString()))
383 else: 383 else:
384 # reset after first download attempt 384 # reset after first download attempt
385 self.__defaultSubscription = False 385 self.__defaultSubscription = False
386 return 386 return
387 387
399 E5MessageBox.warning( 399 E5MessageBox.warning(
400 None, 400 None,
401 self.trUtf8("Downloading subscription rules"), 401 self.trUtf8("Downloading subscription rules"),
402 self.trUtf8( 402 self.trUtf8(
403 """Unable to open adblock file '{0}' for writing.""") 403 """Unable to open adblock file '{0}' for writing.""")
404 .file(fileName)) 404 .file(fileName))
405 return 405 return
406 f.write(response) 406 f.write(response)
407 f.close() 407 f.close()
408 self.__lastUpdate = QDateTime.currentDateTime() 408 self.__lastUpdate = QDateTime.currentDateTime()
409 if self.__validateCheckSum(fileName): 409 if self.__validateCheckSum(fileName):
455 """<p>AdBlock subscription <b>{0}</b> has a wrong""" 455 """<p>AdBlock subscription <b>{0}</b> has a wrong"""
456 """ checksum.<br/>""" 456 """ checksum.<br/>"""
457 """Found: {1}<br/>""" 457 """Found: {1}<br/>"""
458 """Calculated: {2}<br/>""" 458 """Calculated: {2}<br/>"""
459 """Use it anyway?</p>""") 459 """Use it anyway?</p>""")
460 .format(self.__title, expectedChecksum, 460 .format(self.__title, expectedChecksum,
461 calculatedChecksum)) 461 calculatedChecksum))
462 return res 462 return res
463 463
464 def saveRules(self): 464 def saveRules(self):
465 """ 465 """
466 Public method to save the subscription rules. 466 Public method to save the subscription rules.
474 E5MessageBox.warning( 474 E5MessageBox.warning(
475 None, 475 None,
476 self.trUtf8("Saving subscription rules"), 476 self.trUtf8("Saving subscription rules"),
477 self.trUtf8( 477 self.trUtf8(
478 """Unable to open adblock file '{0}' for writing.""") 478 """Unable to open adblock file '{0}' for writing.""")
479 .format(fileName)) 479 .format(fileName))
480 return 480 return
481 481
482 textStream = QTextStream(f) 482 textStream = QTextStream(f)
483 if not self.__rules or not self.__rules[0].isHeader(): 483 if not self.__rules or not self.__rules[0].isHeader():
484 textStream << "[Adblock Plus 1.1.1]\n" 484 textStream << "[Adblock Plus 1.1.1]\n"

eric ide

mercurial