/*
ptrnt - print labels on linux
Copyright (C) 2025 Moritz Martinius
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "PrinterDriverFactory.hpp"
#include
#include
#include
#include "libusbwrap/LibUsbTypes.hpp"
#include "printers/FakePrinter.hpp"
#include "printers/P700Printer.hpp"
namespace ptprnt {
std::shared_ptr PrinterDriverFactory::create(libusbwrap::usbId id) {
if (printer::P700Printer::mInfo.usbId == id) {
spdlog::info("Found printer P700!");
return std::make_shared();
} else {
spdlog::trace("{:04x}:{:04x} is not a compatible printer", id.first, id.second);
}
return nullptr;
}
std::shared_ptr PrinterDriverFactory::createFakePrinter() {
spdlog::info("Creating FakePrinter (virtual test printer)");
return std::make_shared();
}
std::shared_ptr PrinterDriverFactory::createByName(const std::string& driverName) {
// Convert to lowercase for case-insensitive comparison
std::string nameLower = driverName;
std::ranges::transform(nameLower, nameLower.begin(), [](unsigned char c) { return std::tolower(c); });
if (nameLower == "p700" || nameLower == "p700printer") {
spdlog::info("Creating P700 printer driver by name");
return std::make_shared();
} else if (nameLower == "fakeprinter" || nameLower == "fake") {
return createFakePrinter();
}
spdlog::warn("Unknown printer driver name: {}", driverName);
return nullptr;
}
std::vector PrinterDriverFactory::listAllDrivers() const {
return {std::string(printer::P700Printer::mInfo.driverName), std::string(printer::FakePrinter::mInfo.driverName)};
}
} // namespace ptprnt