From 097c27daac118ac86997eaa18cb25b51604762dc Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 21 May 2023 07:41:36 +0300 Subject: [PATCH] okular: simplify compressed MIME type checks Signed-off-by: Ivailo Monev --- okular/part.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/okular/part.cpp b/okular/part.cpp index fae5968c..1626e44d 100644 --- a/okular/part.cpp +++ b/okular/part.cpp @@ -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 ) {