author | llornkcor <llornkcor> | 2002-10-06 21:57:48 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-10-06 21:57:48 (UTC) |
commit | a60fbe6f441b906489984b0dbc239259adacdcbc (patch) (unidiff) | |
tree | 84c47ae8e87c7d100fdd954a28256e0e8d5bd044 | |
parent | 2623a1e2fddf0bfb91191ea7224f016032336ed5 (diff) | |
download | opie-a60fbe6f441b906489984b0dbc239259adacdcbc.zip opie-a60fbe6f441b906489984b0dbc239259adacdcbc.tar.gz opie-a60fbe6f441b906489984b0dbc239259adacdcbc.tar.bz2 |
use m3u now. probably buggy still
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.cpp | 157 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.h | 79 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/opieplayer2.pro | 4 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 580 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.h | 2 |
5 files changed, 543 insertions, 279 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 | |||
51 | Om3u::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 | |||
62 | Om3u::~Om3u(){} | ||
63 | |||
64 | void 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 | |||
97 | void 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 | |||
133 | void 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 | |||
143 | void Om3u::add(const QString &filePath) { //adds to m3u file | ||
144 | append(filePath); | ||
145 | } | ||
146 | |||
147 | void Om3u::remove(const QString &filePath) { //removes from m3u list | ||
148 | |||
149 | } | ||
150 | |||
151 | void Om3u::deleteFile(const QString &filePath) {//deletes m3u file | ||
152 | |||
153 | } | ||
154 | |||
155 | void 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 | |||
53 | class Om3u : public QStringList { | ||
54 | // Q_OBJECT | ||
55 | public: | ||
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 | |||
66 | public slots: | ||
67 | |||
68 | protected: | ||
69 | |||
70 | private: | ||
71 | QFile f; | ||
72 | private 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 | |||
@@ -5,3 +5,3 @@ DESTDIR = $(OPIEDIR)/bin | |||
5 | HEADERS = playlistselection.h mediaplayerstate.h xinecontrol.h \ | 5 | HEADERS = 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\ |
@@ -10,3 +10,3 @@ SOURCES = 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 \ |
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 | |||
@@ -49,2 +49,3 @@ | |||
49 | #include "inputDialog.h" | 49 | #include "inputDialog.h" |
50 | #include "om3u.h" | ||
50 | 51 | ||
@@ -83,5 +84,5 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | |||
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() ) ); |
@@ -149,3 +150,4 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | |||
149 | 150 | ||
150 | readConfig( cfg ); | 151 | // cfg.setGroup( "PlayList" ); |
152 | // if( cfg.readBoolEntry("newPlaylist") ){ | ||
151 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); | 153 | QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" ); |
@@ -153,3 +155,6 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | |||
153 | setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); | 155 | setCaption( tr( "OpiePlayer: " ) + currentPlaylist ); |
156 | // } else { | ||
157 | // readConfig( cfg ); | ||
154 | 158 | ||
159 | // } | ||
155 | // see which skins are installed | 160 | // see which skins are installed |
@@ -181,2 +186,3 @@ void PlayListWidget::initializeStates() { | |||
181 | void PlayListWidget::readConfig( Config& cfg ) { | 186 | void PlayListWidget::readConfig( Config& cfg ) { |
187 | |||
182 | cfg.setGroup( "PlayList" ); | 188 | cfg.setGroup( "PlayList" ); |
@@ -184,2 +190,3 @@ void PlayListWidget::readConfig( Config& cfg ) { | |||
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++ ) { |
@@ -187,8 +194,17 @@ void PlayListWidget::readConfig( Config& cfg ) { | |||
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 | } |
@@ -197,2 +213,3 @@ void PlayListWidget::readConfig( Config& cfg ) { | |||
197 | d->selectedFiles->setSelectedItem( currentString ); | 213 | d->selectedFiles->setSelectedItem( currentString ); |
214 | |||
198 | } | 215 | } |
@@ -201,32 +218,69 @@ void PlayListWidget::readConfig( Config& cfg ) { | |||
201 | void PlayListWidget::writeConfig( Config& cfg ) const { | 218 | void 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" ); |
222 | |||
223 | // if(config.readBoolEntry("newPlaylist")) { | ||
224 | // new for testing | ||
225 | QString name, filename, list; | ||
226 | Om3u *m3uList; | ||
227 | name = "default"; | ||
228 | |||
229 | filename=QPEApplication::documentDir() + "/" + name+".m3u"; | ||
230 | |||
231 | m3uList = new Om3u(filename); | ||
232 | |||
205 | d->selectedFiles->first(); | 233 | d->selectedFiles->first(); |
206 | do { | 234 | do { |
207 | const DocLnk *lnk = d->selectedFiles->current(); | 235 | m3uList->add( d->selectedFiles->current()->file()); |
208 | if ( lnk ) { | ||
209 | QString entryName; | ||
210 | entryName.sprintf( "File%i", noOfFiles + 1 ); | ||
211 | cfg.writeEntry( entryName, lnk->linkFile() ); | ||
212 | // if this link does exist, add it so we have the file | ||
213 | // next time... | ||
214 | if ( !QFile::exists( lnk->linkFile() ) ) { | ||
215 | // the way writing lnks doesn't really check for out | ||
216 | // of disk space, but check it anyway. | ||
217 | if ( !lnk->writeLink() ) { | ||
218 | QMessageBox::critical( 0, tr("Out of space"), | ||
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 | } | ||
229 | } | 236 | } |
230 | while ( d->selectedFiles->next() ); | 237 | while ( d->selectedFiles->next() ); |
231 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 238 | |
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 | } |
@@ -402,3 +456,3 @@ bool PlayListWidget::prev() { | |||
402 | bool PlayListWidget::next() { | 456 | bool PlayListWidget::next() { |
403 | qDebug("<<<<<<<<<<<<next()"); | 457 | //qDebug("<<<<<<<<<<<<next()"); |
404 | if ( mediaPlayerState->playlist() ) { | 458 | if ( mediaPlayerState->playlist() ) { |
@@ -439,44 +493,60 @@ bool PlayListWidget::last() { | |||
439 | void 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 | // } | ||
440 | 526 | ||
441 | QString filename; | 527 | // config.writeEntry("CurrentPlaylist",filename); |
442 | InputDialog *fileDlg = 0l; | 528 | // setCaption(tr("OpiePlayer: ")+filename); |
443 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); | 529 | // d->selectedFiles->first(); |
444 | fileDlg->exec(); | 530 | // if(fileDlg) { |
445 | if( fileDlg->result() == 1 ) { | 531 | // delete fileDlg; |
446 | if ( d->current ) | 532 | // } |
447 | delete d->current; | 533 | // } |
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 | } | 534 | } |
472 | 535 | ||
536 | |||
473 | void PlayListWidget::loadList( const DocLnk & lnk) { | 537 | void 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 | ||
@@ -485,4 +555,6 @@ void PlayListWidget::loadList( const DocLnk & lnk) { | |||
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 | } |
@@ -646,30 +718,3 @@ void PlayListWidget::btnPlay(bool b) { | |||
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 | } |
@@ -703,3 +748,4 @@ void PlayListWidget::scanForAudio() { | |||
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; |
@@ -799,22 +845,11 @@ void PlayListWidget::openFile() { | |||
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) { | ||
804 | //found a port | ||
805 | m3uFile=filename.left(filename.find(":",8,TRUE)); | ||
806 | |||
807 | m3uFile=m3uFile.right(m3uFile.length()-7); | ||
808 | qDebug(m3uFile); | ||
809 | m3uFilePath= QDir::homeDirPath()+"/"+m3uFile+".m3u"; | ||
810 | 850 | ||
811 | QFile f(m3uFilePath ); | 851 | if(filename.find(":",8,TRUE) != -1) { //found a port |
812 | f.open( IO_WriteOnly ); | 852 | m3uFile = filename.left( filename.find( ":",8,TRUE)); |
813 | f.writeBlock( filename, filename.length() ); | ||
814 | f.close(); | ||
815 | 853 | ||
816 | lnk.setName( m3uFile ); //sets file name | 854 | m3uFile = m3uFile.right( 7); |
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 | ||
@@ -822,31 +857,27 @@ void PlayListWidget::openFile() { | |||
822 | 857 | ||
858 | m3uFile=filename; | ||
823 | m3uFile=m3uFile.right(m3uFile.length()-7); | 859 | m3uFile=m3uFile.right(m3uFile.length()-7); |
824 | qDebug(m3uFile); | ||
825 | 860 | ||
861 | } else{ | ||
862 | m3uFile=filename; | ||
863 | } | ||
864 | |||
865 | // qDebug( m3uFile); | ||
866 | |||
867 | //this is where this new m3u is going to live at | ||
826 | m3uFilePath= QDir::homeDirPath()+"/"+m3uFile+".m3u"; | 868 | m3uFilePath= QDir::homeDirPath()+"/"+m3uFile+".m3u"; |
869 | // m3uFile += ".m3u"; | ||
870 | m3uList = new Om3u( m3uFile+".m3u"); | ||
827 | 871 | ||
828 | QFile f(m3uFilePath ); | 872 | m3uList->add( filename); |
829 | f.open( IO_WriteOnly ); | 873 | m3uList->write(); |
830 | f.writeBlock( filename, filename.length() ); | 874 | if(m3uList) delete m3uList; |
831 | f.close(); | ||
832 | 875 | ||
833 | lnk.setName( m3uFile ); //sets file name | 876 | // qDebug( m3uFile); |
877 | lnk.setName( filename ); //sets file name | ||
834 | lnk.setFile( m3uFilePath ); //sets File property | 878 | lnk.setFile( m3uFilePath ); //sets File property |
835 | //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() ); | ||
836 | lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() ); | 879 | lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() ); |
837 | 880 | ||
838 | } else{ | 881 | lnk.setExec( "opieplayer2" ); |
839 | 882 | lnk.setIcon("opieplayer2/playlist2"); | |
840 | QFile f( filename ); | ||
841 | f.open( IO_WriteOnly ); | ||
842 | f.writeBlock( filename, filename.length() ); | ||
843 | f.close(); | ||
844 | |||
845 | lnk.setName( filename ); //sets file name | ||
846 | lnk.setFile( filename ); //sets File property | ||
847 | //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() ); | ||
848 | lnk.setType( MimeType( QFile::encodeName(filename) ).id() ); | ||
849 | } | ||
850 | lnk.setExec( "opieplayer" ); | ||
851 | lnk.setIcon( "opieplayer2/MPEGPlayer" ); | ||
852 | 883 | ||
@@ -860,2 +891,3 @@ void PlayListWidget::openFile() { | |||
860 | readm3u( filename ); | 891 | readm3u( filename ); |
892 | |||
861 | } else if( filename.right(3) == "pls" ) { | 893 | } else if( filename.right(3) == "pls" ) { |
@@ -869,2 +901,142 @@ void PlayListWidget::openFile() { | |||
869 | 901 | ||
902 | /* | ||
903 | reads m3u and adds files/urls to playlist */ | ||
904 | void 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 | /* | ||
943 | reads pls and adds files/urls to playlist */ | ||
944 | void 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 */ | ||
988 | void 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 | |||
870 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { | 1042 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { |
@@ -916,3 +1088,2 @@ void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { | |||
916 | d->selectedFiles->first(); | 1088 | d->selectedFiles->first(); |
917 | |||
918 | break; | 1089 | break; |
@@ -921,146 +1092,3 @@ void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { | |||
921 | // d->selectedFiles->last(); | 1092 | // d->selectedFiles->last(); |
922 | |||
923 | break; | 1093 | break; |
924 | |||
925 | } | ||
926 | } | ||
927 | |||
928 | void 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 | |||
981 | void 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 | |||
1019 | void 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 | } | 1094 | } |
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 | |||
@@ -63,3 +63,3 @@ public: | |||
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) |