diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/btdiscovery.cpp | 73 | ||||
-rw-r--r-- | core/btdiscovery.h | 17 | ||||
-rw-r--r-- | core/downloadfromdcthread.cpp | 11 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 3 |
4 files changed, 90 insertions, 14 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index 71d6353c5..8a9bedc73 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -9,6 +9,47 @@ extern QMap<QString, dc_descriptor_t *> descriptorLookup; BTDiscovery *BTDiscovery::m_instance = NULL; +ConnectionListModel::ConnectionListModel(QObject *parent) : + QAbstractListModel(parent) +{ +} + +QHash <int, QByteArray> ConnectionListModel::roleNames() const +{ + QHash<int, QByteArray> roles; + roles[AddressRole] = "address"; + return roles; +} + +QVariant ConnectionListModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < 0 || index.row() >= m_addresses.count()) + return QVariant(); + if (role != AddressRole) + return QVariant(); + return m_addresses[index.row()]; +} + +QString ConnectionListModel::address(int idx) const +{ + if (idx < 0 || idx >> m_addresses.count()) + return QString(); + return m_addresses[idx]; +} + +int ConnectionListModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return m_addresses.count(); +} + +void ConnectionListModel::addAddress(const QString address) +{ + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_addresses.append(address); + endInsertRows(); +} + static dc_descriptor_t *getDeviceType(QString btName) // central function to convert a BT name to a Subsurface known vendor/model pair { @@ -19,6 +60,7 @@ static dc_descriptor_t *getDeviceType(QString btName) if (btName.mid(4,2) == "3#") product = "OSTC 3"; else if (btName.mid(4,2) == "3+") product = "OSTC 3+"; else if (btName.mid(4,2) == "s#") product = "OSTC Sport"; + else if (btName.mid(4,2) == "s ") product = "OSTC Sport"; else if (btName.mid(4,2) == "4-") product = "OSTC 4"; else if (btName.mid(4,2) == "2-") product = "OSTC 2N"; // all OSTCs are HW_FAMILY_OSTC_3, so when we do not know, @@ -150,25 +192,28 @@ void BTDiscovery::btDeviceDiscoveredMain(const btPairedDevice &device) dc_descriptor_t *newDC = getDeviceType(device.name); if (newDC) newDevice = dc_descriptor_get_product(newDC); - else + else newDevice = device.name; qDebug() << "Found new device:" << newDevice << device.address; QString vendor; - if (newDC) foreach (vendor, productList.keys()) { - if (productList[vendor].contains(newDevice)) { - qDebug() << "this could be a " + vendor + " " + - (newDevice == "OSTC 3" ? "OSTC family" : newDevice); - btVP.btpdi = device; - btVP.dcDescriptor = newDC; - btVP.vendorIdx = vendorList.indexOf(vendor); - btVP.productIdx = productList[vendor].indexOf(newDevice); - qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;; - btDCs << btVP; - productList[QObject::tr("Paired Bluetooth Devices")].append(device.name + " (" + device.address + ")"); - return; + if (newDC) + foreach (vendor, productList.keys()) { + if (productList[vendor].contains(newDevice)) { + qDebug() << "this could be a " + vendor + " " + + (newDevice == "OSTC 3" ? "OSTC family" : newDevice); + btVP.btpdi = device; + btVP.dcDescriptor = newDC; + btVP.vendorIdx = vendorList.indexOf(vendor); + btVP.productIdx = productList[vendor].indexOf(newDevice); + qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;; + btDCs << btVP; + productList[QObject::tr("Paired Bluetooth Devices")].append(device.name + " (" + device.address + ")"); + connectionListModel.addAddress(device.address + " (" + device.name + ")"); + return; + } } - } + connectionListModel.addAddress(device.address); qDebug() << "Not recognized as dive computer"; } diff --git a/core/btdiscovery.h b/core/btdiscovery.h index 4b4e4b802..71df24f24 100644 --- a/core/btdiscovery.h +++ b/core/btdiscovery.h @@ -5,6 +5,7 @@ #include <QObject> #include <QString> #include <QLoggingCategory> +#include <QAbstractListModel> #if defined(BT_SUPPORT) #include <QBluetoothLocalDevice> #include <QBluetoothDeviceDiscoveryAgent> @@ -17,6 +18,22 @@ #include <QAndroidJniEnvironment> #endif +class ConnectionListModel : public QAbstractListModel { + Q_OBJECT +public: + enum CLMRole { + AddressRole = Qt::UserRole + 1 + }; + ConnectionListModel(QObject *parent = 0); + QHash<int, QByteArray> roleNames() const; + QVariant data(const QModelIndex &index, int role = AddressRole) const; + QString address(int idx) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + void addAddress(const QString address); +private: + QStringList m_addresses; +}; + class BTDiscovery : public QObject { Q_OBJECT diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 76b314da7..8abc46bcd 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -7,6 +7,7 @@ QStringList vendorList; QHash<QString, QStringList> productList; static QHash<QString, QStringList> mobileProductList; // BT, BLE or FTDI supported DCs for mobile QMap<QString, dc_descriptor_t *> descriptorLookup; +ConnectionListModel connectionListModel; static QString str_error(const char *fmt, ...) { @@ -193,6 +194,16 @@ QStringList DCDeviceData::getProductListFromVendor(const QString &vendor) return productList[vendor]; } +int DCDeviceData::getMatchingAddress(const QString &vendor, const QString &product) +{ + for (int i = 0; i < connectionListModel.rowCount(); i++) { + QString address = connectionListModel.address(i); + if (address.contains(product)) + return i; + } + return -1; +} + DCDeviceData * DownloadThread::data() { return m_data; diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h index fb9c73965..51b2a825f 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -45,6 +45,8 @@ public: device_data_t* internalData(); Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor); + Q_INVOKABLE int getMatchingAddress(const QString &vendor, const QString &product); + Q_INVOKABLE int getDetectedVendorIndex(const QString ¤tText); Q_INVOKABLE int getDetectedProductIndex(const QString ¤tVendorText, const QString ¤tProductText); @@ -102,5 +104,6 @@ void fill_computer_list(); extern QStringList vendorList; extern QHash<QString, QStringList> productList; extern QMap<QString, dc_descriptor_t *> descriptorLookup; +extern ConnectionListModel connectionListModel; #endif |