[198e35]: qeilin / modelconfig.cpp  Maximize  Restore  History

Download this file

70 lines (58 with data), 2.3 kB

 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
/*
* qeilin is a Linux utility to control settings of EIZO monitors.
* Copyright (C) 2014 Lukáš Jirkovský <l.jirkovsky@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "modelconfig.h"
#include <eilin.h>
#include <QSettings>
ModelConfig::ModelConfig(libusb_device *device, QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f)
{
char *descriptor = eilin_getDeviceDescriptor(device);
m_descriptorHexStr = QString(descriptor);
free(descriptor);
// prepare UI
setupUi(this);
connect(comboModel, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(changeModel(const QString &)));
// set ui labels etc.
labelNumBus->setText(QString::number(libusb_get_bus_number(device)));
labelNumPort->setText(QString::number(libusb_get_port_number(device)));
eilin_vector_item *model_list = eilin_get_model_list();
eilin_vector_item *item = model_list;
while (item) {
const char *model = (const char *) item->data;
comboModel->addItem(model);
item = item->next;
}
eilin_free_model_list(model_list);
}
void ModelConfig::changeModel(const QString &model) {
m_model = model;
}
QString ModelConfig::getModel()
{
QSettings settings;
// if there are no settings for the descriptor, show the dialog
if (! settings.contains(m_descriptorHexStr)) {
if (exec() == QDialog::Accepted) {
// store the model in settings
settings.setValue(m_descriptorHexStr, m_model);
}
else {
throw std::runtime_error("Model not set");
}
}
return settings.value(m_descriptorHexStr).toString();
}
#include "modelconfig.moc"