FileTreeTableNode Class Reference
[File Explorer example]

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

#include <FileTreeTableNode.h>

Inheritance diagram for FileTreeTableNode:

Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Private Member Functions

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

Static Private Member Functions

static Wt::WIconPaircreateIcon (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 28 of file FileTreeTableNode.h.


Constructor & Destructor Documentation

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

Construct a new node for the given file.

Definition at line 22 of file FileTreeTableNode.C.

00023   : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
00024     path_(path)
00025 {
00026   label()->setTextFormat(PlainText);
00027 
00028   if (boost::filesystem::exists(path)) {
00029     if (!boost::filesystem::is_directory(path)) {
00030       int fsize = boost::filesystem::file_size(path);
00031       setColumnWidget(1, new WText(boost::lexical_cast<std::wstring>(fsize)));
00032       columnWidget(1)->setStyleClass("fsize");
00033     } else
00034       setSelectable(false);
00035 
00036     std::time_t t = boost::filesystem::last_write_time(path);
00037     struct tm ttm;
00038 #if WIN32
00039     ttm=*localtime(&t);
00040 #else
00041     localtime_r(&t, &ttm);
00042 #endif
00043 
00044     char c[100];
00045     strftime(c, 100, "%b %d %Y", &ttm);
00046 
00047     setColumnWidget(2, new WText(c));
00048     columnWidget(2)->setStyleClass("date");
00049   }
00050 }


Member Function Documentation

void FileTreeTableNode::populate (  )  [private, virtual]

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

Reimplemented from Wt::WTreeNode.

Definition at line 63 of file FileTreeTableNode.C.

00064 {
00065   try {
00066     if (boost::filesystem::is_directory(path_)) {
00067       std::set<boost::filesystem::path> paths;
00068       boost::filesystem::directory_iterator end_itr;
00069 
00070       for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i)
00071         paths.insert(*i);
00072 
00073       for (std::set<boost::filesystem::path>::iterator i = paths.begin();
00074            i != paths.end(); ++i)
00075         addChildNode(new FileTreeTableNode(*i));
00076     }
00077   } catch (boost::filesystem::filesystem_error& e) {
00078     std::cerr << e.what() << std::endl;
00079   }
00080 }

bool FileTreeTableNode::expandable (  )  [private, virtual]

Reimplements WTreeNode::expandable.

Reimplemented from Wt::WTreeNode.

Definition at line 82 of file FileTreeTableNode.C.

00083 {
00084   if (!populated()) {
00085     return boost::filesystem::is_directory(path_);
00086   } else
00087     return WTreeTableNode::expandable();
00088 }

WIconPair * FileTreeTableNode::createIcon ( const boost::filesystem::path &  path  )  [static, private]

Create the iconpair for representing the path.

Definition at line 52 of file FileTreeTableNode.C.

00053 {
00054   if (boost::filesystem::exists(path)
00055       && boost::filesystem::is_directory(path))
00056     return new WIconPair("icons/yellow-folder-closed.png",
00057                          "icons/yellow-folder-open.png", false);
00058   else
00059     return new WIconPair("icons/document.png",
00060                          "icons/yellow-folder-open.png", false);
00061 }


Member Data Documentation

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 Tue Nov 3 15:34:40 2009 for Wt by doxygen 1.5.6