Messagelib

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

KDE's Doxygen guidelines are available online.