Diffstat (limited to 'noncore/multimedia/opieplayer2') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.cpp | 13 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistfileview.h | 1 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 56 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.h | 1 |
4 files changed, 59 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistfileview.cpp b/noncore/multimedia/opieplayer2/playlistfileview.cpp index 3ef4d03..3094876 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.cpp +++ b/noncore/multimedia/opieplayer2/playlistfileview.cpp @@ -68,28 +68,39 @@ void PlayListFileView::populateView() m_viewPopulated = true; QString storage; QListIterator<DocLnk> dit( m_files.children() ); for ( ; dit.current(); ++dit ) { QListViewItem *newItem; if ( QFile::exists( dit.current()->file() ) || dit.current()->file().left( 4 ) == "http" ) { unsigned long size = QFile( dit.current()->file() ).size(); + QString sizestr; + fileSize(size, sizestr); newItem = new QListViewItem( this, dit.current()->name(), - QString::number( size ), "" /*storage*/, + sizestr, "" /*storage*/, dit.current()->file() ); newItem->setPixmap( 0, Resource::loadPixmap( m_itemPixmapName ) ); } } } void PlayListFileView::checkSelection() { emit itemsSelected( hasSelection() ); } +void PlayListFileView::fileSize(unsigned long size, QString &str) { + if( size > 1048576 ) + str.sprintf( "%.0fM", size / 1048576.0 ); + else if( size > 1024 ) + str.sprintf( "%.0fK", size / 1024.0 ); + else + str.sprintf( "%d", size ); +} + /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistfileview.h b/noncore/multimedia/opieplayer2/playlistfileview.h index 5b15526..d92f258 100644 --- a/noncore/multimedia/opieplayer2/playlistfileview.h +++ b/noncore/multimedia/opieplayer2/playlistfileview.h @@ -16,22 +16,23 @@ public: public slots: void scanFiles(); void populateView(); signals: void itemsSelected( bool selected ); private slots: void checkSelection(); private: + void fileSize(unsigned long size, QString &str); QString m_mimeTypePattern; QString m_itemPixmapName; DocLnkSet m_files; bool m_scannedFiles; bool m_viewPopulated; }; #endif // PLAYLISTFILEVIEW_H /* vim: et sw=4 ts=4 */ diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 5f4159c..83eb83b 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -171,24 +171,56 @@ PlayListWidget::~PlayListWidget() { delete d; delete m_mp; } void PlayListWidget::initializeStates() { d->tbPlay->setOn( mediaPlayerState->isPlaying() ); d->tbLoop->setOn( mediaPlayerState->isLooping() ); d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); d->playListFrame->show(); } +void PlayListWidget::setButtons(void) { + bool hasitem; + + switch ( currentTab() ) { + case CurrentPlayList: + { + hasitem = !d->selectedFiles->isEmpty(); + d->tbPlay->setEnabled( hasitem ); + d->tbRemoveFromList->setEnabled( hasitem ); + } + break; + case AudioFiles: + { + d->tbPlay->setEnabled( audioView->hasSelection() ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + case VideoFiles: + { + d->tbPlay->setEnabled( videoView->hasSelection() ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + case PlayLists: + { + d->tbPlay->setEnabled( false ); + d->tbRemoveFromList->setEnabled( false ); + } + break; + }; +} + void PlayListWidget::writeDefaultPlaylist() { Config config( "OpiePlayer" ); config.setGroup( "PlayList" ); QString filename=QPEApplication::documentDir() + "/default.m3u"; QString currentString = config.readEntry( "CurrentPlaylist", filename); if( currentString == filename) { Om3u *m3uList; if( d->selectedFiles->first() ) { m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); do { m3uList->add( d->selectedFiles->current()->file() ); @@ -211,24 +243,25 @@ void PlayListWidget::addToSelection( const DocLnk& lnk ) { } } void PlayListWidget::clearList() { while ( first() ) { d->selectedFiles->removeSelected(); } Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); cfg.writeEntry("CurrentPlaylist","default"); setCaption("OpiePlayer"); + setButtons(); } void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { switch (mouse) { case LeftButton: break; case RightButton: { QPopupMenu m; m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); m.exec( QCursor::pos() ); @@ -275,64 +308,70 @@ void PlayListWidget::addAllToList() { QListViewItemIterator videoIt( videoView ); for ( ; videoIt.current(); ++videoIt ) { filename = videoIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::addAllMusicToList() { audioView->populateView(); QListViewItemIterator audioIt( audioView ); DocLnk lnk; QString filename; // iterate through all items of the listview for ( ; audioIt.current(); ++audioIt ) { filename = audioIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::addAllVideoToList() { videoView->populateView(); QListViewItemIterator videoIt( videoView ); DocLnk lnk; QString filename; for ( ; videoIt.current(); ++videoIt ) { filename = videoIt.current()->text(3); lnk.setName( QFileInfo(filename).baseName() ); //sets name lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); } tabWidget->setCurrentPage(0); writeCurrentM3u(); d->selectedFiles->first(); + + setButtons(); } void PlayListWidget::setDocument( const QString& _fileref ) { // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl; QString fileref = _fileref; fromSetDocument = TRUE; DocLnk lnk(_fileref); if(lnk.isValid()) fileref = lnk.file(); @@ -467,24 +506,25 @@ void PlayListWidget::addSelected() { d->selectedFiles->addToSelection( lnk ); } currentFileListView->clearSelection(); writeCurrentM3u(); } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); writeCurrentM3u(); + setButtons(); } void PlayListWidget::playIt( QListViewItem *it) { if(!it) return; mediaPlayerState->setPlaying(FALSE); mediaPlayerState->setPlaying(TRUE); d->selectedFiles->unSelect(); } void PlayListWidget::addToSelection( QListViewItem *it) { @@ -501,92 +541,83 @@ void PlayListWidget::addToSelection( QListViewItem *it) { lnk.setFile( filename ); //sets file name d->selectedFiles->addToSelection( lnk); writeCurrentM3u(); // tabWidget->setCurrentPage(0); } } void PlayListWidget::tabChanged(QWidget *) { - d->tbPlay->setEnabled( true ); - disconnect( audioView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); disconnect( videoView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); currentFileListView = 0; switch ( currentTab() ) { case CurrentPlayList: { if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); - d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); } break; case AudioFiles: { audioView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); connect( audioView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); - d->tbPlay->setEnabled( audioView->hasSelection() ); - currentFileListView = audioView; } break; case VideoFiles: { videoView->populateView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } - d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); connect( videoView, SIGNAL( itemsSelected(bool) ), d->tbPlay, SLOT( setEnabled(bool) ) ); - d->tbPlay->setEnabled( videoView->hasSelection() ); - currentFileListView = videoView; } break; case PlayLists: { if( tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->show(); } playLists->reread(); d->tbAddToList->setEnabled(FALSE); - d->tbPlay->setEnabled( false ); } break; }; + + setButtons(); } void PlayListWidget::btnPlay(bool b) { // mediaPlayerState->setPlaying(false); mediaPlayerState->setPlaying(b); insanityBool=FALSE; } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), @@ -701,24 +732,26 @@ void PlayListWidget::openFile() { return; if(str.left(2) == "//") str=str.right(str.length()-1); if( str.right( 3) == "m3u" || str.right(3) == "pls" ) { readListFromFile( str ); } else { QFileInfo info( str ); DocLnk lnk = addFileToPlaylist( str, info.baseName() ); d->selectedFiles->setSelectedItem( lnk.name() ); } + + setButtons(); } void PlayListWidget::openDirectory() { QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector, QString::null, 0, tr( "Add Files from Directory")); if(str.isEmpty() ) return; if(str.left(2) == "//") str=str.right(str.length()-1); QDir dir( str ); @@ -770,24 +803,25 @@ void PlayListWidget::readListFromFile( const QString &filename ) { config.setGroup( "PlayList" ); config.writeEntry("CurrentPlaylist",filename); config.write(); currentPlayList=filename; m3uList->close(); delete m3uList; d->selectedFiles->setSelectedItem( s); setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); + setButtons(); } // writes current playlist to current m3u file */ void PlayListWidget::writeCurrentM3u() { odebug << "writing to current m3u" << oendl; Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); Om3u *m3uList; m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); if( d->selectedFiles->first()) { diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h index 1f5ba92..7db0029 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.h +++ b/noncore/multimedia/opieplayer2/playlistwidget.h @@ -123,23 +123,24 @@ private slots: void playIt( QListViewItem *); void btnPlay(bool); void deletePlaylist(); void addSelected(); void removeSelected(); void tabChanged(QWidget*); void viewPressed( int, QListViewItem *, const QPoint&, int); void playlistViewPressed( int, QListViewItem *, const QPoint&, int); void playSelected(); private: DocLnk addFileToPlaylist(const QString& directory, const QString& name); + void setButtons(void); bool fromSetDocument; bool insanityBool; QString setDocFileRef, currentPlayList; int selected; QListView *currentFileListView; MediaPlayer *m_mp; }; #endif // PLAY_LIST_WIDGET_H |