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 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 ..}^=.=       =       ;      General Public License for more
00021 ++=   -.     .`     .:       details.
00022  :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           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 
00032 #include "om3u.h"
00033 
00034 /* OPIE */
00035 #include <opie2/odebug.h>
00036 using namespace Opie::Core;
00037 
00038 //extern PlayListWidget *playList;
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 //    odebug << "<<<<<<reading m3u "+f.name() << oendl; 
00051     QTextStream t(&f);
00052                 t.setEncoding(QTextStream::UnicodeUTF8);
00053                 QString s;
00054     while ( !t.atEnd() ) {
00055         s=t.readLine();
00056 //                odebug << s << oendl; 
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 //                    odebug << s << oendl; 
00066                 } else { // is url
00067                     QString name;
00068                     name = s;
00069                     append(name);
00070                 }
00071         }
00072     }
00073 }
00074 
00075 void Om3u::readPls() { //it's a pls file
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 //                odebug << "adding " + s + " to playlist" << oendl; 
00086                 // numberofentries=2
00087                 // File1=http
00088                 // Title
00089                 // Length
00090                 // Version
00091                 // File2=http
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) == '.') // if this is probably a file
00102                 append(s);
00103                 else { //if its a url
00104 //                     if( name.right( 1 ).find( '/' ) == -1) {
00105 //                         s += "/";
00106 //                     }
00107                     append(s);
00108                 }
00109             }
00110         }
00111 }
00112 
00113 void Om3u::write() { //writes list to m3u file
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 //      odebug << *it << oendl; 
00120                                 t << *it << "\n";
00121     }
00122   }
00123 //    f.close();
00124 }
00125 
00126 void Om3u::add(const QString &filePath) { //adds to m3u file
00127     append(filePath);
00128 }
00129 
00130 void Om3u::remove(const QString &filePath) { //removes from m3u list
00131   QString list, currentFile;
00132   if(count()>0) {
00133     for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
00134       currentFile=*it;
00135       //        odebug << *it << oendl; 
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 &/*filePath*/) {//deletes m3u file
00145      f.close();
00146      f.remove();
00147 
00148 }
00149 
00150 void Om3u::close() { //closes m3u file
00151     f.close();
00152 }

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