author | llornkcor <llornkcor> | 2002-06-17 23:21:17 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-17 23:21:17 (UTC) |
commit | 8b089ad594fad0eed4303bc83db4910784e17dd5 (patch) (unidiff) | |
tree | 77a84d7b564db72f4c04b6efc2e4fa2d8c9eef11 | |
parent | 554f88d0e8839bd6112fa42139a967712552e519 (diff) | |
download | opie-8b089ad594fad0eed4303bc83db4910784e17dd5.zip opie-8b089ad594fad0eed4303bc83db4910784e17dd5.tar.gz opie-8b089ad594fad0eed4303bc83db4910784e17dd5.tar.bz2 |
check for file existing before adding to playlist
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 35208e4..b0d4958 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -228,417 +228,422 @@ PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | |||
228 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 228 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
229 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 229 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
230 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 230 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
231 | 231 | ||
232 | QWidget *aTab; | 232 | QWidget *aTab; |
233 | aTab = new QWidget( tabWidget, "aTab" ); | 233 | aTab = new QWidget( tabWidget, "aTab" ); |
234 | audioView = new QListView( aTab, "Audioview" ); | 234 | audioView = new QListView( aTab, "Audioview" ); |
235 | audioView->setMinimumSize(233,260); | 235 | audioView->setMinimumSize(233,260); |
236 | audioView->addColumn( tr("Title"),140); | 236 | audioView->addColumn( tr("Title"),140); |
237 | audioView->addColumn(tr("Size"), -1); | 237 | audioView->addColumn(tr("Size"), -1); |
238 | audioView->addColumn(tr("Media"),-1); | 238 | audioView->addColumn(tr("Media"),-1); |
239 | audioView->setColumnAlignment(1, Qt::AlignRight); | 239 | audioView->setColumnAlignment(1, Qt::AlignRight); |
240 | audioView->setColumnAlignment(2, Qt::AlignRight); | 240 | audioView->setColumnAlignment(2, Qt::AlignRight); |
241 | audioView->setAllColumnsShowFocus(TRUE); | 241 | audioView->setAllColumnsShowFocus(TRUE); |
242 | 242 | ||
243 | audioView->setMultiSelection( TRUE ); | 243 | audioView->setMultiSelection( TRUE ); |
244 | audioView->setSelectionMode( QListView::Extended); | 244 | audioView->setSelectionMode( QListView::Extended); |
245 | 245 | ||
246 | tabWidget->insertTab(aTab,tr("Audio")); | 246 | tabWidget->insertTab(aTab,tr("Audio")); |
247 | 247 | ||
248 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 248 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
249 | 249 | ||
250 | // audioView | 250 | // audioView |
251 | // populateAudioView(); | 251 | // populateAudioView(); |
252 | // videowidget | 252 | // videowidget |
253 | 253 | ||
254 | QWidget *vTab; | 254 | QWidget *vTab; |
255 | vTab = new QWidget( tabWidget, "vTab" ); | 255 | vTab = new QWidget( tabWidget, "vTab" ); |
256 | videoView = new QListView( vTab, "Videoview" ); | 256 | videoView = new QListView( vTab, "Videoview" ); |
257 | videoView->setMinimumSize(233,260); | 257 | videoView->setMinimumSize(233,260); |
258 | 258 | ||
259 | videoView->addColumn(tr("Title"),140); | 259 | videoView->addColumn(tr("Title"),140); |
260 | videoView->addColumn(tr("Size"),-1); | 260 | videoView->addColumn(tr("Size"),-1); |
261 | videoView->addColumn(tr("Media"),-1); | 261 | videoView->addColumn(tr("Media"),-1); |
262 | videoView->setColumnAlignment(1, Qt::AlignRight); | 262 | videoView->setColumnAlignment(1, Qt::AlignRight); |
263 | videoView->setColumnAlignment(2, Qt::AlignRight); | 263 | videoView->setColumnAlignment(2, Qt::AlignRight); |
264 | videoView->setAllColumnsShowFocus(TRUE); | 264 | videoView->setAllColumnsShowFocus(TRUE); |
265 | videoView->setMultiSelection( TRUE ); | 265 | videoView->setMultiSelection( TRUE ); |
266 | videoView->setSelectionMode( QListView::Extended); | 266 | videoView->setSelectionMode( QListView::Extended); |
267 | 267 | ||
268 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 268 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
269 | 269 | ||
270 | tabWidget->insertTab( vTab,tr("Video")); | 270 | tabWidget->insertTab( vTab,tr("Video")); |
271 | // populateVideoView(); | 271 | // populateVideoView(); |
272 | 272 | ||
273 | //playlists list | 273 | //playlists list |
274 | QWidget *LTab; | 274 | QWidget *LTab; |
275 | LTab = new QWidget( tabWidget, "LTab" ); | 275 | LTab = new QWidget( tabWidget, "LTab" ); |
276 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy | 276 | playLists = new FileSelector( "playlist/plain", LTab, "fileselector" , FALSE, FALSE); //buggy |
277 | playLists->setMinimumSize(233,260); | 277 | playLists->setMinimumSize(233,260); |
278 | tabWidget->insertTab(LTab,tr("Lists")); | 278 | tabWidget->insertTab(LTab,tr("Lists")); |
279 | 279 | ||
280 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 280 | // connect( playLists, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
281 | 281 | ||
282 | // add the library area | 282 | // add the library area |
283 | 283 | ||
284 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 284 | // connect( audioView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
285 | // this, SLOT( fauxPlay( QListViewItem *) ) ); | 285 | // this, SLOT( fauxPlay( QListViewItem *) ) ); |
286 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), | 286 | // connect( videoView, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int)), |
287 | // this, SLOT( fauxPlay( QListViewItem *)) ); | 287 | // this, SLOT( fauxPlay( QListViewItem *)) ); |
288 | 288 | ||
289 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 289 | // connect( audioView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
290 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); | 290 | // connect( videoView, SIGNAL( clicked( QListViewItem *) ), this, SLOT( fauxPlay( QListViewItem *) ) ); |
291 | 291 | ||
292 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | 292 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
293 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | 293 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); |
294 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | 294 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); |
295 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 295 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
296 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | 296 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); |
297 | 297 | ||
298 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 298 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
299 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 299 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
300 | 300 | ||
301 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | 301 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), |
302 | this,SLOT( playIt( QListViewItem *)) ); | 302 | this,SLOT( playIt( QListViewItem *)) ); |
303 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 303 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
304 | 304 | ||
305 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 305 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
306 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 306 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
307 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | 307 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), |
308 | this,SLOT( playIt( QListViewItem *)) ); | 308 | this,SLOT( playIt( QListViewItem *)) ); |
309 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 309 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
310 | 310 | ||
311 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 311 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
312 | 312 | ||
313 | 313 | ||
314 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 314 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
315 | 315 | ||
316 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 316 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
317 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 317 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
318 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 318 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
319 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 319 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
320 | 320 | ||
321 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 321 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
322 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); | 322 | // connect( d->selectedFiles, SIGNAL( fileSelected( const DocLnk & ) ), this, SLOT( addToSelection( const DocLnk & ) ) ); |
323 | 323 | ||
324 | setCentralWidget( vbox5 ); | 324 | setCentralWidget( vbox5 ); |
325 | 325 | ||
326 | Config cfg( "OpiePlayer" ); | 326 | Config cfg( "OpiePlayer" ); |
327 | readConfig( cfg ); | 327 | readConfig( cfg ); |
328 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); | 328 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); |
329 | // qDebug("currentList is "+currentPlaylist); | 329 | // qDebug("currentList is "+currentPlaylist); |
330 | loadList(DocLnk( currentPlaylist)); | 330 | loadList(DocLnk( currentPlaylist)); |
331 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); | 331 | setCaption(tr("OpiePlayer: ")+ currentPlaylist ); |
332 | 332 | ||
333 | initializeStates(); | 333 | initializeStates(); |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | PlayListWidget::~PlayListWidget() { | 337 | PlayListWidget::~PlayListWidget() { |
338 | Config cfg( "OpiePlayer" ); | 338 | Config cfg( "OpiePlayer" ); |
339 | writeConfig( cfg ); | 339 | writeConfig( cfg ); |
340 | 340 | ||
341 | 341 | ||
342 | if ( d->current ) | 342 | if ( d->current ) |
343 | delete d->current; | 343 | delete d->current; |
344 | delete d; | 344 | delete d; |
345 | } | 345 | } |
346 | 346 | ||
347 | 347 | ||
348 | void PlayListWidget::initializeStates() { | 348 | void PlayListWidget::initializeStates() { |
349 | 349 | ||
350 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 350 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
351 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 351 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
352 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 352 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
353 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); | 353 | // d->tbFull->setOn( mediaPlayerState->fullscreen() ); |
354 | // d->tbScale->setOn( mediaPlayerState->scaled() ); | 354 | // d->tbScale->setOn( mediaPlayerState->scaled() ); |
355 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); | 355 | // d->tbScale->setEnabled( mediaPlayerState->fullscreen() ); |
356 | // setPlaylist( mediaPlayerState->playlist() ); | 356 | // setPlaylist( mediaPlayerState->playlist() ); |
357 | setPlaylist( true); | 357 | setPlaylist( true); |
358 | // d->selectedFiles->first(); | 358 | // d->selectedFiles->first(); |
359 | 359 | ||
360 | } | 360 | } |
361 | 361 | ||
362 | 362 | ||
363 | void PlayListWidget::readConfig( Config& cfg ) { | 363 | void PlayListWidget::readConfig( Config& cfg ) { |
364 | cfg.setGroup("PlayList"); | 364 | cfg.setGroup("PlayList"); |
365 | QString currentString = cfg.readEntry("current", "" ); | 365 | QString currentString = cfg.readEntry("current", "" ); |
366 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 366 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
367 | for ( int i = 0; i < noOfFiles; i++ ) { | 367 | for ( int i = 0; i < noOfFiles; i++ ) { |
368 | QString entryName; | 368 | QString entryName; |
369 | entryName.sprintf( "File%i", i + 1 ); | 369 | entryName.sprintf( "File%i", i + 1 ); |
370 | QString linkFile = cfg.readEntry( entryName ); | 370 | QString linkFile = cfg.readEntry( entryName ); |
371 | DocLnk lnk( linkFile ); | 371 | DocLnk lnk( linkFile ); |
372 | if ( lnk.isValid() ) { | 372 | if ( lnk.isValid() ) { |
373 | d->selectedFiles->addToSelection( lnk ); | 373 | d->selectedFiles->addToSelection( lnk ); |
374 | } | 374 | } |
375 | } | 375 | } |
376 | d->selectedFiles->setSelectedItem( currentString); | 376 | d->selectedFiles->setSelectedItem( currentString); |
377 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); | 377 | // d->selectedFiles->setSelectedItem( (const QString &)currentString); |
378 | } | 378 | } |
379 | 379 | ||
380 | 380 | ||
381 | void PlayListWidget::writeConfig( Config& cfg ) const { | 381 | void PlayListWidget::writeConfig( Config& cfg ) const { |
382 | 382 | ||
383 | d->selectedFiles->writeCurrent( cfg); | 383 | d->selectedFiles->writeCurrent( cfg); |
384 | cfg.setGroup("PlayList"); | 384 | cfg.setGroup("PlayList"); |
385 | int noOfFiles = 0; | 385 | int noOfFiles = 0; |
386 | d->selectedFiles->first(); | 386 | d->selectedFiles->first(); |
387 | do { | 387 | do { |
388 | const DocLnk *lnk = d->selectedFiles->current(); | 388 | const DocLnk *lnk = d->selectedFiles->current(); |
389 | if ( lnk ) { | 389 | if ( lnk ) { |
390 | QString entryName; | 390 | QString entryName; |
391 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 391 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
392 | // qDebug(entryName); | 392 | // qDebug(entryName); |
393 | cfg.writeEntry( entryName, lnk->linkFile() ); | 393 | cfg.writeEntry( entryName, lnk->linkFile() ); |
394 | // if this link does exist, add it so we have the file | 394 | // if this link does exist, add it so we have the file |
395 | // next time... | 395 | // next time... |
396 | if ( !QFile::exists( lnk->linkFile() ) ) { | 396 | if ( !QFile::exists( lnk->linkFile() ) ) { |
397 | // the way writing lnks doesn't really check for out | 397 | // the way writing lnks doesn't really check for out |
398 | // of disk space, but check it anyway. | 398 | // of disk space, but check it anyway. |
399 | if ( !lnk->writeLink() ) { | 399 | if ( !lnk->writeLink() ) { |
400 | QMessageBox::critical( 0, tr("Out of space"), | 400 | QMessageBox::critical( 0, tr("Out of space"), |
401 | tr( "There was a problem saving " | 401 | tr( "There was a problem saving " |
402 | "the playlist.\n" | 402 | "the playlist.\n" |
403 | "Your playlist " | 403 | "Your playlist " |
404 | "may be missing some entries\n" | 404 | "may be missing some entries\n" |
405 | "the next time you start it." ) | 405 | "the next time you start it." ) |
406 | ); | 406 | ); |
407 | } | 407 | } |
408 | } | 408 | } |
409 | noOfFiles++; | 409 | noOfFiles++; |
410 | } | 410 | } |
411 | } | 411 | } |
412 | while ( d->selectedFiles->next() ); | 412 | while ( d->selectedFiles->next() ); |
413 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 413 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 417 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
418 | // qDebug("add"); | 418 | // qDebug("add"); |
419 | d->setDocumentUsed = FALSE; | 419 | d->setDocumentUsed = FALSE; |
420 | if ( mediaPlayerState->playlist() ) | 420 | if ( mediaPlayerState->playlist() ) { |
421 | d->selectedFiles->addToSelection( lnk ); | 421 | if(QFileInfo(lnk.file()).exists()) |
422 | d->selectedFiles->addToSelection( lnk ); | ||
423 | } | ||
422 | else | 424 | else |
423 | mediaPlayerState->setPlaying( TRUE ); | 425 | mediaPlayerState->setPlaying( TRUE ); |
424 | } | 426 | } |
425 | 427 | ||
426 | 428 | ||
427 | void PlayListWidget::clearList() { | 429 | void PlayListWidget::clearList() { |
428 | while ( first() ) | 430 | while ( first() ) |
429 | d->selectedFiles->removeSelected(); | 431 | d->selectedFiles->removeSelected(); |
430 | } | 432 | } |
431 | 433 | ||
432 | 434 | ||
433 | void PlayListWidget::addAllToList() { | 435 | void PlayListWidget::addAllToList() { |
434 | DocLnkSet filesAll; | 436 | DocLnkSet filesAll; |
435 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 437 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
436 | QListIterator<DocLnk> Adit( filesAll.children() ); | 438 | QListIterator<DocLnk> Adit( filesAll.children() ); |
437 | for ( ; Adit.current(); ++Adit ) | 439 | for ( ; Adit.current(); ++Adit ) |
438 | d->selectedFiles->addToSelection( **Adit ); | 440 | if(QFileInfo(Adit.current()->file()).exists()) |
441 | d->selectedFiles->addToSelection( **Adit ); | ||
439 | } | 442 | } |
440 | 443 | ||
441 | 444 | ||
442 | void PlayListWidget::addAllMusicToList() { | 445 | void PlayListWidget::addAllMusicToList() { |
443 | QListIterator<DocLnk> dit( files.children() ); | 446 | QListIterator<DocLnk> dit( files.children() ); |
444 | for ( ; dit.current(); ++dit ) | 447 | for ( ; dit.current(); ++dit ) |
448 | if(QFileInfo(dit.current()->file()).exists()) | ||
445 | d->selectedFiles->addToSelection( **dit ); | 449 | d->selectedFiles->addToSelection( **dit ); |
446 | } | 450 | } |
447 | 451 | ||
448 | 452 | ||
449 | void PlayListWidget::addAllVideoToList() { | 453 | void PlayListWidget::addAllVideoToList() { |
450 | QListIterator<DocLnk> dit( vFiles.children() ); | 454 | QListIterator<DocLnk> dit( vFiles.children() ); |
451 | for ( ; dit.current(); ++dit ) | 455 | for ( ; dit.current(); ++dit ) |
452 | d->selectedFiles->addToSelection( **dit ); | 456 | if(QFileInfo( dit.current()->file()).exists()) |
457 | d->selectedFiles->addToSelection( **dit ); | ||
453 | } | 458 | } |
454 | 459 | ||
455 | 460 | ||
456 | void PlayListWidget::setDocument(const QString& fileref) { | 461 | void PlayListWidget::setDocument(const QString& fileref) { |
457 | qDebug(fileref); | 462 | qDebug(fileref); |
458 | fromSetDocument = TRUE; | 463 | fromSetDocument = TRUE; |
459 | if ( fileref.isNull() ) { | 464 | if ( fileref.isNull() ) { |
460 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); | 465 | QMessageBox::critical( 0, tr( "Invalid File" ), tr( "There was a problem in getting the file." ) ); |
461 | return; | 466 | return; |
462 | } | 467 | } |
463 | // qDebug("setDocument "+fileref); | 468 | // qDebug("setDocument "+fileref); |
464 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u | 469 | if(fileref.find("m3u",0,TRUE) != -1) { //is m3u |
465 | readm3u( fileref); | 470 | readm3u( fileref); |
466 | } | 471 | } |
467 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls | 472 | else if(fileref.find("pls",0,TRUE) != -1) { //is pls |
468 | readPls( fileref); | 473 | readPls( fileref); |
469 | } | 474 | } |
470 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist | 475 | else if(fileref.find("playlist",0,TRUE) != -1) {//is playlist |
471 | clearList(); | 476 | clearList(); |
472 | loadList(DocLnk(fileref)); | 477 | loadList(DocLnk(fileref)); |
473 | d->selectedFiles->first(); | 478 | d->selectedFiles->first(); |
474 | } else { | 479 | } else { |
475 | clearList(); | 480 | clearList(); |
476 | addToSelection( DocLnk( fileref ) ); | 481 | addToSelection( DocLnk( fileref ) ); |
477 | d->setDocumentUsed = TRUE; | 482 | d->setDocumentUsed = TRUE; |
478 | mediaPlayerState->setPlaying( FALSE ); | 483 | mediaPlayerState->setPlaying( FALSE ); |
479 | qApp->processEvents(); | 484 | qApp->processEvents(); |
480 | mediaPlayerState->setPlaying( TRUE ); | 485 | mediaPlayerState->setPlaying( TRUE ); |
481 | qApp->processEvents(); | 486 | qApp->processEvents(); |
482 | setCaption(tr("OpiePlayer")); | 487 | setCaption(tr("OpiePlayer")); |
483 | } | 488 | } |
484 | } | 489 | } |
485 | 490 | ||
486 | 491 | ||
487 | void PlayListWidget::setActiveWindow() { | 492 | void PlayListWidget::setActiveWindow() { |
488 | // When we get raised we need to ensure that it switches views | 493 | // When we get raised we need to ensure that it switches views |
489 | char origView = mediaPlayerState->view(); | 494 | char origView = mediaPlayerState->view(); |
490 | mediaPlayerState->setView( 'l' ); // invalidate | 495 | mediaPlayerState->setView( 'l' ); // invalidate |
491 | mediaPlayerState->setView( origView ); // now switch back | 496 | mediaPlayerState->setView( origView ); // now switch back |
492 | } | 497 | } |
493 | 498 | ||
494 | 499 | ||
495 | void PlayListWidget::useSelectedDocument() { | 500 | void PlayListWidget::useSelectedDocument() { |
496 | d->setDocumentUsed = FALSE; | 501 | d->setDocumentUsed = FALSE; |
497 | } | 502 | } |
498 | 503 | ||
499 | 504 | ||
500 | const DocLnk *PlayListWidget::current() { // this is fugly | 505 | const DocLnk *PlayListWidget::current() { // this is fugly |
501 | 506 | ||
502 | // if( fromSetDocument) { | 507 | // if( fromSetDocument) { |
503 | // qDebug("from setDoc"); | 508 | // qDebug("from setDoc"); |
504 | // DocLnkSet files; | 509 | // DocLnkSet files; |
505 | // Global::findDocuments(&files, "video/*;audio/*"); | 510 | // Global::findDocuments(&files, "video/*;audio/*"); |
506 | // QListIterator<DocLnk> dit( files.children() ); | 511 | // QListIterator<DocLnk> dit( files.children() ); |
507 | // for ( ; dit.current(); ++dit ) { | 512 | // for ( ; dit.current(); ++dit ) { |
508 | // if(dit.current()->linkFile() == setDocFileRef) { | 513 | // if(dit.current()->linkFile() == setDocFileRef) { |
509 | // qDebug(setDocFileRef); | 514 | // qDebug(setDocFileRef); |
510 | // return dit; | 515 | // return dit; |
511 | // } | 516 | // } |
512 | // } | 517 | // } |
513 | // } else | 518 | // } else |
514 | 519 | ||
515 | 520 | ||
516 | switch (tabWidget->currentPageIndex()) { | 521 | switch (tabWidget->currentPageIndex()) { |
517 | case 0: //playlist | 522 | case 0: //playlist |
518 | { | 523 | { |
519 | qDebug("playlist"); | 524 | qDebug("playlist"); |
520 | if ( mediaPlayerState->playlist() ) { | 525 | if ( mediaPlayerState->playlist() ) { |
521 | return d->selectedFiles->current(); | 526 | return d->selectedFiles->current(); |
522 | } | 527 | } |
523 | else if ( d->setDocumentUsed && d->current ) { | 528 | else if ( d->setDocumentUsed && d->current ) { |
524 | return d->current; | 529 | return d->current; |
525 | } else { | 530 | } else { |
526 | return d->files->selected(); | 531 | return d->files->selected(); |
527 | } | 532 | } |
528 | } | 533 | } |
529 | break; | 534 | break; |
530 | case 1://audio | 535 | case 1://audio |
531 | { | 536 | { |
532 | qDebug("audioView"); | 537 | qDebug("audioView"); |
533 | QListIterator<DocLnk> dit( files.children() ); | 538 | QListIterator<DocLnk> dit( files.children() ); |
534 | for ( ; dit.current(); ++dit ) { | 539 | for ( ; dit.current(); ++dit ) { |
535 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | 540 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { |
536 | qDebug("here"); | 541 | qDebug("here"); |
537 | insanityBool=TRUE; | 542 | insanityBool=TRUE; |
538 | return dit; | 543 | return dit; |
539 | } | 544 | } |
540 | } | 545 | } |
541 | } | 546 | } |
542 | break; | 547 | break; |
543 | case 2: // video | 548 | case 2: // video |
544 | { | 549 | { |
545 | qDebug("videoView"); | 550 | qDebug("videoView"); |
546 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 551 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
547 | for ( ; Vdit.current(); ++Vdit ) { | 552 | for ( ; Vdit.current(); ++Vdit ) { |
548 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | 553 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { |
549 | insanityBool=TRUE; | 554 | insanityBool=TRUE; |
550 | return Vdit; | 555 | return Vdit; |
551 | } | 556 | } |
552 | } | 557 | } |
553 | } | 558 | } |
554 | break; | 559 | break; |
555 | }; | 560 | }; |
556 | return 0; | 561 | return 0; |
557 | } | 562 | } |
558 | 563 | ||
559 | bool PlayListWidget::prev() { | 564 | bool PlayListWidget::prev() { |
560 | if ( mediaPlayerState->playlist() ) { | 565 | if ( mediaPlayerState->playlist() ) { |
561 | if ( mediaPlayerState->shuffled() ) { | 566 | if ( mediaPlayerState->shuffled() ) { |
562 | const DocLnk *cur = current(); | 567 | const DocLnk *cur = current(); |
563 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 568 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
564 | for ( int i = 0; i < j; i++ ) { | 569 | for ( int i = 0; i < j; i++ ) { |
565 | if ( !d->selectedFiles->next() ) | 570 | if ( !d->selectedFiles->next() ) |
566 | d->selectedFiles->first(); | 571 | d->selectedFiles->first(); |
567 | } | 572 | } |
568 | if ( cur == current() ) | 573 | if ( cur == current() ) |
569 | if ( !d->selectedFiles->next() ) | 574 | if ( !d->selectedFiles->next() ) |
570 | d->selectedFiles->first(); | 575 | d->selectedFiles->first(); |
571 | return TRUE; | 576 | return TRUE; |
572 | } else { | 577 | } else { |
573 | if ( !d->selectedFiles->prev() ) { | 578 | if ( !d->selectedFiles->prev() ) { |
574 | if ( mediaPlayerState->looping() ) { | 579 | if ( mediaPlayerState->looping() ) { |
575 | return d->selectedFiles->last(); | 580 | return d->selectedFiles->last(); |
576 | } else { | 581 | } else { |
577 | return FALSE; | 582 | return FALSE; |
578 | } | 583 | } |
579 | } | 584 | } |
580 | return TRUE; | 585 | return TRUE; |
581 | } | 586 | } |
582 | } else { | 587 | } else { |
583 | return mediaPlayerState->looping(); | 588 | return mediaPlayerState->looping(); |
584 | } | 589 | } |
585 | } | 590 | } |
586 | 591 | ||
587 | 592 | ||
588 | bool PlayListWidget::next() { | 593 | bool PlayListWidget::next() { |
589 | if ( mediaPlayerState->playlist() ) { | 594 | if ( mediaPlayerState->playlist() ) { |
590 | if ( mediaPlayerState->shuffled() ) { | 595 | if ( mediaPlayerState->shuffled() ) { |
591 | return prev(); | 596 | return prev(); |
592 | } else { | 597 | } else { |
593 | if ( !d->selectedFiles->next() ) { | 598 | if ( !d->selectedFiles->next() ) { |
594 | if ( mediaPlayerState->looping() ) { | 599 | if ( mediaPlayerState->looping() ) { |
595 | return d->selectedFiles->first(); | 600 | return d->selectedFiles->first(); |
596 | } else { | 601 | } else { |
597 | return FALSE; | 602 | return FALSE; |
598 | } | 603 | } |
599 | } | 604 | } |
600 | return TRUE; | 605 | return TRUE; |
601 | } | 606 | } |
602 | } else { | 607 | } else { |
603 | return mediaPlayerState->looping(); | 608 | return mediaPlayerState->looping(); |
604 | } | 609 | } |
605 | } | 610 | } |
606 | 611 | ||
607 | 612 | ||
608 | bool PlayListWidget::first() { | 613 | bool PlayListWidget::first() { |
609 | if ( mediaPlayerState->playlist() ) | 614 | if ( mediaPlayerState->playlist() ) |
610 | return d->selectedFiles->first(); | 615 | return d->selectedFiles->first(); |
611 | else | 616 | else |
612 | return mediaPlayerState->looping(); | 617 | return mediaPlayerState->looping(); |
613 | } | 618 | } |
614 | 619 | ||
615 | 620 | ||
616 | bool PlayListWidget::last() { | 621 | bool PlayListWidget::last() { |
617 | if ( mediaPlayerState->playlist() ) | 622 | if ( mediaPlayerState->playlist() ) |
618 | return d->selectedFiles->last(); | 623 | return d->selectedFiles->last(); |
619 | else | 624 | else |
620 | return mediaPlayerState->looping(); | 625 | return mediaPlayerState->looping(); |
621 | } | 626 | } |
622 | 627 | ||
623 | 628 | ||
624 | void PlayListWidget::saveList() { | 629 | void PlayListWidget::saveList() { |
625 | 630 | ||
626 | QString filename; | 631 | QString filename; |
627 | InputDialog *fileDlg; | 632 | InputDialog *fileDlg; |
628 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); | 633 | fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); |
629 | fileDlg->exec(); | 634 | fileDlg->exec(); |
630 | if( fileDlg->result() == 1 ) { | 635 | if( fileDlg->result() == 1 ) { |
631 | if ( d->current ) | 636 | if ( d->current ) |
632 | delete d->current; | 637 | delete d->current; |
633 | filename = fileDlg->LineEdit1->text();//+".playlist"; | 638 | filename = fileDlg->LineEdit1->text();//+".playlist"; |
634 | // qDebug("saving playlist "+filename+".playlist"); | 639 | // qDebug("saving playlist "+filename+".playlist"); |
635 | Config cfg( filename +".playlist"); | 640 | Config cfg( filename +".playlist"); |
636 | writeConfig( cfg ); | 641 | writeConfig( cfg ); |
637 | 642 | ||
638 | DocLnk lnk; | 643 | DocLnk lnk; |
639 | // lnk.setComment( ""); | 644 | // lnk.setComment( ""); |
640 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property | 645 | lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property |
641 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D | 646 | lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D |
642 | lnk.setIcon("opieplayer/playlist2"); | 647 | lnk.setIcon("opieplayer/playlist2"); |
643 | lnk.setName( filename); //sets file name | 648 | lnk.setName( filename); //sets file name |
644 | // qDebug(filename); | 649 | // qDebug(filename); |