while searching for songs in media library, consider year of the album
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
AC_INIT(configure.in)
|
||||
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
AM_INIT_AUTOMAKE(ncmpcpp, 0.3.1)
|
||||
AM_INIT_AUTOMAKE(ncmpcpp, 0.3.2_pre)
|
||||
|
||||
AC_PREREQ(2.59)
|
||||
|
||||
|
||||
@@ -181,15 +181,6 @@ bool CaseInsensitiveSorting::operator()(string a, string b)
|
||||
return a < b;
|
||||
}
|
||||
|
||||
bool CaseInsensitiveSorting::operator()(const string_pair &a, const string_pair &b)
|
||||
{
|
||||
string aa = a.first;
|
||||
string bb = b.first;
|
||||
ToLower(aa);
|
||||
ToLower(bb);
|
||||
return aa < bb;
|
||||
}
|
||||
|
||||
bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb)
|
||||
{
|
||||
string a = sa->GetName();
|
||||
|
||||
@@ -33,11 +33,24 @@ class CaseInsensitiveSorting
|
||||
{
|
||||
public:
|
||||
bool operator()(std::string, std::string);
|
||||
bool operator()(const string_pair &, const string_pair &);
|
||||
bool operator()(MPD::Song *, MPD::Song *);
|
||||
bool operator()(const MPD::Item &, const MPD::Item &);
|
||||
|
||||
template <class A, class B> bool operator()(const std::pair<A, B> &a, const std::pair<A, B> &b)
|
||||
{
|
||||
std::string aa = a.first;
|
||||
std::string bb = b.first;
|
||||
ToLower(aa);
|
||||
ToLower(bb);
|
||||
return aa < bb;
|
||||
}
|
||||
};
|
||||
|
||||
template <class A, class B> std::string StringPairToString(const std::pair<A, B> &pair, void *)
|
||||
{
|
||||
return pair.first;
|
||||
}
|
||||
|
||||
void UpdateSongList(Menu<MPD::Song> *);
|
||||
|
||||
bool Keypressed(int, const int *);
|
||||
|
||||
@@ -54,7 +54,7 @@ void MediaLibrary::Init()
|
||||
Artists->SetTimeout(ncmpcpp_window_timeout);
|
||||
Artists->SetItemDisplayer(Display::Generic);
|
||||
|
||||
Albums = new Menu<string_pair>(itsMiddleColStartX, main_start_y, itsMiddleColWidth, main_height, "Albums", Config.main_color, brNone);
|
||||
Albums = new Menu< std::pair<std::string, SearchConstraints> >(itsMiddleColStartX, main_start_y, itsMiddleColWidth, main_height, "Albums", Config.main_color, brNone);
|
||||
Albums->HighlightColor(Config.main_highlight_color);
|
||||
Albums->SetTimeout(ncmpcpp_window_timeout);
|
||||
Albums->SetItemDisplayer(Display::Pairs);
|
||||
@@ -150,7 +150,7 @@ void MediaLibrary::Update()
|
||||
{
|
||||
Albums->Reset();
|
||||
TagList list;
|
||||
std::vector<string_pair> maplist;
|
||||
std::vector< std::pair<std::string, SearchConstraints> > maplist;
|
||||
locale_to_utf(Artists->Current());
|
||||
if (Config.media_lib_primary_tag == MPD_TAG_ITEM_ARTIST)
|
||||
Mpd->GetAlbums(Artists->Current(), list);
|
||||
@@ -171,7 +171,7 @@ void MediaLibrary::Update()
|
||||
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, "");
|
||||
Mpd->CommitSearch(noalbum_list);
|
||||
if (!noalbum_list.empty())
|
||||
Albums->AddOption(std::make_pair("<no album>", ""));
|
||||
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
|
||||
FreeSongList(noalbum_list);
|
||||
}
|
||||
|
||||
@@ -182,17 +182,21 @@ void MediaLibrary::Update()
|
||||
Mpd->AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, *it);
|
||||
Mpd->CommitSearch(l);
|
||||
if (!l.empty() && !l[0]->GetAlbum().empty())
|
||||
sort(l.begin(), l.end(), SortSongsByYear);
|
||||
for (SongList::const_iterator j = l.begin(); j != l.end(); j++)
|
||||
{
|
||||
utf_to_locale(*it);
|
||||
l[0]->Localize();
|
||||
maplist.push_back(make_pair(l[0]->toString(Config.media_lib_album_format), *it));
|
||||
if (!(*j)->GetAlbum().empty() && (maplist.empty() || (*j)->GetYear() != maplist.back().second.Year))
|
||||
{
|
||||
utf_to_locale(*it);
|
||||
(*j)->Localize();
|
||||
maplist.push_back(make_pair((*j)->toString(Config.media_lib_album_format), SearchConstraints(*it, (*j)->GetYear())));
|
||||
}
|
||||
}
|
||||
FreeSongList(l);
|
||||
}
|
||||
utf_to_locale(Artists->Current());
|
||||
sort(maplist.begin(), maplist.end(), CaseInsensitiveSorting());
|
||||
for (std::vector<string_pair>::const_iterator it = maplist.begin(); it != maplist.end(); it++)
|
||||
for (std::vector< std::pair<std::string, SearchConstraints> >::const_iterator it = maplist.begin(); it != maplist.end(); it++)
|
||||
Albums->AddOption(*it);
|
||||
Albums->Window::Clear();
|
||||
Albums->Refresh();
|
||||
@@ -219,7 +223,11 @@ void MediaLibrary::Update()
|
||||
Albums->Window::Refresh();
|
||||
}
|
||||
else
|
||||
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, locale_to_utf_cpy(Albums->Current().second));
|
||||
{
|
||||
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, locale_to_utf_cpy(Albums->Current().second.Album));
|
||||
if (!Albums->Current().second.Album.empty()) // for <no album>
|
||||
Mpd->AddSearch(MPD_TAG_ITEM_DATE, locale_to_utf_cpy(Albums->Current().second.Year));
|
||||
}
|
||||
Mpd->CommitSearch(list);
|
||||
|
||||
sort(list.begin(), list.end(), SortSongsByTrack);
|
||||
@@ -358,7 +366,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
||||
Mpd->QueueAddSong(Songs->at(i));
|
||||
if (Mpd->CommitQueue())
|
||||
{
|
||||
ShowMessage("Adding songs from album \"%s\"", Albums->Current().second.c_str());
|
||||
ShowMessage("Adding songs from album \"%s\"", Albums->Current().second.Album.c_str());
|
||||
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-Songs->Size());
|
||||
if (s->GetHash() == Songs->at(0).GetHash())
|
||||
{
|
||||
@@ -432,16 +440,16 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
||||
}
|
||||
}
|
||||
|
||||
std::string MediaLibrary::StringPairToString(const string_pair &pair, void *)
|
||||
{
|
||||
return pair.first;
|
||||
}
|
||||
|
||||
std::string MediaLibrary::SongToString(const MPD::Song &s, void *)
|
||||
{
|
||||
return s.toString(Config.song_library_format);
|
||||
}
|
||||
|
||||
bool MediaLibrary::SortSongsByYear(Song *a, Song *b)
|
||||
{
|
||||
return a->GetYear() < b->GetYear();
|
||||
}
|
||||
|
||||
bool MediaLibrary::SortSongsByTrack(Song *a, Song *b)
|
||||
{
|
||||
if (a->GetDisc() == b->GetDisc())
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
|
||||
class MediaLibrary : public Screen<Window>
|
||||
{
|
||||
struct SearchConstraints
|
||||
{
|
||||
SearchConstraints(const std::string &album, const std::string &year) : Album(album), Year(year) { }
|
||||
|
||||
std::string Album;
|
||||
std::string Year;
|
||||
};
|
||||
|
||||
public:
|
||||
virtual void Init();
|
||||
virtual void SwitchTo();
|
||||
@@ -52,10 +60,8 @@ class MediaLibrary : public Screen<Window>
|
||||
void NextColumn();
|
||||
void PrevColumn();
|
||||
|
||||
static std::string StringPairToString(const string_pair &pair, void *);
|
||||
|
||||
Menu<std::string> *Artists;
|
||||
Menu<string_pair> *Albums;
|
||||
Menu< std::pair<std::string, SearchConstraints> > *Albums;
|
||||
Menu<MPD::Song> *Songs;
|
||||
|
||||
protected:
|
||||
@@ -64,6 +70,7 @@ class MediaLibrary : public Screen<Window>
|
||||
static std::string SongToString(const MPD::Song &s, void *);
|
||||
|
||||
static bool SortSongsByTrack(MPD::Song *, MPD::Song *);
|
||||
static bool SortSongsByYear(MPD::Song *, MPD::Song *);
|
||||
|
||||
static size_t itsLeftColWidth;
|
||||
static size_t itsMiddleColWidth;
|
||||
|
||||
@@ -1080,9 +1080,9 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
LockStatusbar();
|
||||
Statusbar() << fmtBold << "Album: " << fmtBoldEnd;
|
||||
string new_album = wFooter->GetString(myLibrary->Albums->Current().second);
|
||||
string new_album = wFooter->GetString(myLibrary->Albums->Current().second.Album);
|
||||
UnlockStatusbar();
|
||||
if (!new_album.empty() && new_album != myLibrary->Albums->Current().second)
|
||||
if (!new_album.empty() && new_album != myLibrary->Albums->Current().second.Album)
|
||||
{
|
||||
bool success = 1;
|
||||
ShowMessage("Updating tags...");
|
||||
|
||||
@@ -304,13 +304,13 @@ void TagEditor::Init()
|
||||
Albums->HighlightColor(Config.active_column_color);
|
||||
Albums->SetTimeout(ncmpcpp_window_timeout);
|
||||
Albums->SetItemDisplayer(Display::Pairs);
|
||||
Albums->SetGetStringFunction(MediaLibrary::StringPairToString);
|
||||
Albums->SetGetStringFunction(StringPairToString);
|
||||
|
||||
Dirs = new Menu<string_pair>(0, main_start_y, LeftColumnWidth, main_height, "Directories", Config.main_color, brNone);
|
||||
Dirs->HighlightColor(Config.active_column_color);
|
||||
Dirs->SetTimeout(ncmpcpp_window_timeout);
|
||||
Dirs->SetItemDisplayer(Display::Pairs);
|
||||
Dirs->SetGetStringFunction(MediaLibrary::StringPairToString);
|
||||
Dirs->SetGetStringFunction(StringPairToString);
|
||||
|
||||
LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user