/usr/lib/Wt/examples/filetreetable/FileTreeTableNode.C is in witty-examples 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include "FileTreeTableNode.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <time.h>
#include <Wt/WIconPair>
#include <Wt/WStringUtil>
#include <Wt/WText>
using namespace Wt;
FileTreeTableNode::FileTreeTableNode(const boost::filesystem::path& path)
#if BOOST_FILESYSTEM_VERSION < 3
#ifndef WT_NO_STD_WSTRING
: 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");
}
}
WIconPair *FileTreeTableNode::createIcon(const boost::filesystem::path& path)
{
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);
}
void FileTreeTableNode::populate()
{
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;
}
}
bool FileTreeTableNode::expandable()
{
if (!populated()) {
return boost::filesystem::is_directory(path_);
} else
return WTreeTableNode::expandable();
}
|