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
00032 #include "om3u.h"
00033
00034
00035 #include <opie2/odebug.h>
00036 using namespace Opie::Core;
00037
00038
00039
00040 Om3u::Om3u( const QString &filePath, int mode)
00041 : QStringList (){
00042 odebug << "<<<<<<<new m3u "+filePath << oendl;
00043 f.setName(filePath);
00044 f.open(mode);
00045 }
00046
00047 Om3u::~Om3u(){}
00048
00049 void Om3u::readM3u() {
00050
00051 QTextStream t(&f);
00052 t.setEncoding(QTextStream::UnicodeUTF8);
00053 QString s;
00054 while ( !t.atEnd() ) {
00055 s=t.readLine();
00056
00057 if( s.find( "#", 0, TRUE) == -1 ) {
00058 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
00059 s = s.right( s.length() -2 );
00060 QFileInfo f( s );
00061 QString name = f.baseName();
00062 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
00063 s=s.replace( QRegExp( "\\" ), "/" );
00064 append(s);
00065
00066 } else {
00067 QString name;
00068 name = s;
00069 append(name);
00070 }
00071 }
00072 }
00073 }
00074
00075 void Om3u::readPls() {
00076 QTextStream t( &f );
00077 t.setEncoding(QTextStream::UnicodeUTF8);
00078 QString s;
00079 while ( !t.atEnd() ) {
00080 s = t.readLine();
00081 if( s.left(4) == "File" ) {
00082 s = s.right( s.length() - s.find("=",0,true)-1 );
00083 s = s.stripWhiteSpace();
00084 s.replace( QRegExp( "%20" )," ");
00085
00086
00087
00088
00089
00090
00091
00092 s = s.replace( QRegExp( "\\" ), "/" );
00093 QFileInfo f( s );
00094 QString name = f.baseName();
00095 if( name.left( 4 ) == "http" ) {
00096 name = s.right( s.length() - 7);
00097 } else {
00098 name = s;
00099 }
00100 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
00101 if( s.at( s.length() - 4) == '.')
00102 append(s);
00103 else {
00104
00105
00106
00107 append(s);
00108 }
00109 }
00110 }
00111 }
00112
00113 void Om3u::write() {
00114 QString list;
00115 QTextStream t(&f);
00116 t.setEncoding(QTextStream::UnicodeUTF8);
00117 if(count()>0) {
00118 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00119
00120 t << *it << "\n";
00121 }
00122 }
00123
00124 }
00125
00126 void Om3u::add(const QString &filePath) {
00127 append(filePath);
00128 }
00129
00130 void Om3u::remove(const QString &filePath) {
00131 QString list, currentFile;
00132 if(count()>0) {
00133 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00134 currentFile=*it;
00135
00136
00137 if( filePath != currentFile)
00138 list += currentFile+"\n";
00139 }
00140 f.writeBlock( list, list.length() );
00141 }
00142 }
00143
00144 void Om3u::deleteFile(const QString &) {
00145 f.close();
00146 f.remove();
00147
00148 }
00149
00150 void Om3u::close() {
00151 f.close();
00152 }