9 #include "tdefilemetapreview.h"
13 #include <tdeio/previewjob.h>
14 #include <klibloader.h>
15 #include <kimagefilepreview.h>
16 #include <kmimetype.h>
18 bool KFileMetaPreview::s_tryAudioPreview =
true;
20 KFileMetaPreview::KFileMetaPreview( TQWidget *parent,
const char *name )
22 haveAudioPreview( false )
24 TQHBoxLayout *layout =
new TQHBoxLayout(
this, 0, 0 );
25 m_stack =
new TQWidgetStack(
this );
26 layout->addWidget( m_stack );
30 initPreviewProviders();
33 KFileMetaPreview::~KFileMetaPreview()
37 void KFileMetaPreview::initPreviewProviders()
39 m_previewProviders.clear();
44 (void) m_stack->addWidget( imagePreview );
45 m_stack->raiseWidget( imagePreview );
46 resize( imagePreview->sizeHint() );
48 TQStringList mimeTypes = imagePreview->supportedMimeTypes();
49 TQStringList::ConstIterator it = mimeTypes.begin();
50 for ( ; it != mimeTypes.end(); ++it )
53 m_previewProviders.insert( *it, imagePreview );
62 if ( mimeType ==
"inode/directory" )
71 if ( s_tryAudioPreview &&
72 !mimeType.startsWith(
"text/") && !mimeType.startsWith(
"image/") )
74 if ( !haveAudioPreview )
79 haveAudioPreview =
true;
80 (void) m_stack->addWidget( audioPreview );
81 TQStringList mimeTypes = audioPreview->supportedMimeTypes();
82 TQStringList::ConstIterator it = mimeTypes.begin();
83 for ( ; it != mimeTypes.end(); ++it )
84 m_previewProviders.insert( *it, audioPreview );
90 provider = m_previewProviders.find( mimeType );
95 int index = mimeType.find(
'/' );
98 provider = m_previewProviders.find( mimeType.left( index + 1 ) +
"*" );
103 KMimeType::Ptr mimeInfo = KMimeType::mimeType( mimeType );
107 TQString parentMimeType = mimeInfo->parentMimeType();
108 while ( !parentMimeType.isEmpty() )
110 provider = m_previewProviders.find( parentMimeType );
114 KMimeType::Ptr parentMimeInfo = KMimeType::mimeType( parentMimeType );
115 if ( !parentMimeInfo )
break;
117 parentMimeType = parentMimeInfo->parentMimeType();
121 TQVariant textProperty = mimeInfo->property(
"X-TDE-text" );
122 if ( textProperty.isValid() && textProperty.type() == TQVariant::Bool )
124 if ( textProperty.toBool() )
126 provider = m_previewProviders.find(
"text/plain" );
130 provider = m_previewProviders.find(
"text/*" );
140 void KFileMetaPreview::showPreview(
const KURL &url)
142 KMimeType::Ptr mt = KMimeType::findByURL( url );
146 if ( provider != m_stack->visibleWidget() )
149 m_stack->setEnabled(
true );
150 m_stack->raiseWidget( provider );
156 m_stack->setEnabled(
false );
160 void KFileMetaPreview::clearPreview()
162 if ( m_stack->visibleWidget() )
166 void KFileMetaPreview::addPreviewProvider(
const TQString& mimeType,
169 m_previewProviders.insert( mimeType, provider );
172 void KFileMetaPreview::clearPreviewProviders()
174 TQDictIterator<KPreviewWidgetBase> it( m_previewProviders );
175 for ( ; it.current(); ++it )
176 m_stack->removeWidget( it.current() );
178 m_previewProviders.clear();
184 KLibFactory *factory = KLibLoader::self()->factory(
"tdefileaudiopreview" );
187 s_tryAudioPreview =
false;
191 return dynamic_cast<KPreviewWidgetBase*
>( factory->create( parent,
"tdefileaudiopreview" ));
194 void KFileMetaPreview::virtual_hook(
int,
void* ) {}
196 #include "tdefilemetapreview.moc"
Image preview widget for the file dialog.