Messagelib

trackingwarningwidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2017-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "trackingwarningwidget.h"
8 #include "trackingdetailsdialog.h"
9 #include <KLocalizedString>
10 
11 using namespace WebEngineViewer;
12 TrackingWarningWidget::TrackingWarningWidget(QWidget *parent)
13  : KMessageWidget(parent)
14 {
15  setVisible(false);
16  setCloseButtonVisible(true);
17  setMessageType(Warning);
18  setWordWrap(true);
19 
20  setText(i18n("Some Mail Tracker was found and was blocked.<a href=\"mailtrackingdetails\">(Details...)"));
21  connect(this, &TrackingWarningWidget::linkActivated, this, &TrackingWarningWidget::slotShowDetails);
22 }
23 
24 TrackingWarningWidget::~TrackingWarningWidget() = default;
25 
26 void TrackingWarningWidget::slotShowDetails(const QString &content)
27 {
28  if (content == QLatin1String("mailtrackingdetails")) {
29  if (!mMailTrackingDetailDialog) {
30  mMailTrackingDetailDialog = new WebEngineViewer::TrackingDetailsDialog;
31  }
32  mMailTrackingDetailDialog->setDetails(generateDetails());
33  mMailTrackingDetailDialog->show();
34  }
35 }
36 
37 QString TrackingWarningWidget::generateDetails() const
38 {
39  QString details = QLatin1String("<b>") + i18n("Details:") + QLatin1String("</b><ul>");
40 
42  while (i.hasNext()) {
43  i.next();
44  details += QLatin1String("<li>")
45  + i18np("1 tracker from the company %2 (%3)", "%1 trackers from the company %2 (%3)", i.value().number, i.key(), i.value().url);
46  }
47  details += QLatin1String("</ul>");
48  return details;
49 }
50 
51 void TrackingWarningWidget::addTracker(const WebEngineViewer::BlockTrackingUrlInterceptor::TrackerBlackList &tracker)
52 {
53  blackListFound item = mBackLists.value(tracker.mCompanyName);
54  if (item.url.isEmpty()) {
55  item.url = tracker.mCompanyUrl;
56  mBackLists.insert(tracker.mCompanyName, item);
57  } else {
58  item.number = item.number + 1;
59  mBackLists.insert(tracker.mCompanyName, item);
60  }
61  if (!isVisible()) {
62  animatedShow();
63  }
64 }
65 
66 void TrackingWarningWidget::hideAndClear()
67 {
68  mBackLists.clear();
69  setVisible(false);
70 }
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:04:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.