ContentBlockingDialog::ContentBlockingDialog(QWidget *parent) : Dialog(parent), m_ui(new Ui::ContentBlockingDialog) { m_ui->setupUi(this); const QSettings profilesSettings(SessionsManager::getWritableDataPath(QLatin1String("contentBlocking.ini")), QSettings::IniFormat); const QStringList globalProfiles = SettingsManager::getValue(QLatin1String("Content/BlockingProfiles")).toStringList(); const QVector<ContentBlockingInformation> profiles = ContentBlockingManager::getProfiles(); QStandardItemModel *model = new QStandardItemModel(this); QStringList labels; labels << tr("Title") << tr("Update Interval") << tr("Last Update"); model->setHorizontalHeaderLabels(labels); for (int i = 0; i < profiles.count(); ++i) { QList<QStandardItem*> items; items.append(new QStandardItem(profiles.at(i).title)); items[0]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); items[0]->setData(profiles.at(i).name, Qt::UserRole); items[0]->setData(profiles.at(i).updateUrl, (Qt::UserRole + 1)); items[0]->setCheckable(true); items[0]->setCheckState(globalProfiles.contains(profiles.at(i).name) ? Qt::Checked : Qt::Unchecked); items.append(new QStandardItem(profilesSettings.value(profiles.at(i).name + QLatin1String("/updateInterval")).toString())); items[1]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); items.append(new QStandardItem(Utils::formatDateTime(profilesSettings.value(profiles.at(i).name + QLatin1String("/lastUpdate")).toDateTime()))); items[2]->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); model->appendRow(items); } m_ui->profilesViewWidget->setModel(model); m_ui->profilesViewWidget->setItemDelegate(new OptionDelegate(true, this)); m_ui->profilesViewWidget->setItemDelegateForColumn(1, new ContentBlockingIntervalDelegate(this)); connect(ContentBlockingManager::getInstance(), SIGNAL(profileModified(QString)), this, SLOT(profileModified(QString))); connect(m_ui->profilesViewWidget, SIGNAL(needsActionsUpdate()), this, SLOT(updateActions())); connect(m_ui->updateButton, SIGNAL(clicked(bool)), this, SLOT(updateProfile())); connect(m_ui->confirmButtonBox, SIGNAL(accepted()), this, SLOT(save())); connect(m_ui->confirmButtonBox, SIGNAL(rejected()), this, SLOT(close())); }
ContentBlockingDialog::ContentBlockingDialog(QWidget *parent) : Dialog(parent), m_ui(new Ui::ContentBlockingDialog) { m_ui->setupUi(this); const QStringList globalProfiles(SettingsManager::getValue(SettingsManager::ContentBlocking_ProfilesOption).toStringList()); m_ui->profilesViewWidget->setModel(ContentBlockingManager::createModel(this, globalProfiles)); m_ui->profilesViewWidget->setItemDelegateForColumn(1, new ContentBlockingIntervalDelegate(this)); m_ui->profilesViewWidget->setViewMode(ItemViewWidget::TreeViewMode); m_ui->profilesViewWidget->header()->setSectionResizeMode(0, QHeaderView::Stretch); m_ui->profilesViewWidget->expandAll(); m_ui->cosmeticFiltersComboBox->addItem(tr("All"), QLatin1String("all")); m_ui->cosmeticFiltersComboBox->addItem(tr("Domain specific only"), QLatin1String("domainOnly")); m_ui->cosmeticFiltersComboBox->addItem(tr("None"), QLatin1String("none")); const int cosmeticFiltersIndex(m_ui->cosmeticFiltersComboBox->findData(SettingsManager::getValue(SettingsManager::ContentBlocking_CosmeticFiltersModeOption).toString())); m_ui->cosmeticFiltersComboBox->setCurrentIndex((cosmeticFiltersIndex < 0) ? 0 : cosmeticFiltersIndex); m_ui->enableCustomRulesCheckBox->setChecked(globalProfiles.contains(QLatin1String("custom"))); QStandardItemModel *customRulesModel(new QStandardItemModel(this)); QFile file(SessionsManager::getWritableDataPath("contentBlocking/custom.txt")); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); if (stream.readLine().trimmed().startsWith(QLatin1String("[Adblock Plus"), Qt::CaseInsensitive)) { while (!stream.atEnd()) { customRulesModel->appendRow(new QStandardItem(stream.readLine().trimmed())); } } else { Console::addMessage(QCoreApplication::translate("main", "Failed to load custom rules: invalid adblock header"), Console::OtherCategory, Console::ErrorLevel, file.fileName()); } file.close(); } m_ui->customRulesViewWidget->setModel(customRulesModel); m_ui->enableWildcardsCheckBox->setChecked(SettingsManager::getValue(SettingsManager::ContentBlocking_EnableWildcardsOption).toBool()); connect(ContentBlockingManager::getInstance(), SIGNAL(profileModified(QString)), this, SLOT(updateProfile(QString))); connect(m_ui->profilesViewWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateProfilesActions())); connect(m_ui->updateProfileButton, SIGNAL(clicked(bool)), this, SLOT(updateProfile())); connect(m_ui->addProfileButton, SIGNAL(clicked(bool)), this, SLOT(addProfile())); connect(m_ui->editProfileButton, SIGNAL(clicked(bool)), this, SLOT(editProfile())); connect(m_ui->confirmButtonBox, SIGNAL(accepted()), this, SLOT(save())); connect(m_ui->confirmButtonBox, SIGNAL(rejected()), this, SLOT(close())); connect(m_ui->enableCustomRulesCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateRulesActions())); connect(m_ui->customRulesViewWidget, SIGNAL(needsActionsUpdate()), this, SLOT(updateRulesActions())); connect(m_ui->addRuleButton, SIGNAL(clicked(bool)), this, SLOT(addRule())); connect(m_ui->editRuleButton, SIGNAL(clicked(bool)), this, SLOT(editRule())); connect(m_ui->removeRuleButton, SIGNAL(clicked(bool)), this, SLOT(removeRule())); updateRulesActions(); }