Commit 37a421fc authored by Laurent Montel's avatar Laurent Montel 😁

Allow to enable/disable subscription

parent 15107fa6
......@@ -218,3 +218,20 @@ void AdblockManager::updateMatcher()
{
mAdBlockMatcher->update();
}
bool AdblockManager::removeSubscription(AdBlockSubscription* subscription)
{
// QMutexLocker locker(&m_mutex);
// if (!m_subscriptions.contains(subscription) || !subscription->canBeRemoved()) {
// return false;
// }
// QFile(subscription->filePath()).remove();
// m_subscriptions.removeOne(subscription);
// m_matcher->update();
// delete subscription;
return true;
}
......@@ -50,6 +50,7 @@ public:
AdBlockSubscription* addSubscription(const QString &title, const QString &url);
Q_REQUIRED_RESULT bool removeSubscription(AdBlockSubscription *subscription);
Q_SIGNALS:
void enabledChanged(bool);
......
......@@ -210,6 +210,16 @@ bool AdBlockSubscription::saveDownloadedData(const QByteArray &data)
return true;
}
bool AdBlockSubscription::enabled() const
{
return mEnabled;
}
void AdBlockSubscription::setEnabled(bool enabled)
{
mEnabled = enabled;
}
const AdBlockRule *AdBlockSubscription::rule(int offset) const
{
if (!AdblockUtil::containsIndex(mRules, offset)) {
......
......@@ -78,12 +78,12 @@ public:
explicit AdBlockSubscription(const QString &title, QObject *parent = nullptr);
~AdBlockSubscription();
QString title() const;
Q_REQUIRED_RESULT QString title() const;
QString filePath() const;
Q_REQUIRED_RESULT QString filePath() const;
void setFilePath(const QString &path);
QUrl url() const;
Q_REQUIRED_RESULT QUrl url() const;
void setUrl(const QUrl &url);
virtual void loadSubscription(const QStringList &disabledRules);
......@@ -95,13 +95,16 @@ public:
const AdBlockRule *enableRule(int offset);
const AdBlockRule *disableRule(int offset);
virtual bool canEditRules() const;
virtual bool canBeRemoved() const;
virtual Q_REQUIRED_RESULT bool canEditRules() const;
virtual Q_REQUIRED_RESULT bool canBeRemoved() const;
virtual int addRule(AdBlockRule *rule);
virtual bool removeRule(int offset);
virtual Q_REQUIRED_RESULT int addRule(AdBlockRule *rule);
virtual Q_REQUIRED_RESULT bool removeRule(int offset);
virtual const AdBlockRule *replaceRule(AdBlockRule *rule, int offset);
Q_REQUIRED_RESULT bool enabled() const;
void setEnabled(bool enabled);
public Q_SLOTS:
void updateSubscription();
......@@ -127,6 +130,7 @@ private:
QUrl mUrl;
QNetworkAccessManager *mNetworkAccessManager = nullptr;
bool mUpdated = false;
bool mEnabled = true;
};
class AdBlockCustomList : public AdBlockSubscription
......
......@@ -229,8 +229,6 @@ void AdBlockSettingWidget::doLoadFromGlobalSettings()
// ------------------------------------------------------------------------------
// automatic filters
//TODO load customlist !
for (AdBlockSubscription* subscription : AdblockManager::self()->subscriptions()) {
const QString url = subscription->url().toString();
const QString name = subscription->title();
......@@ -238,17 +236,14 @@ void AdBlockSettingWidget::doLoadFromGlobalSettings()
if (!url.isEmpty()) {
QListWidgetItem *subItem = new QListWidgetItem(mUi->automaticFiltersListWidget);
subItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
// if (isFilterEnabled) {
// subItem->setCheckState(Qt::Checked);
// } else {
// subItem->setCheckState(Qt::Unchecked);
// }
if (subscription->enabled()) {
subItem->setCheckState(Qt::Checked);
} else {
subItem->setCheckState(Qt::Unchecked);
}
subItem->setData(UrlList, url);
subItem->setText(name);
//subItem->setData(PathList, path);
//TODO
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment