Diffstat (limited to 'noncore/multimedia/opieplayer2/om3u.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/om3u.cpp | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp index 790fa09..f2a01d3 100644 --- a/noncore/multimedia/opieplayer2/om3u.cpp +++ b/noncore/multimedia/opieplayer2/om3u.cpp | |||
@@ -1,152 +1,145 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> | 4 | Copyright (c) 2002 L. Potter <ljp@llornkcor.com> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; General Public License for more | 20 | ..}^=.= = ; General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = General Public License along with | 24 | -_. . . )=. = General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | 29 | ||
30 | */ | 30 | */ |
31 | 31 | ||
32 | #include "om3u.h" | 32 | #include "om3u.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | 36 | using namespace Opie::Core; |
37 | 37 | ||
38 | //extern PlayListWidget *playList; | 38 | //extern PlayListWidget *playList; |
39 | 39 | ||
40 | Om3u::Om3u( const QString &filePath, int mode) | 40 | Om3u::Om3u( const QString &filePath, int mode) |
41 | : QStringList (){ | 41 | : QStringList () |
42 | { | ||
42 | odebug << "<<<<<<<new m3u "+filePath << oendl; | 43 | odebug << "<<<<<<<new m3u "+filePath << oendl; |
43 | f.setName(filePath); | 44 | f.setName(filePath); |
44 | f.open(mode); | 45 | if (!f.open(mode)) { |
46 | owarn << "Unable to open file " << f.name() << oendl; | ||
47 | } | ||
45 | } | 48 | } |
46 | 49 | ||
47 | Om3u::~Om3u(){} | 50 | Om3u::~Om3u(){} |
48 | 51 | ||
49 | void Om3u::readM3u() { | 52 | void Om3u::readM3u() { |
50 | // odebug << "<<<<<<reading m3u "+f.name() << oendl; | 53 | // odebug << "<<<<<<reading m3u "+f.name() << oendl; |
51 | QTextStream t(&f); | 54 | QTextStream t(&f); |
52 | t.setEncoding(QTextStream::UnicodeUTF8); | 55 | t.setEncoding(QTextStream::UnicodeUTF8); |
53 | QString s; | 56 | QString s; |
54 | while ( !t.atEnd() ) { | 57 | while ( !t.atEnd() ) { |
55 | s=t.readLine(); | 58 | s=t.readLine(); |
56 | // odebug << s << oendl; | 59 | // odebug << s << oendl; |
57 | if( s.find( "#", 0, TRUE) == -1 ) { | 60 | if( s.find( "#", 0, TRUE) == -1 ) { |
58 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { | 61 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { |
59 | s = s.right( s.length() -2 ); | 62 | s = s.right( s.length() -2 ); |
60 | QFileInfo f( s ); | 63 | QFileInfo f( s ); |
61 | QString name = f.baseName(); | 64 | QString name = f.baseName(); |
62 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); | 65 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); |
63 | s=s.replace( QRegExp( "\\" ), "/" ); | 66 | s=s.replace( QRegExp( "\\" ), "/" ); |
64 | append(s); | 67 | append(s); |
65 | // odebug << s << oendl; | 68 | // odebug << s << oendl; |
66 | } else { // is url | 69 | } else { // is url |
67 | QString name; | 70 | QString name; |
68 | name = s; | 71 | name = s; |
69 | append(name); | 72 | append(name); |
70 | } | 73 | } |
71 | } | 74 | } |
72 | } | 75 | } |
73 | } | 76 | } |
74 | 77 | ||
75 | void Om3u::readPls() { //it's a pls file | 78 | void Om3u::readPls() { //it's a pls file |
76 | QTextStream t( &f ); | 79 | QTextStream t( &f ); |
77 | t.setEncoding(QTextStream::UnicodeUTF8); | 80 | t.setEncoding(QTextStream::UnicodeUTF8); |
78 | QString s; | 81 | QString s; |
79 | while ( !t.atEnd() ) { | 82 | while ( !t.atEnd() ) { |
80 | s = t.readLine(); | 83 | s = t.readLine(); |
81 | if( s.left(4) == "File" ) { | 84 | if( s.left(4) == "File" ) { |
82 | s = s.right( s.length() - s.find("=",0,true)-1 ); | 85 | s = s.right( s.length() - s.find("=",0,true)-1 ); |
83 | s = s.stripWhiteSpace(); | 86 | s = s.stripWhiteSpace(); |
84 | s.replace( QRegExp( "%20" )," "); | 87 | s.replace( QRegExp( "%20" )," "); |
85 | // odebug << "adding " + s + " to playlist" << oendl; | 88 | // odebug << "adding " + s + " to playlist" << oendl; |
86 | // numberofentries=2 | ||
87 | // File1=http | ||
88 | // Title | ||
89 | // Length | ||
90 | // Version | ||
91 | // File2=http | ||
92 | s = s.replace( QRegExp( "\\" ), "/" ); | 89 | s = s.replace( QRegExp( "\\" ), "/" ); |
93 | QFileInfo f( s ); | 90 | QFileInfo f( s ); |
94 | QString name = f.baseName(); | 91 | QString name = f.baseName(); |
95 | if( name.left( 4 ) == "http" ) { | 92 | if( name.left( 4 ) == "http" ) { |
96 | name = s.right( s.length() - 7); | 93 | name = s.right( s.length() - 7); |
97 | } else { | 94 | } else { |
98 | name = s; | 95 | name = s; |
99 | } | 96 | } |
100 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 97 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
101 | if( s.at( s.length() - 4) == '.') // if this is probably a file | 98 | if( s.at( s.length() - 4) == '.') // if this is probably a file |
102 | append(s); | 99 | append(s); |
103 | else { //if its a url | 100 | else { //if its a url |
104 | // if( name.right( 1 ).find( '/' ) == -1) { | ||
105 | // s += "/"; | ||
106 | // } | ||
107 | append(s); | 101 | append(s); |
108 | } | 102 | } |
109 | } | 103 | } |
110 | } | 104 | } |
111 | } | 105 | } |
112 | 106 | ||
113 | void Om3u::write() { //writes list to m3u file | 107 | void Om3u::write() { //writes list to m3u file |
114 | QString list; | 108 | QString list; |
115 | QTextStream t(&f); | 109 | QTextStream t(&f); |
116 | t.setEncoding(QTextStream::UnicodeUTF8); | 110 | t.setEncoding(QTextStream::UnicodeUTF8); |
117 | if(count()>0) { | 111 | if(count()>0) { |
118 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 112 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
119 | // odebug << *it << oendl; | 113 | // odebug << *it << oendl; |
120 | t << *it << "\n"; | 114 | t << *it << "\n"; |
121 | } | 115 | } |
122 | } | 116 | } |
123 | // f.close(); | ||
124 | } | 117 | } |
125 | 118 | ||
126 | void Om3u::add(const QString &filePath) { //adds to m3u file | 119 | void Om3u::add(const QString &filePath) { //adds to m3u file |
127 | append(filePath); | 120 | append(filePath); |
128 | } | 121 | } |
129 | 122 | ||
130 | void Om3u::remove(const QString &filePath) { //removes from m3u list | 123 | void Om3u::remove(const QString &filePath) { //removes from m3u list |
131 | QString list, currentFile; | 124 | QString list, currentFile; |
132 | if(count()>0) { | 125 | if(count()>0) { |
133 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 126 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
134 | currentFile=*it; | 127 | currentFile=*it; |
135 | // odebug << *it << oendl; | 128 | // odebug << *it << oendl; |
136 | 129 | ||
137 | if( filePath != currentFile) | 130 | if( filePath != currentFile) |
138 | list += currentFile+"\n"; | 131 | list += currentFile+"\n"; |
139 | } | 132 | } |
140 | f.writeBlock( list, list.length() ); | 133 | f.writeBlock( list, list.length() ); |
141 | } | 134 | } |
142 | } | 135 | } |
143 | 136 | ||
144 | void Om3u::deleteFile(const QString &/*filePath*/) {//deletes m3u file | 137 | void Om3u::deleteFile(const QString &/*filePath*/) {//deletes m3u file |
145 | f.close(); | 138 | f.close(); |
146 | f.remove(); | 139 | f.remove(); |
147 | 140 | ||
148 | } | 141 | } |
149 | 142 | ||
150 | void Om3u::close() { //closes m3u file | 143 | void Om3u::close() { //closes m3u file |
151 | f.close(); | 144 | f.close(); |
152 | } | 145 | } |