summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/om3u.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/om3u.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp29
1 files changed, 13 insertions, 16 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
index 0be727b..039f3b1 100644
--- a/noncore/multimedia/opieplayer2/om3u.cpp
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -29,57 +29,51 @@
29 29
30*/ 30*/
31 31
32#include "playlistwidget.h" 32#include "playlistwidget.h"
33#include "om3u.h" 33#include "om3u.h"
34 34
35#include <qpe/applnk.h> 35#include <qpe/applnk.h>
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/storage.h> 37#include <qpe/storage.h>
38#include <qpe/mimetype.h> 38#include <qpe/mimetype.h>
39#include <qpe/global.h> 39#include <qpe/global.h>
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41 41
42#include <qdir.h> 42#include <qdir.h>
43#include <qregexp.h> 43#include <qregexp.h>
44#include <qstring.h> 44#include <qstring.h>
45#include <qtextstream.h> 45#include <qtextstream.h>
46#include <qstringlist.h> 46#include <qstringlist.h>
47#include <qcstring.h> 47#include <qcstring.h>
48 48
49//extern PlayListWidget *playList; 49//extern PlayListWidget *playList;
50 50
51Om3u::Om3u( const QString &filePath, int mode) 51Om3u::Om3u( const QString &filePath, int mode)
52 : QStringList (){ 52 : QStringList (){
53//filePath is path name to m3u
54//qDebug("<<<<<<<new m3u "+filePath); 53//qDebug("<<<<<<<new m3u "+filePath);
55 f.setName(filePath); 54 f.setName(filePath);
56// if(f.exists()) 55 f.open(mode);
57// f.open( IO_ReadWrite);
58// else
59// f.open( IO_ReadWrite | IO_Truncate);
60 f.open(mode);
61
62} 56}
63 57
64Om3u::~Om3u(){} 58Om3u::~Om3u(){}
65 59
66void Om3u::readM3u() { 60void Om3u::readM3u() {
67// qDebug("<<<<<<reading m3u "+f.name()); 61// qDebug("<<<<<<reading m3u "+f.name());
68 QTextStream t(&f); 62 QTextStream t(&f);
69 QString s; 63 QString s;
70 while ( !t.atEnd() ) { 64 while ( !t.atEnd() ) {
71 s=t.readLine(); 65 s=t.readLine();
72 qDebug(s); 66 qDebug(s);
73 if( s.find( "#", 0, TRUE) == -1 ) { 67 if( s.find( "#", 0, TRUE) == -1 ) {
74 if( s.left(2) == "E:" || s.left(2) == "P:" ) { 68 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
75 s = s.right( s.length() -2 ); 69 s = s.right( s.length() -2 );
76 QFileInfo f( s ); 70 QFileInfo f( s );
77 QString name = f.baseName(); 71 QString name = f.baseName();
78 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); 72 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
79 s=s.replace( QRegExp( "\\" ), "/" ); 73 s=s.replace( QRegExp( "\\" ), "/" );
80 append(s); 74 append(s);
81// qDebug(s); 75// qDebug(s);
82 } else { // is url 76 } else { // is url
83 s.replace( QRegExp( "%20" )," " ); 77 s.replace( QRegExp( "%20" )," " );
84 QString name; 78 QString name;
85// if( name.left( 4 ) == "http" ) { 79// if( name.left( 4 ) == "http" ) {
@@ -110,59 +104,62 @@ void Om3u::readPls() { //it's a pls file
110 // Version 104 // Version
111 // File2=http 105 // File2=http
112 s = s.replace( QRegExp( "\\" ), "/" ); 106 s = s.replace( QRegExp( "\\" ), "/" );
113 QFileInfo f( s ); 107 QFileInfo f( s );
114 QString name = f.baseName(); 108 QString name = f.baseName();
115 if( name.left( 4 ) == "http" ) { 109 if( name.left( 4 ) == "http" ) {
116 name = s.right( s.length() - 7); 110 name = s.right( s.length() - 7);
117 } else { 111 } else {
118 name = s; 112 name = s;
119 } 113 }
120 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 114 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
121 if( s.at( s.length() - 4) == '.') // if this is probably a file 115 if( s.at( s.length() - 4) == '.') // if this is probably a file
122 append(s); 116 append(s);
123 else { //if its a url 117 else { //if its a url
124 if( name.right( 1 ).find( '/' ) == -1) { 118 if( name.right( 1 ).find( '/' ) == -1) {
125 s += "/"; 119 s += "/";
126 } 120 }
127 append(s); 121 append(s);
128 } 122 }
129 } 123 }
130 } 124 }
131} 125}
132 126
133void Om3u::write() { //writes list to m3u file 127void Om3u::write() { //writes list to m3u file
134 QString list; 128 QString list;
129 if(count()>0) {
135 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 130 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
136 qDebug(*it); 131 qDebug(*it);
137 list += *it+"\n"; 132 list += *it+"\n";
138 } 133 }
139 f.writeBlock( list, list.length() ); 134 f.writeBlock( list, list.length() );
135 }
140// f.close(); 136// f.close();
141} 137}
142 138
143void Om3u::add(const QString &filePath) { //adds to m3u file 139void Om3u::add(const QString &filePath) { //adds to m3u file
144 append(filePath); 140 append(filePath);
145} 141}
146 142
147void Om3u::remove(const QString &filePath) { //removes from m3u list 143void Om3u::remove(const QString &filePath) { //removes from m3u list
148 QString list, currentFile; 144 QString list, currentFile;
145 if(count()>0) {
149 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 146 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
150 currentFile=*it; 147 currentFile=*it;
151// qDebug(*it); 148 // qDebug(*it);
152 149
153 if( filePath != currentFile) 150 if( filePath != currentFile)
154 list += currentFile+"\n"; 151 list += currentFile+"\n";
155 } 152 }
156 f.writeBlock( list, list.length() ); 153 f.writeBlock( list, list.length() );
157 154 }
158} 155}
159 156
160void Om3u::deleteFile(const QString &filePath) {//deletes m3u file 157void Om3u::deleteFile(const QString &filePath) {//deletes m3u file
161 f.close(); 158 f.close();
162 f.remove(); 159 f.remove();
163 160
164} 161}
165 162
166void Om3u::close() { //closes m3u file 163void Om3u::close() { //closes m3u file
167 f.close(); 164 f.close();
168} 165}