summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-01-13 21:38:45 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-01-31 16:13:19 +0000
commitc8aa4732798c59781e8a51da81beee6b8585ce8b (patch)
tree3e819334b78493d64a800341f189f2fe5737e103
parentRemove old util.h (diff)
downloadmythfs-c8aa4732798c59781e8a51da81beee6b8585ce8b.tar.bz2
mythfs-c8aa4732798c59781e8a51da81beee6b8585ce8b.tar.xz
mythfs-c8aa4732798c59781e8a51da81beee6b8585ce8b.zip
Add group by title folder
-rw-r--r--mythfs/service/inodes/byTitleDirectory.cpp22
-rw-r--r--mythfs/service/inodes/byTitleDirectory.h5
-rw-r--r--mythfs/service/inodes/groupingDirectory.cpp24
-rw-r--r--mythfs/service/inodes/groupingDirectory.h6
-rw-r--r--mythfs/service/recordingsVolume.cpp2
-rw-r--r--mythfs/unittests/testMain.cpp5
6 files changed, 61 insertions, 3 deletions
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<std::string>(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<std::string> {
+ 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 <algorithm>
+
+namespace MythFS {
+ template<typename T>
+ GroupingDirectory<T>::GroupingDirectory(DBPrx d) : db(d) { }
+
+ template<typename T>
+ NetFS::NameList
+ GroupingDirectory<T>::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<std::string>;
+}
+
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 <myth-models.h>
+#include <myth-db.h>
namespace MythFS {
template <typename T>
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 <Ice/ObjectAdapter.h>
#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();
}