File indexing completed on 2024-10-27 04:50:59
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 #include "potentialphishingdetailwidget.h" 0008 0009 #include <KConfigGroup> 0010 #include <KLocalizedString> 0011 #include <KSharedConfig> 0012 #include <QLabel> 0013 #include <QListWidget> 0014 #include <QVBoxLayout> 0015 0016 PotentialPhishingDetailWidget::PotentialPhishingDetailWidget(QWidget *parent) 0017 : QWidget(parent) 0018 , mListWidget(new QListWidget(this)) 0019 { 0020 auto mainLayout = new QVBoxLayout(this); 0021 mainLayout->setContentsMargins({}); 0022 auto lab = new QLabel(i18n("Select email to put in whitelist:"), this); 0023 lab->setObjectName(QLatin1StringView("label")); 0024 mainLayout->addWidget(lab); 0025 0026 mListWidget->setObjectName(QLatin1StringView("list_widget")); 0027 mainLayout->addWidget(mListWidget); 0028 } 0029 0030 PotentialPhishingDetailWidget::~PotentialPhishingDetailWidget() = default; 0031 0032 void PotentialPhishingDetailWidget::fillList(const QStringList &lst) 0033 { 0034 mListWidget->clear(); 0035 QStringList emailsAdded; 0036 for (const QString &mail : lst) { 0037 if (!emailsAdded.contains(mail)) { 0038 auto item = new QListWidgetItem(mListWidget); 0039 item->setCheckState(Qt::Unchecked); 0040 item->setText(mail); 0041 emailsAdded << mail; 0042 } 0043 } 0044 } 0045 0046 void PotentialPhishingDetailWidget::save() 0047 { 0048 KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("PotentialPhishing")); 0049 QStringList potentialPhishing = group.readEntry("whiteList", QStringList()); 0050 bool emailsAdded = false; 0051 const int numberOfItem(mListWidget->count()); 0052 for (int i = 0; i < numberOfItem; ++i) { 0053 QListWidgetItem *item = mListWidget->item(i); 0054 if (item->checkState() == Qt::Checked) { 0055 const QString email = item->text(); 0056 if (!potentialPhishing.contains(email)) { 0057 potentialPhishing << email; 0058 emailsAdded = true; 0059 } 0060 } 0061 } 0062 if (emailsAdded) { 0063 group.writeEntry("whiteList", potentialPhishing); 0064 } 0065 } 0066 0067 #include "moc_potentialphishingdetailwidget.cpp"