1 #include "tdefileaudiopreview.h"
3 #include <tqcheckbox.h>
6 #include <tqvgroupbox.h>
10 #include <klibloader.h>
12 #include <tdemediaplayer/player.h>
13 #include <kmimetype.h>
14 #include <tdeparts/componentfactory.h>
16 #include <kplayobjectfactory.h>
18 #include <config-tdefile.h>
23 virtual TQObject *
createObject( TQObject *parent,
const char *name,
24 const char *className,
const TQStringList & args)
32 K_EXPORT_COMPONENT_FACTORY( tdefileaudiopreview, KFileAudioPreviewFactory )
39 class KFileAudioPreview::KFileAudioPreviewPrivate
42 KFileAudioPreviewPrivate( TQWidget *parent )
44 player = KParts::ComponentFactory::createInstanceFromQuery<KMediaPlayer::Player>(
"KMediaPlayer/Player", TQString(), parent );
47 ~KFileAudioPreviewPrivate()
56 KFileAudioPreview::KFileAudioPreview( TQWidget *parent,
const char *name )
57 : KPreviewWidgetBase( parent,
name )
61 TQStringList formats = KDE::PlayObjectFactory::mimeTypes();
63 TQStringList::ConstIterator it = formats.begin();
64 for ( ; it != formats.end(); ++it )
65 m_supportedFormats.insert( *it, (
void*) 1 );
67 TQVGroupBox *box =
new TQVGroupBox( i18n(
"Media Player"),
this );
68 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
69 layout->addWidget( box );
71 (void)
new TQWidget( box );
73 d =
new KFileAudioPreviewPrivate( 0L );
76 setSupportedMimeTypes( formats );
78 view->setEnabled(
false );
84 TQHBox *frame =
new TQHBox( box );
85 frame->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
86 frame->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
87 view->
videoWidget()->reparent( frame, TQPoint(0,0) );
90 view->reparent( box, TQPoint(0,0) );
93 m_autoPlay =
new TQCheckBox( i18n(
"Play &automatically"), box );
95 m_autoPlay->setChecked( config.readBoolEntry(
"Autoplay sounds",
true ) );
96 connect( m_autoPlay, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(toggleAuto(
bool)) );
99 KFileAudioPreview::~KFileAudioPreview()
102 config.writeEntry(
"Autoplay sounds", m_autoPlay->isChecked() );
107 void KFileAudioPreview::showPreview(
const KURL &url )
109 if ( !d->player || !url.
isValid() )
112 KMimeType::Ptr mt = KMimeType::findByURL( url );
113 bool supported = m_supportedFormats.find( mt->name() );
114 d->player->view()->setEnabled( supported );
119 if ( m_autoPlay->isChecked() )
123 void KFileAudioPreview::clearPreview()
128 d->player->closeURL();
132 void KFileAudioPreview::toggleAuto(
bool on )
137 if ( on && m_currentURL.
isValid() && d->player->view()->isEnabled() )
143 void KFileAudioPreview::virtual_hook(
int,
void* )
146 #include "tdefileaudiopreview.moc"
Audio "preview" widget for the file dialog.
virtual TQObject * createObject(TQObject *parent=0, const char *name=0, const char *className="TQObject", const TQStringList &args=TQStringList())=0
static TDEConfig * config()
static TDELocale * locale()
void insertCatalogue(const TQString &catalog)
TQString name(StdAccel id)