9 #include <boost/algorithm/string/replace.hpp>
10 #include <boost/lexical_cast.hpp>
15 #include <Wt/WHBoxLayout>
16 #include <Wt/WVBoxLayout>
18 #include <Wt/WItemDelegate>
21 #include <gdcore/gdCore.h>
23 #include <gdwtcore/gdWTextDelegate.h>
53 : WTableView(parent), m_pModelView(0), m_bLogSearch(true), m_wNavBar(0)
56 if ( WString::tr(
"byObjectStyleSheet").narrow() ==
"true" )
57 wApp->useStyleSheet(wApp->theme()->resourcesUrl() +
"wittyshare/Css/WsSearchView.css");
58 parent->addStyleClass(
"WsSearchView");
61 wApp->messageResourceBundle().use(wApp->docRoot() + wApp->resourcesUrl() +
"wittyshare/Transl/WsSearchView");
63 m_pModelView->setHeaderData(0, WString::tr(
"WsSearchView-Name"));
64 m_pModelView->setHeaderData(1, WString::tr(
"WsSearchView-Desc"));
65 m_pModelView->setHeaderData(2, WString::tr(
"WsSearchView-Size"));
66 m_pModelView->setHeaderData(3, WString::tr(
"WsSearchView-Date"));
71 if ( !pRootNode.get() ) {
72 wApp->log(
"notice") <<
"WsSearchView::WsSearchView() : getAccessRoot() is null";
76 for (
int row = 0; row < vResSearch.size(); ++row) {
77 NodePtr pNode = pRootNode.get()->eatPath(vResSearch[row].getPath().
string());
79 wApp->log(
"notice") <<
"WsSearchView::WsSearchView() : Path = " <<
", getAccessRoot() eatPath is null";
82 if ( pNode.get()->isDirectory() )
continue;
83 if ( pNode.get()->getProperties().get()->get(
"global",
"in_view",
"true") !=
"true" )
continue;
85 std::string sName = vResSearch[row].getName(
true);
86 std::string sDesc = vResSearch[row].getBody();
87 long lSize = vResSearch[row].getSize();
88 time_t tTime = vResSearch[row].getModifyDate();
90 std::vector<std::string> searchWords;
91 gd_core_string2vector(searchWords, sSearch.c_str(),
" ");
92 for (
int iWord = 0; iWord < searchWords.size(); ++iWord) {
93 boost::algorithm::replace_all(sDesc,
"\u0002",
"<strong>");
94 boost::algorithm::replace_all(sDesc,
"\u0003",
"</strong>");
99 localtime_r(&tTime, &ttm);
100 strftime(c, 100,
"%Y-%m-%d", &ttm);
102 std::vector<WStandardItem*> pRow;
104 newItem->
setNode(&vResSearch[row]);
105 newItem->setData(vResSearch[row].getPath().
string(), UserRole);
106 newItem->setIcon(wApp->theme()->resourcesUrl() +
"gdwtcore/Icons/file.png");
107 pRow.push_back(newItem);
109 strDesc->
setNode(&vResSearch[row]);
110 strDesc->setData(sDesc, UserRole);
111 pRow.push_back(strDesc);
112 std::string strSize = boost::lexical_cast<std::string>(lSize);
114 colSize->setData(lSize, UserRole);
115 pRow.push_back(colSize);
117 colDate->setData(strDate, UserRole);
118 pRow.push_back(colDate);
123 setColumnResizeEnabled(
true);
124 setSortingEnabled(
true);
125 setAlternatingRowColors(
true);
126 setSelectionMode(ExtendedSelection);
127 setColumnAlignment(2, AlignRight);
129 setColumnWidth(0, 300);
130 setColumnWidth(1, 470);
131 setColumnWidth(2, 80);
132 setColumnWidth(3, 80);
133 setHeight((rowHeight() * 50));
134 WItemDelegate* delegate =
new WItemDelegate(parent);
135 delegate->setTextFormat(
"%s");
136 setItemDelegate(delegate);
137 gdWTextDelegate* delegate2 =
new gdWTextDelegate(parent);
138 delegate2->setRowHeight(rowHeight().value() - 2);
139 setItemDelegateForColumn(1, delegate2);
160 if ( idx.column() != 0 ) {
161 if ( idx.parent().isValid() )
162 idxcol0 = idx.parent().child(idx.row(), 0);
164 idxcol0 = idx.child(idx.row(), 0);
167 if ( !idxcol0.isValid() )
return;
168 std::string str = asString(idxcol0.data(UserRole)).toUTF8();
169 wApp->setInternalPath(str,
true);
174 WModelIndexSet pSet = selectedIndexes();
175 WModelIndexSet::iterator it = pSet.begin();
176 if ( pSet.empty() )
return;
177 WModelIndex idx = *it;
178 std::string str = asString(idx.data(UserRole)).toUTF8();
179 wApp->setInternalPath(str,
true);
Wt::WStandardItemModel * m_pModelView
boost::shared_ptr< WsAbstractNode > NodePtr
void setNode(WsAbstractNode *pNode)
Contains Abstract metods on nodes and variables.
std::vector< WsResultItem > getSearchResults(const std::string &terms)
search for all matching results of terms using WsSearch class
Interface that provides differents methods for accessing the FsTree as well as other features...
void onViewSelectionChanged()
void onViewDblClick(Wt::WModelIndex, Wt::WMouseEvent)
WsSearchView(std::string sSearch, Wt::WContainerWidget *parent=0)
const std::string getRootPath()
return the root path of the filesystem tree, example : /var/www/demo_site
#define WsApp
Define a shortcut to the application instance.
static WsLayoutProperties * instance()
Get the singleton instance.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root