missing declare currentPath
[avrdudequi:avrdudequi.git] / programmersettings.cpp
1 #include "programmersettings.h"
2 #include <QDebug>
3
4
5 ProgrammerSettings::ProgrammerSettings(QMap<QString, QString> *progData, QWidget *parent)
6     : QDialog(parent)
7 {
8     okButton = new QPushButton("Ok");
9     cancelButton = new QPushButton("Cancel");
10
11     ptr_dataMap = progData;
12
13     int dtype = AvrDudeQuiDevices::SERIAL;
14     if ((progData->value("port.type") == "ttyACMx")
15             || (progData->value("port.type") == "ttyUSBx")) {
16         dtype = AvrDudeQuiDevices::TTYUSB;
17     } else
18     if (progData->value("port.type") == "parport") {
19         dtype = AvrDudeQuiDevices::PARPORT;
20     } else
21     if (progData->value("port.type") == "usb") {
22         dtype = AvrDudeQuiDevices::USB;
23     }
24
25     QList<QMap<QString,QString>*> devices = AvrDudeQuiDevices::deviceList(dtype, ptr_dataMap);
26     cBoxDeviceFiles = new QComboBox;
27     for(int i=0; i<devices.size(); i++) {
28         cBoxDeviceFiles->addItem(devices.at(i)->value("description"),
29                                  QVariant(devices.at(i)->value("device_file")));
30         //qDebug() << devices.at(i)->keys() << devices.at(i)->values();
31     }
32     if (cBoxDeviceFiles->count()) {
33         cBoxDeviceFiles->setDisabled(false);
34         okButton->setDisabled(false);
35
36     } else {
37         cBoxDeviceFiles->setDisabled(true);
38         okButton->setDisabled(true);
39     }
40     // non crea la combobox se il programmatore non ha il baudrate
41     baudrateIsEmpty = progData->value("port.baudrate").isEmpty();
42     if (!baudrateIsEmpty) {
43         cBoxBaudRate = new QComboBox;
44
45         cBoxBaudRate->addItem(progData->value("port.baudrate"));
46     }
47
48
49
50     VeLayout = new QVBoxLayout;
51     VeLayout->addWidget(cBoxDeviceFiles);
52     if (!baudrateIsEmpty)
53         VeLayout->addWidget(cBoxBaudRate);
54     VeLayout->addStretch();
55     HoLayout = new QHBoxLayout;
56     HoLayout->addWidget(cancelButton);
57     HoLayout->addWidget(okButton);
58     mLayout = new QVBoxLayout;
59     mLayout->addLayout(VeLayout);
60     mLayout->addLayout(HoLayout);
61
62     setLayout(mLayout);
63
64
65     connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
66     connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
67 }
68
69 ProgrammerSettings::~ProgrammerSettings()
70 {
71 //    delete cBoxBaudRate;
72 //    delete cBoxDeviceFiles;
73 //    delete okButton;
74 //    delete cancelButton;
75 //    delete VeLayout;
76 //    delete HoLayout;
77 //    delete mLayout;
78 }
79
80 void ProgrammerSettings::accept()
81 {
82     ptr_dataMap->insert("port.device_file",
83                         cBoxDeviceFiles->itemData(cBoxDeviceFiles->currentIndex()).toString());
84     // se il baudrate รจ vuoto l'oggetto cBoxBaudRate non esiste
85     if (!baudrateIsEmpty)
86         ptr_dataMap->insert("port.baudrate", cBoxBaudRate->currentText());
87
88
89     qDebug() << ptr_dataMap->value("port.device_file");
90     done(0);
91 }