From df7bbf5a66576a5a320b54c8f6ad52bc84f0e833 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Fri, 12 Aug 2016 16:51:13 +0200 Subject: [PATCH] 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. --- lang/cpp/src/data.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) 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" ) << ", "