Add transfer progress

This commit is contained in:
Anton Thomasson 2020-06-03 20:42:18 +02:00
parent d62f0c8a56
commit 1b1079b679
3 changed files with 24 additions and 4 deletions

View file

@ -29,7 +29,7 @@ Page {
} }
BusyLabel { BusyLabel {
text: printer.busyMessage text: printer.busyMessage+"\n"+printer.progress;
running: true running: true
} }
} }

View file

@ -221,7 +221,9 @@ void IppPrinter::convertDone(QNetworkRequest request, QTemporaryFile* data)
setBusyMessage("Transferring"); setBusyMessage("Transferring");
_print_nam->post(request, data); QNetworkReply* reply = _print_nam->post(request, data);
connect(reply, &QNetworkReply::uploadProgress, this, &IppPrinter::setProgress);
} }
@ -252,6 +254,9 @@ bool IppPrinter::hasPrinterDeviceIdCmd(QString cmd)
void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert){ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert){
qDebug() << "printing" << filename << attrs; qDebug() << "printing" << filename << attrs;
_progress = "";
emit progressChanged();
QFile file(filename); QFile file(filename);
bool file_ok = file.open(QIODevice::ReadOnly); bool file_ok = file.open(QIODevice::ReadOnly);
if(!file_ok) if(!file_ok)
@ -468,6 +473,16 @@ void IppPrinter::setBusyMessage(QString msg)
emit busyMessageChanged(); emit busyMessageChanged();
} }
void IppPrinter::setProgress(qint64 sent, qint64 total)
{
if(total == 0)
return;
_progress = QString::number(100*sent/total);
_progress += "%";
emit progressChanged();
}
QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name) QJsonValue IppPrinter::getAttrOrDefault(QJsonObject jobAttrs, QString name)
{ {
if(jobAttrs.contains(name)) if(jobAttrs.contains(name))

View file

@ -14,6 +14,7 @@ class IppPrinter : public QObject
Q_PROPERTY(QJsonObject jobAttrs MEMBER _jobAttrs NOTIFY jobAttrsChanged) Q_PROPERTY(QJsonObject jobAttrs MEMBER _jobAttrs NOTIFY jobAttrsChanged)
Q_PROPERTY(QJsonArray jobs MEMBER _jobs NOTIFY jobsChanged) Q_PROPERTY(QJsonArray jobs MEMBER _jobs NOTIFY jobsChanged)
Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged) Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged)
Q_PROPERTY(QString progress MEMBER _progress NOTIFY progressChanged)
public: public:
@ -63,6 +64,7 @@ signals:
quint32 HwResX, quint32 HwResY); quint32 HwResX, quint32 HwResY);
void busyMessageChanged(); void busyMessageChanged();
void progressChanged();
public slots: public slots:
void print(QJsonObject attrs, QString file, bool alwaysConvert); void print(QJsonObject attrs, QString file, bool alwaysConvert);
@ -86,6 +88,8 @@ private:
QJsonObject opAttrs(); QJsonObject opAttrs();
void setBusyMessage(QString msg); void setBusyMessage(QString msg);
void setProgress(qint64 sent, qint64 total);
QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name); QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name);
QNetworkAccessManager* _nam; QNetworkAccessManager* _nam;
@ -97,6 +101,7 @@ private:
QJsonObject _jobAttrs; QJsonObject _jobAttrs;
QJsonArray _jobs; QJsonArray _jobs;
QString _busyMessage; QString _busyMessage;
QString _progress;
QThread _workerThread; QThread _workerThread;
ConvertWorker* _worker; ConvertWorker* _worker;