| 85 | } |
| 86 | |
| 87 | void AdBlockManager::updateSubscriptions() |
| 88 | { |
| 89 | if (!m_enabled) |
| 90 | return; |
| 91 | |
| 92 | // Try updating the subscription if its next_update is hit |
| 93 | // Check if subscription should be updated |
| 94 | for (size_t i = 0; i < m_subscriptions.size(); ++i) |
| 95 | { |
| 96 | AdBlockSubscription *subPtr = &(m_subscriptions[i]); |
| 97 | if (!subPtr) |
| 98 | continue; |
| 99 | const QDateTime &updateTime = subPtr->getNextUpdate(); |
| 100 | QDateTime now = QDateTime::currentDateTime(); |
| 101 | if (!updateTime.isNull() && updateTime < now) |
| 102 | { |
| 103 | const QUrl &srcUrl = subPtr->getSourceUrl(); |
| 104 | if (srcUrl.isValid() && !srcUrl.isLocalFile()) |
| 105 | { |
| 106 | QNetworkRequest request; |
| 107 | request.setUrl(srcUrl); |
| 108 | |
| 109 | InternalDownloadItem *item = m_downloadManager->downloadInternal(request, m_subscriptionDir, false, true); |
| 110 | connect(item, &InternalDownloadItem::downloadFinished, [item, now, subPtr](const QString &filePath) { |
| 111 | if (filePath != subPtr->getFilePath()) |
| 112 | { |
| 113 | QFile oldFile(subPtr->getFilePath()); |
| 114 | oldFile.remove(); |
| 115 | subPtr->setFilePath(filePath); |
| 116 | } |
| 117 | item->deleteLater(); |
| 118 | subPtr->setLastUpdate(now); |
| 119 | subPtr->setNextUpdate(now.addDays(7)); |
| 120 | }); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | void AdBlockManager::installResource(const QUrl &url) |
| 127 | { |
no test coverage detected