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.
This commit is contained in:
Andre Heinecke 2016-08-12 16:51:13 +02:00
parent fe1e8e71aa
commit df7bbf5a66

View File

@ -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" ) << ", "