okular: simplify compressed MIME type checks

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-05-21 07:41:36 +03:00
parent 019587b602
commit 097c27daac

View file

@ -180,38 +180,29 @@ static QAction* actionForExportFormat( const Okular::ExportFormat& format, QObje
static QString compressedMimeFor( const QString& mime_to_check )
{
// The compressedMimeMap is here in case you have a very old shared mime database
// that doesn't have inheritance info for things like gzeps, etc
// Otherwise the "is()" calls below are just good enough
static QHash< QString, QString > compressedMimeMap;
static bool supportChecked = false;
static bool supportBzip = false;
static bool supportXz = false;
const QString app_gzip( QString::fromLatin1( "application/x-gzip" ) );
const QString app_bzip( QString::fromLatin1( "application/x-bzip" ) );
const QString app_xz( QString::fromLatin1( "application/x-xz" ) );
if ( compressedMimeMap.isEmpty() )
if ( !supportChecked )
{
KDecompressor f;
compressedMimeMap[ QString::fromLatin1( "image/x-gzeps" ) ] = app_gzip;
// check we can read bzip2-compressed files
if ( f.setType( KDecompressor::typeForMime( app_bzip ) ) )
if ( f.setType( KDecompressor::TypeBZip2 ) )
{
supportBzip = true;
compressedMimeMap[ QString::fromLatin1( "application/x-bzpdf" ) ] = app_bzip;
compressedMimeMap[ QString::fromLatin1( "application/x-bzpostscript" ) ] = app_bzip;
compressedMimeMap[ QString::fromLatin1( "application/x-bzdvi" ) ] = app_bzip;
compressedMimeMap[ QString::fromLatin1( "image/x-bzeps" ) ] = app_bzip;
}
// check we can read XZ-compressed files
if ( f.setType( KDecompressor::typeForMime( app_xz ) ) )
if ( f.setType( KDecompressor::TypeXZ ) )
{
supportXz = true;
}
supportChecked = true;
}
QHash< QString, QString >::const_iterator it = compressedMimeMap.constFind( mime_to_check );
if ( it != compressedMimeMap.constEnd() )
return it.value();
// The "is()" calls below check inheritance too
KMimeType::Ptr mime = KMimeType::mimeType( mime_to_check );
if ( mime )
{