summaryrefslogtreecommitdiff
path: root/apps/onplay.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/onplay.c')
-rw-r--r--apps/onplay.c273
1 files changed, 118 insertions, 155 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index a78cf7ceac..729fe40f0a 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -476,16 +476,40 @@ MAKE_ONPLAYMENU( wps_playlist_menu, ID2P(LANG_PLAYLIST),
476 &playlist_save_item, &reshuffle_item, &playing_time_item 476 &playlist_save_item, &reshuffle_item, &playing_time_item
477 ); 477 );
478 478
479/* argument for add_to_playlist (for use by menu callbacks) */
480struct add_to_pl_param
481{
482 int8_t position;
483 unsigned int queue: 1;
484 unsigned int replace: 1;
485};
486
487static struct add_to_pl_param addtopl_insert = {PLAYLIST_INSERT, 0, 0};
488static struct add_to_pl_param addtopl_insert_first = {PLAYLIST_INSERT_FIRST, 0, 0};
489static struct add_to_pl_param addtopl_insert_last = {PLAYLIST_INSERT_LAST, 0, 0};
490static struct add_to_pl_param addtopl_insert_shuf = {PLAYLIST_INSERT_SHUFFLED, 0, 0};
491static struct add_to_pl_param addtopl_insert_last_shuf = {PLAYLIST_INSERT_LAST_SHUFFLED, 0, 0};
492
493static struct add_to_pl_param addtopl_queue = {PLAYLIST_INSERT, 1, 0};
494static struct add_to_pl_param addtopl_queue_first = {PLAYLIST_INSERT_FIRST, 1, 0};
495static struct add_to_pl_param addtopl_queue_last = {PLAYLIST_INSERT_LAST, 1, 0};
496static struct add_to_pl_param addtopl_queue_shuf = {PLAYLIST_INSERT_SHUFFLED, 1, 0};
497static struct add_to_pl_param addtopl_queue_last_shuf = {PLAYLIST_INSERT_LAST_SHUFFLED, 1, 0};
498
499static struct add_to_pl_param addtopl_replace = {PLAYLIST_INSERT, 0, 1};
500static struct add_to_pl_param addtopl_replace_shuffled = {PLAYLIST_INSERT_SHUFFLED, 0, 1};
501
479/* CONTEXT_[TREE|ID3DB|STD] playlist options */ 502/* CONTEXT_[TREE|ID3DB|STD] playlist options */
480static bool add_to_playlist(int position, bool queue) 503static int add_to_playlist(void* arg)
481{ 504{
482 bool new_playlist = false; 505 struct add_to_pl_param* param = arg;
483 if (!(audio_status() & AUDIO_STATUS_PLAY)) 506 int position = param->position;
484 { 507 bool new_playlist = param->replace ? true : false;
485 new_playlist = true; 508 bool queue = param->queue ? true : false;
486 if (position == PLAYLIST_REPLACE) 509
487 position = PLAYLIST_INSERT; 510 /* warn if replacing the playlist */
488 } 511 if (new_playlist && !warn_on_pl_erase())
512 return 0;
489 513
490 const char *lines[] = { 514 const char *lines[] = {
491 ID2P(LANG_RECURSE_DIRECTORY_QUESTION), 515 ID2P(LANG_RECURSE_DIRECTORY_QUESTION),
@@ -568,121 +592,59 @@ static bool view_playlist(void)
568 return result; 592 return result;
569} 593}
570 594
571static int playlist_insert_func(void *param)
572{
573 if (((intptr_t)param == PLAYLIST_REPLACE ||
574 (((intptr_t)param == PLAYLIST_INSERT_SHUFFLED || (intptr_t)param == PLAYLIST_INSERT)
575 && !(audio_status() & AUDIO_STATUS_PLAY))) && !warn_on_pl_erase())
576 return 0;
577 add_to_playlist((intptr_t)param, false);
578 return 0;
579}
580
581static int playlist_queue_func(void *param)
582{
583 add_to_playlist((intptr_t)param, true);
584 return 0;
585}
586
587static int treeplaylist_wplayback_callback(int action,
588 const struct menu_item_ex* this_item,
589 struct gui_synclist *this_list);
590
591static int treeplaylist_callback(int action, 595static int treeplaylist_callback(int action,
592 const struct menu_item_ex *this_item, 596 const struct menu_item_ex *this_item,
593 struct gui_synclist *this_list); 597 struct gui_synclist *this_list);
594 598
595/* insert items */ 599/* insert items */
596MENUITEM_FUNCTION(i_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT), 600MENUITEM_FUNCTION(i_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT),
597 playlist_insert_func, (intptr_t*)PLAYLIST_INSERT, 601 add_to_playlist, &addtopl_insert,
598 treeplaylist_wplayback_callback, Icon_Playlist); 602 treeplaylist_callback, Icon_Playlist);
599MENUITEM_FUNCTION(i_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_FIRST), 603MENUITEM_FUNCTION(i_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_FIRST),
600 playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_FIRST, 604 add_to_playlist, &addtopl_insert_first,
601 treeplaylist_wplayback_callback, Icon_Playlist); 605 treeplaylist_callback, Icon_Playlist);
602MENUITEM_FUNCTION(i_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_LAST), 606MENUITEM_FUNCTION(i_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_LAST),
603 playlist_insert_func, (intptr_t*)PLAYLIST_INSERT_LAST, 607 add_to_playlist, &addtopl_insert_last,
604 treeplaylist_wplayback_callback, Icon_Playlist); 608 treeplaylist_callback, Icon_Playlist);
605MENUITEM_FUNCTION(i_shuf_pl_item, MENU_FUNC_USEPARAM, 609MENUITEM_FUNCTION(i_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_SHUFFLED),
606 ID2P(LANG_INSERT_SHUFFLED), playlist_insert_func, 610 add_to_playlist, &addtopl_insert_shuf,
607 (intptr_t*)PLAYLIST_INSERT_SHUFFLED,
608 treeplaylist_callback, Icon_Playlist); 611 treeplaylist_callback, Icon_Playlist);
609MENUITEM_FUNCTION(i_last_shuf_pl_item, MENU_FUNC_USEPARAM, 612MENUITEM_FUNCTION(i_last_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_INSERT_LAST_SHUFFLED),
610 ID2P(LANG_INSERT_LAST_SHUFFLED), playlist_insert_func, 613 add_to_playlist, &addtopl_insert_last_shuf,
611 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED,
612 treeplaylist_callback, Icon_Playlist); 614 treeplaylist_callback, Icon_Playlist);
613/* queue items */ 615/* queue items */
614MENUITEM_FUNCTION(q_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE), 616MENUITEM_FUNCTION(q_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE),
615 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT, 617 add_to_playlist, &addtopl_queue,
616 treeplaylist_callback, Icon_Playlist); 618 treeplaylist_callback, Icon_Playlist);
617MENUITEM_FUNCTION(q_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_FIRST), 619MENUITEM_FUNCTION(q_first_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_FIRST),
618 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_FIRST, 620 add_to_playlist, &addtopl_queue_first,
619 treeplaylist_callback, Icon_Playlist); 621 treeplaylist_callback, Icon_Playlist);
620MENUITEM_FUNCTION(q_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST), 622MENUITEM_FUNCTION(q_last_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST),
621 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_LAST, 623 add_to_playlist, &addtopl_queue_last,
622 treeplaylist_callback, Icon_Playlist); 624 treeplaylist_callback, Icon_Playlist);
623MENUITEM_FUNCTION(q_shuf_pl_item, MENU_FUNC_USEPARAM, 625MENUITEM_FUNCTION(q_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_SHUFFLED),
624 ID2P(LANG_QUEUE_SHUFFLED), playlist_queue_func, 626 add_to_playlist, &addtopl_queue_shuf,
625 (intptr_t*)PLAYLIST_INSERT_SHUFFLED,
626 treeplaylist_callback, Icon_Playlist); 627 treeplaylist_callback, Icon_Playlist);
627MENUITEM_FUNCTION(q_last_shuf_pl_item, MENU_FUNC_USEPARAM, 628MENUITEM_FUNCTION(q_last_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST_SHUFFLED),
628 ID2P(LANG_QUEUE_LAST_SHUFFLED), playlist_queue_func, 629 add_to_playlist, &addtopl_queue_last_shuf,
629 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED,
630 treeplaylist_callback, Icon_Playlist);
631
632/* queue items in submenu */
633MENUITEM_FUNCTION(q_pl_submenu_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE),
634 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT,
635 NULL, Icon_Playlist);
636MENUITEM_FUNCTION(q_first_pl_submenu_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_FIRST),
637 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_FIRST,
638 NULL, Icon_Playlist);
639MENUITEM_FUNCTION(q_last_pl_submenu_item, MENU_FUNC_USEPARAM, ID2P(LANG_QUEUE_LAST),
640 playlist_queue_func, (intptr_t*)PLAYLIST_INSERT_LAST,
641 NULL, Icon_Playlist);
642MENUITEM_FUNCTION(q_shuf_pl_submenu_item, MENU_FUNC_USEPARAM,
643 ID2P(LANG_QUEUE_SHUFFLED), playlist_queue_func,
644 (intptr_t*)PLAYLIST_INSERT_SHUFFLED,
645 treeplaylist_callback, Icon_Playlist);
646MENUITEM_FUNCTION(q_last_shuf_pl_submenu_item, MENU_FUNC_USEPARAM,
647 ID2P(LANG_QUEUE_LAST_SHUFFLED), playlist_queue_func,
648 (intptr_t*)PLAYLIST_INSERT_LAST_SHUFFLED,
649 treeplaylist_callback, Icon_Playlist); 630 treeplaylist_callback, Icon_Playlist);
650 631
632/* queue submenu */
651MAKE_ONPLAYMENU(queue_menu, ID2P(LANG_QUEUE_MENU), 633MAKE_ONPLAYMENU(queue_menu, ID2P(LANG_QUEUE_MENU),
652 treeplaylist_wplayback_callback, Icon_Playlist, 634 treeplaylist_callback, Icon_Playlist,
653 &q_pl_submenu_item, 635 &q_pl_item,
654 &q_first_pl_submenu_item, 636 &q_first_pl_item,
655 &q_last_pl_submenu_item, 637 &q_last_pl_item,
656 &q_shuf_pl_submenu_item, 638 &q_shuf_pl_item,
657 &q_last_shuf_pl_submenu_item); 639 &q_last_shuf_pl_item);
658
659static int treeplaylist_wplayback_callback(int action,
660 const struct menu_item_ex* this_item,
661 struct gui_synclist *this_list)
662{
663 (void)this_list;
664 switch (action)
665 {
666 case ACTION_REQUEST_MENUITEM:
667 if ((audio_status() & AUDIO_STATUS_PLAY) &&
668 (this_item != &queue_menu ||
669 global_settings.show_queue_options == QUEUE_SHOW_IN_SUBMENU))
670 return action;
671 else
672 return ACTION_EXIT_MENUITEM;
673 break;
674 }
675 return action;
676}
677 640
678/* replace playlist */ 641/* replace playlist */
679MENUITEM_FUNCTION(replace_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_CLEAR_LIST_AND_PLAY_NEXT), 642MENUITEM_FUNCTION(replace_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_PLAY),
680 playlist_insert_func, (intptr_t*)PLAYLIST_REPLACE, 643 add_to_playlist, &addtopl_replace,
681 NULL, Icon_Playlist); 644 treeplaylist_callback, Icon_Playlist);
682 645
683MENUITEM_FUNCTION(replace_shuf_pl_item, MENU_FUNC_USEPARAM, 646MENUITEM_FUNCTION(replace_shuf_pl_item, MENU_FUNC_USEPARAM, ID2P(LANG_PLAY_SHUFFLED),
684 ID2P(LANG_CLEAR_LIST_AND_PLAY_SHUFFLED), playlist_insert_func, 647 add_to_playlist, &addtopl_replace_shuffled,
685 (intptr_t*)PLAYLIST_INSERT_SHUFFLED,
686 treeplaylist_callback, Icon_Playlist); 648 treeplaylist_callback, Icon_Playlist);
687 649
688MAKE_ONPLAYMENU(tree_playlist_menu, ID2P(LANG_CURRENT_PLAYLIST), 650MAKE_ONPLAYMENU(tree_playlist_menu, ID2P(LANG_CURRENT_PLAYLIST),
@@ -713,70 +675,71 @@ static int treeplaylist_callback(int action,
713 const struct menu_item_ex *this_item, 675 const struct menu_item_ex *this_item,
714 struct gui_synclist *this_list) 676 struct gui_synclist *this_list)
715{ 677{
678 static bool in_queue_submenu = false;
679
716 (void)this_list; 680 (void)this_list;
717 switch (action) 681 switch (action)
718 { 682 {
719 case ACTION_REQUEST_MENUITEM: 683 case ACTION_REQUEST_MENUITEM:
720 if (this_item == &tree_playlist_menu) 684 if (this_item == &tree_playlist_menu)
721 { 685 {
722 if ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO || 686 if ((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_AUDIO &&
723 (selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U || 687 (selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_M3U &&
724 (selected_file_attr & ATTR_DIRECTORY)) 688 (selected_file_attr & ATTR_DIRECTORY) == 0)
725 return action; 689 return ACTION_EXIT_MENUITEM;
726 } 690 }
727 else if ((this_item == &q_pl_item || 691 else if (this_item == &queue_menu)
728 this_item == &q_first_pl_item || 692 {
729 this_item == &q_last_pl_item) && 693 if (global_settings.show_queue_options != QUEUE_SHOW_IN_SUBMENU)
730 global_settings.show_queue_options == QUEUE_SHOW_AT_TOPLEVEL && 694 return ACTION_EXIT_MENUITEM;
731 (audio_status() & AUDIO_STATUS_PLAY)) 695
732 { 696 /* queueing options only work during playback */
733 return action; 697 if (!(audio_status() & AUDIO_STATUS_PLAY))
734 } 698 return ACTION_EXIT_MENUITEM;
735 else if (this_item == &i_shuf_pl_item) 699 }
736 { 700 else if ((this_item->flags & MENU_TYPE_MASK) == MT_FUNCTION_CALL &&
737 if (global_settings.show_shuffled_adding_options && 701 this_item->function->function_w_param == add_to_playlist)
738 (audio_status() & AUDIO_STATUS_PLAY)) 702 {
739 { 703 struct add_to_pl_param *param = this_item->function->param;
740 return action; 704
741 } 705 if (param->queue)
742 }
743 else if (this_item == &replace_shuf_pl_item)
744 { 706 {
745 if (global_settings.show_shuffled_adding_options && 707 if (global_settings.show_queue_options != QUEUE_SHOW_AT_TOPLEVEL &&
746 !(audio_status() & AUDIO_STATUS_PLAY) && 708 !in_queue_submenu)
747 ((selected_file_attr & ATTR_DIRECTORY) || 709 return ACTION_EXIT_MENUITEM;
748 ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)))
749 {
750 return action;
751 }
752 } 710 }
753 else if (this_item == &q_shuf_pl_submenu_item || 711
754 (this_item == &q_shuf_pl_item && 712 if (param->position == PLAYLIST_INSERT_SHUFFLED ||
755 global_settings.show_queue_options == QUEUE_SHOW_AT_TOPLEVEL)) 713 param->position == PLAYLIST_INSERT_LAST_SHUFFLED)
756 { 714 {
757 if (global_settings.show_shuffled_adding_options && 715 if (!global_settings.show_shuffled_adding_options)
758 (audio_status() & AUDIO_STATUS_PLAY)) 716 return ACTION_EXIT_MENUITEM;
759 { 717
760 return action; 718 if ((selected_file_attr & FILE_ATTR_MASK) != FILE_ATTR_M3U &&
761 } 719 (selected_file_attr & ATTR_DIRECTORY) == 0)
720 return ACTION_EXIT_MENUITEM;
762 } 721 }
763 else if (this_item == &i_last_shuf_pl_item || 722
764 this_item == &q_last_shuf_pl_submenu_item || 723 if (!param->replace)
765 (this_item == &q_last_shuf_pl_item &&
766 global_settings.show_queue_options == QUEUE_SHOW_AT_TOPLEVEL))
767 { 724 {
768 if (global_settings.show_shuffled_adding_options && 725 if (!(audio_status() & AUDIO_STATUS_PLAY))
769 (playlist_amount() > 0) && 726 return ACTION_EXIT_MENUITEM;
770 (audio_status() & AUDIO_STATUS_PLAY) &&
771 ((selected_file_attr & ATTR_DIRECTORY) ||
772 ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)))
773 {
774 return action;
775 }
776 } 727 }
777 return ACTION_EXIT_MENUITEM; 728 }
778 break; 729
730 break;
731
732 case ACTION_ENTER_MENUITEM:
733 if (this_item == &queue_menu)
734 in_queue_submenu = true;
735 break;
736
737 case ACTION_EXIT_MENUITEM:
738 if (this_item == &queue_menu)
739 in_queue_submenu = false;
740 break;
779 } 741 }
742
780 return action; 743 return action;
781} 744}
782 745
@@ -1840,7 +1803,7 @@ static int playlist_insert_shuffled(void)
1840 (selected_file_attr & ATTR_DIRECTORY) || 1803 (selected_file_attr & ATTR_DIRECTORY) ||
1841 ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U)) 1804 ((selected_file_attr & FILE_ATTR_MASK) == FILE_ATTR_M3U))
1842 { 1805 {
1843 playlist_insert_func((intptr_t*)PLAYLIST_INSERT_SHUFFLED); 1806 add_to_playlist(&addtopl_insert_shuf);
1844 return ONPLAY_START_PLAY; 1807 return ONPLAY_START_PLAY;
1845 } 1808 }
1846 1809
@@ -1883,7 +1846,7 @@ static struct hotkey_assignment hotkey_items[] = {
1883 HOTKEY_FUNC(delete_item, NULL), 1846 HOTKEY_FUNC(delete_item, NULL),
1884 ONPLAY_RELOAD_DIR }, 1847 ONPLAY_RELOAD_DIR },
1885 { HOTKEY_INSERT, LANG_INSERT, 1848 { HOTKEY_INSERT, LANG_INSERT,
1886 HOTKEY_FUNC(playlist_insert_func, (intptr_t*)PLAYLIST_INSERT), 1849 HOTKEY_FUNC(add_to_playlist, (intptr_t*)&addtopl_insert),
1887 ONPLAY_RELOAD_DIR }, 1850 ONPLAY_RELOAD_DIR },
1888 { HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED, 1851 { HOTKEY_INSERT_SHUFFLED, LANG_INSERT_SHUFFLED,
1889 HOTKEY_FUNC(playlist_insert_shuffled, NULL), 1852 HOTKEY_FUNC(playlist_insert_shuffled, NULL),