Add transfer progress
This commit is contained in:
parent
d62f0c8a56
commit
1b1079b679
3 changed files with 24 additions and 4 deletions
|
@ -29,7 +29,7 @@ Page {
|
|||
}
|
||||
|
||||
BusyLabel {
|
||||
text: printer.busyMessage
|
||||
text: printer.busyMessage+"\n"+printer.progress;
|
||||
running: true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@ IppPrinter::IppPrinter()
|
|||
_jobs_nam = new QNetworkAccessManager(this);
|
||||
_job_cancel_nam = new QNetworkAccessManager(this);
|
||||
|
||||
connect(_nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(getPrinterAttributesFinished(QNetworkReply*)));
|
||||
connect(_nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(getPrinterAttributesFinished(QNetworkReply*)));
|
||||
connect(_nam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(ignoreKnownSslErrors(QNetworkReply*, const QList<QSslError>&)));
|
||||
|
||||
connect(_print_nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(printRequestFinished(QNetworkReply*)));
|
||||
connect(_print_nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(printRequestFinished(QNetworkReply*)));
|
||||
connect(_print_nam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)), this, SLOT(ignoreKnownSslErrors(QNetworkReply*, const QList<QSslError>&)));
|
||||
|
||||
connect(_jobs_nam, SIGNAL(finished(QNetworkReply*)),this, SLOT(getJobsRequestFinished(QNetworkReply*)));
|
||||
|
@ -221,7 +221,9 @@ void IppPrinter::convertDone(QNetworkRequest request, QTemporaryFile* data)
|
|||
|
||||
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){
|
||||
qDebug() << "printing" << filename << attrs;
|
||||
|
||||
_progress = "";
|
||||
emit progressChanged();
|
||||
|
||||
QFile file(filename);
|
||||
bool file_ok = file.open(QIODevice::ReadOnly);
|
||||
if(!file_ok)
|
||||
|
@ -468,6 +473,16 @@ void IppPrinter::setBusyMessage(QString msg)
|
|||
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)
|
||||
{
|
||||
if(jobAttrs.contains(name))
|
||||
|
|
|
@ -14,6 +14,7 @@ class IppPrinter : public QObject
|
|||
Q_PROPERTY(QJsonObject jobAttrs MEMBER _jobAttrs NOTIFY jobAttrsChanged)
|
||||
Q_PROPERTY(QJsonArray jobs MEMBER _jobs NOTIFY jobsChanged)
|
||||
Q_PROPERTY(QString busyMessage MEMBER _busyMessage NOTIFY busyMessageChanged)
|
||||
Q_PROPERTY(QString progress MEMBER _progress NOTIFY progressChanged)
|
||||
|
||||
|
||||
public:
|
||||
|
@ -63,6 +64,7 @@ signals:
|
|||
quint32 HwResX, quint32 HwResY);
|
||||
|
||||
void busyMessageChanged();
|
||||
void progressChanged();
|
||||
|
||||
public slots:
|
||||
void print(QJsonObject attrs, QString file, bool alwaysConvert);
|
||||
|
@ -86,6 +88,8 @@ private:
|
|||
QJsonObject opAttrs();
|
||||
|
||||
void setBusyMessage(QString msg);
|
||||
void setProgress(qint64 sent, qint64 total);
|
||||
|
||||
QJsonValue getAttrOrDefault(QJsonObject jobAttrs, QString name);
|
||||
|
||||
QNetworkAccessManager* _nam;
|
||||
|
@ -97,6 +101,7 @@ private:
|
|||
QJsonObject _jobAttrs;
|
||||
QJsonArray _jobs;
|
||||
QString _busyMessage;
|
||||
QString _progress;
|
||||
|
||||
QThread _workerThread;
|
||||
ConvertWorker* _worker;
|
||||
|
|
Loading…
Reference in a new issue