adblockblockableitemsdialog.cpp 2.85 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2016-2017 Montel Laurent <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3

Laurent Montel's avatar
Laurent Montel committed
4 5 6 7
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
Laurent Montel's avatar
Laurent Montel committed
8

Laurent Montel's avatar
Laurent Montel committed
9 10 11 12
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
Laurent Montel's avatar
Laurent Montel committed
13

Laurent Montel's avatar
Laurent Montel committed
14 15 16 17
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
Laurent Montel's avatar
Laurent Montel committed
18 19 20 21 22 23 24 25 26 27 28 29 30
*/

#include "adblockblockableitemsdialog.h"
#include "adblockblockableitemswidget.h"

#include <KLocalizedString>
#include <KTreeWidgetSearchLine>

#include <QVBoxLayout>
#include <KSharedConfig>
#include <QDialogButtonBox>
#include <KConfigGroup>
#include <QPushButton>
Laurent Montel's avatar
Laurent Montel committed
31
using namespace AdBlock;
Laurent Montel's avatar
Laurent Montel committed
32 33 34 35
AdBlockBlockableItemsDialog::AdBlockBlockableItemsDialog(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(i18n("Blockable Items"));
36 37 38 39 40 41 42

    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    mBlockableItems = new AdBlockBlockableItemsWidget(this);
    mBlockableItems->setObjectName(QStringLiteral("blockableitemswidget"));

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
Laurent Montel's avatar
Laurent Montel committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    buttonBox->setObjectName(QStringLiteral("buttonbox"));
    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setDefault(true);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, &QDialogButtonBox::accepted, this, &AdBlockBlockableItemsDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &AdBlockBlockableItemsDialog::reject);

    mainLayout->addWidget(mBlockableItems);
    mainLayout->addWidget(buttonBox);
    readConfig();
}

AdBlockBlockableItemsDialog::~AdBlockBlockableItemsDialog()
{
    writeConfig();
}

60 61 62 63 64 65
void AdBlockBlockableItemsDialog::accept()
{
    saveFilters();
    QDialog::accept();
}

Laurent Montel's avatar
Laurent Montel committed
66 67
void AdBlockBlockableItemsDialog::saveFilters()
{
68
    mBlockableItems->saveFilters();
Laurent Montel's avatar
Laurent Montel committed
69 70
}

Laurent Montel's avatar
Laurent Montel committed
71 72 73 74 75
void AdBlockBlockableItemsDialog::setAdblockResult(const QVector<AdBlock::AdBlockResult> &result)
{
    mBlockableItems->setAdblockResult(result);
}

Laurent Montel's avatar
Laurent Montel committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89
void AdBlockBlockableItemsDialog::writeConfig()
{
    KConfigGroup group(KSharedConfig::openConfig(), "AdBlockBlockableItemsDialog");
    group.writeEntry("Size", size());
}

void AdBlockBlockableItemsDialog::readConfig()
{
    KConfigGroup group(KSharedConfig::openConfig(), "AdBlockBlockableItemsDialog");
    const QSize sizeDialog = group.readEntry("Size", QSize(500, 300));
    if (sizeDialog.isValid()) {
        resize(sizeDialog);
    }
}