1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#include "configuredivecomputerdialog.h"
#include "ui_configuredivecomputerdialog.h"
#include "../divecomputer.h"
#include "../libdivecomputer.h"
#include "../helpers.h"
#include "../display.h"
#include "../divelist.h"
#include "configuredivecomputer.h"
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;
};
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigureDiveComputerDialog),
config(0),
vendorModel(0),
productModel(0)
{
ui->setupUi(this);
config = new ConfigureDiveComputer(this);
connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
connect (config, SIGNAL(deviceSettings(QString)), ui->availableDetails, SLOT(setText(QString)));
fill_computer_list();
vendorModel = new QStringListModel(vendorList);
ui->vendor->setModel(vendorModel);
if (default_dive_computer_vendor) {
ui->vendor->setCurrentIndex(ui->vendor->findText(default_dive_computer_vendor));
productModel = new QStringListModel(productList[default_dive_computer_vendor]);
ui->product->setModel(productModel);
if (default_dive_computer_product)
ui->product->setCurrentIndex(ui->product->findText(default_dive_computer_product));
}
if (default_dive_computer_device)
ui->device->setEditText(default_dive_computer_device);
memset(&device_data, 0, sizeof(device_data));
connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
}
ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog()
{
delete ui;
}
void ConfigureDiveComputerDialog::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);
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);
}
static void fillDeviceList(const char *name, void *data)
{
QComboBox *comboBox = (QComboBox *)data;
comboBox->addItem(name);
}
void ConfigureDiveComputerDialog::fill_device_list(int dc_type)
{
int deviceIndex;
ui->device->clear();
deviceIndex = enumerate_devices(fillDeviceList, ui->device, dc_type);
if (deviceIndex >= 0)
ui->device->setCurrentIndex(deviceIndex);
}
void ConfigureDiveComputerDialog::on_vendor_currentIndexChanged(const QString &vendor)
{
int dcType = DC_TYPE_SERIAL;
QAbstractItemModel *currentModel = ui->product->model();
if (!currentModel)
return;
productModel = new QStringListModel(productList[vendor]);
ui->product->setModel(productModel);
if (vendor == QString("Uemis"))
dcType = DC_TYPE_UEMIS;
fill_device_list(dcType);
}
void ConfigureDiveComputerDialog::on_product_currentIndexChanged(const QString &product)
{
dc_descriptor_t *descriptor = NULL;
descriptor = descriptorLookup[ui->vendor->currentText() + product];
// call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL
if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) {
// if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box.
ui->device->setEnabled(true);
} else {
// otherwise disable the device node box
ui->device->setEnabled(false);
}
}
void ConfigureDiveComputerDialog::readSettings()
{
ui->statusLabel->clear();
ui->errorLabel->clear();
getDeviceData();
config->readSettings(&device_data);
}
void ConfigureDiveComputerDialog::configMessage(QString msg)
{
ui->statusLabel->setText(msg);
}
void ConfigureDiveComputerDialog::configError(QString err)
{
ui->errorLabel->setText(err);
}
void ConfigureDiveComputerDialog::getDeviceData()
{
device_data.devname = strdup(ui->device->currentText().toUtf8().data());
device_data.vendor = strdup(ui->vendor->currentText().toUtf8().data());
device_data.product = strdup(ui->product->currentText().toUtf8().data());
device_data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()];
device_data.deviceid = device_data.diveid = 0;
set_default_dive_computer(device_data.vendor, device_data.product);
set_default_dive_computer_device(device_data.devname);
}
void ConfigureDiveComputerDialog::on_cancel_clicked()
{
this->close();
}
|