-rw-r--r-- | core/multimedia/opieplayer/om3u.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/om3u.cpp b/core/multimedia/opieplayer/om3u.cpp index 8b92a8c..778eb22 100644 --- a/core/multimedia/opieplayer/om3u.cpp +++ b/core/multimedia/opieplayer/om3u.cpp | |||
@@ -46,120 +46,123 @@ | |||
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qcstring.h> | 47 | #include <qcstring.h> |
48 | 48 | ||
49 | static inline QString fullBaseName ( const QFileInfo &fi ) | 49 | static inline QString fullBaseName ( const QFileInfo &fi ) |
50 | { | 50 | { |
51 | QString str = fi. fileName ( ); | 51 | QString str = fi. fileName ( ); |
52 | return str. left ( str. findRev ( '.' )); | 52 | return str. left ( str. findRev ( '.' )); |
53 | } | 53 | } |
54 | 54 | ||
55 | 55 | ||
56 | //extern PlayListWidget *playList; | 56 | //extern PlayListWidget *playList; |
57 | 57 | ||
58 | Om3u::Om3u( const QString &filePath, int mode) | 58 | Om3u::Om3u( const QString &filePath, int mode) |
59 | : QStringList (){ | 59 | : QStringList (){ |
60 | //qDebug("<<<<<<<new m3u "+filePath); | 60 | //qDebug("<<<<<<<new m3u "+filePath); |
61 | f.setName(filePath); | 61 | f.setName(filePath); |
62 | f.open(mode); | 62 | f.open(mode); |
63 | } | 63 | } |
64 | 64 | ||
65 | Om3u::~Om3u(){} | 65 | Om3u::~Om3u(){} |
66 | 66 | ||
67 | void Om3u::readM3u() { | 67 | void Om3u::readM3u() { |
68 | // qDebug("<<<<<<reading m3u "+f.name()); | 68 | // qDebug("<<<<<<reading m3u "+f.name()); |
69 | QTextStream t(&f); | 69 | QTextStream t(&f); |
70 | t.setEncoding(QTextStream::UnicodeUTF8); | ||
70 | QString s; | 71 | QString s; |
71 | while ( !t.atEnd() ) { | 72 | while ( !t.atEnd() ) { |
72 | s=t.readLine(); | 73 | s=t.readLine(); |
73 | // qDebug(s); | 74 | // qDebug(s); |
74 | if( s.find( "#", 0, TRUE) == -1 ) { | 75 | if( s.find( "#", 0, TRUE) == -1 ) { |
75 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { | 76 | if( s.left(2) == "E:" || s.left(2) == "P:" ) { |
76 | s = s.right( s.length() -2 ); | 77 | s = s.right( s.length() -2 ); |
77 | QFileInfo f( s ); | 78 | QFileInfo f( s ); |
78 | QString name = fullBaseName ( f ); | 79 | QString name = fullBaseName ( f ); |
79 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); | 80 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); |
80 | s=s.replace( QRegExp( "\\" ), "/" ); | 81 | s=s.replace( QRegExp( "\\" ), "/" ); |
81 | append(s); | 82 | append(s); |
82 | // qDebug(s); | 83 | // qDebug(s); |
83 | } else { // is url | 84 | } else { // is url |
84 | s.replace( QRegExp( "%20" )," " ); | 85 | s.replace( QRegExp( "%20" )," " ); |
85 | QString name; | 86 | QString name; |
86 | // if( name.left( 4 ) == "http" ) { | 87 | // if( name.left( 4 ) == "http" ) { |
87 | // name = s.right( s.length() - 7 ); | 88 | // name = s.right( s.length() - 7 ); |
88 | // } else { | 89 | // } else { |
89 | name = s; | 90 | name = s; |
90 | // } | 91 | // } |
91 | append(name); | 92 | append(name); |
92 | // qDebug(name); | 93 | // qDebug(name); |
93 | } | 94 | } |
94 | } | 95 | } |
95 | } | 96 | } |
96 | } | 97 | } |
97 | 98 | ||
98 | void Om3u::readPls() { //it's a pls file | 99 | void Om3u::readPls() { //it's a pls file |
99 | QTextStream t( &f ); | 100 | QTextStream t( &f ); |
101 | t.setEncoding(QTextStream::UnicodeUTF8); | ||
100 | QString s; | 102 | QString s; |
101 | while ( !t.atEnd() ) { | 103 | while ( !t.atEnd() ) { |
102 | s = t.readLine(); | 104 | s = t.readLine(); |
103 | if( s.left(4) == "File" ) { | 105 | if( s.left(4) == "File" ) { |
104 | s = s.right( s.length() - 6 ); | 106 | s = s.right( s.length() - 6 ); |
105 | s.replace( QRegExp( "%20" )," "); | 107 | s.replace( QRegExp( "%20" )," "); |
106 | // qDebug( "adding " + s + " to playlist" ); | 108 | // qDebug( "adding " + s + " to playlist" ); |
107 | // numberofentries=2 | 109 | // numberofentries=2 |
108 | // File1=http | 110 | // File1=http |
109 | // Title | 111 | // Title |
110 | // Length | 112 | // Length |
111 | // Version | 113 | // Version |
112 | // File2=http | 114 | // File2=http |
113 | s = s.replace( QRegExp( "\\" ), "/" ); | 115 | s = s.replace( QRegExp( "\\" ), "/" ); |
114 | QFileInfo f( s ); | 116 | QFileInfo f( s ); |
115 | QString name = fullBaseName ( f ); | 117 | QString name = fullBaseName ( f ); |
116 | if( name.left( 4 ) == "http" ) { | 118 | if( name.left( 4 ) == "http" ) { |
117 | name = s.right( s.length() - 7); | 119 | name = s.right( s.length() - 7); |
118 | } else { | 120 | } else { |
119 | name = s; | 121 | name = s; |
120 | } | 122 | } |
121 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 123 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
122 | if( s.at( s.length() - 4) == '.') // if this is probably a file | 124 | if( s.at( s.length() - 4) == '.') // if this is probably a file |
123 | append(s); | 125 | append(s); |
124 | else { //if its a url | 126 | else { //if its a url |
125 | if( name.right( 1 ).find( '/' ) == -1) { | 127 | if( name.right( 1 ).find( '/' ) == -1) { |
126 | s += "/"; | 128 | s += "/"; |
127 | } | 129 | } |
128 | append(s); | 130 | append(s); |
129 | } | 131 | } |
130 | } | 132 | } |
131 | } | 133 | } |
132 | } | 134 | } |
133 | 135 | ||
134 | void Om3u::write() { //writes list to m3u file | 136 | void Om3u::write() { //writes list to m3u file |
135 | QString list; | 137 | QString list; |
138 | QTextStream t(&f); | ||
139 | t.setEncoding(QTextStream::UnicodeUTF8); | ||
136 | if(count()>0) { | 140 | if(count()>0) { |
137 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 141 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
138 | // qDebug(*it); | 142 | // qDebug(*it); |
139 | list += *it+"\n"; | 143 | t << *it << "\n"; |
140 | } | 144 | } |
141 | f.writeBlock( list, list.length() ); | ||
142 | } | 145 | } |
143 | // f.close(); | 146 | // f.close(); |
144 | } | 147 | } |
145 | 148 | ||
146 | void Om3u::add(const QString &filePath) { //adds to m3u file | 149 | void Om3u::add(const QString &filePath) { //adds to m3u file |
147 | append(filePath); | 150 | append(filePath); |
148 | } | 151 | } |
149 | 152 | ||
150 | void Om3u::remove(const QString &filePath) { //removes from m3u list | 153 | void Om3u::remove(const QString &filePath) { //removes from m3u list |
151 | QString list, currentFile; | 154 | QString list, currentFile; |
152 | if(count()>0) { | 155 | if(count()>0) { |
153 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { | 156 | for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { |
154 | currentFile=*it; | 157 | currentFile=*it; |
155 | // qDebug(*it); | 158 | // qDebug(*it); |
156 | 159 | ||
157 | if( filePath != currentFile) | 160 | if( filePath != currentFile) |
158 | list += currentFile+"\n"; | 161 | list += currentFile+"\n"; |
159 | } | 162 | } |
160 | f.writeBlock( list, list.length() ); | 163 | f.writeBlock( list, list.length() ); |
161 | } | 164 | } |
162 | } | 165 | } |
163 | 166 | ||
164 | void Om3u::deleteFile(const QString &filePath) {//deletes m3u file | 167 | void Om3u::deleteFile(const QString &filePath) {//deletes m3u file |
165 | f.close(); | 168 | f.close(); |