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 "requestconfirmation.h" 0011 #include "bluedevil_kded.h" 0012 0013 #include <KLocalizedString> 0014 #include <KNotification> 0015 0016 RequestConfirmation::RequestConfirmation(BluezQt::DevicePtr device, const QString &pin, QObject *parent) 0017 : QObject(parent) 0018 , m_device(device) 0019 , m_pin(pin) 0020 { 0021 KNotification *notification = new KNotification(QStringLiteral("RequestConfirmation"), KNotification::Persistent, this); 0022 0023 notification->setComponentName(QStringLiteral("bluedevil")); 0024 notification->setTitle(QStringLiteral("%1 (%2)").arg(m_device->name().toHtmlEscaped(), m_device->address())); 0025 notification->setText( 0026 i18nc("The text is shown in a notification to know if the PIN is correct," 0027 "%1 is the remote bluetooth device and %2 is the pin", 0028 "%1 is asking if the PIN is correct: %2", 0029 m_device->name().toHtmlEscaped(), 0030 m_pin)); 0031 0032 QStringList actions; 0033 actions.append(i18nc("Notification button to know if the pin is correct or not", "PIN correct")); 0034 actions.append(i18nc("Notification button to say that the PIN is wrong", "PIN incorrect")); 0035 0036 notification->setActions(actions); 0037 0038 connect(notification, &KNotification::action1Activated, this, &RequestConfirmation::pinCorrect); 0039 connect(notification, &KNotification::action2Activated, this, &RequestConfirmation::pinWrong); 0040 connect(notification, &KNotification::closed, this, &RequestConfirmation::pinWrong); 0041 connect(notification, &KNotification::ignored, this, &RequestConfirmation::pinWrong); 0042 connect(parent, SIGNAL(agentCanceled()), this, SLOT(pinWrong())); 0043 0044 notification->sendEvent(); 0045 } 0046 0047 void RequestConfirmation::pinCorrect() 0048 { 0049 qCDebug(BLUEDEVIL_KDED_LOG) << "PIN correct:" << m_device->name() << m_device->address(); 0050 0051 deleteLater(); 0052 Q_EMIT done(Accept); 0053 } 0054 0055 void RequestConfirmation::pinWrong() 0056 { 0057 qCDebug(BLUEDEVIL_KDED_LOG) << "PIN wrong:" << m_device->name() << m_device->address(); 0058 0059 deleteLater(); 0060 Q_EMIT done(Deny); 0061 }