| 
									
										
										
										
											2017-04-27 20:26:05 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | #ifndef BTDEVICESELECTIONDIALOG_H
 | 
					
						
							|  |  |  | #define BTDEVICESELECTIONDIALOG_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDialog>
 | 
					
						
							|  |  |  | #include <QListWidgetItem>
 | 
					
						
							|  |  |  | #include <QPointer>
 | 
					
						
							|  |  |  | #include <QtBluetooth/QBluetoothLocalDevice>
 | 
					
						
							|  |  |  | #include <QtBluetooth/qbluetoothglobal.h>
 | 
					
						
							|  |  |  | #include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 20:51:10 +03:00
										 |  |  | #if defined(Q_OS_WIN)
 | 
					
						
							|  |  |  | 	#include <QThread>
 | 
					
						
							|  |  |  | 	#include <winsock2.h>
 | 
					
						
							|  |  |  | 	#include <ws2bth.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	#define SUCCESS				0
 | 
					
						
							| 
									
										
										
										
											2015-09-19 19:31:21 +03:00
										 |  |  | 	#define BTH_ADDR_BUF_LEN                40
 | 
					
						
							| 
									
										
										
										
											2015-09-19 19:14:51 +03:00
										 |  |  | 	#define BTH_ADDR_PRETTY_STRING_LEN	17	// there are 6 two-digit hex values and 5 colons
 | 
					
						
							| 
									
										
										
										
											2015-08-18 20:51:10 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	#undef ERROR				// this is already declared in our headers
 | 
					
						
							|  |  |  | 	#undef IGNORE				// this is already declared in our headers
 | 
					
						
							|  |  |  | 	#undef DC_VERSION			// this is already declared in libdivecomputer header
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | namespace Ui { | 
					
						
							|  |  |  | 	class BtDeviceSelectionDialog; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-18 20:51:10 +03:00
										 |  |  | #if defined(Q_OS_WIN)
 | 
					
						
							|  |  |  | class WinBluetoothDeviceDiscoveryAgent : public QThread { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | signals: | 
					
						
							|  |  |  | 	void deviceDiscovered(const QBluetoothDeviceInfo &info); | 
					
						
							|  |  |  | 	void error(QBluetoothDeviceDiscoveryAgent::Error error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	WinBluetoothDeviceDiscoveryAgent(QObject *parent); | 
					
						
							|  |  |  | 	~WinBluetoothDeviceDiscoveryAgent(); | 
					
						
							|  |  |  | 	bool isActive() const; | 
					
						
							|  |  |  | 	QString errorToString() const; | 
					
						
							|  |  |  | 	QBluetoothDeviceDiscoveryAgent::Error error() const; | 
					
						
							|  |  |  | 	virtual void run(); | 
					
						
							|  |  |  | 	virtual void stop(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	bool running; | 
					
						
							|  |  |  | 	bool stopped; | 
					
						
							|  |  |  | 	QString lastErrorToString; | 
					
						
							|  |  |  | 	QBluetoothDeviceDiscoveryAgent::Error lastError; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | class BtDeviceSelectionDialog : public QDialog { | 
					
						
							|  |  |  | 	Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 	explicit BtDeviceSelectionDialog(QWidget *parent = 0); | 
					
						
							|  |  |  | 	~BtDeviceSelectionDialog(); | 
					
						
							|  |  |  | 	QString getSelectedDeviceAddress(); | 
					
						
							|  |  |  | 	QString getSelectedDeviceName(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							|  |  |  | 	void on_changeDeviceState_clicked(); | 
					
						
							|  |  |  | 	void on_save_clicked(); | 
					
						
							|  |  |  | 	void on_clear_clicked(); | 
					
						
							|  |  |  | 	void on_scan_clicked(); | 
					
						
							|  |  |  | 	void remoteDeviceScanFinished(); | 
					
						
							|  |  |  | 	void hostModeStateChanged(QBluetoothLocalDevice::HostMode mode); | 
					
						
							|  |  |  | 	void addRemoteDevice(const QBluetoothDeviceInfo &remoteDeviceInfo); | 
					
						
							| 
									
										
										
										
											2015-07-17 01:21:49 +03:00
										 |  |  | 	void itemClicked(QListWidgetItem *item); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	void displayPairingMenu(const QPoint &pos); | 
					
						
							|  |  |  | 	void pairingFinished(const QBluetoothAddress &address,QBluetoothLocalDevice::Pairing pairing); | 
					
						
							|  |  |  | 	void error(QBluetoothLocalDevice::Error error); | 
					
						
							| 
									
										
										
										
											2015-07-18 20:54:31 +03:00
										 |  |  | 	void deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error error); | 
					
						
							| 
									
										
										
										
											2015-07-18 17:50:18 +03:00
										 |  |  | 	void localDeviceChanged(int); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	Ui::BtDeviceSelectionDialog *ui; | 
					
						
							| 
									
										
										
										
											2015-08-18 20:51:10 +03:00
										 |  |  | #if defined(Q_OS_WIN)
 | 
					
						
							|  |  |  | 	WinBluetoothDeviceDiscoveryAgent *remoteDeviceDiscoveryAgent; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	QBluetoothLocalDevice *localDevice; | 
					
						
							|  |  |  | 	QBluetoothDeviceDiscoveryAgent *remoteDeviceDiscoveryAgent; | 
					
						
							| 
									
										
										
										
											2015-08-18 20:51:10 +03:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | 	QSharedPointer<QBluetoothDeviceInfo> selectedRemoteDeviceInfo; | 
					
						
							| 
									
										
										
										
											2015-07-18 17:50:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void updateLocalDeviceInformation(); | 
					
						
							| 
									
										
										
										
											2015-07-18 20:51:45 +03:00
										 |  |  | 	void initializeDeviceDiscoveryAgent(); | 
					
						
							| 
									
										
										
										
											2015-07-06 16:35:13 +03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // BTDEVICESELECTIONDIALOG_H
 |