Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

om3u.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) 2002 L. Potter <ljp@llornkcor.com>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "om3u.h"
00032 
00033 /* OPIE */
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 //extern PlayListWidget *playList;
00045 
00046 Om3u::Om3u( const QString &filePath, int mode)
00047       : QStringList (){
00048 //odebug << "<<<<<<<new m3u "+filePath << oendl;
00049   f.setName(filePath);
00050   f.open(mode);
00051 }
00052 
00053 Om3u::~Om3u(){}
00054 
00055 void Om3u::readM3u() {
00056 //    odebug << "<<<<<<reading m3u "+f.name() << oendl;
00057    QTextStream t(&f);
00058      t.setEncoding(QTextStream::UnicodeUTF8);
00059    QString s;
00060    while ( !t.atEnd() ) {
00061       s=t.readLine();
00062       //                odebug << s << oendl;
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             //                    odebug << s << oendl;
00072          } else { // is url
00073             s.replace( QRegExp( "%20" )," " );
00074             QString name;
00075             //                     if( name.left( 4 ) == "http" ) {
00076             //                         name = s.right( s.length() - 7 );
00077             //                     } else {
00078             name = s;
00079             //                     }
00080             append(name);
00081             //                    odebug << name << oendl;
00082          }
00083       }
00084    }
00085 }
00086 
00087 void Om3u::readPls() { //it's a pls file
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 //                odebug << "adding " + s + " to playlist" << oendl;
00097                 // numberofentries=2
00098                 // File1=http
00099                 // Title
00100                 // Length
00101                 // Version
00102                 // File2=http
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) == '.') // if this is probably a file
00113                 append(s);
00114                 else { //if its a url
00115                     if( name.right( 1 ).find( '/' ) == -1) {
00116                         s += "/";
00117                     }
00118                     append(s);
00119                 }
00120             }
00121         }
00122 }
00123 
00124 void Om3u::write() { //writes list to m3u file
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        //      odebug << *it << oendl;
00131                 t << *it << "\n";
00132     }
00133   }
00134 //    f.close();
00135 }
00136 
00137 void Om3u::add(const QString &filePath) { //adds to m3u file
00138     append(filePath);
00139 }
00140 
00141 void Om3u::remove(const QString &filePath) { //removes from m3u list
00142   QString list, currentFile;
00143   if(count()>0) {
00144     for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00145       currentFile=*it;
00146       //        odebug << *it << oendl;
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 &) {//deletes m3u file
00156      f.close();
00157      f.remove();
00158 
00159 }
00160 
00161 void Om3u::close() { //closes m3u file
00162     f.close();
00163 }

Generated on Sat Nov 5 16:15:42 2005 for OPIE by  doxygen 1.4.2