From: Rafał Długołęcki Date: Tue, 26 Jan 2016 22:40:13 +0000 (+0100) Subject: Use separate class for logker options X-Git-Tag: 3.4-b1~41 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=5a6940c4321b2b3ec027d8b3d7d96079dc0cbd79;p=vlp.git Use separate class for logker options --- diff --git a/src/kernel/options.cpp b/src/kernel/options.cpp index 1a0a294..149e357 100644 --- a/src/kernel/options.cpp +++ b/src/kernel/options.cpp @@ -1,6 +1,7 @@ #include #include +#include "vlp/config.h" #include "options.h" OptionsDialog::OptionsDialog(QString configFilePath, QWidget * parent) @@ -68,88 +69,27 @@ void OptionsDialog::on_delConnectionButton_clicked() */ void OptionsDialog::loadConfig(const char * fname) { - config_t cfg; - config_setting_t *setting; - - /* Hack for checking if file exists without using external libs.*/ - FILE * file = fopen(fname, "rt"); - if (!file) { - fprintf(stderr, "Error: Cannot load configuration file %s!\n", fname); - exit(3); - } - /* File exists, so file has been locked. Release it. */ - - config_init(&cfg); - - /* Read the file. If there is an error, report it and exit. */ - if (!config_read(&cfg, file)) { - fprintf(stderr, "%s! In file %s, line %d\n", - config_error_text(&cfg), - config_error_file(&cfg), - config_error_line(&cfg)); - config_destroy(&cfg); - fclose(file); - exit(3); - } - - setting = config_lookup(&cfg, "node_number"); - if (setting) { - nodeNumber->setValue(config_setting_get_int(setting)); - } else { - fprintf(stderr, "%s! In file %s, '%s' was not found.\n", - "Warning", fname, "node_number"); - config_destroy(&cfg); - fclose(file); - exit(3); - } - - setting = config_lookup(&cfg, "type"); - if (setting) { - /* same as strcmp(..) == 0 */ - if (!strcmp(config_setting_get_string(setting), "explicit")) { - explicitConnectionMode->setEnabled(true); - registrationConnectionMode->setDisabled(true); - } else { - registrationConnectionMode->setEnabled(true); - explicitConnectionMode->setDisabled(true); - } - } else { - fprintf(stderr, "%s! In file %s, '%s' was not found.\n", "Warning", fname, "type"); + loglan::vlp::Config config; + config.load(fname); + + nodeNumber->setValue(config.getNodeNumber()); + switch(config.getConnectionType()) { + case loglan::vlp::EXPLICIT: + explicitConnectionMode->setEnabled(true); + registrationConnectionMode->setDisabled(true); + break; + case loglan::vlp::REGISTER: + registrationConnectionMode->setEnabled(true); + explicitConnectionMode->setDisabled(true); + break; } - setting = config_lookup(&cfg, "host"); - if (setting) { - switch(config_setting_type(setting)) { - /* TODO: Deprecated. Made for back compatibility. */ - case CONFIG_TYPE_STRING: - connections->addItem(config_setting_get_string(setting)); - break; - case CONFIG_TYPE_ARRAY: { - int size = config_setting_length(setting); - for (int i = 0; i < size; i++) { - connections->addItem(config_setting_get_string_elem(setting, i)); - } - break; - } - default: - fprintf(stderr, "%s! In file %s, bad entry type for %s." - " Will not be read.\n", - "Error", fname, "host"); - } - } else { - fprintf(stderr, "%s! In file %s, '%s' was not found.\n", - "Warning", fname, "host"); + std::vector hosts = config.getHosts(); + for (int i = 0; i < hosts.size(); i++) { + connections->addItem(hosts[i].c_str()); } - setting = config_lookup(&cfg, "progdir"); - if (setting){ - programsDirectory->setText(config_setting_get_string(setting)); - } else { - fprintf(stderr, "%s! In file %s, '%s' was not found.\n", "Warning", fname, "progdir"); - } - - config_destroy(&cfg); - fclose(file); + programsDirectory->setText(config.getProgramDir()); } void OptionsDialog::saveConfig(QString fname)