Messagelib

scamdetectionwarningwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5
6*/
7
8#include "scamdetectionwarningwidget.h"
9#include "settings/messageviewersettings.h"
10
11#include <KLocalizedString>
12#include <QAction>
13#include <QMenu>
14
15using namespace MessageViewer;
16
17class MessageViewer::ScamDetectionWarningWidgetPrivate
18{
19public:
20 ScamDetectionWarningWidgetPrivate() = default;
21
22 bool mUseInTestApps = false;
23};
24
25ScamDetectionWarningWidget::ScamDetectionWarningWidget(QWidget *parent)
26 : KMessageWidget(parent)
27 , d(new MessageViewer::ScamDetectionWarningWidgetPrivate)
28{
29 setVisible(false);
30 setCloseButtonVisible(true);
31 setMessageType(Warning);
32 setWordWrap(true);
33 setPosition(KMessageWidget::Header);
34 setText(i18n("This message may be a scam. <a href=\"scamdetails\">(Details...)</a>"));
35
36 connect(this, &ScamDetectionWarningWidget::linkActivated, this, &ScamDetectionWarningWidget::slotShowDetails);
37
38 auto menu = new QMenu(this);
39 auto action = new QAction(i18nc("@action", "Move to Trash"), this);
40 connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::moveMessageToTrash);
41 action->setMenu(menu);
42 addAction(action);
43
44 action = new QAction(i18nc("@action", "I confirm it's not a scam"), this);
45 menu->addAction(action);
46 connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotMessageIsNotAScam);
47
48 action = new QAction(i18nc("@action", "Add email to whitelist"), this);
49 menu->addAction(action);
50 connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotAddToWhiteList);
51
52 action = new QAction(i18nc("@action", "Disable scam detection for all messages"), this);
53 menu->addAction(action);
54 connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotDisableScamDetection);
55}
56
57ScamDetectionWarningWidget::~ScamDetectionWarningWidget() = default;
58
59void ScamDetectionWarningWidget::setUseInTestApps(bool b)
60{
61 d->mUseInTestApps = b;
62}
63
64void ScamDetectionWarningWidget::slotMessageIsNotAScam()
65{
66 Q_EMIT messageIsNotAScam();
67 setVisible(false);
68}
69
70void ScamDetectionWarningWidget::slotShowDetails(const QString &content)
71{
72 if (content == QLatin1StringView("scamdetails")) {
73 Q_EMIT showDetails();
74 }
75}
76
77void ScamDetectionWarningWidget::slotShowWarning()
78{
80}
81
82void ScamDetectionWarningWidget::slotDisableScamDetection()
83{
84 if (!d->mUseInTestApps) {
85 MessageViewer::MessageViewerSettings::self()->setScamDetectionEnabled(false);
86 MessageViewer::MessageViewerSettings::self()->save();
87 }
88 setVisible(false);
89}
90
91void ScamDetectionWarningWidget::slotAddToWhiteList()
92{
93 setVisible(false);
94 Q_EMIT addToWhiteList();
95}
96
97#include "moc_scamdetectionwarningwidget.cpp"
void animatedShow()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void triggered(bool checked)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
virtual void setVisible(bool visible)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.