-rw-r--r-- | core/multimedia/opieplayer/playlistselection.cpp | 11 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 22 |
2 files changed, 21 insertions, 12 deletions
diff --git a/core/multimedia/opieplayer/playlistselection.cpp b/core/multimedia/opieplayer/playlistselection.cpp index 85228a9..67187f8 100644 --- a/core/multimedia/opieplayer/playlistselection.cpp +++ b/core/multimedia/opieplayer/playlistselection.cpp @@ -1,215 +1,216 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include <qpe/applnk.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpainter.h> #include <qimage.h> #include <qheader.h> #include <qlistview.h> #include <qlist.h> #include <qpixmap.h> #include "playlistselection.h" #include <stdlib.h> class PlayListSelectionItem : public QListViewItem { public: PlayListSelectionItem( QListView *parent, const DocLnk *f ) : QListViewItem( parent ), fl( f ) { setText( 0, f->name() ); setPixmap( 0, f->pixmap() ); } ~PlayListSelectionItem() { }; const DocLnk *file() const { return fl; } private: const DocLnk *fl; }; PlayListSelection::PlayListSelection( QWidget *parent, const char *name ) : QListView( parent, name ) { // qDebug("starting playlistselector"); // #ifdef USE_PLAYLIST_BACKGROUND // setStaticBackground( TRUE ); // setBackgroundPixmap( Resource::loadPixmap( "opieplayer/background" ) ); // setBackgroundPixmap( Resource::loadPixmap( "launcher/opielogo" ) ); // #endif // addColumn("Title",236); // setAllColumnsShowFocus( TRUE ); addColumn( tr( "Playlist Selection" ) ); header()->hide(); - setSorting( -1, FALSE ); +// setSorting( -1, FALSE ); + // FIXME } PlayListSelection::~PlayListSelection() { } // #ifdef USE_PLAYLIST_BACKGROUND void PlayListSelection::drawBackground( QPainter *p, const QRect &r ) { // qDebug("drawBackground"); p->fillRect( r, QBrush( white ) ); // QImage logo = Resource::loadImage( "launcher/opielogo" ); // if ( !logo.isNull() ) // p->drawImage( (width() - logo.width()) / 2, (height() - logo.height()) / 2, logo ); } // #endif void PlayListSelection::contentsMouseMoveEvent( QMouseEvent *event ) { if ( event->state() == QMouseEvent::LeftButton ) { QListViewItem *currentItem = selectedItem(); QListViewItem *itemUnder = itemAt( QPoint( event->pos().x(), event->pos().y() - contentsY() ) ); if ( currentItem && currentItem->itemAbove() == itemUnder ) moveSelectedUp(); else if ( currentItem && currentItem->itemBelow() == itemUnder ) moveSelectedDown(); } } const DocLnk *PlayListSelection::current() { PlayListSelectionItem *item = (PlayListSelectionItem *)selectedItem(); if ( item ) return item->file(); return NULL; } void PlayListSelection::addToSelection( const DocLnk &lnk ) { PlayListSelectionItem *item = new PlayListSelectionItem( this, new DocLnk( lnk ) ); - QListViewItem *current = selectedItem(); - if ( current ) - item->moveItem( current ); + QListViewItem *current = selectedItem(); + if ( current ) + item->moveItem( current ); setSelected( item, TRUE ); - ensureItemVisible( selectedItem() ); + ensureItemVisible( item); } void PlayListSelection::removeSelected() { QListViewItem *item = selectedItem(); if ( item ) delete item; setSelected( currentItem(), TRUE ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedUp() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) item->itemAbove()->moveItem( item ); ensureItemVisible( selectedItem() ); } void PlayListSelection::moveSelectedDown() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) item->moveItem( item->itemBelow() ); ensureItemVisible( selectedItem() ); } bool PlayListSelection::prev() { QListViewItem *item = selectedItem(); if ( item && item->itemAbove() ) setSelected( item->itemAbove(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::next() { QListViewItem *item = selectedItem(); if ( item && item->itemBelow() ) setSelected( item->itemBelow(), TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::first() { QListViewItem *item = firstChild(); if ( item ) setSelected( item, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } bool PlayListSelection::last() { QListViewItem *prevItem = NULL; QListViewItem *item = firstChild(); while ( ( item = item->nextSibling() ) ) prevItem = item; if ( prevItem ) setSelected( prevItem, TRUE ); else return FALSE; ensureItemVisible( selectedItem() ); return TRUE; } void PlayListSelection::unSelect() { QListViewItem *item = selectedItem(); setSelected( currentItem(), FALSE); } void PlayListSelection::writeCurrent( Config& cfg ) { cfg.setGroup("PlayList"); QListViewItem *item = selectedItem(); if ( item ) cfg.writeEntry("current", item->text(0) ); qDebug(item->text(0)); } void PlayListSelection::setSelectedItem(const QString &strk ) { unSelect(); QListViewItemIterator it( this ); for ( ; it.current(); ++it ) { // qDebug( it.current()->text(0)); if( strk == it.current()->text(0)) { // qDebug( "We have a match "+strk); setSelected( it.current(), TRUE); ensureItemVisible( it.current() ); return; } } // setSelected( item, TRUE ); // ensureItemVisible( selectedItem() ); } diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 395037f..19c8056 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -70,438 +70,445 @@ #include <sys/soundcard.h> // for setBacklight() #include <linux/fb.h> #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #define BUTTONS_ON_TOOLBAR #define SIDE_BUTTONS #define CAN_SAVE_LOAD_PLAYLISTS extern AudioWidget *audioUI; extern VideoWidget *videoUI; extern MediaPlayerState *mediaPlayerState; static inline QString fullBaseName ( const QFileInfo &fi ) { QString str = fi. fileName ( ); return str. left ( str. findRev ( '.' )); } QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod"; // class myFileSelector { // }; class PlayListWidgetPrivate { public: QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; QFrame *playListFrame; FileSelector *files; PlayListSelection *selectedFiles; bool setDocumentUsed; DocLnk *current; }; class ToolButton : public QToolButton { public: ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) : QToolButton( parent, name ) { setTextLabel( name ); setPixmap( Resource::loadPixmap( icon ) ); setAutoRaise( TRUE ); setFocusPolicy( QWidget::NoFocus ); setToggleButton( t ); connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); QPEMenuToolFocusManager::manager()->addWidget( this ); } }; class MenuItem : public QAction { public: MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) : QAction( text, QString::null, 0, 0 ) { connect( this, SIGNAL( activated() ), handler, slot ); addTo( parent ); } }; PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { d = new PlayListWidgetPrivate; d->setDocumentUsed = FALSE; d->current = NULL; fromSetDocument = FALSE; insanityBool=FALSE; audioScan = FALSE; videoScan = FALSE; // menuTimer = new QTimer( this ,"menu timer"), // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); setBackgroundMode( PaletteButton ); setCaption( tr("OpiePlayer") ); setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); setToolBarsMovable( FALSE ); // Create Toolbar QPEToolBar *toolbar = new QPEToolBar( this ); toolbar->setHorizontalStretchable( TRUE ); // Create Menubar QPEMenuBar *menu = new QPEMenuBar( toolbar ); menu->setMargin( 0 ); QPEToolBar *bar = new QPEToolBar( this ); bar->setLabel( tr( "Play Operations" ) ); // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", // this , SLOT( addSelected()) ); tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); tbDeletePlaylist->setFlat(TRUE); tbDeletePlaylist->setFixedSize(20,20); d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", this , SLOT(addSelected()) ); d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", this , SLOT(removeSelected()) ); // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", this , SLOT( btnPlay(bool) ), TRUE ); d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", mediaPlayerState, SLOT(setLooping(bool)), TRUE ); tbDeletePlaylist->hide(); QPopupMenu *pmPlayList = new QPopupMenu( this ); menu->insertItem( tr( "File" ), pmPlayList ); new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); pmPlayList->insertSeparator(-1); new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); QPopupMenu *pmView = new QPopupMenu( this ); menu->insertItem( tr( "View" ), pmView ); fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); fullScreenButton->addTo(pmView); scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); scaleButton->addTo(pmView); skinsMenu = new QPopupMenu( this ); menu->insertItem( tr( "Skins" ), skinsMenu ); skinsMenu->isCheckable(); connect( skinsMenu, SIGNAL( activated( int ) ) , this, SLOT( skinsMenuActivated( int ) ) ); populateSkinsMenu(); QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); tabWidget = new QTabWidget( hbox6, "tabWidget" ); tabWidget->setTabShape(QTabWidget::Triangular); QWidget *pTab; pTab = new QWidget( tabWidget, "pTab" ); // playlistView = new QListView( pTab, "playlistview" ); // playlistView->setMinimumSize(236,260); tabWidget->insertTab( pTab,"Playlist"); // Add the playlist area QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); d->playListFrame = vbox3; d->playListFrame ->setMinimumSize(235,260); QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); d->selectedFiles = new PlayListSelection( hbox2); QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch QWidget *aTab; aTab = new QWidget( tabWidget, "aTab" ); audioView = new QListView( aTab, "Audioview" ); audioView->setMinimumSize(233,260); audioView->addColumn( tr("Title"),140); audioView->addColumn(tr("Size"), -1); audioView->addColumn(tr("Media"),-1); audioView->addColumn( tr( "Path" ), 0 ); audioView->setColumnAlignment(1, Qt::AlignRight); audioView->setColumnAlignment(2, Qt::AlignRight); audioView->setAllColumnsShowFocus(TRUE); audioView->setMultiSelection( TRUE ); audioView->setSelectionMode( QListView::Extended); + audioView->setSorting( 3, TRUE ); tabWidget->insertTab(aTab,tr("Audio")); QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); // audioView // populateAudioView(); // videowidget QWidget *vTab; vTab = new QWidget( tabWidget, "vTab" ); videoView = new QListView( vTab, "Videoview" ); videoView->setMinimumSize(233,260); videoView->addColumn(tr("Title"),140); videoView->addColumn(tr("Size"),-1); videoView->addColumn(tr("Media"),-1); videoView->addColumn(tr( "Path" ), 0 ); videoView->setColumnAlignment(1, Qt::AlignRight); videoView->setColumnAlignment(2, Qt::AlignRight); videoView->setAllColumnsShowFocus(TRUE); videoView->setMultiSelection( TRUE ); videoView->setSelectionMode( QListView::Extended); QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); tabWidget->insertTab( vTab,tr("Video")); QWidget *LTab; LTab = new QWidget( tabWidget, "LTab" ); playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy playLists->setMinimumSize(233,260); tabWidget->insertTab(LTab,tr("Lists")); connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); + +///audioView connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); connect( audioView, SIGNAL( returnPressed( QListViewItem *)), this,SLOT( playIt( QListViewItem *)) ); connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); + +//videoView connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); connect( videoView, SIGNAL( returnPressed( QListViewItem *)), this,SLOT( playIt( QListViewItem *)) ); connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); + +//playlists connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); // connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); setCentralWidget( vbox5 ); Config cfg( "OpiePlayer" ); readConfig( cfg ); QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); loadList(DocLnk( currentPlaylist)); setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlaylist))); initializeStates(); } PlayListWidget::~PlayListWidget() { Config cfg( "OpiePlayer" ); writeConfig( cfg ); if ( d->current ) delete d->current; delete d; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState->playing() ); d->tbLoop->setOn( mediaPlayerState->looping() ); d->tbShuffle->setOn( mediaPlayerState->shuffled() ); setPlaylist( true); } void PlayListWidget::readConfig( Config& cfg ) { cfg.setGroup("PlayList"); QString currentString = cfg.readEntry("current", "" ); int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); for ( int i = 0; i < noOfFiles; i++ ) { QString entryName; entryName.sprintf( "File%i", i + 1 ); QString linkFile = cfg.readEntry( entryName ); DocLnk lnk( linkFile ); if ( lnk.isValid() ) { d->selectedFiles->addToSelection( lnk ); } } d->selectedFiles->setSelectedItem( currentString); } void PlayListWidget::writeConfig( Config& cfg ) const { d->selectedFiles->writeCurrent( cfg); cfg.setGroup("PlayList"); int noOfFiles = 0; d->selectedFiles->first(); do { const DocLnk *lnk = d->selectedFiles->current(); if ( lnk ) { QString entryName; entryName.sprintf( "File%i", noOfFiles + 1 ); // qDebug(entryName); cfg.writeEntry( entryName, lnk->linkFile() ); // if this link does exist, add it so we have the file // next time... if ( !QFile::exists( lnk->linkFile() ) ) { // the way writing lnks doesn't really check for out // of disk space, but check it anyway. if ( !lnk->writeLink() ) { QMessageBox::critical( 0, tr("Out of space"), tr( "There was a problem saving " "the playlist.\n" "Your playlist " "may be missing some entries\n" "the next time you start it." ) ); } } noOfFiles++; } } while ( d->selectedFiles->next() ); cfg.writeEntry("NumberOfFiles", noOfFiles ); } void PlayListWidget::addToSelection( const DocLnk& lnk ) { d->setDocumentUsed = false; if ( mediaPlayerState->playlist() ) { if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) d->selectedFiles->addToSelection( lnk ); } else mediaPlayerState->setPlaying( true); } void PlayListWidget::clearList() { while ( first() ) d->selectedFiles->removeSelected(); } void PlayListWidget::addAllToList() { DocLnkSet filesAll; Global::findDocuments(&filesAll, "video/*;audio/*"); QListIterator<DocLnk> Adit( filesAll.children() ); for ( ; Adit.current(); ++Adit ) if(QFileInfo(Adit.current()->file()).exists()) d->selectedFiles->addToSelection( **Adit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllMusicToList() { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) if(QFileInfo(dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::addAllVideoToList() { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); } void PlayListWidget::setDocument(const QString& fileref) { qDebug(fileref); fromSetDocument = TRUE; QFileInfo fileInfo(fileref); if ( !fileInfo.exists() ) { QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); return; } // qDebug("setDocument "+fileref); QString extension = fileInfo.extension(false); if( extension.find( "m3u", 0, false) != -1) { //is m3u readm3u( fileref); } else if( extension.find( "pls", 0, false) != -1 ) { //is pls readPls( fileref); } else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist clearList(); DocLnk lnk; lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( fileref ); //sets file name //addToSelection( lnk ); loadList( lnk); d->selectedFiles->first(); } else { clearList(); DocLnk lnk; lnk.setName( fileInfo.baseName() ); //sets name lnk.setFile( fileref ); //sets file name addToSelection( lnk ); // addToSelection( DocLnk( fileref ) ); d->setDocumentUsed = TRUE; mediaPlayerState->setPlaying( FALSE ); qApp->processEvents(); mediaPlayerState->setPlaying( TRUE ); qApp->processEvents(); setCaption(tr("OpiePlayer")); } } @@ -618,402 +625,403 @@ bool PlayListWidget::next() { } else { if ( !d->selectedFiles->next() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->first(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::first() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->first(); else return mediaPlayerState->looping(); } bool PlayListWidget::last() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->last(); else return mediaPlayerState->looping(); } void PlayListWidget::saveList() { writem3u(); } void PlayListWidget::loadList( const DocLnk & lnk) { QString name = lnk.name(); // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); if( name.length()>0) { setCaption("OpiePlayer: "+name); // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); clearList(); readm3u(lnk.file()); tabWidget->setCurrentPage(0); } } void PlayListWidget::setPlaylist( bool shown ) { if ( shown ) d->playListFrame->show(); else d->playListFrame->hide(); } void PlayListWidget::setView( char view ) { if ( view == 'l' ) showMaximized(); else hide(); } void PlayListWidget::addSelected() { qDebug("addSelected"); DocLnk lnk; QString filename; switch (tabWidget->currentPageIndex()) { case 0: //playlist return; break; case 1: { //audio filename=audioView->currentItem()->text(3); // d->selectedFiles->next(); } break; case 2: { // video filename=videoView->currentItem()->text(3); // tabWidget->setCurrentPage(0); } break; }; lnk.setName( fullBaseName ( QFileInfo(filename))); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); tabWidget->setCurrentPage(0); writeCurrentM3u(); } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); } void PlayListWidget::playIt( QListViewItem *) { // d->setDocumentUsed = FALSE; // mediaPlayerState->curPosition =0; qDebug("playIt"); mediaPlayerState->setPlaying(FALSE); mediaPlayerState->setPlaying(TRUE); d->selectedFiles->unSelect(); } void PlayListWidget::addToSelection( QListViewItem *it) { d->setDocumentUsed = FALSE; if(it) { switch ( tabWidget->currentPageIndex()) { case 0: //playlist return; break; }; // case 1: { DocLnk lnk; QString filename; filename=it->text(3); lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); writeCurrentM3u(); tabWidget->setCurrentPage(0); } } void PlayListWidget::tabChanged(QWidget *) { switch ( tabWidget->currentPageIndex()) { case 0: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); } break; case 1: { audioView->clear(); populateAudioView(); if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 2: { videoView->clear(); populateVideoView(); if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 3: { if( tbDeletePlaylist->isHidden()) tbDeletePlaylist->show(); playLists->reread(); } break; }; } void PlayListWidget::btnPlay(bool b) { qDebug("<<<<<<<<<<<<<<<BtnPlay"); // mediaPlayerState->setPlaying(b); switch ( tabWidget->currentPageIndex()) { case 0: { qDebug("1"); // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { // QMessageBox::message("Note","You are trying to play\na malformed url."); // } else { mediaPlayerState->setPlaying(b); insanityBool=FALSE; qDebug("insanity"); // } } break; case 1: { qDebug("2"); +// d->selectedFiles->unSelect(); addToSelection( audioView->currentItem() ); - mediaPlayerState->setPlaying(b); - d->selectedFiles->removeSelected( ); - tabWidget->setCurrentPage(1); - d->selectedFiles->unSelect(); + mediaPlayerState->setPlaying(true); + d->selectedFiles->removeSelected( ); + d->selectedFiles->unSelect(); + tabWidget->setCurrentPage(1); insanityBool=FALSE; }// audioView->clearSelection(); break; case 2: { qDebug("3"); addToSelection( videoView->currentItem() ); - mediaPlayerState->setPlaying(b); - qApp->processEvents(); + mediaPlayerState->setPlaying(true); +// qApp->processEvents(); d->selectedFiles->removeSelected( ); - tabWidget->setCurrentPage(2); d->selectedFiles->unSelect(); + tabWidget->setCurrentPage(2); insanityBool=FALSE; }// videoView->clearSelection(); break; }; } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), (tr("Yes")), (tr("No")), 0 )){ case 0: // Yes clicked, QFile().remove(playLists->selectedDocument().file()); QFile().remove(playLists->selectedDocument().linkFile()); playLists->reread(); break; case 1: // Cancel break; }; } void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) { switch (mouse) { case 1: break; case 2:{ QPopupMenu m; m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); m.insertSeparator(); if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); m.exec( QCursor::pos() ); } break; }; } void PlayListWidget::playSelected() { qDebug("playSelected"); btnPlay( true); // d->selectedFiles->unSelect(); } void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) { switch (mouse) { case 1: break; case 2:{ QPopupMenu m; m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); // m.insertSeparator(); // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); m.exec( QCursor::pos() ); } break; }; } void PlayListWidget::listDelete() { Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); QString file; // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); switch ( tabWidget->currentPageIndex()) { case 0: break; case 1: { file = audioView->currentItem()->text(0); QListIterator<DocLnk> Pdit( files.children() ); for ( ; Pdit.current(); ++Pdit ) { if( Pdit.current()->name() == file) { LnkProperties prop( Pdit.current() ); prop.showMaximized(); prop.exec(); } } populateAudioView(); } break; case 2: { // file = videoView->selectedItem()->text(0); // for ( int i = 0; i < noOfFiles; i++ ) { // QString entryName; // entryName.sprintf( "File%i", i + 1 ); // QString linkFile = cfg.readEntry( entryName ); // AppLnk lnk( AppLnk(linkFile)); // if( lnk.name() == file ) { // LnkProperties prop( &lnk); // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); // prop.showMaximized(); // prop.exec(); // } // } } break; }; } void PlayListWidget::scanForAudio() { // qDebug("scan for audio"); files.detachChildren(); QListIterator<DocLnk> sdit( files.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments( &files, audioMimes); audioScan = true; } void PlayListWidget::scanForVideo() { // qDebug("scan for video"); vFiles.detachChildren(); QListIterator<DocLnk> sdit( vFiles.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments(&vFiles, "video/*"); videoScan = true; } void PlayListWidget::populateAudioView() { audioView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!audioScan) scanForAudio(); QListIterator<DocLnk> dit( files.children() ); QListIterator<FileSystem> it ( fs ); QString storage; for ( ; dit.current(); ++dit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if(dit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { long size; if( dit.current()->file().left(4) == "http" ) size=0; else size = QFile( dit.current()->file() ).size(); // qDebug(dit.current()->name()); newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number(size ), storage, dit.current()->file()); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); } } } void PlayListWidget::populateVideoView() { videoView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!videoScan ) scanForVideo(); QListIterator<DocLnk> Vdit( vFiles.children() ); QListIterator<FileSystem> it ( fs ); videoView->clear(); QString storage; for ( ; Vdit.current(); ++Vdit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if( Vdit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; if ( QFile( Vdit.current()->file()).exists() ) { newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file() ).size() ), storage, Vdit.current()->file()); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); } } } |