예제 #1
0
bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b) const
{
	bool result = false;
	if (a.type() == b.type())
	{
		switch (m_sort_mode)
		{
			case SortMode::Name:
				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(), b.song());
						break;
				}
				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(Format::stringify<char>(Config.browser_sort_format, &a.song()),
						               Format::stringify<char>(Config.browser_sort_format, &b.song()));
						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();
	return result;
}
예제 #2
0
void Browser::remove(const MPD::Item &item)
{
	if (!Config.allow_for_physical_item_deletion)
		throw std::runtime_error("physical deletion is forbidden");
	if (isParentDirectory((item)))
		throw std::runtime_error("deletion of parent directory is forbidden");

	std::string path;
	switch (item.type())
	{
		case MPD::Item::Type::Directory:
			path = realPath(m_local_browser, item.directory().path());
			clearDirectory(path);
			fs::remove(path);
			break;
		case MPD::Item::Type::Song:
			path = realPath(m_local_browser, item.song().getURI());
			fs::remove(path);
			break;
		case MPD::Item::Type::Playlist:
			path = item.playlist().path();
			try {
				Mpd.DeletePlaylist(path);
			} catch (MPD::ServerError &e) {
				// if there is no such mpd playlist, it's a local one
				if (e.code() == MPD_SERVER_ERROR_NO_EXIST)
				{
					path = realPath(m_local_browser, std::move(path));
					fs::remove(path);
				}
				else
					throw;
			}
			break;
	}
}