Wt examples 3.3.12
FileTreeTableNode.C
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7
8#include "FileTreeTableNode.h"
9
10#include <boost/filesystem/operations.hpp>
11#include <boost/filesystem/exception.hpp>
12#include <boost/lexical_cast.hpp>
13#include <iostream>
14#include <time.h>
15
16#include <Wt/WIconPair>
17#include <Wt/WStringUtil>
18#include <Wt/WText>
19
20using namespace Wt;
21
22FileTreeTableNode::FileTreeTableNode(const boost::filesystem::path& path)
23#if BOOST_FILESYSTEM_VERSION < 3
24#ifndef WT_NO_STD_WSTRING
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}
59
60WIconPair *FileTreeTableNode::createIcon(const boost::filesystem::path& path)
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}
70
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 {
88 } catch (boost::filesystem::filesystem_error& e) {
89 std::cerr << e.what() << std::endl;
90 }
91 }
92}
93
95{
96 if (!populated()) {
97 return boost::filesystem::is_directory(path_);
98 } else
99 return WTreeTableNode::expandable();
100}
A single node in a file tree table.
boost::filesystem::path path_
The path.
virtual void populate()
Reimplements WTreeNode::populate to read files within a directory.
virtual bool expandable()
Reimplements WTreeNode::expandable.
static Wt::WIconPair * createIcon(const boost::filesystem::path &path)
Create the iconpair for representing the path.
FileTreeTableNode(const boost::filesystem::path &path)
Construct a new node for the given file.
bool populated() const
void addChildNode(WTreeNode *node)
PlainText

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8