Wt examples 3.1.10
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
FileTreeTableNode Class Reference

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.

  : WTreeTableNode(Wt::widen(path.leaf()), createIcon(path)),
#else
  : WTreeTableNode(path.leaf(), createIcon(path)),
#endif
#else
  : WTreeTableNode(path.leaf().string(), createIcon(path)),
#endif
    path_(path)
{
  label()->setTextFormat(PlainText);

  if (boost::filesystem::exists(path)) {
    if (!boost::filesystem::is_directory(path)) {
      int fsize = (int)boost::filesystem::file_size(path);
      setColumnWidget(1, new WText(boost::lexical_cast<std::string>(fsize)));
      columnWidget(1)->setStyleClass("fsize");
    } else
      setSelectable(false);

    std::time_t t = boost::filesystem::last_write_time(path);
    struct tm ttm;
#if WIN32
    ttm=*localtime(&t);
#else
    localtime_r(&t, &ttm);
#endif

    char c[100];
    strftime(c, 100, "%b %d %Y", &ttm);

    setColumnWidget(2, new WText(c));
    columnWidget(2)->setStyleClass("date");
  }
}

Member Function Documentation

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

Create the iconpair for representing the path.

Definition at line 60 of file FileTreeTableNode.C.

{
  if (boost::filesystem::exists(path)
      && boost::filesystem::is_directory(path))
    return new WIconPair("icons/yellow-folder-closed.png",
                         "icons/yellow-folder-open.png", false);
  else
    return new WIconPair("icons/document.png",
                         "icons/yellow-folder-open.png", false);
}
bool FileTreeTableNode::expandable ( ) [private, virtual]

Reimplements WTreeNode::expandable.

Reimplemented from Wt::WTreeNode.

Definition at line 90 of file FileTreeTableNode.C.

{
  if (!populated()) {
    return boost::filesystem::is_directory(path_);
  } else
    return WTreeTableNode::expandable();
}
void FileTreeTableNode::populate ( ) [private, virtual]

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

Reimplemented from Wt::WTreeNode.

Definition at line 71 of file FileTreeTableNode.C.

{
  try {
    if (boost::filesystem::is_directory(path_)) {
      std::set<boost::filesystem::path> paths;
      boost::filesystem::directory_iterator end_itr;

      for (boost::filesystem::directory_iterator i(path_); i != end_itr; ++i)
        paths.insert(*i);

      for (std::set<boost::filesystem::path>::iterator i = paths.begin();
           i != paths.end(); ++i)
        addChildNode(new FileTreeTableNode(*i));
    }
  } catch (boost::filesystem::filesystem_error& e) {
    std::cerr << e.what() << std::endl;
  }
}

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 Mon Nov 14 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.4