File indexing completed on 2025-02-02 04:49:38
0001 /* 0002 This file is part of the KDE project. 0003 0004 SPDX-FileCopyrightText: 2009 Dawit Alemayehu <adawit @ kde.org> 0005 SPDX-FileCopyrightText: 2013 Allan Sandfeld Jensen <sandfeld@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "featurepermissionbar.h" 0011 0012 0013 #include <QAction> 0014 0015 0016 FeaturePermissionBar::FeaturePermissionBar(QWidget *parent) 0017 :KMessageWidget(parent) 0018 { 0019 setCloseButtonVisible(false); 0020 setMessageType(KMessageWidget::Information); 0021 0022 QAction *action = new QAction(i18nc("@action:deny permission", "&Deny permission"), this); 0023 connect(action, &QAction::triggered, this, &FeaturePermissionBar::onDeniedButtonClicked); 0024 addAction(action); 0025 0026 action = new QAction(i18nc("@action:grant permission", "&Grant permission"), this); 0027 connect(action, &QAction::triggered, this, &FeaturePermissionBar::onGrantedButtonClicked); 0028 addAction(action); 0029 0030 // FIXME: Add option to allow and remember for this site. 0031 } 0032 0033 FeaturePermissionBar::~FeaturePermissionBar() 0034 { 0035 } 0036 0037 QWebEnginePage::Feature FeaturePermissionBar::feature() const 0038 { 0039 return m_feature; 0040 } 0041 0042 QUrl FeaturePermissionBar::url() const 0043 { 0044 return m_url; 0045 } 0046 0047 void FeaturePermissionBar::setUrl(const QUrl& url) 0048 { 0049 m_url = url; 0050 } 0051 0052 QString FeaturePermissionBar::labelText(QWebEnginePage::Feature feature) const 0053 { 0054 QString origin = m_url.toDisplayString(); 0055 switch (feature) { 0056 case QWebEnginePage::Notifications: 0057 return i18n("<html><b>%1</b> would like to send you notifications", origin); 0058 case QWebEnginePage::Geolocation: 0059 return i18n("<html><b>%1</b> would like to access information about your current physical location", origin); 0060 case QWebEnginePage::MediaAudioCapture: 0061 return i18n("<html><b>%1</b> would like to access your microphone and other audio capture devices", origin); 0062 case QWebEnginePage::MediaVideoCapture: 0063 return i18n("<html><b>%1</b> would like to access your camera and other video capture devices", origin); 0064 case QWebEnginePage::MediaAudioVideoCapture: 0065 return i18n("<html><b>%1</b> would like to access to your microphone, camera and other audio and video capture devices", origin); 0066 case QWebEnginePage::MouseLock: 0067 return i18n("<html><b>%1</b> would like to lock your mouse inside the web page", origin); 0068 case QWebEnginePage::DesktopVideoCapture: 0069 return i18n("<html><b>%1</b> would like to record your screen", origin); 0070 case QWebEnginePage::DesktopAudioVideoCapture: 0071 return i18n("<html><b>%1</b> would like to record your screen and your audio", origin); 0072 default: 0073 return QString(); 0074 } 0075 } 0076 0077 void FeaturePermissionBar::setFeature (QWebEnginePage::Feature feature) 0078 { 0079 m_feature = feature; 0080 setText(labelText(feature)); 0081 } 0082 0083 void FeaturePermissionBar::onDeniedButtonClicked() 0084 { 0085 animatedHide(); 0086 emit permissionPolicyChosen(m_feature, QWebEnginePage::PermissionDeniedByUser); 0087 emit done(); 0088 } 0089 0090 void FeaturePermissionBar::onGrantedButtonClicked() 0091 { 0092 animatedHide(); 0093 emit permissionPolicyChosen(m_feature, QWebEnginePage::PermissionGrantedByUser); 0094 emit done(); 0095 }