void AdBlockManager::load()
{
#if defined(ADBLOCKMANAGER_DEBUG)
    qDebug() << "AdBlockManager::" << __FUNCTION__ << m_loaded;
#endif

    if (m_loaded)
        return;
    m_loaded = true;

    QSettings settings;
    settings.beginGroup(QLatin1String("AdBlock"));
    m_enabled = settings.value(QLatin1String("enabled"), m_enabled).toBool();

    QStringList defaultSubscriptions;
    defaultSubscriptions.append(QString::fromUtf8(customSubscriptionUrl().toEncoded()));
    defaultSubscriptions.append(QLatin1String("abp:subscribe?location=http://adblockplus.mozdev.org/easylist/easylist.txt&title=EasyList"));

    QStringList subscriptions = settings.value(QLatin1String("subscriptions"), defaultSubscriptions).toStringList();
    foreach (const QString &subscription, subscriptions) {
        QUrl url = QUrl::fromEncoded(subscription.toUtf8());
        AdBlockSubscription *adBlockSubscription = new AdBlockSubscription(url, this);
        connect(adBlockSubscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
        connect(adBlockSubscription, SIGNAL(changed()), this, SIGNAL(rulesChanged()));
        m_subscriptions.append(adBlockSubscription);
    }
void AdBlockManager::addSubscription(AdBlockSubscription *subscription)
{
    if (!subscription)
        return;
#if defined(ADBLOCKMANAGER_DEBUG)
    qDebug() << "AdBlockManager::" << __FUNCTION__ << subscription->location();
#endif
    m_subscriptions.append(subscription);
    connect(subscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
    connect(subscription, SIGNAL(changed()), this, SIGNAL(rulesChanged()));
    emit rulesChanged();
}
void AdBlockManager::setEnabled(bool enabled)
{
    if (isEnabled() == enabled)
        return;
    m_enabled = enabled;
    emit rulesChanged();
}
Exemple #4
0
DomainInfoDock::DomainInfoDock(QWidget *parent) :
	EditorDock(parent),
	ui(new Ui::DomainInfoDock)
{
    ui->setupUi(this);

	//Resize the edit button so that it fits the icon button above
	ui->editButton->setMaximumWidth(ui->iconButton->geometry().width());

	//Update rules whenever they change
	ConfigurationStack &stack=ConfigurationStack::instance();
	connect(&stack, SIGNAL(domainChanged(QString,QString)), this, SLOT(onDomainChanged(QString,QString)));
	connect(&stack, SIGNAL(configurationChanged()), this, SLOT(onProgramsOrRulesChanged()));
	connect(&stack, SIGNAL(allRulesChanged()), this, SLOT(onProgramsOrRulesChanged()));
	connect(&stack, SIGNAL(loopsChanged()), this, SLOT(onProgramsOrRulesChanged()));
	connect(&stack, SIGNAL(rulesChanged()), this, SLOT(onProgramsOrRulesChanged()));
	connect(&stack, SIGNAL(programChanged(QString,QString)), this, SLOT(onProgramsOrRulesChanged()));
	connect(&stack, SIGNAL(warningsChanged()), this, SLOT(onProgramsOrRulesChanged()));

	//Connect the edit button
	connect(ui->editButton, SIGNAL(clicked()), this, SLOT(onEditClicked()));

	//Forward domain/program activated signals to parents
	connect(ui->loopsTreeWidget, SIGNAL(programActivated(QString)), this, SIGNAL(programActivated(QString)));
	connect(ui->loopsTreeWidget, SIGNAL(ruleActivated(int)), this, SIGNAL(ruleActivated(int)));
	connect(ui->incomingTreeWidget, SIGNAL(domainActivated(QString)), this, SIGNAL(domainActivated(QString)));
	connect(ui->incomingTreeWidget, SIGNAL(programActivated(QString)), this, SIGNAL(programActivated(QString)));
	connect(ui->incomingTreeWidget, SIGNAL(ruleActivated(int)), this, SIGNAL(ruleActivated(int)));
	connect(ui->leavingTreeWidget, SIGNAL(domainActivated(QString)), this, SIGNAL(domainActivated(QString)));
	connect(ui->leavingTreeWidget, SIGNAL(programActivated(QString)), this, SIGNAL(programActivated(QString)));
	connect(ui->leavingTreeWidget, SIGNAL(ruleActivated(int)), this, SIGNAL(ruleActivated(int)));
}
Exemple #5
0
QaView::QaView(QWidget* parent)
 : QDockWidget ( i18nc("@title:window","Quality Assurance"), parent)
 , m_browser(new QTreeView(this))
{
    if (!QaModel::isInstantiated())
        QaModel::instance()->loadRules(Project::instance()->qaPath());
    m_qaModel=QaModel::instance();

    setWidget(m_browser);
    m_browser->setModel(m_qaModel);
    m_browser->setRootIsDecorated(false);
    m_browser->setContextMenuPolicy(Qt::ActionsContextMenu);

    QAction* action=new QAction(i18nc("@action:inmenu", "Add"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(addRule()));
    m_browser->addAction(action);

    action=new QAction(i18nc("@action:inmenu", "Remove"), m_browser);
    connect(action, SIGNAL(triggered()), this, SLOT(removeRule()));
    m_browser->addAction(action);
    
    m_browser->setAlternatingRowColors(true);
    
    connect(m_qaModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(rulesChanged()));
}
void RuleListWidget::updateRuleList()
{
	// create a first element if necessary
	if(_ruleLayout->count() == 0)
		_ruleLayout->addWidget(createWidgetAt(0));

	// create a last element if necessary
	RuleWidget * last = qobject_cast<RuleWidget*>(_ruleLayout->itemAt(_ruleLayout->count()-1)->widget());
	Q_ASSERT(last != 0);
	if(!last->scene()->isEmpty())
	{
		_ruleLayout->addWidget(createWidgetAt(_ruleLayout->count()));
		emit numberOfRulesChanged(numberOfRules() - 1);
	}

	for(int i = 0; i < _ruleLayout->count(); i++)
	{
		RuleWidget * w = qobject_cast<RuleWidget*>(_ruleLayout->itemAt(i)->widget());
		Q_ASSERT(w != 0);

		w->setPosition(i);

		w->setUpEnabled(i != 0 && i != _ruleLayout->count()-1);
		w->setDownEnabled(i < _ruleLayout->count() - 2);
		w->setDeleteEnabled(i != _ruleLayout->count() - 1);
	}

	emit rulesChanged();
}
void AdBlockManager::rulesUpdated()
{
    Settings settings;
    settings.beginGroup("AdBlock");
    settings.setValue("lastUpdate", QDateTime::currentDateTime());

    emit rulesChanged();
}
void SituationModel::setRules(const QString theValue, bool update) {
    if (theValue != m_rules) {
        if (debugLevel & 1 << MODEL) std::cout << "Setting Rules " << theValue.toStdString() << std::endl;
       m_rules = theValue;
        if (update)
            emit rulesChanged(m_rules);
    }
}
void AdBlockManager::setEnabled(bool enabled)
{
    if (isEnabled() == enabled) {
        return;
    }
    m_enabled = enabled;
    emit rulesChanged();
    mApp->sendMessages(Qz::AM_SetAdBlockIconEnabled, enabled);
}
// public void load()
void tst_AdBlockManager::load()
{
    SubAdBlockManager manager;

    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));

    manager.load();

    QCOMPARE(spy0.count(), 0);
}
// public AdBlockDialog *showDialog()
void tst_AdBlockManager::showDialog()
{
    SubAdBlockManager manager;

    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));

    AdBlockDialog *dialog = manager.showDialog();
    QVERIFY(dialog);
    QTRY_VERIFY(dialog->isVisible());
}
void AdBlockManager::setEnabled(bool b)
{
    bool changed = b != this->_enabled;
    this->_enabled = b;

    if(changed)
    {
        emit enabledChanged();
        emit rulesChanged();
    }
}
void AdBlockManager::load()
{
    if (m_loaded) {
        return;
    }
    m_loaded = true;

    Settings settings;
    settings.beginGroup("AdBlock");
    m_enabled = settings.value("enabled", m_enabled).toBool();
    QDateTime lastUpdate = settings.value("lastUpdate", QDateTime()).toDateTime();
    settings.endGroup();

    m_subscription = new AdBlockSubscription();
    connect(m_subscription, SIGNAL(rulesChanged()), this, SIGNAL(rulesChanged()));
    connect(m_subscription, SIGNAL(rulesUpdated()), this, SLOT(rulesUpdated()));

    if (lastUpdate.addDays(3) < QDateTime::currentDateTime()) {
        m_subscription->scheduleUpdate();
    }
}
AdBlockManager::AdBlockManager(QObject *parent)
    : QObject(parent)
    , m_loaded(false)
    , m_enabled(true)
    , m_saveTimer(new AutoSaver(this))
    , m_adBlockDialog(0)
    , m_adBlockNetwork(0)
    , m_adBlockPage(0)
{
    connect(this, SIGNAL(rulesChanged()),
            m_saveTimer, SLOT(changeOccurred()));
}
void AdBlockManager::removeSubscription(AdBlockSubscription *subscription)
{
    if (!subscription)
        return;
#if defined(ADBLOCKMANAGER_DEBUG)
    qDebug() << "AdBlockManager::" << __FUNCTION__ << subscription->location();
#endif
    m_saveTimer->saveIfNeccessary();
    m_subscriptions.removeOne(subscription);
    if (subscription->parent() == this)
        subscription->deleteLater();
    emit rulesChanged();
}
void CompositorSettings::setKeymap(Keymap *keymap)
{
    Q_D(CompositorSettings);

    if (d->keymap == keymap)
        return;

    if (d->keymap) {
        disconnect(keymap, SIGNAL(rulesChanged()),
                   this, SLOT(_q_setupKeymap()));
        disconnect(keymap, SIGNAL(modelChanged()),
                   this, SLOT(_q_setupKeymap()));
        disconnect(keymap, SIGNAL(layoutChanged()),
                   this, SLOT(_q_setupKeymap()));
        disconnect(keymap, SIGNAL(variantChanged()),
                   this, SLOT(_q_setupKeymap()));
        disconnect(keymap, SIGNAL(optionsChanged()),
                   this, SLOT(_q_setupKeymap()));
    }

    if (keymap) {
        connect(keymap, SIGNAL(rulesChanged()),
                this, SLOT(_q_setupKeymap()));
        connect(keymap, SIGNAL(modelChanged()),
                this, SLOT(_q_setupKeymap()));
        connect(keymap, SIGNAL(layoutChanged()),
                this, SLOT(_q_setupKeymap()));
        connect(keymap, SIGNAL(variantChanged()),
                this, SLOT(_q_setupKeymap()));
        connect(keymap, SIGNAL(optionsChanged()),
                this, SLOT(_q_setupKeymap()));

        d->_q_setupKeymap();
    }

    d->keymap = keymap;
    Q_EMIT keymapChanged();
}
void tst_AdBlockManager::rulesChanged()
{
    SubAdBlockManager manager;

    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));


    AdBlockSubscription *subscription = new AdBlockSubscription(QUrl(), &manager);
    manager.addSubscription(subscription);
    subscription->setEnabled(true);
    subscription->addRule(AdBlockRule());

    QCOMPARE(spy0.count(), 3);
}
// public void removeSubscription(AdBlockSubscription *subscription)
void tst_AdBlockManager::removeSubscription()
{
    SubAdBlockManager manager;

    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));

    QList<AdBlockSubscription*> list = manager.subscriptions();
    AdBlockSubscription *subscription = new AdBlockSubscription(QUrl(), &manager);
    manager.addSubscription(subscription);
    manager.removeSubscription(subscription);
    QCOMPARE(manager.subscriptions(), list);

    QCOMPARE(spy0.count(), 2);
}
// public AdBlockSubscription *customRules()
void tst_AdBlockManager::customRules()
{
    SubAdBlockManager manager;
    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));

    AdBlockSubscription *subscription = manager.customRules();
    QVERIFY(subscription);
    QVERIFY(!subscription->title().isEmpty());
    QVERIFY(subscription->allRules().isEmpty());

    QCOMPARE(spy0.count(), 1);

    subscription = manager.customRules();
    QCOMPARE(spy0.count(), 1);
}
// public bool isEnabled() const
void tst_AdBlockManager::isEnabled()
{
    QFETCH(bool, isEnabled);

    SubAdBlockManager manager;

    QSignalSpy spy0(&manager, SIGNAL(rulesChanged()));

    bool before = manager.isEnabled();

    manager.setEnabled(isEnabled);
    manager.setEnabled(isEnabled);
    QCOMPARE(manager.isEnabled(), isEnabled);

    QCOMPARE(spy0.count(), before == isEnabled ? 0 : 1);
}