featurepermissionbar.cpp 3.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * This file is part of the KDE project.
 *
 * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org>
 * Copyright (C) 2013 Allan Sandfeld Jensen <sandfeld@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "featurepermissionbar.h"

25
#include <KLocalizedString>
26
27
28
29
30
31
32
33
34
35
36

#include <QAction>


FeaturePermissionBar::FeaturePermissionBar(QWidget *parent)
                     :KMessageWidget(parent)
{
    setCloseButtonVisible(false);
    setMessageType(KMessageWidget::Information);

    QAction* action = new QAction(i18nc("@action:deny access", "&Deny access"), this);
37
    connect(action, &QAction::triggered, this, &FeaturePermissionBar::onDeniedButtonClicked);
38
39
40
    addAction(action);

    action = new QAction(i18nc("@action:grant access", "&Grant access"), this);
41
    connect(action, &QAction::triggered, this, &FeaturePermissionBar::onGrantedButtonClicked);
42
43
44
45
46
47
48
49
50
    addAction(action);

    // FIXME: Add option to allow and remember for this site.
}

FeaturePermissionBar::~FeaturePermissionBar()
{
}

51
QWebEnginePage::Feature FeaturePermissionBar::feature() const
52
53
54
55
{
    return m_feature;
}

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
QUrl FeaturePermissionBar::url() const
{
    return m_url;
}

void FeaturePermissionBar::setUrl(const QUrl& url)
{
    m_url = url;
}

QString FeaturePermissionBar::labelForFeature(QWebEnginePage::Feature feature)
{
    switch (feature) {
        case QWebEnginePage::Notifications:
            return i18n("<html>Do you want to allow the site to send you notifications?");
        case QWebEnginePage::Geolocation:
            return i18n("<html>Do you want to grant the site access to information about your current physical location?");
        case QWebEnginePage::MediaAudioCapture:
            return i18n("<html>Do you want to allow the site to access your microphone and other audio capture devices?");
        case QWebEnginePage::MediaVideoCapture:
            return i18n("<html>Do you want to allow the site to access your camera and other video capture devices?");
        case QWebEnginePage::MediaAudioVideoCapture:
            return i18n("<html>Do you want to allow the site to access to your microphone, camera and other audio and video capture devices?");
        case QWebEnginePage::MouseLock:
            return i18n("<html>Do you want to allow the site to lock your mouse inside the web page?");
        case QWebEnginePage::DesktopVideoCapture:
            return i18n("<html>Do you want to allow the site to record your screen?");
        case QWebEnginePage::DesktopAudioVideoCapture:
            return i18n("<html>Do you want to allow the site to record your screen and your audio?");
Stefano Crocco's avatar
Stefano Crocco committed
85
86
        default:
            return QString();
87
88
89
    }
}

90
void FeaturePermissionBar::setFeature (QWebEnginePage::Feature feature)
91
92
{
    m_feature = feature;
93
    setText(labelForFeature(feature));
94
95
96
97
98
}

void FeaturePermissionBar::onDeniedButtonClicked()
{
    animatedHide();
99
    emit permissionPolicyChosen(m_feature, QWebEnginePage::PermissionDeniedByUser);
100
101
102
103
104
105
    emit done();
}

void FeaturePermissionBar::onGrantedButtonClicked()
{
    animatedHide();
106
    emit permissionPolicyChosen(m_feature, QWebEnginePage::PermissionGrantedByUser);
107
108
    emit done();
}