summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/main.cpp2
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp64
2 files changed, 45 insertions, 21 deletions
diff --git a/core/multimedia/opieplayer/main.cpp b/core/multimedia/opieplayer/main.cpp
index 4f43ff6..18cd7a6 100644
--- a/core/multimedia/opieplayer/main.cpp
+++ b/core/multimedia/opieplayer/main.cpp
@@ -2,55 +2,55 @@
** 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/qpeapplication.h>
#include "mediaplayerstate.h"
#include "playlistwidget.h"
#include "audiowidget.h"
#include "videowidget.h"
#include "loopcontrol.h"
#include "mediaplayer.h"
MediaPlayerState *mediaPlayerState;
PlayListWidget *playList;
AudioWidget *audioUI;
VideoWidget *videoUI;
LoopControl *loopControl;
int main(int argc, char **argv) {
QPEApplication a(argc,argv);
MediaPlayerState st( 0, "mediaPlayerState" );
mediaPlayerState = &st;
PlayListWidget pl( 0, "playList" );
playList = &pl;
AudioWidget aw( 0, "audioUI" );
audioUI = &aw;
VideoWidget vw( 0, "videoUI" );
videoUI = &vw;
LoopControl lc( 0, "loopControl" );
loopControl = &lc;
MediaPlayer mp( 0, "mediaPlayer" );
- pl.setCaption( MediaPlayer::tr("OpiePlayer") );
+// pl.setCaption( MediaPlayer::tr("OpiePlayer") );
a.showMainDocumentWidget(&pl);
return a.exec();
}
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index cb58888..9969526 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,69 +1,68 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of 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.
**
**********************************************************************/
// code added by L. J. Potter Sat 03-02-2002 06:17:54
-
#include <qpe/qpemenubar.h>
#include <qpe/qpetoolbar.h>
#include <qpe/fileselector.h>
#include <qpe/qpeapplication.h>
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/global.h>
#include <qpe/resource.h>
#include <qaction.h>
#include <qimage.h>
#include <qfile.h>
#include <qdir.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qlist.h>
#include <qlistbox.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qtoolbutton.h>
#include <qtabwidget.h>
#include <qlistview.h>
#include <qpoint.h>
#include <qlineedit.h>
#include <qpushbutton.h>
//#include <qtimer.h>
#include "playlistselection.h"
#include "playlistwidget.h"
#include "mediaplayerstate.h"
#include "inputDialog.h"
#include <stdlib.h>
#define BUTTONS_ON_TOOLBAR
#define SIDE_BUTTONS
#define CAN_SAVE_LOAD_PLAYLISTS
extern MediaPlayerState *mediaPlayerState;
// class myFileSelector {
// };
class PlayListWidgetPrivate {
public:
QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
@@ -211,259 +210,265 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
QListIterator<DocLnk> dit( files.children() );
QString storage;
for ( ; dit.current(); ++dit ) {
QListViewItem * newItem;
if(dit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
else if(dit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
else if(dit.current()->file().find("/mnt/card") != -1 ) storage="SD";
else storage="RAM";
if ( QFile( dit.current()->file()).exists() ) {
newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number( QFile( dit.current()->file()).size() ), storage);
newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/musicfile" ));
}
}
// videowidget
QWidget *vTab;
vTab = new QWidget( tabWidget, "vTab" );
videoView = new QListView( vTab, "Videoview" );
videoView->setMinimumSize(233,260);
videoView->addColumn("Title",150);
videoView->addColumn("Size",45);
videoView->addColumn("Media",35);
videoView->setColumnAlignment(1, Qt::AlignRight);
videoView->setColumnAlignment(2, Qt::AlignRight);
tabWidget->insertTab( vTab,"Video");
Global::findDocuments(&vFiles, "video/*");
QListIterator<DocLnk> Vdit( vFiles.children() );
for ( ; Vdit.current(); ++Vdit ) {
if( Vdit.current()->file().find("/mnt/cf") != -1 ) storage="CF";
else if( Vdit.current()->file().find("/mnt/hda") != -1 ) storage="CF";
else if( Vdit.current()->file().find("/mnt/card") != -1 ) storage="SD";
else storage="RAM";
QListViewItem * newItem;
if ( QFile( Vdit.current()->file()).exists() ) {
newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage);
newItem->setPixmap(0, Resource::loadPixmap( "mpegplayer/videofile" ));
}
}
//playlists list
QWidget *LTab;
LTab = new QWidget( tabWidget, "LTab" );
playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy
playLists->setMinimumSize(233,260);;
tabWidget->insertTab(LTab,"Lists");
+
connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) );
// connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
// add the library area
QPEApplication::setStylusOperation( this, QPEApplication::RightOnHold );
- connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
- this, SLOT( fauxPlay( QListViewItem *) ) );
- connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
- this, SLOT( fauxPlay( QListViewItem *)) );
+// connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
+// this, SLOT( fauxPlay( QListViewItem *) ) );
+// connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)),
+// this, SLOT( fauxPlay( QListViewItem *)) );
// connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
// connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) );
connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) );
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 *) ) );
// connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) );
setCentralWidget( vbox5 );
Config cfg( "MediaPlayer" );
readConfig( cfg );
-
+ QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
+// qDebug("currentList is "+currentPlaylist);
+ loadList(DocLnk( currentPlaylist));
+ setCaption("OpiePlayer: "+ currentPlaylist );
+
initializeStates();
}
PlayListWidget::~PlayListWidget() {
Config cfg( "MediaPlayer" );
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() );
// d->tbFull->setOn( mediaPlayerState->fullscreen() );
// d->tbScale->setOn( mediaPlayerState->scaled() );
// d->tbScale->setEnabled( mediaPlayerState->fullscreen() );
// setPlaylist( mediaPlayerState->playlist() );
- setPlaylist( true);
- d->selectedFiles->first();
-
+ setPlaylist( true);
+ d->selectedFiles->first();
}
void PlayListWidget::readConfig( Config& cfg ) {
cfg.setGroup("PlayList");
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 );
}
}
void PlayListWidget::writeConfig( Config& cfg ) const {
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 );
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 ) {
- qDebug("add");
+// qDebug("add");
d->setDocumentUsed = FALSE;
if ( mediaPlayerState->playlist() )
d->selectedFiles->addToSelection( lnk );
else
mediaPlayerState->setPlaying( TRUE );
}
void PlayListWidget::clearList() {
while ( first() )
d->selectedFiles->removeSelected();
}
void PlayListWidget::addAllToList() {
DocLnkSet files;
Global::findDocuments(&files, "video/*;audio/*");
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::addAllMusicToList() {
DocLnkSet files;
Global::findDocuments(&files, "audio/*");
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::addAllVideoToList() {
DocLnkSet files;
Global::findDocuments(&files, "video/*");
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::setDocument(const QString& fileref) {
if ( fileref.isNull() ) {
QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
return;
}
+// qDebug("setDocument");
if(fileref.find("playlist",0,TRUE) == -1) {
addToSelection( DocLnk( fileref ) );
d->setDocumentUsed = TRUE;
qApp->processEvents();
mediaPlayerState->setPlaying( FALSE );
qApp->processEvents();
mediaPlayerState->setPlaying( TRUE );
d->selectedFiles->removeSelected( );
} else {
loadList(DocLnk(fileref));
d->selectedFiles->first();
// mediaPlayerState->setPlaying( TRUE );
// mediaPlayerState->setPlaying( FALSE );
}
}
void PlayListWidget::setActiveWindow() {
// When we get raised we need to ensure that it switches views
char origView = mediaPlayerState->view();
mediaPlayerState->setView( 'l' ); // invalidate
mediaPlayerState->setView( origView ); // now switch back
}
void PlayListWidget::useSelectedDocument() {
d->setDocumentUsed = FALSE;
}
const DocLnk *PlayListWidget::current() {
// qDebug("in Playlist widget ::current");
if ( mediaPlayerState->playlist() ) {
return d->selectedFiles->current();
}
else if ( d->setDocumentUsed && d->current ) {
return d->current;
} else {
return d->files->selected();
}
}
bool PlayListWidget::prev() {
if ( mediaPlayerState->playlist() ) {
if ( mediaPlayerState->shuffled() ) {
@@ -488,126 +493,145 @@ bool PlayListWidget::prev() {
return TRUE;
}
} else {
return mediaPlayerState->looping();
}
}
bool PlayListWidget::next() {
if ( mediaPlayerState->playlist() ) {
if ( mediaPlayerState->shuffled() ) {
return prev();
} 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() {
QString filename;
InputDialog *fileDlg;
- fileDlg=new InputDialog(this,"Save Playlist",TRUE, 0);
+ fileDlg = new InputDialog(this,"Save Playlist",TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
+ if ( d->current )
+ delete d->current;
filename = fileDlg->LineEdit1->text();//+".playlist";
- qDebug("saving playlist "+filename+".playlist");
+// qDebug("saving playlist "+filename+".playlist");
Config cfg( filename +".playlist");
writeConfig( cfg );
+ if( playLists->selected()->name() == filename) {
+// qDebug("same name so delete lnk");
+ QFile().remove(playLists->selected()->file());
+ QFile().remove(playLists->selected()->linkFile());
+ playLists->reread();
+ }
+
DocLnk lnk;
// lnk.setComment( "");
lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property
lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
lnk.setIcon("mpegplayer/playlist2");
lnk.setName( filename); //sets file name
if(!lnk.writeLink())
qDebug("Writing doclink did not work");
- }
-
+ }
+ Config config( "MediaPlayer" );
+ config.writeEntry("CurrentPlaylist",filename);
+ setCaption("OpiePlayer: "+filename);
+ d->selectedFiles->first();
if(fileDlg)
delete fileDlg;
}
void PlayListWidget::loadList( const DocLnk & lnk) {
- qDebug("load list "+ lnk.name()+".playlist");
- clearList();
- Config cfg( lnk.name()+".playlist");
- readConfig(cfg);
- tabWidget->setCurrentPage(0);
- setCaption("OpiePlayer: "+lnk.name());
+ QString name= lnk.name();
+// qDebug("currentList is "+name);
+ if( name.length()>1) {
+ setCaption("OpiePlayer: "+name);
+// qDebug("load list "+ name+".playlist");
+ clearList();
+ Config cfg( name+".playlist");
+ readConfig(cfg);
+ tabWidget->setCurrentPage(0);
+ Config config( "MediaPlayer" );
+ config.writeEntry("CurrentPlaylist", name);
+ d->selectedFiles->first();
+ }
}
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() {
switch (tabWidget->currentPageIndex()) {
case 0: //playlist
break;
case 1: { //audio
addToSelection( audioView->selectedItem() );
}
break;
case 2: { // video
addToSelection( videoView->selectedItem() );
}
break;
};
}
void PlayListWidget::removeSelected() {
d->selectedFiles->removeSelected( );
}
void PlayListWidget::playIt( QListViewItem *it) {
// d->setDocumentUsed = FALSE;
mediaPlayerState->setPlaying(TRUE);
}
void PlayListWidget::addToSelection( QListViewItem *it) {
d->setDocumentUsed = FALSE;
if(it) {