1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Automatic updates for EasyList in AdBlock.

- updates are scheduled to every 3 days
This commit is contained in:
nowrep 2011-12-28 19:28:34 +01:00
parent 6259577d8b
commit 89cad89ad0
6 changed files with 41 additions and 16 deletions

View File

@ -63,7 +63,7 @@ AdBlockDialog::AdBlockDialog(QWidget* parent)
connect(addButton, SIGNAL(clicked()), this, SLOT(addCustomRule()));
connect(reloadButton, SIGNAL(clicked()), this, SLOT(updateSubscription()));
connect(search, SIGNAL(textChanged(QString)), treeWidget, SLOT(filterString(QString)));
connect(m_manager->subscription(), SIGNAL(changed()), this, SLOT(refreshAfterUpdate()));
connect(m_manager->subscription(), SIGNAL(rulesUpdated()), this, SLOT(refreshAfterUpdate()));
connect(treeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested()));
// QTimer::singleShot(0, this, SLOT(firstRefresh()));

View File

@ -108,11 +108,25 @@ void AdBlockManager::load()
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
settings.beginGroup("AdBlock");
m_enabled = settings.value("enabled", m_enabled).toBool();
QDateTime lastUpdate = settings.value("lastUpdate", QDateTime()).toDateTime();
settings.endGroup();
m_subscription = new AdBlockSubscription(this);
m_subscription = new AdBlockSubscription();
connect(m_subscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
connect(m_subscription, SIGNAL(changed()), this, SIGNAL(rulesChanged()));
connect(m_subscription, SIGNAL(rulesUpdated()), this, SLOT(rulesUpdated()));
if (lastUpdate.addDays(3) < QDateTime::currentDateTime()) {
m_subscription->scheduleUpdate();
}
}
void AdBlockManager::rulesUpdated()
{
QSettings settings(mApp->getActiveProfilPath() + "settings.ini", QSettings::IniFormat);
settings.beginGroup("AdBlock");
settings.setValue("lastUpdate", QDateTime::currentDateTime());
emit rulesChanged();
}
void AdBlockManager::save()

View File

@ -81,6 +81,9 @@ public slots:
AdBlockDialog* showDialog();
void showRule();
private slots:
void rulesUpdated();
private:
static AdBlockManager* s_adBlockManager;

View File

@ -82,6 +82,16 @@ void AdBlockSubscription::loadRules()
}
}
}
if (m_rules.isEmpty()) {
// Initial update
QTimer::singleShot(0, this, SLOT(updateNow()));
}
}
void AdBlockSubscription::scheduleUpdate()
{
QTimer::singleShot(1000 * 30, this, SLOT(updateNow()));
}
void AdBlockSubscription::updateNow()
@ -140,7 +150,7 @@ void AdBlockSubscription::rulesDownloaded()
file.write(response);
file.close();
loadRules();
emit changed();
emit rulesUpdated();
m_downloading = 0;
}

View File

@ -55,6 +55,7 @@
#include <QNetworkReply>
#include <QTextStream>
#include <QFileInfo>
#include <QTimer>
class QNetworkReply;
class QUrl;
@ -62,19 +63,13 @@ class AdBlockSubscription : public QObject
{
Q_OBJECT
signals:
void changed();
void rulesChanged();
public:
AdBlockSubscription(QObject* parent = 0);
QString title() const { return m_title; }
void setTitle(const QString &title) { m_title = title; }
void updateNow();
QDateTime lastUpdate() const;
void scheduleUpdate();
void saveRules();
const AdBlockRule* allow(const QString &urlString) const;
@ -86,17 +81,21 @@ public:
void removeRule(int offset);
void replaceRule(const AdBlockRule &rule, int offset);
signals:
void rulesUpdated();
void rulesChanged();
public slots:
void updateNow();
private slots:
void loadRules();
void rulesDownloaded();
private:
void populateCache();
QString rulesFileName() const;
void parseUrl(const QUrl &url);
void loadRules();
QString m_title;
bool m_enabled;
QNetworkReply* m_downloading;
QList<AdBlockRule> m_rules;

View File

@ -98,7 +98,6 @@ QList<QTreeWidgetItem*> TreeWidget::allItems()
return m_allTreeItems;
}
#include <QDebug>
void TreeWidget::filterString(QString string)
{
expandAll();