kdeui: return a single format type from KImageIO::typeForMime() and add mode argument for it

because it returns only one (definitive) format type using QStringList as
return type makes no sense, also a mode argument is very much required to
return correct result - not all image format plugins support writing

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-08 17:57:18 +03:00
parent 0c2a65b0e9
commit 65bedeae01
2 changed files with 18 additions and 12 deletions

View file

@ -41,15 +41,22 @@ QString KImageIO::pattern(Mode mode)
return patterns.join(QLatin1String("\n"));
}
QStringList KImageIO::typeForMime(const QString &mimeType)
QString KImageIO::typeForMime(const QString &mimeType, Mode mode)
{
QStringList result;
QString result;
if (mimeType.isEmpty()) {
return result;
}
const QByteArray format = QImageReader::formatForMimeType(mimeType.toLatin1());
if (!format.isEmpty()) {
result << QString::fromLatin1(format.constData(), format.size());
if (mode == KImageIO::Reading) {
const QByteArray format = QImageReader::formatForMimeType(mimeType.toLatin1());
if (!format.isEmpty()) {
result = QString::fromLatin1(format.constData(), format.size());
}
} else {
const QByteArray format = QImageWriter::formatForMimeType(mimeType.toLatin1());
if (!format.isEmpty()) {
result = QString::fromLatin1(format.constData(), format.size());
}
}
return result;
}

View file

@ -43,22 +43,21 @@ namespace KImageIO
/**
* Returns a list of patterns of all KImageIO supported formats.
*
* These patterns can be passed to KFileDialog::getOpenFileName()
* or KFileDialog::getSaveFileName(), for example.
* These patterns can be passed to KFileDialog::getOpenFileName() or
* KFileDialog::getSaveFileName(), for example.
*
* @param mode Tells whether to retrieve modes that can be read or written.
* @return a space-separated list of file globs that describe the
* supported formats
* @return a space-separated list of file globs that describe the supported formats
*/
KDEUI_EXPORT QString pattern(Mode mode = Reading);
/**
* Returns the type of a MIME type.
* @param mimeType the MIME type to search
* @return type id(s) of the MIME type or QStringList() if the MIME type
* is not supported
* @param mode Tells whether to retrieve type that can be read or written.
* @return type id of the MIME type or QString() if the MIME type is not supported
*/
KDEUI_EXPORT QStringList typeForMime(const QString &mimeType);
KDEUI_EXPORT QString typeForMime(const QString &mimeType, Mode mode = Writing);
/**
* Returns a list of all KImageIO supported formats.
*