Index: sources/view/settings/VBluetooth.cpp =================================================================== diff -u -raa8f2c87c14c68d1fda6da2540d47144990a596c -rb252cd2777aadbce2d04aa32cc275f193de0cf52 --- sources/view/settings/VBluetooth.cpp (.../VBluetooth.cpp) (revision aa8f2c87c14c68d1fda6da2540d47144990a596c) +++ sources/view/settings/VBluetooth.cpp (.../VBluetooth.cpp) (revision b252cd2777aadbce2d04aa32cc275f193de0cf52) @@ -21,23 +21,40 @@ #include "GuiController.h" #include "BluetoothInterface.h" -VIEW_DEF_CLASS(VBluetooth) - using namespace Bluetooth; using namespace Model; +View::VBluetooth::VBluetooth(QObject *parent) : QAbstractListModel(parent) { + initConnections(); +} + /*! * \brief VBluetooth::initConnections * Makes the necessary connections. Called inside VIEW_DEF_CLASS */ void View::VBluetooth::initConnections() { - connect(&_BluetoothInterface, SIGNAL(didStateChange (BluetoothData )), - this , SLOT( onStateChange (Model::MBluetooth ))); + connect(&_BluetoothInterface, SIGNAL(didStateChange (BluetoothData )), + this , SLOT( onStateChange (BluetoothData ))); + connect(&_BluetoothInterface, SIGNAL(didDeviceChange(BluetoothDeviceData)), + this , SLOT( onDeviceChange(BluetoothDeviceData))); + connect(this , SIGNAL(didDeviceSelect(QString, QString )), + this , SLOT( onDeviceSelect(QString, QString ))); } -void View::VBluetooth::onStateChange(const Model::MBluetooth &vData) +int View::VBluetooth::rowCount(const QModelIndex &) const { + return _devices.count(); +} + +void View::VBluetooth::reset() { + beginResetModel(); + _devices.clear(); + endResetModel(); +} + +void View::VBluetooth::onStateChange(const BluetoothData &vData) +{ if ( vData.state == MBluetooth::eIS_Local_Error_POST ) { isInvalid( true ); notify( vData.state ); @@ -56,9 +73,9 @@ switch (vData.state) { // The device name is not always available and the interface may be in investigation. - case MBluetooth::eIS_Scan_Found : case MBluetooth::eIS_Scan_NotFound : case MBluetooth::eIS_Scan_Discover : + case MBluetooth::eIS_Scan_Found : deviceAddr (vData.deviceAddr ); deviceName (vData.deviceName ); devicePair (vData.devicePair ); @@ -79,8 +96,37 @@ detailValue (vData.detailValue ); break; - default: + case MBluetooth::eIS_Scan_Start : + reset(); break; + case MBluetooth::eIS_Idle : + case MBluetooth::eIS_Local_Connect : + case MBluetooth::eIS_Local_Error_Invalid : + case MBluetooth::eIS_Local_Error_POST : + case MBluetooth::eIS_Local_Error_Off : + case MBluetooth::eIS_Local_Error_IO : + case MBluetooth::eIS_Local_Error : + case MBluetooth::eIS_Local_Disconnect : + case MBluetooth::eIS_Scan_Reject : + case MBluetooth::eIS_Scan_Stop : + case MBluetooth::eIS_Scan_Done : + case MBluetooth::eIS_Device_Init : + case MBluetooth::eIS_Device_Start : + case MBluetooth::eIS_Device_Connect : + case MBluetooth::eIS_Device_Error_Init : + case MBluetooth::eIS_Device_Error : + case MBluetooth::eIS_Device_Done : + case MBluetooth::eIS_Device_Disconnect : + case MBluetooth::eIS_Service_Start : + case MBluetooth::eIS_Service_Error : + case MBluetooth::eIS_Service_Discover : + case MBluetooth::eIS_Service_Detail : + case MBluetooth::eIS_Service_Detail_Invalid : + case MBluetooth::eIS_Service_Detail_Error : + case MBluetooth::eIS_Service_Detail_Done : + case MBluetooth::eIS_Service_Done : + case MBluetooth::eIS_Close : + break; } error (vData.error ); @@ -89,6 +135,30 @@ notify( vData.state ); } +void View::VBluetooth::onDeviceChange(const BluetoothDeviceData &vDevice) +{ + int row = 0; + while (row < _devices.count()) ++row; + beginInsertRows(QModelIndex(), row, row); + _devices.insert(row, vDevice); + endInsertRows(); + + qDebug() << _devices.count(); + + for (auto device: _devices) { + qDebug() << device.addr << device.name << device.pair; + } + +} + +void View::VBluetooth::onDeviceSelect(const QString &vAddr, const QString &vName) +{ + BluetoothDeviceData data; + data.addr = vAddr; + data.name = vName; + emit _BluetoothInterface.didDeviceSelect(data); +} + QString View::VBluetooth::toText(MBluetooth::InterfaceStates vState) const { QString message;