10 #include <boost/lexical_cast.hpp>
11 #include <boost/tokenizer.hpp>
12 #include <boost/algorithm/string.hpp>
15 #include <Wt/WApplication>
16 #include <Wt/WEnvironment>
19 #include <Wt/WPushButton>
20 #include <Wt/WStackedWidget>
21 #include <Wt/WTabWidget>
23 #include <Wt/WTableCell>
24 #include <Wt/WTemplate>
26 #include <Wt/WViewWidget>
27 #include <Wt/WVBoxLayout>
30 #include "view/BlogView.h"
39 Wt::Dbo::SqlConnectionPool& blogDb,
40 const std::string& title,
const std::string& resourceBundle,
41 const std::string& cssPath)
48 messageResourceBundle().use(appRoot() + resourceBundle,
false);
50 useStyleSheet(cssPath +
"/wt.css");
51 useStyleSheet(cssPath +
"/wt_ie.css",
"lt IE 7",
"all");
52 useStyleSheet(
"css/home.css");
53 useStyleSheet(
"css/sourceview.css");
54 useStyleSheet(
"css/chatwidget.css");
55 useStyleSheet(
"css/chatwidget_ie6.css",
"lt IE 7",
"all");
83 std::string base = internalPathNextPart(
"/");
93 WVBoxLayout *layout =
new WVBoxLayout();
94 layout->setContentsMargins(0, 0, 0, 0);
96 root()->setLayout(layout);
115 WTemplate *result =
new WTemplate(
tr(
"template"), root());
118 WContainerWidget *languagesDiv =
new WContainerWidget();
119 languagesDiv->setId(
"top_languages");
121 for (
unsigned i = 0; i <
languages.size(); ++i) {
123 new WText(
"- ", languagesDiv);
127 new WAnchor(WLink(WLink::InternalPath, l.
path_),
131 WStackedWidget *contents =
new WStackedWidget();
132 WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250);
133 contents->setTransitionAnimation(fade);
134 contents->setId(
"main_page");
136 mainMenu_ =
new WMenu(contents, Vertical);
149 WMenuItem::PreLoading);
153 WMenuItem::PreLoading)->setPathComponent(
"examples/");
157 WMenuItem::PreLoading);
164 WMenuItem::PreLoading);
175 result->bindWidget(
"languages", languagesDiv);
177 result->bindWidget(
"contents", contents);
188 std::string langPath = l.
path_;
189 mainMenu_->setInternalBasePath(langPath);
191 BlogView *
blog =
dynamic_cast<BlogView *
>(findWidget(
"blog"));
193 blog->setInternalBasePath(langPath +
"blog/");
208 WText *a =
new WText(
tr(
"source-browser-link").arg(path));
209 a->setInternalPathEncoding(
true);
215 std::string langPath = internalPathNextPart(
"/");
217 if (langPath.empty())
220 langPath =
'/' + langPath +
'/';
224 for (
unsigned i = 0; i <
languages.size(); ++i) {
238 setTitle(
tr(
"wt") +
" - " +
mainMenu_->currentItem()->text());
248 if (path.size() >= 4 && path.substr(0, 4) ==
"/src") {
255 return new WText(
tr(
"home.intro"));
261 std::string langPath = l.
path_;
262 BlogView *
blog =
new BlogView(langPath +
"blog/",
264 blog->setObjectName(
"blog");
266 if (!
blog->user().empty())
276 WApplication::instance()->doJavaScript
277 (
"if (window.chat && window.chat.emit) {"
279 "" "window.chat.emit(window.chat, 'login', "
280 "" "" + userName.jsStringLiteral() +
"); "
282 "" "window.chatUser=" + userName.jsStringLiteral() +
";"
285 """window.chatUser=" + userName.jsStringLiteral() +
";");
290 return new WText(
tr(
"home.status"));
295 return new WText(
tr(
"home.features"));
300 WText *result =
new WText(
tr(
"home.documentation"));
301 result->setInternalPathEncoding(
true);
307 return new WText(
tr(
"home.other-language"));
312 return makeStaticModel(boost::bind(
createWidget,
this));
315 std::string
Home::href(
const std::string& url,
const std::string& description)
317 return "<a href=\"" + url +
"\" target=\"_blank\">" + description +
"</a>";
322 return new WText(
tr(
"home.community"));
327 std::ifstream f((
filePrefix() +
"releases.txt").c_str());
329 releaseTable->clear();
331 releaseTable->elementAt(0, 0)
332 ->addWidget(
new WText(
tr(
"home.download.version")));
333 releaseTable->elementAt(0, 1)
334 ->addWidget(
new WText(
tr(
"home.download.date")));
335 releaseTable->elementAt(0, 2)
336 ->addWidget(
new WText(
tr(
"home.download.description")));
338 releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx),
340 releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx),
350 typedef boost::tokenizer<boost::escaped_list_separator<char> >
352 CsvTokenizer tok(line);
354 CsvTokenizer::iterator i=tok.begin();
356 std::string fileName = *i;
357 std::string description = *(++i);
358 releaseTable->elementAt(row, 1)->addWidget(
new WText(*(++i)));
359 releaseTable->elementAt(row, 2)->addWidget(
new WText(*(++i)));
362 std::string url =
"http://prdownloads.sourceforge.net/witty/"
363 + fileName +
"?download";
367 releaseTable->elementAt(row, 0)->addWidget
368 (
new WText(
href(url, description)));
375 #ifdef WT_EMWEB_BUILD
378 WContainerWidget *result =
new WContainerWidget();
379 result->setStyleClass(
"quote");
381 WTemplate *requestTemplate =
new WTemplate(
tr(
"quote.request"), result);
383 WPushButton *quoteButton =
new WPushButton(
tr(
"quote.requestbutton"));
384 requestTemplate->bindWidget(
"button", quoteButton);
389 quoteButton->clicked().connect(
quoteForm, &WWidget::show);
390 quoteButton->clicked().connect(requestTemplate, &WWidget::hide);
396 #endif // WT_EMWEB_BUILD
400 WContainerWidget *result =
new WContainerWidget();
401 result->addWidget(
new WText(
tr(
"home.download")));
403 result->addWidget(
new WText(
tr(
"home.download.license")));
405 #ifdef WT_EMWEB_BUILD
407 #endif // WT_EMWEB_BUILD
409 result->addWidget(
new WText(
tr(
"home.download.packages")));
415 result->addWidget(
new WText(
tr(
"home.download.other")));
423 return WString::tr(key);
428 doJavaScript(
"if (window.ga) ga('send','pageview',"
429 + WWebWidget::jsStringLiteral(environment().deploymentPath()
430 + internalPath()) +
");");