// (C) 2005 Max Howell (max.howell@methylblue.com) // See COPYING file for licensing information #include "config.h" #include "listView.cpp" #include #include #include #include #include #include #include "playDialog.h" #include "mxcl.library.h" #include #include #include #include TQString i18n( const char *text ); namespace Codeine { PlayDialog::PlayDialog( TQWidget *parent, bool be_welcome_dialog ) : TQDialog( parent ) { setCaption( kapp->makeStdCaption( i18n("Play Media") ) ); TQSignalMapper *mapper = new TQSignalMapper( this ); TQWidget *o, *closeButton = new KPushButton( KStdGuiItem::close(), this ); TQBoxLayout *hbox, *vbox = new TQVBoxLayout( this, 15, 20 ); vbox->addWidget( new TQLabel( i18n( "What media would you like to play?" ), this ) ); TQGridLayout *grid = new TQGridLayout( vbox, 1, 3, 20 ); //TODO use the kguiItems from the actions mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play File..."), "fileopen" ), this ), FILE ); connect( o, SIGNAL(clicked()), mapper, SLOT(map()) ); grid->TQLayout::add( o ); mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play VCD"), "cdaudio_unmount" ), this ), VCD ); connect( o, SIGNAL(clicked()), mapper, SLOT(map()) ); grid->TQLayout::add( o ); mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play DVD"), "dvd_unmount" ), this ), DVD ); connect( o, SIGNAL(clicked()), mapper, SLOT(map()) ); grid->TQLayout::add( o ); mapper->setMapping( closeButton, TQDialog::Rejected ); connect( closeButton, SIGNAL(clicked()), mapper, SLOT(map()) ); createRecentFileWidget( vbox ); hbox = new TQHBoxLayout( vbox ); hbox->addItem( new TQSpacerItem( 10, 10, TQSizePolicy::Expanding ) ); if( be_welcome_dialog ) { TQWidget *w = new KPushButton( KStdGuiItem::quit(), this ); hbox->addWidget( w ); connect( w, SIGNAL(clicked()), kapp, SLOT(quit()) ); } hbox->addWidget( closeButton ); connect( mapper, SIGNAL(mapped( int )), SLOT(done( int )) ); } void PlayDialog::createRecentFileWidget( TQBoxLayout *layout ) { TDEListView *lv; lv = new Codeine::ListView( this ); lv->setColumnText( 1, i18n("Recently Played Media") ); const TQStringList list1 = Codeine::config( "General" )->readPathListEntry( "Recent Urls" ); KURL::List urls; foreach( list1 ) urls += *it; for( KURL::List::Iterator it = urls.begin(), end = urls.end(); it != end; ) { if( urls.contains( *it ) > 1 ) //remove duplicates it = urls.remove( it ); else if( (*it).protocol() == "file" && !TQFile::exists( (*it).path() ) ) //remove stale entries it = urls.remove( it ); else ++it; } for( KURL::List::ConstIterator it = urls.begin(), end = urls.end(); it != end; ++it ) { const TQString fileName = (*it).fileName(); new TDEListViewItem( lv, 0, (*it).url(), fileName.isEmpty() ? (*it).prettyURL() : fileName ); } if( lv->childCount() ) { layout->addWidget( lv, 1 ); connect( lv, SIGNAL(executed( TQListViewItem* )), SLOT(done( TQListViewItem* )) ); } else delete lv; } void PlayDialog::done( TQListViewItem *item ) { m_url = item->text( 0 ); TQDialog::done( RECENT_FILE ); } }