Messagelib

scamdetectionwarningwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 
15 using namespace MessageViewer;
16 
17 class MessageViewer::ScamDetectionWarningWidgetPrivate
18 {
19 public:
20  ScamDetectionWarningWidgetPrivate() = default;
21 
22  bool mUseInTestApps = false;
23 };
24 
25 ScamDetectionWarningWidget::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  setText(i18n("This message may be a scam. <a href=\"scamdetails\">(Details...)</a>"));
34 
35  connect(this, &ScamDetectionWarningWidget::linkActivated, this, &ScamDetectionWarningWidget::slotShowDetails);
36 
37  auto menu = new QMenu(this);
38  auto action = new QAction(i18n("Move to Trash"), this);
39  connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::moveMessageToTrash);
40  action->setMenu(menu);
41  addAction(action);
42 
43  action = new QAction(i18n("I confirm it's not a scam"), this);
44  menu->addAction(action);
45  connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotMessageIsNotAScam);
46 
47  action = new QAction(i18n("Add email to whitelist"), this);
48  menu->addAction(action);
49  connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotAddToWhiteList);
50 
51  action = new QAction(i18n("Disable scam detection for all messages"), this);
52  menu->addAction(action);
53  connect(action, &QAction::triggered, this, &ScamDetectionWarningWidget::slotDisableScamDetection);
54 }
55 
56 ScamDetectionWarningWidget::~ScamDetectionWarningWidget() = default;
57 
58 void ScamDetectionWarningWidget::setUseInTestApps(bool b)
59 {
60  d->mUseInTestApps = b;
61 }
62 
63 void ScamDetectionWarningWidget::slotMessageIsNotAScam()
64 {
65  Q_EMIT messageIsNotAScam();
66  setVisible(false);
67 }
68 
69 void ScamDetectionWarningWidget::slotShowDetails(const QString &content)
70 {
71  if (content == QLatin1String("scamdetails")) {
72  Q_EMIT showDetails();
73  }
74 }
75 
76 void ScamDetectionWarningWidget::slotShowWarning()
77 {
78  animatedShow();
79 }
80 
81 void ScamDetectionWarningWidget::slotDisableScamDetection()
82 {
83  if (!d->mUseInTestApps) {
84  MessageViewer::MessageViewerSettings::self()->setScamDetectionEnabled(false);
85  MessageViewer::MessageViewerSettings::self()->save();
86  }
87  setVisible(false);
88 }
89 
90 void ScamDetectionWarningWidget::slotAddToWhiteList()
91 {
92  setVisible(false);
93  Q_EMIT addToWhiteList();
94 }
void triggered(bool checked)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.