Merge branch 'choose_printer'
This commit is contained in:
commit
dc74c59287
4 changed files with 55 additions and 16 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include <posprinter.h>
|
#include <posprinter.h>
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
@ -16,7 +17,7 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
|
||||||
|
|
||||||
QSettings settings{};
|
QSettings settings{};
|
||||||
int cashPointNo = settings.value("global/cashPointNo").toInt();
|
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 feeInPercent = settings.value("global/feeInPercent").toInt();
|
||||||
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
||||||
|
|
||||||
|
@ -24,26 +25,44 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
|
||||||
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
|
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
|
||||||
|
|
||||||
ui_.cashPointNoSpinBox->setValue(cashPointNo);
|
ui_.cashPointNoSpinBox->setValue(cashPointNo);
|
||||||
// ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
||||||
ui_.feePercentSpinBox->setValue(feeInPercent);
|
ui_.feePercentSpinBox->setValue(feeInPercent);
|
||||||
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
|
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
|
||||||
|
|
||||||
connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() {
|
connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() {
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
try {
|
try {
|
||||||
PosPrinter printer;
|
if (ui_.posPrinterDeviceEdit->text().isEmpty()) {
|
||||||
printer.printTest();
|
PosPrinter printer;
|
||||||
if (printer.isValid())
|
printer.printTest();
|
||||||
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
|
} else {
|
||||||
else
|
std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString();
|
||||||
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
|
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): "
|
||||||
|
"<VendorID>:<ProductID>\nBeispiel: 0416:5011"),
|
||||||
|
QMessageBox::StandardButton::Ok, this)
|
||||||
|
.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PosPrinter printer(printerDevice);
|
||||||
|
printer.printTest();
|
||||||
|
}
|
||||||
} catch (std::runtime_error& err) {
|
} catch (std::runtime_error& err) {
|
||||||
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
|
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
|
||||||
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
|
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
|
||||||
this)
|
this)
|
||||||
.exec();
|
.exec();
|
||||||
this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -56,7 +75,7 @@ void SettingsDialog::accept()
|
||||||
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
|
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
|
||||||
int newCashPointNo = ui_.cashPointNoSpinBox->value();
|
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/feeInPercent", ui_.feePercentSpinBox->value());
|
||||||
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
|
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>180</height>
|
<height>203</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -33,8 +33,8 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="posPrinterDeviceEdit">
|
<widget class="QLineEdit" name="posPrinterDeviceEdit">
|
||||||
<property name="enabled">
|
<property name="toolTip">
|
||||||
<bool>false</bool>
|
<string><idVendor>:<idProduct></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -20,7 +20,9 @@ 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::FONT_SIZE_NORMAL = {0x1b, 0x21, 0x00};
|
||||||
const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03};
|
const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03};
|
||||||
|
|
||||||
PosPrinter::PosPrinter()
|
PosPrinter::PosPrinter() : PosPrinter(PrinterDevice()) {}
|
||||||
|
|
||||||
|
PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_(printerDevice)
|
||||||
{
|
{
|
||||||
int retValue;
|
int retValue;
|
||||||
|
|
||||||
|
@ -35,12 +37,23 @@ PosPrinter::PosPrinter()
|
||||||
libusb_exit(contextPtr_);
|
libusb_exit(contextPtr_);
|
||||||
throw std::runtime_error("Could not receive device list");
|
throw std::runtime_error("Could not receive device list");
|
||||||
}
|
}
|
||||||
|
|
||||||
int numDevice = -1;
|
int numDevice = -1;
|
||||||
|
|
||||||
for (int i = 0; i < devCount; ++i) {
|
for (int i = 0; i < devCount; ++i) {
|
||||||
libusb_device_descriptor desc;
|
libusb_device_descriptor desc;
|
||||||
libusb_get_device_descriptor(devList[i], &desc);
|
libusb_get_device_descriptor(devList[i], &desc);
|
||||||
for (const auto& supported : supportedPrinters_.models) {
|
|
||||||
if (desc.idVendor == supported.first && desc.idProduct == supported.second) {
|
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) {
|
||||||
numDevice = i;
|
numDevice = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,16 @@ struct SupportedPrinters {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PrinterDevice {
|
||||||
|
int idVendor{};
|
||||||
|
int idProduct{};
|
||||||
|
};
|
||||||
|
|
||||||
class PosPrinter
|
class PosPrinter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PosPrinter();
|
PosPrinter();
|
||||||
|
PosPrinter(const PrinterDevice& printerDevice);
|
||||||
~PosPrinter();
|
~PosPrinter();
|
||||||
void write(const std::string& text);
|
void write(const std::string& text);
|
||||||
void printHeader();
|
void printHeader();
|
||||||
|
@ -43,6 +49,7 @@ class PosPrinter
|
||||||
libusb_context* contextPtr_{};
|
libusb_context* contextPtr_{};
|
||||||
libusb_device_handle* devicePtr_{};
|
libusb_device_handle* devicePtr_{};
|
||||||
SupportedPrinters supportedPrinters_;
|
SupportedPrinters supportedPrinters_;
|
||||||
|
PrinterDevice printerDevice_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue