summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Klöcker <dev@ingo-kloecker.de>2023-02-13 10:58:31 +0100
committerIngo Klöcker <dev@ingo-kloecker.de>2023-02-14 09:25:21 +0100
commitea6f15ed602eeb9fa87766ba88acc78361a14b38 (patch)
tree8e3d23caee9507a367920116fddae0b6bc8fb9ed
parent9c5506fde701f637381614dcfe22e3f9dc82955d (diff)
downloadgpgme-ea6f15ed602eeb9fa87766ba88acc78361a14b38.tar.gz
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
-rw-r--r--NEWS3
-rw-r--r--lang/qt/src/job.h33
-rw-r--r--lang/qt/src/multideletejob.cpp8
-rw-r--r--lang/qt/src/qgpgmerefreshsmimekeysjob.cpp11
-rw-r--r--lang/qt/src/threadedjobmixin.h26
-rw-r--r--lang/qt/tests/t-encrypt.cpp17
6 files changed, 80 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index a7b0d9f9..0b051d5e 100644
--- a/NEWS
+++ b/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
diff --git a/lang/qt/src/job.h b/lang/qt/src/job.h
index 8b974b4f..46c5e717 100644
--- a/lang/qt/src/job.h
+++ b/lang/qt/src/job.h
@@ -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();
};
diff --git a/lang/qt/src/multideletejob.cpp b/lang/qt/src/multideletejob.cpp
index c3e6520d..d660a931 100644
--- a/lang/qt/src/multideletejob.cpp
+++ b/lang/qt/src/multideletejob.cpp
@@ -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()
diff --git a/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp b/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp
index 3e430ad7..cff115ec 100644
--- a/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp
+++ b/lang/qt/src/qgpgmerefreshsmimekeysjob.cpp
@@ -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
}
}
diff --git a/lang/qt/src/threadedjobmixin.h b/lang/qt/src/threadedjobmixin.h
index afabae3b..e92d02d7 100644
--- a/lang/qt/src/threadedjobmixin.h
+++ b/lang/qt/src/threadedjobmixin.h
@@ -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>
diff --git a/lang/qt/tests/t-encrypt.cpp b/lang/qt/tests/t-encrypt.cpp
index 6a4c68e9..35b9bbf9 100644
--- a/lang/qt/tests/t-encrypt.cpp
+++ b/lang/qt/tests/t-encrypt.cpp
@@ -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);