1 /*
2 SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "adblockblockableelementgui.h"
8 #include "../lib/adblockblockableitemsjob.h"
9 #include "../lib/widgets/adblockblockableitemsdialog.h"
10 #include <QApplication>
11 #include <QCommandLineParser>
12 #include <QPushButton>
13 #include <QStandardPaths>
14 #include <QVBoxLayout>
15 #include <QWebEngineView>
16 using namespace AdBlock;
AdblockBlockableElementGui(QWidget * parent)17 AdblockBlockableElementGui::AdblockBlockableElementGui(QWidget *parent)
18 : QWidget(parent)
19 {
20 auto vbox = new QVBoxLayout(this);
21
22 mWebEngineView = new QWebEngineView(this);
23 mWebEngineView->load(QUrl(QStringLiteral("http://www.kde.org")));
24 vbox->addWidget(mWebEngineView);
25 auto button = new QPushButton(QStringLiteral("search adblock"), this);
26 connect(button, &QPushButton::clicked, this, &AdblockBlockableElementGui::slotSearchAdblock);
27 vbox->addWidget(button);
28 }
29
~AdblockBlockableElementGui()30 AdblockBlockableElementGui::~AdblockBlockableElementGui()
31 {
32 }
33
slotSearchItemsDone(const QVector<AdBlock::AdBlockResult> & result)34 void AdblockBlockableElementGui::slotSearchItemsDone(const QVector<AdBlock::AdBlockResult> &result)
35 {
36 AdBlockBlockableItemsDialog dlg(this);
37 dlg.setAdblockResult(result);
38 dlg.exec();
39 }
40
slotSearchAdblock()41 void AdblockBlockableElementGui::slotSearchAdblock()
42 {
43 auto job = new AdBlockBlockableItemsJob(this);
44 job->setWebEngineView(mWebEngineView);
45 connect(job, &AdBlockBlockableItemsJob::searchItemsDone, this, &AdblockBlockableElementGui::slotSearchItemsDone);
46 job->start();
47 }
48
main(int argc,char ** argv)49 int main(int argc, char **argv)
50 {
51 QApplication app(argc, argv);
52 QStandardPaths::setTestModeEnabled(true);
53 QCommandLineParser parser;
54 parser.addVersionOption();
55 parser.addHelpOption();
56 parser.process(app);
57
58 auto dialog = new AdblockBlockableElementGui;
59 dialog->resize(800, 600);
60 dialog->show();
61 app.exec();
62 delete dialog;
63 return 0;
64 }
65