From a55efcf7d88e0521d754508b7ff9f0e89692950a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 27 Apr 2017 20:24:14 +0200 Subject: 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 Signed-off-by: Dirk Hohndel --- desktop-widgets/downloadfromdivecomputer.cpp | 68 ---------------------------- desktop-widgets/downloadfromdivecomputer.h | 4 -- 2 files changed, 72 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index c38ffe980..f27a3cb73 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -14,25 +14,6 @@ #include #include -struct product { - const char *product; - dc_descriptor_t *descriptor; - struct product *next; -}; - -struct vendor { - const char *vendor; - struct product *productlist; - struct vendor *next; -}; - -struct mydescriptor { - const char *vendor; - const char *product; - dc_family_t type; - unsigned int model; -}; - namespace DownloadFromDcGlobal { const char *err_string; }; @@ -51,8 +32,6 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : ostcFirmwareCheck(0), currentState(INITIAL) { - fill_computer_list(); - diveImportedModel = new DiveImportedModel(this); diveImportedModel->setDiveTable(&downloadTable); vendorModel = new QStringListModel(vendorList); @@ -253,53 +232,6 @@ void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product } } -void DownloadFromDCWidget::fill_computer_list() -{ - dc_iterator_t *iterator = NULL; - dc_descriptor_t *descriptor = NULL; - struct mydescriptor *mydescriptor; - - QStringList computer; - dc_descriptor_iterator(&iterator); - while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) { - const char *vendor = dc_descriptor_get_vendor(descriptor); - const char *product = dc_descriptor_get_product(descriptor); - - if (!vendorList.contains(vendor)) - vendorList.append(vendor); - - if (!productList[vendor].contains(product)) - productList[vendor].push_back(product); - - descriptorLookup[QString(vendor) + QString(product)] = descriptor; - } - dc_iterator_free(iterator); - Q_FOREACH (QString vendor, vendorList) - qSort(productList[vendor]); - - /* and add the Uemis Zurich which we are handling internally - THIS IS A HACK as we magically have a data structure here that - happens to match a data structure that is internal to libdivecomputer; - this WILL BREAK if libdivecomputer changes the dc_descriptor struct... - eventually the UEMIS code needs to move into libdivecomputer, I guess */ - - mydescriptor = (struct mydescriptor *)malloc(sizeof(struct mydescriptor)); - mydescriptor->vendor = "Uemis"; - mydescriptor->product = "Zurich"; - mydescriptor->type = DC_FAMILY_NULL; - mydescriptor->model = 0; - - if (!vendorList.contains("Uemis")) - vendorList.append("Uemis"); - - if (!productList["Uemis"].contains("Zurich")) - productList["Uemis"].push_back("Zurich"); - - descriptorLookup["UemisZurich"] = (dc_descriptor_t *)mydescriptor; - - qSort(vendorList); -} - void DownloadFromDCWidget::on_search_clicked() { if (ui.vendor->currentText() == "Uemis") { diff --git a/desktop-widgets/downloadfromdivecomputer.h b/desktop-widgets/downloadfromdivecomputer.h index 906cc6eb7..f137bcd5e 100644 --- a/desktop-widgets/downloadfromdivecomputer.h +++ b/desktop-widgets/downloadfromdivecomputer.h @@ -63,15 +63,11 @@ private: DownloadThread *thread; bool downloading; - QStringList vendorList; - QHash productList; - QMap descriptorLookup; device_data_t data; int previousLast; QStringListModel *vendorModel; QStringListModel *productModel; - void fill_computer_list(); void fill_device_list(int dc_type); QString logFile; QString dumpFile; -- cgit v1.2.3-70-g09d2