Basic failure propagation from failed uploads
This commit is contained in:
parent
81c85f3a51
commit
6b11d16bfc
10 changed files with 75 additions and 27 deletions
|
@ -14,6 +14,8 @@
|
||||||
#include "pdf2printable.h"
|
#include "pdf2printable.h"
|
||||||
#include "ppm2pwg.h"
|
#include "ppm2pwg.h"
|
||||||
|
|
||||||
|
#define OK(call) if(!(call)) throw ConvertFailedException()
|
||||||
|
|
||||||
ConvertWorker::ConvertWorker(IppPrinter* parent) // : QObject((QObject*)parent) borks multithereading?!
|
ConvertWorker::ConvertWorker(IppPrinter* parent) // : QObject((QObject*)parent) borks multithereading?!
|
||||||
{
|
{
|
||||||
_printer = parent;
|
_printer = parent;
|
||||||
|
@ -21,46 +23,52 @@ ConvertWorker::ConvertWorker(IppPrinter* parent) // : QObject((QObject*)parent)
|
||||||
|
|
||||||
void ConvertWorker::command(QByteArray msg)
|
void ConvertWorker::command(QByteArray msg)
|
||||||
{
|
{
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::getPrinterAttributesFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::getPrinterAttributesFinished);
|
||||||
|
|
||||||
qDebug() << "command...";
|
qDebug() << "command...";
|
||||||
|
|
||||||
cid.write(msg.data(), msg.length());
|
cr.write(msg.data(), msg.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: de-duplicate
|
// TODO: de-duplicate
|
||||||
void ConvertWorker::getJobs(QByteArray msg)
|
void ConvertWorker::getJobs(QByteArray msg)
|
||||||
{
|
{
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::getJobsRequestFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::getJobsRequestFinished);
|
||||||
|
|
||||||
cid.write(msg.data(), msg.length());
|
cr.write(msg.data(), msg.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertWorker::cancelJob(QByteArray msg)
|
void ConvertWorker::cancelJob(QByteArray msg)
|
||||||
{
|
{
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::cancelJobFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::cancelJobFinished);
|
||||||
|
|
||||||
cid.write(msg.data(), msg.length());
|
cr.write(msg.data(), msg.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertWorker::justUpload(QString filename, QByteArray header)
|
void ConvertWorker::justUpload(QString filename, QByteArray header)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
emit busyMessage(tr("Printing"));
|
emit busyMessage(tr("Printing"));
|
||||||
|
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||||
|
|
||||||
QFile file(filename);
|
QFile file(filename);
|
||||||
file.open(QFile::ReadOnly);
|
file.open(QFile::ReadOnly);
|
||||||
|
|
||||||
cid.write(header.data(), header.length());
|
OK(cr.write(header.data(), header.length()));
|
||||||
QByteArray tmp = file.readAll();
|
QByteArray tmp = file.readAll();
|
||||||
cid.write(tmp.data(), tmp.length());
|
OK(cr.write(tmp.data(), tmp.length()));
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
catch(const ConvertFailedException& e)
|
||||||
|
{
|
||||||
|
emit failed(e.what() == QString("") ? tr("Upload error") : e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ConvertWorker::convertPdf(QString filename, QByteArray header,
|
void ConvertWorker::convertPdf(QString filename, QByteArray header,
|
||||||
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
QString targetFormat, quint32 Colors, quint32 Quality, QString PaperSize,
|
||||||
|
@ -98,17 +106,16 @@ try {
|
||||||
Colors = 3;
|
Colors = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||||
|
|
||||||
cid.write(header.data(), header.length());
|
OK(cr.write(header.data(), header.length()));
|
||||||
|
|
||||||
write_fun WriteFun([&cid](unsigned char const* buf, unsigned int len) -> bool
|
write_fun WriteFun([&cr](unsigned char const* buf, unsigned int len) -> bool
|
||||||
{
|
{
|
||||||
if(len == 0)
|
if(len == 0)
|
||||||
return true;
|
return true;
|
||||||
cid.write((const char*)buf, len);
|
return cr.write((const char*)buf, len);
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
progress_fun ProgressFun([this](size_t page, size_t total) -> void
|
progress_fun ProgressFun([this](size_t page, size_t total) -> void
|
||||||
|
@ -287,11 +294,11 @@ try {
|
||||||
|
|
||||||
emit busyMessage(tr("Printing"));
|
emit busyMessage(tr("Printing"));
|
||||||
|
|
||||||
CurlRequester cid(_printer->httpUrl());
|
CurlRequester cr(_printer->httpUrl());
|
||||||
cid.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
cr.setFinishedCallback(_printer, &IppPrinter::printRequestFinished);
|
||||||
|
|
||||||
cid.write(header.data(), header.length());
|
OK(cr.write(header.data(), header.length()));
|
||||||
cid.write((char*)(outBts.raw()), outBts.size());
|
OK(cr.write((char*)(outBts.raw()), outBts.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "posted";
|
qDebug() << "posted";
|
||||||
|
|
|
@ -10,7 +10,13 @@ CurlRequester::CurlRequester(QUrl addr) : _addr(addr), _canWrite(1), _canRead(),
|
||||||
|
|
||||||
CurlRequester::~CurlRequester()
|
CurlRequester::~CurlRequester()
|
||||||
{
|
{
|
||||||
_canWrite.acquire();
|
while(!_canWrite.tryAcquire(1, 500))
|
||||||
|
{
|
||||||
|
if(!_performer.isRunning())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
_done = true;
|
_done = true;
|
||||||
_canRead.release();
|
_canRead.release();
|
||||||
_performer.wait();
|
_performer.wait();
|
||||||
|
@ -21,10 +27,16 @@ CurlRequester::~CurlRequester()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurlRequester::write(const char *data, size_t size)
|
bool CurlRequester::write(const char *data, size_t size)
|
||||||
{
|
{
|
||||||
qDebug() << "write " << size;
|
qDebug() << "write " << size;
|
||||||
_canWrite.acquire();
|
while(!_canWrite.tryAcquire(1, 500))
|
||||||
|
{
|
||||||
|
if(!_performer.isRunning())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(_dest != nullptr)
|
if(_dest != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -35,6 +47,7 @@ void CurlRequester::write(const char *data, size_t size)
|
||||||
_size = size;
|
_size = size;
|
||||||
_offset = 0;
|
_offset = 0;
|
||||||
_canRead.release();
|
_canRead.release();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CurlRequester::requestWrite(char* dest, size_t size)
|
size_t CurlRequester::requestWrite(char* dest, size_t size)
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const char *data, size_t size);
|
bool write(const char *data, size_t size);
|
||||||
size_t requestWrite(char* dest, size_t size);
|
size_t requestWrite(char* dest, size_t size);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
|
@ -199,6 +199,10 @@
|
||||||
<source>Conversion failed</source>
|
<source>Conversion failed</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Upload error</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>CoverPage</name>
|
<name>CoverPage</name>
|
||||||
|
|
Loading…
Reference in a new issue