ugly hackl to allow umlauts in pos text

This commit is contained in:
Martin Brodbeck 2018-08-06 14:59:57 +02:00
parent b2c64d8631
commit 23659078b4
4 changed files with 41 additions and 8 deletions

View File

@ -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("<nicht gefunden>");
return;
}
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
});
}
@ -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());

View File

@ -2,6 +2,14 @@
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QDialog" name="SettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>180</height>
</rect>
</property>
<property name="windowTitle">
<string>Einstellungen</string>
</property>
@ -24,7 +32,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="posPrinterDeviceEdit"/>
<widget class="QLineEdit" name="posPrinterDeviceEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="testPosPrinterButton">

View File

@ -1,3 +1,7 @@
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.62 REQUIRED)
find_package(LibUSB REQUIRED)
set(PRINTER_SOURCES

View File

@ -1,9 +1,11 @@
#include "posprinter.h"
#include <algorithm>
#include <exception>
#include <iostream>
#include <sstream>
#include <string>
#include <boost/algorithm/string.hpp>
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());