128 WebBrowserWindow.adBlockManager().loadRequiredSubscription( |
128 WebBrowserWindow.adBlockManager().loadRequiredSubscription( |
129 self.__requiresLocation, self.__requiresTitle) |
129 self.__requiresLocation, self.__requiresTitle) |
130 |
130 |
131 lastUpdateString = urlQuery.queryItemValue("lastUpdate") |
131 lastUpdateString = urlQuery.queryItemValue("lastUpdate") |
132 self.__lastUpdate = QDateTime.fromString(lastUpdateString, |
132 self.__lastUpdate = QDateTime.fromString(lastUpdateString, |
133 Qt.ISODate) |
133 Qt.DateFormat.ISODate) |
134 |
134 |
135 self.__loadRules() |
135 self.__loadRules() |
136 |
136 |
137 def url(self): |
137 def url(self): |
138 """ |
138 """ |
152 queryItems.append(("requiresLocation", self.__requiresLocation)) |
152 queryItems.append(("requiresLocation", self.__requiresLocation)) |
153 queryItems.append(("requiresTitle", self.__requiresTitle)) |
153 queryItems.append(("requiresTitle", self.__requiresTitle)) |
154 if not self.__enabled: |
154 if not self.__enabled: |
155 queryItems.append(("enabled", "false")) |
155 queryItems.append(("enabled", "false")) |
156 if self.__lastUpdate.isValid(): |
156 if self.__lastUpdate.isValid(): |
157 queryItems.append(("lastUpdate", |
157 queryItems.append( |
158 self.__lastUpdate.toString(Qt.ISODate))) |
158 ("lastUpdate", |
|
159 self.__lastUpdate.toString(Qt.DateFormat.ISODate)) |
|
160 ) |
159 |
161 |
160 query = QUrlQuery() |
162 query = QUrlQuery() |
161 query.setQueryItems(queryItems) |
163 query.setQueryItems(queryItems) |
162 url.setQuery(query) |
164 url.setQuery(query) |
163 return url |
165 return url |
259 |
261 |
260 if self.__location.isEmpty(): |
262 if self.__location.isEmpty(): |
261 return "" |
263 return "" |
262 |
264 |
263 sha1 = bytes(QCryptographicHash.hash( |
265 sha1 = bytes(QCryptographicHash.hash( |
264 self.__location, QCryptographicHash.Sha1).toHex()).decode() |
266 self.__location, QCryptographicHash.Algorithm.Sha1).toHex() |
|
267 ).decode() |
265 dataDir = os.path.join( |
268 dataDir = os.path.join( |
266 Utilities.getConfigDir(), "web_browser", "subscriptions") |
269 Utilities.getConfigDir(), "web_browser", "subscriptions") |
267 if not os.path.exists(dataDir): |
270 if not os.path.exists(dataDir): |
268 os.makedirs(dataDir) |
271 os.makedirs(dataDir) |
269 fileName = os.path.join( |
272 fileName = os.path.join( |
275 Private method to load the rules of the subscription. |
278 Private method to load the rules of the subscription. |
276 """ |
279 """ |
277 fileName = self.rulesFileName() |
280 fileName = self.rulesFileName() |
278 f = QFile(fileName) |
281 f = QFile(fileName) |
279 if f.exists(): |
282 if f.exists(): |
280 if not f.open(QIODevice.ReadOnly): |
283 if not f.open(QIODevice.OpenModeFlag.ReadOnly): |
281 E5MessageBox.warning( |
284 E5MessageBox.warning( |
282 None, |
285 None, |
283 self.tr("Load subscription rules"), |
286 self.tr("Load subscription rules"), |
284 self.tr( |
287 self.tr( |
285 """Unable to open AdBlock file '{0}' for reading.""") |
288 """Unable to open AdBlock file '{0}' for reading.""") |
389 """ |
392 """ |
390 response = reply.readAll() |
393 response = reply.readAll() |
391 reply.close() |
394 reply.close() |
392 self.__downloading = None |
395 self.__downloading = None |
393 |
396 |
394 if reply.error() != QNetworkReply.NoError: |
397 if reply.error() != QNetworkReply.NetworkError.NoError: |
395 if not self.__defaultSubscription: |
398 if not self.__defaultSubscription: |
396 # don't show error if we try to load the default |
399 # don't show error if we try to load the default |
397 E5MessageBox.warning( |
400 E5MessageBox.warning( |
398 None, |
401 None, |
399 self.tr("Downloading subscription rules"), |
402 self.tr("Downloading subscription rules"), |
414 return |
417 return |
415 |
418 |
416 fileName = self.rulesFileName() |
419 fileName = self.rulesFileName() |
417 QFile.remove(fileName) |
420 QFile.remove(fileName) |
418 f = QFile(fileName) |
421 f = QFile(fileName) |
419 if not f.open(QIODevice.ReadWrite): |
422 if not f.open(QIODevice.OpenModeFlag.ReadWrite): |
420 E5MessageBox.warning( |
423 E5MessageBox.warning( |
421 None, |
424 None, |
422 self.tr("Downloading subscription rules"), |
425 self.tr("Downloading subscription rules"), |
423 self.tr( |
426 self.tr( |
424 """Unable to open AdBlock file '{0}' for writing.""") |
427 """Unable to open AdBlock file '{0}' for writing.""") |
517 fileName = self.rulesFileName() |
520 fileName = self.rulesFileName() |
518 if not fileName: |
521 if not fileName: |
519 return |
522 return |
520 |
523 |
521 f = QFile(fileName) |
524 f = QFile(fileName) |
522 if not f.open(QIODevice.ReadWrite | QIODevice.Truncate): |
525 if not f.open(QIODevice.OpenModeFlag.ReadWrite | |
|
526 QIODevice.OpenModeFlag.Truncate): |
523 E5MessageBox.warning( |
527 E5MessageBox.warning( |
524 None, |
528 None, |
525 self.tr("Saving subscription rules"), |
529 self.tr("Saving subscription rules"), |
526 self.tr( |
530 self.tr( |
527 """Unable to open AdBlock file '{0}' for writing.""") |
531 """Unable to open AdBlock file '{0}' for writing.""") |