File indexing completed on 2024-04-28 04:57:01

0001 /**
0002  * SPDX-FileCopyrightText: 2015 Vineet Garg <grg.vineet@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef KDECONNECT_PAIRINGHANDLER_H
0008 #define KDECONNECT_PAIRINGHANDLER_H
0009 
0010 #include "device.h"
0011 #include "networkpacket.h"
0012 #include "pairstate.h"
0013 
0014 #include <QTimer>
0015 
0016 class KDECONNECTCORE_EXPORT PairingHandler : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     const static int pairingTimeoutMsec = 30 * 1000; // 30 seconds of timeout
0021 
0022     PairingHandler(Device *parent, PairState initialState);
0023 
0024     void packetReceived(const NetworkPacket &np);
0025 
0026     PairState pairState()
0027     {
0028         return m_pairState;
0029     }
0030 
0031 public Q_SLOTS:
0032     bool requestPairing();
0033     bool acceptPairing();
0034     void cancelPairing();
0035     void unpair();
0036 
0037 Q_SIGNALS:
0038     void incomingPairRequest();
0039     void pairingFailed(const QString &errorMessage);
0040     void pairingSuccessful();
0041     void unpaired();
0042 
0043 private:
0044     void pairingDone();
0045 
0046     QTimer m_pairingTimeout;
0047     Device *m_device;
0048     PairState m_pairState;
0049 
0050 private Q_SLOTS:
0051     void pairingTimeout();
0052 };
0053 
0054 #endif // KDECONNECT_PAIRINGHANDLER_H