2009-09-19 20:13:35 +12:00
|
|
|
/*
|
|
|
|
Zint Barcode Generator - the open source barcode generator
|
Remove `bitmap_byte_length` member from `zint_symbol`
(was only set on BMP output to length of BMP pixel array)
EXCODE39: change to display check digit in HRT by default
CODE39/EXCODE39/LOGMARS: new hidden check digit option
(`option_2 = 2`)
qr.c: suppress bogus gcc-13 warning (only appears on optimize)
GUI: move some symbology-specific options into Data Tab so
separate tab unnecessary (those with few options and no
Composite/ECI), namely: all C25XXX, CODE39/EXCODE39/LOGMARS,
MSI_PLESSEY, CODABAR, DAFT, DPD, MAILMARK_2D, ITF-14, PZN,
UPNQR, CHANNEL, CODE93 and VIN, adjusting grp uis.
change Data dialog button (ellipsis) QToolButton -> QPushButton
& vice versa zap/clear/eye/swap/scale buttons QPushButton ->
QToolButton for better mac compat (also makes sense);
remove some mac hacks that no longer seem necessary;
use folder icon for Export dialog directory button
manual: document new Symbology-specific groupbox & CODE39/etc
hidden check digit option; add annexes on Qt and Tcl backends;
narrow some tables for better txt output;
remove echoed image tags in txt (pandoc 3.1.5 regression?);
add one-page HTML output to Makefile; also tex output (debug);
add class attributes to images to aid HTML styling;
various other fiddlings
2023-07-18 22:11:50 +12:00
|
|
|
Copyright (C) 2009-2023 Robin Stuart <rstuart114@gmail.com>
|
2009-09-19 20:13:35 +12:00
|
|
|
|
|
|
|
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, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2022-06-17 03:47:34 +12:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
2009-09-19 20:13:35 +12:00
|
|
|
|
2020-10-28 04:21:50 +13:00
|
|
|
//#include <QDebug>
|
2009-09-19 20:13:35 +12:00
|
|
|
#include <QUiLoader>
|
2009-09-21 03:40:46 +12:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2017-05-12 08:14:38 +12:00
|
|
|
#include <QSettings>
|
2021-11-24 08:12:48 +13:00
|
|
|
#include <QStringBuilder>
|
2009-09-19 20:13:35 +12:00
|
|
|
|
|
|
|
#include "exportwindow.h"
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
// Shorthand
|
|
|
|
#define QSL QStringLiteral
|
|
|
|
|
2022-08-22 02:15:27 +12:00
|
|
|
ExportWindow::ExportWindow(BarcodeItem *bc, const QString& output_data)
|
|
|
|
: m_bc(bc), m_output_data(output_data), m_lines(0)
|
2009-09-19 20:13:35 +12:00
|
|
|
{
|
2021-11-24 08:12:48 +13:00
|
|
|
setupUi(this);
|
2022-11-25 03:18:31 +13:00
|
|
|
|
|
|
|
if (m_bc->bc.noPng()) {
|
|
|
|
cmbFileType->removeItem(0); // PNG
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:14:38 +12:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2017-05-12 08:14:38 +12:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
QByteArray geometry = settings.value(QSL("studio/export/window_geometry")).toByteArray();
|
|
|
|
restoreGeometry(geometry);
|
|
|
|
|
|
|
|
linDestPath->setText(settings.value(QSL("studio/export/destination"),
|
Add Structured Append support for AZTEC, CODEONE, DATAMATRIX, DOTCODE,
GRIDMATRIX, MAXICODE, MICROPDF417, PDF417, QRCODE, ULTRA
DOTCODE: use pre-calculated generator poly coeffs in Reed-Solomon for
performance improvement
PDF417/MICROPDF417: use common routine pdf417_initial()
GUI: code lines <= 118, shorthand widget_obj(),
shorten calling upcean_addon_gap(), upcean_guard_descent()
various backend: var name debug -> debug_print
2021-09-29 09:42:44 +13:00
|
|
|
QDir::toNativeSeparators(QDir::homePath())).toString());
|
2021-11-24 08:12:48 +13:00
|
|
|
linPrefix->setText(settings.value(QSL("studio/export/file_prefix"), QSL("bcs_")).toString());
|
2022-05-26 00:44:45 +12:00
|
|
|
linPostfix->setText(settings.value(QSL("studio/export/file_postfix"), QSL("")).toString());
|
2021-11-24 08:12:48 +13:00
|
|
|
cmbFileName->setCurrentIndex(settings.value(QSL("studio/export/name_format"), 0).toInt());
|
2022-11-25 03:18:31 +13:00
|
|
|
cmbFileType->setCurrentIndex(std::min(settings.value(QSL("studio/export/filetype"), 0).toInt(),
|
|
|
|
cmbFileType->count() - 1));
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
QIcon closeIcon(QIcon::fromTheme(QSL("window-close"), QIcon(QSL(":res/x.svg"))));
|
|
|
|
btnCancel->setIcon(closeIcon);
|
Remove `bitmap_byte_length` member from `zint_symbol`
(was only set on BMP output to length of BMP pixel array)
EXCODE39: change to display check digit in HRT by default
CODE39/EXCODE39/LOGMARS: new hidden check digit option
(`option_2 = 2`)
qr.c: suppress bogus gcc-13 warning (only appears on optimize)
GUI: move some symbology-specific options into Data Tab so
separate tab unnecessary (those with few options and no
Composite/ECI), namely: all C25XXX, CODE39/EXCODE39/LOGMARS,
MSI_PLESSEY, CODABAR, DAFT, DPD, MAILMARK_2D, ITF-14, PZN,
UPNQR, CHANNEL, CODE93 and VIN, adjusting grp uis.
change Data dialog button (ellipsis) QToolButton -> QPushButton
& vice versa zap/clear/eye/swap/scale buttons QPushButton ->
QToolButton for better mac compat (also makes sense);
remove some mac hacks that no longer seem necessary;
use folder icon for Export dialog directory button
manual: document new Symbology-specific groupbox & CODE39/etc
hidden check digit option; add annexes on Qt and Tcl backends;
narrow some tables for better txt output;
remove echoed image tags in txt (pandoc 3.1.5 regression?);
add one-page HTML output to Makefile; also tex output (debug);
add class attributes to images to aid HTML styling;
various other fiddlings
2023-07-18 22:11:50 +12:00
|
|
|
QIcon folderIcon(QIcon::fromTheme(QSL("folder"), QIcon(QSL(":res/folder.svg"))));
|
|
|
|
btnDestPath->setIcon(folderIcon);
|
2021-11-24 08:12:48 +13:00
|
|
|
|
|
|
|
connect(btnCancel, SIGNAL( clicked( bool )), SLOT(close()));
|
2017-07-27 21:21:46 +12:00
|
|
|
connect(btnOK, SIGNAL( clicked( bool )), SLOT(process()));
|
|
|
|
connect(btnDestPath, SIGNAL( clicked( bool )), SLOT(get_directory()));
|
2022-06-17 03:47:34 +12:00
|
|
|
|
|
|
|
m_dataList = m_output_data.split('\n');
|
|
|
|
m_lines = m_dataList.size();
|
|
|
|
if (m_lines && m_dataList[m_lines - 1].isEmpty()) {
|
|
|
|
m_lines--;
|
|
|
|
}
|
|
|
|
/*: %1 is number of sequences */
|
|
|
|
lblFeedback->setText(tr("Export Results (%1):").arg(m_lines));
|
2009-09-19 20:13:35 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
ExportWindow::~ExportWindow()
|
|
|
|
{
|
2017-05-12 08:14:38 +12:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/export/window_geometry"), saveGeometry());
|
2017-05-12 08:14:38 +12:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/export/destination"), linDestPath->text());
|
|
|
|
settings.setValue(QSL("studio/export/file_prefix"), linPrefix->text());
|
2022-05-26 00:44:45 +12:00
|
|
|
settings.setValue(QSL("studio/export/file_postfix"), linPostfix->text());
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/export/name_format"), cmbFileName->currentIndex());
|
2022-11-25 03:18:31 +13:00
|
|
|
settings.setValue(QSL("studio/export/filetype"), cmbFileType->currentIndex());
|
2009-09-21 03:40:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExportWindow::get_directory()
|
|
|
|
{
|
2017-07-27 21:21:46 +12:00
|
|
|
QSettings settings;
|
2021-01-12 07:11:41 +13:00
|
|
|
#if QT_VERSION < 0x60000
|
2020-10-28 04:11:33 +13:00
|
|
|
settings.setIniCodec("UTF-8");
|
2021-01-12 07:11:41 +13:00
|
|
|
#endif
|
2017-07-27 21:21:46 +12:00
|
|
|
QString directory;
|
|
|
|
QFileDialog fdialog;
|
|
|
|
|
|
|
|
fdialog.setFileMode(QFileDialog::Directory);
|
2021-11-24 08:12:48 +13:00
|
|
|
fdialog.setDirectory(settings.value(QSL("studio/default_dir"),
|
|
|
|
QDir::toNativeSeparators(QDir::homePath())).toString());
|
2017-07-27 21:21:46 +12:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
if (fdialog.exec()) {
|
2017-07-27 21:21:46 +12:00
|
|
|
directory = fdialog.selectedFiles().at(0);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
linDestPath->setText(QDir::toNativeSeparators(directory));
|
2021-11-24 08:12:48 +13:00
|
|
|
settings.setValue(QSL("studio/default_dir"), directory);
|
2009-09-21 03:40:46 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExportWindow::process()
|
|
|
|
{
|
2021-11-24 08:12:48 +13:00
|
|
|
const QRegularExpression urlRE(QSL("[\\/:*?\"<>|%]"));
|
|
|
|
|
|
|
|
txtFeedback->setPlainText(tr("Processing..."));
|
|
|
|
txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
|
|
|
|
QString biggest;
|
|
|
|
bool needUrlEscape = false;
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
const int fileNameIdx = cmbFileName->currentIndex();
|
|
|
|
if (fileNameIdx == 1) {
|
2022-06-17 03:47:34 +12:00
|
|
|
biggest = QString::number(m_lines + 1);
|
2021-11-24 08:12:48 +13:00
|
|
|
} else {
|
|
|
|
needUrlEscape = m_output_data.contains(urlRE);
|
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
QString suffix;
|
2022-11-25 03:18:31 +13:00
|
|
|
int suffixIdx = cmbFileType->currentText().lastIndexOf(QSL("(*."));
|
|
|
|
if (suffixIdx == -1) {
|
|
|
|
suffix = m_bc->bc.noPng() ? QSL(".gif") : QSL(".png");
|
|
|
|
} else {
|
|
|
|
suffix = cmbFileType->currentText().mid(suffixIdx + 2, 4);
|
2017-05-12 08:14:38 +12:00
|
|
|
}
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
QString filePathPrefix = linDestPath->text() % QDir::separator() % linPrefix->text();
|
2022-05-26 00:44:45 +12:00
|
|
|
QString postfix = linPostfix->text();
|
2021-11-24 08:12:48 +13:00
|
|
|
|
|
|
|
QStringList Feedback;
|
|
|
|
int successCount = 0, errorCount = 0;
|
2022-06-17 03:47:34 +12:00
|
|
|
for (int i = 0; i < m_lines; i++) {
|
|
|
|
const QString &dataString = m_dataList[i];
|
2021-11-24 08:12:48 +13:00
|
|
|
QString fileName;
|
|
|
|
switch (fileNameIdx) {
|
|
|
|
case 0: /* Same as Data (URL Escaped) */
|
|
|
|
if (needUrlEscape) {
|
2020-10-28 04:21:50 +13:00
|
|
|
QString url_escaped;
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
for (int m = 0; m < dataString.length(); m++) {
|
|
|
|
QChar name_qchar = dataString[m];
|
2017-09-11 03:03:09 +12:00
|
|
|
char name_char = name_qchar.toLatin1();
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
switch (name_char) {
|
|
|
|
case '\\': url_escaped += QSL("%5C"); break;
|
|
|
|
case '/': url_escaped += QSL("%2F"); break;
|
|
|
|
case ':': url_escaped += QSL("%3A"); break;
|
|
|
|
case '*': url_escaped += QSL("%2A"); break;
|
|
|
|
case '?': url_escaped += QSL("%3F"); break;
|
|
|
|
case '"': url_escaped += QSL("%22"); break;
|
|
|
|
case '<': url_escaped += QSL("%3C"); break;
|
|
|
|
case '>': url_escaped += QSL("%3E"); break;
|
|
|
|
case '|': url_escaped += QSL("%7C"); break;
|
|
|
|
case '%': url_escaped += QSL("%25"); break;
|
2020-10-28 04:21:50 +13:00
|
|
|
default: url_escaped += name_qchar; break;
|
|
|
|
}
|
|
|
|
}
|
2022-05-26 00:44:45 +12:00
|
|
|
fileName = filePathPrefix % url_escaped % postfix % suffix;
|
2021-11-24 08:12:48 +13:00
|
|
|
} else {
|
2022-05-26 00:44:45 +12:00
|
|
|
fileName = filePathPrefix % dataString % postfix % suffix;
|
2017-08-12 09:36:40 +12:00
|
|
|
}
|
2020-10-28 04:21:50 +13:00
|
|
|
break;
|
|
|
|
case 1: { /* Formatted Serial Number */
|
2021-11-24 08:12:48 +13:00
|
|
|
QString this_val, pad;
|
2020-10-28 04:21:50 +13:00
|
|
|
|
|
|
|
this_val = QString::number(i + 1);
|
|
|
|
|
2021-11-24 08:12:48 +13:00
|
|
|
pad.fill('0', biggest.length() - this_val.length());
|
2017-10-24 08:37:52 +13:00
|
|
|
|
2022-05-26 00:44:45 +12:00
|
|
|
fileName = filePathPrefix % pad % this_val % postfix % suffix;
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-11-24 08:12:48 +13:00
|
|
|
m_bc->bc.setText(dataString);
|
|
|
|
m_bc->bc.save_to_file(fileName);
|
|
|
|
if (m_bc->bc.hasErrors()) {
|
|
|
|
/*: %1 is line number, %2 is error message */
|
|
|
|
Feedback << tr("Line %1: %2").arg(i + 1).arg(m_bc->bc.error_message());
|
|
|
|
errorCount++;
|
2020-10-28 04:21:50 +13:00
|
|
|
} else {
|
2021-11-24 08:12:48 +13:00
|
|
|
/*: %1 is line number */
|
|
|
|
Feedback << tr("Line %1: Success").arg(i + 1);
|
|
|
|
successCount++;
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
2021-11-24 08:12:48 +13:00
|
|
|
if (i && (i % 100 == 0)) {
|
|
|
|
txtFeedback->appendPlainText(Feedback.join('\n'));
|
|
|
|
txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
|
|
Feedback.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString summary;
|
|
|
|
if (errorCount && successCount) {
|
|
|
|
/*: %1 is total no. of items processed, %2 is no. of failures, %3 is no. of successes */
|
|
|
|
summary = tr("Total %1, %2 failed, %3 succeeded.").arg(errorCount + successCount).arg(errorCount)
|
|
|
|
.arg(successCount);
|
|
|
|
} else if (errorCount) {
|
|
|
|
/*: %1 is no. of failures */
|
|
|
|
summary = tr("All %1 failed.").arg(errorCount);
|
|
|
|
} else if (successCount) {
|
|
|
|
/*: %1 is no. of successes */
|
|
|
|
summary = tr("All %1 succeeded.").arg(successCount);
|
|
|
|
} else {
|
|
|
|
summary = tr("No items.");
|
|
|
|
}
|
|
|
|
if (Feedback.size()) {
|
|
|
|
txtFeedback->appendPlainText(Feedback.join('\n') + '\n' + summary + '\n');
|
|
|
|
} else {
|
|
|
|
txtFeedback->appendPlainText(summary + '\n');
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
2021-11-24 08:12:48 +13:00
|
|
|
txtFeedback->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
|
2020-10-28 04:21:50 +13:00
|
|
|
}
|
2022-06-17 03:47:34 +12:00
|
|
|
|
|
|
|
/* vim: set ts=4 sw=4 et : */
|