-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index c9ae225..a8429e3 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -255,768 +255,769 @@ void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoi | |||
255 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 255 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
256 | m.exec( QCursor::pos() ); | 256 | m.exec( QCursor::pos() ); |
257 | } | 257 | } |
258 | break; | 258 | break; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | 262 | ||
263 | void PlayListWidget::addAllToList() { | 263 | void PlayListWidget::addAllToList() { |
264 | 264 | ||
265 | // QTime t; | 265 | // QTime t; |
266 | // t.start(); | 266 | // t.start(); |
267 | 267 | ||
268 | if(!audioScan) { | 268 | if(!audioScan) { |
269 | if(audioView->childCount() < 1) | 269 | if(audioView->childCount() < 1) |
270 | populateAudioView(); | 270 | populateAudioView(); |
271 | } | 271 | } |
272 | 272 | ||
273 | QListViewItemIterator audioIt( audioView ); | 273 | QListViewItemIterator audioIt( audioView ); |
274 | DocLnk lnk; | 274 | DocLnk lnk; |
275 | QString filename; | 275 | QString filename; |
276 | // iterate through all items of the listview | 276 | // iterate through all items of the listview |
277 | for ( ; audioIt.current(); ++audioIt ) { | 277 | for ( ; audioIt.current(); ++audioIt ) { |
278 | filename = audioIt.current()->text(3); | 278 | filename = audioIt.current()->text(3); |
279 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 279 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
280 | lnk.setFile( filename ); //sets file name | 280 | lnk.setFile( filename ); //sets file name |
281 | d->selectedFiles->addToSelection( lnk); | 281 | d->selectedFiles->addToSelection( lnk); |
282 | } | 282 | } |
283 | 283 | ||
284 | if(!videoScan) { | 284 | if(!videoScan) { |
285 | if(videoView->childCount() < 1) | 285 | if(videoView->childCount() < 1) |
286 | populateVideoView(); | 286 | populateVideoView(); |
287 | } | 287 | } |
288 | 288 | ||
289 | QListViewItemIterator videoIt( videoView ); | 289 | QListViewItemIterator videoIt( videoView ); |
290 | for ( ; videoIt.current(); ++videoIt ) { | 290 | for ( ; videoIt.current(); ++videoIt ) { |
291 | filename = videoIt.current()->text(3); | 291 | filename = videoIt.current()->text(3); |
292 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 292 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
293 | lnk.setFile( filename ); //sets file name | 293 | lnk.setFile( filename ); //sets file name |
294 | d->selectedFiles->addToSelection( lnk); | 294 | d->selectedFiles->addToSelection( lnk); |
295 | } | 295 | } |
296 | 296 | ||
297 | // d->selectedFiles->addToSelection( ); | 297 | // d->selectedFiles->addToSelection( ); |
298 | // if ( it.current()->isSelected() ) | 298 | // if ( it.current()->isSelected() ) |
299 | // lst->append( audioIt.current() ); | 299 | // lst->append( audioIt.current() ); |
300 | // } | 300 | // } |
301 | 301 | ||
302 | 302 | ||
303 | // if(!audioScan) | 303 | // if(!audioScan) |
304 | // scanForAudio(); | 304 | // scanForAudio(); |
305 | // if(!videoScan) | 305 | // if(!videoScan) |
306 | // scanForVideo(); | 306 | // scanForVideo(); |
307 | 307 | ||
308 | // DocLnkSet filesAll; | 308 | // DocLnkSet filesAll; |
309 | // Global::findDocuments(&filesAll, "video/*;"+audioMimes); | 309 | // Global::findDocuments(&filesAll, "video/*;"+audioMimes); |
310 | // QListIterator<DocLnk> Adit( filesAll.children() ); | 310 | // QListIterator<DocLnk> Adit( filesAll.children() ); |
311 | // for ( ; Adit.current(); ++Adit ) { | 311 | // for ( ; Adit.current(); ++Adit ) { |
312 | // if( QFileInfo( Adit.current()->file() ).exists() ) { | 312 | // if( QFileInfo( Adit.current()->file() ).exists() ) { |
313 | // d->selectedFiles->addToSelection( **Adit ); | 313 | // d->selectedFiles->addToSelection( **Adit ); |
314 | // } | 314 | // } |
315 | // } | 315 | // } |
316 | 316 | ||
317 | // qDebug("elapsed time %d", t.elapsed() ); | 317 | // qDebug("elapsed time %d", t.elapsed() ); |
318 | 318 | ||
319 | tabWidget->setCurrentPage(0); | 319 | tabWidget->setCurrentPage(0); |
320 | 320 | ||
321 | writeCurrentM3u(); | 321 | writeCurrentM3u(); |
322 | d->selectedFiles->first(); | 322 | d->selectedFiles->first(); |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | void PlayListWidget::addAllMusicToList() { | 326 | void PlayListWidget::addAllMusicToList() { |
327 | 327 | ||
328 | if(!audioScan) { | 328 | if(!audioScan) { |
329 | if(audioView->childCount() < 1) | 329 | if(audioView->childCount() < 1) |
330 | populateAudioView(); | 330 | populateAudioView(); |
331 | } | 331 | } |
332 | 332 | ||
333 | QListViewItemIterator audioIt( audioView ); | 333 | QListViewItemIterator audioIt( audioView ); |
334 | DocLnk lnk; | 334 | DocLnk lnk; |
335 | QString filename; | 335 | QString filename; |
336 | // iterate through all items of the listview | 336 | // iterate through all items of the listview |
337 | for ( ; audioIt.current(); ++audioIt ) { | 337 | for ( ; audioIt.current(); ++audioIt ) { |
338 | filename = audioIt.current()->text(3); | 338 | filename = audioIt.current()->text(3); |
339 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 339 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
340 | lnk.setFile( filename ); //sets file name | 340 | lnk.setFile( filename ); //sets file name |
341 | d->selectedFiles->addToSelection( lnk); | 341 | d->selectedFiles->addToSelection( lnk); |
342 | } | 342 | } |
343 | 343 | ||
344 | /* if(!audioScan) | 344 | /* if(!audioScan) |
345 | scanForAudio(); | 345 | scanForAudio(); |
346 | QListIterator<DocLnk> dit( files.children() ); | 346 | QListIterator<DocLnk> dit( files.children() ); |
347 | for ( ; dit.current(); ++dit ) { | 347 | for ( ; dit.current(); ++dit ) { |
348 | if( QFileInfo(dit.current()->file() ).exists() ) { | 348 | if( QFileInfo(dit.current()->file() ).exists() ) { |
349 | d->selectedFiles->addToSelection( **dit ); | 349 | d->selectedFiles->addToSelection( **dit ); |
350 | } | 350 | } |
351 | } | 351 | } |
352 | */ | 352 | */ |
353 | tabWidget->setCurrentPage(0); | 353 | tabWidget->setCurrentPage(0); |
354 | writeCurrentM3u(); | 354 | writeCurrentM3u(); |
355 | d->selectedFiles->first(); | 355 | d->selectedFiles->first(); |
356 | } | 356 | } |
357 | 357 | ||
358 | 358 | ||
359 | void PlayListWidget::addAllVideoToList() { | 359 | void PlayListWidget::addAllVideoToList() { |
360 | 360 | ||
361 | if(!videoScan) { | 361 | if(!videoScan) { |
362 | if(videoView->childCount() < 1) | 362 | if(videoView->childCount() < 1) |
363 | populateVideoView(); | 363 | populateVideoView(); |
364 | } | 364 | } |
365 | 365 | ||
366 | QListViewItemIterator videoIt( videoView ); | 366 | QListViewItemIterator videoIt( videoView ); |
367 | DocLnk lnk; | 367 | DocLnk lnk; |
368 | QString filename; | 368 | QString filename; |
369 | for ( ; videoIt.current(); ++videoIt ) { | 369 | for ( ; videoIt.current(); ++videoIt ) { |
370 | filename = videoIt.current()->text(3); | 370 | filename = videoIt.current()->text(3); |
371 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 371 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
372 | lnk.setFile( filename ); //sets file name | 372 | lnk.setFile( filename ); //sets file name |
373 | d->selectedFiles->addToSelection( lnk); | 373 | d->selectedFiles->addToSelection( lnk); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
377 | /* if(!videoScan) | 377 | /* if(!videoScan) |
378 | scanForVideo(); | 378 | scanForVideo(); |
379 | QListIterator<DocLnk> dit( vFiles.children() ); | 379 | QListIterator<DocLnk> dit( vFiles.children() ); |
380 | for ( ; dit.current(); ++dit ) { | 380 | for ( ; dit.current(); ++dit ) { |
381 | if( QFileInfo( dit.current()->file() ).exists() ) { | 381 | if( QFileInfo( dit.current()->file() ).exists() ) { |
382 | d->selectedFiles->addToSelection( **dit ); | 382 | d->selectedFiles->addToSelection( **dit ); |
383 | } | 383 | } |
384 | } | 384 | } |
385 | */ | 385 | */ |
386 | tabWidget->setCurrentPage(0); | 386 | tabWidget->setCurrentPage(0); |
387 | writeCurrentM3u(); | 387 | writeCurrentM3u(); |
388 | d->selectedFiles->first(); | 388 | d->selectedFiles->first(); |
389 | } | 389 | } |
390 | 390 | ||
391 | 391 | ||
392 | void PlayListWidget::setDocument( const QString& fileref ) { | 392 | void PlayListWidget::setDocument( const QString& fileref ) { |
393 | // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); | 393 | // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); |
394 | fromSetDocument = TRUE; | 394 | fromSetDocument = TRUE; |
395 | if ( fileref.isNull() ) { | 395 | if ( fileref.isNull() ) { |
396 | QMessageBox::warning( this, tr( "Invalid File" ), | 396 | QMessageBox::warning( this, tr( "Invalid File" ), |
397 | tr( "There was a problem in getting the file." ) ); | 397 | tr( "There was a problem in getting the file." ) ); |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | 400 | ||
401 | clearList(); | 401 | clearList(); |
402 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u | 402 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u |
403 | readm3u( fileref ); | 403 | readm3u( fileref ); |
404 | } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { | 404 | } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { |
405 | readm3u( DocLnk( fileref).file() ); | 405 | readm3u( DocLnk( fileref).file() ); |
406 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls | 406 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls |
407 | readPls( fileref ); | 407 | readPls( fileref ); |
408 | } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { | 408 | } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { |
409 | readPls( DocLnk( fileref).file() ); | 409 | readPls( DocLnk( fileref).file() ); |
410 | } else { | 410 | } else { |
411 | clearList(); | 411 | clearList(); |
412 | addToSelection( DocLnk( fileref ) ); | 412 | addToSelection( DocLnk( fileref ) ); |
413 | writeCurrentM3u(); | 413 | writeCurrentM3u(); |
414 | 414 | ||
415 | d->setDocumentUsed = TRUE; | 415 | d->setDocumentUsed = TRUE; |
416 | mediaPlayerState->setPlaying( FALSE ); | 416 | mediaPlayerState->setPlaying( FALSE ); |
417 | mediaPlayerState->setPlaying( TRUE ); | 417 | mediaPlayerState->setPlaying( TRUE ); |
418 | } | 418 | } |
419 | } | 419 | } |
420 | 420 | ||
421 | 421 | ||
422 | void PlayListWidget::useSelectedDocument() { | 422 | void PlayListWidget::useSelectedDocument() { |
423 | d->setDocumentUsed = FALSE; | 423 | d->setDocumentUsed = FALSE; |
424 | } | 424 | } |
425 | 425 | ||
426 | 426 | ||
427 | const DocLnk *PlayListWidget::current() { // this is fugly | 427 | const DocLnk *PlayListWidget::current() { // this is fugly |
428 | assert( currentTab() == CurrentPlayList ); | 428 | assert( currentTab() == CurrentPlayList ); |
429 | 429 | ||
430 | // qDebug("playlist"); | 430 | // qDebug("playlist"); |
431 | if ( mediaPlayerState->isUsingPlaylist() ) { | 431 | if ( mediaPlayerState->isUsingPlaylist() ) { |
432 | return d->selectedFiles->current(); | 432 | return d->selectedFiles->current(); |
433 | } else if ( d->setDocumentUsed && d->current ) { | 433 | } else if ( d->setDocumentUsed && d->current ) { |
434 | return d->current; | 434 | return d->current; |
435 | } else { | 435 | } else { |
436 | return &(d->files->selectedDocument()); | 436 | return &(d->files->selectedDocument()); |
437 | } | 437 | } |
438 | } | 438 | } |
439 | 439 | ||
440 | 440 | ||
441 | bool PlayListWidget::prev() { | 441 | bool PlayListWidget::prev() { |
442 | if ( mediaPlayerState->isUsingPlaylist() ) { | 442 | if ( mediaPlayerState->isUsingPlaylist() ) { |
443 | if ( mediaPlayerState->isShuffled() ) { | 443 | if ( mediaPlayerState->isShuffled() ) { |
444 | const DocLnk *cur = current(); | 444 | const DocLnk *cur = current(); |
445 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 445 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
446 | for ( int i = 0; i < j; i++ ) { | 446 | for ( int i = 0; i < j; i++ ) { |
447 | if ( !d->selectedFiles->next() ) | 447 | if ( !d->selectedFiles->next() ) |
448 | d->selectedFiles->first(); | 448 | d->selectedFiles->first(); |
449 | } | 449 | } |
450 | if ( cur == current() ) | 450 | if ( cur == current() ) |
451 | if ( !d->selectedFiles->next() ) { | 451 | if ( !d->selectedFiles->next() ) { |
452 | d->selectedFiles->first(); | 452 | d->selectedFiles->first(); |
453 | } | 453 | } |
454 | return TRUE; | 454 | return TRUE; |
455 | } else { | 455 | } else { |
456 | if ( !d->selectedFiles->prev() ) { | 456 | if ( !d->selectedFiles->prev() ) { |
457 | if ( mediaPlayerState->isLooping() ) { | 457 | if ( mediaPlayerState->isLooping() ) { |
458 | return d->selectedFiles->last(); | 458 | return d->selectedFiles->last(); |
459 | } else { | 459 | } else { |
460 | return FALSE; | 460 | return FALSE; |
461 | } | 461 | } |
462 | } | 462 | } |
463 | return TRUE; | 463 | return TRUE; |
464 | } | 464 | } |
465 | } else { | 465 | } else { |
466 | return mediaPlayerState->isLooping(); | 466 | return mediaPlayerState->isLooping(); |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | 470 | ||
471 | bool PlayListWidget::next() { | 471 | bool PlayListWidget::next() { |
472 | //qDebug("<<<<<<<<<<<<next()"); | 472 | //qDebug("<<<<<<<<<<<<next()"); |
473 | if ( mediaPlayerState->isUsingPlaylist() ) { | 473 | if ( mediaPlayerState->isUsingPlaylist() ) { |
474 | if ( mediaPlayerState->isShuffled() ) { | 474 | if ( mediaPlayerState->isShuffled() ) { |
475 | return prev(); | 475 | return prev(); |
476 | } else { | 476 | } else { |
477 | if ( !d->selectedFiles->next() ) { | 477 | if ( !d->selectedFiles->next() ) { |
478 | if ( mediaPlayerState->isLooping() ) { | 478 | if ( mediaPlayerState->isLooping() ) { |
479 | return d->selectedFiles->first(); | 479 | return d->selectedFiles->first(); |
480 | } else { | 480 | } else { |
481 | return FALSE; | 481 | return FALSE; |
482 | } | 482 | } |
483 | } | 483 | } |
484 | return TRUE; | 484 | return TRUE; |
485 | } | 485 | } |
486 | } else { | 486 | } else { |
487 | return mediaPlayerState->isLooping(); | 487 | return mediaPlayerState->isLooping(); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | bool PlayListWidget::first() { | 492 | bool PlayListWidget::first() { |
493 | if ( mediaPlayerState->isUsingPlaylist() ) | 493 | if ( mediaPlayerState->isUsingPlaylist() ) |
494 | return d->selectedFiles->first(); | 494 | return d->selectedFiles->first(); |
495 | else | 495 | else |
496 | return mediaPlayerState->isLooping(); | 496 | return mediaPlayerState->isLooping(); |
497 | } | 497 | } |
498 | 498 | ||
499 | 499 | ||
500 | bool PlayListWidget::last() { | 500 | bool PlayListWidget::last() { |
501 | if ( mediaPlayerState->isUsingPlaylist() ) | 501 | if ( mediaPlayerState->isUsingPlaylist() ) |
502 | return d->selectedFiles->last(); | 502 | return d->selectedFiles->last(); |
503 | else | 503 | else |
504 | return mediaPlayerState->isLooping(); | 504 | return mediaPlayerState->isLooping(); |
505 | } | 505 | } |
506 | 506 | ||
507 | 507 | ||
508 | void PlayListWidget::saveList() { | 508 | void PlayListWidget::saveList() { |
509 | writem3u(); | 509 | writem3u(); |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | void PlayListWidget::loadList( const DocLnk & lnk) { | 513 | void PlayListWidget::loadList( const DocLnk & lnk) { |
514 | QString name = lnk.name(); | 514 | QString name = lnk.name(); |
515 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); | 515 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); |
516 | 516 | ||
517 | if( name.length()>0) { | 517 | if( name.length()>0) { |
518 | setCaption("OpiePlayer: "+name); | 518 | setCaption("OpiePlayer: "+name); |
519 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); | 519 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); |
520 | clearList(); | 520 | clearList(); |
521 | readm3u(lnk.file()); | 521 | readm3u(lnk.file()); |
522 | tabWidget->setCurrentPage(0); | 522 | tabWidget->setCurrentPage(0); |
523 | } | 523 | } |
524 | } | 524 | } |
525 | 525 | ||
526 | 526 | ||
527 | void PlayListWidget::setPlaylist( bool shown ) { | 527 | void PlayListWidget::setPlaylist( bool shown ) { |
528 | if ( shown ) { | 528 | if ( shown ) { |
529 | d->playListFrame->show(); | 529 | d->playListFrame->show(); |
530 | } else { | 530 | } else { |
531 | d->playListFrame->hide(); | 531 | d->playListFrame->hide(); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | 534 | ||
535 | 535 | ||
536 | void PlayListWidget::addSelected() { | 536 | void PlayListWidget::addSelected() { |
537 | assert( inFileListMode() ); | 537 | assert( inFileListMode() ); |
538 | 538 | ||
539 | QListView *fileListView = currentFileListView(); | 539 | QListView *fileListView = currentFileListView(); |
540 | QListViewItemIterator it( fileListView ); | 540 | QListViewItemIterator it( fileListView ); |
541 | for ( ; it.current(); ++it ) | 541 | for ( ; it.current(); ++it ) |
542 | if ( it.current()->isSelected() ) { | 542 | if ( it.current()->isSelected() ) { |
543 | QString filename = it.current()->text(3); | 543 | QString filename = it.current()->text(3); |
544 | 544 | ||
545 | DocLnk lnk; | 545 | DocLnk lnk; |
546 | lnk.setName( QFileInfo( filename ).baseName() ); //sets name | 546 | lnk.setName( QFileInfo( filename ).baseName() ); //sets name |
547 | lnk.setFile( filename ); //sets file name | 547 | lnk.setFile( filename ); //sets file name |
548 | 548 | ||
549 | d->selectedFiles->addToSelection( lnk ); | 549 | d->selectedFiles->addToSelection( lnk ); |
550 | } | 550 | } |
551 | 551 | ||
552 | fileListView->clearSelection(); | 552 | fileListView->clearSelection(); |
553 | 553 | ||
554 | tabWidget->setCurrentPage( 0 ); | 554 | tabWidget->setCurrentPage( 0 ); |
555 | writeCurrentM3u(); | 555 | writeCurrentM3u(); |
556 | } | 556 | } |
557 | 557 | ||
558 | 558 | ||
559 | void PlayListWidget::removeSelected() { | 559 | void PlayListWidget::removeSelected() { |
560 | d->selectedFiles->removeSelected( ); | 560 | d->selectedFiles->removeSelected( ); |
561 | writeCurrentM3u(); | 561 | writeCurrentM3u(); |
562 | } | 562 | } |
563 | 563 | ||
564 | 564 | ||
565 | void PlayListWidget::playIt( QListViewItem *it) { | 565 | void PlayListWidget::playIt( QListViewItem *it) { |
566 | if(!it) return; | 566 | if(!it) return; |
567 | mediaPlayerState->setPlaying(FALSE); | 567 | mediaPlayerState->setPlaying(FALSE); |
568 | mediaPlayerState->setPlaying(TRUE); | 568 | mediaPlayerState->setPlaying(TRUE); |
569 | d->selectedFiles->unSelect(); | 569 | d->selectedFiles->unSelect(); |
570 | } | 570 | } |
571 | 571 | ||
572 | 572 | ||
573 | void PlayListWidget::addToSelection( QListViewItem *it) { | 573 | void PlayListWidget::addToSelection( QListViewItem *it) { |
574 | d->setDocumentUsed = FALSE; | 574 | d->setDocumentUsed = FALSE; |
575 | 575 | ||
576 | if(it) { | 576 | if(it) { |
577 | switch ( whichList()) { | 577 | switch ( whichList()) { |
578 | case 0: //playlist | 578 | case 0: //playlist |
579 | return; | 579 | return; |
580 | break; | 580 | break; |
581 | }; | 581 | }; |
582 | // case 1: { | 582 | // case 1: { |
583 | DocLnk lnk; | 583 | DocLnk lnk; |
584 | QString filename; | 584 | QString filename; |
585 | 585 | ||
586 | filename=it->text(3); | 586 | filename=it->text(3); |
587 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 587 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
588 | lnk.setFile( filename ); //sets file name | 588 | lnk.setFile( filename ); //sets file name |
589 | d->selectedFiles->addToSelection( lnk); | 589 | d->selectedFiles->addToSelection( lnk); |
590 | 590 | ||
591 | writeCurrentM3u(); | 591 | writeCurrentM3u(); |
592 | tabWidget->setCurrentPage(0); | 592 | tabWidget->setCurrentPage(0); |
593 | 593 | ||
594 | } | 594 | } |
595 | } | 595 | } |
596 | 596 | ||
597 | 597 | ||
598 | void PlayListWidget::tabChanged(QWidget *) { | 598 | void PlayListWidget::tabChanged(QWidget *) { |
599 | 599 | ||
600 | switch ( whichList()) { | 600 | switch ( whichList()) { |
601 | case 0: | 601 | case 0: |
602 | { | 602 | { |
603 | if( !tbDeletePlaylist->isHidden() ) { | 603 | if( !tbDeletePlaylist->isHidden() ) { |
604 | tbDeletePlaylist->hide(); | 604 | tbDeletePlaylist->hide(); |
605 | } | 605 | } |
606 | d->tbRemoveFromList->setEnabled(TRUE); | 606 | d->tbRemoveFromList->setEnabled(TRUE); |
607 | d->tbAddToList->setEnabled(FALSE); | 607 | d->tbAddToList->setEnabled(FALSE); |
608 | } | 608 | } |
609 | break; | 609 | break; |
610 | case 1: | 610 | case 1: |
611 | { | 611 | { |
612 | // audioView->clear(); | 612 | // audioView->clear(); |
613 | if(!audioPopulated) populateAudioView(); | 613 | if(!audioPopulated) populateAudioView(); |
614 | 614 | ||
615 | if( !tbDeletePlaylist->isHidden() ) { | 615 | if( !tbDeletePlaylist->isHidden() ) { |
616 | tbDeletePlaylist->hide(); | 616 | tbDeletePlaylist->hide(); |
617 | } | 617 | } |
618 | d->tbRemoveFromList->setEnabled(FALSE); | 618 | d->tbRemoveFromList->setEnabled(FALSE); |
619 | d->tbAddToList->setEnabled(TRUE); | 619 | d->tbAddToList->setEnabled(TRUE); |
620 | } | 620 | } |
621 | break; | 621 | break; |
622 | case 2: | 622 | case 2: |
623 | { | 623 | { |
624 | // videoView->clear(); | 624 | // videoView->clear(); |
625 | if(!videoPopulated) populateVideoView(); | 625 | if(!videoPopulated) populateVideoView(); |
626 | if( !tbDeletePlaylist->isHidden() ) { | 626 | if( !tbDeletePlaylist->isHidden() ) { |
627 | tbDeletePlaylist->hide(); | 627 | tbDeletePlaylist->hide(); |
628 | } | 628 | } |
629 | d->tbRemoveFromList->setEnabled(FALSE); | 629 | d->tbRemoveFromList->setEnabled(FALSE); |
630 | d->tbAddToList->setEnabled(TRUE); | 630 | d->tbAddToList->setEnabled(TRUE); |
631 | } | 631 | } |
632 | break; | 632 | break; |
633 | case 3: | 633 | case 3: |
634 | { | 634 | { |
635 | if( tbDeletePlaylist->isHidden() ) { | 635 | if( tbDeletePlaylist->isHidden() ) { |
636 | tbDeletePlaylist->show(); | 636 | tbDeletePlaylist->show(); |
637 | } | 637 | } |
638 | playLists->reread(); | 638 | playLists->reread(); |
639 | d->tbAddToList->setEnabled(FALSE); | ||
639 | } | 640 | } |
640 | break; | 641 | break; |
641 | }; | 642 | }; |
642 | } | 643 | } |
643 | 644 | ||
644 | 645 | ||
645 | void PlayListWidget::btnPlay(bool b) { | 646 | void PlayListWidget::btnPlay(bool b) { |
646 | // mediaPlayerState->setPlaying(false); | 647 | // mediaPlayerState->setPlaying(false); |
647 | mediaPlayerState->setPlaying(b); | 648 | mediaPlayerState->setPlaying(b); |
648 | insanityBool=FALSE; | 649 | insanityBool=FALSE; |
649 | } | 650 | } |
650 | 651 | ||
651 | void PlayListWidget::deletePlaylist() { | 652 | void PlayListWidget::deletePlaylist() { |
652 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 653 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
653 | (tr("You really want to delete\nthis playlist?")), | 654 | (tr("You really want to delete\nthis playlist?")), |
654 | (tr("Yes")), (tr("No")), 0 )){ | 655 | (tr("Yes")), (tr("No")), 0 )){ |
655 | case 0: // Yes clicked, | 656 | case 0: // Yes clicked, |
656 | QFile().remove(playLists->selectedDocument().file()); | 657 | QFile().remove(playLists->selectedDocument().file()); |
657 | QFile().remove(playLists->selectedDocument().linkFile()); | 658 | QFile().remove(playLists->selectedDocument().linkFile()); |
658 | playLists->reread(); | 659 | playLists->reread(); |
659 | break; | 660 | break; |
660 | case 1: // Cancel | 661 | case 1: // Cancel |
661 | break; | 662 | break; |
662 | }; | 663 | }; |
663 | } | 664 | } |
664 | 665 | ||
665 | 666 | ||
666 | void PlayListWidget::playSelected() { | 667 | void PlayListWidget::playSelected() { |
667 | btnPlay( TRUE); | 668 | btnPlay( TRUE); |
668 | } | 669 | } |
669 | 670 | ||
670 | 671 | ||
671 | void PlayListWidget::scanForAudio() { | 672 | void PlayListWidget::scanForAudio() { |
672 | // qDebug("scan for audio"); | 673 | // qDebug("scan for audio"); |
673 | files.detachChildren(); | 674 | files.detachChildren(); |
674 | QListIterator<DocLnk> sdit( files.children() ); | 675 | QListIterator<DocLnk> sdit( files.children() ); |
675 | for ( ; sdit.current(); ++sdit ) { | 676 | for ( ; sdit.current(); ++sdit ) { |
676 | delete sdit.current(); | 677 | delete sdit.current(); |
677 | } | 678 | } |
678 | // Global::findDocuments( &files, "audio/*"); | 679 | // Global::findDocuments( &files, "audio/*"); |
679 | Global::findDocuments( &files, audioMimes); | 680 | Global::findDocuments( &files, audioMimes); |
680 | audioScan = true; | 681 | audioScan = true; |
681 | populateAudioView(); | 682 | populateAudioView(); |
682 | } | 683 | } |
683 | 684 | ||
684 | void PlayListWidget::scanForVideo() { | 685 | void PlayListWidget::scanForVideo() { |
685 | // qDebug("scan for video"); | 686 | // qDebug("scan for video"); |
686 | vFiles.detachChildren(); | 687 | vFiles.detachChildren(); |
687 | QListIterator<DocLnk> sdit( vFiles.children() ); | 688 | QListIterator<DocLnk> sdit( vFiles.children() ); |
688 | for ( ; sdit.current(); ++sdit ) { | 689 | for ( ; sdit.current(); ++sdit ) { |
689 | delete sdit.current(); | 690 | delete sdit.current(); |
690 | } | 691 | } |
691 | Global::findDocuments(&vFiles, "video/*"); | 692 | Global::findDocuments(&vFiles, "video/*"); |
692 | videoScan = true; | 693 | videoScan = true; |
693 | populateVideoView(); | 694 | populateVideoView(); |
694 | } | 695 | } |
695 | 696 | ||
696 | void PlayListWidget::populateAudioView() { | 697 | void PlayListWidget::populateAudioView() { |
697 | audioView->clear(); | 698 | audioView->clear(); |
698 | StorageInfo storageInfo; | 699 | StorageInfo storageInfo; |
699 | // const QList<FileSystem> &fs = storageInfo.fileSystems(); | 700 | // const QList<FileSystem> &fs = storageInfo.fileSystems(); |
700 | if(!audioScan) { | 701 | if(!audioScan) { |
701 | scanForAudio(); | 702 | scanForAudio(); |
702 | } | 703 | } |
703 | 704 | ||
704 | QListIterator<DocLnk> dit( files.children() ); | 705 | QListIterator<DocLnk> dit( files.children() ); |
705 | // QListIterator<FileSystem> it ( fs ); | 706 | // QListIterator<FileSystem> it ( fs ); |
706 | audioView->clear(); | 707 | audioView->clear(); |
707 | 708 | ||
708 | QString storage; | 709 | QString storage; |
709 | for ( ; dit.current(); ++dit ) { | 710 | for ( ; dit.current(); ++dit ) { |
710 | // // for( ; it.current(); ++it ){ | 711 | // // for( ; it.current(); ++it ){ |
711 | // const QString name = (*dit)->name(); | 712 | // const QString name = (*dit)->name(); |
712 | // const QString path = (*dit)->path(); | 713 | // const QString path = (*dit)->path(); |
713 | // if(dit.current()->file().find(path) != -1 ) { | 714 | // if(dit.current()->file().find(path) != -1 ) { |
714 | // storage = name; | 715 | // storage = name; |
715 | // // } | 716 | // // } |
716 | // } | 717 | // } |
717 | 718 | ||
718 | QListViewItem * newItem; | 719 | QListViewItem * newItem; |
719 | if ( QFile( dit.current()->file()).exists() || | 720 | if ( QFile( dit.current()->file()).exists() || |
720 | dit.current()->file().left(4) == "http" ) { | 721 | dit.current()->file().left(4) == "http" ) { |
721 | long size; | 722 | long size; |
722 | if( dit.current()->file().left(4) == "http" ) | 723 | if( dit.current()->file().left(4) == "http" ) |
723 | size=0; | 724 | size=0; |
724 | else | 725 | else |
725 | size = QFile( dit.current()->file() ).size(); | 726 | size = QFile( dit.current()->file() ).size(); |
726 | 727 | ||
727 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 728 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
728 | QString::number(size ), "" /*storage*/, | 729 | QString::number(size ), "" /*storage*/, |
729 | dit.current()->file() ); | 730 | dit.current()->file() ); |
730 | newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); | 731 | newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); |
731 | // qDebug("<<<< "+dit.current()->file()); | 732 | // qDebug("<<<< "+dit.current()->file()); |
732 | } | 733 | } |
733 | } | 734 | } |
734 | audioPopulated=true; | 735 | audioPopulated=true; |
735 | } | 736 | } |
736 | 737 | ||
737 | 738 | ||
738 | void PlayListWidget::populateVideoView() { | 739 | void PlayListWidget::populateVideoView() { |
739 | videoView->clear(); | 740 | videoView->clear(); |
740 | StorageInfo storageInfo; | 741 | StorageInfo storageInfo; |
741 | // const QList<FileSystem> &fs = storageInfo.fileSystems(); | 742 | // const QList<FileSystem> &fs = storageInfo.fileSystems(); |
742 | 743 | ||
743 | if(!videoScan ) { | 744 | if(!videoScan ) { |
744 | scanForVideo(); | 745 | scanForVideo(); |
745 | } | 746 | } |
746 | 747 | ||
747 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 748 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
748 | // QListIterator<FileSystem> it ( fs ); | 749 | // QListIterator<FileSystem> it ( fs ); |
749 | videoView->clear(); | 750 | videoView->clear(); |
750 | QString storage, pathName; | 751 | QString storage, pathName; |
751 | for ( ; Vdit.current(); ++Vdit ) { | 752 | for ( ; Vdit.current(); ++Vdit ) { |
752 | // // for( ; it.current(); ++it ) { | 753 | // // for( ; it.current(); ++it ) { |
753 | // const QString name = (*Vdit)->name(); | 754 | // const QString name = (*Vdit)->name(); |
754 | // const QString path = (*Vdit)->path(); | 755 | // const QString path = (*Vdit)->path(); |
755 | // if( Vdit.current()->file().find(path) != -1 ) { | 756 | // if( Vdit.current()->file().find(path) != -1 ) { |
756 | // storage=name; | 757 | // storage=name; |
757 | // pathName=path; | 758 | // pathName=path; |
758 | // // } | 759 | // // } |
759 | // } | 760 | // } |
760 | 761 | ||
761 | QListViewItem * newItem; | 762 | QListViewItem * newItem; |
762 | if ( QFile( Vdit.current()->file() ).exists() ) { | 763 | if ( QFile( Vdit.current()->file() ).exists() ) { |
763 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 764 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
764 | QString::number( QFile( Vdit.current()->file() ).size() ), | 765 | QString::number( QFile( Vdit.current()->file() ).size() ), |
765 | ""/*storage*/, Vdit.current()->file()); | 766 | ""/*storage*/, Vdit.current()->file()); |
766 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); | 767 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); |
767 | } | 768 | } |
768 | } | 769 | } |
769 | videoPopulated=true; | 770 | videoPopulated=true; |
770 | } | 771 | } |
771 | 772 | ||
772 | QListView *PlayListWidget::currentFileListView() const | 773 | QListView *PlayListWidget::currentFileListView() const |
773 | { | 774 | { |
774 | switch ( currentTab() ) { | 775 | switch ( currentTab() ) { |
775 | case AudioFiles: return audioView; | 776 | case AudioFiles: return audioView; |
776 | case VideoFiles: return videoView; | 777 | case VideoFiles: return videoView; |
777 | default: assert( false ); | 778 | default: assert( false ); |
778 | } | 779 | } |
779 | return 0; | 780 | return 0; |
780 | } | 781 | } |
781 | 782 | ||
782 | bool PlayListWidget::inFileListMode() const | 783 | bool PlayListWidget::inFileListMode() const |
783 | { | 784 | { |
784 | TabType tab = currentTab(); | 785 | TabType tab = currentTab(); |
785 | return tab == AudioFiles || tab == VideoFiles; | 786 | return tab == AudioFiles || tab == VideoFiles; |
786 | } | 787 | } |
787 | 788 | ||
788 | void PlayListWidget::openFile() { | 789 | void PlayListWidget::openFile() { |
789 | // http://66.28.164.33:2080 | 790 | // http://66.28.164.33:2080 |
790 | // http://somafm.com/star0242.m3u | 791 | // http://somafm.com/star0242.m3u |
791 | QString filename, name; | 792 | QString filename, name; |
792 | InputDialog *fileDlg; | 793 | InputDialog *fileDlg; |
793 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 794 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
794 | fileDlg->exec(); | 795 | fileDlg->exec(); |
795 | if( fileDlg->result() == 1 ) { | 796 | if( fileDlg->result() == 1 ) { |
796 | filename = fileDlg->text(); | 797 | filename = fileDlg->text(); |
797 | qDebug( "Selected filename is " + filename ); | 798 | qDebug( "Selected filename is " + filename ); |
798 | // Om3u *m3uList; | 799 | // Om3u *m3uList; |
799 | DocLnk lnk; | 800 | DocLnk lnk; |
800 | Config cfg( "OpiePlayer" ); | 801 | Config cfg( "OpiePlayer" ); |
801 | cfg.setGroup("PlayList"); | 802 | cfg.setGroup("PlayList"); |
802 | 803 | ||
803 | if(filename.left(4) == "http") { | 804 | if(filename.left(4) == "http") { |
804 | QString m3uFile, m3uFilePath; | 805 | QString m3uFile, m3uFilePath; |
805 | if(filename.find(":",8,TRUE) != -1) { //found a port | 806 | if(filename.find(":",8,TRUE) != -1) { //found a port |
806 | m3uFile = filename.left( filename.find( ":",8,TRUE)); | 807 | m3uFile = filename.left( filename.find( ":",8,TRUE)); |
807 | m3uFile = m3uFile.right( 7); | 808 | m3uFile = m3uFile.right( 7); |
808 | } else if(filename.left(4) == "http"){ | 809 | } else if(filename.left(4) == "http"){ |
809 | m3uFile=filename; | 810 | m3uFile=filename; |
810 | m3uFile = m3uFile.right( m3uFile.length() - 7); | 811 | m3uFile = m3uFile.right( m3uFile.length() - 7); |
811 | } else{ | 812 | } else{ |
812 | m3uFile=filename; | 813 | m3uFile=filename; |
813 | } | 814 | } |
814 | 815 | ||
815 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); | 816 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"+ m3uFile); |
816 | lnk.setName( filename ); //sets name | 817 | lnk.setName( filename ); //sets name |
817 | lnk.setFile( filename ); //sets file name | 818 | lnk.setFile( filename ); //sets file name |
818 | 819 | ||
819 | // lnk.setIcon("opieplayer2/musicfile"); | 820 | // lnk.setIcon("opieplayer2/musicfile"); |
820 | 821 | ||
821 | d->selectedFiles->addToSelection( lnk ); | 822 | d->selectedFiles->addToSelection( lnk ); |
822 | writeCurrentM3u(); | 823 | writeCurrentM3u(); |
823 | d->selectedFiles->setSelectedItem( lnk.name()); | 824 | d->selectedFiles->setSelectedItem( lnk.name()); |
824 | } | 825 | } |
825 | else if( filename.right( 3) == "m3u" ) { | 826 | else if( filename.right( 3) == "m3u" ) { |
826 | readm3u( filename ); | 827 | readm3u( filename ); |
827 | 828 | ||
828 | } else if( filename.right(3) == "pls" ) { | 829 | } else if( filename.right(3) == "pls" ) { |
829 | readPls( filename ); | 830 | readPls( filename ); |
830 | } else { | 831 | } else { |
831 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 832 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
832 | lnk.setFile( filename ); //sets file name | 833 | lnk.setFile( filename ); //sets file name |
833 | d->selectedFiles->addToSelection( lnk); | 834 | d->selectedFiles->addToSelection( lnk); |
834 | writeCurrentM3u(); | 835 | writeCurrentM3u(); |
835 | d->selectedFiles->setSelectedItem( lnk.name()); | 836 | d->selectedFiles->setSelectedItem( lnk.name()); |
836 | } | 837 | } |
837 | } | 838 | } |
838 | 839 | ||
839 | if( fileDlg ) { | 840 | if( fileDlg ) { |
840 | delete fileDlg; | 841 | delete fileDlg; |
841 | } | 842 | } |
842 | } | 843 | } |
843 | 844 | ||
844 | /* | 845 | /* |
845 | reads m3u and shows files/urls to playlist widget */ | 846 | reads m3u and shows files/urls to playlist widget */ |
846 | void PlayListWidget::readm3u( const QString &filename ) { | 847 | void PlayListWidget::readm3u( const QString &filename ) { |
847 | qDebug( "read m3u filename " + filename ); | 848 | qDebug( "read m3u filename " + filename ); |
848 | 849 | ||
849 | Om3u *m3uList; | 850 | Om3u *m3uList; |
850 | QString s, name; | 851 | QString s, name; |
851 | m3uList = new Om3u( filename, IO_ReadOnly ); | 852 | m3uList = new Om3u( filename, IO_ReadOnly ); |
852 | m3uList->readM3u(); | 853 | m3uList->readM3u(); |
853 | DocLnk lnk; | 854 | DocLnk lnk; |
854 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 855 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
855 | s = *it; | 856 | s = *it; |
856 | // qDebug("reading "+ s); | 857 | // qDebug("reading "+ s); |
857 | if(s.left(4)=="http") { | 858 | if(s.left(4)=="http") { |
858 | lnk.setName( s ); //sets file name | 859 | lnk.setName( s ); //sets file name |
859 | lnk.setIcon("opieplayer2/musicfile"); | 860 | lnk.setIcon("opieplayer2/musicfile"); |
860 | lnk.setFile( s ); //sets file name | 861 | lnk.setFile( s ); //sets file name |
861 | 862 | ||
862 | } else { | 863 | } else { |
863 | // if( QFileInfo( s ).exists() ) { | 864 | // if( QFileInfo( s ).exists() ) { |
864 | lnk.setName( QFileInfo(s).baseName()); | 865 | lnk.setName( QFileInfo(s).baseName()); |
865 | // if(s.right(4) == '.') {//if regular file | 866 | // if(s.right(4) == '.') {//if regular file |
866 | if(s.left(1) != "/") { | 867 | if(s.left(1) != "/") { |
867 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); | 868 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); |
868 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | 869 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); |
869 | // lnk.setIcon(MimeType(s).pixmap() ); | 870 | // lnk.setIcon(MimeType(s).pixmap() ); |
870 | // lnk.setIcon("SoundPlayer"); | 871 | // lnk.setIcon("SoundPlayer"); |
871 | } else { | 872 | } else { |
872 | // qDebug("set link2 "+s); | 873 | // qDebug("set link2 "+s); |
873 | lnk.setFile( s); | 874 | lnk.setFile( s); |
874 | // lnk.setIcon(MimeType(s).pixmap() ); | 875 | // lnk.setIcon(MimeType(s).pixmap() ); |
875 | // lnk.setIcon("SoundPlayer"); | 876 | // lnk.setIcon("SoundPlayer"); |
876 | } | 877 | } |
877 | } | 878 | } |
878 | d->selectedFiles->addToSelection( lnk ); | 879 | d->selectedFiles->addToSelection( lnk ); |
879 | } | 880 | } |
880 | Config config( "OpiePlayer" ); | 881 | Config config( "OpiePlayer" ); |
881 | config.setGroup( "PlayList" ); | 882 | config.setGroup( "PlayList" ); |
882 | 883 | ||
883 | config.writeEntry("CurrentPlaylist",filename); | 884 | config.writeEntry("CurrentPlaylist",filename); |
884 | config.write(); | 885 | config.write(); |
885 | currentPlayList=filename; | 886 | currentPlayList=filename; |
886 | 887 | ||
887 | // m3uList->write(); | 888 | // m3uList->write(); |
888 | m3uList->close(); | 889 | m3uList->close(); |
889 | if(m3uList) delete m3uList; | 890 | if(m3uList) delete m3uList; |
890 | 891 | ||
891 | d->selectedFiles->setSelectedItem( s); | 892 | d->selectedFiles->setSelectedItem( s); |
892 | setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); | 893 | setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); |
893 | 894 | ||
894 | } | 895 | } |
895 | 896 | ||
896 | /* | 897 | /* |
897 | reads pls and adds files/urls to playlist */ | 898 | reads pls and adds files/urls to playlist */ |
898 | void PlayListWidget::readPls( const QString &filename ) { | 899 | void PlayListWidget::readPls( const QString &filename ) { |
899 | 900 | ||
900 | qDebug( "pls filename is " + filename ); | 901 | qDebug( "pls filename is " + filename ); |
901 | Om3u *m3uList; | 902 | Om3u *m3uList; |
902 | QString s, name; | 903 | QString s, name; |
903 | m3uList = new Om3u( filename, IO_ReadOnly ); | 904 | m3uList = new Om3u( filename, IO_ReadOnly ); |
904 | m3uList->readPls(); | 905 | m3uList->readPls(); |
905 | 906 | ||
906 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 907 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
907 | s = *it; | 908 | s = *it; |
908 | // s.replace( QRegExp( "%20" )," " ); | 909 | // s.replace( QRegExp( "%20" )," " ); |
909 | DocLnk lnk( s ); | 910 | DocLnk lnk( s ); |
910 | QFileInfo f( s ); | 911 | QFileInfo f( s ); |
911 | QString name = f.baseName(); | 912 | QString name = f.baseName(); |
912 | 913 | ||
913 | if( name.left( 4 ) == "http" ) { | 914 | if( name.left( 4 ) == "http" ) { |
914 | name = s.right( s.length() - 7); | 915 | name = s.right( s.length() - 7); |
915 | } else { | 916 | } else { |
916 | name = s; | 917 | name = s; |
917 | } | 918 | } |
918 | 919 | ||
919 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 920 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
920 | 921 | ||
921 | lnk.setName( name ); | 922 | lnk.setName( name ); |
922 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 923 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
923 | lnk.setFile( s ); | 924 | lnk.setFile( s ); |
924 | } else { //if its a url | 925 | } else { //if its a url |
925 | // if( name.right( 1 ).find( '/' ) == -1) { | 926 | // if( name.right( 1 ).find( '/' ) == -1) { |
926 | // s += "/"; | 927 | // s += "/"; |
927 | // } | 928 | // } |
928 | lnk.setFile( s ); | 929 | lnk.setFile( s ); |
929 | } | 930 | } |
930 | lnk.setType( "audio/x-mpegurl" ); | 931 | lnk.setType( "audio/x-mpegurl" ); |
931 | 932 | ||
932 | lnk.writeLink(); | 933 | lnk.writeLink(); |
933 | d->selectedFiles->addToSelection( lnk ); | 934 | d->selectedFiles->addToSelection( lnk ); |
934 | } | 935 | } |
935 | 936 | ||
936 | m3uList->close(); | 937 | m3uList->close(); |
937 | if(m3uList) delete m3uList; | 938 | if(m3uList) delete m3uList; |
938 | } | 939 | } |
939 | 940 | ||
940 | /* | 941 | /* |
941 | writes current playlist to current m3u file */ | 942 | writes current playlist to current m3u file */ |
942 | void PlayListWidget::writeCurrentM3u() { | 943 | void PlayListWidget::writeCurrentM3u() { |
943 | qDebug("writing to current m3u"); | 944 | qDebug("writing to current m3u"); |
944 | Config cfg( "OpiePlayer" ); | 945 | Config cfg( "OpiePlayer" ); |
945 | cfg.setGroup("PlayList"); | 946 | cfg.setGroup("PlayList"); |
946 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); | 947 | QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); |
947 | 948 | ||
948 | Om3u *m3uList; | 949 | Om3u *m3uList; |
949 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); | 950 | m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); |
950 | if( d->selectedFiles->first()) { | 951 | if( d->selectedFiles->first()) { |
951 | 952 | ||
952 | do { | 953 | do { |
953 | // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file()); | 954 | // qDebug( "add writeCurrentM3u " +d->selectedFiles->current()->file()); |
954 | m3uList->add( d->selectedFiles->current()->file() ); | 955 | m3uList->add( d->selectedFiles->current()->file() ); |
955 | } | 956 | } |
956 | while ( d->selectedFiles->next() ); | 957 | while ( d->selectedFiles->next() ); |
957 | // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); | 958 | // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); |
958 | m3uList->write(); | 959 | m3uList->write(); |
959 | m3uList->close(); | 960 | m3uList->close(); |
960 | 961 | ||
961 | if(m3uList) delete m3uList; | 962 | if(m3uList) delete m3uList; |
962 | } | 963 | } |
963 | 964 | ||
964 | } | 965 | } |
965 | 966 | ||
966 | /* | 967 | /* |
967 | writes current playlist to m3u file */ | 968 | writes current playlist to m3u file */ |
968 | void PlayListWidget::writem3u() { | 969 | void PlayListWidget::writem3u() { |
969 | InputDialog *fileDlg; | 970 | InputDialog *fileDlg; |
970 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | 971 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); |
971 | fileDlg->exec(); | 972 | fileDlg->exec(); |
972 | QString name, filename, list; | 973 | QString name, filename, list; |
973 | Om3u *m3uList; | 974 | Om3u *m3uList; |
974 | 975 | ||
975 | if( fileDlg->result() == 1 ) { | 976 | if( fileDlg->result() == 1 ) { |
976 | name = fileDlg->text(); | 977 | name = fileDlg->text(); |
977 | // qDebug( filename ); | 978 | // qDebug( filename ); |
978 | 979 | ||
979 | if( name.left( 1) != "/" ) { | 980 | if( name.left( 1) != "/" ) { |
980 | filename = QPEApplication::documentDir() + "/" + name; | 981 | filename = QPEApplication::documentDir() + "/" + name; |
981 | } | 982 | } |
982 | 983 | ||
983 | if( name.right( 3 ) != "m3u" ) { | 984 | if( name.right( 3 ) != "m3u" ) { |
984 | filename = QPEApplication::documentDir() + "/" +name+".m3u"; | 985 | filename = QPEApplication::documentDir() + "/" +name+".m3u"; |
985 | } | 986 | } |
986 | 987 | ||
987 | if( d->selectedFiles->first()) { | 988 | if( d->selectedFiles->first()) { |
988 | m3uList = new Om3u(filename, IO_ReadWrite); | 989 | m3uList = new Om3u(filename, IO_ReadWrite); |
989 | 990 | ||
990 | do { | 991 | do { |
991 | m3uList->add( d->selectedFiles->current()->file()); | 992 | m3uList->add( d->selectedFiles->current()->file()); |
992 | } | 993 | } |
993 | while ( d->selectedFiles->next() ); | 994 | while ( d->selectedFiles->next() ); |
994 | // qDebug( list ); | 995 | // qDebug( list ); |
995 | m3uList->write(); | 996 | m3uList->write(); |
996 | m3uList->close(); | 997 | m3uList->close(); |
997 | if(m3uList) delete m3uList; | 998 | if(m3uList) delete m3uList; |
998 | 999 | ||
999 | if(fileDlg) delete fileDlg; | 1000 | if(fileDlg) delete fileDlg; |
1000 | 1001 | ||
1001 | DocLnk lnk; | 1002 | DocLnk lnk; |
1002 | lnk.setFile( filename); | 1003 | lnk.setFile( filename); |
1003 | lnk.setIcon("opieplayer2/playlist2"); | 1004 | lnk.setIcon("opieplayer2/playlist2"); |
1004 | lnk.setName( name); //sets file name | 1005 | lnk.setName( name); //sets file name |
1005 | 1006 | ||
1006 | // qDebug(filename); | 1007 | // qDebug(filename); |
1007 | Config config( "OpiePlayer" ); | 1008 | Config config( "OpiePlayer" ); |
1008 | config.setGroup( "PlayList" ); | 1009 | config.setGroup( "PlayList" ); |
1009 | 1010 | ||
1010 | config.writeEntry("CurrentPlaylist",filename); | 1011 | config.writeEntry("CurrentPlaylist",filename); |
1011 | currentPlayList=filename; | 1012 | currentPlayList=filename; |
1012 | 1013 | ||
1013 | if(!lnk.writeLink()) { | 1014 | if(!lnk.writeLink()) { |
1014 | qDebug("Writing doclink did not work"); | 1015 | qDebug("Writing doclink did not work"); |
1015 | } | 1016 | } |
1016 | 1017 | ||
1017 | setCaption(tr("OpiePlayer: ") + name); | 1018 | setCaption(tr("OpiePlayer: ") + name); |
1018 | } | 1019 | } |
1019 | } | 1020 | } |
1020 | } | 1021 | } |
1021 | 1022 | ||
1022 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { | 1023 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { |