Wt examples  4.0.2
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 21 of file FileTreeTableNode.C.

23  : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
24 #else
25  : WTreeTableNode(path.leaf().string(), createIcon(path)),
26 #endif
27  path_(path)
28 {
29  label()->setTextFormat(TextFormat::Plain);
30 
31  if (boost::filesystem::exists(path)) {
32  if (!boost::filesystem::is_directory(path)) {
33  int fsize = (int)boost::filesystem::file_size(path);
34  setColumnWidget(1, cpp14::make_unique<WText>(asString(fsize)));
35  columnWidget(1)->setStyleClass("fsize");
36  } else
37  setSelectable(false);
38 
39  std::time_t t = boost::filesystem::last_write_time(path);
40  struct tm ttm;
41 #if WIN32
42  ttm=*localtime(&t);
43 #else
44  localtime_r(&t, &ttm);
45 #endif
46 
47  char c[100];
48  strftime(c, 100, "%b %d %Y", &ttm);
49 
50  setColumnWidget(2, cpp14::make_unique<WText>(c));
51  columnWidget(2)->setStyleClass("date");
52  }
53 }
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 55 of file FileTreeTableNode.C.

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

§ expandable()

bool FileTreeTableNode::expandable ( )
overrideprivatevirtual

Reimplements WTreeNode::expandable.

Definition at line 89 of file FileTreeTableNode.C.

90 {
91  if (!populated()) {
92  return boost::filesystem::is_directory(path_);
93  } else
94  return WTreeTableNode::expandable();
95 }
boost::filesystem::path path_
The path.

§ populate()

void FileTreeTableNode::populate ( )
overrideprivatevirtual

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

Definition at line 66 of file FileTreeTableNode.C.

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

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 Wed May 30 2018 for the C++ Web Toolkit (Wt) by doxygen 1.8.12