kima2/src/gui/settingsdialog.cpp

121 lines
4.8 KiB
C++
Raw Normal View History

2018-07-30 13:40:58 +02:00
#include "settingsdialog.h"
2018-08-07 08:31:43 +02:00
#include "mainwindow.h"
2019-10-10 08:09:16 +02:00
#include <core/database.h>
2022-07-07 15:31:32 +02:00
#include <core/utils.h>
2019-10-10 08:09:16 +02:00
#include <printer/posprinter.h>
#include <printer/utils.h>
2018-07-30 13:40:58 +02:00
2018-08-06 13:39:12 +02:00
#include <exception>
2018-08-15 08:50:46 +02:00
#include <stdexcept>
2018-08-06 13:39:12 +02:00
2018-07-30 13:40:58 +02:00
#include <QMessageBox>
#include <QSettings>
2022-07-07 15:31:32 +02:00
SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
2018-07-30 13:40:58 +02:00
{
2022-07-07 15:37:33 +02:00
m_ui.setupUi(this);
2018-07-30 13:40:58 +02:00
QSettings settings{};
int cashPointNo = settings.value("global/cashPointNo").toInt();
QString commune = settings.value("global/commune", "Dettingen").toString();
2018-08-15 08:03:44 +02:00
QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
2018-08-15 10:51:57 +02:00
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint").toString();
2018-07-30 13:40:58 +02:00
int feeInPercent = settings.value("global/feeInPercent").toInt();
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
2018-08-07 20:39:15 +02:00
if (parent)
2022-07-07 15:37:33 +02:00
m_market = dynamic_cast<MainWindow *>(parent)->getMarketplace();
2018-08-07 08:31:43 +02:00
2022-07-07 15:37:33 +02:00
m_ui.cashPointNoSpinBox->setValue(cashPointNo);
m_ui.communeEdit->setText(commune);
m_ui.posPrinterDeviceEdit->setText(posPrinterDevice);
m_ui.posPrinterEndpointEdit->setText(posPrinterEndpoint);
m_ui.feePercentSpinBox->setValue(feeInPercent);
m_ui.maxFeeSpinBox->setValue(maxFeeInEuro);
2018-08-06 09:59:06 +02:00
2022-07-07 15:37:33 +02:00
connect(m_ui.testPosPrinterButton, &QPushButton::clicked, this, [this]() {
2018-08-06 13:39:12 +02:00
using namespace std::string_literals;
try {
2022-07-07 15:37:33 +02:00
if (m_ui.posPrinterDeviceEdit->text().isEmpty()) {
2018-08-15 08:03:44 +02:00
PosPrinter printer;
printer.printTest();
} else {
2022-07-07 15:37:33 +02:00
std::string posPrinterDeviceString = m_ui.posPrinterDeviceEdit->text().toStdString();
2018-08-15 10:51:57 +02:00
std::string posPrinterEndpointString =
2022-07-07 15:37:33 +02:00
m_ui.posPrinterEndpointEdit->text().toStdString();
2018-08-15 10:51:57 +02:00
2018-08-15 08:50:46 +02:00
try {
2018-08-15 10:51:57 +02:00
auto printerDevice =
convertToPosPrinterDevice(posPrinterDeviceString, posPrinterEndpointString);
if (printerDevice) {
PosPrinter printer(*printerDevice);
printer.printTest();
}
2022-07-07 15:31:32 +02:00
} catch (std::exception &) {
2018-08-15 08:50:46 +02:00
QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe",
2018-08-15 10:51:57 +02:00
QString("Eingabeformat für Device (hexadezimale IDs): "
"<VendorID>:<ProductID>\nBeispiel: 0416:5011\n "
"Eingabeformat für Endpoint: Hexadezimale Adresse"),
2018-08-15 08:50:46 +02:00
QMessageBox::StandardButton::Ok, this)
.exec();
return;
}
}
2022-07-07 15:31:32 +02:00
} catch (std::runtime_error &err) {
2018-08-06 13:39:12 +02:00
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
2018-08-06 20:57:12 +02:00
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
this)
2018-08-06 13:39:12 +02:00
.exec();
2018-08-06 20:57:12 +02:00
return;
2018-08-06 13:39:12 +02:00
}
2018-08-06 09:59:06 +02:00
});
2018-07-30 13:40:58 +02:00
}
void SettingsDialog::accept()
{
QSettings settings;
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
2022-07-07 15:37:33 +02:00
int newCashPointNo = m_ui.cashPointNoSpinBox->value();
2018-07-30 13:40:58 +02:00
2022-07-07 15:37:33 +02:00
settings.setValue("global/commune", m_ui.communeEdit->text().trimmed());
settings.setValue("global/posPrinterDevice", m_ui.posPrinterDeviceEdit->text().trimmed());
settings.setValue("global/posPrinterEndpoint", m_ui.posPrinterEndpointEdit->text().trimmed());
settings.setValue("global/feeInPercent", m_ui.feePercentSpinBox->value());
settings.setValue("global/maxFeeInEuro", m_ui.maxFeeSpinBox->value());
2018-07-30 13:40:58 +02:00
if (oldCashPointNo != newCashPointNo) {
2018-08-07 08:31:43 +02:00
int result{0};
2022-07-07 15:37:33 +02:00
if (m_market && m_market->getSales().size() > 0) {
2018-08-07 08:31:43 +02:00
result = QMessageBox(QMessageBox::Icon::Question, "Sind Sie sicher?",
"Möchten Sie die Kassen-Nr wirklich ändern? Diese muss über alle "
"Installationen hinweg eindeutig sein.",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No,
this)
.exec();
} else {
result = QMessageBox::Yes;
}
2018-07-30 13:40:58 +02:00
if (result == QMessageBox::Yes) {
try {
Database().updateCashPointNo(oldCashPointNo, newCashPointNo);
2022-07-07 15:31:32 +02:00
} catch (std::exception &ex) {
2018-07-30 13:40:58 +02:00
std::string errMsg("Das Ändern der Kassen-Nr. ist fehlgeschlagen: ");
errMsg.append(ex.what());
2018-08-06 13:39:12 +02:00
QMessageBox(QMessageBox::Icon::Critical, "Fehler", errMsg.c_str(),
QMessageBox::StandardButton::Ok, this)
2018-07-30 13:40:58 +02:00
.exec();
QDialog::accept();
return;
}
2022-07-07 15:37:33 +02:00
settings.setValue("global/cashPointNo", m_ui.cashPointNoSpinBox->value());
2018-07-30 13:40:58 +02:00
}
}
QDialog::accept();
2019-10-10 08:09:16 +02:00
}