Changeset 790c0dc in subsurface


Ignore:
Timestamp:
Jun 12, 2017, 9:55:27 AM (13 days ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
ca59dbd
Parents:
c7a35098
git-author:
Jan Mulder <jlmulder@…> (06/10/17 01:09:56)
git-committer:
Dirk Hohndel <dirk@…> (06/12/17 09:55:27)
Message:

QML UI: add internal admin for virtual vendor

Added a list of paired BT devices for the "Paired BT Devices" vendor. The
devices under this vendor represent all BT devces that can be found
from the local BT interface. Some special processing is required, as
the BT provided data is (obviously) missing the specific data needed
to open a BT device using libdc code. This processing is not in
this commit, but will follow. This commit is preparation for that.

Signed-off-by: Jan Mulder <jlmulder@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • core/btdiscovery.cpp

    rb14a522 r790c0dc  
    6767        this_d.name = device.name();
    6868        btPairedDevices.append(this_d);
     69        struct btVendorProduct btVP;
    6970
    7071        QString newDevice = device.name();
     
    7879                qDebug() << id.toByteArray();
    7980        }
    80         qDebug() << "Found new device " + newDevice + " (" + device.address().toString() + ")";
    81         QString vendor, product;
     81        qDebug() << "Found new device:" << newDevice << device.address();
     82        QString vendor;
    8283        foreach (vendor, productList.keys()) {
    8384                if (productList[vendor].contains(newDevice)) {
    8485                        qDebug() << "this could be a " + vendor + " " +
    8586                                        (newDevice == "OSTC 3" ? "OSTC family" : newDevice);
    86                         struct btVendorProduct btVP;
    8787                        btVP.btdi = device;
    8888                        btVP.vendorIdx = vendorList.indexOf(vendor);
    8989                        btVP.productIdx = productList[vendor].indexOf(newDevice);
    90                         qDebug() << "adding new btDCs entry" << newDevice << btVP.vendorIdx << btVP.productIdx;
     90                        qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();;
    9191                        btDCs << btVP;
     92                        break;
    9293                }
    9394        }
     95        productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name);
     96
     97        btVP.btdi = device;
     98        btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
     99        btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
     100        qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx <<  btVP.btdi.address();
     101        btAllDevices << btVP;
    94102}
    95103
     
    99107}
    100108
     109QList <struct btVendorProduct> BTDiscovery::getBtAllDevices()
     110{
     111        return btAllDevices;
     112}
    101113
    102114// Android: As Qt is not able to pull the pairing data from a device, i
  • core/btdiscovery.h

    r74bf8d52 r790c0dc  
    4141#endif
    4242        QList<struct btVendorProduct> getBtDcs();
     43        QList<struct btVendorProduct> getBtAllDevices();
    4344#endif
    4445private:
    4546        static BTDiscovery *m_instance;
    4647#if defined(BT_SUPPORT)
    47         QList<struct btVendorProduct> btDCs;
     48        QList<struct btVendorProduct> btDCs;            // recognized DCs
     49        QList<struct btVendorProduct> btAllDevices;     // all paired BT stuff
    4850#endif
    4951#if defined(Q_OS_ANDROID)
  • core/downloadfromdcthread.cpp

    rf6e94e6 r790c0dc  
    243243}
    244244
    245 int DCDeviceData::getDetectedVendorIndex()
     245int DCDeviceData::getDetectedVendorIndex(const QString &currentText)
    246246{
    247247#if defined(BT_SUPPORT)
    248248        QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    249         if (!btDCs.isEmpty()) {
    250                 qDebug() << "getDetectedVendorIndex" << btDCs.first().vendorIdx;
     249        QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     250
     251        // Pick the vendor of the first confirmed find of a DC (if any), but
     252        // only return a true vendow, and not our virtual one
     253        if (!btDCs.isEmpty() && currentText != QObject::tr("Paired Bluetooth Devices")) {
     254                qDebug() << "getDetectedVendorIndex" << currentText << btDCs.first().vendorIdx;
    251255                return btDCs.first().vendorIdx;
    252256        }
     257
     258        // When the above fails, just pick the (one and only) virtual vendor
     259        if (!btAllDevices.isEmpty() && currentText == QObject::tr("Paired Bluetooth Devices")) {
     260                qDebug() << "getDetectedVendorIndex" << currentText << btAllDevices.first().vendorIdx;
     261                return btAllDevices.first().vendorIdx;
     262        }
    253263#endif
    254264        return -1;
    255265}
    256266
    257 int DCDeviceData::getDetectedProductIndex()
     267int DCDeviceData::getDetectedProductIndex(const QString &currentVendorText,
     268                                          const QString &currentProductText)
    258269{
    259270#if defined(BT_SUPPORT)
    260271        QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    261         if (!btDCs.isEmpty()) {
     272
     273        // Display in the QML UI, the first found dive computer that is been
     274        // detected as a possible real dive computer (and not some other paired
     275        // BT device
     276        if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
    262277                qDebug() << "getDetectedProductIndex" << btDCs.first().productIdx;
    263278                return btDCs.first().productIdx;
    264279        }
     280
     281        // if the above fails, display the selected paired device
     282        if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
     283                qDebug() << "getDetectedProductIndex" << productList[currentVendorText].indexOf(currentProductText);
     284                return productList[currentVendorText].indexOf(currentProductText);
     285        }
    265286#endif
    266287        return -1;
    267288}
    268289
    269 QString DCDeviceData::getDetectedDeviceAddress()
    270 {
    271 #if BT_SUPPORT
     290QString DCDeviceData::getDetectedDeviceAddress(const QString &currentVendorText,
     291                                               const QString &currentProductText)
     292{
     293#if defined(BT_SUPPORT)
    272294        QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    273         if (!btDCs.isEmpty()) {
     295        QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     296
     297        // Pull the BT address from the first found dive computer that is been
     298        // detected as a possible real dive computer (and not some other paired
     299        // BT device
     300        if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
    274301                QString btAddr = btDCs.first().btdi.address().toString();
    275302                qDebug() << "getDetectedDeviceAddress" << btAddr;
    276303                return btAddr;
    277304        }
     305
     306        // if the above fails, pull the BT address from the selected paired device
     307        // unsure being a dive computer
     308        if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
     309                int i =  productList[currentVendorText].indexOf(currentProductText);
     310                QString btAddr = btAllDevices[i].btdi.address().toString();
     311                qDebug() << "getDetectedDeviceAddress" << btAddr;
     312                return btAddr;
     313        }
     314
    278315        return QString();
    279316#endif
  • core/downloadfromdcthread.h

    rb14a522 r790c0dc  
    4646
    4747        Q_INVOKABLE QStringList getProductListFromVendor(const QString& vendor);
    48         Q_INVOKABLE int getDetectedVendorIndex();
    49         Q_INVOKABLE int getDetectedProductIndex();
    50         Q_INVOKABLE QString getDetectedDeviceAddress();
     48        Q_INVOKABLE int getDetectedVendorIndex(const QString &currentText);
     49        Q_INVOKABLE int getDetectedProductIndex(const QString &currentVendorText,
     50                                                const QString &currentProductText);
     51        Q_INVOKABLE QString getDetectedDeviceAddress(const QString &currentVendorText,
     52                                                     const QString &currentProductText);
    5153
    5254public slots:
  • mobile-widgets/qml/DownloadFromDiveComputer.qml

    rf6e94e6 r790c0dc  
    5858                                Layout.fillWidth: true
    5959                                model: vendorList
    60                                 currentIndex: downloadThread.data().getDetectedVendorIndex()
     60                                currentIndex: downloadThread.data().getDetectedVendorIndex(currentText)
    6161                                onCurrentTextChanged: {
    6262                                        comboProduct.model = downloadThread.data().getProductListFromVendor(comboVendor.currentText)
    63                                         if (currentIndex == downloadThread.data().getDetectedVendorIndex())
    64                                                 comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex()
     63                                        if (currentIndex == downloadThread.data().getDetectedVendorIndex(currentText))
     64                                                comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex(currentText, comboProduct.currentText)
    6565                                }
    6666                        }
     
    7575                        CheckBox {
    7676                                id: isBluetooth
    77                                 checked: downloadThread.data().getDetectedVendorIndex() != -1
     77                                checked: downloadThread.data().getDetectedVendorIndex(ComboBox.currentText) != -1
    7878                        }
    7979                }
     
    9090                                        text: qsTr("Retry")
    9191                                        if (downloadThread.deviceData.bluetoothMode) {
    92                                                 var addr = downloadThread.data().getDetectedDeviceAddress()
     92                                                var addr = downloadThread.data().getDetectedDeviceAddress(comboVendor.currentText,
     93                                                                                                                                                                  comboProduct.currentText)
    9394                                                if (addr !== "")
    9495                                                downloadThread.deviceData.devName = addr
Note: See TracChangeset for help on using the changeset viewer.