OSDN Git Service

okular: simplify compressed MIME type checks
authorIvailo Monev <xakepa10@gmail.com>
Sun, 21 May 2023 04:41:36 +0000 (07:41 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Sun, 21 May 2023 04:41:36 +0000 (07:41 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
okular/part.cpp

index fae5968..1626e44 100644 (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 )
     {