Wt examples  4.11.1
Loading...
Searching...
No Matches
FileTreeTableNode Class Reference

A single node in a file tree table. More...

#include <FileTreeTableNode.h>

Inheritance diagram for FileTreeTableNode:
[legend]

Public Member Functions

 FileTreeTableNode (const boost::filesystem::path &path)
 Construct a new node for the given file.

Private Member Functions

virtual void populate () override
 Reimplements WTreeNode::populate to read files within a directory.
virtual bool expandable () override
 Reimplements WTreeNode::expandable.

Static Private Member Functions

static std::unique_ptr< WIconPair > createIcon (const boost::filesystem::path &path)
 Create the iconpair for representing the path.

Private Attributes

boost::filesystem::path path_
 The path.

Detailed Description

A single node in a file tree table.

The node manages the details about one file, and if the file is a directory, populates a subtree with nodes for every directory item.

The tree node reimplements Wt::WTreeTableNode::populate() to populate a directory node only when the node is expanded. In this way, only directories that are actually browsed are loaded from disk.

Definition at line 30 of file FileTreeTableNode.h.

Constructor & Destructor Documentation

◆ FileTreeTableNode()

FileTreeTableNode::FileTreeTableNode ( const boost::filesystem::path & path)

Construct a new node for the given file.

Definition at line 31 of file FileTreeTableNode.C.

33 : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
34#else
35 : WTreeTableNode(path.filename().string(), createIcon(path)),
36#endif
37 path_(path)
38{
39 label()->setTextFormat(TextFormat::Plain);
40
41 if (boost::filesystem::exists(path)) {
42 if (!boost::filesystem::is_directory(path)) {
43 int fsize = (int)boost::filesystem::file_size(path);
44 setColumnWidget(1, std::make_unique<WText>(asString(fsize)));
45 columnWidget(1)->setStyleClass("fsize");
46 } else
47 setSelectable(false);
48
49 std::time_t t = boost::filesystem::last_write_time(path);
50 Wt::WDateTime dateTime = Wt::WDateTime::fromTime_t(t);
51 Wt::WString dateTimeStr = dateTime.toString(Wt::utf8("MMM dd yyyy"));
52
53 setColumnWidget(2, std::make_unique<WText>(dateTimeStr));
54 columnWidget(2)->setStyleClass("date");
55 }
56}
boost::filesystem::path path_
The path.
static std::unique_ptr< WIconPair > createIcon(const boost::filesystem::path &path)
Create the iconpair for representing the path.

Member Function Documentation

◆ createIcon()

std::unique_ptr< WIconPair > FileTreeTableNode::createIcon ( const boost::filesystem::path & path)
staticprivate

Create the iconpair for representing the path.

Definition at line 58 of file FileTreeTableNode.C.

59{
60 if (boost::filesystem::exists(path)
61 && boost::filesystem::is_directory(path))
62 return std::make_unique<WIconPair>("icons/yellow-folder-closed.png",
63 "icons/yellow-folder-open.png", false);
64 else
65 return std::make_unique<WIconPair>("icons/document.png",
66 "icons/yellow-folder-open.png", false);
67}

◆ expandable()

bool FileTreeTableNode::expandable ( )
overrideprivatevirtual

Reimplements WTreeNode::expandable.

Definition at line 92 of file FileTreeTableNode.C.

93{
94 if (!populated()) {
95 return boost::filesystem::is_directory(path_);
96 } else
97 return WTreeTableNode::expandable();
98}

◆ populate()

void FileTreeTableNode::populate ( )
overrideprivatevirtual

Reimplements WTreeNode::populate to read files within a directory.

Definition at line 69 of file FileTreeTableNode.C.

70{
71 if (boost::filesystem::is_directory(path_)) {
72 std::set<boost::filesystem::path> paths;
73 boost::filesystem::directory_iterator end_itr;
74
75 for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i)
76 try {
77 paths.insert(*i);
78 } catch (boost::filesystem::filesystem_error& e) {
79 std::cerr << e.what() << std::endl;
80 }
81
82 for (std::set<boost::filesystem::path>::iterator i = paths.begin();
83 i != paths.end(); ++i)
84 try {
85 addChildNode(std::make_unique<FileTreeTableNode>(*i));
86 } catch (boost::filesystem::filesystem_error& e) {
87 std::cerr << e.what() << std::endl;
88 }
89 }
90}

Member Data Documentation

◆ path_

boost::filesystem::path FileTreeTableNode::path_
private

The path.

Definition at line 39 of file FileTreeTableNode.h.


The documentation for this class was generated from the following files: