diff --git a/src/adblock/adblockdialog.cpp b/src/adblock/adblockdialog.cpp index 92c6eec11..32a8a206d 100644 --- a/src/adblock/adblockdialog.cpp +++ b/src/adblock/adblockdialog.cpp @@ -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())); diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 3c6d09037..2048fe40a 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -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() diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h index 99c135a46..5b399208b 100644 --- a/src/adblock/adblockmanager.h +++ b/src/adblock/adblockmanager.h @@ -81,6 +81,9 @@ public slots: AdBlockDialog* showDialog(); void showRule(); +private slots: + void rulesUpdated(); + private: static AdBlockManager* s_adBlockManager; diff --git a/src/adblock/adblocksubscription.cpp b/src/adblock/adblocksubscription.cpp index e390fa3a1..618d412b5 100644 --- a/src/adblock/adblocksubscription.cpp +++ b/src/adblock/adblocksubscription.cpp @@ -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; } diff --git a/src/adblock/adblocksubscription.h b/src/adblock/adblocksubscription.h index 83391bd23..68fba086f 100644 --- a/src/adblock/adblocksubscription.h +++ b/src/adblock/adblocksubscription.h @@ -55,6 +55,7 @@ #include #include #include +#include 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 m_rules; diff --git a/src/tools/treewidget.cpp b/src/tools/treewidget.cpp index 99fdc9ede..fa31ecffb 100644 --- a/src/tools/treewidget.cpp +++ b/src/tools/treewidget.cpp @@ -98,7 +98,6 @@ QList TreeWidget::allItems() return m_allTreeItems; } -#include void TreeWidget::filterString(QString string) { expandAll();