summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp157
-rw-r--r--noncore/multimedia/opieplayer2/om3u.h79
-rw-r--r--noncore/multimedia/opieplayer2/opieplayer2.pro4
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp612
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h2
5 files changed, 559 insertions, 295 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
new file mode 100644
index 0000000..d378145
--- a/dev/null
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -0,0 +1,157 @@
1/*
2                This file is part of the Opie Project
3
4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29
30*/
31
32#include "playlistwidget.h"
33#include "om3u.h"
34
35#include <qpe/applnk.h>
36#include <qpe/qpeapplication.h>
37#include <qpe/storage.h>
38#include <qpe/mimetype.h>
39#include <qpe/global.h>
40#include <qpe/resource.h>
41
42#include <qdir.h>
43#include <qregexp.h>
44#include <qstring.h>
45#include <qtextstream.h>
46#include <qstringlist.h>
47#include <qcstring.h>
48
49//extern PlayListWidget *playList;
50
51Om3u::Om3u( const QString &filePath)
52 : QStringList (){
53//filePath is path name to m3u
54//qDebug("<<<<<<<new m3u "+filePath);
55 f.setName(filePath);
56 if(f.exists())
57 f.open( IO_ReadWrite );
58 else
59 f.open( IO_ReadWrite | IO_Truncate);
60}
61
62Om3u::~Om3u(){}
63
64void Om3u::readM3u() { //it's m3u
65// qDebug("<<<<<<reading m3u "+f.name());
66 QTextStream t(&f);
67 QString s;
68 while ( !t.atEnd() ) {
69 s=t.readLine();
70
71 if( s.find( "#", 0, TRUE) == -1 ) {
72 if( s.find( " ", 0, TRUE) == -1 ) {
73 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
74 s = s.right( s.length() -2 );
75 QFileInfo f( s );
76 QString name = f.baseName();
77 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
78 s=s.replace( QRegExp( "\\" ), "/" );
79 append(s);
80// qDebug(s);
81 } else { // is url
82 s.replace( QRegExp( "%20" )," " );
83 QString name;
84 if( name.left( 4 ) == "http" ) {
85 name = s.right( s.length() - 7 );
86 } else {
87 name = s;
88 }
89 append(name);
90// qDebug(name);
91 }
92 }
93 }
94 }
95}
96
97void Om3u::readPls() { //it's a pls file
98 QTextStream t( &f );
99 QString s;
100 while ( !t.atEnd() ) {
101 s = t.readLine();
102 if( s.left(4) == "File" ) {
103 s = s.right( s.length() - 6 );
104 s.replace( QRegExp( "%20" )," ");
105// qDebug( "adding " + s + " to playlist" );
106 // numberofentries=2
107 // File1=http
108 // Title
109 // Length
110 // Version
111 // File2=http
112 s = s.replace( QRegExp( "\\" ), "/" );
113 QFileInfo f( s );
114 QString name = f.baseName();
115 if( name.left( 4 ) == "http" ) {
116 name = s.right( s.length() - 7);
117 } else {
118 name = s;
119 }
120 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
121 if( s.at( s.length() - 4) == '.') // if this is probably a file
122 append(s);
123 else { //if its a url
124 if( name.right( 1 ).find( '/' ) == -1) {
125 s += "/";
126 }
127 append(s);
128 }
129 }
130 }
131}
132
133void Om3u::write() { //writes list to m3u file
134 QString list;
135 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
136 qDebug(*it);
137 list += *it+"\n";
138 }
139 f.writeBlock( list, list.length() );
140 f.close();
141}
142
143void Om3u::add(const QString &filePath) { //adds to m3u file
144 append(filePath);
145}
146
147void Om3u::remove(const QString &filePath) { //removes from m3u list
148
149}
150
151void Om3u::deleteFile(const QString &filePath) {//deletes m3u file
152
153}
154
155void Om3u::close() { //closes m3u file
156 f.close();
157}
diff --git a/noncore/multimedia/opieplayer2/om3u.h b/noncore/multimedia/opieplayer2/om3u.h
new file mode 100644
index 0000000..392980e
--- a/dev/null
+++ b/noncore/multimedia/opieplayer2/om3u.h
@@ -0,0 +1,79 @@
1/*
2                This file is part of the Opie Project
3
4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29
30*/
31
32#ifndef OM3U_H
33#define OM3U_H
34
35#include "playlistwidget.h"
36
37#include <qpe/applnk.h>
38#include <qpe/qpeapplication.h>
39#include <qpe/storage.h>
40#include <qpe/mimetype.h>
41#include <qpe/global.h>
42#include <qpe/resource.h>
43
44#include <qdir.h>
45#include <qregexp.h>
46#include <qstring.h>
47#include <qtextstream.h>
48#include <qstringlist.h>
49#include <qcstring.h>
50#include <qfile.h>
51
52
53class Om3u : public QStringList {
54// Q_OBJECT
55public:
56 Om3u( const QString &filePath);
57 ~Om3u();
58 void readM3u();
59 void readPls();
60 void write();
61 void add(const QString &);
62 void remove(const QString &);
63 void deleteFile(const QString &);
64 void close();
65
66public slots:
67
68protected:
69
70private:
71 QFile f;
72private slots:
73
74
75};
76
77#endif// M3U_H
78
79
diff --git a/noncore/multimedia/opieplayer2/opieplayer2.pro b/noncore/multimedia/opieplayer2/opieplayer2.pro
index 619d36d..52814e7 100644
--- a/noncore/multimedia/opieplayer2/opieplayer2.pro
+++ b/noncore/multimedia/opieplayer2/opieplayer2.pro
@@ -3,12 +3,12 @@ TEMPLATE = app
3CONFIG = qt warn_on debug 3CONFIG = qt warn_on debug
4DESTDIR = $(OPIEDIR)/bin 4DESTDIR = $(OPIEDIR)/bin
5HEADERS = playlistselection.h mediaplayerstate.h xinecontrol.h \ 5HEADERS = playlistselection.h mediaplayerstate.h xinecontrol.h \
6 videowidget.h audiowidget.h playlistwidget.h mediaplayer.h inputDialog.h \ 6 videowidget.h audiowidget.h playlistwidget.h om3u.h mediaplayer.h inputDialog.h \
7 frame.h lib.h xinevideowidget.h volumecontrol.h playlistwidgetgui.h\ 7 frame.h lib.h xinevideowidget.h volumecontrol.h playlistwidgetgui.h\
8 alphablend.h yuv2rgb.h 8 alphablend.h yuv2rgb.h
9SOURCES = main.cpp \ 9SOURCES = main.cpp \
10 playlistselection.cpp mediaplayerstate.cpp xinecontrol.cpp \ 10 playlistselection.cpp mediaplayerstate.cpp xinecontrol.cpp \
11 videowidget.cpp audiowidget.cpp playlistwidget.cpp mediaplayer.cpp inputDialog.cpp \ 11 videowidget.cpp audiowidget.cpp playlistwidget.cpp om3u.cpp mediaplayer.cpp inputDialog.cpp \
12 frame.cpp lib.cpp nullvideo.c xinevideowidget.cpp volumecontrol.cpp \ 12 frame.cpp lib.cpp nullvideo.c xinevideowidget.cpp volumecontrol.cpp \
13 playlistwidgetgui.cpp\ 13 playlistwidgetgui.cpp\
14 alphablend.c yuv2rgb.c yuv2rgb_arm.c yuv2rgb_arm4l.S 14 alphablend.c yuv2rgb.c yuv2rgb_arm.c yuv2rgb_arm4l.S
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 6acdd1d..ab6b593 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -47,6 +47,7 @@
47#include "playlistwidget.h" 47#include "playlistwidget.h"
48#include "mediaplayerstate.h" 48#include "mediaplayerstate.h"
49#include "inputDialog.h" 49#include "inputDialog.h"
50#include "om3u.h"
50 51
51//only needed for the random play 52//only needed for the random play
52#include <stdlib.h> 53#include <stdlib.h>
@@ -81,9 +82,9 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
81 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 82 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
82 this, SLOT( addAllToList() ) ); 83 this, SLOT( addAllToList() ) );
83 pmPlayList->insertSeparator(-1); 84 pmPlayList->insertSeparator(-1);
84 (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), 85// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ),
85 this, SLOT( saveList() ) ); 86// this, SLOT( saveList() ) );
86 (void)new MenuItem( pmPlayList, tr( "Export playlist to m3u" ), 87 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
87 this, SLOT(writem3u() ) ); 88 this, SLOT(writem3u() ) );
88 pmPlayList->insertSeparator(-1); 89 pmPlayList->insertSeparator(-1);
89 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), 90 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ),
@@ -147,11 +148,15 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
147 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 148 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
148 mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 149 mediaPlayerState, SLOT( setVideoGamma( int ) ) );
149 150
150 readConfig( cfg ); 151// cfg.setGroup( "PlayList" );
151 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); 152// if( cfg.readBoolEntry("newPlaylist") ){
152 loadList(DocLnk( currentPlaylist ) ); 153 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
153 setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); 154 loadList(DocLnk( currentPlaylist ) );
154 155 setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
156// } else {
157// readConfig( cfg );
158
159// }
155 // see which skins are installed 160 // see which skins are installed
156 videoScan=FALSE; 161 videoScan=FALSE;
157 audioScan=FALSE; 162 audioScan=FALSE;
@@ -179,56 +184,105 @@ void PlayListWidget::initializeStates() {
179 184
180 185
181void PlayListWidget::readConfig( Config& cfg ) { 186void PlayListWidget::readConfig( Config& cfg ) {
187
182 cfg.setGroup( "PlayList" ); 188 cfg.setGroup( "PlayList" );
183 QString currentString = cfg.readEntry( "current", "" ); 189 QString currentString = cfg.readEntry( "current", "" );
184 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 ); 190 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 );
191
185 for ( int i = 0; i < noOfFiles; i++ ) { 192 for ( int i = 0; i < noOfFiles; i++ ) {
186 QString entryName; 193 QString entryName;
187 entryName.sprintf( "File%i", i + 1 ); 194 entryName.sprintf( "File%i", i + 1 );
195
188 QString linkFile = cfg.readEntry( entryName ); 196 QString linkFile = cfg.readEntry( entryName );
197
198 qDebug("reading "+linkFile);
199
189 if( QFileInfo( linkFile ).exists() ) { 200 if( QFileInfo( linkFile ).exists() ) {
201
190 DocLnk lnk( linkFile ); 202 DocLnk lnk( linkFile );
203
191 if ( QFileInfo( lnk.file() ).exists() || 204 if ( QFileInfo( lnk.file() ).exists() ||
205
192 linkFile.find( "http" , 0, TRUE) != -1) { 206 linkFile.find( "http" , 0, TRUE) != -1) {
207
193 d->selectedFiles->addToSelection( lnk ); 208 d->selectedFiles->addToSelection( lnk );
209
194 } 210 }
195 } 211 }
196 } 212 }
197 d->selectedFiles->setSelectedItem( currentString ); 213 d->selectedFiles->setSelectedItem( currentString );
214
198} 215}
199 216
200 217
201void PlayListWidget::writeConfig( Config& cfg ) const { 218void PlayListWidget::writeConfig( Config& cfg ) const {
202 d->selectedFiles->writeCurrent( cfg ); 219
203 cfg.setGroup( "PlayList" ); 220// Config config( "OpiePlayer" );
204 int noOfFiles = 0; 221// config.setGroup( "PlayList" );
205 d->selectedFiles->first(); 222
206 do { 223// if(config.readBoolEntry("newPlaylist")) {
207 const DocLnk *lnk = d->selectedFiles->current(); 224// new for testing
208 if ( lnk ) { 225 QString name, filename, list;
209 QString entryName; 226 Om3u *m3uList;
210 entryName.sprintf( "File%i", noOfFiles + 1 ); 227 name = "default";
211 cfg.writeEntry( entryName, lnk->linkFile() ); 228
212 // if this link does exist, add it so we have the file 229 filename=QPEApplication::documentDir() + "/" + name+".m3u";
213 // next time... 230
214 if ( !QFile::exists( lnk->linkFile() ) ) { 231 m3uList = new Om3u(filename);
215 // the way writing lnks doesn't really check for out 232
216 // of disk space, but check it anyway. 233 d->selectedFiles->first();
217 if ( !lnk->writeLink() ) { 234 do {
218 QMessageBox::critical( 0, tr("Out of space"), 235 m3uList->add( d->selectedFiles->current()->file());
219 tr( "There was a problem saving "
220 "the playlist.\n"
221 "Your playlist "
222 "may be missing some entries\n"
223 "the next time you start it." )
224 );
225 }
226 }
227 noOfFiles++;
228 } 236 }
229 } 237 while ( d->selectedFiles->next() );
230 while ( d->selectedFiles->next() ); 238
231 cfg.writeEntry("NumberOfFiles", noOfFiles ); 239 qDebug( list );
240
241 m3uList->write();
242 m3uList->close();
243 if(m3uList) delete m3uList;
244
245 DocLnk lnk;
246 lnk.setFile( filename);
247 lnk.setIcon("opieplayer2/playlist2");
248 lnk.setName( name); //sets file name
249
250 qDebug("writing default playlist "+filename);
251
252 config.writeEntry("CurrentPlaylist", filename);
253// currentPlayList=filename;
254
255 if(!lnk.writeLink()) {
256 qDebug("Writing doclink did not work");
257 }
258
259// } else {
260
261// d->selectedFiles->writeCurrent( cfg );
262// int noOfFiles = 0;
263// d->selectedFiles->first();
264
265// do {
266// const DocLnk *lnk = d->selectedFiles->current();
267
268// if ( lnk ) {
269
270// QString entryName;
271// entryName.sprintf( "File%i", noOfFiles + 1 );
272
273// cfg.writeEntry( entryName, lnk->linkFile() );
274// // if this link does exist, add it so we have the file
275// // next time...
276
277// if ( !QFile::exists( lnk->linkFile() ) ) {
278// lnk->writeLink();
279// }
280// }
281// noOfFiles++;
282// }
283// while ( d->selectedFiles->next() );
284// cfg.writeEntry("NumberOfFiles", noOfFiles );
285// }
232} 286}
233 287
234 288
@@ -400,7 +454,7 @@ bool PlayListWidget::prev() {
400 454
401 455
402bool PlayListWidget::next() { 456bool PlayListWidget::next() {
403qDebug("<<<<<<<<<<<<next()"); 457//qDebug("<<<<<<<<<<<<next()");
404 if ( mediaPlayerState->playlist() ) { 458 if ( mediaPlayerState->playlist() ) {
405 if ( mediaPlayerState->shuffled() ) { 459 if ( mediaPlayerState->shuffled() ) {
406 return prev(); 460 return prev();
@@ -436,55 +490,73 @@ bool PlayListWidget::last() {
436} 490}
437 491
438 492
439void PlayListWidget::saveList() { 493 void PlayListWidget::saveList() {
494// Config config( "OpiePlayer" );
495// config.setGroup( "PlayList" );
496
497// if(config.readBoolEntry("newPlaylist") ){
498 writem3u();
499
500// } else {
501
502// QString filename;
503// InputDialog *fileDlg = 0l;
504// fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
505// fileDlg->exec();
506// if( fileDlg->result() == 1 ) {
507// if ( d->current )
508// delete d->current;
509// filename = fileDlg->text();//+".playlist";
510// // qDebug("saving playlist "+filename+".playlist");
511
512// Config cfg( filename +".playlist");
513// writeConfig( cfg );
514
515// DocLnk lnk;
516// lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf");
517// //sets File property
518// lnk.setType("playlist/plain");
519// lnk.setIcon("opieplayer2/playlist2");
520// lnk.setName( filename); //sets file name
521// // qDebug(filename);
522// if(!lnk.writeLink()) {
523// qDebug("Writing doclink did not work");
524// }
525// }
526
527// config.writeEntry("CurrentPlaylist",filename);
528// setCaption(tr("OpiePlayer: ")+filename);
529// d->selectedFiles->first();
530// if(fileDlg) {
531// delete fileDlg;
532// }
533// }
534 }
440 535
441 QString filename;
442 InputDialog *fileDlg = 0l;
443 fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
444 fileDlg->exec();
445 if( fileDlg->result() == 1 ) {
446 if ( d->current )
447 delete d->current;
448 filename = fileDlg->text();//+".playlist";
449 // qDebug("saving playlist "+filename+".playlist");
450 Config cfg( filename +".playlist");
451 writeConfig( cfg );
452
453 DocLnk lnk;
454 lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf");
455//sets File property
456 lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D
457 lnk.setIcon("opieplayer2/playlist2");
458 lnk.setName( filename); //sets file name
459 // qDebug(filename);
460 if(!lnk.writeLink()) {
461 qDebug("Writing doclink did not work");
462 }
463 }
464 Config config( "OpiePlayer" );
465 config.writeEntry("CurrentPlaylist",filename);
466 setCaption(tr("OpiePlayer: ")+filename);
467 d->selectedFiles->first();
468 if(fileDlg) {
469 delete fileDlg;
470 }
471}
472 536
473void PlayListWidget::loadList( const DocLnk & lnk) { 537void PlayListWidget::loadList( const DocLnk & lnk) {
474 QString name= lnk.name(); 538 QString name = lnk.name();
475// qDebug("currentList is "+name); 539 qDebug("currentList is "+name);
540
476 if( name.length()>0) { 541 if( name.length()>0) {
477 setCaption("OpiePlayer: "+name); 542 setCaption("OpiePlayer: "+name);
478 // qDebug("load list "+ name+".playlist"); 543 qDebug("<<<<<<<<<<<<load list "+ lnk.file());
479 clearList(); 544 clearList();
480 Config cfg( name+".playlist"); 545
481 readConfig(cfg); 546// if(name.right(3) == "m3u") {
547
548 readm3u(lnk.file());
549// } else {
550// / Config cfg( name+".playlist");
551// readConfig(cfg);
482 552
483 tabWidget->setCurrentPage(0); 553 tabWidget->setCurrentPage(0);
484 554
485 Config config( "OpiePlayer" ); 555 Config config( "OpiePlayer" );
486 config.writeEntry("CurrentPlaylist", name); 556 config.setGroup( "PlayList" );
487 // d->selectedFiles->first(); 557 config.writeEntry("CurrentPlaylist", lnk.file());
558// // d->selectedFiles->first();
559// }
488 } 560 }
489} 561}
490 562
@@ -580,7 +652,7 @@ void PlayListWidget::addToSelection( QListViewItem *it) {
580 QListIterator<DocLnk> dit( vFiles.children() ); 652 QListIterator<DocLnk> dit( vFiles.children() );
581 for ( ; dit.current(); ++dit ) { 653 for ( ; dit.current(); ++dit ) {
582 if( dit.current()->name() == it->text(0)) { 654 if( dit.current()->name() == it->text(0)) {
583 if(QFileInfo( dit.current()->file()).exists()) 655 if( QFileInfo( dit.current()->file()).exists() )
584 d->selectedFiles->addToSelection( **dit ); 656 d->selectedFiles->addToSelection( **dit );
585 } 657 }
586 } 658 }
@@ -644,34 +716,7 @@ void PlayListWidget::tabChanged(QWidget *) {
644void PlayListWidget::btnPlay(bool b) { 716void PlayListWidget::btnPlay(bool b) {
645// mediaPlayerState->setPlaying(false); 717// mediaPlayerState->setPlaying(false);
646 mediaPlayerState->setPlaying(b); 718 mediaPlayerState->setPlaying(b);
647// qApp->processEvents();
648 insanityBool=FALSE; 719 insanityBool=FALSE;
649// switch ( whichList()) {
650// case 0:
651// {
652// mediaPlayerState->setPlaying(b);
653// }
654// break;
655// case 1:
656// {
657// mediaPlayerState->setPlaying(b);
658// qApp->processEvents();
659// insanityBool=FALSE;
660// }// audioView->clearSelection();
661// break;
662// case 2:
663// {
664// // addToSelection( videoView->currentItem() );
665// mediaPlayerState->setPlaying(b);
666// qApp->processEvents();
667// // d->selectedFiles->removeSelected( );
668// // tabWidget->setCurrentPage(2);
669// // d->selectedFiles->unSelect();
670// insanityBool=FALSE;
671// }// videoView->clearSelection();
672// break;
673// };
674
675} 720}
676 721
677void PlayListWidget::deletePlaylist() { 722void PlayListWidget::deletePlaylist() {
@@ -701,7 +746,8 @@ void PlayListWidget::scanForAudio() {
701 for ( ; sdit.current(); ++sdit ) { 746 for ( ; sdit.current(); ++sdit ) {
702 delete sdit.current(); 747 delete sdit.current();
703 } 748 }
704 Global::findDocuments(&files, "audio/*"); 749// Global::findDocuments( &files, "audio/*");
750 Global::findDocuments( &files, "audio/mpeg;audio/x-wav;audio/x-ogg");
705 audioScan = TRUE; 751 audioScan = TRUE;
706} 752}
707 753
@@ -797,58 +843,43 @@ void PlayListWidget::openFile() {
797 843
798 qDebug( "Selected filename is " + filename ); 844 qDebug( "Selected filename is " + filename );
799 845
800 if(filename.left(4) == "http") { 846 if(filename.left(4) == "http") { //if http, lets write a new m3u
847 Om3u *m3uList;
801 DocLnk lnk; 848 DocLnk lnk;
802 QString m3uFile, m3uFilePath; 849 QString m3uFile, m3uFilePath;
803 if(filename.find(":",8,TRUE) != -1) { 850
804//found a port 851 if(filename.find(":",8,TRUE) != -1) { //found a port
805 m3uFile=filename.left(filename.find(":",8,TRUE)); 852 m3uFile = filename.left( filename.find( ":",8,TRUE));
806 853
807 m3uFile=m3uFile.right(m3uFile.length()-7); 854 m3uFile = m3uFile.right( 7);
808 qDebug(m3uFile);
809 m3uFilePath= QDir::homeDirPath()+"/"+m3uFile+".m3u";
810
811 QFile f(m3uFilePath );
812 f.open( IO_WriteOnly );
813 f.writeBlock( filename, filename.length() );
814 f.close();
815
816 lnk.setName( m3uFile ); //sets file name
817 lnk.setFile( m3uFilePath ); //sets File property
818 //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() );
819 lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() );
820 855
821 } else if(filename.left(4) == "http"){ 856 } else if(filename.left(4) == "http"){
822 857
823 m3uFile=m3uFile.right(m3uFile.length()-7); 858 m3uFile=filename;
824 qDebug(m3uFile); 859 m3uFile = m3uFile.right( m3uFile.length() - 7);
825
826 m3uFilePath= QDir::homeDirPath()+"/"+m3uFile+".m3u";
827 860
828 QFile f(m3uFilePath ); 861 } else{
829 f.open( IO_WriteOnly ); 862 m3uFile=filename;
830 f.writeBlock( filename, filename.length() ); 863 }
831 f.close();
832 864
833 lnk.setName( m3uFile ); //sets file name 865// qDebug( m3uFile);
834 lnk.setFile( m3uFilePath ); //sets File property
835 //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() );
836 lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() );
837 866
838 } else{ 867//this is where this new m3u is going to live at
868 m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u";
869// m3uFile += ".m3u";
870 m3uList = new Om3u( m3uFile+".m3u");
839 871
840 QFile f( filename ); 872 m3uList->add( filename);
841 f.open( IO_WriteOnly ); 873 m3uList->write();
842 f.writeBlock( filename, filename.length() ); 874 if(m3uList) delete m3uList;
843 f.close();
844 875
845 lnk.setName( filename ); //sets file name 876// qDebug( m3uFile);
846 lnk.setFile( filename ); //sets File property 877 lnk.setName( filename ); //sets file name
847 //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() ); 878 lnk.setFile( m3uFilePath ); //sets File property
848 lnk.setType( MimeType( QFile::encodeName(filename) ).id() ); 879 lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() );
849 } 880
850 lnk.setExec( "opieplayer" ); 881 lnk.setExec( "opieplayer2" );
851 lnk.setIcon( "opieplayer2/MPEGPlayer" ); 882 lnk.setIcon("opieplayer2/playlist2");
852 883
853 if( !lnk.writeLink() ) { 884 if( !lnk.writeLink() ) {
854 qDebug( "Writing doclink did not work" ); 885 qDebug( "Writing doclink did not work" );
@@ -858,6 +889,7 @@ void PlayListWidget::openFile() {
858 } 889 }
859 else if( filename.right( 3 ) == "m3u" ) { 890 else if( filename.right( 3 ) == "m3u" ) {
860 readm3u( filename ); 891 readm3u( filename );
892
861 } else if( filename.right(3) == "pls" ) { 893 } else if( filename.right(3) == "pls" ) {
862 readPls( filename ); 894 readPls( filename );
863 } 895 }
@@ -867,6 +899,146 @@ void PlayListWidget::openFile() {
867 } 899 }
868} 900}
869 901
902/*
903reads m3u and adds files/urls to playlist */
904void PlayListWidget::readm3u( const QString &filename ) {
905 qDebug( "read m3u filename " + filename );
906
907 Om3u *m3uList;
908 QString s, name;
909 m3uList = new Om3u( filename);
910 m3uList->readM3u();
911 DocLnk lnk;
912 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
913 s = *it;
914 s.replace( QRegExp( "%20" )," " );
915 qDebug("reading "+ s);
916
917 if( QFileInfo( s ).exists() ) {
918 lnk.setName( QFileInfo(s).baseName());
919 qDebug("set link "+s);
920 if(s.at(s.length()-4) == '.') //if regular file
921 lnk.setFile( s);
922 else
923 lnk.setFile( s+"/"); //if url with no extension
924
925 d->selectedFiles->addToSelection( lnk );
926 }
927 }
928 Config config( "OpiePlayer" );
929 config.setGroup( "PlayList" );
930
931 config.writeEntry("CurrentPlaylist",filename);
932 currentPlayList=filename;
933
934 m3uList->close();
935 if(m3uList) delete m3uList;
936
937 d->selectedFiles->setSelectedItem( s);
938 setCaption(tr("OpiePlayer: ")+ QFileInfo(s).baseName());
939
940}
941
942/*
943reads pls and adds files/urls to playlist */
944void PlayListWidget::readPls( const QString &filename ) {
945
946 qDebug( "pls filename is " + filename );
947 Om3u *m3uList;
948 QString s, name;
949 m3uList = new Om3u( filename);
950 m3uList->readPls();
951
952 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
953 s = *it;
954 s.replace( QRegExp( "%20" )," " );
955 DocLnk lnk( s );
956 QFileInfo f( s );
957 QString name = f.baseName();
958
959 if( name.left( 4 ) == "http" ) {
960 name = s.right( s.length() - 7);
961 } else {
962 name = s;
963 }
964
965 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
966
967 lnk.setName( name );
968 if( s.at( s.length() - 4) == '.') {// if this is probably a file
969 lnk.setFile( s );
970 } else { //if its a url
971 if( name.right( 1 ).find( '/' ) == -1) {
972 s += "/";
973 }
974 lnk.setFile( s );
975 }
976 lnk.setType( "audio/x-mpegurl" );
977
978 lnk.writeLink();
979 d->selectedFiles->addToSelection( lnk );
980 }
981
982 m3uList->close();
983 if(m3uList) delete m3uList;
984}
985
986/*
987 writes current playlist to m3u file */
988void PlayListWidget::writem3u() {
989 InputDialog *fileDlg;
990 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
991 fileDlg->exec();
992 QString name, filename, list;
993 Om3u *m3uList;
994
995 if( fileDlg->result() == 1 ) {
996 name = fileDlg->text();
997 qDebug( filename );
998
999 if( name.left( 1) != "/" ) {
1000 filename = QPEApplication::documentDir() + "/" + name;
1001 }
1002
1003 if( name.right( 3 ) != "m3u" ) {
1004 filename = QPEApplication::documentDir() + "/" +name+".m3u";
1005 }
1006
1007 m3uList = new Om3u(filename);
1008
1009 d->selectedFiles->first();
1010
1011 do {
1012 m3uList->add( d->selectedFiles->current()->file());
1013 }
1014 while ( d->selectedFiles->next() );
1015// qDebug( list );
1016
1017 m3uList->write();
1018 m3uList->close();
1019 }
1020 if(m3uList) delete m3uList;
1021 if(fileDlg) delete fileDlg;
1022
1023 DocLnk lnk;
1024 lnk.setFile( filename);
1025 lnk.setIcon("opieplayer2/playlist2");
1026 lnk.setName( name); //sets file name
1027
1028// qDebug(filename);
1029 Config config( "OpiePlayer" );
1030 config.setGroup( "PlayList" );
1031
1032 config.writeEntry("CurrentPlaylist",filename);
1033 currentPlayList=filename;
1034
1035 if(!lnk.writeLink()) {
1036 qDebug("Writing doclink did not work");
1037 }
1038
1039 setCaption(tr("OpiePlayer: ") + name);
1040}
1041
870void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 1042void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
871 switch ( e->key() ) { 1043 switch ( e->key() ) {
872 ////////////////////////////// Zaurus keys 1044 ////////////////////////////// Zaurus keys
@@ -914,158 +1086,14 @@ void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
914 case Key_Down: 1086 case Key_Down:
915 if ( !d->selectedFiles->next() ) 1087 if ( !d->selectedFiles->next() )
916 d->selectedFiles->first(); 1088 d->selectedFiles->first();
917
918 break; 1089 break;
919 case Key_Up: 1090 case Key_Up:
920 if ( !d->selectedFiles->prev() ) 1091 if ( !d->selectedFiles->prev() )
921 // d->selectedFiles->last(); 1092 // d->selectedFiles->last();
922
923 break; 1093 break;
924
925 } 1094 }
926} 1095}
927 1096
928void PlayListWidget::readm3u( const QString &filename ) {
929 qDebug( "m3u filename is " + filename );
930 QFile f( filename );
931
932 if( f.open( IO_ReadOnly ) ) {
933 QTextStream t(&f);
934 QString s;//, first, second;
935 int i=0;
936 while ( !t.atEnd() ) {
937 s=t.readLine();
938
939 if( s.find( "#", 0, TRUE) == -1 ) {
940 if( s.find( " ", 0, TRUE) == -1 ) {
941// not sure if this is neede since cf uses vfat
942 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
943 s = s.right( s.length() -2 );
944 DocLnk lnk( s );
945 QFileInfo f( s );
946 QString name = f.baseName();
947 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
948 lnk.setName( name );
949 s=s.replace( QRegExp( "\\" ), "/" );
950 lnk.setFile( s );
951 lnk.writeLink();
952 qDebug( "add " + name);
953 d->selectedFiles->addToSelection( lnk );
954 } else { // is url
955 s.replace( QRegExp( "%20" )," " );
956 DocLnk lnk( s );
957 QString name;
958 if( name.left( 4 ) == "http" ) {
959 name = s.right( s.length() - 7 );
960 } else {
961 name = s;
962 }
963 lnk.setName( name );
964 if( s.at( s.length() - 4) == '.' ) {
965 lnk.setFile( s );
966 } else {
967 lnk.setFile( s + "/" );
968 }
969 lnk.setType( "audio/x-mpegurl" );
970 lnk.writeLink();
971 d->selectedFiles->addToSelection( lnk );
972 }
973 i++;
974 }
975 }
976 }
977 }
978 f.close();
979}
980
981void PlayListWidget::writem3u() {
982 InputDialog *fileDlg;
983 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
984 fileDlg->exec();
985 QString filename, list;
986 if( fileDlg->result() == 1 ) {
987 filename = fileDlg->text();
988 qDebug( filename );
989 int noOfFiles = 0;
990 d->selectedFiles->first();
991 do {
992 // we dont check for existance because of url's
993 // qDebug(d->selectedFiles->current()->file());
994
995 // so maybe we should do some net checking to ,-)
996 // no, cause it takes to long...
997
998 list += d->selectedFiles->current()->file() + "\n";
999 noOfFiles++;
1000 }
1001 while ( d->selectedFiles->next() );
1002 qDebug( list );
1003 if( filename.left( 1) != "/" ) {
1004 filename=QPEApplication::documentDir() + "/" + filename;
1005 }
1006 if( filename.right( 3 ) != "m3u" ) {
1007 filename=filename+".m3u";
1008 }
1009 QFile f( filename );
1010 f.open( IO_WriteOnly );
1011 f.writeBlock( list, list.length() );
1012 f.close();
1013 }
1014 if( fileDlg ) {
1015 delete fileDlg;
1016 }
1017}
1018
1019void PlayListWidget::readPls( const QString &filename ) {
1020
1021 qDebug( "pls filename is " + filename );
1022 QFile f( filename );
1023
1024 if( f.open( IO_ReadOnly ) ) {
1025 QTextStream t( &f );
1026 QString s;//, first, second;
1027 int i = 0;
1028 while ( !t.atEnd() ) {
1029 s = t.readLine();
1030 if( s.left(4) == "File" ) {
1031 s = s.right( s.length() - 6 );
1032 s.replace( QRegExp( "%20" )," ");
1033 qDebug( "adding " + s + " to playlist" );
1034 // numberofentries=2
1035 // File1=http
1036 // Title
1037 // Length
1038 // Version
1039 // File2=http
1040 s = s.replace( QRegExp( "\\" ), "/" );
1041 DocLnk lnk( s );
1042 QFileInfo f( s );
1043 QString name = f.baseName();
1044 if( name.left( 4 ) == "http" ) {
1045 name = s.right( s.length() - 7);
1046 } else {
1047 name = s;
1048 }
1049 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
1050 lnk.setName( name );
1051 if( s.at( s.length() - 4) == '.') // if this is probably a file
1052 lnk.setFile( s );
1053 else { //if its a url
1054 if( name.right( 1 ).find( '/' ) == -1) {
1055 s += "/";
1056 }
1057 lnk.setFile( s );
1058 }
1059 lnk.setType( "audio/x-mpegurl" );
1060
1061 //qDebug("DocLnk add "+name);
1062 d->selectedFiles->addToSelection( lnk );
1063 }
1064 }
1065 i++;
1066 }
1067}
1068
1069void PlayListWidget::pmViewActivated(int index) { 1097void PlayListWidget::pmViewActivated(int index) {
1070// qDebug("%d", index); 1098// qDebug("%d", index);
1071 switch(index) { 1099 switch(index) {
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h
index 2873dca..428821a 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.h
+++ b/noncore/multimedia/opieplayer2/playlistwidget.h
@@ -61,7 +61,7 @@ public:
61 DocLnkSet vFiles; 61 DocLnkSet vFiles;
62 bool fromSetDocument; 62 bool fromSetDocument;
63 bool insanityBool; 63 bool insanityBool;
64 QString setDocFileRef; 64 QString setDocFileRef, currentPlayList;
65 // retrieve the current playlist entry (media file link) 65 // retrieve the current playlist entry (media file link)
66 const DocLnk *current(); 66 const DocLnk *current();
67 void useSelectedDocument(); 67 void useSelectedDocument();