diff --git a/lang/qt/src/decryptverifyarchivejob.h b/lang/qt/src/decryptverifyarchivejob.h index ea922bc4..4e72be2d 100644 --- a/lang/qt/src/decryptverifyarchivejob.h +++ b/lang/qt/src/decryptverifyarchivejob.h @@ -1,91 +1,108 @@ /* decryptverifyarchivejob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __QGPGME_DECRYPTVERIFYARCHIVEJOB_H__ #define __QGPGME_DECRYPTVERIFYARCHIVEJOB_H__ #include "job.h" #ifdef BUILDING_QGPGME # include "context.h" #else # include #endif namespace GpgME { class Key; } namespace QGpgME { /** * Abstract base class for job for decrypting encrypted (signed) archives */ class QGPGME_EXPORT DecryptVerifyArchiveJob : public Job { Q_OBJECT protected: explicit DecryptVerifyArchiveJob(QObject *parent); public: ~DecryptVerifyArchiveJob() override; static bool isSupported(); void setOutputDirectory(const QString &outputDirectory); QString outputDirectory() const; /** * Starts the decryption of an encrypted (and signed) archive. * * Decrypts and extracts the encrypted archive in \a cipherText. If the * archive is signed, then the signature is verified. * If a non-empty output directory was set, then the content of the archive * is extracted into this directory. Otherwise, it is extracted into a * directory named \c GPGARCH_n_ (where \c n is a number). * * Emits result() when the job has finished. */ virtual GpgME::Error start(const std::shared_ptr &cipherText) = 0; Q_SIGNALS: + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the number of files. In the scanning phase (i.e. while gpgtar checks + * which files to put into the archive), \a current is the current number of + * files and \a total is 0. In the writing phase, \a current is the number + * of processed files and \a total is the total number of files. + */ + void fileProgress(int current, int total); + + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the amount of processed data. It is only emitted in the writing phase. + * \a current is the processed amount data and \a total is the total amount + * of data to process. Both values never exceed 2^20. + */ + void dataProgress(int current, int total); + void result(const GpgME::DecryptionResult &decryptionResult, const GpgME::VerificationResult &verificationResult, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {}); }; } #endif // __QGPGME_DECRYPTVERIFYARCHIVEJOB_H__ diff --git a/lang/qt/src/encryptarchivejob.h b/lang/qt/src/encryptarchivejob.h index 39b8fb14..b3c16c3a 100644 --- a/lang/qt/src/encryptarchivejob.h +++ b/lang/qt/src/encryptarchivejob.h @@ -1,91 +1,108 @@ /* encryptarchivejob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __QGPGME_ENCRYPTARCHIVEJOB_H__ #define __QGPGME_ENCRYPTARCHIVEJOB_H__ #include "job.h" #ifdef BUILDING_QGPGME # include "context.h" #else # include #endif namespace GpgME { class Key; } namespace QGpgME { /** * Abstract base class for job for creating encrypted archives */ class QGPGME_EXPORT EncryptArchiveJob : public Job { Q_OBJECT protected: explicit EncryptArchiveJob(QObject *parent); public: ~EncryptArchiveJob() override; static bool isSupported(); void setBaseDirectory(const QString &baseDirectory); QString baseDirectory() const; /** * Starts the creation of an encrypted archive. * * Encrypts the files and directories in \a paths into an archive for the * keys in \a recipients. If \a recipients is empty, then symmetric * encryption is performed. The encrypted archive is written to \a cipherText. * * Emits result() when the job has finished. */ virtual GpgME::Error start(const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags flags) = 0; Q_SIGNALS: + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the number of files. In the scanning phase (i.e. while gpgtar checks + * which files to put into the archive), \a current is the current number of + * files and \a total is 0. In the writing phase, \a current is the number + * of processed files and \a total is the total number of files. + */ + void fileProgress(int current, int total); + + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the amount of processed data. It is only emitted in the writing phase. + * \a current is the processed amount data and \a total is the total amount + * of data to process. Both values never exceed 2^20. + */ + void dataProgress(int current, int total); + void result(const GpgME::EncryptionResult &result, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {}); }; } #endif // __QGPGME_ENCRYPTARCHIVEJOB_H__ diff --git a/lang/qt/src/job_p.h b/lang/qt/src/job_p.h index ff99d6ea..7d0f9952 100644 --- a/lang/qt/src/job_p.h +++ b/lang/qt/src/job_p.h @@ -1,67 +1,88 @@ /* job_p.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2021 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __QGPGME_JOB_P_H__ #define __QGPGME_JOB_P_H__ #include "job.h" +#include "qgpgme_debug.h" + #include namespace QGpgME { // Base class for pimpl classes for Job subclasses class JobPrivate { public: virtual ~JobPrivate() {} virtual void start() = 0; }; // Setter and getters for the externally stored pimpl instances of jobs // BCI: Add a real d-pointer to Job void setJobPrivate(const Job *job, std::unique_ptr d); JobPrivate *getJobPrivate(const Job *job); template static T *jobPrivate(const Job *job) { auto d = getJobPrivate(job); return dynamic_cast(d); } +// Helper for the archive job classes +template +void emitArchiveProgressSignals(JobClass *job, const QString &what, int type, int current, int total) +{ + if (what != QLatin1String{"gpgtar"}) { + return; + } + switch (type) { + case 'c': + Q_EMIT job->fileProgress(current, total); + break; + case 's': + Q_EMIT job->dataProgress(current, total); + break; + default: + qCDebug(QGPGME_LOG) << job << __func__ << "Received progress for gpgtar with unknown type" << char(type); + }; +} + } #endif // __QGPGME_JOB_P_H__ diff --git a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp index 2e8c89c1..ddbbac20 100644 --- a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp +++ b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp @@ -1,119 +1,122 @@ /* qgpgmedecryptverifyarchivejob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmedecryptverifyarchivejob.h" #include "dataprovider.h" #include "decryptverifyarchivejob_p.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMEDecryptVerifyArchiveJobPrivate : public DecryptVerifyArchiveJobPrivate { QGpgMEDecryptVerifyArchiveJob *q = nullptr; public: QGpgMEDecryptVerifyArchiveJobPrivate(QGpgMEDecryptVerifyArchiveJob *qq) : q{qq} { } ~QGpgMEDecryptVerifyArchiveJobPrivate() override = default; private: void start() override { q->run(); } }; } QGpgMEDecryptVerifyArchiveJob::QGpgMEDecryptVerifyArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMEDecryptVerifyArchiveJobPrivate{this}}); lateInitialization(); + connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { + emitArchiveProgressSignals(this, what, type, current, total); + }); } static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify(Context *ctx, QThread *thread, const std::weak_ptr &cipherText_, const QString &outputDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::QIODeviceDataProvider in{cipherText}; Data indata(&in); Data outdata; if (!outputDirectory.isEmpty()) { outdata.setFileName(outputDirectory.toStdString()); } const auto res = ctx->decryptAndVerify(indata, outdata, Context::DecryptArchive); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, log, ae); } GpgME::Error QGpgMEDecryptVerifyArchiveJob::start(const std::shared_ptr &cipherText) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&decrypt_verify, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, outputDirectory()), cipherText); return {}; } #include "qgpgmedecryptverifyarchivejob.moc" diff --git a/lang/qt/src/qgpgmeencryptarchivejob.cpp b/lang/qt/src/qgpgmeencryptarchivejob.cpp index 91086426..3dc5b433 100644 --- a/lang/qt/src/qgpgmeencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmeencryptarchivejob.cpp @@ -1,131 +1,134 @@ /* qgpgmeencryptarchivejob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2022,2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmeencryptarchivejob.h" #include "dataprovider.h" #include "encryptarchivejob_p.h" #include "filelistdataprovider.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMEEncryptArchiveJobPrivate : public EncryptArchiveJobPrivate { QGpgMEEncryptArchiveJob *q = nullptr; public: QGpgMEEncryptArchiveJobPrivate(QGpgMEEncryptArchiveJob *qq) : q{qq} { } ~QGpgMEEncryptArchiveJobPrivate() override = default; private: void start() override { q->run(); } }; } QGpgMEEncryptArchiveJob::QGpgMEEncryptArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMEEncryptArchiveJobPrivate{this}}); lateInitialization(); + connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { + emitArchiveProgressSignals(this, what, type, current, total); + }); } static QGpgMEEncryptArchiveJob::result_type encrypt(Context *ctx, QThread *thread, const std::vector &recipients, const std::vector &paths, const std::weak_ptr &cipherText_, Context::EncryptionFlags flags, const QString &baseDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{cipherText}; Data outdata(&out); flags = static_cast(flags | Context::EncryptArchive); const EncryptionResult res = ctx->encrypt(recipients, indata, outdata, flags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } GpgME::Error QGpgMEEncryptArchiveJob::start(const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags flags) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&encrypt, std::placeholders::_1, std::placeholders::_2, recipients, paths, std::placeholders::_3, flags, baseDirectory()), cipherText); return {}; } #include "qgpgmeencryptarchivejob.moc" diff --git a/lang/qt/src/qgpgmesignarchivejob.cpp b/lang/qt/src/qgpgmesignarchivejob.cpp index 0a99627a..cd569f31 100644 --- a/lang/qt/src/qgpgmesignarchivejob.cpp +++ b/lang/qt/src/qgpgmesignarchivejob.cpp @@ -1,136 +1,139 @@ /* qgpgmesignarchivejob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2022,2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmesignarchivejob.h" #include "dataprovider.h" #include "signarchivejob_p.h" #include "filelistdataprovider.h" #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMESignArchiveJobPrivate : public SignArchiveJobPrivate { QGpgMESignArchiveJob *q = nullptr; public: QGpgMESignArchiveJobPrivate(QGpgMESignArchiveJob *qq) : q{qq} { } ~QGpgMESignArchiveJobPrivate() override = default; private: void start() override { q->run(); } }; } QGpgMESignArchiveJob::QGpgMESignArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMESignArchiveJobPrivate{this}}); lateInitialization(); + connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { + emitArchiveProgressSignals(this, what, type, current, total); + }); } static QGpgMESignArchiveJob::result_type sign(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &paths, const std::weak_ptr &output_, const QString &baseDirectory) { const std::shared_ptr output = output_.lock(); const _detail::ToThreadMover ctMover(output, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{output}; Data outdata(&out); ctx->clearSigningKeys(); for (const Key &signer : signers) { if (!signer.isNull()) { if (const Error err = ctx->addSigningKey(signer)) { return std::make_tuple(SigningResult{err}, QString{}, Error{}); } } } const SigningResult res = ctx->sign(indata, outdata, GpgME::SignArchive); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res, log, ae); } GpgME::Error QGpgMESignArchiveJob::start(const std::vector &signers, const std::vector &paths, const std::shared_ptr &output) { if (!output) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&sign, std::placeholders::_1, std::placeholders::_2, signers, paths, std::placeholders::_3, baseDirectory()), output); return {}; } #include "qgpgmesignarchivejob.moc" diff --git a/lang/qt/src/qgpgmesignencryptarchivejob.cpp b/lang/qt/src/qgpgmesignencryptarchivejob.cpp index b75c4d0f..c5e00ef0 100644 --- a/lang/qt/src/qgpgmesignencryptarchivejob.cpp +++ b/lang/qt/src/qgpgmesignencryptarchivejob.cpp @@ -1,150 +1,153 @@ /* qgpgmesignencryptarchivejob.cpp This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2004,2007,2008 Klarälvdalens Datakonsult AB Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Copyright (c) 2022,2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "qgpgmesignencryptarchivejob.h" #include "dataprovider.h" #include "signencryptarchivejob_p.h" #include "filelistdataprovider.h" // #include #include // #include // // #include // #include // // #include using namespace QGpgME; using namespace GpgME; namespace { class QGpgMESignEncryptArchiveJobPrivate : public SignEncryptArchiveJobPrivate { QGpgMESignEncryptArchiveJob *q = nullptr; public: QGpgMESignEncryptArchiveJobPrivate(QGpgMESignEncryptArchiveJob *qq) : q{qq} { } ~QGpgMESignEncryptArchiveJobPrivate() override = default; private: void start() override { q->run(); } }; } QGpgMESignEncryptArchiveJob::QGpgMESignEncryptArchiveJob(Context *context) : mixin_type{context} { setJobPrivate(this, std::unique_ptr{new QGpgMESignEncryptArchiveJobPrivate{this}}); lateInitialization(); + connect(this, &Job::rawProgress, this, [this](const QString &what, int type, int current, int total) { + emitArchiveProgressSignals(this, what, type, current, total); + }); } static QGpgMESignEncryptArchiveJob::result_type sign_encrypt(Context *ctx, QThread *thread, const std::vector &signers, const std::vector &recipients, const std::vector &paths, const std::weak_ptr &cipherText_, Context::EncryptionFlags encryptionFlags, const QString &baseDirectory) { const std::shared_ptr cipherText = cipherText_.lock(); const _detail::ToThreadMover ctMover(cipherText, thread); QGpgME::FileListDataProvider in{paths}; Data indata(&in); if (!baseDirectory.isEmpty()) { indata.setFileName(baseDirectory.toStdString()); } QGpgME::QIODeviceDataProvider out{cipherText}; Data outdata(&out); ctx->clearSigningKeys(); for (const Key &signer : signers) { if (!signer.isNull()) { if (const Error err = ctx->addSigningKey(signer)) { return std::make_tuple(SigningResult{err}, EncryptionResult{}, QString{}, Error{}); } } } encryptionFlags = static_cast(encryptionFlags | Context::EncryptArchive); const auto res = ctx->signAndEncrypt(recipients, indata, outdata, encryptionFlags); Error ae; const QString log = _detail::audit_log_as_html(ctx, ae); return std::make_tuple(res.first, res.second, log, ae); } GpgME::Error QGpgMESignEncryptArchiveJob::start(const std::vector &signers, const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags encryptionFlags) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } run(std::bind(&sign_encrypt, std::placeholders::_1, std::placeholders::_2, signers, recipients, paths, std::placeholders::_3, encryptionFlags, baseDirectory()), cipherText); return {}; } #include "qgpgmesignencryptarchivejob.moc" diff --git a/lang/qt/src/signarchivejob.h b/lang/qt/src/signarchivejob.h index f30e3e5e..ef2b6754 100644 --- a/lang/qt/src/signarchivejob.h +++ b/lang/qt/src/signarchivejob.h @@ -1,90 +1,107 @@ /* signarchivejob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __QGPGME_SIGNARCHIVEJOB_H__ #define __QGPGME_SIGNARCHIVEJOB_H__ #include "job.h" #ifdef BUILDING_QGPGME # include "context.h" #else # include #endif namespace GpgME { class Key; } namespace QGpgME { /** * Abstract base class for job for creating signed archives */ class QGPGME_EXPORT SignArchiveJob : public Job { Q_OBJECT protected: explicit SignArchiveJob(QObject *parent); public: ~SignArchiveJob() override; static bool isSupported(); void setBaseDirectory(const QString &baseDirectory); QString baseDirectory() const; /** * Starts the creation of a signed archive. * * Creates a signed archive with the files and directories in \a paths. * The archive is signed with the keys in \a signers or with the default * key, if \a signers is empty. The signed archive is written to \a output. * * Emits result() when the job has finished. */ virtual GpgME::Error start(const std::vector &signers, const std::vector &paths, const std::shared_ptr &output) = 0; Q_SIGNALS: + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the number of files. In the scanning phase (i.e. while gpgtar checks + * which files to put into the archive), \a current is the current number of + * files and \a total is 0. In the writing phase, \a current is the number + * of processed files and \a total is the total number of files. + */ + void fileProgress(int current, int total); + + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the amount of processed data. It is only emitted in the writing phase. + * \a current is the processed amount data and \a total is the total amount + * of data to process. Both values never exceed 2^20. + */ + void dataProgress(int current, int total); + void result(const GpgME::SigningResult &result, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {}); }; } #endif // __QGPGME_SIGNARCHIVEJOB_H__ diff --git a/lang/qt/src/signencryptarchivejob.h b/lang/qt/src/signencryptarchivejob.h index 2cc28a5e..a14b6d64 100644 --- a/lang/qt/src/signencryptarchivejob.h +++ b/lang/qt/src/signencryptarchivejob.h @@ -1,97 +1,114 @@ /* signencryptarchivejob.h This file is part of qgpgme, the Qt API binding for gpgme Copyright (c) 2023 g10 Code GmbH Software engineering by Ingo Klöcker QGpgME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. QGpgME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #ifndef __QGPGME_SIGNENCRYPTARCHIVEJOB_H__ #define __QGPGME_SIGNENCRYPTARCHIVEJOB_H__ #include "job.h" #ifdef BUILDING_QGPGME # include "context.h" #else # include #endif namespace GpgME { class Key; } namespace QGpgME { /** * Abstract base class for job for creating encrypted signed archives */ class QGPGME_EXPORT SignEncryptArchiveJob : public Job { Q_OBJECT protected: explicit SignEncryptArchiveJob(QObject *parent); public: ~SignEncryptArchiveJob() override; static bool isSupported(); void setBaseDirectory(const QString &baseDirectory); QString baseDirectory() const; /** * Starts the creation of an encrypted signed archive. * * Creates an encrypted signed archive with the files and directories in * \a paths. * The archive is signed with the keys in \a signers or with the default * key, if \a signers is empty. Then the archive is encrypted for the * keys in \a recipients. If \a recipients is empty, then symmetric * encryption is performed. The encrypted signed archive is written to * \a cipherText. * * Emits result() when the job has finished. */ virtual GpgME::Error start(const std::vector &signers, const std::vector &recipients, const std::vector &paths, const std::shared_ptr &cipherText, const GpgME::Context::EncryptionFlags flags) = 0; Q_SIGNALS: + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the number of files. In the scanning phase (i.e. while gpgtar checks + * which files to put into the archive), \a current is the current number of + * files and \a total is 0. In the writing phase, \a current is the number + * of processed files and \a total is the total number of files. + */ + void fileProgress(int current, int total); + + /** + * This signal is emitted whenever gpgtar sends a progress status update for + * the amount of processed data. It is only emitted in the writing phase. + * \a current is the processed amount data and \a total is the total amount + * of data to process. Both values never exceed 2^20. + */ + void dataProgress(int current, int total); + void result(const GpgME::SigningResult &signingResult, const GpgME::EncryptionResult &encryptionResult, const QString &auditLogAsHtml = {}, const GpgME::Error &auditLogError = {}); }; } #endif // __QGPGME_SIGNENCRYPTARCHIVEJOB_H__