diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index a7533fb..b14622a 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -17,7 +16,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par QSettings settings{}; int cashPointNo = settings.value("global/cashPointNo").toInt(); - QString posPrinterDevice = settings.value("global/posPrinterDevice").toString(); + // QString posPrinterDevice = settings.value("global/posPrinterDevice").toString(); int feeInPercent = settings.value("global/feeInPercent").toInt(); int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt(); @@ -25,44 +24,26 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par market_ = dynamic_cast(parent)->getMarketplace(); ui_.cashPointNoSpinBox->setValue(cashPointNo); - ui_.posPrinterDeviceEdit->setText(posPrinterDevice); + // ui_.posPrinterDeviceEdit->setText(posPrinterDevice); ui_.feePercentSpinBox->setValue(feeInPercent); ui_.maxFeeSpinBox->setValue(maxFeeInEuro); connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() { using namespace std::string_literals; try { - if (ui_.posPrinterDeviceEdit->text().isEmpty()) { - PosPrinter printer; - printer.printTest(); - } else { - std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString(); - std::string delimiter = ":"; - PrinterDevice printerDevice; - try { - printerDevice.idVendor = std::stoi( - posPrinterDeviceString.substr(0, posPrinterDeviceString.find(delimiter)), 0, - 16); - printerDevice.idProduct = std::stoi( - posPrinterDeviceString.substr(posPrinterDeviceString.find(delimiter) + 1), - 0, 16); - } catch (std::exception&) { - QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe", - QString("Eingabeformat für den Bondrucker (hexadezimale IDs): " - ":\nBeispiel: 0416:5011"), - QMessageBox::StandardButton::Ok, this) - .exec(); - return; - } + PosPrinter printer; + printer.printTest(); + if (printer.isValid()) + this->ui_.posPrinterDeviceEdit->setText(""); + else + this->ui_.posPrinterDeviceEdit->setText(""); - PosPrinter printer(printerDevice); - printer.printTest(); - } } catch (std::runtime_error& err) { QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler", QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, this) .exec(); + this->ui_.posPrinterDeviceEdit->setText(""); return; } }); @@ -75,7 +56,7 @@ void SettingsDialog::accept() int oldCashPointNo = settings.value("global/cashPointNo").toInt(); int newCashPointNo = ui_.cashPointNoSpinBox->value(); - settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text()); + // settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text()); settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value()); settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value()); diff --git a/src/gui/settingsdialog.ui b/src/gui/settingsdialog.ui index d965f7f..8aefef0 100644 --- a/src/gui/settingsdialog.ui +++ b/src/gui/settingsdialog.ui @@ -7,7 +7,7 @@ 0 0 400 - 203 + 180 @@ -33,8 +33,8 @@ - - <idVendor>:<idProduct> + + false diff --git a/src/printer/posprinter.cpp b/src/printer/posprinter.cpp index 9c6609d..9ff4dec 100644 --- a/src/printer/posprinter.cpp +++ b/src/printer/posprinter.cpp @@ -20,9 +20,7 @@ const std::string PosPrinter::Command::FONT_SIZE_BIG = {0x1b, 0x21, 0x10}; const std::string PosPrinter::Command::FONT_SIZE_NORMAL = {0x1b, 0x21, 0x00}; const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03}; -PosPrinter::PosPrinter() : PosPrinter(PrinterDevice()) {} - -PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(printerDevice) +PosPrinter::PosPrinter() { int retValue; @@ -37,23 +35,12 @@ PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(prin libusb_exit(contextPtr_); throw std::runtime_error("Could not receive device list"); } - int numDevice = -1; - for (int i = 0; i < devCount; ++i) { libusb_device_descriptor desc; libusb_get_device_descriptor(devList[i], &desc); - - if (printerDevice_.idVendor == 0) { - for (const auto& supported : supportedPrinters_.models) { - if (desc.idVendor == supported.first && desc.idProduct == supported.second) { - numDevice = i; - break; - } - } - } else { - if (desc.idVendor == printerDevice_.idVendor && - desc.idProduct == printerDevice_.idProduct) { + for (const auto& supported : supportedPrinters_.models) { + if (desc.idVendor == supported.first && desc.idProduct == supported.second) { numDevice = i; break; } diff --git a/src/printer/posprinter.h b/src/printer/posprinter.h index 04db2f1..140b6cc 100644 --- a/src/printer/posprinter.h +++ b/src/printer/posprinter.h @@ -16,16 +16,10 @@ struct SupportedPrinters { }; }; -struct PrinterDevice { - int idVendor{}; - int idProduct{}; -}; - class PosPrinter { public: PosPrinter(); - PosPrinter(const PrinterDevice& printerDevice); ~PosPrinter(); void write(const std::string& text); void printHeader(); @@ -49,7 +43,6 @@ class PosPrinter libusb_context* contextPtr_{}; libusb_device_handle* devicePtr_{}; SupportedPrinters supportedPrinters_; - PrinterDevice printerDevice_{}; }; #endif \ No newline at end of file