summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/playlistwidget.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/playlistwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp88
1 files changed, 44 insertions, 44 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 9a9e1ec..0a84268 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -1,745 +1,745 @@
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,2003 Max Reiss <harlekin@handhelds.org> 4              Copyright (c) 2002,2003 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#include <qtoolbar.h> 34#include <qtoolbar.h>
35 35
36#include <opie/ofiledialog.h> 36#include <opie/ofiledialog.h>
37 37
38#include <qmessagebox.h> 38#include <qmessagebox.h>
39 39
40#include "playlistselection.h" 40#include "playlistselection.h"
41#include "playlistwidget.h" 41#include "playlistwidget.h"
42#include "mediaplayer.h" 42#include "mediaplayer.h"
43#include "mediaplayerstate.h" 43#include "mediaplayerstate.h"
44#include "inputDialog.h" 44#include "inputDialog.h"
45#include "om3u.h" 45#include "om3u.h"
46#include "playlistfileview.h" 46#include "playlistfileview.h"
47 47
48//only needed for the random play 48//only needed for the random play
49#include <assert.h> 49#include <assert.h>
50 50
51PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl ) 51PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl )
52 : PlayListWidgetGui( parent, "playList" ) , currentFileListView( 0 ) 52 : PlayListWidgetGui( parent, "playList" ) , currentFileListView( 0 )
53{ 53{
54 mediaPlayerState = new MediaPlayerState(0, "mediaPlayerState" ); 54 mediaPlayerState = new MediaPlayerState(0, "mediaPlayerState" );
55 m_mp = new MediaPlayer(*this, *mediaPlayerState, 0, "mediaPlayer"); 55 m_mp = new MediaPlayer(*this, *mediaPlayerState, 0, "mediaPlayer");
56 56
57 57
58 58
59 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 59 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
60 "opieplayer2/add_to_playlist", 60 "opieplayer2/add_to_playlist",
61 this , SLOT(addSelected() ) ); 61 this , SLOT(addSelected() ) );
62 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 62 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
63 "opieplayer2/remove_from_playlist", 63 "opieplayer2/remove_from_playlist",
64 this , SLOT(removeSelected() ) ); 64 this , SLOT(removeSelected() ) );
65 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 65 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
66 this , SLOT( btnPlay( bool) ), TRUE ); 66 this , SLOT( btnPlay(bool) ), TRUE );
67 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 67 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
68 mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); 68 mediaPlayerState, SLOT( setShuffled(bool) ), TRUE );
69 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 69 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
70 mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); 70 mediaPlayerState, SLOT( setLooping(bool) ), TRUE );
71 71
72 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 72 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
73 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 73 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
74 this, SLOT( addAllMusicToList() ) ); 74 this, SLOT( addAllMusicToList() ) );
75 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 75 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
76 this, SLOT( addAllVideoToList() ) ); 76 this, SLOT( addAllVideoToList() ) );
77 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 77 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
78 this, SLOT( addAllToList() ) ); 78 this, SLOT( addAllToList() ) );
79 pmPlayList->insertSeparator(-1); 79 pmPlayList->insertSeparator(-1);
80 (void)new MenuItem( pmPlayList, tr( "Add File" ), 80 (void)new MenuItem( pmPlayList, tr( "Add File" ),
81 this,SLOT( openFile() ) ); 81 this,SLOT( openFile() ) );
82 (void)new MenuItem( pmPlayList, tr("Add URL"), 82 (void)new MenuItem( pmPlayList, tr("Add URL"),
83 this,SLOT( openURL() ) ); 83 this,SLOT( openURL() ) );
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(writem3u() ) ); 86 this, SLOT(writem3u() ) );
87 pmPlayList->insertSeparator(-1); 87 pmPlayList->insertSeparator(-1);
88 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 88 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
89 audioView, SLOT( scanFiles() ) ); 89 audioView, SLOT( scanFiles() ) );
90 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 90 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
91 videoView, SLOT( scanFiles() ) ); 91 videoView, SLOT( scanFiles() ) );
92 92
93 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 93 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
94 mediaPlayerState, SLOT( toggleFullscreen() ) ); 94 mediaPlayerState, SLOT( toggleFullscreen() ) );
95 95
96 Config cfg( "OpiePlayer" ); 96 Config cfg( "OpiePlayer" );
97 bool b= cfg.readBoolEntry("FullScreen", 0); 97 bool b= cfg.readBoolEntry("FullScreen", 0);
98 mediaPlayerState->setFullscreen( b ); 98 mediaPlayerState->setFullscreen( b );
99 pmView->setItemChecked( -16, b ); 99 pmView->setItemChecked( -16, b );
100 100
101 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 101 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
102 d->selectedFiles, SLOT(moveSelectedUp() ) ); 102 d->selectedFiles, SLOT(moveSelectedUp() ) );
103 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 103 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
104 d->selectedFiles, SLOT(removeSelected() ) ); 104 d->selectedFiles, SLOT(removeSelected() ) );
105 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 105 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
106 d->selectedFiles, SLOT(moveSelectedDown() ) ); 106 d->selectedFiles, SLOT(moveSelectedDown() ) );
107 QVBox *stretch2 = new QVBox( vbox1 ); 107 QVBox *stretch2 = new QVBox( vbox1 );
108 108
109 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 109 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
110 SLOT( deletePlaylist() ) ); 110 SLOT( deletePlaylist() ) );
111 connect( pmView, SIGNAL( activated( int ) ), 111 connect( pmView, SIGNAL( activated(int) ),
112 this, SLOT( pmViewActivated( int ) ) ); 112 this, SLOT( pmViewActivated(int) ) );
113 connect( skinsMenu, SIGNAL( activated( int ) ) , 113 connect( skinsMenu, SIGNAL( activated(int) ) ,
114 this, SLOT( skinsMenuActivated( int ) ) ); 114 this, SLOT( skinsMenuActivated(int) ) );
115 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 115 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
116 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 116 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) );
117 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 117 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
118 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 118 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
119 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 119 connect( audioView, SIGNAL( returnPressed(QListViewItem*) ),
120 this,SLOT( playIt( QListViewItem *) ) ); 120 this,SLOT( playIt(QListViewItem*) ) );
121 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 121 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ),
122 this, SLOT( addToSelection( QListViewItem *) ) ); 122 this, SLOT( addToSelection(QListViewItem*) ) );
123 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 123 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
124 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 124 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
125 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 125 connect( videoView, SIGNAL( returnPressed(QListViewItem*) ),
126 this,SLOT( playIt( QListViewItem *) ) ); 126 this,SLOT( playIt(QListViewItem*) ) );
127 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 127 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ),
128 this, SLOT( addToSelection( QListViewItem *) ) ); 128 this, SLOT( addToSelection(QListViewItem*) ) );
129 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 129 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ),
130 this, SLOT( loadList( const DocLnk & ) ) ); 130 this, SLOT( loadList(const DocLnk&) ) );
131 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 131 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
132 this, SLOT( tabChanged( QWidget* ) ) ); 132 this, SLOT( tabChanged(QWidget*) ) );
133 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), 133 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ),
134 d->tbPlay, SLOT( setOn( bool ) ) ); 134 d->tbPlay, SLOT( setOn(bool) ) );
135 connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 135 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ),
136 d->tbLoop, SLOT( setOn( bool ) ) ); 136 d->tbLoop, SLOT( setOn(bool) ) );
137 connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 137 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ),
138 d->tbShuffle, SLOT( setOn( bool ) ) ); 138 d->tbShuffle, SLOT( setOn(bool) ) );
139 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 139 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ),
140 this, SLOT( playIt( QListViewItem *) ) ); 140 this, SLOT( playIt(QListViewItem*) ) );
141 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 141 connect ( gammaSlider, SIGNAL( valueChanged(int) ),
142 mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 142 mediaPlayerState, SLOT( setVideoGamma(int) ) );
143 143
144 connect( this, SIGNAL(skinSelected() ), 144 connect( this, SIGNAL(skinSelected() ),
145 m_mp, SLOT( reloadSkins() ) ); 145 m_mp, SLOT( reloadSkins() ) );
146 146
147 // see which skins are installed 147 // see which skins are installed
148 populateSkinsMenu(); 148 populateSkinsMenu();
149 initializeStates(); 149 initializeStates();
150 150
151 channel = new QCopChannel( "QPE/Application/opieplayer2", this ); 151 channel = new QCopChannel( "QPE/Application/opieplayer2", this );
152 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 152 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
153 this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); 153 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) );
154 154
155 155
156 cfg.setGroup("PlayList"); 156 cfg.setGroup("PlayList");
157 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 157 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
158 loadList(DocLnk( currentPlaylist ) ); 158 loadList(DocLnk( currentPlaylist ) );
159 159
160 tabWidget->showPage( playListTab ); 160 tabWidget->showPage( playListTab );
161} 161}
162 162
163 163
164PlayListWidget::~PlayListWidget() { 164PlayListWidget::~PlayListWidget() {
165 delete d; 165 delete d;
166 delete m_mp; 166 delete m_mp;
167} 167}
168 168
169 169
170void PlayListWidget::initializeStates() { 170void PlayListWidget::initializeStates() {
171 d->tbPlay->setOn( mediaPlayerState->isPlaying() ); 171 d->tbPlay->setOn( mediaPlayerState->isPlaying() );
172 d->tbLoop->setOn( mediaPlayerState->isLooping() ); 172 d->tbLoop->setOn( mediaPlayerState->isLooping() );
173 d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); 173 d->tbShuffle->setOn( mediaPlayerState->isShuffled() );
174 d->playListFrame->show(); 174 d->playListFrame->show();
175} 175}
176 176
177void PlayListWidget::writeDefaultPlaylist() { 177void PlayListWidget::writeDefaultPlaylist() {
178 178
179 Config config( "OpiePlayer" ); 179 Config config( "OpiePlayer" );
180 config.setGroup( "PlayList" ); 180 config.setGroup( "PlayList" );
181 QString filename=QPEApplication::documentDir() + "/default.m3u"; 181 QString filename=QPEApplication::documentDir() + "/default.m3u";
182 QString currentString = config.readEntry( "CurrentPlaylist", filename); 182 QString currentString = config.readEntry( "CurrentPlaylist", filename);
183 if( currentString == filename) { 183 if( currentString == filename) {
184 Om3u *m3uList; 184 Om3u *m3uList;
185 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); 185 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
186 if( d->selectedFiles->first() ) { 186 if( d->selectedFiles->first() ) {
187 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 187 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
188 do { 188 do {
189 // qDebug(d->selectedFiles->current()->file()); 189 // qDebug(d->selectedFiles->current()->file());
190 m3uList->add( d->selectedFiles->current()->file() ); 190 m3uList->add( d->selectedFiles->current()->file() );
191 } 191 }
192 while ( d->selectedFiles->next() ); 192 while ( d->selectedFiles->next() );
193 193
194 m3uList->write(); 194 m3uList->write();
195 m3uList->close(); 195 m3uList->close();
196 delete m3uList; 196 delete m3uList;
197 197
198 } 198 }
199 } 199 }
200} 200}
201 201
202void PlayListWidget::addToSelection( const DocLnk& lnk ) { 202void PlayListWidget::addToSelection( const DocLnk& lnk ) {
203 d->setDocumentUsed = FALSE; 203 d->setDocumentUsed = FALSE;
204 if( QFileInfo( lnk.file() ).exists() || 204 if( QFileInfo( lnk.file() ).exists() ||
205 lnk.file().left(4) == "http" ) { 205 lnk.file().left(4) == "http" ) {
206 d->selectedFiles->addToSelection( lnk ); 206 d->selectedFiles->addToSelection( lnk );
207 } 207 }
208// writeCurrentM3u(); 208// writeCurrentM3u();
209} 209}
210 210
211 211
212void PlayListWidget::clearList() { 212void PlayListWidget::clearList() {
213 while ( first() ) { 213 while ( first() ) {
214 d->selectedFiles->removeSelected(); 214 d->selectedFiles->removeSelected();
215 } 215 }
216 Config cfg( "OpiePlayer" ); 216 Config cfg( "OpiePlayer" );
217 cfg.setGroup("PlayList"); 217 cfg.setGroup("PlayList");
218 cfg.writeEntry("CurrentPlaylist","default"); 218 cfg.writeEntry("CurrentPlaylist","default");
219 setCaption("OpiePlayer"); 219 setCaption("OpiePlayer");
220} 220}
221 221
222void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 222void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
223 switch (mouse) { 223 switch (mouse) {
224 case LeftButton: 224 case LeftButton:
225 break; 225 break;
226 case RightButton: 226 case RightButton:
227 { 227 {
228 QPopupMenu m; 228 QPopupMenu m;
229 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 229 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
230 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 230 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
231 m.exec( QCursor::pos() ); 231 m.exec( QCursor::pos() );
232 } 232 }
233 break; 233 break;
234 } 234 }
235} 235}
236 236
237 237
238void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 238void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
239 switch (mouse) { 239 switch (mouse) {
240 case LeftButton: 240 case LeftButton:
241 break; 241 break;
242 case RightButton: 242 case RightButton:
243 { 243 {
244 QPopupMenu m; 244 QPopupMenu m;
245 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 245 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
246 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 246 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
247 m.exec( QCursor::pos() ); 247 m.exec( QCursor::pos() );
248 } 248 }
249 break; 249 break;
250 } 250 }
251} 251}
252 252
253 253
254void PlayListWidget::addAllToList() { 254void PlayListWidget::addAllToList() {
255 255
256 256
257 audioView->populateView(); 257 audioView->populateView();
258 258
259 QListViewItemIterator audioIt( audioView ); 259 QListViewItemIterator audioIt( audioView );
260 DocLnk lnk; 260 DocLnk lnk;
261 QString filename; 261 QString filename;
262 // iterate through all items of the listview 262 // iterate through all items of the listview
263 for ( ; audioIt.current(); ++audioIt ) { 263 for ( ; audioIt.current(); ++audioIt ) {
264 filename = audioIt.current()->text(3); 264 filename = audioIt.current()->text(3);
265 lnk.setName( QFileInfo(filename).baseName() ); //sets name 265 lnk.setName( QFileInfo(filename).baseName() ); //sets name
266 lnk.setFile( filename ); //sets file name 266 lnk.setFile( filename ); //sets file name
267 d->selectedFiles->addToSelection( lnk); 267 d->selectedFiles->addToSelection( lnk);
268 } 268 }
269 269
270 videoView->populateView(); 270 videoView->populateView();
271 271
272 QListViewItemIterator videoIt( videoView ); 272 QListViewItemIterator videoIt( videoView );
273 for ( ; videoIt.current(); ++videoIt ) { 273 for ( ; videoIt.current(); ++videoIt ) {
274 filename = videoIt.current()->text(3); 274 filename = videoIt.current()->text(3);
275 lnk.setName( QFileInfo(filename).baseName() ); //sets name 275 lnk.setName( QFileInfo(filename).baseName() ); //sets name
276 lnk.setFile( filename ); //sets file name 276 lnk.setFile( filename ); //sets file name
277 d->selectedFiles->addToSelection( lnk); 277 d->selectedFiles->addToSelection( lnk);
278 } 278 }
279 279
280 tabWidget->setCurrentPage(0); 280 tabWidget->setCurrentPage(0);
281 281
282 writeCurrentM3u(); 282 writeCurrentM3u();
283 d->selectedFiles->first(); 283 d->selectedFiles->first();
284} 284}
285 285
286 286
287void PlayListWidget::addAllMusicToList() { 287void PlayListWidget::addAllMusicToList() {
288 288
289 audioView->populateView(); 289 audioView->populateView();
290 290
291 QListViewItemIterator audioIt( audioView ); 291 QListViewItemIterator audioIt( audioView );
292 DocLnk lnk; 292 DocLnk lnk;
293 QString filename; 293 QString filename;
294 // iterate through all items of the listview 294 // iterate through all items of the listview
295 for ( ; audioIt.current(); ++audioIt ) { 295 for ( ; audioIt.current(); ++audioIt ) {
296 filename = audioIt.current()->text(3); 296 filename = audioIt.current()->text(3);
297 lnk.setName( QFileInfo(filename).baseName() ); //sets name 297 lnk.setName( QFileInfo(filename).baseName() ); //sets name
298 lnk.setFile( filename ); //sets file name 298 lnk.setFile( filename ); //sets file name
299 d->selectedFiles->addToSelection( lnk); 299 d->selectedFiles->addToSelection( lnk);
300 } 300 }
301 301
302 tabWidget->setCurrentPage(0); 302 tabWidget->setCurrentPage(0);
303 writeCurrentM3u(); 303 writeCurrentM3u();
304 d->selectedFiles->first(); 304 d->selectedFiles->first();
305} 305}
306 306
307 307
308void PlayListWidget::addAllVideoToList() { 308void PlayListWidget::addAllVideoToList() {
309 309
310 videoView->populateView(); 310 videoView->populateView();
311 311
312 QListViewItemIterator videoIt( videoView ); 312 QListViewItemIterator videoIt( videoView );
313 DocLnk lnk; 313 DocLnk lnk;
314 QString filename; 314 QString filename;
315 for ( ; videoIt.current(); ++videoIt ) { 315 for ( ; videoIt.current(); ++videoIt ) {
316 filename = videoIt.current()->text(3); 316 filename = videoIt.current()->text(3);
317 lnk.setName( QFileInfo(filename).baseName() ); //sets name 317 lnk.setName( QFileInfo(filename).baseName() ); //sets name
318 lnk.setFile( filename ); //sets file name 318 lnk.setFile( filename ); //sets file name
319 d->selectedFiles->addToSelection( lnk); 319 d->selectedFiles->addToSelection( lnk);
320 } 320 }
321 tabWidget->setCurrentPage(0); 321 tabWidget->setCurrentPage(0);
322 writeCurrentM3u(); 322 writeCurrentM3u();
323 d->selectedFiles->first(); 323 d->selectedFiles->first();
324} 324}
325 325
326 326
327void PlayListWidget::setDocument( const QString& fileref ) { 327void PlayListWidget::setDocument( const QString& fileref ) {
328 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); 328 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref );
329 fromSetDocument = TRUE; 329 fromSetDocument = TRUE;
330 QFileInfo fileInfo(fileref); 330 QFileInfo fileInfo(fileref);
331 331
332 if ( !fileInfo.exists() ) { 332 if ( !fileInfo.exists() ) {
333 QMessageBox::warning( this, tr( "Invalid File" ), 333 QMessageBox::warning( this, tr( "Invalid File" ),
334 tr( "There was a problem in getting the file." ) ); 334 tr( "There was a problem in getting the file." ) );
335 return; 335 return;
336 } 336 }
337 337
338 clearList(); 338 clearList();
339 QString extension = fileInfo.extension(false); 339 QString extension = fileInfo.extension(false);
340 340
341 if( extension.find( "m3u", 0, false) != -1 341 if( extension.find( "m3u", 0, false) != -1
342 || extension.find( "pls", 0, false) != -1 ) { 342 || extension.find( "pls", 0, false) != -1 ) {
343 readListFromFile( fileref ); 343 readListFromFile( fileref );
344 } else { 344 } else {
345 clearList(); 345 clearList();
346 DocLnk lnk; 346 DocLnk lnk;
347 lnk.setName( fileInfo.baseName() ); //sets name 347 lnk.setName( fileInfo.baseName() ); //sets name
348 lnk.setFile( fileref ); //sets file name 348 lnk.setFile( fileref ); //sets file name
349 addToSelection( lnk ); 349 addToSelection( lnk );
350 writeCurrentM3u(); 350 writeCurrentM3u();
351 351
352 d->setDocumentUsed = TRUE; 352 d->setDocumentUsed = TRUE;
353 mediaPlayerState->setPlaying( FALSE ); 353 mediaPlayerState->setPlaying( FALSE );
354 mediaPlayerState->setPlaying( TRUE ); 354 mediaPlayerState->setPlaying( TRUE );
355 } 355 }
356} 356}
357 357
358 358
359void PlayListWidget::useSelectedDocument() { 359void PlayListWidget::useSelectedDocument() {
360 d->setDocumentUsed = FALSE; 360 d->setDocumentUsed = FALSE;
361} 361}
362 362
363 363
364const DocLnk *PlayListWidget::current() const { // this is fugly 364const DocLnk *PlayListWidget::current() const { // this is fugly
365 assert( currentTab() == CurrentPlayList ); 365 assert( currentTab() == CurrentPlayList );
366 366
367 const DocLnk *lnk = d->selectedFiles->current(); 367 const DocLnk *lnk = d->selectedFiles->current();
368 if ( !lnk ) { 368 if ( !lnk ) {
369 d->selectedFiles->first(); 369 d->selectedFiles->first();
370 lnk = d->selectedFiles->current(); 370 lnk = d->selectedFiles->current();
371 } 371 }
372 assert( lnk ); 372 assert( lnk );
373 return lnk; 373 return lnk;
374} 374}
375 375
376 376
377bool PlayListWidget::prev() { 377bool PlayListWidget::prev() {
378 if ( mediaPlayerState->isShuffled() ) { 378 if ( mediaPlayerState->isShuffled() ) {
379 const DocLnk *cur = current(); 379 const DocLnk *cur = current();
380 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 380 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
381 for ( int i = 0; i < j; i++ ) { 381 for ( int i = 0; i < j; i++ ) {
382 if ( !d->selectedFiles->next() ) 382 if ( !d->selectedFiles->next() )
383 d->selectedFiles->first(); 383 d->selectedFiles->first();
384 } 384 }
385 if ( cur == current() ) 385 if ( cur == current() )
386 if ( !d->selectedFiles->next() ) { 386 if ( !d->selectedFiles->next() ) {
387 d->selectedFiles->first(); 387 d->selectedFiles->first();
388 } 388 }
389 return TRUE; 389 return TRUE;
390 } else { 390 } else {
391 if ( !d->selectedFiles->prev() ) { 391 if ( !d->selectedFiles->prev() ) {
392 if ( mediaPlayerState->isLooping() ) { 392 if ( mediaPlayerState->isLooping() ) {
393 return d->selectedFiles->last(); 393 return d->selectedFiles->last();
394 } else { 394 } else {
395 return FALSE; 395 return FALSE;
396 } 396 }
397 } 397 }
398 return TRUE; 398 return TRUE;
399 } 399 }
400} 400}
401 401
402 402
403bool PlayListWidget::next() { 403bool PlayListWidget::next() {
404//qDebug("<<<<<<<<<<<<next()"); 404//qDebug("<<<<<<<<<<<<next()");
405 if ( mediaPlayerState->isShuffled() ) { 405 if ( mediaPlayerState->isShuffled() ) {
406 return prev(); 406 return prev();
407 } else { 407 } else {
408 if ( !d->selectedFiles->next() ) { 408 if ( !d->selectedFiles->next() ) {
409 if ( mediaPlayerState->isLooping() ) { 409 if ( mediaPlayerState->isLooping() ) {
410 return d->selectedFiles->first(); 410 return d->selectedFiles->first();
411 } else { 411 } else {
412 return FALSE; 412 return FALSE;
413 } 413 }
414 } 414 }
415 return TRUE; 415 return TRUE;
416 } 416 }
417} 417}
418 418
419 419
420bool PlayListWidget::first() { 420bool PlayListWidget::first() {
421 return d->selectedFiles->first(); 421 return d->selectedFiles->first();
422} 422}
423 423
424 424
425bool PlayListWidget::last() { 425bool PlayListWidget::last() {
426 return d->selectedFiles->last(); 426 return d->selectedFiles->last();
427} 427}
428 428
429 429
430 void PlayListWidget::saveList() { 430 void PlayListWidget::saveList() {
431 writem3u(); 431 writem3u();
432 } 432 }
433 433
434 434
435void PlayListWidget::loadList( const DocLnk & lnk) { 435void PlayListWidget::loadList( const DocLnk & lnk) {
436 QString name = lnk.name(); 436 QString name = lnk.name();
437 437
438 if( name.length()>0) { 438 if( name.length()>0) {
439 setCaption("OpiePlayer: "+name); 439 setCaption("OpiePlayer: "+name);
440 clearList(); 440 clearList();
441 readListFromFile(lnk.file()); 441 readListFromFile(lnk.file());
442 tabWidget->setCurrentPage(0); 442 tabWidget->setCurrentPage(0);
443 } 443 }
444} 444}
445 445
446void PlayListWidget::addSelected() { 446void PlayListWidget::addSelected() {
447 assert( inFileListMode() ); 447 assert( inFileListMode() );
448 448
449 QListViewItemIterator it( currentFileListView ); 449 QListViewItemIterator it( currentFileListView );
450 for ( ; it.current(); ++it ) 450 for ( ; it.current(); ++it )
451 if ( it.current()->isSelected() ) { 451 if ( it.current()->isSelected() ) {
452 QString filename = it.current()->text(3); 452 QString filename = it.current()->text(3);
453 453
454 DocLnk lnk; 454 DocLnk lnk;
455 lnk.setName( QFileInfo( filename ).baseName() ); //sets name 455 lnk.setName( QFileInfo( filename ).baseName() ); //sets name
456 lnk.setFile( filename ); //sets file name 456 lnk.setFile( filename ); //sets file name
457 457
458 d->selectedFiles->addToSelection( lnk ); 458 d->selectedFiles->addToSelection( lnk );
459 } 459 }
460 460
461 currentFileListView->clearSelection(); 461 currentFileListView->clearSelection();
462 462
463 writeCurrentM3u(); 463 writeCurrentM3u();
464} 464}
465 465
466 466
467void PlayListWidget::removeSelected() { 467void PlayListWidget::removeSelected() {
468 d->selectedFiles->removeSelected( ); 468 d->selectedFiles->removeSelected( );
469 writeCurrentM3u(); 469 writeCurrentM3u();
470} 470}
471 471
472 472
473void PlayListWidget::playIt( QListViewItem *it) { 473void PlayListWidget::playIt( QListViewItem *it) {
474 if(!it) return; 474 if(!it) return;
475 mediaPlayerState->setPlaying(FALSE); 475 mediaPlayerState->setPlaying(FALSE);
476 mediaPlayerState->setPlaying(TRUE); 476 mediaPlayerState->setPlaying(TRUE);
477 d->selectedFiles->unSelect(); 477 d->selectedFiles->unSelect();
478} 478}
479 479
480 480
481void PlayListWidget::addToSelection( QListViewItem *it) { 481void PlayListWidget::addToSelection( QListViewItem *it) {
482 d->setDocumentUsed = FALSE; 482 d->setDocumentUsed = FALSE;
483 483
484 if(it) { 484 if(it) {
485 if ( currentTab() == CurrentPlayList ) 485 if ( currentTab() == CurrentPlayList )
486 return; 486 return;
487 DocLnk lnk; 487 DocLnk lnk;
488 QString filename; 488 QString filename;
489 489
490 filename=it->text(3); 490 filename=it->text(3);
491 lnk.setName( QFileInfo(filename).baseName() ); //sets name 491 lnk.setName( QFileInfo(filename).baseName() ); //sets name
492 lnk.setFile( filename ); //sets file name 492 lnk.setFile( filename ); //sets file name
493 d->selectedFiles->addToSelection( lnk); 493 d->selectedFiles->addToSelection( lnk);
494 494
495 writeCurrentM3u(); 495 writeCurrentM3u();
496// tabWidget->setCurrentPage(0); 496// tabWidget->setCurrentPage(0);
497 497
498 } 498 }
499} 499}
500 500
501 501
502void PlayListWidget::tabChanged(QWidget *) { 502void PlayListWidget::tabChanged(QWidget *) {
503 503
504 d->tbPlay->setEnabled( true ); 504 d->tbPlay->setEnabled( true );
505 505
506 disconnect( audioView, SIGNAL( itemsSelected( bool ) ), 506 disconnect( audioView, SIGNAL( itemsSelected(bool) ),
507 d->tbPlay, SLOT( setEnabled( bool ) ) ); 507 d->tbPlay, SLOT( setEnabled(bool) ) );
508 disconnect( videoView, SIGNAL( itemsSelected( bool ) ), 508 disconnect( videoView, SIGNAL( itemsSelected(bool) ),
509 d->tbPlay, SLOT( setEnabled( bool ) ) ); 509 d->tbPlay, SLOT( setEnabled(bool) ) );
510 510
511 currentFileListView = 0; 511 currentFileListView = 0;
512 512
513 switch ( currentTab() ) { 513 switch ( currentTab() ) {
514 case CurrentPlayList: 514 case CurrentPlayList:
515 { 515 {
516 if( !tbDeletePlaylist->isHidden() ) { 516 if( !tbDeletePlaylist->isHidden() ) {
517 tbDeletePlaylist->hide(); 517 tbDeletePlaylist->hide();
518 } 518 }
519 d->tbRemoveFromList->setEnabled(TRUE); 519 d->tbRemoveFromList->setEnabled(TRUE);
520 d->tbAddToList->setEnabled(FALSE); 520 d->tbAddToList->setEnabled(FALSE);
521 521
522 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); 522 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() );
523 } 523 }
524 break; 524 break;
525 case AudioFiles: 525 case AudioFiles:
526 { 526 {
527 audioView->populateView(); 527 audioView->populateView();
528 528
529 if( !tbDeletePlaylist->isHidden() ) { 529 if( !tbDeletePlaylist->isHidden() ) {
530 tbDeletePlaylist->hide(); 530 tbDeletePlaylist->hide();
531 } 531 }
532 d->tbRemoveFromList->setEnabled(FALSE); 532 d->tbRemoveFromList->setEnabled(FALSE);
533 d->tbAddToList->setEnabled(TRUE); 533 d->tbAddToList->setEnabled(TRUE);
534 534
535 connect( audioView, SIGNAL( itemsSelected( bool ) ), 535 connect( audioView, SIGNAL( itemsSelected(bool) ),
536 d->tbPlay, SLOT( setEnabled( bool ) ) ); 536 d->tbPlay, SLOT( setEnabled(bool) ) );
537 537
538 d->tbPlay->setEnabled( audioView->hasSelection() ); 538 d->tbPlay->setEnabled( audioView->hasSelection() );
539 539
540 currentFileListView = audioView; 540 currentFileListView = audioView;
541 } 541 }
542 break; 542 break;
543 case VideoFiles: 543 case VideoFiles:
544 { 544 {
545 videoView->populateView(); 545 videoView->populateView();
546 if( !tbDeletePlaylist->isHidden() ) { 546 if( !tbDeletePlaylist->isHidden() ) {
547 tbDeletePlaylist->hide(); 547 tbDeletePlaylist->hide();
548 } 548 }
549 d->tbRemoveFromList->setEnabled(FALSE); 549 d->tbRemoveFromList->setEnabled(FALSE);
550 d->tbAddToList->setEnabled(TRUE); 550 d->tbAddToList->setEnabled(TRUE);
551 551
552 connect( videoView, SIGNAL( itemsSelected( bool ) ), 552 connect( videoView, SIGNAL( itemsSelected(bool) ),
553 d->tbPlay, SLOT( setEnabled( bool ) ) ); 553 d->tbPlay, SLOT( setEnabled(bool) ) );
554 554
555 d->tbPlay->setEnabled( videoView->hasSelection() ); 555 d->tbPlay->setEnabled( videoView->hasSelection() );
556 556
557 currentFileListView = videoView; 557 currentFileListView = videoView;
558 } 558 }
559 break; 559 break;
560 case PlayLists: 560 case PlayLists:
561 { 561 {
562 if( tbDeletePlaylist->isHidden() ) { 562 if( tbDeletePlaylist->isHidden() ) {
563 tbDeletePlaylist->show(); 563 tbDeletePlaylist->show();
564 } 564 }
565 playLists->reread(); 565 playLists->reread();
566 d->tbAddToList->setEnabled(FALSE); 566 d->tbAddToList->setEnabled(FALSE);
567 567
568 d->tbPlay->setEnabled( false ); 568 d->tbPlay->setEnabled( false );
569 } 569 }
570 break; 570 break;
571 }; 571 };
572} 572}
573 573
574 574
575void PlayListWidget::btnPlay(bool b) { 575void PlayListWidget::btnPlay(bool b) {
576// mediaPlayerState->setPlaying(false); 576// mediaPlayerState->setPlaying(false);
577 mediaPlayerState->setPlaying(b); 577 mediaPlayerState->setPlaying(b);
578 insanityBool=FALSE; 578 insanityBool=FALSE;
579} 579}
580 580
581void PlayListWidget::deletePlaylist() { 581void PlayListWidget::deletePlaylist() {
582 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 582 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
583 (tr("You really want to delete\nthis playlist?")), 583 (tr("You really want to delete\nthis playlist?")),
584 (tr("Yes")), (tr("No")), 0 )){ 584 (tr("Yes")), (tr("No")), 0 )){
585 case 0: // Yes clicked, 585 case 0: // Yes clicked,
586 QFile().remove(playLists->selectedDocument().file()); 586 QFile().remove(playLists->selectedDocument().file());
587 QFile().remove(playLists->selectedDocument().linkFile()); 587 QFile().remove(playLists->selectedDocument().linkFile());
588 playLists->reread(); 588 playLists->reread();
589 break; 589 break;
590 case 1: // Cancel 590 case 1: // Cancel
591 break; 591 break;
592 }; 592 };
593} 593}
594 594
595 595
596void PlayListWidget::playSelected() { 596void PlayListWidget::playSelected() {
597 btnPlay( TRUE); 597 btnPlay( TRUE);
598} 598}
599 599
600bool PlayListWidget::inFileListMode() const 600bool PlayListWidget::inFileListMode() const
601{ 601{
602 TabType tab = currentTab(); 602 TabType tab = currentTab();
603 return tab == AudioFiles || tab == VideoFiles; 603 return tab == AudioFiles || tab == VideoFiles;
604} 604}
605 605
606void PlayListWidget::openURL() { 606void PlayListWidget::openURL() {
607 // http://66.28.164.33:2080 607 // http://66.28.164.33:2080
608 // http://somafm.com/star0242.m3u 608 // http://somafm.com/star0242.m3u
609 QString filename, name; 609 QString filename, name;
610 InputDialog *fileDlg; 610 InputDialog *fileDlg;
611 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0); 611 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0);
612 fileDlg->exec(); 612 fileDlg->exec();
613 if( fileDlg->result() == 1 ) { 613 if( fileDlg->result() == 1 ) {
614 filename = fileDlg->text(); 614 filename = fileDlg->text();
615 qDebug( "Selected filename is " + filename ); 615 qDebug( "Selected filename is " + filename );
616 // Om3u *m3uList; 616 // Om3u *m3uList;
617 DocLnk lnk; 617 DocLnk lnk;
618 Config cfg( "OpiePlayer" ); 618 Config cfg( "OpiePlayer" );
619 cfg.setGroup("PlayList"); 619 cfg.setGroup("PlayList");
620 620
621 if(filename.left(4) == "http") { 621 if(filename.left(4) == "http") {
622 QString m3uFile, m3uFilePath; 622 QString m3uFile, m3uFilePath;
623 if(filename.find(":",8,TRUE) != -1) { //found a port 623 if(filename.find(":",8,TRUE) != -1) { //found a port
624 m3uFile = filename.left( filename.find( ":",8,TRUE)); 624 m3uFile = filename.left( filename.find( ":",8,TRUE));
625 m3uFile = m3uFile.right( 7); 625 m3uFile = m3uFile.right( 7);
626 } else if(filename.left(4) == "http"){ 626 } else if(filename.left(4) == "http"){
627 m3uFile=filename; 627 m3uFile=filename;
628 m3uFile = m3uFile.right( m3uFile.length() - 7); 628 m3uFile = m3uFile.right( m3uFile.length() - 7);
629 } else{ 629 } else{
630 m3uFile=filename; 630 m3uFile=filename;
631 } 631 }
632 632
633 lnk.setName( filename ); //sets name 633 lnk.setName( filename ); //sets name
634 lnk.setFile( filename ); //sets file name 634 lnk.setFile( filename ); //sets file name
635 635
636// lnk.setIcon("opieplayer2/musicfile"); 636// lnk.setIcon("opieplayer2/musicfile");
637 637
638 d->selectedFiles->addToSelection( lnk ); 638 d->selectedFiles->addToSelection( lnk );
639 writeCurrentM3u(); 639 writeCurrentM3u();
640 d->selectedFiles->setSelectedItem( lnk.name()); 640 d->selectedFiles->setSelectedItem( lnk.name());
641 } 641 }
642 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 642 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
643 readListFromFile( filename ); 643 readListFromFile( filename );
644 } else { 644 } else {
645 lnk.setName( QFileInfo(filename).baseName() ); //sets name 645 lnk.setName( QFileInfo(filename).baseName() ); //sets name
646 lnk.setFile( filename ); //sets file name 646 lnk.setFile( filename ); //sets file name
647 d->selectedFiles->addToSelection( lnk); 647 d->selectedFiles->addToSelection( lnk);
648 writeCurrentM3u(); 648 writeCurrentM3u();
649 d->selectedFiles->setSelectedItem( lnk.name()); 649 d->selectedFiles->setSelectedItem( lnk.name());
650 } 650 }
651 } 651 }
652 652
653 653
654 delete fileDlg; 654 delete fileDlg;
655} 655}
656 656
657 657
658void PlayListWidget::openFile() { 658void PlayListWidget::openFile() {
659 659
660 QString filename, name; 660 QString filename, name;
661 661
662 Config cfg( "OpiePlayer" ); 662 Config cfg( "OpiePlayer" );
663 cfg.setGroup("Dialog"); 663 cfg.setGroup("Dialog");
664 MimeTypes types; 664 MimeTypes types;
665 QStringList audio, video, all; 665 QStringList audio, video, all;
666 audio << "audio/*"; 666 audio << "audio/*";
667 audio << "playlist/plain"; 667 audio << "playlist/plain";
668 audio << "application/ogg"; 668 audio << "application/ogg";
669 audio << "audio/x-mpegurl"; 669 audio << "audio/x-mpegurl";
670 670
671 video << "video/*"; 671 video << "video/*";
672 video << "playlist/plain"; 672 video << "playlist/plain";
673 673
674 all += audio; 674 all += audio;
675 all += video; 675 all += video;
676 types.insert("All Media Files", all ); 676 types.insert("All Media Files", all );
677 types.insert("Audio", audio ); 677 types.insert("Audio", audio );
678 types.insert("Video", video ); 678 types.insert("Video", video );
679 679
680 QString str = OFileDialog::getOpenFileName( 1, 680 QString str = OFileDialog::getOpenFileName( 1,
681 cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"", 681 cfg.readEntry("LastDirectory",QPEApplication::documentDir()),"",
682 types, 0 ); 682 types, 0 );
683 683
684 if(str.left(2) == "//") { 684 if(str.left(2) == "//") {
685 str=str.right(str.length()-1); 685 str=str.right(str.length()-1);
686 } 686 }
687 cfg.writeEntry( "LastDirectory" ,QFileInfo( str ).dirPath() ); 687 cfg.writeEntry( "LastDirectory" ,QFileInfo( str ).dirPath() );
688 688
689 if( !str.isEmpty() ) { 689 if( !str.isEmpty() ) {
690 690
691 qDebug( "Selected filename is " + str ); 691 qDebug( "Selected filename is " + str );
692 filename = str; 692 filename = str;
693 DocLnk lnk; 693 DocLnk lnk;
694 694
695 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 695 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
696 readListFromFile( filename ); 696 readListFromFile( filename );
697 } else { 697 } else {
698 lnk.setName( QFileInfo(filename).baseName() ); //sets name 698 lnk.setName( QFileInfo(filename).baseName() ); //sets name
699 lnk.setFile( filename ); //sets file name 699 lnk.setFile( filename ); //sets file name
700 d->selectedFiles->addToSelection( lnk ); 700 d->selectedFiles->addToSelection( lnk );
701 writeCurrentM3u(); 701 writeCurrentM3u();
702 d->selectedFiles->setSelectedItem( lnk.name() ); 702 d->selectedFiles->setSelectedItem( lnk.name() );
703 } 703 }
704 } 704 }
705} 705}
706 706
707 707
708void PlayListWidget::readListFromFile( const QString &filename ) { 708void PlayListWidget::readListFromFile( const QString &filename ) {
709 qDebug( "read list filename " + filename ); 709 qDebug( "read list filename " + filename );
710 QFileInfo fi(filename); 710 QFileInfo fi(filename);
711 Om3u *m3uList; 711 Om3u *m3uList;
712 QString s, name; 712 QString s, name;
713 m3uList = new Om3u( filename, IO_ReadOnly ); 713 m3uList = new Om3u( filename, IO_ReadOnly );
714 if(fi.extension(false).find("m3u",0,false) != -1 ) 714 if(fi.extension(false).find("m3u",0,false) != -1 )
715 m3uList->readM3u(); 715 m3uList->readM3u();
716 else if(fi.extension(false).find("pls",0,false) != -1 ) 716 else if(fi.extension(false).find("pls",0,false) != -1 )
717 m3uList->readPls(); 717 m3uList->readPls();
718 718
719 DocLnk lnk; 719 DocLnk lnk;
720 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 720 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
721 s = *it; 721 s = *it;
722 // qDebug(s); 722 // qDebug(s);
723 if(s.left(4)=="http") { 723 if(s.left(4)=="http") {
724 lnk.setName( s ); //sets file name 724 lnk.setName( s ); //sets file name
725 lnk.setIcon("opieplayer2/musicfile"); 725 lnk.setIcon("opieplayer2/musicfile");
726 lnk.setFile( s ); //sets file name 726 lnk.setFile( s ); //sets file name
727 727
728 } else { //is file 728 } else { //is file
729 lnk.setName( QFileInfo(s).baseName()); 729 lnk.setName( QFileInfo(s).baseName());
730 if(s.left(1) != "/") { 730 if(s.left(1) != "/") {
731 731
732 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 732 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
733 } else { 733 } else {
734 lnk.setFile( s); 734 lnk.setFile( s);
735 } 735 }
736 } 736 }
737 d->selectedFiles->addToSelection( lnk ); 737 d->selectedFiles->addToSelection( lnk );
738 } 738 }
739 Config config( "OpiePlayer" ); 739 Config config( "OpiePlayer" );
740 config.setGroup( "PlayList" ); 740 config.setGroup( "PlayList" );
741 741
742 config.writeEntry("CurrentPlaylist",filename); 742 config.writeEntry("CurrentPlaylist",filename);
743 config.write(); 743 config.write();
744 currentPlayList=filename; 744 currentPlayList=filename;
745 745