summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-10-08 02:01:16 (UTC)
committer llornkcor <llornkcor>2002-10-08 02:01:16 (UTC)
commit40e9c78666e74221e06329bb07dfd66648b2727b (patch) (unidiff)
treeafccf992024cc56a64d8495d80ce10478f946478
parentc43b5d600a7d1dcaadcba2cb047a60313b37f2f2 (diff)
downloadopie-40e9c78666e74221e06329bb07dfd66648b2727b.zip
opie-40e9c78666e74221e06329bb07dfd66648b2727b.tar.gz
opie-40e9c78666e74221e06329bb07dfd66648b2727b.tar.bz2
fixed m3u handling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/om3u.cpp16
-rw-r--r--noncore/multimedia/opieplayer2/om3u.h2
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp180
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.h1
4 files changed, 76 insertions, 123 deletions
diff --git a/noncore/multimedia/opieplayer2/om3u.cpp b/noncore/multimedia/opieplayer2/om3u.cpp
index d378145..c947033 100644
--- a/noncore/multimedia/opieplayer2/om3u.cpp
+++ b/noncore/multimedia/opieplayer2/om3u.cpp
@@ -1,157 +1,157 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU General Public 10:`=1 )Y*s>-.--   : the terms of the GNU General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; General Public License for more 20..}^=.=       =       ; General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = General Public License along with 24  -_. . .   )=.  = General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
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) 51Om3u::Om3u( const QString &filePath, int mode)
52 : QStringList (){ 52 : QStringList (){
53//filePath is path name to m3u 53//filePath is path name to m3u
54//qDebug("<<<<<<<new m3u "+filePath); 54//qDebug("<<<<<<<new m3u "+filePath);
55 f.setName(filePath); 55 f.setName(filePath);
56 if(f.exists()) 56// if(f.exists())
57 f.open( IO_ReadWrite ); 57// f.open( IO_ReadWrite);
58 else 58// else
59 f.open( IO_ReadWrite | IO_Truncate); 59// f.open( IO_ReadWrite | IO_Truncate);
60 f.open(mode);
61
60} 62}
61 63
62Om3u::~Om3u(){} 64Om3u::~Om3u(){}
63 65
64void Om3u::readM3u() { //it's m3u 66void Om3u::readM3u() { //it's m3u
65// qDebug("<<<<<<reading m3u "+f.name()); 67// qDebug("<<<<<<reading m3u "+f.name());
66 QTextStream t(&f); 68 QTextStream t(&f);
67 QString s; 69 QString s;
68 while ( !t.atEnd() ) { 70 while ( !t.atEnd() ) {
69 s=t.readLine(); 71 s=t.readLine();
70 72 // qDebug(s);
71 if( s.find( "#", 0, TRUE) == -1 ) { 73 if( s.find( "#", 0, TRUE) == -1 ) {
72 if( s.find( " ", 0, TRUE) == -1 ) {
73 if( s.left(2) == "E:" || s.left(2) == "P:" ) { 74 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
74 s = s.right( s.length() -2 ); 75 s = s.right( s.length() -2 );
75 QFileInfo f( s ); 76 QFileInfo f( s );
76 QString name = f.baseName(); 77 QString name = f.baseName();
77 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); 78 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
78 s=s.replace( QRegExp( "\\" ), "/" ); 79 s=s.replace( QRegExp( "\\" ), "/" );
79 append(s); 80 append(s);
80// qDebug(s); 81// qDebug(s);
81 } else { // is url 82 } else { // is url
82 s.replace( QRegExp( "%20" )," " ); 83 s.replace( QRegExp( "%20" )," " );
83 QString name; 84 QString name;
84 if( name.left( 4 ) == "http" ) { 85 if( name.left( 4 ) == "http" ) {
85 name = s.right( s.length() - 7 ); 86 name = s.right( s.length() - 7 );
86 } else { 87 } else {
87 name = s; 88 name = s;
88 } 89 }
89 append(name); 90 append(name);
90// qDebug(name); 91// qDebug(name);
91 } 92 }
92 }
93 } 93 }
94 } 94 }
95} 95}
96 96
97void Om3u::readPls() { //it's a pls file 97void Om3u::readPls() { //it's a pls file
98 QTextStream t( &f ); 98 QTextStream t( &f );
99 QString s; 99 QString s;
100 while ( !t.atEnd() ) { 100 while ( !t.atEnd() ) {
101 s = t.readLine(); 101 s = t.readLine();
102 if( s.left(4) == "File" ) { 102 if( s.left(4) == "File" ) {
103 s = s.right( s.length() - 6 ); 103 s = s.right( s.length() - 6 );
104 s.replace( QRegExp( "%20" )," "); 104 s.replace( QRegExp( "%20" )," ");
105// qDebug( "adding " + s + " to playlist" ); 105// qDebug( "adding " + s + " to playlist" );
106 // numberofentries=2 106 // numberofentries=2
107 // File1=http 107 // File1=http
108 // Title 108 // Title
109 // Length 109 // Length
110 // Version 110 // Version
111 // File2=http 111 // File2=http
112 s = s.replace( QRegExp( "\\" ), "/" ); 112 s = s.replace( QRegExp( "\\" ), "/" );
113 QFileInfo f( s ); 113 QFileInfo f( s );
114 QString name = f.baseName(); 114 QString name = f.baseName();
115 if( name.left( 4 ) == "http" ) { 115 if( name.left( 4 ) == "http" ) {
116 name = s.right( s.length() - 7); 116 name = s.right( s.length() - 7);
117 } else { 117 } else {
118 name = s; 118 name = s;
119 } 119 }
120 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 120 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
121 if( s.at( s.length() - 4) == '.') // if this is probably a file 121 if( s.at( s.length() - 4) == '.') // if this is probably a file
122 append(s); 122 append(s);
123 else { //if its a url 123 else { //if its a url
124 if( name.right( 1 ).find( '/' ) == -1) { 124 if( name.right( 1 ).find( '/' ) == -1) {
125 s += "/"; 125 s += "/";
126 } 126 }
127 append(s); 127 append(s);
128 } 128 }
129 } 129 }
130 } 130 }
131} 131}
132 132
133void Om3u::write() { //writes list to m3u file 133void Om3u::write() { //writes list to m3u file
134 QString list; 134 QString list;
135 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 135 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
136 qDebug(*it); 136 qDebug(*it);
137 list += *it+"\n"; 137 list += *it+"\n";
138 } 138 }
139 f.writeBlock( list, list.length() ); 139 f.writeBlock( list, list.length() );
140 f.close(); 140 f.close();
141} 141}
142 142
143void Om3u::add(const QString &filePath) { //adds to m3u file 143void Om3u::add(const QString &filePath) { //adds to m3u file
144 append(filePath); 144 append(filePath);
145} 145}
146 146
147void Om3u::remove(const QString &filePath) { //removes from m3u list 147void Om3u::remove(const QString &filePath) { //removes from m3u list
148 148
149} 149}
150 150
151void Om3u::deleteFile(const QString &filePath) {//deletes m3u file 151void Om3u::deleteFile(const QString &filePath) {//deletes m3u file
152 152
153} 153}
154 154
155void Om3u::close() { //closes m3u file 155void Om3u::close() { //closes m3u file
156 f.close(); 156 f.close();
157} 157}
diff --git a/noncore/multimedia/opieplayer2/om3u.h b/noncore/multimedia/opieplayer2/om3u.h
index 392980e..9c7cf9a 100644
--- a/noncore/multimedia/opieplayer2/om3u.h
+++ b/noncore/multimedia/opieplayer2/om3u.h
@@ -1,79 +1,79 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 4 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU General Public 10:`=1 )Y*s>-.--   : the terms of the GNU General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; General Public License for more 20..}^=.=       =       ; General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = General Public License along with 24  -_. . .   )=.  = General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef OM3U_H 32#ifndef OM3U_H
33#define OM3U_H 33#define OM3U_H
34 34
35#include "playlistwidget.h" 35#include "playlistwidget.h"
36 36
37#include <qpe/applnk.h> 37#include <qpe/applnk.h>
38#include <qpe/qpeapplication.h> 38#include <qpe/qpeapplication.h>
39#include <qpe/storage.h> 39#include <qpe/storage.h>
40#include <qpe/mimetype.h> 40#include <qpe/mimetype.h>
41#include <qpe/global.h> 41#include <qpe/global.h>
42#include <qpe/resource.h> 42#include <qpe/resource.h>
43 43
44#include <qdir.h> 44#include <qdir.h>
45#include <qregexp.h> 45#include <qregexp.h>
46#include <qstring.h> 46#include <qstring.h>
47#include <qtextstream.h> 47#include <qtextstream.h>
48#include <qstringlist.h> 48#include <qstringlist.h>
49#include <qcstring.h> 49#include <qcstring.h>
50#include <qfile.h> 50#include <qfile.h>
51 51
52 52
53class Om3u : public QStringList { 53class Om3u : public QStringList {
54// Q_OBJECT 54// Q_OBJECT
55public: 55public:
56 Om3u( const QString &filePath); 56 Om3u( const QString &filePath, int mode);
57 ~Om3u(); 57 ~Om3u();
58 void readM3u(); 58 void readM3u();
59 void readPls(); 59 void readPls();
60 void write(); 60 void write();
61 void add(const QString &); 61 void add(const QString &);
62 void remove(const QString &); 62 void remove(const QString &);
63 void deleteFile(const QString &); 63 void deleteFile(const QString &);
64 void close(); 64 void close();
65 65
66public slots: 66public slots:
67 67
68protected: 68protected:
69 69
70private: 70private:
71 QFile f; 71 QFile f;
72private slots: 72private slots:
73 73
74 74
75}; 75};
76 76
77#endif// M3U_H 77#endif// M3U_H
78 78
79 79
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 26c2896..b6525e1 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -55,700 +55,639 @@
55#include "audiowidget.h" 55#include "audiowidget.h"
56#include "videowidget.h" 56#include "videowidget.h"
57 57
58extern MediaPlayerState *mediaPlayerState; 58extern MediaPlayerState *mediaPlayerState;
59 59
60 60
61PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 61PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
62 : PlayListWidgetGui( parent, name, fl ) { 62 : PlayListWidgetGui( parent, name, fl ) {
63 63
64 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 64 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
65 "opieplayer2/add_to_playlist", 65 "opieplayer2/add_to_playlist",
66 this , SLOT(addSelected() ) ); 66 this , SLOT(addSelected() ) );
67 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 67 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
68 "opieplayer2/remove_from_playlist", 68 "opieplayer2/remove_from_playlist",
69 this , SLOT(removeSelected() ) ); 69 this , SLOT(removeSelected() ) );
70 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 70 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
71 this , SLOT( btnPlay( bool) ), TRUE ); 71 this , SLOT( btnPlay( bool) ), TRUE );
72 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 72 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
73 mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); 73 mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE );
74 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 74 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
75 mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); 75 mediaPlayerState, SLOT( setLooping( bool ) ), TRUE );
76 76
77 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 77 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
78 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 78 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
79 this, SLOT( addAllMusicToList() ) ); 79 this, SLOT( addAllMusicToList() ) );
80 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 80 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
81 this, SLOT( addAllVideoToList() ) ); 81 this, SLOT( addAllVideoToList() ) );
82 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 82 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
83 this, SLOT( addAllToList() ) ); 83 this, SLOT( addAllToList() ) );
84 pmPlayList->insertSeparator(-1); 84 pmPlayList->insertSeparator(-1);
85// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), 85// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ),
86// this, SLOT( saveList() ) ); 86// this, SLOT( saveList() ) );
87 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), 87 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
88 this, SLOT(writem3u() ) ); 88 this, SLOT(writem3u() ) );
89 pmPlayList->insertSeparator(-1); 89 pmPlayList->insertSeparator(-1);
90 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ), 90 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ),
91 this,SLOT( openFile() ) ); 91 this,SLOT( openFile() ) );
92 pmPlayList->insertSeparator(-1); 92 pmPlayList->insertSeparator(-1);
93 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 93 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
94 this,SLOT( scanForAudio() ) ); 94 this,SLOT( scanForAudio() ) );
95 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 95 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
96 this,SLOT( scanForVideo() ) ); 96 this,SLOT( scanForVideo() ) );
97 97
98 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 98 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
99 mediaPlayerState, SLOT( toggleFullscreen() ) ); 99 mediaPlayerState, SLOT( toggleFullscreen() ) );
100 100
101 Config cfg( "OpiePlayer" ); 101 Config cfg( "OpiePlayer" );
102 bool b= cfg.readBoolEntry("FullScreen", 0); 102 bool b= cfg.readBoolEntry("FullScreen", 0);
103 mediaPlayerState->setFullscreen( b ); 103 mediaPlayerState->setFullscreen( b );
104 pmView->setItemChecked( -16, b ); 104 pmView->setItemChecked( -16, b );
105 105
106 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 106 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
107 d->selectedFiles, SLOT(moveSelectedUp() ) ); 107 d->selectedFiles, SLOT(moveSelectedUp() ) );
108 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 108 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
109 d->selectedFiles, SLOT(removeSelected() ) ); 109 d->selectedFiles, SLOT(removeSelected() ) );
110 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 110 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
111 d->selectedFiles, SLOT(moveSelectedDown() ) ); 111 d->selectedFiles, SLOT(moveSelectedDown() ) );
112 QVBox *stretch2 = new QVBox( vbox1 ); 112 QVBox *stretch2 = new QVBox( vbox1 );
113 113
114 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 114 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
115 SLOT( deletePlaylist() ) ); 115 SLOT( deletePlaylist() ) );
116 connect( pmView, SIGNAL( activated( int ) ), 116 connect( pmView, SIGNAL( activated( int ) ),
117 this, SLOT( pmViewActivated( int ) ) ); 117 this, SLOT( pmViewActivated( int ) ) );
118 connect( skinsMenu, SIGNAL( activated( int ) ) , 118 connect( skinsMenu, SIGNAL( activated( int ) ) ,
119 this, SLOT( skinsMenuActivated( int ) ) ); 119 this, SLOT( skinsMenuActivated( int ) ) );
120 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 120 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
121 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 121 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
122 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 122 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
123 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 123 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
124 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 124 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
125 this,SLOT( playIt( QListViewItem *) ) ); 125 this,SLOT( playIt( QListViewItem *) ) );
126 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 126 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
127 this, SLOT( addToSelection( QListViewItem *) ) ); 127 this, SLOT( addToSelection( QListViewItem *) ) );
128 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 128 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
129 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 129 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
130 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 130 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
131 this,SLOT( playIt( QListViewItem *) ) ); 131 this,SLOT( playIt( QListViewItem *) ) );
132 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 132 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
133 this, SLOT( addToSelection( QListViewItem *) ) ); 133 this, SLOT( addToSelection( QListViewItem *) ) );
134 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 134 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
135 this, SLOT( loadList( const DocLnk & ) ) ); 135 this, SLOT( loadList( const DocLnk & ) ) );
136 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 136 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
137 this, SLOT( tabChanged( QWidget* ) ) ); 137 this, SLOT( tabChanged( QWidget* ) ) );
138 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), 138 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ),
139 d->tbPlay, SLOT( setOn( bool ) ) ); 139 d->tbPlay, SLOT( setOn( bool ) ) );
140 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 140 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
141 d->tbLoop, SLOT( setOn( bool ) ) ); 141 d->tbLoop, SLOT( setOn( bool ) ) );
142 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 142 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
143 d->tbShuffle, SLOT( setOn( bool ) ) ); 143 d->tbShuffle, SLOT( setOn( bool ) ) );
144 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), 144 connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ),
145 this, SLOT( setPlaylist( bool ) ) ); 145 this, SLOT( setPlaylist( bool ) ) );
146 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 146 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
147 this, SLOT( playIt( QListViewItem *) ) ); 147 this, SLOT( playIt( QListViewItem *) ) );
148 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 148 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
149 mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 149 mediaPlayerState, SLOT( setVideoGamma( int ) ) );
150 150
151// cfg.setGroup( "PlayList" );
152// if( cfg.readBoolEntry("newPlaylist") ){
153 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
154 loadList(DocLnk( currentPlaylist ) );
155 setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
156// } else {
157// readConfig( cfg );
158
159// }
160 // see which skins are installed 151 // see which skins are installed
161 videoScan=FALSE; 152 videoScan=FALSE;
162 audioScan=FALSE; 153 audioScan=FALSE;
163 populateSkinsMenu(); 154 populateSkinsMenu();
164 initializeStates(); 155 initializeStates();
156
157 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "" );
158 loadList(DocLnk( currentPlaylist ) );
159 setCaption( tr( "OpiePlayer: " ) + currentPlaylist );
165} 160}
166 161
167 162
168PlayListWidget::~PlayListWidget() { 163PlayListWidget::~PlayListWidget() {
169 // WTF?!@?!
170
171 if ( d->current ) { 164 if ( d->current ) {
172 delete d->current; 165 delete d->current;
173 } 166 }
174 delete d; 167 delete d;
175} 168}
176 169
177 170
178void PlayListWidget::initializeStates() { 171void PlayListWidget::initializeStates() {
179 d->tbPlay->setOn( mediaPlayerState->playing() ); 172 d->tbPlay->setOn( mediaPlayerState->playing() );
180 d->tbLoop->setOn( mediaPlayerState->looping() ); 173 d->tbLoop->setOn( mediaPlayerState->looping() );
181 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 174 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
182 setPlaylist( true ); 175 setPlaylist( true );
183} 176}
184 177
185 178
186void PlayListWidget::readConfig( Config& cfg ) { 179void PlayListWidget::readConfig( Config& cfg ) {
187 180
188 cfg.setGroup( "PlayList" ); 181 cfg.setGroup( "PlayList" );
189 QString currentString = cfg.readEntry( "current", "" ); 182 QString currentString = cfg.readEntry( "current", "" );
190 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 ); 183 int noOfFiles = cfg.readNumEntry( "NumberOfFiles", 0 );
191 184
192 for ( int i = 0; i < noOfFiles; i++ ) { 185 for ( int i = 0; i < noOfFiles; i++ ) {
193 QString entryName; 186 QString entryName;
194 entryName.sprintf( "File%i", i + 1 ); 187 entryName.sprintf( "File%i", i + 1 );
195 188
196 QString linkFile = cfg.readEntry( entryName ); 189 QString linkFile = cfg.readEntry( entryName );
197 190
198 qDebug("reading "+linkFile); 191 qDebug("reading "+linkFile);
199 192
200 if( QFileInfo( linkFile ).exists() ) { 193 if( QFileInfo( linkFile ).exists() ) {
201 194
202 DocLnk lnk( linkFile ); 195 DocLnk lnk( linkFile );
203 196
204 if ( QFileInfo( lnk.file() ).exists() || 197 if ( QFileInfo( lnk.file() ).exists() ||
205 198
206 linkFile.find( "http" , 0, TRUE) != -1) { 199 linkFile.find( "http" , 0, TRUE) != -1) {
207 200
208 d->selectedFiles->addToSelection( lnk ); 201 d->selectedFiles->addToSelection( lnk );
209
210 } 202 }
211 } 203 }
212 } 204 }
213 d->selectedFiles->setSelectedItem( currentString ); 205 d->selectedFiles->setSelectedItem( currentString );
214
215} 206}
216 207
217 208
218void PlayListWidget::writeConfig( Config& cfg ) const { 209void PlayListWidget::writeConfig( Config& cfg ) const {
219 210
220 Config config( "OpiePlayer" ); 211 Config config( "OpiePlayer" );
221 config.setGroup( "PlayList" ); 212 config.setGroup( "PlayList" );
222 213
223// if(config.readBoolEntry("newPlaylist")) { 214// if(config.readBoolEntry("newPlaylist")) {
224// new for testing 215// new for testing
225 QString name, filename, list; 216 QString name, filename, list;
226 Om3u *m3uList; 217 Om3u *m3uList;
227 name = "default"; 218 name = "default";
228 219
229 filename=QPEApplication::documentDir() + "/" + name+".m3u"; 220 filename=QPEApplication::documentDir() + "/" + name+".m3u";
230 221 m3uList = new Om3u(filename, IO_ReadWrite);
231 m3uList = new Om3u(filename);
232
233 d->selectedFiles->first(); 222 d->selectedFiles->first();
234 do { 223 do {
235 m3uList->add( d->selectedFiles->current()->file()); 224 qDebug(d->selectedFiles->current()->file());
225 m3uList->add( d->selectedFiles->current()->file() );
236 } 226 }
237 while ( d->selectedFiles->next() ); 227 while ( d->selectedFiles->next() );
228 // qDebug( list );
238 229
239 qDebug( list ); 230 // m3uList->write();
240
241 m3uList->write();
242 m3uList->close(); 231 m3uList->close();
243 if(m3uList) delete m3uList; 232 if(m3uList) delete m3uList;
244 233
245 DocLnk lnk; 234 DocLnk lnk;
246 lnk.setFile( filename); 235 lnk.setFile( filename);
247 lnk.setIcon("opieplayer2/playlist2"); 236 lnk.setIcon("opieplayer2/playlist2");
248 lnk.setName( name); //sets file name 237 lnk.setName( name); //sets file name
249 238
250 qDebug("writing default playlist "+filename); 239 qDebug("writing default playlist "+filename);
251 240
252 config.writeEntry("CurrentPlaylist", filename); 241 config.writeEntry("CurrentPlaylist", filename);
253// currentPlayList=filename; 242// currentPlayList=filename;
254
255 if(!lnk.writeLink()) { 243 if(!lnk.writeLink()) {
256 qDebug("Writing doclink did not work"); 244 qDebug("Writing doclink did not work");
257 } 245 }
258
259// } else { 246// } else {
260 247
261// d->selectedFiles->writeCurrent( cfg ); 248// d->selectedFiles->writeCurrent( cfg );
262// int noOfFiles = 0; 249// int noOfFiles = 0;
263// d->selectedFiles->first(); 250// d->selectedFiles->first();
264 251
265// do { 252// do {
266// const DocLnk *lnk = d->selectedFiles->current(); 253// const DocLnk *lnk = d->selectedFiles->current();
267 254
268// if ( lnk ) { 255// if ( lnk ) {
269 256
270// QString entryName; 257// QString entryName;
271// entryName.sprintf( "File%i", noOfFiles + 1 ); 258// entryName.sprintf( "File%i", noOfFiles + 1 );
272 259
273// cfg.writeEntry( entryName, lnk->linkFile() ); 260// cfg.writeEntry( entryName, lnk->linkFile() );
274// // if this link does exist, add it so we have the file 261// // if this link does exist, add it so we have the file
275// // next time... 262// // next time...
276 263
277// if ( !QFile::exists( lnk->linkFile() ) ) { 264// if ( !QFile::exists( lnk->linkFile() ) ) {
278// lnk->writeLink(); 265// lnk->writeLink();
279// } 266// }
280// } 267// }
281// noOfFiles++; 268// noOfFiles++;
282// } 269// }
283// while ( d->selectedFiles->next() ); 270// while ( d->selectedFiles->next() );
284// cfg.writeEntry("NumberOfFiles", noOfFiles ); 271// cfg.writeEntry("NumberOfFiles", noOfFiles );
285// } 272// }
286} 273}
287 274
288
289void PlayListWidget::addToSelection( const DocLnk& lnk ) { 275void PlayListWidget::addToSelection( const DocLnk& lnk ) {
290 d->setDocumentUsed = FALSE; 276 d->setDocumentUsed = FALSE;
291 if ( mediaPlayerState->playlist() ) { 277 if ( mediaPlayerState->playlist() ) {
292 if( QFileInfo( lnk.file() ).exists() || 278 if( QFileInfo( lnk.file() ).exists() ||
293 lnk.file().left(4) == "http" ) 279 lnk.file().left(4) == "http" )
294 d->selectedFiles->addToSelection( lnk ); 280 d->selectedFiles->addToSelection( lnk );
281 writeCurrentM3u();
295 } 282 }
296 else 283 else
297 mediaPlayerState->setPlaying( TRUE ); 284 mediaPlayerState->setPlaying( TRUE );
298} 285}
299 286
300 287
301void PlayListWidget::clearList() { 288void PlayListWidget::clearList() {
302 while ( first() ) { 289 while ( first() ) {
303 d->selectedFiles->removeSelected(); 290 d->selectedFiles->removeSelected();
304 } 291 }
305} 292}
306 293
307
308void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 294void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
309 switch (mouse) { 295 switch (mouse) {
310 case 1: 296 case 1:
311 break; 297 break;
312 case 2: 298 case 2:
313 { 299 {
314 QPopupMenu m; 300 QPopupMenu m;
315 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 301 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
316 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 302 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
317 m.exec( QCursor::pos() ); 303 m.exec( QCursor::pos() );
318 } 304 }
319 break; 305 break;
320 } 306 }
321} 307}
322 308
323 309
324void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 310void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
325 switch (mouse) { 311 switch (mouse) {
326 case 1: 312 case 1:
327 break; 313 break;
328 case 2: 314 case 2:
329 { 315 {
330 QPopupMenu m; 316 QPopupMenu m;
331 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 317 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
332 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 318 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
333 m.exec( QCursor::pos() ); 319 m.exec( QCursor::pos() );
334 } 320 }
335 break; 321 break;
336 } 322 }
337} 323}
338 324
339 325
340void PlayListWidget::addAllToList() { 326void PlayListWidget::addAllToList() {
341 DocLnkSet filesAll; 327 DocLnkSet filesAll;
342 Global::findDocuments(&filesAll, "video/*;audio/*"); 328 Global::findDocuments(&filesAll, "video/*;audio/*");
343 QListIterator<DocLnk> Adit( filesAll.children() ); 329 QListIterator<DocLnk> Adit( filesAll.children() );
344 for ( ; Adit.current(); ++Adit ) { 330 for ( ; Adit.current(); ++Adit ) {
345 if( QFileInfo( Adit.current()->file() ).exists() ) { 331 if( QFileInfo( Adit.current()->file() ).exists() ) {
346 d->selectedFiles->addToSelection( **Adit ); 332 d->selectedFiles->addToSelection( **Adit );
347 } 333 }
348 } 334 }
335 writeCurrentM3u();
349} 336}
350 337
351 338
352void PlayListWidget::addAllMusicToList() { 339void PlayListWidget::addAllMusicToList() {
353 QListIterator<DocLnk> dit( files.children() ); 340 QListIterator<DocLnk> dit( files.children() );
354 for ( ; dit.current(); ++dit ) { 341 for ( ; dit.current(); ++dit ) {
355 if( QFileInfo(dit.current()->file() ).exists() ) { 342 if( QFileInfo(dit.current()->file() ).exists() ) {
356 d->selectedFiles->addToSelection( **dit ); 343 d->selectedFiles->addToSelection( **dit );
357 } 344 }
358 } 345 }
346 writeCurrentM3u();
359} 347}
360 348
361 349
362void PlayListWidget::addAllVideoToList() { 350void PlayListWidget::addAllVideoToList() {
363 QListIterator<DocLnk> dit( vFiles.children() ); 351 QListIterator<DocLnk> dit( vFiles.children() );
364 for ( ; dit.current(); ++dit ) { 352 for ( ; dit.current(); ++dit ) {
365 if( QFileInfo( dit.current()->file() ).exists() ) { 353 if( QFileInfo( dit.current()->file() ).exists() ) {
366 d->selectedFiles->addToSelection( **dit ); 354 d->selectedFiles->addToSelection( **dit );
367 } 355 }
368 } 356 }
357 writeCurrentM3u();
369} 358}
370 359
371 360
372void PlayListWidget::setDocument( const QString& fileref ) { 361void PlayListWidget::setDocument( const QString& fileref ) {
373 //qDebug( fileref ); 362 //qDebug( fileref );
374 fromSetDocument = TRUE; 363 fromSetDocument = TRUE;
375 if ( fileref.isNull() ) { 364 if ( fileref.isNull() ) {
376 QMessageBox::critical( 0, tr( "Invalid File" ), 365 QMessageBox::critical( 0, tr( "Invalid File" ),
377 tr( "There was a problem in getting the file." ) ); 366 tr( "There was a problem in getting the file." ) );
378 return; 367 return;
379 } 368 }
380 369
381 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u 370 if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u
382 readm3u( fileref ); 371 readm3u( fileref );
383 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls 372 } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls
384 readPls( fileref ); 373 readPls( fileref );
385 } else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist 374 }// else if( fileref.find( "playlist", 0, TRUE) != -1 ) {//is playlist
386 clearList(); 375// clearList();
387 loadList( DocLnk( fileref ) ); 376// loadList( DocLnk( fileref ) );
388 d->selectedFiles->first(); 377// d->selectedFiles->first();
389 } else { 378// }
379 else {
390 clearList(); 380 clearList();
391 addToSelection( DocLnk( fileref ) ); 381 addToSelection( DocLnk( fileref ) );
392 d->setDocumentUsed = TRUE; 382 d->setDocumentUsed = TRUE;
393 mediaPlayerState->setPlaying( FALSE ); 383 mediaPlayerState->setPlaying( FALSE );
394// qApp->processEvents();
395 mediaPlayerState->setPlaying( TRUE ); 384 mediaPlayerState->setPlaying( TRUE );
396// qApp->processEvents();
397 setCaption( tr("OpiePlayer") );
398 } 385 }
399} 386}
400 387
401 388
402void PlayListWidget::useSelectedDocument() { 389void PlayListWidget::useSelectedDocument() {
403 d->setDocumentUsed = FALSE; 390 d->setDocumentUsed = FALSE;
404} 391}
405 392
406 393
407const DocLnk *PlayListWidget::current() { // this is fugly 394const DocLnk *PlayListWidget::current() { // this is fugly
408 switch ( whichList() ) { 395 switch ( whichList() ) {
409 case 0: //playlist 396 case 0: //playlist
410 { 397 {
411// qDebug("playlist"); 398// qDebug("playlist");
412 if ( mediaPlayerState->playlist() ) { 399 if ( mediaPlayerState->playlist() ) {
413 return d->selectedFiles->current(); 400 return d->selectedFiles->current();
414 } else if ( d->setDocumentUsed && d->current ) { 401 } else if ( d->setDocumentUsed && d->current ) {
415 return d->current; 402 return d->current;
416 } else { 403 } else {
417 return &(d->files->selectedDocument()); 404 return &(d->files->selectedDocument());
418 } 405 }
419 } 406 }
420 break; 407 break;
421 }; 408 };
422 return 0; 409 return 0;
423} 410}
424 411
425 412
426bool PlayListWidget::prev() { 413bool PlayListWidget::prev() {
427 if ( mediaPlayerState->playlist() ) { 414 if ( mediaPlayerState->playlist() ) {
428 if ( mediaPlayerState->shuffled() ) { 415 if ( mediaPlayerState->shuffled() ) {
429 const DocLnk *cur = current(); 416 const DocLnk *cur = current();
430 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 417 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
431 for ( int i = 0; i < j; i++ ) { 418 for ( int i = 0; i < j; i++ ) {
432 if ( !d->selectedFiles->next() ) 419 if ( !d->selectedFiles->next() )
433 d->selectedFiles->first(); 420 d->selectedFiles->first();
434 } 421 }
435 if ( cur == current() ) 422 if ( cur == current() )
436 if ( !d->selectedFiles->next() ) { 423 if ( !d->selectedFiles->next() ) {
437 d->selectedFiles->first(); 424 d->selectedFiles->first();
438 } 425 }
439 return TRUE; 426 return TRUE;
440 } else { 427 } else {
441 if ( !d->selectedFiles->prev() ) { 428 if ( !d->selectedFiles->prev() ) {
442 if ( mediaPlayerState->looping() ) { 429 if ( mediaPlayerState->looping() ) {
443 return d->selectedFiles->last(); 430 return d->selectedFiles->last();
444 } else { 431 } else {
445 return FALSE; 432 return FALSE;
446 } 433 }
447 } 434 }
448 return TRUE; 435 return TRUE;
449 } 436 }
450 } else { 437 } else {
451 return mediaPlayerState->looping(); 438 return mediaPlayerState->looping();
452 } 439 }
453} 440}
454 441
455 442
456bool PlayListWidget::next() { 443bool PlayListWidget::next() {
457//qDebug("<<<<<<<<<<<<next()"); 444//qDebug("<<<<<<<<<<<<next()");
458 if ( mediaPlayerState->playlist() ) { 445 if ( mediaPlayerState->playlist() ) {
459 if ( mediaPlayerState->shuffled() ) { 446 if ( mediaPlayerState->shuffled() ) {
460 return prev(); 447 return prev();
461 } else { 448 } else {
462 if ( !d->selectedFiles->next() ) { 449 if ( !d->selectedFiles->next() ) {
463 if ( mediaPlayerState->looping() ) { 450 if ( mediaPlayerState->looping() ) {
464 return d->selectedFiles->first(); 451 return d->selectedFiles->first();
465 } else { 452 } else {
466 return FALSE; 453 return FALSE;
467 } 454 }
468 } 455 }
469 return TRUE; 456 return TRUE;
470 } 457 }
471 } else { 458 } else {
472 return mediaPlayerState->looping(); 459 return mediaPlayerState->looping();
473 } 460 }
474} 461}
475 462
476 463
477bool PlayListWidget::first() { 464bool PlayListWidget::first() {
478 if ( mediaPlayerState->playlist() ) 465 if ( mediaPlayerState->playlist() )
479 return d->selectedFiles->first(); 466 return d->selectedFiles->first();
480 else 467 else
481 return mediaPlayerState->looping(); 468 return mediaPlayerState->looping();
482} 469}
483 470
484 471
485bool PlayListWidget::last() { 472bool PlayListWidget::last() {
486 if ( mediaPlayerState->playlist() ) 473 if ( mediaPlayerState->playlist() )
487 return d->selectedFiles->last(); 474 return d->selectedFiles->last();
488 else 475 else
489 return mediaPlayerState->looping(); 476 return mediaPlayerState->looping();
490} 477}
491 478
492 479
493 void PlayListWidget::saveList() { 480 void PlayListWidget::saveList() {
494// Config config( "OpiePlayer" ); 481 writem3u();
495// config.setGroup( "PlayList" );
496
497// if(config.readBoolEntry("newPlaylist") ){
498 writem3u();
499
500// } else {
501
502// QString filename;
503// InputDialog *fileDlg = 0l;
504// fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0);
505// fileDlg->exec();
506// if( fileDlg->result() == 1 ) {
507// if ( d->current )
508// delete d->current;
509// filename = fileDlg->text();//+".playlist";
510// // qDebug("saving playlist "+filename+".playlist");
511
512// Config cfg( filename +".playlist");
513// writeConfig( cfg );
514
515// DocLnk lnk;
516// lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf");
517// //sets File property
518// lnk.setType("playlist/plain");
519// lnk.setIcon("opieplayer2/playlist2");
520// lnk.setName( filename); //sets file name
521// // qDebug(filename);
522// if(!lnk.writeLink()) {
523// qDebug("Writing doclink did not work");
524// }
525// }
526
527// config.writeEntry("CurrentPlaylist",filename);
528// setCaption(tr("OpiePlayer: ")+filename);
529// d->selectedFiles->first();
530// if(fileDlg) {
531// delete fileDlg;
532// }
533// }
534 } 482 }
535 483
536 484
537void PlayListWidget::loadList( const DocLnk & lnk) { 485void PlayListWidget::loadList( const DocLnk & lnk) {
538 QString name = lnk.name(); 486 QString name = lnk.name();
539 qDebug("currentList is "+name); 487 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
540 488
541 if( name.length()>0) { 489 if( name.length()>0) {
542 setCaption("OpiePlayer: "+name); 490 setCaption("OpiePlayer: "+name);
543 qDebug("<<<<<<<<<<<<load list "+ lnk.file()); 491 qDebug("<<<<<<<<<<<<load list "+ lnk.file());
544 clearList(); 492 clearList();
545
546// if(name.right(3) == "m3u") {
547
548 readm3u(lnk.file()); 493 readm3u(lnk.file());
549// } else {
550// / Config cfg( name+".playlist");
551// readConfig(cfg);
552
553 tabWidget->setCurrentPage(0); 494 tabWidget->setCurrentPage(0);
554
555 Config config( "OpiePlayer" );
556 config.setGroup( "PlayList" );
557 config.writeEntry("CurrentPlaylist", lnk.file());
558// // d->selectedFiles->first();
559// }
560 } 495 }
561} 496}
562 497
563 498
564void PlayListWidget::setPlaylist( bool shown ) { 499void PlayListWidget::setPlaylist( bool shown ) {
565 if ( shown ) { 500 if ( shown ) {
566 d->playListFrame->show(); 501 d->playListFrame->show();
567 } else { 502 } else {
568 d->playListFrame->hide(); 503 d->playListFrame->hide();
569 } 504 }
570} 505}
571 506
572 507
573void PlayListWidget::addSelected() { 508void PlayListWidget::addSelected() {
574 509
575 Config cfg( "OpiePlayer" );
576 cfg.setGroup("PlayList");
577 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
578 // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
579
580 switch (whichList()) { 510 switch (whichList()) {
581 case 0: //playlist 511 case 0: //playlist
582 break; 512 break;
583 case 1: { //audio 513 case 1: { //audio
584 QListViewItemIterator it( audioView ); 514 QListViewItemIterator it( audioView );
585 // iterate through all items of the listview 515 // iterate through all items of the listview
586 for ( ; it.current(); ++it ) { 516 for ( ; it.current(); ++it ) {
587 if ( it.current()->isSelected() ) { 517 if ( it.current()->isSelected() ) {
588 QListIterator<DocLnk> dit( files.children() ); 518 QListIterator<DocLnk> dit( files.children() );
589 for ( ; dit.current(); ++dit ) { 519 for ( ; dit.current(); ++dit ) {
590 if( dit.current()->name() == it.current()->text(0) ) { 520 if( dit.current()->name() == it.current()->text(0) ) {
591 if(QFileInfo( dit.current()->file()).exists()) 521 if( QFileInfo( dit.current()->file()).exists()) {
592 d->selectedFiles->addToSelection( **dit ); 522 d->selectedFiles->addToSelection( **dit );
523 audioView->setSelected( it.current(),FALSE);
524 }
593 } 525 }
594 } 526 }
595 audioView->setSelected( it.current(),FALSE);
596 } 527 }
597 } 528 }
598 tabWidget->setCurrentPage(0); 529 tabWidget->setCurrentPage(0);
530 writeCurrentM3u();
599 } 531 }
600 break; 532 break;
601 case 2: { // video 533 case 2: { // video
602 QListViewItemIterator it( videoView ); 534 QListViewItemIterator it( videoView );
603 // iterate through all items of the listview 535 // iterate through all items of the listview
604 for ( ; it.current(); ++it ) { 536 for ( ; it.current(); ++it ) {
605 if ( it.current()->isSelected() ) { 537 if ( it.current()->isSelected() ) {
606 QListIterator<DocLnk> dit( vFiles.children() ); 538 QListIterator<DocLnk> dit( vFiles.children() );
607 for ( ; dit.current(); ++dit ) { 539 for ( ; dit.current(); ++dit ) {
608 if( dit.current()->name() == it.current()->text(0) ) { 540 if( dit.current()->name() == it.current()->text(0) ) {
609 if(QFileInfo( dit.current()->file()).exists()) 541 if(QFileInfo( dit.current()->file()).exists()) {
610 d->selectedFiles->addToSelection( **dit ); 542 d->selectedFiles->addToSelection( **dit );
543 videoView->setSelected( it.current(),FALSE);
544 }
611 } 545 }
612 } 546 }
613 videoView->setSelected( it.current(),FALSE);
614 } 547 }
615 } 548 }
616 tabWidget->setCurrentPage(0); 549 tabWidget->setCurrentPage(0);
550 writeCurrentM3u();
617 } 551 }
618 break; 552 break;
619 }; 553 };
620} 554}
621 555
622 556
623void PlayListWidget::removeSelected() { 557void PlayListWidget::removeSelected() {
624 d->selectedFiles->removeSelected( ); 558 d->selectedFiles->removeSelected( );
625} 559}
626 560
627 561
628void PlayListWidget::playIt( QListViewItem *it) { 562void PlayListWidget::playIt( QListViewItem *it) {
629 if(!it) return; 563 if(!it) return;
630 mediaPlayerState->setPlaying(FALSE); 564 mediaPlayerState->setPlaying(FALSE);
631 mediaPlayerState->setPlaying(TRUE); 565 mediaPlayerState->setPlaying(TRUE);
632 d->selectedFiles->unSelect(); 566 d->selectedFiles->unSelect();
633} 567}
634 568
635 569
636void PlayListWidget::addToSelection( QListViewItem *it) { 570void PlayListWidget::addToSelection( QListViewItem *it) {
637 d->setDocumentUsed = FALSE; 571 d->setDocumentUsed = FALSE;
638 572
639 if(it) { 573 if(it) {
640 switch ( whichList()) { 574 switch ( whichList()) {
641 case 1: { 575 case 1: {
642 QListIterator<DocLnk> dit( files.children() ); 576 QListIterator<DocLnk> dit( files.children() );
643 for ( ; dit.current(); ++dit ) { 577 for ( ; dit.current(); ++dit ) {
644 if( dit.current()->name() == it->text(0)) { 578 if( dit.current()->name() == it->text(0)) {
645 if(QFileInfo( dit.current()->file()).exists()) 579 if(QFileInfo( dit.current()->file()).exists())
646 d->selectedFiles->addToSelection( **dit ); 580 d->selectedFiles->addToSelection( **dit );
647 } 581 }
648 } 582 }
583 writeCurrentM3u();
584
649 } 585 }
586
650 break; 587 break;
651 case 2: { 588 case 2: {
652 QListIterator<DocLnk> dit( vFiles.children() ); 589 QListIterator<DocLnk> dit( vFiles.children() );
653 for ( ; dit.current(); ++dit ) { 590 for ( ; dit.current(); ++dit ) {
654 if( dit.current()->name() == it->text(0)) { 591 if( dit.current()->name() == it->text(0)) {
655 if( QFileInfo( dit.current()->file()).exists() ) 592 if( QFileInfo( dit.current()->file()).exists() )
656 d->selectedFiles->addToSelection( **dit ); 593 d->selectedFiles->addToSelection( **dit );
657 } 594 }
658 } 595 }
596 writeCurrentM3u();
597
659 } 598 }
660 break; 599 break;
661 case 0: 600 case 0:
662 break; 601 break;
663 }; 602 };
664 tabWidget->setCurrentPage(0); 603 tabWidget->setCurrentPage(0);
665 } 604 }
666} 605}
667 606
668 607
669void PlayListWidget::tabChanged(QWidget *) { 608void PlayListWidget::tabChanged(QWidget *) {
670 609
671 switch ( whichList()) { 610 switch ( whichList()) {
672 case 0: 611 case 0:
673 { 612 {
674 if( !tbDeletePlaylist->isHidden() ) { 613 if( !tbDeletePlaylist->isHidden() ) {
675 tbDeletePlaylist->hide(); 614 tbDeletePlaylist->hide();
676 } 615 }
677 d->tbRemoveFromList->setEnabled(TRUE); 616 d->tbRemoveFromList->setEnabled(TRUE);
678 d->tbAddToList->setEnabled(FALSE); 617 d->tbAddToList->setEnabled(FALSE);
679 } 618 }
680 break; 619 break;
681 case 1: 620 case 1:
682 { 621 {
683 audioView->clear(); 622 audioView->clear();
684 populateAudioView(); 623 populateAudioView();
685 624
686 if( !tbDeletePlaylist->isHidden() ) { 625 if( !tbDeletePlaylist->isHidden() ) {
687 tbDeletePlaylist->hide(); 626 tbDeletePlaylist->hide();
688 } 627 }
689 d->tbRemoveFromList->setEnabled(FALSE); 628 d->tbRemoveFromList->setEnabled(FALSE);
690 d->tbAddToList->setEnabled(TRUE); 629 d->tbAddToList->setEnabled(TRUE);
691 } 630 }
692 break; 631 break;
693 case 2: 632 case 2:
694 { 633 {
695 videoView->clear(); 634 videoView->clear();
696 populateVideoView(); 635 populateVideoView();
697 if( !tbDeletePlaylist->isHidden() ) { 636 if( !tbDeletePlaylist->isHidden() ) {
698 tbDeletePlaylist->hide(); 637 tbDeletePlaylist->hide();
699 } 638 }
700 d->tbRemoveFromList->setEnabled(FALSE); 639 d->tbRemoveFromList->setEnabled(FALSE);
701 d->tbAddToList->setEnabled(TRUE); 640 d->tbAddToList->setEnabled(TRUE);
702 } 641 }
703 break; 642 break;
704 case 3: 643 case 3:
705 { 644 {
706 if( tbDeletePlaylist->isHidden() ) { 645 if( tbDeletePlaylist->isHidden() ) {
707 tbDeletePlaylist->show(); 646 tbDeletePlaylist->show();
708 } 647 }
709 playLists->reread(); 648 playLists->reread();
710 } 649 }
711 break; 650 break;
712 }; 651 };
713} 652}
714 653
715 654
716void PlayListWidget::btnPlay(bool b) { 655void PlayListWidget::btnPlay(bool b) {
717// mediaPlayerState->setPlaying(false); 656// mediaPlayerState->setPlaying(false);
718 mediaPlayerState->setPlaying(b); 657 mediaPlayerState->setPlaying(b);
719 insanityBool=FALSE; 658 insanityBool=FALSE;
720} 659}
721 660
722void PlayListWidget::deletePlaylist() { 661void PlayListWidget::deletePlaylist() {
723 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 662 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
724 (tr("You really want to delete\nthis playlist?")), 663 (tr("You really want to delete\nthis playlist?")),
725 (tr("Yes")), (tr("No")), 0 )){ 664 (tr("Yes")), (tr("No")), 0 )){
726 case 0: // Yes clicked, 665 case 0: // Yes clicked,
727 QFile().remove(playLists->selectedDocument().file()); 666 QFile().remove(playLists->selectedDocument().file());
728 QFile().remove(playLists->selectedDocument().linkFile()); 667 QFile().remove(playLists->selectedDocument().linkFile());
729 playLists->reread(); 668 playLists->reread();
730 break; 669 break;
731 case 1: // Cancel 670 case 1: // Cancel
732 break; 671 break;
733 }; 672 };
734} 673}
735 674
736 675
737void PlayListWidget::playSelected() { 676void PlayListWidget::playSelected() {
738 btnPlay( TRUE); 677 btnPlay( TRUE);
739} 678}
740 679
741 680
742void PlayListWidget::scanForAudio() { 681void PlayListWidget::scanForAudio() {
743// qDebug("scan for audio"); 682// qDebug("scan for audio");
744 files.detachChildren(); 683 files.detachChildren();
745 QListIterator<DocLnk> sdit( files.children() ); 684 QListIterator<DocLnk> sdit( files.children() );
746 for ( ; sdit.current(); ++sdit ) { 685 for ( ; sdit.current(); ++sdit ) {
747 delete sdit.current(); 686 delete sdit.current();
748 } 687 }
749// Global::findDocuments( &files, "audio/*"); 688// Global::findDocuments( &files, "audio/*");
750 Global::findDocuments( &files, "audio/mpeg;audio/x-wav;audio/x-ogg"); 689 Global::findDocuments( &files, "audio/mpeg;audio/x-wav;audio/x-ogg");
751 audioScan = TRUE; 690 audioScan = TRUE;
752} 691}
753 692
754void PlayListWidget::scanForVideo() { 693void PlayListWidget::scanForVideo() {
@@ -757,358 +696,371 @@ void PlayListWidget::scanForVideo() {
757 QListIterator<DocLnk> sdit( vFiles.children() ); 696 QListIterator<DocLnk> sdit( vFiles.children() );
758 for ( ; sdit.current(); ++sdit ) { 697 for ( ; sdit.current(); ++sdit ) {
759 delete sdit.current(); 698 delete sdit.current();
760 } 699 }
761 Global::findDocuments(&vFiles, "video/*"); 700 Global::findDocuments(&vFiles, "video/*");
762 videoScan = TRUE; 701 videoScan = TRUE;
763} 702}
764 703
765void PlayListWidget::populateAudioView() { 704void PlayListWidget::populateAudioView() {
766 audioView->clear(); 705 audioView->clear();
767 StorageInfo storageInfo; 706 StorageInfo storageInfo;
768 const QList<FileSystem> &fs = storageInfo.fileSystems(); 707 const QList<FileSystem> &fs = storageInfo.fileSystems();
769 if(!audioScan) { 708 if(!audioScan) {
770 scanForAudio(); 709 scanForAudio();
771 } 710 }
772 711
773 QListIterator<DocLnk> dit( files.children() ); 712 QListIterator<DocLnk> dit( files.children() );
774 QListIterator<FileSystem> it ( fs ); 713 QListIterator<FileSystem> it ( fs );
775 714
776 QString storage; 715 QString storage;
777 for ( ; dit.current(); ++dit ) { 716 for ( ; dit.current(); ++dit ) {
778 for( ; it.current(); ++it ){ 717 for( ; it.current(); ++it ){
779 const QString name = (*it)->name(); 718 const QString name = (*it)->name();
780 const QString path = (*it)->path(); 719 const QString path = (*it)->path();
781 if(dit.current()->file().find(path) != -1 ) { 720 if(dit.current()->file().find(path) != -1 ) {
782 storage = name; 721 storage = name;
783 } 722 }
784 } 723 }
785 724
786 QListViewItem * newItem; 725 QListViewItem * newItem;
787 if ( QFile( dit.current()->file()).exists() || 726 if ( QFile( dit.current()->file()).exists() ||
788 dit.current()->file().left(4) == "http" ) { 727 dit.current()->file().left(4) == "http" ) {
789 long size; 728 long size;
790 if( dit.current()->file().left(4) == "http" ) 729 if( dit.current()->file().left(4) == "http" )
791 size=0; 730 size=0;
792 else 731 else
793 size = QFile( dit.current()->file() ).size(); 732 size = QFile( dit.current()->file() ).size();
794 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), 733 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(),
795 QString::number(size ), storage, dit.current()->file()); 734 QString::number(size ), storage, dit.current()->file());
796 newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); 735 newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) );
797 } 736 }
798 } 737 }
799} 738}
800 739
801 740
802void PlayListWidget::populateVideoView() { 741void PlayListWidget::populateVideoView() {
803 videoView->clear(); 742 videoView->clear();
804 StorageInfo storageInfo; 743 StorageInfo storageInfo;
805 const QList<FileSystem> &fs = storageInfo.fileSystems(); 744 const QList<FileSystem> &fs = storageInfo.fileSystems();
806 745
807 if(!videoScan ) { 746 if(!videoScan ) {
808 scanForVideo(); 747 scanForVideo();
809 } 748 }
810 749
811 QListIterator<DocLnk> Vdit( vFiles.children() ); 750 QListIterator<DocLnk> Vdit( vFiles.children() );
812 QListIterator<FileSystem> it ( fs ); 751 QListIterator<FileSystem> it ( fs );
813 videoView->clear(); 752 videoView->clear();
814 QString storage, pathName; 753 QString storage, pathName;
815 for ( ; Vdit.current(); ++Vdit ) { 754 for ( ; Vdit.current(); ++Vdit ) {
816 for( ; it.current(); ++it ) { 755 for( ; it.current(); ++it ) {
817 const QString name = (*it)->name(); 756 const QString name = (*it)->name();
818 const QString path = (*it)->path(); 757 const QString path = (*it)->path();
819 if( Vdit.current()->file().find(path) != -1 ) { 758 if( Vdit.current()->file().find(path) != -1 ) {
820 storage=name; 759 storage=name;
821 pathName=path; 760 pathName=path;
822 } 761 }
823 } 762 }
824 763
825 QListViewItem * newItem; 764 QListViewItem * newItem;
826 if ( QFile( Vdit.current()->file() ).exists() ) { 765 if ( QFile( Vdit.current()->file() ).exists() ) {
827 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), 766 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(),
828 QString::number( QFile( Vdit.current()->file() ).size() ), 767 QString::number( QFile( Vdit.current()->file() ).size() ),
829 storage, Vdit.current()->file()); 768 storage, Vdit.current()->file());
830 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); 769 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) );
831 } 770 }
832 } 771 }
833} 772}
834 773
835 774
836void PlayListWidget::openFile() { 775void PlayListWidget::openFile() {
837 QString filename, name; 776 QString filename, name;
838 InputDialog *fileDlg; 777 InputDialog *fileDlg;
839 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 778 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
840 fileDlg->exec(); 779 fileDlg->exec();
841 if( fileDlg->result() == 1 ) { 780 if( fileDlg->result() == 1 ) {
842 filename = fileDlg->text(); 781 filename = fileDlg->text();
843 782
844 qDebug( "Selected filename is " + filename ); 783 qDebug( "Selected filename is " + filename );
845 784
846 if(filename.left(4) == "http") { //if http, lets write a new m3u 785 if(filename.left(4) == "http") { //if http, lets write a new m3u
847 Om3u *m3uList; 786 Om3u *m3uList;
848 DocLnk lnk; 787 DocLnk lnk;
849 QString m3uFile, m3uFilePath; 788 QString m3uFile, m3uFilePath;
850 789
851 if(filename.find(":",8,TRUE) != -1) { //found a port 790 if(filename.find(":",8,TRUE) != -1) { //found a port
852 m3uFile = filename.left( filename.find( ":",8,TRUE)); 791 m3uFile = filename.left( filename.find( ":",8,TRUE));
853
854 m3uFile = m3uFile.right( 7); 792 m3uFile = m3uFile.right( 7);
855
856 } else if(filename.left(4) == "http"){ 793 } else if(filename.left(4) == "http"){
857
858 m3uFile=filename; 794 m3uFile=filename;
859 m3uFile = m3uFile.right( m3uFile.length() - 7); 795 m3uFile = m3uFile.right( m3uFile.length() - 7);
860
861 } else{ 796 } else{
862 m3uFile=filename; 797 m3uFile=filename;
863 } 798 }
864
865// qDebug( m3uFile); 799// qDebug( m3uFile);
866 800
867//this is where this new m3u is going to live at 801//this is where this new m3u is going to live at
868 m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u"; 802 m3uFilePath = QDir::homeDirPath() + "/" + m3uFile + ".m3u";
869// m3uFile += ".m3u"; 803// m3uFile += ".m3u";
870 m3uList = new Om3u( m3uFile+".m3u"); 804 m3uList = new Om3u( m3uFile+".m3u", IO_ReadWrite );
871
872 m3uList->add( filename); 805 m3uList->add( filename);
873 m3uList->write(); 806 m3uList->write();
874 if(m3uList) delete m3uList; 807 if(m3uList) delete m3uList;
875
876// qDebug( m3uFile); 808// qDebug( m3uFile);
877 lnk.setName( filename ); //sets file name 809 lnk.setName( filename ); //sets file name
878 lnk.setFile( m3uFilePath ); //sets File property 810 lnk.setFile( m3uFilePath ); //sets File property
879 lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() ); 811 lnk.setType( MimeType( QFile::encodeName(m3uFilePath) ).id() );
880 812
881 lnk.setExec( "opieplayer2" ); 813 lnk.setExec( "opieplayer2" );
882 lnk.setIcon("opieplayer2/playlist2"); 814 lnk.setIcon("opieplayer2/playlist2");
883 815
884 if( !lnk.writeLink() ) { 816 if( !lnk.writeLink() ) {
885 qDebug( "Writing doclink did not work" ); 817 qDebug( "Writing doclink did not work" );
886 } 818 }
887 d->selectedFiles->addToSelection( lnk ); 819 d->selectedFiles->addToSelection( lnk );
888 820
889 } 821 }
890 else if( filename.right( 3 ) == "m3u" ) { 822 else if( filename.right( 3 ) == "m3u" ) {
891 readm3u( filename ); 823 readm3u( filename );
892 824
893 } else if( filename.right(3) == "pls" ) { 825 } else if( filename.right(3) == "pls" ) {
894 readPls( filename ); 826 readPls( filename );
895 } 827 }
896 } 828 }
897 if( fileDlg ) { 829 if( fileDlg ) {
898 delete fileDlg; 830 delete fileDlg;
899 } 831 }
900} 832}
901 833
902/* 834/*
903reads m3u and adds files/urls to playlist */ 835reads m3u and adds files/urls to playlist */
904void PlayListWidget::readm3u( const QString &filename ) { 836void PlayListWidget::readm3u( const QString &filename ) {
905 qDebug( "read m3u filename " + filename ); 837 qDebug( "read m3u filename " + filename );
906 838
907 Om3u *m3uList; 839 Om3u *m3uList;
908 QString s, name; 840 QString s, name;
909 m3uList = new Om3u( filename); 841 m3uList = new Om3u( filename, IO_ReadOnly );
910 m3uList->readM3u(); 842 m3uList->readM3u();
911 DocLnk lnk; 843 DocLnk lnk;
912 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 844 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
913 s = *it; 845 s = *it;
914 s.replace( QRegExp( "%20" )," " ); 846 s.replace( QRegExp( "%20" )," " );
915 qDebug("reading "+ s); 847// qDebug("reading "+ s);
916 848
917 if( QFileInfo( s ).exists() ) { 849 if( QFileInfo( s ).exists() ) {
918 lnk.setName( QFileInfo(s).baseName()); 850 lnk.setName( QFileInfo(s).baseName());
919 qDebug("set link "+s); 851// qDebug("set link "+s);
920 if(s.at(s.length()-4) == '.') //if regular file 852 if(s.at(s.length()-4) == '.') //if regular file
921 lnk.setFile( s); 853 lnk.setFile( s);
922 else 854 else
923 lnk.setFile( s+"/"); //if url with no extension 855 lnk.setFile( s+"/"); //if url with no extension
924 856
925 d->selectedFiles->addToSelection( lnk ); 857 d->selectedFiles->addToSelection( lnk );
926 } 858 }
927 } 859 }
928 Config config( "OpiePlayer" ); 860 Config config( "OpiePlayer" );
929 config.setGroup( "PlayList" ); 861 config.setGroup( "PlayList" );
930 862
931 config.writeEntry("CurrentPlaylist",filename); 863 config.writeEntry("CurrentPlaylist",filename);
864 config.write();
932 currentPlayList=filename; 865 currentPlayList=filename;
933 866
934 m3uList->close(); 867 m3uList->close();
935 if(m3uList) delete m3uList; 868 if(m3uList) delete m3uList;
936 869
937 d->selectedFiles->setSelectedItem( s); 870 d->selectedFiles->setSelectedItem( s);
938 setCaption(tr("OpiePlayer: ")+ QFileInfo(s).baseName()); 871 setCaption(tr("OpiePlayer: ")+ filename);
939 872
940} 873}
941 874
942/* 875/*
943reads pls and adds files/urls to playlist */ 876reads pls and adds files/urls to playlist */
944void PlayListWidget::readPls( const QString &filename ) { 877void PlayListWidget::readPls( const QString &filename ) {
945 878
946 qDebug( "pls filename is " + filename ); 879 qDebug( "pls filename is " + filename );
947 Om3u *m3uList; 880 Om3u *m3uList;
948 QString s, name; 881 QString s, name;
949 m3uList = new Om3u( filename); 882 m3uList = new Om3u( filename, IO_ReadOnly );
950 m3uList->readPls(); 883 m3uList->readPls();
951 884
952 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 885 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
953 s = *it; 886 s = *it;
954 s.replace( QRegExp( "%20" )," " ); 887 // s.replace( QRegExp( "%20" )," " );
955 DocLnk lnk( s ); 888 DocLnk lnk( s );
956 QFileInfo f( s ); 889 QFileInfo f( s );
957 QString name = f.baseName(); 890 QString name = f.baseName();
958 891
959 if( name.left( 4 ) == "http" ) { 892 if( name.left( 4 ) == "http" ) {
960 name = s.right( s.length() - 7); 893 name = s.right( s.length() - 7);
961 } else { 894 } else {
962 name = s; 895 name = s;
963 } 896 }
964 897
965 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 898 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
966 899
967 lnk.setName( name ); 900 lnk.setName( name );
968 if( s.at( s.length() - 4) == '.') {// if this is probably a file 901 if( s.at( s.length() - 4) == '.') {// if this is probably a file
969 lnk.setFile( s ); 902 lnk.setFile( s );
970 } else { //if its a url 903 } else { //if its a url
971 if( name.right( 1 ).find( '/' ) == -1) { 904 if( name.right( 1 ).find( '/' ) == -1) {
972 s += "/"; 905 s += "/";
973 } 906 }
974 lnk.setFile( s ); 907 lnk.setFile( s );
975 } 908 }
976 lnk.setType( "audio/x-mpegurl" ); 909 lnk.setType( "audio/x-mpegurl" );
977 910
978 lnk.writeLink(); 911 lnk.writeLink();
979 d->selectedFiles->addToSelection( lnk ); 912 d->selectedFiles->addToSelection( lnk );
980 } 913 }
981 914
982 m3uList->close(); 915 m3uList->close();
983 if(m3uList) delete m3uList; 916 if(m3uList) delete m3uList;
984} 917}
985 918
986/* 919/*
920 writes current playlist to current m3u file */
921void PlayListWidget::writeCurrentM3u() {
922 qDebug("writting to current m3u");
923 Config cfg( "OpiePlayer" );
924 cfg.setGroup("PlayList");
925 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","");
926 // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
927 Om3u *m3uList;
928 m3uList = new Om3u( currentPlaylist, IO_ReadWrite );
929 d->selectedFiles->first();
930
931 do {
932 m3uList->add( d->selectedFiles->current()->file());
933 }
934 while ( d->selectedFiles->next() );
935 // qDebug( list );
936 m3uList->write();
937 if(m3uList) delete m3uList;
938}
939
940 /*
987 writes current playlist to m3u file */ 941 writes current playlist to m3u file */
988void PlayListWidget::writem3u() { 942void PlayListWidget::writem3u() {
989 InputDialog *fileDlg; 943 InputDialog *fileDlg;
990 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); 944 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
991 fileDlg->exec(); 945 fileDlg->exec();
992 QString name, filename, list; 946 QString name, filename, list;
993 Om3u *m3uList; 947 Om3u *m3uList;
994 948
995 if( fileDlg->result() == 1 ) { 949 if( fileDlg->result() == 1 ) {
996 name = fileDlg->text(); 950 name = fileDlg->text();
997 qDebug( filename ); 951 qDebug( filename );
998 952
999 if( name.left( 1) != "/" ) { 953 if( name.left( 1) != "/" ) {
1000 filename = QPEApplication::documentDir() + "/" + name; 954 filename = QPEApplication::documentDir() + "/" + name;
1001 } 955 }
1002 956
1003 if( name.right( 3 ) != "m3u" ) { 957 if( name.right( 3 ) != "m3u" ) {
1004 filename = QPEApplication::documentDir() + "/" +name+".m3u"; 958 filename = QPEApplication::documentDir() + "/" +name+".m3u";
1005 } 959 }
1006 960
1007 m3uList = new Om3u(filename); 961 m3uList = new Om3u(filename, IO_ReadWrite);
1008 962
1009 d->selectedFiles->first(); 963 d->selectedFiles->first();
1010 964
1011 do { 965 do {
1012 m3uList->add( d->selectedFiles->current()->file()); 966 m3uList->add( d->selectedFiles->current()->file());
1013 } 967 }
1014 while ( d->selectedFiles->next() ); 968 while ( d->selectedFiles->next() );
1015// qDebug( list ); 969// qDebug( list );
1016
1017 m3uList->write(); 970 m3uList->write();
1018 m3uList->close();
1019 } 971 }
1020 if(m3uList) delete m3uList; 972 if(m3uList) delete m3uList;
1021 if(fileDlg) delete fileDlg; 973 if(fileDlg) delete fileDlg;
1022 974
1023 DocLnk lnk; 975 DocLnk lnk;
1024 lnk.setFile( filename); 976 lnk.setFile( filename);
1025 lnk.setIcon("opieplayer2/playlist2"); 977 lnk.setIcon("opieplayer2/playlist2");
1026 lnk.setName( name); //sets file name 978 lnk.setName( name); //sets file name
1027 979
1028// qDebug(filename); 980// qDebug(filename);
1029 Config config( "OpiePlayer" ); 981 Config config( "OpiePlayer" );
1030 config.setGroup( "PlayList" ); 982 config.setGroup( "PlayList" );
1031 983
1032 config.writeEntry("CurrentPlaylist",filename); 984 config.writeEntry("CurrentPlaylist",filename);
1033 currentPlayList=filename; 985 currentPlayList=filename;
1034 986
1035 if(!lnk.writeLink()) { 987 if(!lnk.writeLink()) {
1036 qDebug("Writing doclink did not work"); 988 qDebug("Writing doclink did not work");
1037 } 989 }
1038 990
1039 setCaption(tr("OpiePlayer: ") + name); 991 setCaption(tr("OpiePlayer: ") + name);
1040} 992}
1041 993
1042void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 994void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
1043 switch ( e->key() ) { 995 switch ( e->key() ) {
1044 ////////////////////////////// Zaurus keys 996 ////////////////////////////// Zaurus keys
1045 case Key_F9: //activity 997 case Key_F9: //activity
1046 // if(audioUI->isHidden()) 998 // if(audioUI->isHidden())
1047 // audioUI->showMaximized(); 999 // audioUI->showMaximized();
1048 break; 1000 break;
1049 case Key_F10: //contacts 1001 case Key_F10: //contacts
1050 // if( videoUI->isHidden()) 1002 // if( videoUI->isHidden())
1051 // videoUI->showMaximized(); 1003 // videoUI->showMaximized();
1052 break; 1004 break;
1053 case Key_F11: //menu 1005 case Key_F11: //menu
1054 break; 1006 break;
1055 case Key_F12: //home 1007 case Key_F12: //home
1056 // doBlank(); 1008 // doBlank();
1057 break; 1009 break;
1058 case Key_F13: //mail 1010 case Key_F13: //mail
1059 // doUnblank(); 1011 // doUnblank();
1060 break; 1012 break;
1061 case Key_Q: //add to playlist 1013 case Key_Q: //add to playlist
1062 addSelected(); 1014 addSelected();
1063 break; 1015 break;
1064 case Key_R: //remove from playlist 1016 case Key_R: //remove from playlist
1065 removeSelected(); 1017 removeSelected();
1066 break; 1018 break;
1067 // case Key_P: //play 1019 // case Key_P: //play
1068 // qDebug("Play"); 1020 // qDebug("Play");
1069 // playSelected(); 1021 // playSelected();
1070 // break; 1022 // break;
1071 case Key_Space: 1023 case Key_Space:
1072 // playSelected(); puh 1024 // playSelected(); puh
1073 break; 1025 break;
1074 case Key_1: 1026 case Key_1:
1075 tabWidget->setCurrentPage( 0 ); 1027 tabWidget->setCurrentPage( 0 );
1076 break; 1028 break;
1077 case Key_2: 1029 case Key_2:
1078 tabWidget->setCurrentPage( 1 ); 1030 tabWidget->setCurrentPage( 1 );
1079 break; 1031 break;
1080 case Key_3: 1032 case Key_3:
1081 tabWidget->setCurrentPage( 2 ); 1033 tabWidget->setCurrentPage( 2 );
1082 break; 1034 break;
1083 case Key_4: 1035 case Key_4:
1084 tabWidget->setCurrentPage( 3 ); 1036 tabWidget->setCurrentPage( 3 );
1085 break; 1037 break;
1086 case Key_Down: 1038 case Key_Down:
1087 if ( !d->selectedFiles->next() ) 1039 if ( !d->selectedFiles->next() )
1088 d->selectedFiles->first(); 1040 d->selectedFiles->first();
1089 break; 1041 break;
1090 case Key_Up: 1042 case Key_Up:
1091 if ( !d->selectedFiles->prev() ) 1043 if ( !d->selectedFiles->prev() )
1092 // d->selectedFiles->last(); 1044 // d->selectedFiles->last();
1093 break; 1045 break;
1094 } 1046 }
1095} 1047}
1096 1048
1097void PlayListWidget::pmViewActivated(int index) { 1049void PlayListWidget::pmViewActivated(int index) {
1098// qDebug("%d", index); 1050// qDebug("%d", index);
1099 switch(index) { 1051 switch(index) {
1100 case -16: 1052 case -16:
1101 { 1053 {
1102 mediaPlayerState->toggleFullscreen(); 1054 mediaPlayerState->toggleFullscreen();
1103 bool b=mediaPlayerState->fullscreen(); 1055 bool b=mediaPlayerState->fullscreen();
1104 pmView->setItemChecked( index, b); 1056 pmView->setItemChecked( index, b);
1105 Config cfg( "OpiePlayer" ); 1057 Config cfg( "OpiePlayer" );
1106 cfg.writeEntry( "FullScreen", b ); 1058 cfg.writeEntry( "FullScreen", b );
1107 } 1059 }
1108 break; 1060 break;
1109 }; 1061 };
1110} 1062}
1111 1063
1112void PlayListWidget::populateSkinsMenu() { 1064void PlayListWidget::populateSkinsMenu() {
1113 int item = 0; 1065 int item = 0;
1114 defaultSkinIndex = 0; 1066 defaultSkinIndex = 0;
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.h b/noncore/multimedia/opieplayer2/playlistwidget.h
index 428821a..8a77619 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.h
+++ b/noncore/multimedia/opieplayer2/playlistwidget.h
@@ -1,121 +1,122 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; General Public License for more 22..}^=.=       =       ; General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = General Public License along with 26  -_. . .   )=.  = General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef PLAY_LIST_WIDGET_H 34#ifndef PLAY_LIST_WIDGET_H
35#define PLAY_LIST_WIDGET_H 35#define PLAY_LIST_WIDGET_H
36 36
37#include <qmainwindow.h> 37#include <qmainwindow.h>
38#include <qpe/applnk.h> 38#include <qpe/applnk.h>
39#include <qtabwidget.h> 39#include <qtabwidget.h>
40#include <qpe/fileselector.h> 40#include <qpe/fileselector.h>
41#include <qpushbutton.h> 41#include <qpushbutton.h>
42#include <qpopupmenu.h> 42#include <qpopupmenu.h>
43 43
44#include "playlistwidgetgui.h" 44#include "playlistwidgetgui.h"
45 45
46 46
47//class PlayListWidgetPrivate; 47//class PlayListWidgetPrivate;
48class Config; 48class Config;
49class QListViewItem; 49class QListViewItem;
50class QListView; 50class QListView;
51class QPoint; 51class QPoint;
52class QAction; 52class QAction;
53class QLabel; 53class QLabel;
54 54
55class PlayListWidget : public PlayListWidgetGui { 55class PlayListWidget : public PlayListWidgetGui {
56 Q_OBJECT 56 Q_OBJECT
57public: 57public:
58 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 ); 58 PlayListWidget( QWidget* parent=0, const char* name=0, WFlags fl=0 );
59 ~PlayListWidget(); 59 ~PlayListWidget();
60 DocLnkSet files; 60 DocLnkSet files;
61 DocLnkSet vFiles; 61 DocLnkSet vFiles;
62 bool fromSetDocument; 62 bool fromSetDocument;
63 bool insanityBool; 63 bool insanityBool;
64 QString setDocFileRef, currentPlayList; 64 QString setDocFileRef, currentPlayList;
65 // retrieve the current playlist entry (media file link) 65 // retrieve the current playlist entry (media file link)
66 const DocLnk *current(); 66 const DocLnk *current();
67 void useSelectedDocument(); 67 void useSelectedDocument();
68 int selected; 68 int selected;
69 int whichList(); 69 int whichList();
70 70
71public slots: 71public slots:
72 bool first(); 72 bool first();
73 bool last(); 73 bool last();
74 bool next(); 74 bool next();
75 bool prev(); 75 bool prev();
76 void writeConfig( Config& cfg ) const; 76 void writeConfig( Config& cfg ) const;
77 QString currentFileListPathName(); 77 QString currentFileListPathName();
78protected: 78protected:
79 void keyReleaseEvent( QKeyEvent *e); 79 void keyReleaseEvent( QKeyEvent *e);
80 80
81private: 81private:
82 int defaultSkinIndex; 82 int defaultSkinIndex;
83 bool audioScan, videoScan; 83 bool audioScan, videoScan;
84 void readm3u(const QString &); 84 void readm3u(const QString &);
85 void readPls(const QString &); 85 void readPls(const QString &);
86 void initializeStates(); 86 void initializeStates();
87 void readConfig( Config& cfg ); 87 void readConfig( Config& cfg );
88 void populateAudioView(); 88 void populateAudioView();
89 void populateVideoView(); 89 void populateVideoView();
90 90
91private slots: 91private slots:
92 void populateSkinsMenu(); 92 void populateSkinsMenu();
93 void skinsMenuActivated(int); 93 void skinsMenuActivated(int);
94 void pmViewActivated(int); 94 void pmViewActivated(int);
95 void writem3u(); 95 void writem3u();
96 void writeCurrentM3u();
96 void scanForAudio(); 97 void scanForAudio();
97 void scanForVideo(); 98 void scanForVideo();
98 void openFile(); 99 void openFile();
99 void setDocument( const QString& fileref ); 100 void setDocument( const QString& fileref );
100 void addToSelection( const DocLnk& ); // Add a media file to the playlist 101 void addToSelection( const DocLnk& ); // Add a media file to the playlist
101 void addToSelection( QListViewItem* ); // Add a media file to the playlist 102 void addToSelection( QListViewItem* ); // Add a media file to the playlist
102 void setPlaylist( bool ); // Show/Hide the playlist 103 void setPlaylist( bool ); // Show/Hide the playlist
103 void clearList(); 104 void clearList();
104 void addAllToList(); 105 void addAllToList();
105 void addAllMusicToList(); 106 void addAllMusicToList();
106 void addAllVideoToList(); 107 void addAllVideoToList();
107 void saveList(); // Save the playlist 108 void saveList(); // Save the playlist
108 void loadList( const DocLnk &); // Load a playlist 109 void loadList( const DocLnk &); // Load a playlist
109 void playIt( QListViewItem *); 110 void playIt( QListViewItem *);
110 void btnPlay(bool); 111 void btnPlay(bool);
111 void deletePlaylist(); 112 void deletePlaylist();
112 void addSelected(); 113 void addSelected();
113 void removeSelected(); 114 void removeSelected();
114 void tabChanged(QWidget*); 115 void tabChanged(QWidget*);
115 void viewPressed( int, QListViewItem *, const QPoint&, int); 116 void viewPressed( int, QListViewItem *, const QPoint&, int);
116 void playlistViewPressed( int, QListViewItem *, const QPoint&, int); 117 void playlistViewPressed( int, QListViewItem *, const QPoint&, int);
117 void playSelected(); 118 void playSelected();
118}; 119};
119 120
120#endif // PLAY_LIST_WIDGET_H 121#endif // PLAY_LIST_WIDGET_H
121 122