qt: Add simple and extended progress signals replacing old signal
* lang/qt/src/job.h (Job): Add signals jobProgress and rawProgress. Deprecate signal progress. * lang/qt/src/multideletejob.cpp (MultiDeleteJob::slotResult): Emit new progress signals. * lang/qt/src/qgpgmerefreshsmimekeysjob.cpp (QGpgMERefreshSMIMEKeysJob::slotStatus): Ditto. * lang/qt/src/threadedjobmixin.h (ThreadedJobMixin::showProgress): Use modern overload of QMetaObject::invokeMethod to forward the progress signal and add the value of what. Add forwarding of progress to the new signals. * lang/qt/tests/t-encrypt.cpp (EncryptionTest::testProgress): Test the new signals instead of the deprecated one. -- The new signal jobProgress omits the what value which is useless for most consumers. The new signal rawProgress makes all information provided by the backend available to consumers. The latter is not really meant to be used by users of gpgme. It will be used by the archive jobs to provide more user-friendly signals. GnuPG-bug-id: 6342
This commit is contained in:
parent
9c5506fde7
commit
ea6f15ed60
3
NEWS
3
NEWS
@ -69,6 +69,9 @@ Noteworthy changes in version 1.19.0 (unreleased)
|
||||
qt: Protocol::encryptArchiveJob NEW.
|
||||
qt: Protocol::signArchiveJob NEW.
|
||||
qt: Protocol::signEncryptArchiveJob NEW.
|
||||
qt: Job::jobProgress NEW.
|
||||
qt: Job::rawProgress NEW.
|
||||
qt: Job::progress DEPRECATED.
|
||||
|
||||
Release-info: https://dev.gnupg.org/T6341
|
||||
|
||||
|
@ -106,7 +106,38 @@ public Q_SLOTS:
|
||||
virtual void slotCancel() = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
void progress(const QString &what, int current, int total);
|
||||
/**
|
||||
* This signal is emitted whenever the backend sends a progress status
|
||||
* message. For most jobs, \a current is the amount of processed data
|
||||
* (or files) and \a total is the total amount of data (of files). If
|
||||
* \a total is 0, then the total amount is unknown or not yet known.
|
||||
* For GnuPG 2.1.13 and later, \a current and \a total do not exceed
|
||||
* 2^20, i.e. for larger values they are scaled down and you should not
|
||||
* assume that they represent absolute values.
|
||||
*
|
||||
* Check the documentation on progress in the GpgME manual for details.
|
||||
*
|
||||
* Note: Some jobs provide special progress signals, e.g. for file-count-
|
||||
* or data-based progress.
|
||||
*/
|
||||
void jobProgress(int current, int total);
|
||||
|
||||
/**
|
||||
* This signal is emitted whenever the backend sends a progress status
|
||||
* message. Compared to the jobProgress signal this signal also provides the
|
||||
* what value and the type value reported by the backend. Usually, these
|
||||
* values can safely be ignored, so that you are better off using the
|
||||
* simpler jobProgress signal.
|
||||
* Check the documentation on progress in the GpgME manual for details
|
||||
* on what and type.
|
||||
*
|
||||
* Note: Some jobs provide special progress signals, so that you do not
|
||||
* have to deal with what and type yourself.
|
||||
*/
|
||||
void rawProgress(const QString &what, int type, int current, int total);
|
||||
|
||||
QGPGME_DEPRECATED void progress(const QString &what, int current, int total);
|
||||
|
||||
void done();
|
||||
};
|
||||
|
||||
|
@ -97,7 +97,13 @@ void QGpgME::MultiDeleteJob::slotResult(const GpgME::Error &err)
|
||||
|
||||
const int current = mIt - mKeys.begin();
|
||||
const int total = mKeys.size();
|
||||
Q_EMIT progress(QStringLiteral("%1/%2").arg(current).arg(total), current, total);
|
||||
const QString what = QStringLiteral("%1/%2").arg(current).arg(total);
|
||||
Q_EMIT jobProgress(current, total);
|
||||
Q_EMIT rawProgress(what, '?', current, total);
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_EMIT progress(what, current, total);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
|
||||
GpgME::Error QGpgME::MultiDeleteJob::startAJob()
|
||||
|
@ -209,7 +209,7 @@ void QGpgMERefreshSMIMEKeysJob::slotStatus(QProcess *proc, const QString &type,
|
||||
}
|
||||
const QString what = *++it;
|
||||
ok = false;
|
||||
(*++it).toInt(&ok);
|
||||
const int type = (*++it).toInt(&ok);
|
||||
if (!ok) {
|
||||
qCDebug(QGPGME_LOG) << "expected number for \"type\", got something else";
|
||||
return;
|
||||
@ -226,9 +226,12 @@ void QGpgMERefreshSMIMEKeysJob::slotStatus(QProcess *proc, const QString &type,
|
||||
qCDebug(QGPGME_LOG) << "expected number for \"total\", got something else";
|
||||
return;
|
||||
}
|
||||
// TODO port
|
||||
Q_EMIT progress(QString(), cur, total);
|
||||
|
||||
Q_EMIT jobProgress(cur, total);
|
||||
Q_EMIT rawProgress(what, type, cur, total);
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_EMIT progress(what, cur, total);
|
||||
QT_WARNING_POP
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,17 +250,21 @@ protected:
|
||||
{
|
||||
return m_auditLogError;
|
||||
}
|
||||
void showProgress(const char * /*what*/,
|
||||
int /*type*/, int current, int total) override {
|
||||
// will be called from the thread exec'ing the operation, so
|
||||
// just bounce everything to the owning thread:
|
||||
// ### hope this is thread-safe (meta obj is const, and
|
||||
// ### portEvent is thread-safe, so should be ok)
|
||||
QMetaObject::invokeMethod(this, "progress", Qt::QueuedConnection,
|
||||
// TODO port
|
||||
Q_ARG(QString, QString()),
|
||||
Q_ARG(int, current),
|
||||
Q_ARG(int, total));
|
||||
void showProgress(const char *what,
|
||||
int type, int current, int total) override {
|
||||
QMetaObject::invokeMethod(this, [this, current, total]() {
|
||||
Q_EMIT this->jobProgress(current, total);
|
||||
}, Qt::QueuedConnection);
|
||||
const QString what_ = QString::fromUtf8(what);
|
||||
QMetaObject::invokeMethod(this, [this, what_, type, current, total]() {
|
||||
Q_EMIT this->rawProgress(what_, type, current, total);
|
||||
}, Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(this, [this, what_, current, total]() {
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
Q_EMIT this->progress(what_, current, total);
|
||||
QT_WARNING_POP
|
||||
}, Qt::QueuedConnection);
|
||||
}
|
||||
private:
|
||||
template <typename T1, typename T2>
|
||||
|
@ -120,7 +120,22 @@ private Q_SLOTS:
|
||||
|
||||
bool initSeen = false;
|
||||
bool finishSeen = false;
|
||||
connect(job, &Job::progress, this, [this, &initSeen, &finishSeen] (const QString&, int current, int total) {
|
||||
connect(job, &Job::jobProgress, this, [&initSeen, &finishSeen] (int current, int total) {
|
||||
// We only check for progress 0 and max progress as the other progress
|
||||
// lines depend on the system speed and are as such unreliable to test.
|
||||
QVERIFY(total == PROGRESS_TEST_SIZE);
|
||||
if (current == 0) {
|
||||
initSeen = true;
|
||||
}
|
||||
if (current == total) {
|
||||
finishSeen = true;
|
||||
}
|
||||
QVERIFY(current >= 0 && current <= total);
|
||||
});
|
||||
connect(job, &Job::rawProgress, this, [&initSeen, &finishSeen] (const QString &what, int type, int current, int total) {
|
||||
// `what` is something like "-&12", i.e. a special fd passed to gpg; we only check that it's not empty
|
||||
QVERIFY(!what.isEmpty());
|
||||
QCOMPARE(type, '?');
|
||||
// We only check for progress 0 and max progress as the other progress
|
||||
// lines depend on the system speed and are as such unreliable to test.
|
||||
QVERIFY(total == PROGRESS_TEST_SIZE);
|
||||
|
Loading…
Reference in New Issue
Block a user