File indexing completed on 2024-04-28 16:43:19
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Alejandro Fiestas Olivares <alex@eyeos.org> 0003 * SPDX-FileCopyrightText: 2010 Eduardo Robles Elvira <edulix@gmail.com> 0004 * SPDX-FileCopyrightText: 2010 UFO Coders <info@ufocoders.com> 0005 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "requestauthorization.h" 0011 #include "bluedevil_kded.h" 0012 0013 #include <QIcon> 0014 0015 #include <KLocalizedString> 0016 #include <KNotification> 0017 0018 RequestAuthorization::RequestAuthorization(BluezQt::DevicePtr device, QObject *parent) 0019 : QObject(parent) 0020 , m_device(device) 0021 { 0022 KNotification *notification = new KNotification(QStringLiteral("Authorize"), KNotification::Persistent, this); 0023 0024 notification->setComponentName(QStringLiteral("bluedevil")); 0025 notification->setTitle(QStringLiteral("%1 (%2)").arg(m_device->name().toHtmlEscaped(), m_device->address().toHtmlEscaped())); 0026 notification->setText( 0027 i18nc("Show a notification asking to authorize or deny access to this computer from Bluetooth." 0028 "The %1 is the name of the bluetooth device", 0029 "%1 is requesting access to this computer", 0030 m_device->name().toHtmlEscaped())); 0031 0032 QStringList actions; 0033 actions.append(i18nc("Button to trust a bluetooth remote device and authorize it to connect", "Trust and Authorize")); 0034 actions.append(i18nc("Button to authorize a bluetooth remote device to connect", "Authorize Only")); 0035 actions.append(i18nc("Deny access to a remote bluetooth device", "Deny")); 0036 0037 notification->setActions(actions); 0038 0039 connect(notification, &KNotification::action1Activated, this, &RequestAuthorization::authorizeAndTrust); 0040 connect(notification, &KNotification::action2Activated, this, &RequestAuthorization::authorize); 0041 connect(notification, &KNotification::action3Activated, this, &RequestAuthorization::deny); 0042 connect(notification, &KNotification::closed, this, &RequestAuthorization::deny); 0043 connect(notification, &KNotification::ignored, this, &RequestAuthorization::deny); 0044 connect(parent, SIGNAL(agentCanceled()), this, SLOT(deny())); 0045 0046 notification->sendEvent(); 0047 } 0048 0049 void RequestAuthorization::authorizeAndTrust() 0050 { 0051 qCDebug(BLUEDEVIL_KDED_LOG) << "Authorization accepted and trusted:" << m_device->name() << m_device->address(); 0052 0053 deleteLater(); 0054 Q_EMIT done(AcceptAndTrust); 0055 } 0056 0057 void RequestAuthorization::authorize() 0058 { 0059 qCDebug(BLUEDEVIL_KDED_LOG) << "Authorization accepted:" << m_device->name() << m_device->address(); 0060 0061 deleteLater(); 0062 Q_EMIT done(Accept); 0063 } 0064 0065 void RequestAuthorization::deny() 0066 { 0067 qCDebug(BLUEDEVIL_KDED_LOG) << "Authorization denied:" << m_device->name() << m_device->address(); 0068 0069 deleteLater(); 0070 Q_EMIT done(Deny); 0071 }