diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-27 18:45:20 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-12-27 18:45:20 +0100 |
commit | 263097e22bdf0a56007644e4d19605371dc79a8f (patch) | |
tree | 1ed40707f9714e178ed07abf834b1a13c33bddc0 /music.cpp | |
parent | cd8874addb61e11cef83d4be31110ed670b58884 (diff) |
Basic directory listing for HTTP.
Diffstat (limited to 'music.cpp')
-rw-r--r-- | music.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
@@ -1,6 +1,6 @@ #include "music.h" -#include <iostream> +#include <boost/format.hpp> namespace music { @@ -10,7 +10,41 @@ void init(const fs::path root) { root_directory = new MusicDirectory(root); } -}; +MusicListing *find(const std::string path, MusicDirectory& root) { + fs::path full_path = root_directory->path / path; + if(root.path == full_path) + return &root; + + for(MusicDirectories::iterator it = root.directories.begin(); it != root.directories.end(); it++) { + MusicListing *ml = find(path, *it); + if(ml) return ml; + } + for(MusicTracks::iterator it = root.tracks.begin(); it != root.tracks.end(); it++) { + std::string rel_path = it->path.string().substr(root_directory->path.string().size()); + std::cout << rel_path << std::endl; + if(rel_path == path) + return &(*it); + } + + return NULL; +} + +MusicListing *find(const std::string path) { + return find(path, *root_directory); +} + +}; // namespace music + +void MusicDirectory::render(std::ostream& os) { + for(MusicDirectories::iterator it = directories.begin(); it != directories.end(); it++) { + std::string rel_path = it->path.string().substr(music::root_directory->path.string().size()); + os << boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path; + } + for(MusicTracks::iterator it = tracks.begin(); it != tracks.end(); it++) { + std::string rel_path = it->path.string().substr(music::root_directory->path.string().size()); + os << boost::format("<a href=\"%s\">%s</a><br />") % rel_path % rel_path; + } +} MusicTrack::MusicTrack(const fs::path path) { std::cout << path << std::endl; @@ -32,3 +66,6 @@ MusicDirectory::MusicDirectory(const fs::path root) { } } } + +void MusicTrack::render(std::ostream& os) { +} |