From 23659078b4a311805b0a140a3c89900cacb00119 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 6 Aug 2018 14:59:57 +0200 Subject: [PATCH] ugly hackl to allow umlauts in pos text --- src/gui/settingsdialog.cpp | 9 ++++++--- src/gui/settingsdialog.ui | 14 +++++++++++++- src/printer/CMakeLists.txt | 4 ++++ src/printer/posprinter.cpp | 22 ++++++++++++++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index bb63e4a..3506238 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -14,12 +14,12 @@ 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(); ui_.cashPointNoSpinBox->setValue(cashPointNo); - ui_.posPrinterDeviceEdit->setText(posPrinterDevice); + //ui_.posPrinterDeviceEdit->setText(posPrinterDevice); ui_.feePercentSpinBox->setValue(feeInPercent); ui_.maxFeeSpinBox->setValue(maxFeeInEuro); @@ -32,7 +32,10 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler", QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, this) .exec(); + this->ui_.posPrinterDeviceEdit->setText(""); + return; } + this->ui_.posPrinterDeviceEdit->setText(""); }); } @@ -43,7 +46,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 f9019e4..8aefef0 100644 --- a/src/gui/settingsdialog.ui +++ b/src/gui/settingsdialog.ui @@ -2,6 +2,14 @@ SettingsDialog + + + 0 + 0 + 400 + 180 + + Einstellungen @@ -24,7 +32,11 @@ - + + + false + + diff --git a/src/printer/CMakeLists.txt b/src/printer/CMakeLists.txt index 4f698d7..35865e2 100644 --- a/src/printer/CMakeLists.txt +++ b/src/printer/CMakeLists.txt @@ -1,3 +1,7 @@ +set(Boost_USE_STATIC_LIBS ON) + +find_package(Boost 1.62 REQUIRED) + find_package(LibUSB REQUIRED) set(PRINTER_SOURCES diff --git a/src/printer/posprinter.cpp b/src/printer/posprinter.cpp index eb32ceb..1e8aacb 100644 --- a/src/printer/posprinter.cpp +++ b/src/printer/posprinter.cpp @@ -1,9 +1,11 @@ #include "posprinter.h" +#include #include #include #include #include +#include const std::string PosPrinter::Command::RESET = {0x1b, 0x40}; const std::string PosPrinter::Command::ENCODING = {'\x1b', '\x74', 16}; @@ -90,10 +92,22 @@ void PosPrinter::write(const std::string& text) { if (devicePtr_ == NULL) return; - int length = text.length(); + + using namespace std::string_literals; + std::string text_escaped = text; + boost::replace_all(text_escaped, "ä", "\xe4"); + boost::replace_all(text_escaped, "ö", "\xf6"); + boost::replace_all(text_escaped, "ü", "\xfc"); + boost::replace_all(text_escaped, "Ä", "\xc4"); + boost::replace_all(text_escaped, "Ö", "\xd6"); + boost::replace_all(text_escaped, "Ü", "\xdc"); + boost::replace_all(text_escaped, "€", "\x80"); + + int length = text_escaped.length(); int actual{0}; - int retValue = libusb_bulk_transfer(devicePtr_, (0x03 | LIBUSB_ENDPOINT_OUT), - (unsigned char*)text.c_str(), length, &actual, 10000); + int retValue = + libusb_bulk_transfer(devicePtr_, (0x03 | LIBUSB_ENDPOINT_OUT), + (unsigned char*)text_escaped.c_str(), length, &actual, 10000); if (retValue != 0 || actual != length) std::cerr << "Write Error" << std::endl; } @@ -116,7 +130,7 @@ void PosPrinter::printTest() std::stringstream commandStream; commandStream << Command::ENCODING; commandStream << "Der Drucker kann von KIMA2\nangesprochen werden.\n\n" - << u8"Beachten Sie, dass nicht\nalle Modelle Strichcodes\nausdrucken können."; + << "Beachten Sie, dass nicht\nalle Modelle Strichcodes\nausdrucken können."; commandStream << Command::FEED; printHeader(); write(commandStream.str());