2024-11-22 23:26:42 +03:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "settings/settings.h"
|
|
|
|
#include "ui_settingsdialog.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
2024-12-04 18:44:40 +03:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
2024-11-22 23:26:42 +03:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent)
|
|
|
|
: QDialog(parent), ui(new Ui::settingsdialog),
|
|
|
|
settings(Settings(get_path_relative_to_home(
|
|
|
|
".local/share/checks_parser/settings.json"))) {
|
|
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->OFDModulesDirEdit->setText(QString::fromStdString(settings.get_all_settings()["ofds_modules_dir"]));
|
|
|
|
ui->OFDModulesURLEdit->setText(QString::fromStdString(settings.get_all_settings()["ofds_modules_url"]));
|
|
|
|
ui->storesModulesDirEdit->setText(QString::fromStdString(settings.get_all_settings()["stores_modules_dir"]));
|
|
|
|
ui->storesModulesURLEdit->setText(QString::fromStdString(settings.get_all_settings()["stores_modules_url"]));
|
|
|
|
|
|
|
|
ui->goodsNamePositionSpin->setValue(this->settings.get_all_settings()["output_order"]["goods_name"]["position"]);
|
|
|
|
ui->goodsNameAliasEdit->setText(QString::fromStdString(this->settings.get_all_settings()["output_order"]["goods_name"]["name"]));
|
|
|
|
|
|
|
|
ui->goodsPricePerUnitPositionSpin->setValue(this->settings.get_all_settings()["output_order"]["goods_price_per_unit"]["position"]);
|
|
|
|
ui->goodsPricePerUnitAliasEdit->setText(QString::fromStdString(this->settings.get_all_settings()["output_order"]["goods_price_per_unit"]["name"]));
|
|
|
|
|
|
|
|
ui->goodsQuantityPositionSpin->setValue(this->settings.get_all_settings()["output_order"]["goods_quantity"]["position"]);
|
|
|
|
ui->goodsQuantityAliasEdit->setText(QString::fromStdString(this->settings.get_all_settings()["output_order"]["goods_quantity"]["name"]));
|
|
|
|
|
|
|
|
ui->goodsNetWeightPositionSpin->setValue(this->settings.get_all_settings()["output_order"]["goods_net_weight"]["position"]);
|
|
|
|
ui->goodsNetWeightAliasEdit->setText(QString::fromStdString(this->settings.get_all_settings()["output_order"]["goods_net_weight"]["name"]));
|
|
|
|
|
|
|
|
ui->goodsTotalPositionSpin->setValue(this->settings.get_all_settings()["output_order"]["goods_total"]["position"]);
|
|
|
|
ui->goodsTotalAliasEdit->setText(QString::fromStdString(this->settings.get_all_settings()["output_order"]["goods_total"]["name"]));
|
|
|
|
|
|
|
|
ui->printHeaderCheckBox->setChecked(this->settings.get_all_settings()["print_header"]);
|
|
|
|
ui->printTotalCheckBox->setChecked(this->settings.get_all_settings()["print_total"]);
|
2024-12-04 18:44:40 +03:00
|
|
|
|
2024-12-05 14:53:20 +03:00
|
|
|
|
|
|
|
int currentLanguageIndex = 0;
|
|
|
|
if (!this->settings.get_all_settings().contains("language")) {
|
|
|
|
currentLanguageIndex = ui->languageComboBox->findText(QLocale::system().name());
|
|
|
|
if (currentLanguageIndex < 0) {
|
|
|
|
currentLanguageIndex = ui->languageComboBox->findText("en_US");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentLanguageIndex = ui->languageComboBox->findText(QString::fromStdString(this->settings.get_all_settings()["language"]));
|
|
|
|
}
|
|
|
|
ui->languageComboBox->setCurrentIndex(currentLanguageIndex);
|
|
|
|
|
2024-11-22 23:26:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog() { delete ui; }
|
|
|
|
|
|
|
|
void SettingsDialog::on_OFDModulesDirEdit_editingFinished() {
|
|
|
|
this->settings.alter_setting("ofds_modules_dir",
|
|
|
|
ui->OFDModulesDirEdit->text().toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_storesModulesDirEdit_editingFinished() {
|
|
|
|
this->settings.alter_setting("stores_modules_dir",
|
|
|
|
ui->storesModulesDirEdit->text().toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_OFDModulesURLEdit_editingFinished() {
|
|
|
|
this->settings.alter_setting("ofds_modules_url",
|
|
|
|
ui->OFDModulesURLEdit->text().toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_storesModulesURLEdit_editingFinished() {
|
|
|
|
this->settings.alter_setting("stores_modules_url",
|
|
|
|
ui->storesModulesURLEdit->text().toStdString());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsNamePositionSpin_valueChanged(int value) {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_name"]["position"] =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
void SettingsDialog::on_goodsNameAliasEdit_editingFinished() {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_name"]["name"] =
|
|
|
|
ui->goodsNameAliasEdit->text().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsPricePerUnitPositionSpin_valueChanged(int value) {
|
|
|
|
this->settings
|
|
|
|
.get_all_settings()["output_order"]["goods_price_per_unit"]["position"] =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsPricePerUnitAliasEdit_editingFinished() {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_price_per_unit"]["name"] =
|
|
|
|
ui->goodsPricePerUnitAliasEdit->text().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsQuantityPositionSpin_valueChanged(int value) {
|
|
|
|
this->settings
|
|
|
|
.get_all_settings()["output_order"]["goods_quantity"]["position"] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsQuantityAliasEdit_editingFinished() {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_quantity"]["name"] =
|
|
|
|
ui->goodsQuantityAliasEdit->text().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsNetWeightPositionSpin_valueChanged(int value) {
|
|
|
|
this->settings
|
|
|
|
.get_all_settings()["output_order"]["goods_net_weight"]["position"] =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsNetWeightAliasEdit_editingFinished() {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_net_weight"]["name"] =
|
|
|
|
ui->goodsNetWeightAliasEdit->text().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsTotalPositionSpin_valueChanged(int value) {
|
|
|
|
this->settings
|
|
|
|
.get_all_settings()["output_order"]["goods_total"]["position"] =
|
|
|
|
value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_goodsTotalAliasEdit_editingFinished() {
|
|
|
|
this->settings.get_all_settings()["output_order"]["goods_total"]["name"] =
|
|
|
|
ui->goodsTotalAliasEdit->text().toStdString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_printHeaderCheckBox_stateChanged(int value) {
|
|
|
|
this->settings.get_all_settings()["print_header"] = (value? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_printTotalCheckBox_stateChanged(int value) {
|
|
|
|
this->settings.get_all_settings()["print_total"] = (value? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::on_buttonBox_accepted() { this->settings.flush(); }
|
|
|
|
|
|
|
|
void SettingsDialog::on_buttonBox_rejected() { this->close(); }
|
|
|
|
|
2024-12-04 18:44:40 +03:00
|
|
|
void SettingsDialog::on_languageComboBox_currentTextChanged(const QString &changed) {
|
2024-12-05 14:53:20 +03:00
|
|
|
if (this->settings.get_all_settings().contains("language")) {
|
|
|
|
if (changed == QString::fromStdString(this->settings.get_all_settings()["language"])) return;
|
|
|
|
} else {
|
|
|
|
if (changed == QLocale::system().name()) return;
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:44:40 +03:00
|
|
|
this->settings.get_all_settings()["language"] = changed.toStdString();
|
|
|
|
|
|
|
|
QMessageBox infoDialog;
|
|
|
|
infoDialog.setText(tr("You need to restart program to apply language changes"));
|
|
|
|
infoDialog.setIcon(QMessageBox::Information);
|
|
|
|
infoDialog.setWindowTitle(tr("Restart required"));
|
|
|
|
infoDialog.exec();
|
|
|
|
}
|
2024-11-22 23:26:42 +03:00
|
|
|
|