Enable translation of error messages from C++

This commit is contained in:
Anton Thomasson 2020-05-14 21:00:37 +02:00
parent ef9b222c35
commit 8c22740651
9 changed files with 99 additions and 10 deletions

View file

@ -78,14 +78,14 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
{ {
qDebug() << "pdftoppm died"; qDebug() << "pdftoppm died";
tempfile->deleteLater(); tempfile->deleteLater();
emit failed(); emit failed(tr("Conversion error"));
return; return;
} }
if(!ppm2pwg->waitForStarted()) if(!ppm2pwg->waitForStarted())
{ {
qDebug() << "ppm2pwg died"; qDebug() << "ppm2pwg died";
tempfile->deleteLater(); tempfile->deleteLater();
emit failed(); emit failed(tr("Conversion error"));
return; return;
} }
qDebug() << "All started"; qDebug() << "All started";
@ -108,7 +108,7 @@ void ConvertWorker::convertImage(QNetworkRequest request, QString filename, QTem
if(!inImage.load(filename)) if(!inImage.load(filename))
{ {
qDebug() << "failed to load"; qDebug() << "failed to load";
emit failed(); emit failed(tr("Failed to load image"));
return; return;
} }
@ -153,7 +153,7 @@ void ConvertWorker::convertImage(QNetworkRequest request, QString filename, QTem
{ {
qDebug() << "ppm2pwg died"; qDebug() << "ppm2pwg died";
tempfile->deleteLater(); tempfile->deleteLater();
emit failed(); emit failed(tr("Conversion error"));
return; return;
} }
qDebug() << "All started"; qDebug() << "All started";

View file

@ -17,7 +17,7 @@ public slots:
signals: signals:
void done(QNetworkRequest request, QTemporaryFile* data); void done(QNetworkRequest request, QTemporaryFile* data);
void failed(); void failed(QString message);
}; };
#endif // CONVERTWORKER_H #endif // CONVERTWORKER_H

View file

@ -97,7 +97,6 @@ void IppPrinter::refresh() {
QNetworkRequest request; QNetworkRequest request;
request.setUrl(httpUrl()); request.setUrl(httpUrl());
// request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp"); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/ipp");
request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint "SEAPRINT_VERSION); request.setHeader(QNetworkRequest::UserAgentHeader, "SeaPrint "SEAPRINT_VERSION);
@ -220,10 +219,10 @@ void IppPrinter::convertDone(QNetworkRequest request, QTemporaryFile* data)
} }
void IppPrinter::convertFailed() void IppPrinter::convertFailed(QString message)
{ {
_jobAttrs = QJsonObject(); _jobAttrs = QJsonObject();
_jobAttrs.insert("job-state-message", QJsonObject {{"tag", IppMsg::TextWithoutLanguage}, {"value", "Internal error"}}); _jobAttrs.insert("job-state-message", QJsonObject {{"tag", IppMsg::TextWithoutLanguage}, {"value", message}});
emit jobAttrsChanged(); emit jobAttrsChanged();
emit jobFinished(false); emit jobFinished(false);
} }
@ -235,7 +234,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename){
bool file_ok = file.open(QIODevice::ReadOnly); bool file_ok = file.open(QIODevice::ReadOnly);
if(!file_ok) if(!file_ok)
{ {
emit jobFinished(false); emit convertFailed(tr("Failed to open file"));
return; return;
} }

View file

@ -74,7 +74,7 @@ public slots:
void ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors); void ignoreKnownSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
void convertDone(QNetworkRequest request, QTemporaryFile* data); void convertDone(QNetworkRequest request, QTemporaryFile* data);
void convertFailed(); void convertFailed(QString message);
private: private:
QUrl _url; QUrl _url;

View file

@ -118,6 +118,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>ConvertWorker</name>
<message>
<source>Conversion error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load image</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -172,6 +183,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>IppPrinter</name>
<message>
<source>Failed to open file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>

View file

@ -118,6 +118,17 @@
<translation type="unfinished">Impresión fallida: </translation> <translation type="unfinished">Impresión fallida: </translation>
</message> </message>
</context> </context>
<context>
<name>ConvertWorker</name>
<message>
<source>Conversion error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load image</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -172,6 +183,13 @@
<translation type="unfinished">Elegir archivo</translation> <translation type="unfinished">Elegir archivo</translation>
</message> </message>
</context> </context>
<context>
<name>IppPrinter</name>
<message>
<source>Failed to open file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>

View file

@ -118,6 +118,17 @@
<translation type="unfinished">Échec de l&apos;impression :</translation> <translation type="unfinished">Échec de l&apos;impression :</translation>
</message> </message>
</context> </context>
<context>
<name>ConvertWorker</name>
<message>
<source>Conversion error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load image</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -172,6 +183,13 @@
<translation type="unfinished">Choisir un fichier</translation> <translation type="unfinished">Choisir un fichier</translation>
</message> </message>
</context> </context>
<context>
<name>IppPrinter</name>
<message>
<source>Failed to open file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>

View file

@ -118,6 +118,17 @@
<translation type="unfinished">:</translation> <translation type="unfinished">:</translation>
</message> </message>
</context> </context>
<context>
<name>ConvertWorker</name>
<message>
<source>Conversion error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load image</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -172,6 +183,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>IppPrinter</name>
<message>
<source>Failed to open file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>

View file

@ -118,6 +118,17 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>ConvertWorker</name>
<message>
<source>Conversion error</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Failed to load image</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CoverPage</name> <name>CoverPage</name>
<message> <message>
@ -172,6 +183,13 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>IppPrinter</name>
<message>
<source>Failed to open file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>JobsPage</name> <name>JobsPage</name>
<message> <message>