diff options
author | Andre Heinecke <[email protected]> | 2016-08-12 14:51:13 +0000 |
---|---|---|
committer | Andre Heinecke <[email protected]> | 2016-08-12 14:51:13 +0000 |
commit | df7bbf5a66576a5a320b54c8f6ad52bc84f0e833 (patch) | |
tree | 7da6eaab9c1593649aa9be51af8ba0020cb69b21 | |
parent | core: Make use of the "size-hint" in engine-gpg. (diff) | |
download | gpgme-df7bbf5a66576a5a320b54c8f6ad52bc84f0e833.tar.gz gpgme-df7bbf5a66576a5a320b54c8f6ad52bc84f0e833.zip |
Cpp: Provide size-hint for seekable and mem data
* lang/cpp/src/data.cpp (GpgME::Data::Data): Set size-hint for
mem and DataProvider based Data.
--
This fixes the case that QGpgME did not have a total value for
progress as the size was unknown.
-rw-r--r-- | lang/cpp/src/data.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index 64acb47f..9527b2ff 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -62,6 +62,9 @@ GpgME::Data::Data(const char *buffer, size_t size, bool copy) { gpgme_data_t data; const gpgme_error_t e = gpgme_data_new_from_mem(&data, buffer, size, int(copy)); + std::string sizestr = std::to_string(size); + // Ignore errors as this is optional + gpgme_data_set_flag(data, "size-hint", sizestr.c_str()); d.reset(new Private(e ? 0 : data)); } @@ -125,6 +128,13 @@ GpgME::Data::Data(DataProvider *dp) if (e) { d->data = 0; } + if (dp->isSupported(DataProvider::Seek)) { + off_t size = seek(0, SEEK_END); + seek(0, SEEK_SET); + std::string sizestr = std::to_string(size); + // Ignore errors as this is optional + gpgme_data_set_flag(d->data, "size-hint", sizestr.c_str()); + } #ifndef NDEBUG //std::cerr << "GpgME::Data(): DataProvider supports: " // << ( d->cbs.read ? "read" : "no read" ) << ", " |