Falkon Develop
Cross-platform Qt-based web browser
protocolhandlerdialog.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2019 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
19#include "ui_protocolhandlerdialog.h"
20#include "mainapplication.h"
22
24 : QDialog(parent)
25 , ui(new Ui::ProtocolHandlerDialog)
26{
27 setAttribute(Qt::WA_DeleteOnClose);
28
29 ui->setupUi(this);
30
31 init();
32
33 ui->treeWidget->header()->resizeSection(0, 100);
34 connect(ui->remove, &QPushButton::clicked, this, &ProtocolHandlerDialog::removeEntry);
35 connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ProtocolHandlerDialog::accepted);
36 connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ProtocolHandlerDialog::close);
37}
38
40{
41 delete ui;
42}
43
44void ProtocolHandlerDialog::init()
45{
46 const auto handlers = mApp->protocolHandlerManager()->protocolHandlers();
47 for (auto it = handlers.cbegin(); it != handlers.cend(); ++it) {
48 auto *item = new QTreeWidgetItem(ui->treeWidget);
49 item->setText(0, it.key());
50 item->setText(1, it.value().host());
51 ui->treeWidget->addTopLevelItem(item);
52 }
53}
54
55void ProtocolHandlerDialog::accepted()
56{
57 auto handlers = mApp->protocolHandlerManager()->protocolHandlers();
58 for (int i = 0; i < ui->treeWidget->topLevelItemCount(); ++i) {
59 QTreeWidgetItem *item = ui->treeWidget->topLevelItem(i);
60 handlers.remove(item->text(0));
61 }
62 for (auto it = handlers.cbegin(); it != handlers.cend(); ++it) {
63 mApp->protocolHandlerManager()->removeProtocolHandler(it.key());
64 }
65 close();
66}
67
68void ProtocolHandlerDialog::removeEntry()
69{
70 delete ui->treeWidget->currentItem();
71}
72
ProtocolHandlerDialog(QWidget *parent=nullptr)
#define mApp
i
Definition: i18n.py:23