13 #include <boost/filesystem.hpp>
23 #include <Wt/WDateTime>
24 #include <Wt/WStandardItemModel>
27 #include <gdcore/gdCore.h>
29 #include <gdwtcore/gdWTextDelegate.h>
36 #include <WsModule/WsModule.h>
45 void* hndl = dlopen(
"libwt.so", RTLD_NOW | RTLD_GLOBAL);
47 fprintf(stderr,
"cannot load wt.so shared library! %s\n", dlerror());
77 addStyleClass(
"WsDirectoryView2");
87 WStandardItemModel* pModelView =
new WStandardItemModel(0, 4,
this);
88 pModelView->setHeaderData(0, WString::tr(
"WsDirectoryView2-Name"));
89 pModelView->setHeaderData(1, WString::tr(
"WsDirectoryView2-Desc"));
90 pModelView->setHeaderData(2, WString::tr(
"WsDirectoryView2-Size"));
91 pModelView->setHeaderData(3, WString::tr(
"WsDirectoryView2-Date"));
92 pModelView->setSortRole(UserRole);
94 std::string path = asString(
option(
"rootPath")).narrow();
95 if ( path.size() < 1 )
97 std::string sWithoutPrefix =
WsApp->WsModules().pathWithoutPrefix(path);
100 if (!accessTree.get()) {
101 wApp->log(
"error") <<
"WsDirectoryView2::load() : accessTree is NULL";
104 NodePtr tmp = accessTree.get()->eatPath(path);
106 wApp->log(
"error") <<
"WsDirectoryView2::load() : eatPath returned null";
109 std::vector<NodePtr> vDirContent = tmp.get()->getAll();
110 int rc = vDirContent.size();
111 long rowsCount = asNumber(
option(
"rowsCount"));
112 if ( rowsCount != -1 ) rc = rowsCount;
113 for (
int row = 0; row < rc; ++row) {
114 std::string sName = vDirContent[row].get()->getName();
115 std::string sDesc = vDirContent[row].get()->getProperties().get()->get(
"global",
"short_description",
"");
116 uintmax_t lSize = vDirContent[row].get()->getSize();
117 time_t tTime = vDirContent[row].get()->getModifyDate();
121 localtime_r(&tTime, &ttm);
122 strftime(c, 100,
"%Y-%m-%d", &ttm);
124 std::vector<WStandardItem*> pRow;
126 newItem->
setNode(vDirContent[row]);
127 if ( vDirContent[row].
get()->isDirectory() ) {
128 newItem->setData(
"1" + vDirContent[row].
get()->getPath().
string(), UserRole);
129 newItem->setIcon(wApp->theme()->resourcesUrl() +
"gdwtcore/Icons/folder.png");
131 newItem->setData(
"2" + vDirContent[row].
get()->getPath().
string(), UserRole);
132 newItem->setIcon(wApp->theme()->resourcesUrl() +
"gdwtcore/Icons/file.png");
134 pRow.push_back(newItem);
136 strDesc->
setNode(vDirContent[row]);
137 strDesc->setData(sDesc, UserRole);
138 pRow.push_back(strDesc);
139 std::string strSize = boost::lexical_cast<std::string>(lSize);
141 colSize->setData(lSize, UserRole);
142 pRow.push_back(colSize);
144 colDate->setData(strDate, UserRole);
145 pRow.push_back(colDate);
146 pModelView->invisibleRootItem()->appendRow(pRow);
148 setModel(pModelView);
149 setColumnResizeEnabled(
true);
150 setSortingEnabled(
true);
151 setAlternatingRowColors(
true);
152 setSelectionMode(ExtendedSelection);
153 setColumnAlignment(2, AlignRight);
154 setColumnAlignment(3, AlignRight);
155 long lRowHeight = asNumber(
option(
"lRowHeight"));
156 if ( lRowHeight < 0 )
159 setRowHeight(lRowHeight);
160 if ( asString(
option(
"hideHeader")).narrow() ==
"true" )
162 std::string columnsWidth = asString(
option(
"columnsWidth")).narrow();
163 if ( columnsWidth.size() < 1 ) {
164 setColumnWidth(0, 180);
165 setColumnWidth(1, 300);
167 std::vector<std::string> sVectColumnsWidth;
168 gd_core_string2vector(sVectColumnsWidth, columnsWidth.c_str(),
",");
169 for (
int iCol = 0; iCol < sVectColumnsWidth.size(); ++iCol) {
170 double width = asNumber(sVectColumnsWidth[iCol]);
172 setColumnWidth(iCol, width);
175 std::string columnsToHide = asString(
option(
"hideColumns")).narrow();
176 std::vector<std::string> sVectColumnsToHide;
177 gd_core_string2vector(sVectColumnsToHide, columnsToHide.c_str(),
",");
178 for (
int iCol = 0; iCol < sVectColumnsToHide.size(); ++iCol) {
179 int col = asNumber(sVectColumnsToHide[iCol]);
180 setColumnHidden(col,
true);
182 gdWTextDelegate* delegate2 =
new gdWTextDelegate(
this);
183 delegate2->setRowHeight(rowHeight().value() - 2);
184 setItemDelegateForColumn(1, delegate2);
191 WModelIndexSet pSet = selectedIndexes();
192 WModelIndexSet::iterator it = pSet.begin();
193 if ( pSet.empty() )
return;
194 WModelIndex idx = *it;
195 std::string str = asString(idx.data(UserRole)).toUTF8();
197 boost::algorithm::replace_first(str,
"1",
"");
199 boost::algorithm::replace_first(str,
"2",
"");
200 wApp->setInternalPath(str,
true);
214 wApp->messageResourceBundle().use(wApp->docRoot() + wApp->resourcesUrl() +
"WsModDirectoryView2/Transl/WsModDirectoryView2");
245 return "WsModDirectoryView2 wittyShare module";
boost::shared_ptr< WsAbstractNode > NodePtr
static WsApplication * wsInstance()
Facility function to access the application object.
void setNode(NodePtr pNode)
const std::vector< WsOption > & options() const
Get all options.
void onViewSelectionChanged()
Interface that provides differents methods for accessing the FsTree as well as other features...
WsEditorWidget * createEditor(Wt::WContainerWidget *parent=0) const
Create the contents for an editor (create a view of options).
const boost::any & option(const std::string &attribute) const
Get an options value.
#define WsApp
Define a shortcut to the application instance.
WsDirectoryView2(Wt::WContainerWidget *parent=0)
Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const
Create the contents.
Wt::WWidget * createAdmin(Wt::WContainerWidget *parent=0) const
Create the contents for an administrator.
void setOptions(const std::vector< WsOption > &vOptions)
Set all options.
Wt::WWidget * createContentsMenuBar(Wt::WContainerWidget *parent=0) const
Create the functionalities.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
std::string description() const
Return the description of the module.
void WsModDirectoryView2Init(void)