Wt examples  3.3.6
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 ()
 Reimplements WTreeNode::populate to read files within a directory. More...
 
virtual bool expandable ()
 Reimplements WTreeNode::expandable. More...
 

Static Private Member Functions

static Wt::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 28 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.

25  : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
26 #else
27  : WTreeTableNode(path.leaf(), createIcon(path)),
28 #endif
29 #else
30  : WTreeTableNode(path.leaf().string(), createIcon(path)),
31 #endif
32  path_(path)
33 {
34  label()->setTextFormat(PlainText);
35 
36  if (boost::filesystem::exists(path)) {
37  if (!boost::filesystem::is_directory(path)) {
38  int fsize = (int)boost::filesystem::file_size(path);
39  setColumnWidget(1, new WText(boost::lexical_cast<std::string>(fsize)));
40  columnWidget(1)->setStyleClass("fsize");
41  } else
42  setSelectable(false);
43 
44  std::time_t t = boost::filesystem::last_write_time(path);
45  struct tm ttm;
46 #if WIN32
47  ttm=*localtime(&t);
48 #else
49  localtime_r(&t, &ttm);
50 #endif
51 
52  char c[100];
53  strftime(c, 100, "%b %d %Y", &ttm);
54 
55  setColumnWidget(2, new WText(c));
56  columnWidget(2)->setStyleClass("date");
57  }
58 }
static Wt::WIconPair * createIcon(const boost::filesystem::path &path)
Create the iconpair for representing the path.
boost::filesystem::path path_
The path.

Member Function Documentation

§ createIcon()

WIconPair * FileTreeTableNode::createIcon ( const boost::filesystem::path &  path)
staticprivate

Create the iconpair for representing the path.

Definition at line 60 of file FileTreeTableNode.C.

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

§ expandable()

bool FileTreeTableNode::expandable ( )
privatevirtual

Reimplements WTreeNode::expandable.

Definition at line 94 of file FileTreeTableNode.C.

95 {
96  if (!populated()) {
97  return boost::filesystem::is_directory(path_);
98  } else
99  return WTreeTableNode::expandable();
100 }
boost::filesystem::path path_
The path.

§ populate()

void FileTreeTableNode::populate ( )
privatevirtual

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

Definition at line 71 of file FileTreeTableNode.C.

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

Member Data Documentation

§ path_

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

The path.

Definition at line 37 of file FileTreeTableNode.h.


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

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.12