From 9abc3cad022da793ae16912d7feced8eef58be3d Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Thu, 6 Jan 2011 15:08:08 +0100 Subject: MusicDirectory::render() now outputs current directory and links to parent directory when applicable. --- music.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/music.cpp b/music.cpp index cebf745..ee9f2ba 100644 --- a/music.cpp +++ b/music.cpp @@ -204,13 +204,26 @@ void MusicDirectory::render(HTTP::Connection::p req) { std::string base_path = boost::algorithm::join(req->base_path, "/"); + // strip root_directory from the absolute file path + std::string rel_base(path.string().substr(music::root_directory.string().size())); + // set relative base to "/" if we're at the root_directory + if(!rel_base.size()) + rel_base = "/"; + req->send_data(boost::str(boost::format("

%s

") % rel_base)); + + // link to parent directory if we're not at the root_directory + if(rel_base != "/") { + std::string rel_parent(rel_base.substr(0, rel_base.find_last_of('/'))); + req->send_data(boost::str(boost::format("..
") % base_path % rel_parent)); + } + for(PathListings::iterator it = directories.begin(); it != directories.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - req->send_data(boost::str(boost::format("%s
") % base_path % rel_path % rel_path)); + req->send_data(boost::str(boost::format("%s
") % base_path % rel_path % it->filename())); } for(PathListings::iterator it = tracks.begin(); it != tracks.end(); it++) { std::string rel_path = it->string().substr(music::root_directory.string().size()); - req->send_data(boost::str(boost::format("%s
") % base_path % rel_path % rel_path)); + req->send_data(boost::str(boost::format("%s
") % base_path % rel_path % it->filename())); } } -- cgit v1.2.3