13 #include <boost/algorithm/string/replace.hpp>
14 #include <boost/lexical_cast.hpp>
15 #include <boost/filesystem/operations.hpp>
16 #include <boost/filesystem/exception.hpp>
18 #include <gdcore/gdCore.h>
22 #include <Wt/WBoostAny>
26 #include <gdcore/gdImage.h>
36 : WAnchor(link, text, parent), m_nImageIndex(0)
63 : WContainerWidget(parent), m_bDebug(false), m_lDelay(5000), m_nCurrentImage(0), m_pTimer(0), m_bLoaded(false), m_bOnLoad(false)
65 if ( WString::tr(
"byObjectStyleSheet").narrow() ==
"true" )
66 wApp->useStyleSheet(wApp->theme()->resourcesUrl() +
"wittyshare/Css/WsImages2.css");
67 addStyleClass(
"WsImages2Widget");
80 WContainerWidget::load();
98 long lDelay = asNumber(
option(
"image_delay"));
101 if ( asString(
option(
"reactWhenPathChange")) ==
"false" )
103 std::string sImagesPath = asString(
option(
"imagesPath")).toUTF8();
104 if ( sImagesPath.size() < 1 )
105 sImagesPath = wApp->theme()->resourcesUrl() +
"wittyshare/Images/WsImages2";
106 if ( boost::filesystem::is_directory(
WsApp->docRoot() + sImagesPath) ) {
107 boost::filesystem::directory_iterator end_itr;
109 for (boost::filesystem::directory_iterator itr_dir(
WsApp->docRoot() + sImagesPath); itr_dir != end_itr; ++itr_dir) {
110 if ( ! ( itr_dir->path().extension() ==
".jpeg"
111 || itr_dir->path().extension() ==
".jpg"
112 || itr_dir->path().extension() ==
".png"
114 if ( gdcore_isPathHidden(itr_dir->path()) )
continue;
115 if ( gdcore_isPathSymLink(itr_dir->path()) )
continue;
116 if ( boost::filesystem::is_directory(itr_dir->status()) )
continue;
117 boost::filesystem::path newPath = itr_dir->path();
120 }
catch (boost::filesystem::filesystem_error& e) {
121 wApp->log(
"ERROR") <<
"WsImages2::build() bad image path =" << sImagesPath <<
" error = " << e.what();
131 std::string sLinkType;
133 std::string sShortDescription;
135 urlFile.replace_extension(
".url");
136 if ( boost::filesystem::exists(urlFile) ) {
137 std::ifstream f(urlFile.string().c_str());
140 while ( std::getline(f, sLine) ) {
141 if ( sLine.compare(0, 5,
"link=") == 0 ) sLink = sLine;
142 if ( sLine.compare(0, 9,
"linkType=") == 0 ) sLinkType = sLine;
143 if ( sLine.compare(0, 6,
"title=") == 0 ) sTitle = sLine;
144 if ( sLine.compare(0, 17,
"shortDescription=") == 0 ) sShortDescription = sLine;
146 boost::algorithm::replace_all(sLink,
"link=",
"");
147 boost::algorithm::replace_all(sLinkType,
"linkType=",
"");
148 boost::algorithm::replace_all(sTitle,
"title=",
"");
149 boost::algorithm::replace_all(sShortDescription,
"shortDescription=",
"");
154 wApp->log(
"notice") <<
"WsImages2::build() url image = " << sLink;
156 if ( sShortDescription.size() < 1 )
157 if ( sLink.size() > 0 ) {
161 sShortDescription = pNode.get()->getProperties().get()->get(
"global",
"short_description",
"");
162 if ( sTitle.size() < 1 )
163 sTitle = pNode.get()->getDisplayName(
true);
195 WApplication::instance()->log(
"notice") <<
"WsImages2::loadImage() : no images !";
200 if ( asString(
option(
"useImageTitle")) ==
"true" ) {
202 if ( curImgTitle.size() > 0 ) {
203 boost::algorithm::replace_all(curImgTitle,
"&",
"&");
204 WText* pTextTitle =
new WText(curImgTitle);
205 pTextTitle->addStyleClass(
"WsImage2Title");
206 addWidget(pTextTitle);
209 WContainerWidget* cwImg =
new WContainerWidget();
210 cwImg->addStyleClass(
"WsImages2");
212 WContainerWidget* cw =
new WContainerWidget();
213 cw->addStyleClass(
"countImages");
214 for (
int countImage = 0; countImage <
m_sImagesVect.size(); ++countImage) {
216 if ( asString(
option(
"setImagesCount")) !=
"true" )
219 pAnchor =
new wsi2Anchor(WLink(), asString(countImage + 1));
223 pAnchor->addStyleClass(
"selected");
224 cw->addWidget(pAnchor);
226 cwImg->addWidget(cw);
229 gdImageProperties imgProp = gdImage_size(curImgUrl);
230 boost::algorithm::replace_first(curImgUrl, wApp->docRoot(),
"");
231 WLink myLink(WLink::Url, curImgUrl);
232 if ( asString(
option(
"imageInBackground")) ==
"true" ) {
233 cwImg->decorationStyle().setBackgroundImage(myLink, Wt::WCssDecorationStyle::NoRepeat);
234 if ( asString(
option(
"textWidget")) ==
"true" ) {
236 WText* textImage =
new WText(
m_sImagesText[m_nCurrentImage]);
237 textImage->addStyleClass(
"WsImages2Text");
239 boost::filesystem::path pUrl(
m_sImagesLink[m_nCurrentImage]);
240 if ( pUrl.extension() !=
".nolink" ) {
241 textImage->addStyleClass(
"WsClickable");
245 cwImg->addWidget(textImage);
249 WImage* pImage =
new WImage();
250 pImage->setImageLink(myLink);
251 cwImg->addWidget(pImage);
253 if ( asString(
option(
"plusWidget")) ==
"true" ) {
255 WAnchor* pA =
new WAnchor(WLink(WLink::InternalPath, curImgUrl2),
"+");
256 pA->addStyleClass(
"WsPlusWidget");
257 cwImg->addWidget(pA);
259 cwImg->resize(WLength(imgProp.width, WLength::Pixel), WLength(imgProp.height, WLength::Pixel));
std::vector< std::string > m_sImagesVect
boost::shared_ptr< WsAbstractNode > NodePtr
void loadImage()
Load the image with the current index.
void setImageIndex(int imageIndex)
void build()
Build the vector.
virtual void load()
Load the widget (traditional wt virtual function).
WsImages2(Wt::WContainerWidget *parent=0)
CTor.
Wt::Signal< int > & imageSelected()
wsi2Anchor(const Wt::WLink &link, const Wt::WString &text, Wt::WContainerWidget *parent=0)
Interface that provides differents methods for accessing the FsTree as well as other features...
int count()
Return the number of images.
std::vector< std::string > m_sImagesTitle
void doClicked(Wt::WMouseEvent mEv)
void doCounterClicked(int index)
const boost::any & option(const std::string &attribute) const
Get an options value.
std::vector< std::string > m_sImagesLink
std::vector< std::string > m_sImagesText
#define WsApp
Define a shortcut to the application instance.
bool m_bReactWhenPathChange
const std::string & text()
Return the text of the current image.
NodePtr getAccessRoot()
return the root node of the access tree starting from the root
Wt::Signal< int > m_sigImageSelected
std::vector< std::string > m_sImagesLinkType
a wittyShare class that render images randomly