author | simon <simon> | 2002-12-02 17:42:44 (UTC) |
---|---|---|
committer | simon <simon> | 2002-12-02 17:42:44 (UTC) |
commit | c31f9b59dba873739494fcd9916c7cb9120ce1d9 (patch) (unidiff) | |
tree | 4b3371edaf5f0f6f6240a7bfe8f16be1dc111e8d | |
parent | 2f2f6cfbc31e0144060588b26814301ce99ebd39 (diff) | |
download | opie-c31f9b59dba873739494fcd9916c7cb9120ce1d9.zip opie-c31f9b59dba873739494fcd9916c7cb9120ce1d9.tar.gz opie-c31f9b59dba873739494fcd9916c7cb9120ce1d9.tar.bz2 |
- don't enable the play button if switching to the playlist tab and the
playlist is empty
- don't crash when starting to play and no item is selected in the
playlist. instead select the first item then.
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistselection.h | 2 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/noncore/multimedia/opieplayer2/playlistselection.h b/noncore/multimedia/opieplayer2/playlistselection.h index d10bc82..9cc4e30 100644 --- a/noncore/multimedia/opieplayer2/playlistselection.h +++ b/noncore/multimedia/opieplayer2/playlistselection.h | |||
@@ -1,63 +1,65 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifndef PLAY_LIST_SELECTION_H | 20 | #ifndef PLAY_LIST_SELECTION_H |
21 | #define PLAY_LIST_SELECTION_H | 21 | #define PLAY_LIST_SELECTION_H |
22 | 22 | ||
23 | #include <qlist.h> | 23 | #include <qlist.h> |
24 | #include <qlistview.h> | 24 | #include <qlistview.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
27 | 27 | ||
28 | class PlayListSelection : public QListView { | 28 | class PlayListSelection : public QListView { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | public: | 30 | public: |
31 | PlayListSelection( QWidget *parent, const char *name=0 ); | 31 | PlayListSelection( QWidget *parent, const char *name=0 ); |
32 | ~PlayListSelection(); | 32 | ~PlayListSelection(); |
33 | 33 | ||
34 | const DocLnk *current(); // retrieve the current playlist entry (media file link) | 34 | const DocLnk *current(); // retrieve the current playlist entry (media file link) |
35 | public slots: | 35 | public slots: |
36 | void addToSelection( const DocLnk & ); // Add a media file to the playlist | 36 | void addToSelection( const DocLnk & ); // Add a media file to the playlist |
37 | void removeSelected(); // Remove a media file from the playlist | 37 | void removeSelected(); // Remove a media file from the playlist |
38 | void moveSelectedUp(); // Move the media file up the playlist so it is played earlier | 38 | void moveSelectedUp(); // Move the media file up the playlist so it is played earlier |
39 | void moveSelectedDown(); // Move the media file down the playlist so it is played later | 39 | void moveSelectedDown(); // Move the media file down the playlist so it is played later |
40 | void unSelect(); | 40 | void unSelect(); |
41 | void writeCurrent( Config &); | 41 | void writeCurrent( Config &); |
42 | void setSelectedItem( const QString & ); | 42 | void setSelectedItem( const QString & ); |
43 | bool prev(); | 43 | bool prev(); |
44 | bool next(); | 44 | bool next(); |
45 | bool first(); | 45 | bool first(); |
46 | bool last(); | 46 | bool last(); |
47 | 47 | ||
48 | bool isEmpty() const { return childCount() == 0; } | ||
49 | |||
48 | protected: | 50 | protected: |
49 | virtual void contentsMouseMoveEvent(QMouseEvent *); | 51 | virtual void contentsMouseMoveEvent(QMouseEvent *); |
50 | /* #ifdef USE_PLAYLIST_BACKGROUND */ | 52 | /* #ifdef USE_PLAYLIST_BACKGROUND */ |
51 | virtual void drawBackground( QPainter *p, const QRect &r ); | 53 | virtual void drawBackground( QPainter *p, const QRect &r ); |
52 | virtual void paintEmptyArea( QPainter *p, const QRect &r ) { drawBackground( p, r ); }; | 54 | virtual void paintEmptyArea( QPainter *p, const QRect &r ) { drawBackground( p, r ); }; |
53 | /* #endif */ | 55 | /* #endif */ |
54 | 56 | ||
55 | private: | 57 | private: |
56 | QList<DocLnk> selectedList; | 58 | QList<DocLnk> selectedList; |
57 | const DocLnk *lnk; | 59 | const DocLnk *lnk; |
58 | }; | 60 | }; |
59 | 61 | ||
60 | 62 | ||
61 | #endif // PLAY_LIST_SELECTION_H | 63 | #endif // PLAY_LIST_SELECTION_H |
62 | 64 | ||
63 | 65 | ||
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index f53def6..b08204e 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp | |||
@@ -373,97 +373,103 @@ void PlayListWidget::addAllVideoToList() { | |||
373 | d->selectedFiles->addToSelection( **dit ); | 373 | d->selectedFiles->addToSelection( **dit ); |
374 | } | 374 | } |
375 | } | 375 | } |
376 | */ | 376 | */ |
377 | tabWidget->setCurrentPage(0); | 377 | tabWidget->setCurrentPage(0); |
378 | writeCurrentM3u(); | 378 | writeCurrentM3u(); |
379 | d->selectedFiles->first(); | 379 | d->selectedFiles->first(); |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | void PlayListWidget::setDocument( const QString& fileref ) { | 383 | void PlayListWidget::setDocument( const QString& fileref ) { |
384 | // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); | 384 | // qDebug( "<<<<<<<<set document>>>>>>>>>> "+fileref ); |
385 | fromSetDocument = TRUE; | 385 | fromSetDocument = TRUE; |
386 | if ( fileref.isNull() ) { | 386 | if ( fileref.isNull() ) { |
387 | QMessageBox::warning( this, tr( "Invalid File" ), | 387 | QMessageBox::warning( this, tr( "Invalid File" ), |
388 | tr( "There was a problem in getting the file." ) ); | 388 | tr( "There was a problem in getting the file." ) ); |
389 | return; | 389 | return; |
390 | } | 390 | } |
391 | 391 | ||
392 | clearList(); | 392 | clearList(); |
393 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u | 393 | if( fileref.find( "m3u", 0, TRUE) != -1 ) { //is m3u |
394 | readm3u( fileref ); | 394 | readm3u( fileref ); |
395 | } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { | 395 | } else if( DocLnk( fileref).file().find( "m3u", 0, TRUE) != -1 ) { |
396 | readm3u( DocLnk( fileref).file() ); | 396 | readm3u( DocLnk( fileref).file() ); |
397 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls | 397 | } else if( fileref.find( "pls", 0, TRUE) != -1 ) { //is pls |
398 | readPls( fileref ); | 398 | readPls( fileref ); |
399 | } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { | 399 | } else if( DocLnk( fileref).file().find( "pls", 0, TRUE) != -1 ) { |
400 | readPls( DocLnk( fileref).file() ); | 400 | readPls( DocLnk( fileref).file() ); |
401 | } else { | 401 | } else { |
402 | clearList(); | 402 | clearList(); |
403 | addToSelection( DocLnk( fileref ) ); | 403 | addToSelection( DocLnk( fileref ) ); |
404 | writeCurrentM3u(); | 404 | writeCurrentM3u(); |
405 | 405 | ||
406 | d->setDocumentUsed = TRUE; | 406 | d->setDocumentUsed = TRUE; |
407 | mediaPlayerState->setPlaying( FALSE ); | 407 | mediaPlayerState->setPlaying( FALSE ); |
408 | mediaPlayerState->setPlaying( TRUE ); | 408 | mediaPlayerState->setPlaying( TRUE ); |
409 | } | 409 | } |
410 | } | 410 | } |
411 | 411 | ||
412 | 412 | ||
413 | void PlayListWidget::useSelectedDocument() { | 413 | void PlayListWidget::useSelectedDocument() { |
414 | d->setDocumentUsed = FALSE; | 414 | d->setDocumentUsed = FALSE; |
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | const DocLnk *PlayListWidget::current() const { // this is fugly | 418 | const DocLnk *PlayListWidget::current() const { // this is fugly |
419 | assert( currentTab() == CurrentPlayList ); | 419 | assert( currentTab() == CurrentPlayList ); |
420 | 420 | ||
421 | return d->selectedFiles->current(); | 421 | const DocLnk *lnk = d->selectedFiles->current(); |
422 | if ( !lnk ) { | ||
423 | d->selectedFiles->first(); | ||
424 | lnk = d->selectedFiles->current(); | ||
425 | } | ||
426 | assert( lnk ); | ||
427 | return lnk; | ||
422 | } | 428 | } |
423 | 429 | ||
424 | 430 | ||
425 | bool PlayListWidget::prev() { | 431 | bool PlayListWidget::prev() { |
426 | if ( mediaPlayerState->isShuffled() ) { | 432 | if ( mediaPlayerState->isShuffled() ) { |
427 | const DocLnk *cur = current(); | 433 | const DocLnk *cur = current(); |
428 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 434 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
429 | for ( int i = 0; i < j; i++ ) { | 435 | for ( int i = 0; i < j; i++ ) { |
430 | if ( !d->selectedFiles->next() ) | 436 | if ( !d->selectedFiles->next() ) |
431 | d->selectedFiles->first(); | 437 | d->selectedFiles->first(); |
432 | } | 438 | } |
433 | if ( cur == current() ) | 439 | if ( cur == current() ) |
434 | if ( !d->selectedFiles->next() ) { | 440 | if ( !d->selectedFiles->next() ) { |
435 | d->selectedFiles->first(); | 441 | d->selectedFiles->first(); |
436 | } | 442 | } |
437 | return TRUE; | 443 | return TRUE; |
438 | } else { | 444 | } else { |
439 | if ( !d->selectedFiles->prev() ) { | 445 | if ( !d->selectedFiles->prev() ) { |
440 | if ( mediaPlayerState->isLooping() ) { | 446 | if ( mediaPlayerState->isLooping() ) { |
441 | return d->selectedFiles->last(); | 447 | return d->selectedFiles->last(); |
442 | } else { | 448 | } else { |
443 | return FALSE; | 449 | return FALSE; |
444 | } | 450 | } |
445 | } | 451 | } |
446 | return TRUE; | 452 | return TRUE; |
447 | } | 453 | } |
448 | } | 454 | } |
449 | 455 | ||
450 | 456 | ||
451 | bool PlayListWidget::next() { | 457 | bool PlayListWidget::next() { |
452 | //qDebug("<<<<<<<<<<<<next()"); | 458 | //qDebug("<<<<<<<<<<<<next()"); |
453 | if ( mediaPlayerState->isShuffled() ) { | 459 | if ( mediaPlayerState->isShuffled() ) { |
454 | return prev(); | 460 | return prev(); |
455 | } else { | 461 | } else { |
456 | if ( !d->selectedFiles->next() ) { | 462 | if ( !d->selectedFiles->next() ) { |
457 | if ( mediaPlayerState->isLooping() ) { | 463 | if ( mediaPlayerState->isLooping() ) { |
458 | return d->selectedFiles->first(); | 464 | return d->selectedFiles->first(); |
459 | } else { | 465 | } else { |
460 | return FALSE; | 466 | return FALSE; |
461 | } | 467 | } |
462 | } | 468 | } |
463 | return TRUE; | 469 | return TRUE; |
464 | } | 470 | } |
465 | } | 471 | } |
466 | 472 | ||
467 | 473 | ||
468 | bool PlayListWidget::first() { | 474 | bool PlayListWidget::first() { |
469 | return d->selectedFiles->first(); | 475 | return d->selectedFiles->first(); |
@@ -519,96 +525,98 @@ void PlayListWidget::addSelected() { | |||
519 | void PlayListWidget::removeSelected() { | 525 | void PlayListWidget::removeSelected() { |
520 | d->selectedFiles->removeSelected( ); | 526 | d->selectedFiles->removeSelected( ); |
521 | writeCurrentM3u(); | 527 | writeCurrentM3u(); |
522 | } | 528 | } |
523 | 529 | ||
524 | 530 | ||
525 | void PlayListWidget::playIt( QListViewItem *it) { | 531 | void PlayListWidget::playIt( QListViewItem *it) { |
526 | if(!it) return; | 532 | if(!it) return; |
527 | mediaPlayerState->setPlaying(FALSE); | 533 | mediaPlayerState->setPlaying(FALSE); |
528 | mediaPlayerState->setPlaying(TRUE); | 534 | mediaPlayerState->setPlaying(TRUE); |
529 | d->selectedFiles->unSelect(); | 535 | d->selectedFiles->unSelect(); |
530 | } | 536 | } |
531 | 537 | ||
532 | 538 | ||
533 | void PlayListWidget::addToSelection( QListViewItem *it) { | 539 | void PlayListWidget::addToSelection( QListViewItem *it) { |
534 | d->setDocumentUsed = FALSE; | 540 | d->setDocumentUsed = FALSE; |
535 | 541 | ||
536 | if(it) { | 542 | if(it) { |
537 | if ( currentTab() == CurrentPlayList ) | 543 | if ( currentTab() == CurrentPlayList ) |
538 | return; | 544 | return; |
539 | // case 1: { | 545 | // case 1: { |
540 | DocLnk lnk; | 546 | DocLnk lnk; |
541 | QString filename; | 547 | QString filename; |
542 | 548 | ||
543 | filename=it->text(3); | 549 | filename=it->text(3); |
544 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 550 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
545 | lnk.setFile( filename ); //sets file name | 551 | lnk.setFile( filename ); //sets file name |
546 | d->selectedFiles->addToSelection( lnk); | 552 | d->selectedFiles->addToSelection( lnk); |
547 | 553 | ||
548 | writeCurrentM3u(); | 554 | writeCurrentM3u(); |
549 | tabWidget->setCurrentPage(0); | 555 | tabWidget->setCurrentPage(0); |
550 | 556 | ||
551 | } | 557 | } |
552 | } | 558 | } |
553 | 559 | ||
554 | 560 | ||
555 | void PlayListWidget::tabChanged(QWidget *) { | 561 | void PlayListWidget::tabChanged(QWidget *) { |
556 | 562 | ||
557 | d->tbPlay->setEnabled( true ); | 563 | d->tbPlay->setEnabled( true ); |
558 | 564 | ||
559 | switch ( currentTab() ) { | 565 | switch ( currentTab() ) { |
560 | case CurrentPlayList: | 566 | case CurrentPlayList: |
561 | { | 567 | { |
562 | if( !tbDeletePlaylist->isHidden() ) { | 568 | if( !tbDeletePlaylist->isHidden() ) { |
563 | tbDeletePlaylist->hide(); | 569 | tbDeletePlaylist->hide(); |
564 | } | 570 | } |
565 | d->tbRemoveFromList->setEnabled(TRUE); | 571 | d->tbRemoveFromList->setEnabled(TRUE); |
566 | d->tbAddToList->setEnabled(FALSE); | 572 | d->tbAddToList->setEnabled(FALSE); |
573 | |||
574 | d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); | ||
567 | } | 575 | } |
568 | break; | 576 | break; |
569 | case AudioFiles: | 577 | case AudioFiles: |
570 | { | 578 | { |
571 | // audioView->clear(); | 579 | // audioView->clear(); |
572 | if(!audioPopulated) populateAudioView(); | 580 | if(!audioPopulated) populateAudioView(); |
573 | 581 | ||
574 | if( !tbDeletePlaylist->isHidden() ) { | 582 | if( !tbDeletePlaylist->isHidden() ) { |
575 | tbDeletePlaylist->hide(); | 583 | tbDeletePlaylist->hide(); |
576 | } | 584 | } |
577 | d->tbRemoveFromList->setEnabled(FALSE); | 585 | d->tbRemoveFromList->setEnabled(FALSE); |
578 | d->tbAddToList->setEnabled(TRUE); | 586 | d->tbAddToList->setEnabled(TRUE); |
579 | } | 587 | } |
580 | break; | 588 | break; |
581 | case VideoFiles: | 589 | case VideoFiles: |
582 | { | 590 | { |
583 | // videoView->clear(); | 591 | // videoView->clear(); |
584 | if(!videoPopulated) populateVideoView(); | 592 | if(!videoPopulated) populateVideoView(); |
585 | if( !tbDeletePlaylist->isHidden() ) { | 593 | if( !tbDeletePlaylist->isHidden() ) { |
586 | tbDeletePlaylist->hide(); | 594 | tbDeletePlaylist->hide(); |
587 | } | 595 | } |
588 | d->tbRemoveFromList->setEnabled(FALSE); | 596 | d->tbRemoveFromList->setEnabled(FALSE); |
589 | d->tbAddToList->setEnabled(TRUE); | 597 | d->tbAddToList->setEnabled(TRUE); |
590 | } | 598 | } |
591 | break; | 599 | break; |
592 | case PlayLists: | 600 | case PlayLists: |
593 | { | 601 | { |
594 | if( tbDeletePlaylist->isHidden() ) { | 602 | if( tbDeletePlaylist->isHidden() ) { |
595 | tbDeletePlaylist->show(); | 603 | tbDeletePlaylist->show(); |
596 | } | 604 | } |
597 | playLists->reread(); | 605 | playLists->reread(); |
598 | d->tbAddToList->setEnabled(FALSE); | 606 | d->tbAddToList->setEnabled(FALSE); |
599 | 607 | ||
600 | d->tbPlay->setEnabled( false ); | 608 | d->tbPlay->setEnabled( false ); |
601 | } | 609 | } |
602 | break; | 610 | break; |
603 | }; | 611 | }; |
604 | } | 612 | } |
605 | 613 | ||
606 | 614 | ||
607 | void PlayListWidget::btnPlay(bool b) { | 615 | void PlayListWidget::btnPlay(bool b) { |
608 | // mediaPlayerState->setPlaying(false); | 616 | // mediaPlayerState->setPlaying(false); |
609 | mediaPlayerState->setPlaying(b); | 617 | mediaPlayerState->setPlaying(b); |
610 | insanityBool=FALSE; | 618 | insanityBool=FALSE; |
611 | } | 619 | } |
612 | 620 | ||
613 | void PlayListWidget::deletePlaylist() { | 621 | void PlayListWidget::deletePlaylist() { |
614 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 622 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |