mpd: redesign Item and adjust browser
This commit is contained in:
@@ -53,36 +53,58 @@ int LocaleStringComparison::compare(const char *a, size_t a_len, const char *b,
|
||||
bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b) const
|
||||
{
|
||||
bool result = false;
|
||||
if (a.type == b.type)
|
||||
if (a.type() == b.type())
|
||||
{
|
||||
switch (a.type)
|
||||
switch (m_sort_mode)
|
||||
{
|
||||
case MPD::Item::Type::Directory:
|
||||
result = m_cmp(getBasename(a.name), getBasename(b.name));
|
||||
break;
|
||||
case MPD::Item::Type::Playlist:
|
||||
result = m_cmp(a.name, b.name);
|
||||
break;
|
||||
case MPD::Item::Type::Song:
|
||||
switch (m_sort_mode)
|
||||
case SortMode::Name:
|
||||
switch (a.type())
|
||||
{
|
||||
case SortMode::Name:
|
||||
result = m_cmp(a.song, b.song);
|
||||
case MPD::Item::Type::Directory:
|
||||
result = m_cmp(a.directory().path(), b.directory().path());
|
||||
break;
|
||||
case SortMode::ModificationTime:
|
||||
result = a.song.getMTime() > b.song.getMTime();
|
||||
case MPD::Item::Type::Playlist:
|
||||
result = m_cmp(a.playlist().path(), b.playlist().path());
|
||||
break;
|
||||
case SortMode::CustomFormat:
|
||||
result = m_cmp(a.song.toString(Config.browser_sort_format, Config.tags_separator),
|
||||
b.song.toString(Config.browser_sort_format, Config.tags_separator));
|
||||
case MPD::Item::Type::Song:
|
||||
result = m_cmp(a.song(), b.song());
|
||||
break;
|
||||
case SortMode::NoOp:
|
||||
throw std::logic_error("can't sort with NoOp sorting mode");
|
||||
}
|
||||
break;
|
||||
case SortMode::CustomFormat:
|
||||
switch (a.type())
|
||||
{
|
||||
case MPD::Item::Type::Directory:
|
||||
result = m_cmp(a.directory().path(), b.directory().path());
|
||||
break;
|
||||
case MPD::Item::Type::Playlist:
|
||||
result = m_cmp(a.playlist().path(), b.playlist().path());
|
||||
break;
|
||||
case MPD::Item::Type::Song:
|
||||
result = m_cmp(a.song().toString(Config.browser_sort_format, Config.tags_separator),
|
||||
b.song().toString(Config.browser_sort_format, Config.tags_separator));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SortMode::ModificationTime:
|
||||
switch (a.type())
|
||||
{
|
||||
case MPD::Item::Type::Directory:
|
||||
result = a.directory().lastModified() > b.directory().lastModified();
|
||||
break;
|
||||
case MPD::Item::Type::Playlist:
|
||||
result = a.playlist().lastModified() > b.playlist().lastModified();
|
||||
break;
|
||||
case MPD::Item::Type::Song:
|
||||
result = a.song().getMTime() > b.song().getMTime();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SortMode::NoOp:
|
||||
throw std::logic_error("can't sort with NoOp sorting mode");
|
||||
}
|
||||
}
|
||||
else
|
||||
result = a.type < b.type;
|
||||
result = a.type() < b.type();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -32,13 +32,14 @@ std::string getBasename(const std::string &path)
|
||||
return path.substr(slash+1);
|
||||
}
|
||||
|
||||
std::string getParentDirectory(const std::string &path)
|
||||
std::string getParentDirectory(std::string path)
|
||||
{
|
||||
size_t slash = path.rfind('/');
|
||||
if (slash == std::string::npos)
|
||||
return "/";
|
||||
path = "";
|
||||
else
|
||||
return path.substr(0, slash);
|
||||
path.resize(slash);
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string getSharedDirectory(const std::string &dir1, const std::string &dir2)
|
||||
|
||||
@@ -53,7 +53,7 @@ StringT join(CollectionT &&collection, StringT &&separator)
|
||||
}
|
||||
|
||||
std::string getBasename(const std::string &path);
|
||||
std::string getParentDirectory(const std::string &path);
|
||||
std::string getParentDirectory(std::string path);
|
||||
std::string getSharedDirectory(const std::string &dir1, const std::string &dir2);
|
||||
|
||||
std::string getEnclosedString(const std::string &s, char a, char b, size_t *pos);
|
||||
|
||||
Reference in New Issue
Block a user