Wt examples 4.5.0
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
FileTreeTableNode Class Reference

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

#include <FileTreeTableNode.h>

Inheritance diagram for FileTreeTableNode:
Inheritance graph
[legend]

Public Member Functions

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

Private Member Functions

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

Static Private Member Functions

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

Private Attributes

boost::filesystem::path path_
 The path. More...
 

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 22 of file FileTreeTableNode.C.

24 : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
25#else
26 : WTreeTableNode(path.leaf().string(), createIcon(path)),
27#endif
28 path_(path)
29{
30 label()->setTextFormat(TextFormat::Plain);
31
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");
37 } else
38 setSelectable(false);
39
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"));
44
45 setColumnWidget(2, std::make_unique<WText>(dateTimeStr));
46 columnWidget(2)->setStyleClass("date");
47 }
48}
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 50 of file FileTreeTableNode.C.

51{
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);
56 else
57 return std::make_unique<WIconPair>("icons/document.png",
58 "icons/yellow-folder-open.png", false);
59}

◆ expandable()

bool FileTreeTableNode::expandable ( )
overrideprivatevirtual

Reimplements WTreeNode::expandable.

Definition at line 84 of file FileTreeTableNode.C.

85{
86 if (!populated()) {
87 return boost::filesystem::is_directory(path_);
88 } else
89 return WTreeTableNode::expandable();
90}

◆ populate()

void FileTreeTableNode::populate ( )
overrideprivatevirtual

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

Definition at line 61 of file FileTreeTableNode.C.

62{
63 if (boost::filesystem::is_directory(path_)) {
64 std::set<boost::filesystem::path> paths;
65 boost::filesystem::directory_iterator end_itr;
66
67 for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i)
68 try {
69 paths.insert(*i);
70 } catch (boost::filesystem::filesystem_error& e) {
71 std::cerr << e.what() << std::endl;
72 }
73
74 for (std::set<boost::filesystem::path>::iterator i = paths.begin();
75 i != paths.end(); ++i)
76 try {
77 addChildNode(std::make_unique<FileTreeTableNode>(*i));
78 } catch (boost::filesystem::filesystem_error& e) {
79 std::cerr << e.what() << std::endl;
80 }
81 }
82}

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:

Generated on Fri Aug 27 2021 for the C++ Web Toolkit (Wt) by doxygen 1.9.2