summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-16 03:24:09 (UTC)
committer llornkcor <llornkcor>2002-12-16 03:24:09 (UTC)
commitffefde3701c0aed084872d05710d78b7201efaa8 (patch) (unidiff)
tree735f2fe5e07792685234b6b84011bdfdb4928365
parent64bc40080abc56e6bd804dadb44d2510f25f2efa (diff)
downloadopie-ffefde3701c0aed084872d05710d78b7201efaa8.zip
opie-ffefde3701c0aed084872d05710d78b7201efaa8.tar.gz
opie-ffefde3701c0aed084872d05710d78b7201efaa8.tar.bz2
fix writng m3u filenames when user specifies a directory
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index 6e2457f..707f4d2 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -1,1012 +1,1013 @@
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
58PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name ) 58PlayListWidget::PlayListWidget( MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name )
59 : PlayListWidgetGui( mediaPlayerState, parent, name ) , currentFileListView( 0 ) 59 : PlayListWidgetGui( mediaPlayerState, parent, name ) , currentFileListView( 0 )
60{ 60{
61 61
62 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 62 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
63 "opieplayer2/add_to_playlist", 63 "opieplayer2/add_to_playlist",
64 this , SLOT(addSelected() ) ); 64 this , SLOT(addSelected() ) );
65 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 65 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
66 "opieplayer2/remove_from_playlist", 66 "opieplayer2/remove_from_playlist",
67 this , SLOT(removeSelected() ) ); 67 this , SLOT(removeSelected() ) );
68 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 68 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
69 this , SLOT( btnPlay( bool) ), TRUE ); 69 this , SLOT( btnPlay( bool) ), TRUE );
70 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 70 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
71 &mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE ); 71 &mediaPlayerState, SLOT( setShuffled( bool ) ), TRUE );
72 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 72 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
73 &mediaPlayerState, SLOT( setLooping( bool ) ), TRUE ); 73 &mediaPlayerState, SLOT( setLooping( bool ) ), TRUE );
74 74
75 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 75 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
76 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 76 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
77 this, SLOT( addAllMusicToList() ) ); 77 this, SLOT( addAllMusicToList() ) );
78 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 78 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
79 this, SLOT( addAllVideoToList() ) ); 79 this, SLOT( addAllVideoToList() ) );
80 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 80 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
81 this, SLOT( addAllToList() ) ); 81 this, SLOT( addAllToList() ) );
82 pmPlayList->insertSeparator(-1); 82 pmPlayList->insertSeparator(-1);
83// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ), 83// (void)new MenuItem( pmPlayList, tr( "Save PlayList" ),
84// this, SLOT( saveList() ) ); 84// this, SLOT( saveList() ) );
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( "Open File or URL" ), 88 (void)new MenuItem( pmPlayList, tr( "Open File or URL" ),
89 this,SLOT( openFile() ) ); 89 this,SLOT( openFile() ) );
90 pmPlayList->insertSeparator(-1); 90 pmPlayList->insertSeparator(-1);
91 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 91 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
92 audioView, SLOT( scanFiles() ) ); 92 audioView, SLOT( scanFiles() ) );
93 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 93 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
94 videoView, SLOT( scanFiles() ) ); 94 videoView, SLOT( scanFiles() ) );
95 95
96 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 96 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
97 &mediaPlayerState, SLOT( toggleFullscreen() ) ); 97 &mediaPlayerState, SLOT( toggleFullscreen() ) );
98 98
99 Config cfg( "OpiePlayer" ); 99 Config cfg( "OpiePlayer" );
100 bool b= cfg.readBoolEntry("FullScreen", 0); 100 bool b= cfg.readBoolEntry("FullScreen", 0);
101 mediaPlayerState.setFullscreen( b ); 101 mediaPlayerState.setFullscreen( b );
102 pmView->setItemChecked( -16, b ); 102 pmView->setItemChecked( -16, b );
103 103
104 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 104 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
105 d->selectedFiles, SLOT(moveSelectedUp() ) ); 105 d->selectedFiles, SLOT(moveSelectedUp() ) );
106 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 106 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
107 d->selectedFiles, SLOT(removeSelected() ) ); 107 d->selectedFiles, SLOT(removeSelected() ) );
108 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 108 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
109 d->selectedFiles, SLOT(moveSelectedDown() ) ); 109 d->selectedFiles, SLOT(moveSelectedDown() ) );
110 // QVBox *stretch2 = new QVBox( vbox1 ); 110 // QVBox *stretch2 = new QVBox( vbox1 );
111 111
112 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 112 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
113 SLOT( deletePlaylist() ) ); 113 SLOT( deletePlaylist() ) );
114 connect( pmView, SIGNAL( activated( int ) ), 114 connect( pmView, SIGNAL( activated( int ) ),
115 this, SLOT( pmViewActivated( int ) ) ); 115 this, SLOT( pmViewActivated( int ) ) );
116 connect( skinsMenu, SIGNAL( activated( int ) ) , 116 connect( skinsMenu, SIGNAL( activated( int ) ) ,
117 this, SLOT( skinsMenuActivated( int ) ) ); 117 this, SLOT( skinsMenuActivated( int ) ) );
118 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 118 connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
119 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 119 this,SLOT( playlistViewPressed( int, QListViewItem *, const QPoint&, int ) ) );
120 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ), 120 connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int ) ),
121 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) ); 121 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int ) ) );
122 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ), 122 connect( audioView, SIGNAL( returnPressed( QListViewItem *) ),
123 this,SLOT( playIt( QListViewItem *) ) ); 123 this,SLOT( playIt( QListViewItem *) ) );
124 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), 124 connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ),
125 this, SLOT( addToSelection( QListViewItem *) ) ); 125 this, SLOT( addToSelection( QListViewItem *) ) );
126 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ), 126 connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int) ),
127 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) ); 127 this,SLOT( viewPressed( int, QListViewItem *, const QPoint&, int) ) );
128 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ), 128 connect( videoView, SIGNAL( returnPressed( QListViewItem *) ),
129 this,SLOT( playIt( QListViewItem *) ) ); 129 this,SLOT( playIt( QListViewItem *) ) );
130 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), 130 connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ),
131 this, SLOT( addToSelection( QListViewItem *) ) ); 131 this, SLOT( addToSelection( QListViewItem *) ) );
132 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), 132 connect( playLists, SIGNAL( fileSelected( const DocLnk &) ),
133 this, SLOT( loadList( const DocLnk & ) ) ); 133 this, SLOT( loadList( const DocLnk & ) ) );
134 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 134 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
135 this, SLOT( tabChanged( QWidget* ) ) ); 135 this, SLOT( tabChanged( QWidget* ) ) );
136 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ), 136 connect( &mediaPlayerState, SIGNAL( playingToggled( bool ) ),
137 d->tbPlay, SLOT( setOn( bool ) ) ); 137 d->tbPlay, SLOT( setOn( bool ) ) );
138 connect( &mediaPlayerState, SIGNAL( loopingToggled( bool ) ), 138 connect( &mediaPlayerState, SIGNAL( loopingToggled( bool ) ),
139 d->tbLoop, SLOT( setOn( bool ) ) ); 139 d->tbLoop, SLOT( setOn( bool ) ) );
140 connect( &mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), 140 connect( &mediaPlayerState, SIGNAL( shuffledToggled( bool ) ),
141 d->tbShuffle, SLOT( setOn( bool ) ) ); 141 d->tbShuffle, SLOT( setOn( bool ) ) );
142 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), 142 connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ),
143 this, SLOT( playIt( QListViewItem *) ) ); 143 this, SLOT( playIt( QListViewItem *) ) );
144 connect ( gammaSlider, SIGNAL( valueChanged( int ) ), 144 connect ( gammaSlider, SIGNAL( valueChanged( int ) ),
145 &mediaPlayerState, SLOT( setVideoGamma( int ) ) ); 145 &mediaPlayerState, SLOT( setVideoGamma( int ) ) );
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 cfg.setGroup("PlayList"); 151 cfg.setGroup("PlayList");
152 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 152 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
153 loadList(DocLnk( currentPlaylist ) ); 153 loadList(DocLnk( currentPlaylist ) );
154 154
155 tabWidget->showPage( playListTab ); 155 tabWidget->showPage( playListTab );
156} 156}
157 157
158 158
159PlayListWidget::~PlayListWidget() { 159PlayListWidget::~PlayListWidget() {
160 delete d; 160 delete d;
161} 161}
162 162
163 163
164void PlayListWidget::initializeStates() { 164void PlayListWidget::initializeStates() {
165 d->tbPlay->setOn( mediaPlayerState.isPlaying() ); 165 d->tbPlay->setOn( mediaPlayerState.isPlaying() );
166 d->tbLoop->setOn( mediaPlayerState.isLooping() ); 166 d->tbLoop->setOn( mediaPlayerState.isLooping() );
167 d->tbShuffle->setOn( mediaPlayerState.isShuffled() ); 167 d->tbShuffle->setOn( mediaPlayerState.isShuffled() );
168 d->playListFrame->show(); 168 d->playListFrame->show();
169} 169}
170 170
171void PlayListWidget::writeDefaultPlaylist() { 171void PlayListWidget::writeDefaultPlaylist() {
172 172
173 Config config( "OpiePlayer" ); 173 Config config( "OpiePlayer" );
174 config.setGroup( "PlayList" ); 174 config.setGroup( "PlayList" );
175 QString filename=QPEApplication::documentDir() + "/default.m3u"; 175 QString filename=QPEApplication::documentDir() + "/default.m3u";
176 QString currentString = config.readEntry( "CurrentPlaylist", filename); 176 QString currentString = config.readEntry( "CurrentPlaylist", filename);
177 if( currentString == filename) { 177 if( currentString == filename) {
178 Om3u *m3uList; 178 Om3u *m3uList;
179 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>"); 179 // qDebug("<<<<<<<<<<<<<default>>>>>>>>>>>>>>>>>>>");
180 if( d->selectedFiles->first() ) { 180 if( d->selectedFiles->first() ) {
181 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 181 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
182 do { 182 do {
183 // qDebug(d->selectedFiles->current()->file()); 183 // qDebug(d->selectedFiles->current()->file());
184 m3uList->add( d->selectedFiles->current()->file() ); 184 m3uList->add( d->selectedFiles->current()->file() );
185 } 185 }
186 while ( d->selectedFiles->next() ); 186 while ( d->selectedFiles->next() );
187 187
188 m3uList->write(); 188 m3uList->write();
189 m3uList->close(); 189 m3uList->close();
190 delete m3uList; 190 delete m3uList;
191 191
192 } 192 }
193 } 193 }
194} 194}
195 195
196void PlayListWidget::addToSelection( const DocLnk& lnk ) { 196void PlayListWidget::addToSelection( const DocLnk& lnk ) {
197 d->setDocumentUsed = FALSE; 197 d->setDocumentUsed = FALSE;
198 if( QFileInfo( lnk.file() ).exists() || 198 if( QFileInfo( lnk.file() ).exists() ||
199 lnk.file().left(4) == "http" ) { 199 lnk.file().left(4) == "http" ) {
200 d->selectedFiles->addToSelection( lnk ); 200 d->selectedFiles->addToSelection( lnk );
201 } 201 }
202// writeCurrentM3u(); 202// writeCurrentM3u();
203} 203}
204 204
205 205
206void PlayListWidget::clearList() { 206void PlayListWidget::clearList() {
207 while ( first() ) { 207 while ( first() ) {
208 d->selectedFiles->removeSelected(); 208 d->selectedFiles->removeSelected();
209 } 209 }
210 Config cfg( "OpiePlayer" ); 210 Config cfg( "OpiePlayer" );
211 cfg.setGroup("PlayList"); 211 cfg.setGroup("PlayList");
212 cfg.writeEntry("CurrentPlaylist","default"); 212 cfg.writeEntry("CurrentPlaylist","default");
213 setCaption("OpiePlayer"); 213 setCaption("OpiePlayer");
214} 214}
215 215
216void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 216void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
217 switch (mouse) { 217 switch (mouse) {
218 case LeftButton: 218 case LeftButton:
219 break; 219 break;
220 case RightButton: 220 case RightButton:
221 { 221 {
222 QPopupMenu m; 222 QPopupMenu m;
223 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 223 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
224 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 224 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
225 m.exec( QCursor::pos() ); 225 m.exec( QCursor::pos() );
226 } 226 }
227 break; 227 break;
228 } 228 }
229} 229}
230 230
231 231
232void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 232void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
233 switch (mouse) { 233 switch (mouse) {
234 case LeftButton: 234 case LeftButton:
235 break; 235 break;
236 case RightButton: 236 case RightButton:
237 { 237 {
238 QPopupMenu m; 238 QPopupMenu m;
239 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 239 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
240 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 240 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
241 m.exec( QCursor::pos() ); 241 m.exec( QCursor::pos() );
242 } 242 }
243 break; 243 break;
244 } 244 }
245} 245}
246 246
247 247
248void PlayListWidget::addAllToList() { 248void PlayListWidget::addAllToList() {
249 249
250// QTime t; 250// QTime t;
251// t.start(); 251// t.start();
252 252
253 audioView->populateView(); 253 audioView->populateView();
254 254
255 QListViewItemIterator audioIt( audioView ); 255 QListViewItemIterator audioIt( audioView );
256 DocLnk lnk; 256 DocLnk lnk;
257 QString filename; 257 QString filename;
258 // iterate through all items of the listview 258 // iterate through all items of the listview
259 for ( ; audioIt.current(); ++audioIt ) { 259 for ( ; audioIt.current(); ++audioIt ) {
260 filename = audioIt.current()->text(3); 260 filename = audioIt.current()->text(3);
261 lnk.setName( QFileInfo(filename).baseName() ); //sets name 261 lnk.setName( QFileInfo(filename).baseName() ); //sets name
262 lnk.setFile( filename ); //sets file name 262 lnk.setFile( filename ); //sets file name
263 d->selectedFiles->addToSelection( lnk); 263 d->selectedFiles->addToSelection( lnk);
264 } 264 }
265 265
266 videoView->populateView(); 266 videoView->populateView();
267 267
268 QListViewItemIterator videoIt( videoView ); 268 QListViewItemIterator videoIt( videoView );
269 for ( ; videoIt.current(); ++videoIt ) { 269 for ( ; videoIt.current(); ++videoIt ) {
270 filename = videoIt.current()->text(3); 270 filename = videoIt.current()->text(3);
271 lnk.setName( QFileInfo(filename).baseName() ); //sets name 271 lnk.setName( QFileInfo(filename).baseName() ); //sets name
272 lnk.setFile( filename ); //sets file name 272 lnk.setFile( filename ); //sets file name
273 d->selectedFiles->addToSelection( lnk); 273 d->selectedFiles->addToSelection( lnk);
274 } 274 }
275 275
276 // d->selectedFiles->addToSelection( ); 276 // d->selectedFiles->addToSelection( );
277 // if ( it.current()->isSelected() ) 277 // if ( it.current()->isSelected() )
278 // lst->append( audioIt.current() ); 278 // lst->append( audioIt.current() );
279 // } 279 // }
280 280
281 281
282// if(!audioScan) 282// if(!audioScan)
283// scanForAudio(); 283// scanForAudio();
284// if(!videoScan) 284// if(!videoScan)
285// scanForVideo(); 285// scanForVideo();
286 286
287// DocLnkSet filesAll; 287// DocLnkSet filesAll;
288// Global::findDocuments(&filesAll, "video/*;"+audioMimes); 288// Global::findDocuments(&filesAll, "video/*;"+audioMimes);
289// QListIterator<DocLnk> Adit( filesAll.children() ); 289// QListIterator<DocLnk> Adit( filesAll.children() );
290// for ( ; Adit.current(); ++Adit ) { 290// for ( ; Adit.current(); ++Adit ) {
291// if( QFileInfo( Adit.current()->file() ).exists() ) { 291// if( QFileInfo( Adit.current()->file() ).exists() ) {
292// d->selectedFiles->addToSelection( **Adit ); 292// d->selectedFiles->addToSelection( **Adit );
293// } 293// }
294// } 294// }
295 295
296 // qDebug("elapsed time %d", t.elapsed() ); 296 // qDebug("elapsed time %d", t.elapsed() );
297 297
298 tabWidget->setCurrentPage(0); 298 tabWidget->setCurrentPage(0);
299 299
300 writeCurrentM3u(); 300 writeCurrentM3u();
301 d->selectedFiles->first(); 301 d->selectedFiles->first();
302} 302}
303 303
304 304
305void PlayListWidget::addAllMusicToList() { 305void PlayListWidget::addAllMusicToList() {
306 306
307 audioView->populateView(); 307 audioView->populateView();
308 308
309 QListViewItemIterator audioIt( audioView ); 309 QListViewItemIterator audioIt( audioView );
310 DocLnk lnk; 310 DocLnk lnk;
311 QString filename; 311 QString filename;
312 // iterate through all items of the listview 312 // iterate through all items of the listview
313 for ( ; audioIt.current(); ++audioIt ) { 313 for ( ; audioIt.current(); ++audioIt ) {
314 filename = audioIt.current()->text(3); 314 filename = audioIt.current()->text(3);
315 lnk.setName( QFileInfo(filename).baseName() ); //sets name 315 lnk.setName( QFileInfo(filename).baseName() ); //sets name
316 lnk.setFile( filename ); //sets file name 316 lnk.setFile( filename ); //sets file name
317 d->selectedFiles->addToSelection( lnk); 317 d->selectedFiles->addToSelection( lnk);
318 } 318 }
319 319
320 /* if(!audioScan) 320 /* if(!audioScan)
321 scanForAudio(); 321 scanForAudio();
322 QListIterator<DocLnk> dit( files.children() ); 322 QListIterator<DocLnk> dit( files.children() );
323 for ( ; dit.current(); ++dit ) { 323 for ( ; dit.current(); ++dit ) {
324 if( QFileInfo(dit.current()->file() ).exists() ) { 324 if( QFileInfo(dit.current()->file() ).exists() ) {
325 d->selectedFiles->addToSelection( **dit ); 325 d->selectedFiles->addToSelection( **dit );
326 } 326 }
327 } 327 }
328 */ 328 */
329 tabWidget->setCurrentPage(0); 329 tabWidget->setCurrentPage(0);
330 writeCurrentM3u(); 330 writeCurrentM3u();
331 d->selectedFiles->first(); 331 d->selectedFiles->first();
332} 332}
333 333
334 334
335void PlayListWidget::addAllVideoToList() { 335void PlayListWidget::addAllVideoToList() {
336 336
337 videoView->populateView(); 337 videoView->populateView();
338 338
339 QListViewItemIterator videoIt( videoView ); 339 QListViewItemIterator videoIt( videoView );
340 DocLnk lnk; 340 DocLnk lnk;
341 QString filename; 341 QString filename;
342 for ( ; videoIt.current(); ++videoIt ) { 342 for ( ; videoIt.current(); ++videoIt ) {
343 filename = videoIt.current()->text(3); 343 filename = videoIt.current()->text(3);
344 lnk.setName( QFileInfo(filename).baseName() ); //sets name 344 lnk.setName( QFileInfo(filename).baseName() ); //sets name
345 lnk.setFile( filename ); //sets file name 345 lnk.setFile( filename ); //sets file name
346 d->selectedFiles->addToSelection( lnk); 346 d->selectedFiles->addToSelection( lnk);
347 } 347 }
348 348
349 349
350 /* if(!videoScan) 350 /* if(!videoScan)
351 scanForVideo(); 351 scanForVideo();
352 QListIterator<DocLnk> dit( vFiles.children() ); 352 QListIterator<DocLnk> dit( vFiles.children() );
353 for ( ; dit.current(); ++dit ) { 353 for ( ; dit.current(); ++dit ) {
354 if( QFileInfo( dit.current()->file() ).exists() ) { 354 if( QFileInfo( dit.current()->file() ).exists() ) {
355 d->selectedFiles->addToSelection( **dit ); 355 d->selectedFiles->addToSelection( **dit );
356 } 356 }
357 } 357 }
358*/ 358*/
359 tabWidget->setCurrentPage(0); 359 tabWidget->setCurrentPage(0);
360 writeCurrentM3u(); 360 writeCurrentM3u();
361 d->selectedFiles->first(); 361 d->selectedFiles->first();
362} 362}
363 363
364 364
365void PlayListWidget::setDocument( const QString& fileref ) { 365void PlayListWidget::setDocument( const QString& fileref ) {
366 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); 366 // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref );
367 fromSetDocument = TRUE; 367 fromSetDocument = TRUE;
368 QFileInfo fileInfo(fileref); 368 QFileInfo fileInfo(fileref);
369 369
370 if ( !fileInfo.exists() ) { 370 if ( !fileInfo.exists() ) {
371 QMessageBox::warning( this, tr( "Invalid File" ), 371 QMessageBox::warning( this, tr( "Invalid File" ),
372 tr( "There was a problem in getting the file." ) ); 372 tr( "There was a problem in getting the file." ) );
373 return; 373 return;
374 } 374 }
375 375
376 clearList(); 376 clearList();
377 QString extension = fileInfo.extension(false); 377 QString extension = fileInfo.extension(false);
378 378
379 if( extension.find( "m3u", 0, false) != -1 379 if( extension.find( "m3u", 0, false) != -1
380 || extension.find( "pls", 0, false) != -1 ) { 380 || extension.find( "pls", 0, false) != -1 ) {
381 readListFromFile( fileref ); 381 readListFromFile( fileref );
382 } else { 382 } else {
383 clearList(); 383 clearList();
384 DocLnk lnk; 384 DocLnk lnk;
385 lnk.setName( fileInfo.baseName() ); //sets name 385 lnk.setName( fileInfo.baseName() ); //sets name
386 lnk.setFile( fileref ); //sets file name 386 lnk.setFile( fileref ); //sets file name
387 addToSelection( lnk ); 387 addToSelection( lnk );
388 writeCurrentM3u(); 388 writeCurrentM3u();
389 389
390 d->setDocumentUsed = TRUE; 390 d->setDocumentUsed = TRUE;
391 mediaPlayerState.setPlaying( FALSE ); 391 mediaPlayerState.setPlaying( FALSE );
392 mediaPlayerState.setPlaying( TRUE ); 392 mediaPlayerState.setPlaying( TRUE );
393 } 393 }
394} 394}
395 395
396 396
397void PlayListWidget::useSelectedDocument() { 397void PlayListWidget::useSelectedDocument() {
398 d->setDocumentUsed = FALSE; 398 d->setDocumentUsed = FALSE;
399} 399}
400 400
401 401
402const DocLnk *PlayListWidget::current() const { // this is fugly 402const DocLnk *PlayListWidget::current() const { // this is fugly
403 assert( currentTab() == CurrentPlayList ); 403 assert( currentTab() == CurrentPlayList );
404 404
405 const DocLnk *lnk = d->selectedFiles->current(); 405 const DocLnk *lnk = d->selectedFiles->current();
406 if ( !lnk ) { 406 if ( !lnk ) {
407 d->selectedFiles->first(); 407 d->selectedFiles->first();
408 lnk = d->selectedFiles->current(); 408 lnk = d->selectedFiles->current();
409 } 409 }
410 assert( lnk ); 410 assert( lnk );
411 return lnk; 411 return lnk;
412} 412}
413 413
414 414
415bool PlayListWidget::prev() { 415bool PlayListWidget::prev() {
416 if ( mediaPlayerState.isShuffled() ) { 416 if ( mediaPlayerState.isShuffled() ) {
417 const DocLnk *cur = current(); 417 const DocLnk *cur = current();
418 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 418 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
419 for ( int i = 0; i < j; i++ ) { 419 for ( int i = 0; i < j; i++ ) {
420 if ( !d->selectedFiles->next() ) 420 if ( !d->selectedFiles->next() )
421 d->selectedFiles->first(); 421 d->selectedFiles->first();
422 } 422 }
423 if ( cur == current() ) 423 if ( cur == current() )
424 if ( !d->selectedFiles->next() ) { 424 if ( !d->selectedFiles->next() ) {
425 d->selectedFiles->first(); 425 d->selectedFiles->first();
426 } 426 }
427 return TRUE; 427 return TRUE;
428 } else { 428 } else {
429 if ( !d->selectedFiles->prev() ) { 429 if ( !d->selectedFiles->prev() ) {
430 if ( mediaPlayerState.isLooping() ) { 430 if ( mediaPlayerState.isLooping() ) {
431 return d->selectedFiles->last(); 431 return d->selectedFiles->last();
432 } else { 432 } else {
433 return FALSE; 433 return FALSE;
434 } 434 }
435 } 435 }
436 return TRUE; 436 return TRUE;
437 } 437 }
438} 438}
439 439
440 440
441bool PlayListWidget::next() { 441bool PlayListWidget::next() {
442//qDebug("<<<<<<<<<<<<next()"); 442//qDebug("<<<<<<<<<<<<next()");
443 if ( mediaPlayerState.isShuffled() ) { 443 if ( mediaPlayerState.isShuffled() ) {
444 return prev(); 444 return prev();
445 } else { 445 } else {
446 if ( !d->selectedFiles->next() ) { 446 if ( !d->selectedFiles->next() ) {
447 if ( mediaPlayerState.isLooping() ) { 447 if ( mediaPlayerState.isLooping() ) {
448 return d->selectedFiles->first(); 448 return d->selectedFiles->first();
449 } else { 449 } else {
450 return FALSE; 450 return FALSE;
451 } 451 }
452 } 452 }
453 return TRUE; 453 return TRUE;
454 } 454 }
455} 455}
456 456
457 457
458bool PlayListWidget::first() { 458bool PlayListWidget::first() {
459 return d->selectedFiles->first(); 459 return d->selectedFiles->first();
460} 460}
461 461
462 462
463bool PlayListWidget::last() { 463bool PlayListWidget::last() {
464 return d->selectedFiles->last(); 464 return d->selectedFiles->last();
465} 465}
466 466
467 467
468 void PlayListWidget::saveList() { 468 void PlayListWidget::saveList() {
469 writem3u(); 469 writem3u();
470 } 470 }
471 471
472 472
473void PlayListWidget::loadList( const DocLnk & lnk) { 473void PlayListWidget::loadList( const DocLnk & lnk) {
474 QString name = lnk.name(); 474 QString name = lnk.name();
475 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); 475 // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name);
476 476
477 if( name.length()>0) { 477 if( name.length()>0) {
478 setCaption("OpiePlayer: "+name); 478 setCaption("OpiePlayer: "+name);
479// qDebug("<<<<<<<<<<<<load list "+ lnk.file()); 479// qDebug("<<<<<<<<<<<<load list "+ lnk.file());
480 clearList(); 480 clearList();
481// readm3u(lnk.file()); 481// readm3u(lnk.file());
482 readListFromFile(lnk.file()); 482 readListFromFile(lnk.file());
483 tabWidget->setCurrentPage(0); 483 tabWidget->setCurrentPage(0);
484 } 484 }
485} 485}
486 486
487void PlayListWidget::addSelected() { 487void PlayListWidget::addSelected() {
488 assert( inFileListMode() ); 488 assert( inFileListMode() );
489 489
490 QListViewItemIterator it( currentFileListView ); 490 QListViewItemIterator it( currentFileListView );
491 for ( ; it.current(); ++it ) 491 for ( ; it.current(); ++it )
492 if ( it.current()->isSelected() ) { 492 if ( it.current()->isSelected() ) {
493 QString filename = it.current()->text(3); 493 QString filename = it.current()->text(3);
494 494
495 DocLnk lnk; 495 DocLnk lnk;
496 lnk.setName( QFileInfo( filename ).baseName() ); //sets name 496 lnk.setName( QFileInfo( filename ).baseName() ); //sets name
497 lnk.setFile( filename ); //sets file name 497 lnk.setFile( filename ); //sets file name
498 498
499 d->selectedFiles->addToSelection( lnk ); 499 d->selectedFiles->addToSelection( lnk );
500 } 500 }
501 501
502 currentFileListView->clearSelection(); 502 currentFileListView->clearSelection();
503 503
504// tabWidget->setCurrentPage( 0 ); 504// tabWidget->setCurrentPage( 0 );
505 writeCurrentM3u(); 505 writeCurrentM3u();
506} 506}
507 507
508 508
509void PlayListWidget::removeSelected() { 509void PlayListWidget::removeSelected() {
510 d->selectedFiles->removeSelected( ); 510 d->selectedFiles->removeSelected( );
511 writeCurrentM3u(); 511 writeCurrentM3u();
512} 512}
513 513
514 514
515void PlayListWidget::playIt( QListViewItem *it) { 515void PlayListWidget::playIt( QListViewItem *it) {
516 if(!it) return; 516 if(!it) return;
517 mediaPlayerState.setPlaying(FALSE); 517 mediaPlayerState.setPlaying(FALSE);
518 mediaPlayerState.setPlaying(TRUE); 518 mediaPlayerState.setPlaying(TRUE);
519 d->selectedFiles->unSelect(); 519 d->selectedFiles->unSelect();
520} 520}
521 521
522 522
523void PlayListWidget::addToSelection( QListViewItem *it) { 523void PlayListWidget::addToSelection( QListViewItem *it) {
524 d->setDocumentUsed = FALSE; 524 d->setDocumentUsed = FALSE;
525 525
526 if(it) { 526 if(it) {
527 if ( currentTab() == CurrentPlayList ) 527 if ( currentTab() == CurrentPlayList )
528 return; 528 return;
529 // case 1: { 529 // case 1: {
530 DocLnk lnk; 530 DocLnk lnk;
531 QString filename; 531 QString filename;
532 532
533 filename=it->text(3); 533 filename=it->text(3);
534 lnk.setName( QFileInfo(filename).baseName() ); //sets name 534 lnk.setName( QFileInfo(filename).baseName() ); //sets name
535 lnk.setFile( filename ); //sets file name 535 lnk.setFile( filename ); //sets file name
536 d->selectedFiles->addToSelection( lnk); 536 d->selectedFiles->addToSelection( lnk);
537 537
538 writeCurrentM3u(); 538 writeCurrentM3u();
539// tabWidget->setCurrentPage(0); 539// tabWidget->setCurrentPage(0);
540 540
541 } 541 }
542} 542}
543 543
544 544
545void PlayListWidget::tabChanged(QWidget *) { 545void PlayListWidget::tabChanged(QWidget *) {
546 546
547 d->tbPlay->setEnabled( true ); 547 d->tbPlay->setEnabled( true );
548 548
549 disconnect( audioView, SIGNAL( itemsSelected( bool ) ), 549 disconnect( audioView, SIGNAL( itemsSelected( bool ) ),
550 d->tbPlay, SLOT( setEnabled( bool ) ) ); 550 d->tbPlay, SLOT( setEnabled( bool ) ) );
551 disconnect( videoView, SIGNAL( itemsSelected( bool ) ), 551 disconnect( videoView, SIGNAL( itemsSelected( bool ) ),
552 d->tbPlay, SLOT( setEnabled( bool ) ) ); 552 d->tbPlay, SLOT( setEnabled( bool ) ) );
553 553
554 currentFileListView = 0; 554 currentFileListView = 0;
555 555
556 switch ( currentTab() ) { 556 switch ( currentTab() ) {
557 case CurrentPlayList: 557 case CurrentPlayList:
558 { 558 {
559 if( !tbDeletePlaylist->isHidden() ) { 559 if( !tbDeletePlaylist->isHidden() ) {
560 tbDeletePlaylist->hide(); 560 tbDeletePlaylist->hide();
561 } 561 }
562 d->tbRemoveFromList->setEnabled(TRUE); 562 d->tbRemoveFromList->setEnabled(TRUE);
563 d->tbAddToList->setEnabled(FALSE); 563 d->tbAddToList->setEnabled(FALSE);
564 564
565 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); 565 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() );
566 } 566 }
567 break; 567 break;
568 case AudioFiles: 568 case AudioFiles:
569 { 569 {
570 audioView->populateView(); 570 audioView->populateView();
571 571
572 if( !tbDeletePlaylist->isHidden() ) { 572 if( !tbDeletePlaylist->isHidden() ) {
573 tbDeletePlaylist->hide(); 573 tbDeletePlaylist->hide();
574 } 574 }
575 d->tbRemoveFromList->setEnabled(FALSE); 575 d->tbRemoveFromList->setEnabled(FALSE);
576 d->tbAddToList->setEnabled(TRUE); 576 d->tbAddToList->setEnabled(TRUE);
577 577
578 connect( audioView, SIGNAL( itemsSelected( bool ) ), 578 connect( audioView, SIGNAL( itemsSelected( bool ) ),
579 d->tbPlay, SLOT( setEnabled( bool ) ) ); 579 d->tbPlay, SLOT( setEnabled( bool ) ) );
580 580
581 d->tbPlay->setEnabled( audioView->hasSelection() ); 581 d->tbPlay->setEnabled( audioView->hasSelection() );
582 582
583 currentFileListView = audioView; 583 currentFileListView = audioView;
584 } 584 }
585 break; 585 break;
586 case VideoFiles: 586 case VideoFiles:
587 { 587 {
588 videoView->populateView(); 588 videoView->populateView();
589 if( !tbDeletePlaylist->isHidden() ) { 589 if( !tbDeletePlaylist->isHidden() ) {
590 tbDeletePlaylist->hide(); 590 tbDeletePlaylist->hide();
591 } 591 }
592 d->tbRemoveFromList->setEnabled(FALSE); 592 d->tbRemoveFromList->setEnabled(FALSE);
593 d->tbAddToList->setEnabled(TRUE); 593 d->tbAddToList->setEnabled(TRUE);
594 594
595 connect( videoView, SIGNAL( itemsSelected( bool ) ), 595 connect( videoView, SIGNAL( itemsSelected( bool ) ),
596 d->tbPlay, SLOT( setEnabled( bool ) ) ); 596 d->tbPlay, SLOT( setEnabled( bool ) ) );
597 597
598 d->tbPlay->setEnabled( videoView->hasSelection() ); 598 d->tbPlay->setEnabled( videoView->hasSelection() );
599 599
600 currentFileListView = videoView; 600 currentFileListView = videoView;
601 } 601 }
602 break; 602 break;
603 case PlayLists: 603 case PlayLists:
604 { 604 {
605 if( tbDeletePlaylist->isHidden() ) { 605 if( tbDeletePlaylist->isHidden() ) {
606 tbDeletePlaylist->show(); 606 tbDeletePlaylist->show();
607 } 607 }
608 playLists->reread(); 608 playLists->reread();
609 d->tbAddToList->setEnabled(FALSE); 609 d->tbAddToList->setEnabled(FALSE);
610 610
611 d->tbPlay->setEnabled( false ); 611 d->tbPlay->setEnabled( false );
612 } 612 }
613 break; 613 break;
614 }; 614 };
615} 615}
616 616
617 617
618void PlayListWidget::btnPlay(bool b) { 618void PlayListWidget::btnPlay(bool b) {
619// mediaPlayerState->setPlaying(false); 619// mediaPlayerState->setPlaying(false);
620 mediaPlayerState.setPlaying(b); 620 mediaPlayerState.setPlaying(b);
621 insanityBool=FALSE; 621 insanityBool=FALSE;
622} 622}
623 623
624void PlayListWidget::deletePlaylist() { 624void PlayListWidget::deletePlaylist() {
625 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 625 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
626 (tr("You really want to delete\nthis playlist?")), 626 (tr("You really want to delete\nthis playlist?")),
627 (tr("Yes")), (tr("No")), 0 )){ 627 (tr("Yes")), (tr("No")), 0 )){
628 case 0: // Yes clicked, 628 case 0: // Yes clicked,
629 QFile().remove(playLists->selectedDocument().file()); 629 QFile().remove(playLists->selectedDocument().file());
630 QFile().remove(playLists->selectedDocument().linkFile()); 630 QFile().remove(playLists->selectedDocument().linkFile());
631 playLists->reread(); 631 playLists->reread();
632 break; 632 break;
633 case 1: // Cancel 633 case 1: // Cancel
634 break; 634 break;
635 }; 635 };
636} 636}
637 637
638 638
639void PlayListWidget::playSelected() { 639void PlayListWidget::playSelected() {
640 btnPlay( TRUE); 640 btnPlay( TRUE);
641} 641}
642 642
643bool PlayListWidget::inFileListMode() const 643bool PlayListWidget::inFileListMode() const
644{ 644{
645 TabType tab = currentTab(); 645 TabType tab = currentTab();
646 return tab == AudioFiles || tab == VideoFiles; 646 return tab == AudioFiles || tab == VideoFiles;
647} 647}
648 648
649void PlayListWidget::openFile() { 649void PlayListWidget::openFile() {
650 // http://66.28.164.33:2080 650 // http://66.28.164.33:2080
651 // http://somafm.com/star0242.m3u 651 // http://somafm.com/star0242.m3u
652 QString filename, name; 652 QString filename, name;
653 InputDialog *fileDlg; 653 InputDialog *fileDlg;
654 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 654 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
655 fileDlg->exec(); 655 fileDlg->exec();
656 if( fileDlg->result() == 1 ) { 656 if( fileDlg->result() == 1 ) {
657 filename = fileDlg->text(); 657 filename = fileDlg->text();
658 qDebug( "Selected filename is " + filename ); 658 qDebug( "Selected filename is " + filename );
659 // Om3u *m3uList; 659 // Om3u *m3uList;
660 DocLnk lnk; 660 DocLnk lnk;
661 Config cfg( "OpiePlayer" ); 661 Config cfg( "OpiePlayer" );
662 cfg.setGroup("PlayList"); 662 cfg.setGroup("PlayList");
663 663
664 if(filename.left(4) == "http") { 664 if(filename.left(4) == "http") {
665 QString m3uFile, m3uFilePath; 665 QString m3uFile, m3uFilePath;
666 if(filename.find(":",8,TRUE) != -1) { //found a port 666 if(filename.find(":",8,TRUE) != -1) { //found a port
667 m3uFile = filename.left( filename.find( ":",8,TRUE)); 667 m3uFile = filename.left( filename.find( ":",8,TRUE));
668 m3uFile = m3uFile.right( 7); 668 m3uFile = m3uFile.right( 7);
669 } else if(filename.left(4) == "http"){ 669 } else if(filename.left(4) == "http"){
670 m3uFile=filename; 670 m3uFile=filename;
671 m3uFile = m3uFile.right( m3uFile.length() - 7); 671 m3uFile = m3uFile.right( m3uFile.length() - 7);
672 } else{ 672 } else{
673 m3uFile=filename; 673 m3uFile=filename;
674 } 674 }
675 675
676// qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); 676// qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile);
677 lnk.setName( filename ); //sets name 677 lnk.setName( filename ); //sets name
678 lnk.setFile( filename ); //sets file name 678 lnk.setFile( filename ); //sets file name
679 679
680// lnk.setIcon("opieplayer2/musicfile"); 680// lnk.setIcon("opieplayer2/musicfile");
681 681
682 d->selectedFiles->addToSelection( lnk ); 682 d->selectedFiles->addToSelection( lnk );
683 writeCurrentM3u(); 683 writeCurrentM3u();
684 d->selectedFiles->setSelectedItem( lnk.name()); 684 d->selectedFiles->setSelectedItem( lnk.name());
685 } 685 }
686 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 686 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
687 readListFromFile( filename ); 687 readListFromFile( filename );
688// readPls( filename ); 688// readPls( filename );
689 } else { 689 } else {
690 lnk.setName( QFileInfo(filename).baseName() ); //sets name 690 lnk.setName( QFileInfo(filename).baseName() ); //sets name
691 lnk.setFile( filename ); //sets file name 691 lnk.setFile( filename ); //sets file name
692 d->selectedFiles->addToSelection( lnk); 692 d->selectedFiles->addToSelection( lnk);
693 writeCurrentM3u(); 693 writeCurrentM3u();
694 d->selectedFiles->setSelectedItem( lnk.name()); 694 d->selectedFiles->setSelectedItem( lnk.name());
695 } 695 }
696 } 696 }
697 697
698 698
699 delete fileDlg; 699 delete fileDlg;
700} 700}
701 701
702void PlayListWidget::readListFromFile( const QString &filename ) { 702void PlayListWidget::readListFromFile( const QString &filename ) {
703 qDebug( "read list filename " + filename ); 703 qDebug( "read list filename " + filename );
704 QFileInfo fi(filename); 704 QFileInfo fi(filename);
705 Om3u *m3uList; 705 Om3u *m3uList;
706 QString s, name; 706 QString s, name;
707 m3uList = new Om3u( filename, IO_ReadOnly ); 707 m3uList = new Om3u( filename, IO_ReadOnly );
708 if(fi.extension(false).find("m3u",0,false) != -1 ) 708 if(fi.extension(false).find("m3u",0,false) != -1 )
709 m3uList->readM3u(); 709 m3uList->readM3u();
710 else if(fi.extension(false).find("pls",0,false) != -1 ) 710 else if(fi.extension(false).find("pls",0,false) != -1 )
711 m3uList->readPls(); 711 m3uList->readPls();
712 712
713 DocLnk lnk; 713 DocLnk lnk;
714 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 714 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
715 s = *it; 715 s = *it;
716 // qDebug(s); 716 // qDebug(s);
717 if(s.left(4)=="http") { 717 if(s.left(4)=="http") {
718 lnk.setName( s ); //sets file name 718 lnk.setName( s ); //sets file name
719 lnk.setIcon("opieplayer2/musicfile"); 719 lnk.setIcon("opieplayer2/musicfile");
720 lnk.setFile( s ); //sets file name 720 lnk.setFile( s ); //sets file name
721 721
722 } else { //is file 722 } else { //is file
723 lnk.setName( QFileInfo(s).baseName()); 723 lnk.setName( QFileInfo(s).baseName());
724 if(s.left(1) != "/") { 724 if(s.left(1) != "/") {
725 725
726 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 726 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
727 } else { 727 } else {
728 lnk.setFile( s); 728 lnk.setFile( s);
729 } 729 }
730 } 730 }
731 d->selectedFiles->addToSelection( lnk ); 731 d->selectedFiles->addToSelection( lnk );
732 } 732 }
733 Config config( "OpiePlayer" ); 733 Config config( "OpiePlayer" );
734 config.setGroup( "PlayList" ); 734 config.setGroup( "PlayList" );
735 735
736 config.writeEntry("CurrentPlaylist",filename); 736 config.writeEntry("CurrentPlaylist",filename);
737 config.write(); 737 config.write();
738 currentPlayList=filename; 738 currentPlayList=filename;
739 739
740// m3uList->write(); 740// m3uList->write();
741 m3uList->close(); 741 m3uList->close();
742 delete m3uList; 742 delete m3uList;
743 743
744 d->selectedFiles->setSelectedItem( s); 744 d->selectedFiles->setSelectedItem( s);
745 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); 745 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName());
746 746
747} 747}
748 748
749// /* 749// /*
750// reads pls and adds files/urls to playlist */ 750// reads pls and adds files/urls to playlist */
751// void PlayListWidget::readPls( const QString &filename ) { 751// void PlayListWidget::readPls( const QString &filename ) {
752 752
753// qDebug( "pls filename is " + filename ); 753// qDebug( "pls filename is " + filename );
754// Om3u *m3uList; 754// Om3u *m3uList;
755// QString s, name; 755// QString s, name;
756// m3uList = new Om3u( filename, IO_ReadOnly ); 756// m3uList = new Om3u( filename, IO_ReadOnly );
757// m3uList->readPls(); 757// m3uList->readPls();
758 758
759// for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 759// for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
760// s = *it; 760// s = *it;
761// // s.replace( QRegExp( "%20" )," " ); 761// // s.replace( QRegExp( "%20" )," " );
762// DocLnk lnk( s ); 762// DocLnk lnk( s );
763// QFileInfo f( s ); 763// QFileInfo f( s );
764// QString name = f.baseName(); 764// QString name = f.baseName();
765 765
766// if( name.left( 4 ) == "http" ) { 766// if( name.left( 4 ) == "http" ) {
767// name = s.right( s.length() - 7); 767// name = s.right( s.length() - 7);
768// } else { 768// } else {
769// name = s; 769// name = s;
770// } 770// }
771 771
772// name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 772// name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
773 773
774// lnk.setName( name ); 774// lnk.setName( name );
775// if( s.at( s.length() - 4) == '.') {// if this is probably a file 775// if( s.at( s.length() - 4) == '.') {// if this is probably a file
776// lnk.setFile( s ); 776// lnk.setFile( s );
777// } else { //if its a url 777// } else { //if its a url
778// // if( name.right( 1 ).find( '/' ) == -1) { 778// // if( name.right( 1 ).find( '/' ) == -1) {
779// // s += "/"; 779// // s += "/";
780// // } 780// // }
781// lnk.setFile( s ); 781// lnk.setFile( s );
782// } 782// }
783// lnk.setType( "audio/x-mpegurl" ); 783// lnk.setType( "audio/x-mpegurl" );
784 784
785// lnk.writeLink(); 785// lnk.writeLink();
786// d->selectedFiles->addToSelection( lnk ); 786// d->selectedFiles->addToSelection( lnk );
787// } 787// }
788 788
789// m3uList->close(); 789// m3uList->close();
790// delete m3uList; 790// delete m3uList;
791// } 791// }
792 792
793// /* 793// /*
794// writes current playlist to current m3u file */ 794// writes current playlist to current m3u file */
795 void PlayListWidget::writeCurrentM3u() { 795 void PlayListWidget::writeCurrentM3u() {
796 qDebug("writing to current m3u"); 796 qDebug("writing to current m3u");
797 Config cfg( "OpiePlayer" ); 797 Config cfg( "OpiePlayer" );
798 cfg.setGroup("PlayList"); 798 cfg.setGroup("PlayList");
799 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); 799 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default");
800 800
801 Om3u *m3uList; 801 Om3u *m3uList;
802 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); 802 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
803 if( d->selectedFiles->first()) { 803 if( d->selectedFiles->first()) {
804 804
805 do { 805 do {
806 // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file()); 806 // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file());
807 m3uList->add( d->selectedFiles->current()->file() ); 807 m3uList->add( d->selectedFiles->current()->file() );
808 } 808 }
809 while ( d->selectedFiles->next() ); 809 while ( d->selectedFiles->next() );
810 // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); 810 // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" );
811 m3uList->write(); 811 m3uList->write();
812 m3uList->close(); 812 m3uList->close();
813 } 813 }
814 delete m3uList; 814 delete m3uList;
815 815
816 } 816 }
817 817
818 /* 818 /*
819 writes current playlist to m3u file */ 819 writes current playlist to m3u file */
820void PlayListWidget::writem3u() { 820void PlayListWidget::writem3u() {
821 InputDialog *fileDlg; 821 InputDialog *fileDlg;
822 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); 822 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
823 fileDlg->exec(); 823 fileDlg->exec();
824 QString name, filename, list; 824 QString name, filename, list;
825 Om3u *m3uList; 825 Om3u *m3uList;
826 826
827 if( fileDlg->result() == 1 ) { 827 if( fileDlg->result() == 1 ) {
828 name = fileDlg->text(); 828 name = fileDlg->text();
829// qDebug( filename ); 829// qDebug( filename );
830 830 if( name.find("/",0,true) != -1) {// assume they specify a file path
831 if( name.left( 1) != "/" ) { 831 filename = name;
832 filename = QPEApplication::documentDir() + "/" + name; 832 name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
833 }
834
835 if( name.right( 3 ) != "m3u" ) {
836 filename = QPEApplication::documentDir() + "/" +name+".m3u";
837 } 833 }
834 else //otherwise dump it somewhere noticable
835 filename = QPEApplication::documentDir() + "/" + name;
838 836
839 if( d->selectedFiles->first()) { 837 if( filename.right( 3 ) != "m3u" ) //needs filename extension
840 m3uList = new Om3u(filename, IO_ReadWrite); 838 filename += ".m3u";
839
840 if( d->selectedFiles->first()) { //ramble through playlist view
841 m3uList = new Om3u( filename, IO_ReadWrite);
841 842
842 do { 843 do {
843 m3uList->add( d->selectedFiles->current()->file()); 844 m3uList->add( d->selectedFiles->current()->file());
844 } 845 }
845 while ( d->selectedFiles->next() ); 846 while ( d->selectedFiles->next() );
846 // qDebug( list ); 847 // qDebug( list );
847 m3uList->write(); 848 m3uList->write();
848 m3uList->close(); 849 m3uList->close();
849 delete m3uList; 850 delete m3uList;
850 851
851 delete fileDlg; 852 delete fileDlg;
852 853
853 DocLnk lnk; 854 DocLnk lnk;
854 lnk.setFile( filename); 855 lnk.setFile( filename);
855 lnk.setIcon("opieplayer2/playlist2"); 856 lnk.setIcon("opieplayer2/playlist2");
856 lnk.setName( name); //sets file name 857 lnk.setName( name); //sets file name
857 858
858 // qDebug(filename); 859 // qDebug(filename);
859 Config config( "OpiePlayer" ); 860 Config config( "OpiePlayer" );
860 config.setGroup( "PlayList" ); 861 config.setGroup( "PlayList" );
861 862
862 config.writeEntry("CurrentPlaylist",filename); 863 config.writeEntry("CurrentPlaylist",filename);
863 currentPlayList=filename; 864 currentPlayList=filename;
864 865
865 if(!lnk.writeLink()) { 866 if(!lnk.writeLink()) {
866 qDebug("Writing doclink did not work"); 867 qDebug("Writing doclink did not work");
867 } 868 }
868 869
869 setCaption(tr("OpiePlayer: ") + name); 870 setCaption(tr("OpiePlayer: ") + name);
870 } 871 }
871 } 872 }
872} 873}
873 874
874void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 875void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
875 switch ( e->key() ) { 876 switch ( e->key() ) {
876 ////////////////////////////// Zaurus keys 877 ////////////////////////////// Zaurus keys
877 case Key_F9: //activity 878 case Key_F9: //activity
878 // if(audioUI->isHidden()) 879 // if(audioUI->isHidden())
879 // audioUI->showMaximized(); 880 // audioUI->showMaximized();
880 break; 881 break;
881 case Key_F10: //contacts 882 case Key_F10: //contacts
882 // if( videoUI->isHidden()) 883 // if( videoUI->isHidden())
883 // videoUI->showMaximized(); 884 // videoUI->showMaximized();
884 break; 885 break;
885 case Key_F11: //menu 886 case Key_F11: //menu
886 break; 887 break;
887 case Key_F12: //home 888 case Key_F12: //home
888 // doBlank(); 889 // doBlank();
889 break; 890 break;
890 case Key_F13: //mail 891 case Key_F13: //mail
891 // doUnblank(); 892 // doUnblank();
892 break; 893 break;
893 case Key_Q: //add to playlist 894 case Key_Q: //add to playlist
894 addSelected(); 895 addSelected();
895 break; 896 break;
896 case Key_R: //remove from playlist 897 case Key_R: //remove from playlist
897 removeSelected(); 898 removeSelected();
898 break; 899 break;
899 // case Key_P: //play 900 // case Key_P: //play
900 // qDebug("Play"); 901 // qDebug("Play");
901 // playSelected(); 902 // playSelected();
902 // break; 903 // break;
903 case Key_Space: 904 case Key_Space:
904 // playSelected(); puh 905 // playSelected(); puh
905 break; 906 break;
906 case Key_1: 907 case Key_1:
907 tabWidget->setCurrentPage( 0 ); 908 tabWidget->setCurrentPage( 0 );
908 break; 909 break;
909 case Key_2: 910 case Key_2:
910 tabWidget->setCurrentPage( 1 ); 911 tabWidget->setCurrentPage( 1 );
911 break; 912 break;
912 case Key_3: 913 case Key_3:
913 tabWidget->setCurrentPage( 2 ); 914 tabWidget->setCurrentPage( 2 );
914 break; 915 break;
915 case Key_4: 916 case Key_4:
916 tabWidget->setCurrentPage( 3 ); 917 tabWidget->setCurrentPage( 3 );
917 break; 918 break;
918 case Key_Down: 919 case Key_Down:
919 if ( !d->selectedFiles->next() ) 920 if ( !d->selectedFiles->next() )
920 d->selectedFiles->first(); 921 d->selectedFiles->first();
921 break; 922 break;
922 case Key_Up: 923 case Key_Up:
923 if ( !d->selectedFiles->prev() ) 924 if ( !d->selectedFiles->prev() )
924 // d->selectedFiles->last(); 925 // d->selectedFiles->last();
925 break; 926 break;
926 } 927 }
927} 928}
928 929
929void PlayListWidget::pmViewActivated(int index) { 930void PlayListWidget::pmViewActivated(int index) {
930// qDebug("%d", index); 931// qDebug("%d", index);
931 switch(index) { 932 switch(index) {
932 case -16: 933 case -16:
933 { 934 {
934 mediaPlayerState.toggleFullscreen(); 935 mediaPlayerState.toggleFullscreen();
935 bool b=mediaPlayerState.isFullscreen(); 936 bool b=mediaPlayerState.isFullscreen();
936 pmView->setItemChecked( index, b); 937 pmView->setItemChecked( index, b);
937 Config cfg( "OpiePlayer" ); 938 Config cfg( "OpiePlayer" );
938 cfg.writeEntry( "FullScreen", b ); 939 cfg.writeEntry( "FullScreen", b );
939 } 940 }
940 break; 941 break;
941 }; 942 };
942} 943}
943 944
944void PlayListWidget::populateSkinsMenu() { 945void PlayListWidget::populateSkinsMenu() {
945 int item = 0; 946 int item = 0;
946 defaultSkinIndex = 0; 947 defaultSkinIndex = 0;
947 QString skinName; 948 QString skinName;
948 Config cfg( "OpiePlayer" ); 949 Config cfg( "OpiePlayer" );
949 cfg.setGroup("Options" ); 950 cfg.setGroup("Options" );
950 QString skin = cfg.readEntry( "Skin", "default" ); 951 QString skin = cfg.readEntry( "Skin", "default" );
951 952
952 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); 953 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" );
953 skinsDir.setFilter( QDir::Dirs ); 954 skinsDir.setFilter( QDir::Dirs );
954 skinsDir.setSorting(QDir::Name ); 955 skinsDir.setSorting(QDir::Name );
955 const QFileInfoList *skinslist = skinsDir.entryInfoList(); 956 const QFileInfoList *skinslist = skinsDir.entryInfoList();
956 QFileInfoListIterator it( *skinslist ); 957 QFileInfoListIterator it( *skinslist );
957 QFileInfo *fi; 958 QFileInfo *fi;
958 while ( ( fi = it.current() ) ) { 959 while ( ( fi = it.current() ) ) {
959 skinName = fi->fileName(); 960 skinName = fi->fileName();
960// qDebug( fi->fileName() ); 961// qDebug( fi->fileName() );
961 if( skinName != "." && skinName != ".." && skinName !="CVS" ) { 962 if( skinName != "." && skinName != ".." && skinName !="CVS" ) {
962 item = skinsMenu->insertItem( fi->fileName() ) ; 963 item = skinsMenu->insertItem( fi->fileName() ) ;
963 } 964 }
964 if( skinName == "default" ) { 965 if( skinName == "default" ) {
965 defaultSkinIndex = item; 966 defaultSkinIndex = item;
966 } 967 }
967 if( skinName == skin ) { 968 if( skinName == skin ) {
968 skinsMenu->setItemChecked( item, TRUE ); 969 skinsMenu->setItemChecked( item, TRUE );
969 } 970 }
970 ++it; 971 ++it;
971 } 972 }
972} 973}
973 974
974void PlayListWidget::skinsMenuActivated( int item ) { 975void PlayListWidget::skinsMenuActivated( int item ) {
975 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { 976 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) {
976 skinsMenu->setItemChecked( i, FALSE ); 977 skinsMenu->setItemChecked( i, FALSE );
977 } 978 }
978 skinsMenu->setItemChecked( item, TRUE ); 979 skinsMenu->setItemChecked( item, TRUE );
979 980
980 { 981 {
981 Config cfg( "OpiePlayer" ); 982 Config cfg( "OpiePlayer" );
982 cfg.setGroup("Options"); 983 cfg.setGroup("Options");
983 cfg.writeEntry("Skin", skinsMenu->text( item ) ); 984 cfg.writeEntry("Skin", skinsMenu->text( item ) );
984 } 985 }
985 986
986 emit skinSelected(); 987 emit skinSelected();
987} 988}
988 989
989PlayListWidget::TabType PlayListWidget::currentTab() const 990PlayListWidget::TabType PlayListWidget::currentTab() const
990{ 991{
991 static const TabType indexToTabType[ TabTypeCount ] = 992 static const TabType indexToTabType[ TabTypeCount ] =
992 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists }; 993 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists };
993 994
994 int index = tabWidget->currentPageIndex(); 995 int index = tabWidget->currentPageIndex();
995 assert( index < TabTypeCount && index >= 0 ); 996 assert( index < TabTypeCount && index >= 0 );
996 997
997 return indexToTabType[ index ]; 998 return indexToTabType[ index ];
998} 999}
999 1000
1000PlayListWidget::Entry PlayListWidget::currentEntry() const 1001PlayListWidget::Entry PlayListWidget::currentEntry() const
1001{ 1002{
1002 if ( currentTab() == CurrentPlayList ) { 1003 if ( currentTab() == CurrentPlayList ) {
1003 const DocLnk *lnk = current(); 1004 const DocLnk *lnk = current();
1004 return Entry( lnk->name(), lnk->file() ); 1005 return Entry( lnk->name(), lnk->file() );
1005 } 1006 }
1006 1007
1007 return Entry( currentFileListPathName() ); 1008 return Entry( currentFileListPathName() );
1008} 1009}
1009 1010
1010QString PlayListWidget::currentFileListPathName() const { 1011QString PlayListWidget::currentFileListPathName() const {
1011 return currentFileListView->currentItem()->text( 3 ); 1012 return currentFileListView->currentItem()->text( 3 );
1012} 1013}