00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "om3u.h"
00032
00033
00034 #include <opie2/odebug.h>
00035
00036
00037 static inline QString fullBaseName ( const QFileInfo &fi )
00038 {
00039 QString str = fi. fileName ( );
00040 return str. left ( str. findRev ( '.' ));
00041 }
00042
00043
00044
00045
00046 Om3u::Om3u( const QString &filePath, int mode)
00047 : QStringList (){
00048
00049 f.setName(filePath);
00050 f.open(mode);
00051 }
00052
00053 Om3u::~Om3u(){}
00054
00055 void Om3u::readM3u() {
00056
00057 QTextStream t(&f);
00058 t.setEncoding(QTextStream::UnicodeUTF8);
00059 QString s;
00060 while ( !t.atEnd() ) {
00061 s=t.readLine();
00062
00063 if( s.find( "#", 0, TRUE) == -1 ) {
00064 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
00065 s = s.right( s.length() -2 );
00066 QFileInfo f( s );
00067 QString name = fullBaseName ( f );
00068 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
00069 s=s.replace( QRegExp( "\\" ), "/" );
00070 append(s);
00071
00072 } else {
00073 s.replace( QRegExp( "%20" )," " );
00074 QString name;
00075
00076
00077
00078 name = s;
00079
00080 append(name);
00081
00082 }
00083 }
00084 }
00085 }
00086
00087 void Om3u::readPls() {
00088 QTextStream t( &f );
00089 t.setEncoding(QTextStream::UnicodeUTF8);
00090 QString s;
00091 while ( !t.atEnd() ) {
00092 s = t.readLine();
00093 if( s.left(4) == "File" ) {
00094 s = s.right( s.length() - 6 );
00095 s.replace( QRegExp( "%20" )," ");
00096
00097
00098
00099
00100
00101
00102
00103 s = s.replace( QRegExp( "\\" ), "/" );
00104 QFileInfo f( s );
00105 QString name = fullBaseName ( f );
00106 if( name.left( 4 ) == "http" ) {
00107 name = s.right( s.length() - 7);
00108 } else {
00109 name = s;
00110 }
00111 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
00112 if( s.at( s.length() - 4) == '.')
00113 append(s);
00114 else {
00115 if( name.right( 1 ).find( '/' ) == -1) {
00116 s += "/";
00117 }
00118 append(s);
00119 }
00120 }
00121 }
00122 }
00123
00124 void Om3u::write() {
00125 QString list;
00126 QTextStream t(&f);
00127 t.setEncoding(QTextStream::UnicodeUTF8);
00128 if(count()>0) {
00129 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00130
00131 t << *it << "\n";
00132 }
00133 }
00134
00135 }
00136
00137 void Om3u::add(const QString &filePath) {
00138 append(filePath);
00139 }
00140
00141 void Om3u::remove(const QString &filePath) {
00142 QString list, currentFile;
00143 if(count()>0) {
00144 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00145 currentFile=*it;
00146
00147
00148 if( filePath != currentFile)
00149 list += currentFile+"\n";
00150 }
00151 f.writeBlock( list, list.length() );
00152 }
00153 }
00154
00155 void Om3u::deleteFile(const QString &) {
00156 f.close();
00157 f.remove();
00158
00159 }
00160
00161 void Om3u::close() {
00162 f.close();
00163 }