From kde-commits Fri Nov 11 15:43:28 2005 From: Kevin Krammer Date: Fri, 11 Nov 2005 15:43:28 +0000 To: kde-commits Subject: branches/KDE/3.5/kdelibs/kio Message-Id: <1131723808.630185.14629.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=113172381908573 SVN commit 479737 by krake: Fixes the second issue of Bug 115825: PHP files, which have the MIME type application/x-php, could be previewed in KFileDialog's preview widget because there is not preview registered with that MIME type. However, being text files, the x-php.desktop file contains the KDE-text property. The patch adds checks for the MIME type inheritance chain and the KDE-text property for files that have no direct preview handler registered. M +34 -0 kfile/kfilemetapreview.cpp M +36 -0 kio/previewjob.cpp --- branches/KDE/3.5/kdelibs/kio/kfile/kfilemetapreview.cpp #479736:479737 @@ -100,6 +100,40 @@ return provider; } + KMimeType::Ptr mimeInfo = KMimeType::mimeType( mimeType ); + if ( mimeInfo ) + { + // check mime type inheritance + QString parentMimeType = mimeInfo->parentMimeType(); + while ( !parentMimeType.isEmpty() ) + { + provider = m_previewProviders.find( parentMimeType ); + if ( provider ) + return provider; + + KMimeType::Ptr parentMimeInfo = KMimeType::mimeType( parentMimeType ); + if ( !parentMimeInfo ) break; + + parentMimeType = parentMimeInfo->parentMimeType(); + } + + // check X-KDE-Text property + QVariant textProperty = mimeInfo->property( "X-KDE-text" ); + if ( textProperty.isValid() && textProperty.type() == QVariant::Bool ) + { + if ( textProperty.toBool() ) + { + provider = m_previewProviders.find( "text/plain" ); + if ( provider ) + return provider; + + provider = m_previewProviders.find( "text/*" ); + if ( provider ) + return provider; + } + } + } + return 0L; } --- branches/KDE/3.5/kdelibs/kio/kio/previewjob.cpp #479736:479737 @@ -179,7 +179,43 @@ { QString mimeType = it.current()->mimetype(); plugin = mimeMap.find(mimeType.replace(QRegExp("/.*"), "/*")); + + if (plugin == mimeMap.end()) + { + // check mime type inheritance + KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype()); + QString parentMimeType = mimeInfo->parentMimeType(); + while (!parentMimeType.isEmpty()) + { + plugin = mimeMap.find(parentMimeType); + if (plugin != mimeMap.end()) break; + + KMimeType::Ptr parentMimeInfo = KMimeType::mimeType(parentMimeType); + if (!parentMimeInfo) break; + + parentMimeType = parentMimeInfo->parentMimeType(); + } + } + + if (plugin == mimeMap.end()) + { + // check X-KDE-Text property + KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype()); + QVariant textProperty = mimeInfo->property("X-KDE-text"); + if (textProperty.isValid() && textProperty.type() == QVariant::Bool) + { + if (textProperty.toBool()) + { + plugin = mimeMap.find("text/plain"); + if (plugin == mimeMap.end()) + { + plugin = mimeMap.find( "text/*" ); + } + } + } + } } + if (plugin != mimeMap.end()) { item.plugin = *plugin;