kdecore: set error string when the type is invalid or unsupported from KCompressor::setType() and KDecompressor::setType()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-17 20:12:52 +03:00
parent 7ede848fe8
commit 1a23738c6d
2 changed files with 30 additions and 2 deletions

View file

@ -71,9 +71,23 @@ KCompressor::KCompressorType KCompressor::type() const
bool KCompressor::setType(const KCompressorType type)
{
d->m_errorstring.clear();
if (type == KCompressor::TypeUnknown) {
d->m_errorstring = i18n("Invalid type: %1", int(type));
return false;
}
#if !defined(HAVE_BZIP2_SUPPORT)
if (type == KCompressor::TypeBZip2) {
d->m_errorstring = i18n("Unsupported type: %1", int(type));
return false;
}
#endif
#if !defined(HAVE_XZ_SUPPORT)
if (type == KCompressor::TypeXZ) {
d->m_errorstring = i18n("Unsupported type: %1", int(type));
return false;
}
#endif
d->m_type = type;
return true;
}
@ -254,7 +268,7 @@ bool KCompressor::process(const QByteArray &data)
}
#endif // HAVE_XZ_SUPPORT
default: {
kWarning() << "Unsupported type" << d->m_type;
d->m_errorstring = i18n("Unsupported type: %1", int(d->m_type));
return false;
}
}

View file

@ -70,9 +70,23 @@ KDecompressor::KDecompressorType KDecompressor::type() const
bool KDecompressor::setType(const KDecompressorType type)
{
d->m_errorstring.clear();
if (type == KDecompressor::TypeUnknown) {
d->m_errorstring = i18n("Invalid type: %1", int(type));
return false;
}
#if !defined(HAVE_BZIP2_SUPPORT)
if (type == KCompressor::TypeBZip2) {
d->m_errorstring = i18n("Unsupported type: %1", int(type));
return false;
}
#endif
#if !defined(HAVE_XZ_SUPPORT)
if (type == KCompressor::TypeXZ) {
d->m_errorstring = i18n("Unsupported type: %1", int(type));
return false;
}
#endif
d->m_type = type;
return true;
}
@ -280,7 +294,7 @@ bool KDecompressor::process(const QByteArray &data)
}
#endif // HAVE_XZ_SUPPORT
default: {
kWarning() << "Unsupported type" << d->m_type;
d->m_errorstring = i18n("Unsupported type: %1", int(d->m_type));
return false;
}
}