diff options
Diffstat (limited to 'lang/qt/src')
-rw-r--r-- | lang/qt/src/decryptverifyarchivejob.cpp | 12 | ||||
-rw-r--r-- | lang/qt/src/decryptverifyarchivejob.h | 12 | ||||
-rw-r--r-- | lang/qt/src/decryptverifyarchivejob_p.h | 1 | ||||
-rw-r--r-- | lang/qt/src/qgpgmedecryptverifyarchivejob.cpp | 61 |
4 files changed, 69 insertions, 17 deletions
diff --git a/lang/qt/src/decryptverifyarchivejob.cpp b/lang/qt/src/decryptverifyarchivejob.cpp index ebfd36ca..76c1721a 100644 --- a/lang/qt/src/decryptverifyarchivejob.cpp +++ b/lang/qt/src/decryptverifyarchivejob.cpp @@ -56,6 +56,18 @@ bool DecryptVerifyArchiveJob::isSupported() return (gpgVersion >= "2.4.1") || (gpgVersion >= "2.2.42" && gpgVersion < "2.3.0"); } +void DecryptVerifyArchiveJob::setInputFile(const QString &path) +{ + auto d = jobPrivate<DecryptVerifyArchiveJobPrivate>(this); + d->m_inputFilePath = path; +} + +QString DecryptVerifyArchiveJob::inputFile() const +{ + auto d = jobPrivate<DecryptVerifyArchiveJobPrivate>(this); + return d->m_inputFilePath; +} + void DecryptVerifyArchiveJob::setOutputDirectory(const QString &outputDirectory) { auto d = jobPrivate<DecryptVerifyArchiveJobPrivate>(this); diff --git a/lang/qt/src/decryptverifyarchivejob.h b/lang/qt/src/decryptverifyarchivejob.h index 4e72be2d..6d87dd36 100644 --- a/lang/qt/src/decryptverifyarchivejob.h +++ b/lang/qt/src/decryptverifyarchivejob.h @@ -63,6 +63,18 @@ public: static bool isSupported(); + /** + * Sets the path of the file to read the archive from. + * + * Used if the job is started with startIt(). + */ + void setInputFile(const QString &path); + QString inputFile() const; + + /** + * Sets the directory the content of the decrypted archive shall be + * written to. + */ void setOutputDirectory(const QString &outputDirectory); QString outputDirectory() const; diff --git a/lang/qt/src/decryptverifyarchivejob_p.h b/lang/qt/src/decryptverifyarchivejob_p.h index b4e66530..e0823d23 100644 --- a/lang/qt/src/decryptverifyarchivejob_p.h +++ b/lang/qt/src/decryptverifyarchivejob_p.h @@ -41,6 +41,7 @@ namespace QGpgME struct DecryptVerifyArchiveJobPrivate : public JobPrivate { + QString m_inputFilePath; QString m_outputDirectory; }; diff --git a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp index 3fd58e35..98ca7403 100644 --- a/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp +++ b/lang/qt/src/qgpgmedecryptverifyarchivejob.cpp @@ -43,6 +43,8 @@ #include "dataprovider.h" #include "decryptverifyarchivejob_p.h" +#include <QFile> + #include <data.h> using namespace QGpgME; @@ -64,11 +66,7 @@ public: ~QGpgMEDecryptVerifyArchiveJobPrivate() override = default; private: - GpgME::Error startIt() override - { - Q_ASSERT(!"Not supported by this Job class."); - return Error::fromCode(GPG_ERR_NOT_SUPPORTED); - } + GpgME::Error startIt() override; void startNow() override { @@ -89,19 +87,9 @@ QGpgMEDecryptVerifyArchiveJob::QGpgMEDecryptVerifyArchiveJob(Context *context) } static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify(Context *ctx, - QThread *thread, - const std::weak_ptr<QIODevice> &cipherText_, + const GpgME::Data &indata, const QString &outputDirectory) { - const std::shared_ptr<QIODevice> cipherText = cipherText_.lock(); - const _detail::ToThreadMover ctMover(cipherText, thread); - - QGpgME::QIODeviceDataProvider in{cipherText}; - Data indata(&in); - if (!cipherText->isSequential()) { - indata.setSizeHint(cipherText->size()); - } - Data outdata; if (!outputDirectory.isEmpty()) { outdata.setFileName(outputDirectory.toStdString()); @@ -113,13 +101,39 @@ static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify(Context *ctx, return std::make_tuple(res.first, res.second, log, ae); } +static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify_from_io_device(Context *ctx, + QThread *thread, + const std::weak_ptr<QIODevice> &cipherText_, + const QString &outputDirectory) +{ + const std::shared_ptr<QIODevice> cipherText = cipherText_.lock(); + const _detail::ToThreadMover ctMover(cipherText, thread); + QGpgME::QIODeviceDataProvider in{cipherText}; + Data indata(&in); + if (!cipherText->isSequential()) { + indata.setSizeHint(cipherText->size()); + } + + return decrypt_verify(ctx, indata, outputDirectory); +} + +static QGpgMEDecryptVerifyArchiveJob::result_type decrypt_verify_from_file_name(Context *ctx, + const QString &inputFile, + const QString &outputDirectory) +{ + Data indata; + indata.setFileName(QFile::encodeName(inputFile).constData()); + + return decrypt_verify(ctx, indata, outputDirectory); +} + GpgME::Error QGpgMEDecryptVerifyArchiveJob::start(const std::shared_ptr<QIODevice> &cipherText) { if (!cipherText) { return Error::fromCode(GPG_ERR_INV_VALUE); } - run(std::bind(&decrypt_verify, + run(std::bind(&decrypt_verify_from_io_device, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, @@ -128,4 +142,17 @@ GpgME::Error QGpgMEDecryptVerifyArchiveJob::start(const std::shared_ptr<QIODevic return {}; } +GpgME::Error QGpgMEDecryptVerifyArchiveJobPrivate::startIt() +{ + if (m_inputFilePath.isEmpty()) { + return Error::fromCode(GPG_ERR_INV_VALUE); + } + + q->run([=](Context *ctx) { + return decrypt_verify_from_file_name(ctx, m_inputFilePath, m_outputDirectory); + }); + + return {}; +} + #include "qgpgmedecryptverifyarchivejob.moc" |