summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistfileview.cpp13
-rw-r--r--noncore/multimedia/opieplayer2/playlistfileview.h1
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp56
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h1
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
@@ -32,64 +32,75 @@ bool PlayListFileView::hasSelection() const
{
for ( QListViewItemIterator it( const_cast<PlayListFileView *>( this ) ); it.current(); ++it )
if ( it.current()->isSelected() )
return true;
return false;
}
void PlayListFileView::scanFiles()
{
m_files.detachChildren();
QListIterator<DocLnk> sdit( m_files.children() );
for ( ; sdit.current(); ++sdit )
delete sdit.current();
Global::findDocuments( &m_files, m_mimeTypePattern );
if ( m_viewPopulated ) {
m_viewPopulated = false;
populateView();
}
}
void PlayListFileView::populateView()
{
if ( m_viewPopulated )
return;
clear();
if( !m_scannedFiles ) {
m_viewPopulated = false; // avoid a recursion :)
scanFiles();
m_scannedFiles = true;
}
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
@@ -1,37 +1,38 @@
#ifndef PLAYLISTFILEVIEW_H
#define PLAYLISTFILEVIEW_H
#include "playlistview.h"
#include <qpe/applnk.h>
class PlayListFileView : public PlayListView
{
Q_OBJECT
public:
PlayListFileView( const QString &mimeTypePattern, const QString &itemPixmapName, QWidget *parent, const char *name = 0 );
virtual ~PlayListFileView();
bool hasSelection() const;
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
@@ -135,240 +135,279 @@ PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl )
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( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ),
this, SLOT( playIt(QListViewItem*) ) );
connect ( gammaSlider, SIGNAL( valueChanged(int) ),
mediaPlayerState, SLOT( setVideoGamma(int) ) );
connect( this, SIGNAL(skinSelected() ),
m_mp, SLOT( reloadSkins() ) );
// see which skins are installed
populateSkinsMenu();
initializeStates();
channel = new QCopChannel( "QPE/Application/opieplayer2", this );
connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
this, SLOT( qcopReceive(const QCString&,const QByteArray&)) );
cfg.setGroup("PlayList");
QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
loadList(DocLnk( currentPlaylist ) );
tabWidget->showPage( playListTab );
}
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() );
}
while ( d->selectedFiles->next() );
m3uList->write();
m3uList->close();
delete m3uList;
}
}
}
void PlayListWidget::addToSelection( const DocLnk& lnk ) {
d->setDocumentUsed = FALSE;
if( QFileInfo( lnk.file() ).exists() ||
lnk.file().left(4) == "http" ) {
d->selectedFiles->addToSelection( 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() );
}
break;
}
}
void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
switch (mouse) {
case LeftButton:
break;
case RightButton:
{
QPopupMenu m;
m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
m.exec( QCursor::pos() );
}
break;
}
}
void PlayListWidget::addAllToList() {
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);
}
videoView->populateView();
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();
QFileInfo fileInfo(fileref);
if ( !fileInfo.exists() ) {
QMessageBox::warning( this, tr( "Invalid File" ),
tr( "There was a problem in getting the file." ) );
return;
}
clearList();
QString extension = fileInfo.extension(false);
if( extension.find( "m3u", 0, false) != -1
|| extension.find( "pls", 0, false) != -1 ) {
readListFromFile( fileref );
} else {
clearList();
DocLnk lnk;
lnk.setName( fileInfo.baseName() ); //sets name
lnk.setFile( fileref ); //sets file name
addToSelection( lnk );
writeCurrentM3u();
d->setDocumentUsed = TRUE;
mediaPlayerState->setPlaying( FALSE );
mediaPlayerState->setPlaying( TRUE );
}
}
void PlayListWidget::useSelectedDocument() {
d->setDocumentUsed = FALSE;
}
const DocLnk *PlayListWidget::current() const { // this is fugly
assert( currentTab() == CurrentPlayList );
@@ -431,198 +470,190 @@ bool PlayListWidget::first() {
}
bool PlayListWidget::last() {
return d->selectedFiles->last();
}
void PlayListWidget::saveList() {
writem3u();
}
void PlayListWidget::loadList( const DocLnk & lnk) {
QString name = lnk.name();
if( name.length()>0) {
setCaption("OpiePlayer: "+name);
clearList();
readListFromFile(lnk.file());
tabWidget->setCurrentPage(0);
}
}
void PlayListWidget::addSelected() {
assert( inFileListMode() );
QListViewItemIterator it( currentFileListView );
for ( ; it.current(); ++it )
if ( it.current()->isSelected() ) {
QString filename = it.current()->text(3);
DocLnk lnk;
lnk.setName( QFileInfo( filename ).baseName() ); //sets name
lnk.setFile( filename ); //sets file name
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) {
d->setDocumentUsed = FALSE;
if(it) {
if ( currentTab() == CurrentPlayList )
return;
DocLnk lnk;
QString filename;
filename=it->text(3);
lnk.setName( QFileInfo(filename).baseName() ); //sets name
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?")),
(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::playSelected() {
btnPlay( TRUE);
}
bool PlayListWidget::inFileListMode() const
{
TabType tab = currentTab();
return tab == AudioFiles || tab == VideoFiles;
}
void PlayListWidget::openURL() {
// http://66.28.164.33:2080
// http://somafm.com/star0242.m3u
QString filename, name;
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
filename = fileDlg->text();
odebug << "Selected filename is " + filename << oendl;
// Om3u *m3uList;
DocLnk lnk;
Config cfg( "OpiePlayer" );
cfg.setGroup("PlayList");
@@ -665,165 +696,168 @@ void PlayListWidget::openURL() {
static MimeTypes fileSelectorMimeTypes() {
MimeTypes types;
QStringList audio, video, all;
audio << "audio/*";
audio << "playlist/plain";
audio << "audio/x-ogg";
audio << "audio/x-mpegurl";
video << "video/*";
video << "playlist/plain";
all += audio;
all += video;
types.insert("All Media Files", all );
types.insert("Audio", audio );
types.insert("Video", video );
return types;
}
void PlayListWidget::openFile() {
QString filename, name;
Config cfg( "OpiePlayer" );
cfg.setGroup("Dialog");
MimeTypes types = fileSelectorMimeTypes();
QString str = OFileDialog::getOpenFileName( 1, QString::null,
QString::null, types, 0,
tr("Add File to Playlist") );
if( str.isEmpty() )
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 );
QStringList lst = dir.entryList(QDir::Files|QDir::Readable);
for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
QString filename = str + "/" + *it;
if( filename.right( 3) == "m3u" || filename.right(3) == "pls" )
readListFromFile( filename );
else {
addFileToPlaylist( filename, QFileInfo(*it).baseName() );
}
}
}
void PlayListWidget::readListFromFile( const QString &filename ) {
odebug << "read list filename " + filename << oendl;
QFileInfo fi(filename);
Om3u *m3uList;
QString s, name;
m3uList = new Om3u( filename, IO_ReadOnly );
if(fi.extension(false).find("m3u",0,false) != -1 )
m3uList->readM3u();
else if(fi.extension(false).find("pls",0,false) != -1 )
m3uList->readPls();
DocLnk lnk;
for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
s = *it;
// odebug << s << oendl;
if(s.left(4)=="http") {
lnk.setName( s ); //sets file name
lnk.setIcon("opieplayer2/musicfile");
lnk.setFile( s ); //sets file name
} else { //is file
lnk.setName( QFileInfo(s).baseName());
if(s.left(1) != "/") {
lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
} else {
lnk.setFile( s);
}
}
d->selectedFiles->addToSelection( lnk );
}
Config config( "OpiePlayer" );
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()) {
do {
// odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl;
m3uList->add( d->selectedFiles->current()->file() );
}
while ( d->selectedFiles->next() );
// odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl;
m3uList->write();
m3uList->close();
}
delete m3uList;
}
/*
writes current playlist to m3u file */
void PlayListWidget::writem3u() {
Config cfg( "OpiePlayer" );
cfg.setGroup("Dialog");
MimeTypes types = fileSelectorMimeTypes();
QString str = OFileDialog::getOpenFileName( 1, QString::null,
QString::null, types, 0,
tr( "Save Playlist" ));
if(str.left(2) == "//") str=str.right(str.length()-1);
QString name, filename, list;
Om3u *m3uList;
if( !str.isEmpty() ) {
name = str;
// name = fileDlg->text();
// odebug << filename << oendl;
if( name.find("/",0,true) != -1) {// assume they specify a file path
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
@@ -87,59 +87,60 @@ public slots:
QString currentFileListPathName() const;
protected:
QCopChannel * channel;
void keyReleaseEvent( QKeyEvent *e);
signals:
void skinSelected();
private:
int defaultSkinIndex;
/* void readm3u(const QString &); */
/* void readPls(const QString &); */
void readListFromFile(const QString &);
void initializeStates();
bool inFileListMode() const;
private slots:
void qcopReceive(const QCString&, const QByteArray&);
void populateSkinsMenu();
void skinsMenuActivated(int);
void pmViewActivated(int);
void writem3u();
void writeCurrentM3u();
void openFile();
void openURL();
void openDirectory();
void setDocument( const QString& fileref );
void addToSelection( const DocLnk& ); // Add a media file to the playlist
void addToSelection( QListViewItem* ); // Add a media file to the playlist
void clearList();
void addAllToList();
void addAllMusicToList();
void addAllVideoToList();
void saveList(); // Save the playlist
void loadList( const DocLnk &); // Load a playlist
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