@@ -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
@@ -5751,6 +5787,18 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
57515787 menu->addAction (QString (tr (" Collapse All Categories" )), this , &Courtroom::music_list_collapse_all);
57525788 menu->addSeparator ();
57535789
5790+ QTreeWidgetItem *current_song = ui_music_list->currentItem ();
5791+ if (ui_music_list->currentItem ()->text (2 ) == " 1" )
5792+ {
5793+ menu->addAction (QString (tr (" Remove Favorite" )), this , [this , current_song] { Courtroom::remove_favorite_song (current_song); });
5794+ menu->addSeparator ();
5795+ }
5796+ else
5797+ {
5798+ menu->addAction (QString (tr (" Add Favorite" )), this , [this , current_song] { Courtroom::add_favorite_song (current_song); });
5799+ menu->addSeparator ();
5800+ }
5801+
57545802 menu->addAction (new QAction (tr (" Fade Out Previous" ), this ));
57555803 menu->actions ().constLast ()->setCheckable (true );
57565804 menu->actions ().constLast ()->setChecked (music_flags & FADE_OUT );
@@ -5779,6 +5827,26 @@ void Courtroom::on_music_list_context_menu_requested(const QPoint &pos)
57795827 menu->popup (ui_music_list->mapToGlobal (pos));
57805828}
57815829
5830+ void Courtroom::add_favorite_song (QTreeWidgetItem *p_item)
5831+ {
5832+ QSettings favorite_songs_ini (get_base_path () + " favorite_songs.ini" , QSettings::IniFormat);
5833+ QStringList favorite_songs = favorite_songs_ini.value (ao_app->server_name ).toStringList ();
5834+ favorite_songs.append (p_item->text (1 ));
5835+
5836+ favorite_songs_ini.setValue (ao_app->server_name , favorite_songs);
5837+ list_music ();
5838+ }
5839+
5840+ void Courtroom::remove_favorite_song (QTreeWidgetItem *p_item)
5841+ {
5842+ QSettings favorite_songs_ini (get_base_path () + " favorite_songs.ini" , QSettings::IniFormat);
5843+ QStringList favorite_songs = favorite_songs_ini.value (ao_app->server_name ).toStringList ();
5844+ favorite_songs.removeAll (p_item->text (1 ));
5845+
5846+ favorite_songs_ini.setValue (ao_app->server_name , favorite_songs);
5847+ list_music ();
5848+ }
5849+
57825850void Courtroom::music_fade_out (bool toggle)
57835851{
57845852 if (toggle)
0 commit comments