Diffstat (limited to 'noncore/multimedia/opieplayer2/om3u.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.cpp | 157 |
1 files changed, 157 insertions, 0 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 | } | ||