185
185
static QString compressedMimeFor( const QString& mime_to_check )
187
// The compressedMimeMap is here in case you have a very old shared mime database
188
// that doesn't have inheritance info for things like gzeps, etc
189
// Otherwise the "is()" calls below are just good enough
187
190
static QHash< QString, QString > compressedMimeMap;
191
static bool supportBzip = false;
192
static bool supportXz = false;
193
const QString app_gzip( QString::fromLatin1( "application/x-gzip" ) );
194
const QString app_bzip( QString::fromLatin1( "application/x-bzip" ) );
195
const QString app_xz( QString::fromLatin1( "application/x-xz" ) );
188
196
if ( compressedMimeMap.isEmpty() )
190
198
std::auto_ptr< KFilterBase > f;
191
compressedMimeMap[ QString::fromLatin1( "application/x-gzip" ) ] =
192
QString::fromLatin1( "application/x-gzip" );
193
compressedMimeMap[ QString::fromLatin1( "image/x-gzeps" ) ] =
194
QString::fromLatin1( "application/x-gzip" );
199
compressedMimeMap[ QString::fromLatin1( "image/x-gzeps" ) ] = app_gzip;
195
200
// check we can read bzip2-compressed files
196
f.reset( KFilterBase::findFilterByMimeType( QString::fromLatin1( "application/x-bzip" ) ) );
201
f.reset( KFilterBase::findFilterByMimeType( app_bzip ) );
199
const QString app_bzip( QString::fromLatin1( "application/x-bzip" ) );
200
compressedMimeMap[ app_bzip ] = app_bzip;
201
205
compressedMimeMap[ QString::fromLatin1( "application/x-bzpdf" ) ] = app_bzip;
202
206
compressedMimeMap[ QString::fromLatin1( "application/x-bzpostscript" ) ] = app_bzip;
203
207
compressedMimeMap[ QString::fromLatin1( "application/x-bzdvi" ) ] = app_bzip;
204
208
compressedMimeMap[ QString::fromLatin1( "image/x-bzeps" ) ] = app_bzip;
206
210
// check we can read XZ-compressed files
207
f.reset( KFilterBase::findFilterByMimeType( QString::fromLatin1( "application/x-xz" ) ) );
211
f.reset( KFilterBase::findFilterByMimeType( app_xz ) );
210
const QString app_xz( QString::fromLatin1( "application/x-xz" ) );
211
compressedMimeMap[ app_xz ] = app_xz;
214
217
QHash< QString, QString >::const_iterator it = compressedMimeMap.constFind( mime_to_check );
215
218
if ( it != compressedMimeMap.constEnd() )
216
219
return it.value();
221
KMimeType::Ptr mime = KMimeType::mimeType( mime_to_check );
222
if ( mime->is( app_gzip ) )
224
else if ( supportBzip && mime->is( app_bzip ) )
226
else if ( supportXz && mime->is( app_xz ) )
218
229
return QString();