#include <FileTreeTableNode.h>
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::WIconPair * | createIcon (const boost::filesystem::path &path) |
Create the iconpair for representing the path. | |
Private Attributes | |
boost::filesystem::path | path_ |
The path. |
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.
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()->setFormatting(WText::PlainFormatting); 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(false, 00032 boost::lexical_cast<std::wstring>(fsize))); 00033 columnWidget(1)->setStyleClass("fsize"); 00034 } else 00035 setSelectable(false); 00036 00037 std::time_t t = boost::filesystem::last_write_time(path); 00038 struct tm ttm; 00039 #if WIN32 00040 ttm=*localtime(&t); 00041 #else 00042 localtime_r(&t, &ttm); 00043 #endif 00044 00045 char c[100]; 00046 strftime(c, 100, "%b %d %Y", &ttm); 00047 00048 setColumnWidget(2, new WText(c)); 00049 columnWidget(2)->setStyleClass("date"); 00050 } 00051 }
void FileTreeTableNode::populate | ( | ) | [private, virtual] |
Reimplements WTreeNode::populate to read files within a directory.
Reimplemented from Wt::WTreeNode.
Definition at line 64 of file FileTreeTableNode.C.
00065 { 00066 try { 00067 if (boost::filesystem::is_directory(path_)) { 00068 std::set<boost::filesystem::path> paths; 00069 boost::filesystem::directory_iterator end_itr; 00070 00071 for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i) 00072 paths.insert(*i); 00073 00074 for (std::set<boost::filesystem::path>::iterator i = paths.begin(); 00075 i != paths.end(); ++i) 00076 addChildNode(new FileTreeTableNode(*i)); 00077 } 00078 } catch (boost::filesystem::filesystem_error& e) { 00079 std::cerr << e.what() << std::endl; 00080 } 00081 }
bool FileTreeTableNode::expandable | ( | ) | [private, virtual] |
Reimplements WTreeNode::expandable.
Reimplemented from Wt::WTreeNode.
Definition at line 83 of file FileTreeTableNode.C.
00084 { 00085 if (!populated()) { 00086 return boost::filesystem::is_directory(path_); 00087 } else 00088 return WTreeTableNode::expandable(); 00089 }
WIconPair * FileTreeTableNode::createIcon | ( | const boost::filesystem::path & | path | ) | [static, private] |
Create the iconpair for representing the path.
Definition at line 53 of file FileTreeTableNode.C.
00054 { 00055 if (boost::filesystem::exists(path) 00056 && boost::filesystem::is_directory(path)) 00057 return new WIconPair("icons/yellow-folder-closed.png", 00058 "icons/yellow-folder-open.png", false); 00059 else 00060 return new WIconPair("icons/document.png", 00061 "icons/yellow-folder-open.png", false); 00062 }