@@ -150,8 +150,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app)
150150 ui_area_list->setObjectName (" ui_area_list" );
151151
152152 ui_music_list = new QTreeWidget (this );
153- ui_music_list->setColumnCount (2 );
153+ ui_music_list->setColumnCount (3 );
154154 ui_music_list->hideColumn (1 );
155+ ui_music_list->hideColumn (2 );
155156 ui_music_list->setHeaderHidden (true );
156157 ui_music_list->header ()->setStretchLastSection (false );
157158 ui_music_list->header ()->setSectionResizeMode (QHeaderView::ResizeToContents);
@@ -1703,6 +1704,40 @@ void Courtroom::list_music()
17031704 QBrush missing_brush (ao_app->get_color (" missing_song_color" , f_file));
17041705
17051706 QTreeWidgetItem *parent = nullptr ;
1707+
1708+ // Handle favorites first so they're at the top of the list
1709+ QSettings favorite_songs_ini (get_base_path () + " favorite_songs.ini" , QSettings::IniFormat);
1710+ const QStringList &favorite_songs = favorite_songs_ini.value (ao_app->server_name ).toStringList ();
1711+ if (!favorite_songs.isEmpty ())
1712+ {
1713+ QTreeWidgetItem *favCategory;
1714+ favCategory = new QTreeWidgetItem (ui_music_list);
1715+ favCategory->setText (0 , tr (" == FAVORITES ==" ));
1716+ favCategory->setText (1 , tr (" == FAVORITES ==" ));
1717+ favCategory->setText (2 , " 1" );
1718+ favCategory->setBackground (0 , missing_brush);
1719+ for (const QString &song : favorite_songs)
1720+ {
1721+ QTreeWidgetItem *favSong = new QTreeWidgetItem (favCategory);
1722+ QString f_song_listname = song.left (song.lastIndexOf (" ." ));
1723+
1724+ favSong->setText (0 , f_song_listname);
1725+ favSong->setText (1 , song);
1726+ favSong->setText (2 , " 1" );
1727+
1728+ QString song_path = ao_app->get_real_path (ao_app->get_music_path (song));
1729+
1730+ if (file_exists (song_path))
1731+ {
1732+ favSong->setBackground (0 , found_brush);
1733+ }
1734+ else
1735+ {
1736+ favSong->setBackground (0 , missing_brush);
1737+ }
1738+ }
1739+ }
1740+
17061741 for (int n_song = 0 ; n_song < music_list.size (); ++n_song)
17071742 {
17081743 QString i_song = music_list.at (n_song);
@@ -1730,6 +1765,7 @@ void Courtroom::list_music()
17301765 }
17311766 treeItem->setText (0 , i_song_listname);
17321767 treeItem->setText (1 , i_song);
1768+ treeItem->setText (2 , " 0" );
17331769
17341770 QString song_path = ao_app->get_real_path (ao_app->get_music_path (i_song));
17351771
@@ -5749,6 +5785,18 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
57495785 menu->addAction (QString (tr (" Collapse All Categories" )), this , &Courtroom::music_list_collapse_all);
57505786 menu->addSeparator ();
57515787
5788+ QTreeWidgetItem *current_song = ui_music_list->currentItem ();
5789+ if (ui_music_list->currentItem ()->text (2 ) == " 1" )
5790+ {
5791+ menu->addAction (QString (tr (" Remove Favorite" )), this , [this , current_song] { Courtroom::remove_favorite_song (current_song); });
5792+ menu->addSeparator ();
5793+ }
5794+ else
5795+ {
5796+ menu->addAction (QString (tr (" Add Favorite" )), this , [this , current_song] { Courtroom::add_favorite_song (current_song); });
5797+ menu->addSeparator ();
5798+ }
5799+
57525800 menu->addAction (new QAction (tr (" Fade Out Previous" ), this ));
57535801 menu->actions ().back ()->setCheckable (true );
57545802 menu->actions ().back ()->setChecked (music_flags & FADE_OUT );
@@ -5777,6 +5825,26 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
57775825 menu->popup (ui_music_list->mapToGlobal (pos));
57785826}
57795827
5828+ void Courtroom::add_favorite_song (QTreeWidgetItem *p_item)
5829+ {
5830+ QSettings favorite_songs_ini (get_base_path () + " favorite_songs.ini" , QSettings::IniFormat);
5831+ QStringList favorite_songs = favorite_songs_ini.value (ao_app->server_name ).toStringList ();
5832+ favorite_songs.append (p_item->text (1 ));
5833+
5834+ favorite_songs_ini.setValue (ao_app->server_name , favorite_songs);
5835+ list_music ();
5836+ }
5837+
5838+ void Courtroom::remove_favorite_song (QTreeWidgetItem *p_item)
5839+ {
5840+ QSettings favorite_songs_ini (get_base_path () + " favorite_songs.ini" , QSettings::IniFormat);
5841+ QStringList favorite_songs = favorite_songs_ini.value (ao_app->server_name ).toStringList ();
5842+ favorite_songs.removeAll (p_item->text (1 ));
5843+
5844+ favorite_songs_ini.setValue (ao_app->server_name , favorite_songs);
5845+ list_music ();
5846+ }
5847+
57805848void Courtroom::music_fade_out (bool toggle)
57815849{
57825850 if (toggle)
0 commit comments