From 5ebf3690b643d8f37508fb864cbda8e20c954204 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 13 Jan 2016 21:38:45 +0000 Subject: Add group by title folder --- mythfs/service/inodes/byTitleDirectory.cpp | 22 ++++++++++++++++++++++ mythfs/service/inodes/byTitleDirectory.h | 5 ++++- mythfs/service/inodes/groupingDirectory.cpp | 24 ++++++++++++++++++++++++ mythfs/service/inodes/groupingDirectory.h | 6 ++++++ mythfs/service/recordingsVolume.cpp | 2 ++ mythfs/unittests/testMain.cpp | 5 +++-- 6 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 mythfs/service/inodes/byTitleDirectory.cpp create mode 100644 mythfs/service/inodes/groupingDirectory.cpp diff --git a/mythfs/service/inodes/byTitleDirectory.cpp b/mythfs/service/inodes/byTitleDirectory.cpp new file mode 100644 index 0000000..148f441 --- /dev/null +++ b/mythfs/service/inodes/byTitleDirectory.cpp @@ -0,0 +1,22 @@ +#include "byTitleDirectory.h" +#include "symlink.h" + +namespace MythFS { + ByTitleDirectory::ByTitleDirectory(DBPrx db) : + GroupingDirectory(db) + { + } + + std::string + ByTitleDirectory::attribute(const MythFS::RecordedPtr & r) const + { + return r->title; + } + + Node::PointerType + ByTitleDirectory::getChild(const std::string & ) const + { + return new Symlink("/"); + } +} + diff --git a/mythfs/service/inodes/byTitleDirectory.h b/mythfs/service/inodes/byTitleDirectory.h index e9883d1..2d88b80 100644 --- a/mythfs/service/inodes/byTitleDirectory.h +++ b/mythfs/service/inodes/byTitleDirectory.h @@ -5,9 +5,12 @@ namespace MythFS { class ByTitleDirectory : public GroupingDirectory { + public: + ByTitleDirectory(DBPrx db); protected: - virtual std::string attribute(const MythFS::RecordedPtr &) const; + std::string attribute(const MythFS::RecordedPtr &) const override; + PointerType getChild(const std::string &) const override; }; } diff --git a/mythfs/service/inodes/groupingDirectory.cpp b/mythfs/service/inodes/groupingDirectory.cpp new file mode 100644 index 0000000..30e71d8 --- /dev/null +++ b/mythfs/service/inodes/groupingDirectory.cpp @@ -0,0 +1,24 @@ +#include "groupingDirectory.h" +#include + +namespace MythFS { + template + GroupingDirectory::GroupingDirectory(DBPrx d) : db(d) { } + + template + NetFS::NameList + GroupingDirectory::getContents() const + { + NetFS::NameList values; + for (auto r : db->getRecorded()) { + auto a = attribute(r); + if (std::find(values.begin(), values.end(), a) == values.end()) { + values.push_back(a); + } + } + return values; + } + + template class GroupingDirectory; +} + diff --git a/mythfs/service/inodes/groupingDirectory.h b/mythfs/service/inodes/groupingDirectory.h index 82b3c0c..5e587ac 100644 --- a/mythfs/service/inodes/groupingDirectory.h +++ b/mythfs/service/inodes/groupingDirectory.h @@ -2,14 +2,20 @@ #define MYTHFS_GROUPINGDIRECTORY_H #include "abstractDynamicDirectory.h" +#include +#include namespace MythFS { template class GroupingDirectory : public AbstractDynamicDirectory { public: + GroupingDirectory(DBPrx db); + protected: virtual T attribute(const MythFS::RecordedPtr &) const = 0; NetFS::NameList getContents() const override; + + DBPrx db; }; } diff --git a/mythfs/service/recordingsVolume.cpp b/mythfs/service/recordingsVolume.cpp index f5bf07b..c6d8a91 100644 --- a/mythfs/service/recordingsVolume.cpp +++ b/mythfs/service/recordingsVolume.cpp @@ -4,12 +4,14 @@ #include #include "inodes/allDirectory.h" +#include "inodes/byTitleDirectory.h" #include "openDirectory.h" namespace MythFS { RecordingsVolume::RecordingsVolume(DBPrx db) { contents.insert({ "all", new AllDirectory(db) }); + contents.insert({ "by title", new ByTitleDirectory(db) }); } NetFS::DirectoryPrx diff --git a/mythfs/unittests/testMain.cpp b/mythfs/unittests/testMain.cpp index 5451630..f6ec148 100644 --- a/mythfs/unittests/testMain.cpp +++ b/mythfs/unittests/testMain.cpp @@ -69,8 +69,9 @@ BOOST_AUTO_TEST_CASE( listRoot ) { auto d = rv->opendir(re, "/"); auto ls = d->readdir(); - BOOST_REQUIRE_EQUAL(1, ls.size()); - BOOST_REQUIRE_EQUAL("all", ls.front()); + BOOST_REQUIRE_EQUAL(2, ls.size()); + BOOST_REQUIRE_EQUAL("all", ls[0]); + BOOST_REQUIRE_EQUAL("by title", ls[1]); d->close(); } -- cgit v1.2.3