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