mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
dec47e11cd
commit
a55efcf7d8
6 changed files with 87 additions and 73 deletions
|
@ -1,6 +1,10 @@
|
||||||
#include "downloadfromdcthread.h"
|
#include "downloadfromdcthread.h"
|
||||||
#include "core/libdivecomputer.h"
|
#include "core/libdivecomputer.h"
|
||||||
|
|
||||||
|
QStringList vendorList;
|
||||||
|
QHash<QString, QStringList> productList;
|
||||||
|
QMap<QString, dc_descriptor_t *> descriptorLookup;
|
||||||
|
|
||||||
static QString str_error(const char *fmt, ...)
|
static QString str_error(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -34,3 +38,50 @@ void DownloadThread::run()
|
||||||
if (errorText)
|
if (errorText)
|
||||||
error = str_error(errorText, data->devname, data->vendor, data->product);
|
error = str_error(errorText, data->devname, data->vendor, data->product);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void 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);
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define DOWNLOADFROMDCTHREAD_H
|
#define DOWNLOADFROMDCTHREAD_H
|
||||||
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
|
|
||||||
|
@ -18,4 +21,32 @@ private:
|
||||||
device_data_t *data;
|
device_data_t *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* This fills the vendor list QStringList and related members.
|
||||||
|
* this code needs to be reworked to be less ugly, but it will
|
||||||
|
* stay like this for now.
|
||||||
|
*/
|
||||||
|
void fill_computer_list();
|
||||||
|
extern QStringList vendorList;
|
||||||
|
extern QHash<QString, QStringList> productList;
|
||||||
|
extern QMap<QString, dc_descriptor_t *> descriptorLookup;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,25 +14,6 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
|
||||||
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 {
|
namespace DownloadFromDcGlobal {
|
||||||
const char *err_string;
|
const char *err_string;
|
||||||
};
|
};
|
||||||
|
@ -51,8 +32,6 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
|
||||||
ostcFirmwareCheck(0),
|
ostcFirmwareCheck(0),
|
||||||
currentState(INITIAL)
|
currentState(INITIAL)
|
||||||
{
|
{
|
||||||
fill_computer_list();
|
|
||||||
|
|
||||||
diveImportedModel = new DiveImportedModel(this);
|
diveImportedModel = new DiveImportedModel(this);
|
||||||
diveImportedModel->setDiveTable(&downloadTable);
|
diveImportedModel->setDiveTable(&downloadTable);
|
||||||
vendorModel = new QStringListModel(vendorList);
|
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()
|
void DownloadFromDCWidget::on_search_clicked()
|
||||||
{
|
{
|
||||||
if (ui.vendor->currentText() == "Uemis") {
|
if (ui.vendor->currentText() == "Uemis") {
|
||||||
|
|
|
@ -63,15 +63,11 @@ private:
|
||||||
DownloadThread *thread;
|
DownloadThread *thread;
|
||||||
bool downloading;
|
bool downloading;
|
||||||
|
|
||||||
QStringList vendorList;
|
|
||||||
QHash<QString, QStringList> productList;
|
|
||||||
QMap<QString, dc_descriptor_t *> descriptorLookup;
|
|
||||||
device_data_t data;
|
device_data_t data;
|
||||||
int previousLast;
|
int previousLast;
|
||||||
|
|
||||||
QStringListModel *vendorModel;
|
QStringListModel *vendorModel;
|
||||||
QStringListModel *productModel;
|
QStringListModel *productModel;
|
||||||
void fill_computer_list();
|
|
||||||
void fill_device_list(int dc_type);
|
void fill_device_list(int dc_type);
|
||||||
QString logFile;
|
QString logFile;
|
||||||
QString dumpFile;
|
QString dumpFile;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "desktop-widgets/diveplanner.h"
|
#include "desktop-widgets/diveplanner.h"
|
||||||
#include "core/color.h"
|
#include "core/color.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
#include "core/downloadfromdcthread.h" // for fill_computer_list
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -81,10 +82,10 @@ int main(int argc, char **argv)
|
||||||
* the constant numbers we used to get before.
|
* the constant numbers we used to get before.
|
||||||
*/
|
*/
|
||||||
qsrand(time(NULL));
|
qsrand(time(NULL));
|
||||||
|
|
||||||
setup_system_prefs();
|
setup_system_prefs();
|
||||||
copy_prefs(&default_prefs, &prefs);
|
copy_prefs(&default_prefs, &prefs);
|
||||||
fill_profile_color();
|
fill_profile_color();
|
||||||
|
fill_computer_list();
|
||||||
parse_xml_init();
|
parse_xml_init();
|
||||||
taglist_init_global();
|
taglist_init_global();
|
||||||
init_ui();
|
init_ui();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "core/color.h"
|
#include "core/color.h"
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
#include "core/helpers.h"
|
#include "core/helpers.h"
|
||||||
|
#include "core/downloadfromdcthread.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -44,6 +45,8 @@ int main(int argc, char **argv)
|
||||||
default_prefs.units = IMPERIAL_units;
|
default_prefs.units = IMPERIAL_units;
|
||||||
prefs = default_prefs;
|
prefs = default_prefs;
|
||||||
fill_profile_color();
|
fill_profile_color();
|
||||||
|
fill_computer_list();
|
||||||
|
|
||||||
parse_xml_init();
|
parse_xml_init();
|
||||||
taglist_init_global();
|
taglist_init_global();
|
||||||
init_ui();
|
init_ui();
|
||||||
|
|
Loading…
Reference in a new issue