11#include <Wt/WApplication.h>
12#include <Wt/WContainerWidget.h>
13#include <Wt/WEnvironment.h>
14#include <Wt/WLineEdit.h>
15#include <Wt/WGridLayout.h>
16#include <Wt/WHBoxLayout.h>
17#include <Wt/WPushButton.h>
20#include <Wt/WTreeView.h>
21#include <Wt/WVBoxLayout.h>
22#include <Wt/WViewWidget.h>
24#include <boost/filesystem/operations.hpp>
25#include <boost/filesystem/exception.hpp>
26#include <boost/filesystem/convenience.hpp>
27#include <boost/algorithm/string.hpp>
32namespace fs = boost::filesystem;
37#if BOOST_FILESYSTEM_VERSION < 3
38 return p.empty() ? std::string() : *--
p.end();
40 return p.empty() ? std::string() : (*--
p.end()).
string();
45static std::string
stem(
const fs::path&
p)
48 std::size_t
pos =
fn.find(
'.');
49 if (
pos == std::string::npos)
52 return fn.substr(0,
pos);
60 std::string
path =
p.string();
62 return path.substr(0,
path.length() -
fn.length() - 1);
77 wApp->internalPathChanged().connect
90 if (example.find(
"..") != std::string::npos
91 || example.find(
'/') != std::string::npos
92 || example.find(
'\\') != std::string::npos) {
93 app->setInternalPathValid(
false);
101 const std::string& example)
108 }
catch (std::exception&) {
112 WApplication::instance()->setInternalPathValid(
false);
113 addWidget(std::make_unique<WText>(
"No such example: " +
exampleDir));
117 model_ = std::make_shared<WStandardItemModel>(0, 1);
124 WApplication::instance()->setTitle(tr(
"srcview.title." + example));
125 std::unique_ptr<WText>
title(std::make_unique<WText>(
127 title->setInternalPathEncoding(
true);
151 WStandardItem *
w =
model_->item(0);
154 if (
w->rowCount() > 0)
162 auto topLayout = std::make_unique<WVBoxLayout>();
165 auto gitLayout = std::make_unique<WHBoxLayout>();
187 std::string
ext = fs::extension(
path);
191 else if (
ext ==
".C" ||
ext ==
".cpp")
198 const fs::path&
path)
201 ".C",
".cpp",
".h",
".css",
".xml",
".png",
".gif",
".csv",
".ico", 0
204 auto dir = std::make_unique<FileItem>(
"/icons/yellow-folder-open.png",
208 parent->appendRow(std::move(
dir));
211 std::set<fs::path>
paths;
213 fs::directory_iterator
end_itr;
218 std::vector<fs::path>
dirs;
220 while (!
paths.empty()) {
221 fs::path
p = *
paths.begin();
225 if (fs::is_symlink(
p))
229 if (fs::is_regular(
p)) {
230 std::string
ext = fs::extension(
p);
253 std::make_unique<FileItem>(
"/icons/cppclass.png",
label, std::string());
257 = std::make_unique<FileItem>(
"/icons/document.png",
filename(
p),
260 = std::make_unique<FileItem>(
"/icons/document.png",
262 (*it_companion).string());
270 = std::make_unique<FileItem>(
"/icons/document.png",
filename(
p),
274 }
else if (fs::is_directory(
p)) {
278 = std::make_unique<FileItem>(
"/icons/document.png",
filename(
p),
286 for (
unsigned int i = 0;
i <
classes.size();
i++)
287 parent->appendRow(std::move(
classes[
i]));
289 for (
unsigned int i = 0;
i <
files.size();
i++)
290 parent->appendRow(std::move(
files[
i]));
292 for (
unsigned int i = 0;
i <
dirs.size();
i++)
294 }
catch (fs::filesystem_error&
e) {
295 std::cerr <<
e.what() << std::endl;
303 fs::directory_iterator
end_itr;
308 if (fs::is_regular(
p)) {
310 auto item = std::make_unique<FileItem>(
"/icons/package.png",
packageName,
"");
312 parent->appendRow(std::move(item));
316 = std::make_unique<FileItem>(
"/icons/javaclass.png",
filename(
p),
324 if (fs::is_directory(
p)) {
336 const fs::path&
path)
339 = std::make_unique<FileItem>(
"/icons/yellow-folder-open.png",
342 parent->appendRow(std::move(
dir));
347 fs::directory_iterator
end_itr;
350 if (fs::is_directory(
p)) {
353 = std::make_unique<FileItem>(
"/icons/package-folder-open.png",
356 parent->appendRow(std::move(
dir));
368 for (
auto item :
dirs)
371 for (
auto item :
files) {
373 = std::make_unique<FileItem>(
"/icons/document.png",
filename(item),
375 parent->appendRow(std::move(
file));
static fs::path getCompanion(const fs::path &path)
static std::string stem(const fs::path &p)
static std::string filename(const fs::path &p)
static bool comparePaths(const fs::path &p1, const fs::path &p2)
fs::path parent_path(const fs::path &p)
Wt::Auth::Dbo::UserDatabase< AuthInfo > UserDatabase
void cppTraverseDir(WStandardItem *parent, const boost::filesystem::path &path)
void setExample(const std::string &exampleDir, const std::string &example)
std::shared_ptr< WStandardItemModel > model_
ExampleSourceViewer(const std::string &deployPath, const std::string &examplesRoot, const std::string &examplesType)
Constructor.
void javaTraversePackages(WStandardItem *parent, const boost::filesystem::path &srcPath, const std::string packageName)
std::string examplesType_
std::string examplesRoot_
void showFile()
Displayed the currently selected file.
void javaTraverseDir(WStandardItem *parent, const boost::filesystem::path &path)
WStandardItem which stores a file.
static const Wt::ItemDataRole FileNameRole
static const Wt::ItemDataRole FilePathRole
static const Wt::ItemDataRole ContentsRole
bool setIndex(const WModelIndex &index)
Sets the model index.