Changeset 23df593 in subsurface


Ignore:
Timestamp:
Jun 12, 2017, 11:05:08 AM (12 days ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
be8f20d
Parents:
5142d74
git-author:
Jan Mulder <jlmulder@…> (06/12/17 01:38:24)
git-committer:
Dirk Hohndel <dirk@…> (06/12/17 11:05:08)
Message:

Mobile: wrap up fixes for BT download on Android

Major functional change in this commit is the addition of found static BT devices
to the internal administration (on Android), in a way that is equivalent to
mobile-on-desktop. So, in both cases, the list of devices in the app are
as in the list of devices on the host OS (Linux or Android). To minimize code
duplication, the btDeviceDiscovered slot is split in two parts, the part to
act as slot for the Qt BT discovery agent (Linux, so mobile-on-desktop), and
the part only needed for Android.

Remaining to be fixed: the correct handling of the QML UI selection of
vendor/product. The first default dive computer is correctly detected,
all paired devices from the virtual vendow can be selected, but clicking
through vendors results in non logical selections. It is obvious why
this is, but a fix is not straigforward at this point.

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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • core/btdiscovery.cpp

    r5142d74 r23df593  
    5353#if defined(Q_OS_ANDROID) && defined(BT_SUPPORT)
    5454                getBluetoothDevices();
     55                // and add the paired devices to the internal data
     56                // So behaviour is same on Linux/Bluez stack and
     57                // Android/Java stack with respect to discovery
     58                for (int i = 0; i < btPairedDevices.length(); i++) {
     59                        btDeviceDiscoveredMain(btPairedDevices[i]);
     60
     61                }
    5562#endif
    5663                for (int i = 0; i < btPairedDevices.length(); i++) {
     
    93100        this_d.name = device.name();
    94101        btPairedDevices.append(this_d);
    95         struct btVendorProduct btVP;
    96 
    97         QString newDevice;
    98         dc_descriptor_t *newDC = getDeviceType(device.name());
    99         if (newDC)
    100                 newDevice = dc_descriptor_get_product(newDC);
    101          else
    102                 newDevice = device.name();
    103102
    104103        QList<QBluetoothUuid> serviceUuids = device.serviceUuids();
     
    107106                qDebug() << id.toByteArray();
    108107        }
    109         qDebug() << "Found new device:" << newDevice << device.address();
     108
     109        btDeviceDiscoveredMain(this_d);
     110}
     111
     112void BTDiscovery::btDeviceDiscoveredMain(const btPairedDevice &device)
     113{
     114        btVendorProduct btVP;
     115
     116        QString newDevice;
     117        dc_descriptor_t *newDC = getDeviceType(device.name);
     118        if (newDC)
     119                newDevice = dc_descriptor_get_product(newDC);
     120         else
     121                newDevice = device.name;
     122
     123        qDebug() << "Found new device:" << newDevice << device.address;
    110124        QString vendor;
    111125        if (newDC) foreach (vendor, productList.keys()) {
     
    113127                        qDebug() << "this could be a " + vendor + " " +
    114128                                        (newDevice == "OSTC 3" ? "OSTC family" : newDevice);
    115                         btVP.btdi = device;
     129                        btVP.btpdi = device;
    116130                        btVP.dcDescriptor = newDC;
    117131                        btVP.vendorIdx = vendorList.indexOf(vendor);
    118132                        btVP.productIdx = productList[vendor].indexOf(newDevice);
    119                         qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btdi.address();;
     133                        qDebug() << "adding new btDCs entry (detected DC)" << newDevice << btVP.vendorIdx << btVP.productIdx << btVP.btpdi.address;;
    120134                        btDCs << btVP;
    121135                        break;
    122136                }
    123137        }
    124         productList[QObject::tr("Paired Bluetooth Devices")].append(this_d.name + " (" + this_d.address.toString() + ")");
    125 
    126         btVP.btdi = device;
     138        productList[QObject::tr("Paired Bluetooth Devices")].append(device.name + " (" + device.address.toString() + ")");
     139
     140        btVP.btpdi = device;
    127141        btVP.dcDescriptor = newDC;
    128142        btVP.vendorIdx = vendorList.indexOf(QObject::tr("Paired Bluetooth Devices"));
    129         btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(this_d.name);
    130         qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx <<  btVP.btdi.address();
     143        btVP.productIdx = productList[QObject::tr("Paired Bluetooth Devices")].indexOf(device.name);
     144        qDebug() << "adding new btDCs entry (all paired)" << newDevice << btVP.vendorIdx << btVP.productIdx <<  btVP.btpdi.address;
    131145        btAllDevices << btVP;
    132146}
    133147
    134 QList <struct btVendorProduct> BTDiscovery::getBtDcs()
     148QList<BTDiscovery::btVendorProduct> BTDiscovery::getBtDcs()
    135149{
    136150        return btDCs;
    137151}
    138152
    139 QList <struct btVendorProduct> BTDiscovery::getBtAllDevices()
     153QList <BTDiscovery::btVendorProduct> BTDiscovery::getBtAllDevices()
    140154{
    141155        return btAllDevices;
  • core/btdiscovery.h

    r5142d74 r23df593  
    1212#include "core/libdivecomputer.h"
    1313
    14 struct btVendorProduct {
    15         QBluetoothDeviceInfo btdi;
    16         dc_descriptor_t *dcDescriptor;
    17         int vendorIdx;
    18         int productIdx;
    19 };
     14
    2015
    2116static dc_descriptor_t *getDeviceType(QString btName);
     
    4035                QString name;
    4136        };
     37
     38        struct btVendorProduct {
     39                btPairedDevice btpdi;
     40                dc_descriptor_t *dcDescriptor;
     41                int vendorIdx;
     42                int productIdx;
     43        };
     44
    4245        void btDeviceDiscovered(const QBluetoothDeviceInfo &device);
     46        void btDeviceDiscoveredMain(const btPairedDevice &device);
    4347#if defined(Q_OS_ANDROID)
    4448        void getBluetoothDevices();
    4549#endif
    46         QList<struct btVendorProduct> getBtDcs();
    47         QList<struct btVendorProduct> getBtAllDevices();
     50        QList<btVendorProduct> getBtDcs();
     51        QList<btVendorProduct> getBtAllDevices();
    4852#endif
    4953private:
  • core/downloadfromdcthread.cpp

    r5142d74 r23df593  
    246246{
    247247#if defined(BT_SUPPORT)
    248         QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    249         QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     248        QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     249        QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
    250250
    251251        // Pick the vendor of the first confirmed find of a DC (if any), but
     
    269269{
    270270#if defined(BT_SUPPORT)
    271         QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     271        QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    272272
    273273        // Display in the QML UI, the first found dive computer that is been
     
    292292{
    293293#if defined(BT_SUPPORT)
    294         QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    295         QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     294        QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     295        QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
    296296
    297297        // Pull the BT address from the first found dive computer that is been
     
    299299        // BT device
    300300        if (currentVendorText != QObject::tr("Paired Bluetooth Devices") && !btDCs.isEmpty()) {
    301                 QString btAddr = btDCs.first().btdi.address().toString();
     301                QString btAddr = btDCs.first().btpdi.address.toString();
    302302                qDebug() << "getDetectedDeviceAddress" << btAddr;
    303303                return btAddr;
     
    308308        if (currentVendorText == QObject::tr("Paired Bluetooth Devices")) {
    309309                int i =  productList[currentVendorText].indexOf(currentProductText);
    310                 QString btAddr = btAllDevices[i].btdi.address().toString();
     310                QString btAddr = btAllDevices[i].btpdi.address.toString();
    311311                qDebug() << "getDetectedDeviceAddress" << btAddr;
    312312                return btAddr;
     
    320320{
    321321#if defined(BT_SUPPORT)
    322         QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    323         QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     322        QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     323        QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
    324324
    325325        // Pull the vendor from the first found dive computer that is been
     
    348348{
    349349#if defined(BT_SUPPORT)
    350         QList<btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
    351         QList<btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
     350        QList<BTDiscovery::btVendorProduct> btDCs = BTDiscovery::instance()->getBtDcs();
     351        QList<BTDiscovery::btVendorProduct> btAllDevices = BTDiscovery::instance()->getBtAllDevices();
    352352
    353353        // Pull the product from the first found dive computer that is been
  • mobile-widgets/qml/DownloadFromDiveComputer.qml

    r5142d74 r23df593  
    5454                        columns: 2
    5555                        Kirigami.Label { text: qsTr(" Vendor name: ") }
     56                        property var vendoridx: downloadThread.data().getDetectedVendorIndex("")
    5657                        ComboBox {
    5758                                id: comboVendor
    5859                                Layout.fillWidth: true
    5960                                model: vendorList
    60                                 currentIndex: downloadThread.data().getDetectedVendorIndex(currentText)
     61                                currentIndex: parent.vendoridx
    6162                                onCurrentTextChanged: {
    62                                         comboProduct.model = downloadThread.data().getProductListFromVendor(comboVendor.currentText)
     63                                        comboProduct.model = downloadThread.data().getProductListFromVendor(currentText)
    6364                                        if (currentIndex == downloadThread.data().getDetectedVendorIndex(currentText))
    6465                                                comboProduct.currentIndex = downloadThread.data().getDetectedProductIndex(currentText, comboProduct.currentText)
     
    6869                        ComboBox {
    6970                                id: comboProduct
     71                                property var productidx: downloadThread.data().getDetectedProductIndex(comboVendor.currentText, currentText)
    7072                                Layout.fillWidth: true
    7173                                model: null
    72                                 currentIndex: -1
     74                                currentIndex: productidx
     75                                onModelChanged: {
     76                                        currentIndex = productidx
     77                                }
    7378                        }
    7479                        Kirigami.Label { text: qsTr("Bluetooth download:") }
Note: See TracChangeset for help on using the changeset viewer.