X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fkernel%2Foptions.cpp;h=5830ca02b94c05d59802f75ac5a6ba0124453799;hb=cec0990bb3507f23b196891002cd25f80e8bbb40;hp=1a0a294678a416216ba2fba86506fb7fb5b461e6;hpb=595f80b4f2420ff252f137cacb22a7d4b6f0850d;p=vlp.git diff --git a/src/kernel/options.cpp b/src/kernel/options.cpp index 1a0a294..5830ca0 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,26 @@ 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"); + for (auto host : config.getHosts()) { + connections->addItem(host.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)