summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-19 12:34:09 (UTC)
committer llornkcor <llornkcor>2002-06-19 12:34:09 (UTC)
commitb55f69a46fd27ce26235029f702c0f3942fde68c (patch) (side-by-side diff)
tree47aa9ca1e9c80367050a93715f384eef2285e7b9
parent1d60bfb5925c5009122ae04009f8e99658436b35 (diff)
downloadopie-b55f69a46fd27ce26235029f702c0f3942fde68c.zip
opie-b55f69a46fd27ce26235029f702c0f3942fde68c.tar.gz
opie-b55f69a46fd27ce26235029f702c0f3942fde68c.tar.bz2
dont crash on malformed urls
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp79
1 files changed, 49 insertions, 30 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 41fcb30..2323ac2 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -371,103 +371,109 @@ void PlayListWidget::readConfig( Config& cfg ) {
DocLnk lnk( linkFile );
if ( lnk.isValid() ) {
d->selectedFiles->addToSelection( lnk );
}
}
d->selectedFiles->setSelectedItem( currentString);
// d->selectedFiles->setSelectedItem( (const QString &)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 ) {
// qDebug("add");
- d->setDocumentUsed = FALSE;
- if ( mediaPlayerState->playlist() ) {
- if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" )
- d->selectedFiles->addToSelection( lnk );
+ if( lnk.file().find(" ",0,TRUE) != -1 || lnk.file().find("%20",0,TRUE) != -1) {
+ QMessageBox::message("Note","You are trying to play\na malformed url.");
+
+ } else {
+
+ d->setDocumentUsed = FALSE;
+ if ( mediaPlayerState->playlist() ) {
+ if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" )
+ d->selectedFiles->addToSelection( lnk );
+ }
+ else
+ mediaPlayerState->setPlaying( TRUE );
}
- 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 );
}
void PlayListWidget::addAllMusicToList() {
QListIterator<DocLnk> dit( files.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo(dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::addAllVideoToList() {
QListIterator<DocLnk> dit( vFiles.children() );
for ( ; dit.current(); ++dit )
if(QFileInfo( dit.current()->file()).exists())
d->selectedFiles->addToSelection( **dit );
}
void PlayListWidget::setDocument(const QString& fileref) {
qDebug(fileref);
fromSetDocument = TRUE;
if ( fileref.isNull() ) {
QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) );
return;
}
// qDebug("setDocument "+fileref);
if(fileref.find("m3u",0,TRUE) != -1) { //is m3u
readm3u( fileref);
}
else if(fileref.find("pls",0,TRUE) != -1) { //is pls
readPls( fileref);
@@ -801,124 +807,128 @@ void PlayListWidget::addToSelection( QListViewItem *it) {
void PlayListWidget::tabChanged(QWidget *widg) {
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) {
// mediaPlayerState->setPlaying(b);
switch ( tabWidget->currentPageIndex()) {
case 0:
{
-
- mediaPlayerState->setPlaying(b);
- }
+ qDebug("here we are");
+ if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 || d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) {
+ QMessageBox::message("Note","You are trying to play\na malformed url.");
+
+ } else {
+
+ mediaPlayerState->setPlaying(b);
+ } }
break;
case 1:
{
- addToSelection( audioView->currentItem() );
- mediaPlayerState->setPlaying(b);
- d->selectedFiles->removeSelected( );
- tabWidget->setCurrentPage(1);
- d->selectedFiles->unSelect();
- insanityBool=FALSE;
-// audioView->clearSelection();
- }
+ addToSelection( audioView->currentItem() );
+ mediaPlayerState->setPlaying(b);
+ d->selectedFiles->removeSelected( );
+ tabWidget->setCurrentPage(1);
+ d->selectedFiles->unSelect();
+ insanityBool=FALSE;
+ }// audioView->clearSelection();
break;
case 2:
{
- addToSelection( videoView->currentItem() );
- mediaPlayerState->setPlaying(b);
- qApp->processEvents();
- d->selectedFiles->removeSelected( );
- tabWidget->setCurrentPage(2);
- d->selectedFiles->unSelect();
- insanityBool=FALSE;
-// videoView->clearSelection();
- }
+ addToSelection( videoView->currentItem() );
+ mediaPlayerState->setPlaying(b);
+ qApp->processEvents();
+ d->selectedFiles->removeSelected( );
+ tabWidget->setCurrentPage(2);
+ d->selectedFiles->unSelect();
+ 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->selected()->file());
QFile().remove(playLists->selected()->linkFile());
playLists->reread();
break;
case 1: // Cancel
break;
};
}
void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
{
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()
{
btnPlay( TRUE);
// d->selectedFiles->unSelect();
}
void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i)
{
switch (mouse) {
case 1:
break;
@@ -1023,122 +1033,126 @@ void PlayListWidget::populateAudioView() {
QListViewItem * newItem;
if ( QFile( dit.current()->file()).exists() ) {
// qDebug(dit.current()->name());
newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(),
QString::number( QFile( dit.current()->file()).size() ), storage);
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);
newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" ));
}
}
}
void PlayListWidget::openFile() {
QString filename, name;
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
filename = fileDlg->LineEdit1->text();
// http://205.188.234.129:8030
// http://66.28.68.70:8000
- filename.replace(QRegExp("%20")," ");
-
- qDebug("Selected filename is "+filename);
+// filename.replace(QRegExp("%20")," ");
+ if(filename.find(" ",0,TRUE) != -1 || filename.find("%20",0,TRUE) != -1) {
+ QMessageBox::message("Note","Spaces in urls are not allowed.");
+ return;
+ } else {
+ qDebug("Selected filename is "+filename);
if(filename.right(3) == "m3u")
readm3u( filename);
else if(filename.right(3) == "pls")
readPls( filename);
else {
DocLnk lnk;
lnk.setName(filename); //sets file name
if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3")
filename += "/";
lnk.setFile(filename); //sets File property
lnk.setType("audio/x-mpegurl");
lnk.setExec("opieplayer");
lnk.setIcon("opieplayer/MPEGPlayer");
if(!lnk.writeLink())
qDebug("Writing doclink did not work");
d->selectedFiles->addToSelection( lnk);
// if(fileDlg2)
// delete fileDlg2;
}
}
+ }
if(fileDlg)
delete fileDlg;
}
void PlayListWidget::keyReleaseEvent( QKeyEvent *e)
{
switch ( e->key() ) {
////////////////////////////// Zaurus keys
case Key_F9: //activity
// if(audioUI->isHidden())
// audioUI->showMaximized();
break;
case Key_F10: //contacts
// if( videoUI->isHidden())
// videoUI->showMaximized();
break;
case Key_F11: //menu
break;
case Key_F12: //home
// doBlank();
break;
case Key_F13: //mail
// doUnblank();
break;
case Key_Q: //add to playlist
qDebug("Add");
addSelected();
break;
case Key_R: //remove from playlist
removeSelected();
break;
// case Key_P: //play
// qDebug("Play");
// playSelected();
// break;
case Key_Space:
qDebug("Play");
// playSelected(); puh
break;
case Key_1:
tabWidget->setCurrentPage(0);
break;
case Key_2:
tabWidget->setCurrentPage(1);
break;
case Key_3:
tabWidget->setCurrentPage(2);
break;
@@ -1160,129 +1174,134 @@ void PlayListWidget::keyPressEvent( QKeyEvent *e)
// case Key_R: //remove from playlist
// removeSelected();
// break;
// case Key_P: //play
// qDebug("Play");
// playSelected();
// break;
// case Key_Space:
// qDebug("Play");
// playSelected();
// break;
// }
}
void PlayListWidget::doBlank() {
qDebug("do blanking");
fd=open("/dev/fb0",O_RDWR);
if (fd != -1) {
ioctl(fd,FBIOBLANK,1);
// close(fd);
}
}
void PlayListWidget::doUnblank() {
// this crashes opieplayer with a segfault
// int fd;
// fd=open("/dev/fb0",O_RDWR);
qDebug("do unblanking");
if (fd != -1) {
ioctl(fd,FBIOBLANK,0);
close(fd);
}
QCopEnvelope h("QPE/System", "setBacklight(int)");
h <<-3;// v[1]; // -3 Force on
}
void PlayListWidget::readm3u(const QString &filename) {
qDebug("m3u filename is "+filename);
QFile f(filename);
if(f.open(IO_ReadOnly)) {
QTextStream t(&f);
QString s;//, first, second;
int i=0;
while ( !t.atEnd()) {
// Lview->insertLine(t.readLine(),-1);
s=t.readLine();
- if(s.find("#",0,TRUE) == -1) {
+ if(s.find(" ",0,TRUE) != -1 || s.find("%20",0,TRUE) != -1) {
+ QMessageBox::message("Note","Spaces in urls are not allowed.");
+ }
+ else if(s.find("#",0,TRUE) == -1) {
if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat
if(s.left(2) == "E:" || s.left(2) == "P:") {
s=s.right(s.length()-2);
DocLnk lnk( s );
QFileInfo f(s);
QString name = f.baseName();
name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
lnk.setName( name);
s=s.replace( QRegExp("\\"),"/");
lnk.setFile( s);
// lnk.setIcon(opieplayer/MPEGPlayer);
qDebug("add "+name);
d->selectedFiles->addToSelection( lnk);
} else { // is url
+
s.replace(QRegExp("%20")," ");
DocLnk lnk( s);
QString name = s.right( s.length() - 7);
// name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
lnk.setName(name);
lnk.setFile( s+"/");
// lnk.setFile( filename);
// lnk.setComment( s+"/");
lnk.setType("audio/x-mpegurl");
// lnk.setIcon( "opieplayer/MPEGPlayer");
// qDebug("add "+s);
d->selectedFiles->addToSelection( lnk);
}
i++;
}
}
}
}
+ f.close();
}
void PlayListWidget::writem3u(const QString &filename) {
}
void PlayListWidget::readPls(const QString &filename) {
qDebug("pls filename is "+filename);
QFile f(filename);
if(f.open(IO_ReadOnly)) {
QTextStream t(&f);
QString s;//, first, second;
int i=0;
while ( !t.atEnd()) {
s=t.readLine();
if(s.left(4) == "File") {
s=s.right(s.length() - 6);
s.replace(QRegExp("%20")," ");
qDebug("adding "+s+" to playlist");
// numberofentries=2
// File1=http
// Title
// Length
// Version
// File2=http
s=s.replace( QRegExp("\\"),"/");
// Lview->insertLine(t.readLine(),-1);
// s=t.readLine();
// s=s.right(s.length()-2);
DocLnk lnk( s );
QFileInfo f(s);
QString name = f.baseName();
name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1);
// QFileInfo f(s);
// QString name = f.baseName();
// // name = name.left(name.length()-4);
// name = name.right(name.findRev("/",0,TRUE));
lnk.setName( name);
lnk.setFile( s+"/");
lnk.setType("audio/x-mpegurl");
qDebug("DocLnk add "+name);
d->selectedFiles->addToSelection( lnk);
}
}