File indexing completed on 2024-12-08 04:54:21

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * SPDX-FileCopyrightText: 2010 Alejandro Fiestas Olivares <afiestas@kde.org>
0005  * SPDX-FileCopyrightText: 2010-2011 UFO Coders <info@ufocoders.com>
0006  *
0007  * SPDX-License-Identifier: LGPL-2.0-or-later
0008  */
0009 
0010 #include "connect.h"
0011 #include "../bluewizard.h"
0012 #include "bluedevil_wizard.h"
0013 
0014 #include <QTimer>
0015 
0016 #include <BluezQt/Device>
0017 #include <BluezQt/PendingCall>
0018 
0019 ConnectPage::ConnectPage(BlueWizard *parent)
0020     : QWizardPage(parent)
0021     , m_wizard(parent)
0022 {
0023     setupUi(this);
0024 }
0025 
0026 int ConnectPage::nextId() const
0027 {
0028     if (m_success) {
0029         return BlueWizard::Success;
0030     }
0031     return BlueWizard::Fail;
0032 }
0033 
0034 void ConnectPage::initializePage()
0035 {
0036     qCDebug(BLUEDEVIL_WIZARD_LOG) << "Initialize Connect Page";
0037 
0038     m_wizard->setButtonLayout(wizardButtonsLayout());
0039     connecting->setText(i18nc("Connecting to a Bluetooth device", "Connecting to %1…", m_wizard->device()->name()));
0040 
0041     m_wizard->device()->setTrusted(true);
0042 
0043     BluezQt::PendingCall *call = m_wizard->device()->connectToDevice();
0044     connect(call, &BluezQt::PendingCall::finished, this, &ConnectPage::connectFinished);
0045 }
0046 
0047 void ConnectPage::connectFinished(BluezQt::PendingCall *call)
0048 {
0049     qCDebug(BLUEDEVIL_WIZARD_LOG) << "Connect finished:";
0050     qCDebug(BLUEDEVIL_WIZARD_LOG) << "\t error     : " << (bool)call->error();
0051     qCDebug(BLUEDEVIL_WIZARD_LOG) << "\t errorText : " << call->errorText();
0052 
0053     m_success = !call->error();
0054     QTimer::singleShot(500, m_wizard, &BlueWizard::next);
0055 }
0056 
0057 QList<QWizard::WizardButton> ConnectPage::wizardButtonsLayout() const
0058 {
0059     QList<QWizard::WizardButton> list;
0060     list << QWizard::Stretch;
0061     list << QWizard::CancelButton;
0062     return list;
0063 }
0064 
0065 #include "moc_connect.cpp"