media library: support for "All tracks" option in middle column
This commit is contained in:
@@ -42,6 +42,12 @@ size_t MediaLibrary::itsMiddleColStartX;
|
|||||||
size_t MediaLibrary::itsRightColWidth;
|
size_t MediaLibrary::itsRightColWidth;
|
||||||
size_t MediaLibrary::itsRightColStartX;
|
size_t MediaLibrary::itsRightColStartX;
|
||||||
|
|
||||||
|
// this string marks the position in middle column that works as "All tracks" option. it's
|
||||||
|
// assigned to Year in SearchConstraint class since date normally cannot contain other chars
|
||||||
|
// than ciphers and -'s (0x7f is interpreted as backspace keycode, so it's quite safe to assume
|
||||||
|
// that it won't appear in any tag, let alone date).
|
||||||
|
const char MediaLibrary::AllTracksMarker[] = "\x7f";
|
||||||
|
|
||||||
void MediaLibrary::Init()
|
void MediaLibrary::Init()
|
||||||
{
|
{
|
||||||
hasTwoColumns = 0;
|
hasTwoColumns = 0;
|
||||||
@@ -227,6 +233,11 @@ void MediaLibrary::Update()
|
|||||||
utf_to_locale(Artists->Current());
|
utf_to_locale(Artists->Current());
|
||||||
if (!Albums->Empty())
|
if (!Albums->Empty())
|
||||||
Albums->Sort<SearchConstraintsSorting>();
|
Albums->Sort<SearchConstraintsSorting>();
|
||||||
|
if (Albums->Size() > 1)
|
||||||
|
{
|
||||||
|
Albums->AddSeparator();
|
||||||
|
Albums->AddOption(SearchConstraints("", AllTracksMarker));
|
||||||
|
}
|
||||||
Albums->Refresh();
|
Albums->Refresh();
|
||||||
}
|
}
|
||||||
else if (hasTwoColumns && Albums->Empty())
|
else if (hasTwoColumns && Albums->Empty())
|
||||||
@@ -304,13 +315,16 @@ void MediaLibrary::Update()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Mpd.AddSearch(MPD_TAG_ALBUM, locale_to_utf_cpy(Albums->Current().Album));
|
if (Albums->Current().Year != AllTracksMarker)
|
||||||
if (Config.media_library_display_date)
|
{
|
||||||
Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Year));
|
Mpd.AddSearch(MPD_TAG_ALBUM, locale_to_utf_cpy(Albums->Current().Album));
|
||||||
|
if (Config.media_library_display_date)
|
||||||
|
Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Year));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearch(list);
|
||||||
|
|
||||||
sort(list.begin(), list.end(), SortSongsByTrack);
|
sort(list.begin(), list.end(), Albums->Current().Year == AllTracksMarker ? SortAllTracks : SortSongsByTrack);
|
||||||
bool bold = 0;
|
bool bold = 0;
|
||||||
|
|
||||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||||
@@ -704,6 +718,8 @@ std::string MediaLibrary::SongToString(const MPD::Song &s, void *)
|
|||||||
|
|
||||||
std::string MediaLibrary::AlbumToString(const SearchConstraints &sc, void *ptr)
|
std::string MediaLibrary::AlbumToString(const SearchConstraints &sc, void *ptr)
|
||||||
{
|
{
|
||||||
|
if (sc.Year == AllTracksMarker)
|
||||||
|
return "All tracks";
|
||||||
std::string result;
|
std::string result;
|
||||||
if (!sc.Artist.empty())
|
if (!sc.Artist.empty())
|
||||||
(result += sc.Artist) += " - ";
|
(result += sc.Artist) += " - ";
|
||||||
@@ -740,3 +756,13 @@ bool MediaLibrary::SortSongsByTrack(MPD::Song *a, MPD::Song *b)
|
|||||||
return StrToInt(a->GetDisc()) < StrToInt(b->GetDisc());
|
return StrToInt(a->GetDisc()) < StrToInt(b->GetDisc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MediaLibrary::SortAllTracks(MPD::Song *a, MPD::Song *b)
|
||||||
|
{
|
||||||
|
static MPD::Song::GetFunction gets[] = { &MPD::Song::GetDate, &MPD::Song::GetAlbum, &MPD::Song::GetDisc, 0 };
|
||||||
|
CaseInsensitiveStringComparison cmp;
|
||||||
|
for (MPD::Song::GetFunction *get = gets; *get; ++get)
|
||||||
|
if (int ret = cmp(a->GetTags(*get), b->GetTags(*get)))
|
||||||
|
return ret < 0;
|
||||||
|
return a->GetTrack() < b->GetTrack();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ class MediaLibrary : public Screen<Window>
|
|||||||
static void DisplayAlbums(const SearchConstraints &, void *, Menu<SearchConstraints> *);
|
static void DisplayAlbums(const SearchConstraints &, void *, Menu<SearchConstraints> *);
|
||||||
|
|
||||||
static bool SortSongsByTrack(MPD::Song *, MPD::Song *);
|
static bool SortSongsByTrack(MPD::Song *, MPD::Song *);
|
||||||
|
static bool SortAllTracks(MPD::Song *, MPD::Song *);
|
||||||
|
|
||||||
static bool hasTwoColumns;
|
static bool hasTwoColumns;
|
||||||
static size_t itsLeftColWidth;
|
static size_t itsLeftColWidth;
|
||||||
@@ -94,6 +95,8 @@ class MediaLibrary : public Screen<Window>
|
|||||||
static size_t itsMiddleColStartX;
|
static size_t itsMiddleColStartX;
|
||||||
static size_t itsRightColWidth;
|
static size_t itsRightColWidth;
|
||||||
static size_t itsRightColStartX;
|
static size_t itsRightColStartX;
|
||||||
|
|
||||||
|
static const char AllTracksMarker[];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MediaLibrary *myLibrary;
|
extern MediaLibrary *myLibrary;
|
||||||
|
|||||||
Reference in New Issue
Block a user