10#include <boost/filesystem/operations.hpp>
11#include <boost/filesystem/exception.hpp>
12#include <boost/lexical_cast.hpp>
15#include <Wt/WDateTime.h>
16#include <Wt/WIconPair.h>
17#include <Wt/WLocalDateTime.h>
18#include <Wt/WStringUtil.h>
23#if BOOST_FILESYSTEM_VERSION < 3
24 : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
26 : WTreeTableNode(path.leaf().string(), createIcon(path)),
30 label()->setTextFormat(TextFormat::Plain);
32 if (boost::filesystem::exists(path)) {
33 if (!boost::filesystem::is_directory(path)) {
34 int fsize = (int)boost::filesystem::file_size(path);
35 setColumnWidget(1, std::make_unique<WText>(asString(fsize)));
36 columnWidget(1)->setStyleClass(
"fsize");
40 std::time_t t = boost::filesystem::last_write_time(path);
41 Wt::WDateTime dateTime = Wt::WDateTime::fromTime_t(t);
42 Wt::WLocalDateTime localDateTime = dateTime.toLocalTime();
43 Wt::WString dateTimeStr = localDateTime.toString(Wt::utf8(
"MMM dd yyyy"));
45 setColumnWidget(2, std::make_unique<WText>(dateTimeStr));
46 columnWidget(2)->setStyleClass(
"date");
52 if (boost::filesystem::exists(path)
53 && boost::filesystem::is_directory(path))
54 return std::make_unique<WIconPair>(
"icons/yellow-folder-closed.png",
55 "icons/yellow-folder-open.png",
false);
57 return std::make_unique<WIconPair>(
"icons/document.png",
58 "icons/yellow-folder-open.png",
false);
63 if (boost::filesystem::is_directory(
path_)) {
64 std::set<boost::filesystem::path> paths;
65 boost::filesystem::directory_iterator end_itr;
67 for (boost::filesystem::directory_iterator i(
path_); i != end_itr; ++i)
70 }
catch (boost::filesystem::filesystem_error& e) {
71 std::cerr << e.what() << std::endl;
74 for (std::set<boost::filesystem::path>::iterator i = paths.begin();
75 i != paths.end(); ++i)
77 addChildNode(std::make_unique<FileTreeTableNode>(*i));
78 }
catch (boost::filesystem::filesystem_error& e) {
79 std::cerr << e.what() << std::endl;
87 return boost::filesystem::is_directory(
path_);
89 return WTreeTableNode::expandable();
boost::filesystem::path path_
The path.
static std::unique_ptr< WIconPair > createIcon(const boost::filesystem::path &path)
Create the iconpair for representing the path.
virtual bool expandable() override
Reimplements WTreeNode::expandable.
FileTreeTableNode(const boost::filesystem::path &path)
Construct a new node for the given file.
virtual void populate() override
Reimplements WTreeNode::populate to read files within a directory.