mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Populate the Vendor && Dive computer information.
This uses the QStringListModel to populate the items of the QComboBoxes. I used a QHash to hold every Computer of a particular Vendor. so, products[vendor] gives me the full list of products from each vendor. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
a542b25bde
commit
f4acbb02e4
5 changed files with 94 additions and 21 deletions
1
Makefile
1
Makefile
|
@ -53,7 +53,6 @@ SOURCES = \
|
||||||
device.c \
|
device.c \
|
||||||
dive.c \
|
dive.c \
|
||||||
divelist.c \
|
divelist.c \
|
||||||
download-dialog.c \
|
|
||||||
equipment.c \
|
equipment.c \
|
||||||
file.c \
|
file.c \
|
||||||
info.c \
|
info.c \
|
||||||
|
|
|
@ -9,24 +9,7 @@ const char *default_dive_computer_vendor;
|
||||||
const char *default_dive_computer_product;
|
const char *default_dive_computer_product;
|
||||||
const char *default_dive_computer_device;
|
const char *default_dive_computer_device;
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vendor *dc_list;
|
struct vendor *dc_list;
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,8 @@ void exit_ui(void)
|
||||||
#endif
|
#endif
|
||||||
if (existing_filename)
|
if (existing_filename)
|
||||||
free((void *)existing_filename);
|
free((void *)existing_filename);
|
||||||
if (default_dive_computer_device)
|
// if (default_dive_computer_device)
|
||||||
free((void *)default_dive_computer_device);
|
// free((void *)default_dive_computer_device);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_filename(const char *filename, gboolean force)
|
void set_filename(const char *filename, gboolean force)
|
||||||
|
|
|
@ -2,9 +2,29 @@
|
||||||
#include "ui_downloadfromdivecomputer.h"
|
#include "ui_downloadfromdivecomputer.h"
|
||||||
|
|
||||||
#include "../libdivecomputer.h"
|
#include "../libdivecomputer.h"
|
||||||
|
#include <cstdlib>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QStringListModel>
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -17,6 +37,65 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget* parent, Qt::WindowFlags f) :
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->progressBar->setMinimum(0);
|
ui->progressBar->setMinimum(0);
|
||||||
ui->progressBar->setMaximum(100);
|
ui->progressBar->setMaximum(100);
|
||||||
|
fill_computer_list();
|
||||||
|
|
||||||
|
vendorModel = new QStringListModel(vendorList);
|
||||||
|
ui->vendor->setModel(vendorModel);
|
||||||
|
ui->diveComputerName->setModel(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString& vendor)
|
||||||
|
{
|
||||||
|
QAbstractItemModel *currentModel = ui->diveComputerName->model();
|
||||||
|
if (!currentModel)
|
||||||
|
return;
|
||||||
|
|
||||||
|
productModel = new QStringListModel(productList[vendor]);
|
||||||
|
ui->diveComputerName->setModel(productModel);
|
||||||
|
|
||||||
|
// Memleak - but deleting gives me a crash.
|
||||||
|
//currentModel->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadFromDCWidget::fill_computer_list()
|
||||||
|
{
|
||||||
|
dc_iterator_t *iterator = NULL;
|
||||||
|
dc_descriptor_t *descriptor = NULL;
|
||||||
|
struct mydescriptor *mydescriptor;
|
||||||
|
struct vendor *dcl;
|
||||||
|
struct product *pl;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
dc_iterator_free(iterator);
|
||||||
|
|
||||||
|
/* 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" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadFromDCWidget::on_cancel_clicked()
|
void DownloadFromDCWidget::on_cancel_clicked()
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef DOWNLOADFROMDIVECOMPUTER_H
|
#ifndef DOWNLOADFROMDIVECOMPUTER_H
|
||||||
#define DOWNLOADFROMDIVECOMPUTER_H
|
#define DOWNLOADFROMDIVECOMPUTER_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
namespace Ui{
|
namespace Ui{
|
||||||
class DownloadFromDiveComputer;
|
class DownloadFromDiveComputer;
|
||||||
|
@ -29,6 +31,7 @@ private:
|
||||||
device_data_t *data;
|
device_data_t *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QStringListModel;
|
||||||
class DownloadFromDCWidget : public QDialog{
|
class DownloadFromDCWidget : public QDialog{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -37,10 +40,19 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void on_ok_clicked();
|
void on_ok_clicked();
|
||||||
void on_cancel_clicked();
|
void on_cancel_clicked();
|
||||||
|
|
||||||
|
void on_vendor_currentIndexChanged(const QString& vendor);
|
||||||
private:
|
private:
|
||||||
Ui::DownloadFromDiveComputer *ui;
|
Ui::DownloadFromDiveComputer *ui;
|
||||||
InterfaceThread *thread;
|
InterfaceThread *thread;
|
||||||
bool downloading;
|
bool downloading;
|
||||||
|
|
||||||
|
QStringList vendorList;
|
||||||
|
QHash<QString, QStringList> productList;
|
||||||
|
|
||||||
|
QStringListModel *vendorModel;
|
||||||
|
QStringListModel *productModel;
|
||||||
|
void fill_computer_list();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Reference in a new issue