Changeset a55efcf in subsurface


Ignore:
Timestamp:
May 27, 2017, 8:07:35 AM (4 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
8056e16
Parents:
dec47e1
git-author:
Tomaz Canabrava <tcanabrava@…> (04/27/17 11:24:14)
git-committer:
Dirk Hohndel <dirk@…> (05/27/17 08:07:35)
Message:

Move the fill_computer_list() out of widgets

fill_computer_list() creates a Qt friendly
structure that contains all of the necessary
information about dive computers and it's
devices, and it's needed both in Qml and Widgets
to allow the user to download their dives.

This patch makes it possible to use the code
in QML without duplication.

Signed-off-by: Tomaz Canabrava <tcanabrava@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • core/downloadfromdcthread.cpp

    rdec47e1 ra55efcf  
    11#include "downloadfromdcthread.h"
    22#include "core/libdivecomputer.h"
     3
     4QStringList vendorList;
     5QHash<QString, QStringList> productList;
     6QMap<QString, dc_descriptor_t *> descriptorLookup;
    37
    48static QString str_error(const char *fmt, ...)
     
    3539                error = str_error(errorText, data->devname, data->vendor, data->product);
    3640}
     41
     42void fill_computer_list()
     43{
     44        dc_iterator_t *iterator = NULL;
     45        dc_descriptor_t *descriptor = NULL;
     46        struct mydescriptor *mydescriptor;
     47
     48        QStringList computer;
     49        dc_descriptor_iterator(&iterator);
     50        while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
     51                const char *vendor = dc_descriptor_get_vendor(descriptor);
     52                const char *product = dc_descriptor_get_product(descriptor);
     53
     54                if (!vendorList.contains(vendor))
     55                        vendorList.append(vendor);
     56
     57                if (!productList[vendor].contains(product))
     58                        productList[vendor].push_back(product);
     59
     60                descriptorLookup[QString(vendor) + QString(product)] = descriptor;
     61        }
     62        dc_iterator_free(iterator);
     63        Q_FOREACH (QString vendor, vendorList)
     64                qSort(productList[vendor]);
     65
     66        /* and add the Uemis Zurich which we are handling internally
     67          THIS IS A HACK as we magically have a data structure here that
     68          happens to match a data structure that is internal to libdivecomputer;
     69          this WILL BREAK if libdivecomputer changes the dc_descriptor struct...
     70          eventually the UEMIS code needs to move into libdivecomputer, I guess */
     71
     72        mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
     73        mydescriptor->vendor = "Uemis";
     74        mydescriptor->product = "Zurich";
     75        mydescriptor->type = DC_FAMILY_NULL;
     76        mydescriptor->model = 0;
     77
     78        if (!vendorList.contains("Uemis"))
     79                vendorList.append("Uemis");
     80
     81        if (!productList["Uemis"].contains("Zurich"))
     82                productList["Uemis"].push_back("Zurich");
     83
     84        descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
     85
     86        qSort(vendorList);
     87}
  • core/downloadfromdcthread.h

    rdec47e1 ra55efcf  
    33
    44#include <QThread>
     5#include <QMap>
     6#include <QHash>
     7
    58#include "dive.h"
    69#include "libdivecomputer.h"
     
    1922};
    2023
     24struct product {
     25        const char *product;
     26        dc_descriptor_t *descriptor;
     27        struct product *next;
     28};
     29
     30struct vendor {
     31        const char *vendor;
     32        struct product *productlist;
     33        struct vendor *next;
     34};
     35
     36struct mydescriptor {
     37        const char *vendor;
     38        const char *product;
     39        dc_family_t type;
     40        unsigned int model;
     41};
     42
     43/* This fills the vendor list QStringList and related members.
     44* this code needs to be reworked to be less ugly, but it will
     45* stay like this for now.
     46*/
     47void fill_computer_list();
     48extern  QStringList vendorList;
     49extern QHash<QString, QStringList> productList;
     50extern QMap<QString, dc_descriptor_t *> descriptorLookup;
     51
    2152#endif
  • desktop-widgets/downloadfromdivecomputer.cpp

    rdec47e1 ra55efcf  
    1515#include <QShortcut>
    1616
    17 struct product {
    18         const char *product;
    19         dc_descriptor_t *descriptor;
    20         struct product *next;
    21 };
    22 
    23 struct vendor {
    24         const char *vendor;
    25         struct product *productlist;
    26         struct vendor *next;
    27 };
    28 
    29 struct mydescriptor {
    30         const char *vendor;
    31         const char *product;
    32         dc_family_t type;
    33         unsigned int model;
    34 };
    35 
    3617namespace DownloadFromDcGlobal {
    3718        const char *err_string;
     
    5233        currentState(INITIAL)
    5334{
    54         fill_computer_list();
    55 
    5635        diveImportedModel = new DiveImportedModel(this);
    5736        diveImportedModel->setDiveTable(&downloadTable);
     
    252231                ui.device->setEnabled(false);
    253232        }
    254 }
    255 
    256 void DownloadFromDCWidget::fill_computer_list()
    257 {
    258         dc_iterator_t *iterator = NULL;
    259         dc_descriptor_t *descriptor = NULL;
    260         struct mydescriptor *mydescriptor;
    261 
    262         QStringList computer;
    263         dc_descriptor_iterator(&iterator);
    264         while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) {
    265                 const char *vendor = dc_descriptor_get_vendor(descriptor);
    266                 const char *product = dc_descriptor_get_product(descriptor);
    267 
    268                 if (!vendorList.contains(vendor))
    269                         vendorList.append(vendor);
    270 
    271                 if (!productList[vendor].contains(product))
    272                         productList[vendor].push_back(product);
    273 
    274                 descriptorLookup[QString(vendor) + QString(product)] = descriptor;
    275         }
    276         dc_iterator_free(iterator);
    277         Q_FOREACH (QString vendor, vendorList)
    278                 qSort(productList[vendor]);
    279 
    280         /* and add the Uemis Zurich which we are handling internally
    281            THIS IS A HACK as we magically have a data structure here that
    282            happens to match a data structure that is internal to libdivecomputer;
    283            this WILL BREAK if libdivecomputer changes the dc_descriptor struct...
    284            eventually the UEMIS code needs to move into libdivecomputer, I guess */
    285 
    286         mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor));
    287         mydescriptor->vendor = "Uemis";
    288         mydescriptor->product = "Zurich";
    289         mydescriptor->type = DC_FAMILY_NULL;
    290         mydescriptor->model = 0;
    291 
    292         if (!vendorList.contains("Uemis"))
    293                 vendorList.append("Uemis");
    294 
    295         if (!productList["Uemis"].contains("Zurich"))
    296                 productList["Uemis"].push_back("Zurich");
    297 
    298         descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor;
    299 
    300         qSort(vendorList);
    301233}
    302234
  • desktop-widgets/downloadfromdivecomputer.h

    rdec47e1 ra55efcf  
    6464        bool downloading;
    6565
    66         QStringList vendorList;
    67         QHash<QString, QStringList> productList;
    68         QMap<QString, dc_descriptor_t *> descriptorLookup;
    6966        device_data_t data;
    7067        int previousLast;
     
    7269        QStringListModel *vendorModel;
    7370        QStringListModel *productModel;
    74         void fill_computer_list();
    7571        void fill_device_list(int dc_type);
    7672        QString logFile;
  • subsurface-desktop-main.cpp

    r59ed9ea3 ra55efcf  
    1717#include "core/color.h"
    1818#include "core/qthelper.h"
     19#include "core/downloadfromdcthread.h" // for fill_computer_list
    1920
    2021#include <QStringList>
     
    8283         */
    8384        qsrand(time(NULL));
    84 
    8585        setup_system_prefs();
    8686        copy_prefs(&default_prefs, &prefs);
    8787        fill_profile_color();
     88        fill_computer_list();
    8889        parse_xml_init();
    8990        taglist_init_global();
  • subsurface-mobile-main.cpp

    r59ed9ea3 ra55efcf  
    1313#include "core/qthelper.h"
    1414#include "core/helpers.h"
     15#include "core/downloadfromdcthread.h"
    1516
    1617#include <QStringList>
     
    4546        prefs = default_prefs;
    4647        fill_profile_color();
     48        fill_computer_list();
     49
    4750        parse_xml_init();
    4851        taglist_init_global();
Note: See TracChangeset for help on using the changeset viewer.