KPreviewWidgetBase * KFileMetaPreview::previewProviderFor( const TQString& mimeType ) { // tqDebug("### looking for: %s", mimeType.latin1()); // often the first highlighted item, where we can be sure, there is no plugin // (this "folders reflect icons" is a konq-specific thing, right?) if ( mimeType == "inode/directory" ) return 0L; KPreviewWidgetBase *provider = m_previewProviders.find( mimeType ); if ( provider ) return provider; //tqDebug("#### didn't find anything for: %s", mimeType.latin1()); if ( s_tryAudioPreview && !mimeType.startsWith("text/") && !mimeType.startsWith("image/") ) { if ( !haveAudioPreview ) { KPreviewWidgetBase *audioPreview = createAudioPreview( m_stack ); if ( audioPreview ) { haveAudioPreview = true; (void) m_stack->addWidget( audioPreview ); TQStringList mimeTypes = audioPreview->supportedMimeTypes(); TQStringList::ConstIterator it = mimeTypes.begin(); for ( ; it != mimeTypes.end(); ++it ) m_previewProviders.insert( *it, audioPreview ); } } } // with the new mimetypes from the audio-preview, try again provider = m_previewProviders.find( mimeType ); if ( provider ) return provider; // ### mimetype may be image/* for example, try that int index = mimeType.find( '/' ); if ( index > 0 ) { provider = m_previewProviders.find( mimeType.left( index + 1 ) + "*" ); if ( provider ) return provider; } KMimeType::Ptr mimeInfo = KMimeType::mimeType( mimeType ); if ( mimeInfo ) { // check mime type inheritance TQString 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-TDE-Text property TQVariant textProperty = mimeInfo->property( "X-TDE-text" ); if ( textProperty.isValid() && textProperty.type() == TQVariant::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; }
void PreviewJob::startPreview() { // Load the list of plugins to determine which mimetypes are supported TDETrader::OfferList plugins = TDETrader::self()->query("ThumbCreator"); TQMap<TQString, KService::Ptr> mimeMap; for (TDETrader::OfferList::ConstIterator it = plugins.begin(); it != plugins.end(); ++it) if (!d->enabledPlugins || d->enabledPlugins->contains((*it)->desktopEntryName())) { TQStringList mimeTypes = (*it)->property("MimeTypes").toStringList(); for (TQStringList::ConstIterator mt = mimeTypes.begin(); mt != mimeTypes.end(); ++mt) mimeMap.insert(*mt, *it); } // Look for images and store the items in our todo list :) bool bNeedCache = false; for (KFileItemListIterator it(d->initialItems); it.current(); ++it ) { PreviewItem item; item.item = it.current(); TQMap<TQString, KService::Ptr>::ConstIterator plugin = mimeMap.find(it.current()->mimetype()); if (plugin == mimeMap.end() && (it.current()->mimetype() != "application/x-desktop") && (it.current()->mimetype() != "media/builtin-mydocuments") && (it.current()->mimetype() != "media/builtin-mycomputer") && (it.current()->mimetype() != "media/builtin-mynetworkplaces") && (it.current()->mimetype() != "media/builtin-printers") && (it.current()->mimetype() != "media/builtin-trash") && (it.current()->mimetype() != "media/builtin-webbrowser")) { TQString mimeType = it.current()->mimetype(); plugin = mimeMap.find(mimeType.replace(TQRegExp("/.*"), "/*")); if (plugin == mimeMap.end()) { // check mime type inheritance KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype()); TQString 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-TDE-Text property KMimeType::Ptr mimeInfo = KMimeType::mimeType(it.current()->mimetype()); TQVariant textProperty = mimeInfo->property("X-TDE-text"); if (textProperty.isValid() && textProperty.type() == TQVariant::Bool) { if (textProperty.toBool()) { plugin = mimeMap.find("text/plain"); if (plugin == mimeMap.end()) { plugin = mimeMap.find( "text/*" ); } } } } } if (plugin != mimeMap.end()) { item.plugin = *plugin; d->items.append(item); if (!bNeedCache && d->bSave && (it.current()->url().protocol() != "file" || !it.current()->url().directory( false ).startsWith(d->thumbRoot)) && (*plugin)->property("CacheThumbnail").toBool()) bNeedCache = true; } else { emitFailed(it.current()); if (d->deleteItems) delete it.current(); } } // Read configuration value for the maximum allowed size TDEConfig * config = TDEGlobal::config(); TDEConfigGroupSaver cgs( config, "PreviewSettings" ); d->maximumSize = config->readNumEntry( "MaximumSize", 1024*1024 /* 1MB */ ); if (bNeedCache) { if (d->width <= 128 && d->height <= 128) d->cacheWidth = d->cacheHeight = 128; else d->cacheWidth = d->cacheHeight = 256; d->thumbPath = d->thumbRoot + (d->cacheWidth == 128 ? "normal/" : "large/"); TDEStandardDirs::makeDir(d->thumbPath, 0700); } else d->bSave = false; determineNextFile(); }