1 #include <QtGui/QDialog>
4 #include "vlp/config.h"
5 #include "OptionsDialog.h"
11 OptionsDialog::OptionsDialog(QString configFilePath, QWidget * parent)
16 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
17 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
19 loadConfig(configFilePath.toStdString().c_str());
22 OptionsDialog::~OptionsDialog()
27 * Adds IP address to the configuration.
28 * Additional window is displayed to add address to the list
30 void OptionsDialog::on_addConnectionButton_clicked()
32 QDialog d(this, Qt::Dialog);
33 QLabel lab("IP Address:", &d);
35 QPushButton ob("", &d);
36 QPushButton cb("", &d);
39 ob.setGeometry(30, 60, 80, 30);
42 lab.setGeometry(10, 10, 60, 30);
43 lab.setText("Address");
44 ed.setGeometry(70, 10, 140, 30);
45 cb.setGeometry(130, 60, 80, 30);
48 connect(&ob, SIGNAL(clicked()), &d, SLOT(accept()));
49 connect(&cb, SIGNAL(clicked()), &d, SLOT(reject()));
51 if (strcmp(ed.text().toAscii().data(), "") != 0) {
52 connections->addItem(ed.text());
58 * Deletes current address from available connections.
60 void OptionsDialog::on_delConnectionButton_clicked()
62 if (connections->currentRow() != -1) {
63 connections->takeItem(connections->currentRow());
68 * Loads configuration from the given file.
70 * @see QKernel::LoadConfig
72 * @param fname Filename of the configuration file.
74 void OptionsDialog::loadConfig(const char * fname)
76 loglan::vlp::Config config;
79 nodeNumber->setValue(config.getNodeNumber());
80 switch(config.getConnectionType()) {
81 case loglan::vlp::EXPLICIT:
82 explicitConnectionMode->setEnabled(true);
83 registrationConnectionMode->setDisabled(true);
85 case loglan::vlp::REGISTER:
86 registrationConnectionMode->setEnabled(true);
87 explicitConnectionMode->setDisabled(true);
91 for (auto host : config.getHosts()) {
92 connections->addItem(host.c_str());
95 programsDirectory->setText(config.getProgramDir());
98 void OptionsDialog::saveConfig(QString fname)
100 saveConfig(fname.toStdString().c_str());
103 void OptionsDialog::saveConfig(const char * fname)
105 loglan::vlp::Config config;
107 config.setProgramDir(programsDirectory->text().toStdString().c_str());
108 config.setNodeNumber(nodeNumber->value());
109 config.setConnectionType(
110 explicitConnectionMode->isChecked() ? EXPLICIT : REGISTER
113 std::vector<std::string> hosts;
114 for(int i = 0; i < connections->count(); i++) {
115 hosts.push_back(connections->item(i)->text().toStdString());
117 config.setHosts(hosts);