summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/mediaplayer.cpp1
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp108
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h2
3 files changed, 64 insertions, 47 deletions
diff --git a/noncore/multimedia/opieplayer2/mediaplayer.cpp b/noncore/multimedia/opieplayer2/mediaplayer.cpp
index b8023ca..043d8ba 100644
--- a/noncore/multimedia/opieplayer2/mediaplayer.cpp
+++ b/noncore/multimedia/opieplayer2/mediaplayer.cpp
@@ -112,97 +112,96 @@ void MediaPlayer::setPlaying( bool play ) {
} else {
tickerText = xineControl()->getMetaInfo();
}
} else {
if ( xineControl()->getMetaInfo().isEmpty() ) {
tickerText = tr( " File: " ) + fileName + tr( ", Length: " ) + time + " ";
} else {
tickerText = xineControl()->getMetaInfo() + " Length: " + time + " ";
}
}
audioUI()->setTickerText( tickerText );
}
void MediaPlayer::prev() {
if( playList.currentTab() == PlayListWidget::CurrentPlayList ) { //if using the playlist
if ( playList.prev() ) {
play();
} else if ( mediaPlayerState.isLooping() ) {
if ( playList.last() ) {
play();
}
} else {
mediaPlayerState.setList();
}
}
}
void MediaPlayer::next() {
if(playList.currentTab() == PlayListWidget::CurrentPlayList) { //if using the playlist
if ( playList.next() ) {
play();
} else if ( mediaPlayerState.isLooping() ) {
if ( playList.first() ) {
play();
}
} else {
mediaPlayerState.setList();
}
} else { //if playing from file list, let's just stop
odebug << "<<<<<<<<<<<<<<<<<stop for filelists" << oendl;
mediaPlayerState.setPlaying(false);
mediaPlayerState.setDisplayType( MediaPlayerState::MediaSelection );
if(l) mediaPlayerState.setLooping(l);
if(r) mediaPlayerState.setShuffled(r);
}
- qApp->processEvents();
}
void MediaPlayer::startDecreasingVolume() {
volumeDirection = -1;
startTimer( 100 );
volControl->decVol(2);
}
void MediaPlayer::startIncreasingVolume() {
volumeDirection = +1;
startTimer( 100 );
volControl->incVol(2);
}
bool drawnOnScreenDisplay = FALSE;
unsigned int onScreenDisplayVolume = 0;
const int yoff = 110;
void MediaPlayer::stopChangingVolume() {
killTimers();
// Get rid of the on-screen display stuff
drawnOnScreenDisplay = FALSE;
onScreenDisplayVolume = 0;
int w=0;
int h=0;
if( !xineControl()->hasVideo() ) {
w = audioUI()->width();
h = audioUI()->height();
audioUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
} else {
w = videoUI()->width();
h = videoUI()->height();
videoUI()->repaint( ( w - 200 ) / 2, h - yoff, 200 + 9, 70, FALSE );
}
}
void MediaPlayer::timerEvent( QTimerEvent * ) {
if ( volumeDirection == +1 ) {
volControl->incVol( 2 );
} else if ( volumeDirection == -1 ) {
volControl->decVol( 2 );
}
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 37b998f..dc2c496 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -40,96 +40,98 @@
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/ofiledialog.h>
using namespace Opie::Core;
using namespace Opie::Ui;
/* QT */
#include <qmessagebox.h>
#include <qtoolbar.h>
/* STD */
#include <assert.h>
PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl )
: PlayListWidgetGui( parent, "playList" ) , currentFileListView( 0 )
{
Global::statusMessage( tr( "Loading of Skin started" ) );
mediaPlayerState = new MediaPlayerState(0, "mediaPlayerState" );
m_mp = new MediaPlayer(*this, *mediaPlayerState, 0, "mediaPlayer");
d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
"opieplayer2/add_to_playlist",
this , SLOT(addSelected() ) );
d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
"opieplayer2/remove_from_playlist",
this , SLOT(removeSelected() ) );
d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
this , SLOT( btnPlay(bool) ), TRUE );
d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
mediaPlayerState, SLOT( setShuffled(bool) ), TRUE );
d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
mediaPlayerState, SLOT( setLooping(bool) ), TRUE );
(void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
(void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
this, SLOT( addAllMusicToList() ) );
(void)new MenuItem( pmPlayList, tr( "Add all video files" ),
this, SLOT( addAllVideoToList() ) );
(void)new MenuItem( pmPlayList, tr( "Add all files" ),
this, SLOT( addAllToList() ) );
pmPlayList->insertSeparator(-1);
(void)new MenuItem( pmPlayList, tr( "Add File" ),
this,SLOT( openFile() ) );
(void)new MenuItem( pmPlayList, tr("Add URL"),
this,SLOT( openURL() ) );
+ (void)new MenuItem( pmPlayList, tr( "Add Directory"),
+ this, SLOT(openDirectory()));
pmPlayList->insertSeparator(-1);
(void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
this, SLOT(writem3u() ) );
pmPlayList->insertSeparator(-1);
(void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
audioView, SLOT( scanFiles() ) );
(void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
videoView, SLOT( scanFiles() ) );
pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
mediaPlayerState, SLOT( toggleFullscreen() ) );
Config cfg( "OpiePlayer" );
bool b= cfg.readBoolEntry("FullScreen", 0);
mediaPlayerState->setFullscreen( b );
pmView->setItemChecked( -16, b );
(void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
d->selectedFiles, SLOT(moveSelectedUp() ) );
(void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
d->selectedFiles, SLOT(removeSelected() ) );
(void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
d->selectedFiles, SLOT(moveSelectedDown() ) );
QVBox *stretch2 = new QVBox( vbox1 );
connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
SLOT( deletePlaylist() ) );
connect( pmView, SIGNAL( activated(int) ),
this, SLOT( pmViewActivated(int) ) );
connect( skinsMenu, SIGNAL( activated(int) ) ,
this, SLOT( skinsMenuActivated(int) ) );
connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) );
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*) ) );
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*) ) );
connect( playLists, SIGNAL( fileSelected(const DocLnk&) ),
this, SLOT( loadList(const DocLnk&) ) );
connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
@@ -617,246 +619,250 @@ void PlayListWidget::openURL() {
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");
if(filename.left(4) == "http") {
QString m3uFile, m3uFilePath;
if(filename.find(":",8,TRUE) != -1) { //found a port
m3uFile = filename.left( filename.find( ":",8,TRUE));
m3uFile = m3uFile.right( 7);
} else if(filename.left(4) == "http"){
m3uFile=filename;
m3uFile = m3uFile.right( m3uFile.length() - 7);
} else{
m3uFile=filename;
}
lnk.setName( filename ); //sets name
lnk.setFile( filename ); //sets file name
// lnk.setIcon("opieplayer2/musicfile");
d->selectedFiles->addToSelection( lnk );
writeCurrentM3u();
d->selectedFiles->setSelectedItem( lnk.name());
}
else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
readListFromFile( filename );
} else {
lnk.setName( QFileInfo(filename).baseName() ); //sets name
lnk.setFile( filename ); //sets file name
d->selectedFiles->addToSelection( lnk);
writeCurrentM3u();
d->selectedFiles->setSelectedItem( lnk.name());
}
}
delete fileDlg;
}
-void PlayListWidget::openFile() {
-
- QString filename, name;
-
- Config cfg( "OpiePlayer" );
- cfg.setGroup("Dialog");
+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 );
- QString str = OFileDialog::getOpenFileName( 1,
- cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"",
- types, 0 );
+ 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.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() );
}
- cfg.writeEntry( "LastDirectory" ,QFileInfo( str ).dirPath() );
+}
- if( !str.isEmpty() ) {
+void PlayListWidget::openDirectory() {
+ QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector,
+ QString::null, 0,
+ tr( "Add Files from Directory"));
- odebug << "Selected filename is " + str << oendl;
- filename = str;
- DocLnk lnk;
+ 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);
- if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
+ 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 {
- lnk.setName( QFileInfo(filename).baseName() ); //sets name
- lnk.setFile( filename ); //sets file name
- d->selectedFiles->addToSelection( lnk );
- writeCurrentM3u();
- d->selectedFiles->setSelectedItem( lnk.name() );
+ 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());
}
// 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() {
- //InputDilog *fileDlg;
- //fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
- //fileDlg->exec();
Config cfg( "OpiePlayer" );
cfg.setGroup("Dialog");
- MimeTypes types;
- QStringList audio, video, all;
- audio << "audio/*";
- audio << "playlist/plain";
- audio << "audio/x-mpegurl";
+ MimeTypes types = fileSelectorMimeTypes();
- video << "video/*";
- video << "playlist/plain";
+ QString str = OFileDialog::getOpenFileName( 1, QString::null,
+ QString::null, types, 0,
+ tr( "Save Playlist" ));
- all += audio;
- all += video;
- types.insert("All Media Files", all );
- types.insert("Audio", audio );
- types.insert("Video", video );
-
- QString str = OFileDialog::getOpenFileName( 1,
- cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"",
- types, 0 );
if(str.left(2) == "//") str=str.right(str.length()-1);
- cfg.writeEntry("LastDirectory" ,QFileInfo(str).dirPath());
-
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
filename = name;
name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
}
else //otherwise dump it somewhere noticable
filename = QPEApplication::documentDir() + "/" + name;
if( filename.right( 3 ) != "m3u" ) //needs filename extension
filename += ".m3u";
if( d->selectedFiles->first()) { //ramble through playlist view
m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate);
do {
m3uList->add( d->selectedFiles->current()->file());
}
while ( d->selectedFiles->next() );
// odebug << list << oendl;
m3uList->write();
m3uList->close();
delete m3uList;
//delete fileDlg;
DocLnk lnk;
lnk.setFile( filename);
lnk.setIcon("opieplayer2/playlist2");
lnk.setName( name); //sets file name
// odebug << filename << oendl;
Config config( "OpiePlayer" );
config.setGroup( "PlayList" );
config.writeEntry("CurrentPlaylist",filename);
currentPlayList=filename;
if(!lnk.writeLink()) {
odebug << "Writing doclink did not work" << oendl;
}
@@ -962,89 +968,99 @@ void PlayListWidget::populateSkinsMenu() {
skinsMenu->setItemChecked( item, TRUE );
}
++it;
}
}
void PlayListWidget::skinsMenuActivated( int item ) {
for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) {
skinsMenu->setItemChecked( i, FALSE );
}
skinsMenu->setItemChecked( item, TRUE );
{
Config cfg( "OpiePlayer" );
cfg.setGroup("Options");
cfg.writeEntry("Skin", skinsMenu->text( item ) );
}
emit skinSelected();
}
PlayListWidget::TabType PlayListWidget::currentTab() const
{
static const TabType indexToTabType[ TabTypeCount ] =
{ CurrentPlayList, AudioFiles, VideoFiles, PlayLists };
int index = tabWidget->currentPageIndex();
assert( index < TabTypeCount && index >= 0 );
return indexToTabType[ index ];
}
PlayListWidget::Entry PlayListWidget::currentEntry() const
{
if ( currentTab() == CurrentPlayList ) {
const DocLnk *lnk = current();
return Entry( lnk->name(), lnk->file() );
}
return Entry( currentFileListPathName() );
}
QString PlayListWidget::currentFileListPathName() const {
return currentFileListView->currentItem()->text( 3 );
}
void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
- odebug << "qcop message "+msg << oendl;
QDataStream stream ( data, IO_ReadOnly );
if ( msg == "play()" ) { //plays current selection
btnPlay( true);
} else if ( msg == "stop()" ) {
mediaPlayerState->setPlaying( false);
} else if ( msg == "togglePause()" ) {
mediaPlayerState->togglePaused();
} else if ( msg == "next()" ) { //select next in list
mediaPlayerState->setNext();
} else if ( msg == "prev()" ) { //select previous in list
mediaPlayerState->setPrev();
} else if ( msg == "toggleLooping()" ) { //loop or not loop
mediaPlayerState->toggleLooping();
} else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled
mediaPlayerState->toggleShuffled();
} else if ( msg == "volUp()" ) { //volume more
// emit moreClicked();
// emit moreReleased();
} else if ( msg == "volDown()" ) { //volume less
// emit lessClicked();
// emit lessReleased();
} else if ( msg == "play(QString)" ) { //play this now
QString file;
stream >> file;
setDocument( (const QString &) file);
} else if ( msg == "add(QString)" ) { //add to playlist
QString file;
stream >> file;
QFileInfo fileInfo(file);
DocLnk lnk;
lnk.setName( fileInfo.baseName() ); //sets name
lnk.setFile( file ); //sets file name
addToSelection( lnk );
} else if ( msg == "rem(QString)" ) { //remove from playlist
QString file;
stream >> file;
}
}
+
+DocLnk PlayListWidget::addFileToPlaylist( const QString& file,
+ const QString& name ) {
+ DocLnk lnk;
+ lnk.setName( name ); //sets name
+ lnk.setFile( file ); //sets file name
+ d->selectedFiles->addToSelection( lnk );
+ writeCurrentM3u();
+
+ return lnk;
+}
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h
index 29f3e8d..1f5ba92 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.h
+++ b/noncore/multimedia/opieplayer2/playlistwidget.h
@@ -65,79 +65,81 @@ public:
QString name;
QString file;
};
static QString appName() { return QString::fromLatin1("opieplayer2"); }
PlayListWidget( QWidget* parent=0, const char* name=0, WFlags = 0 );
~PlayListWidget();
// retrieve the current playlist entry (media file link)
const DocLnk *current() const;
void useSelectedDocument();
TabType currentTab() const;
Entry currentEntry() const;
public slots:
bool first();
bool last();
bool next();
bool prev();
void writeDefaultPlaylist( );
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);
bool fromSetDocument;
bool insanityBool;
QString setDocFileRef, currentPlayList;
int selected;
QListView *currentFileListView;
MediaPlayer *m_mp;
};
#endif // PLAY_LIST_WIDGET_H