Wt examples: Home Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Home Class Referenceabstract

`#include <Home.h>`

Inheritance diagram for Home:
[legend]

## Public Member Functions
| Home (const WEnvironment &env, Dbo::SqlConnectionPool &blogDb, const std::string &title, const std::string &resourceBundle, const std::string &cssPath)
virtual | ~Home ()
void | googleAnalyticsLogger ()

## Protected Member Functions
virtual std::unique_ptr< WWidget > | examples ()=0
virtual std::unique_ptr< WWidget > | createQuoteForm ()=0
virtual std::unique_ptr< WWidget > | sourceViewer (const std::string &deployPath)=0
virtual std::string | filePrefix () const =0
void | init ()
void | addLanguage (const Lang &l)
std::unique_ptr< WWidget > | linkSourceBrowser (const std::string &examplePath)
WString | tr (const char *key)
std::string | href (const std::string &url, const std::string &description)
void | readReleases (WTable *releaseTable)

## Protected Attributes
WTabWidget * | examplesMenu_
WTable * | releases_

## Private Member Functions
void | createHome ()
std::unique_ptr< WWidget > | introduction ()
std::unique_ptr< WWidget > | blog ()
std::unique_ptr< WWidget > | status ()
std::unique_ptr< WWidget > | features ()
std::unique_ptr< WWidget > | documentation ()
std::unique_ptr< WWidget > | community ()
std::unique_ptr< WWidget > | otherLanguage ()
std::unique_ptr< WWidget > | download ()
std::unique_ptr< WWidget > | quoteForm ()
void | readNews (WTable *newsTable, const std::string &newsfile)
std::unique_ptr< WWidget > | wrapView (std::unique_ptr< WWidget >(Home::*createFunction)())
void | updateTitle ()
void | setLanguage (int language)
void | setLanguageFromPath ()
void | setup ()
void | logInternalPath (const std::string &path)
void | chatSetUser (const WString &name)

## Private Attributes
Dbo::SqlConnectionPool & | blogDb_
WWidget * | homePage_
WWidget * | sourceViewer_
WStackedWidget * | contents_
WMenu * | mainMenu_
int | language_
std::unique_ptr< WContainerWidget > | sideBarContent_
std::vector< Lang > | languages

## Detailed Description

Definition at line 67 of file Home.h.

## Constructor & Destructor Documentation

## ◆ Home()

Home::Home | ( | const WEnvironment & | env,
|  | Dbo::SqlConnectionPool & | blogDb,
|  | const std::string & | title,
|  | const std::string & | resourceBundle,
|  | const std::string & | cssPath )

Definition at line 40 of file Home.C.

44 : WApplication(env),
45 blogDb_(blogDb),
46 homePage_(0),
47 sourceViewer_(0)
48{
49 messageResourceBundle().use(appRoot() + resourceBundle, false);
50
51 useStyleSheet(cssPath + "/wt.css");
52 useStyleSheet(cssPath + "/wt_ie.css", "lt IE 7", "all");
53 useStyleSheet("css/home.css");
54 useStyleSheet("css/sourceview.css");
55 useStyleSheet("css/chatwidget.css");
56 useStyleSheet("css/chatwidget_ie6.css", "lt IE 7", "all");
57 setTitle(title);
58
59 setLocale("");
60 language_ = 0;
61}
Home::language_
int language_
Definition Home.h:118
Home::homePage_
WWidget * homePage_
Definition Home.h:99
Home::blogDb_
Dbo::SqlConnectionPool & blogDb_
Definition Home.h:98
Home::sourceViewer_
WWidget * sourceViewer_
Definition Home.h:100

## ◆ ~Home()

Home::~Home | ( |  | ) |
| virtual

Definition at line 36 of file Home.C.

37{
38}

## Member Function Documentation

## ◆ addLanguage()

void Home::addLanguage | ( | const Lang & | l | ) |
| inlineprotected

Definition at line 86 of file Home.h.

86{ languages.push_back(l); }
Home::languages
std::vector< Lang > languages
Definition Home.h:133

## ◆ blog()

std::unique_ptr< WWidget > Home::blog | ( |  | ) |
| private

Definition at line 260 of file Home.C.

261{
262 const Lang& l = languages[language_];
263 std::string langPath = l.path_;
264 std::unique_ptr<BlogView> blog
265 = std::make_unique<BlogView>(langPath + "blog/",
266 blogDb_, "/wt/blog/feed/");
267 blog->setObjectName("blog");
268
269 if (!blog->user().empty())
270 chatSetUser(blog->user());
271
272 blog->userChanged().connect(std::bind(&Home::chatSetUser, this, std::placeholders::_1));
273
274 return std::move(blog);
275}
Home::blog
std::unique_ptr< WWidget > blog()
Definition Home.C:260
Home::chatSetUser
void chatSetUser(const WString &name)
Definition Home.C:277
Lang
Definition Home.h:23
Lang::path_
std::string path_
Definition Home.h:33

## ◆ chatSetUser()

void Home::chatSetUser | ( | const WString & | name | ) |
| private

Definition at line 277 of file Home.C.

278{
279 WApplication::instance()->doJavaScript
280 ("if (window.chat && window.chat.emit) {"
281 """try {"
282 "" "window.chat.emit(window.chat, 'login', "
283 "" "" + userName.jsStringLiteral() + "); "
284 """} catch (e) {"
285 "" "window.chatUser=" + userName.jsStringLiteral() + ";"
286 """}"
287 "} else "
288 """window.chatUser=" + userName.jsStringLiteral() + ";");
289}

## ◆ community()

std::unique_ptr< WWidget > Home::community | ( |  | ) |
| private

Definition at line 324 of file Home.C.

325{
326 return std::make_unique<WText>(tr("home.community"));
327}
Home::tr
WString tr(const char *key)
Definition Home.C:425

## ◆ createHome()

void Home::createHome | ( |  | ) |
| private

Definition at line 114 of file Home.C.

115{
116 WTemplate *result = root()->addWidget(std::make_unique<WTemplate>(tr("template")));
117 homePage_ = result;
118
119 auto languagesDiv = std::make_unique<WContainerWidget>();
120 languagesDiv->setId("top_languages");
121
122 for (unsigned i = 0; i < languages.size(); ++i) {
123 if (i != 0)
124 languagesDiv->addWidget(std::make_unique<WText>("- "));
125
126 const Lang& l = languages[i];
127
128 languagesDiv->addWidget(std::make_unique<WAnchor>(WLink(LinkType::InternalPath, l.path_), l.longDescription_));
129 }
130
131 auto contents = std::make_unique<WStackedWidget>();
132 WAnimation fade(AnimationEffect::Fade, TimingFunction::Linear, 250);
133 contents->setTransitionAnimation(fade);
134 contents->setId("main_page");
135
136 auto mainMenu = std::make_unique<WMenu>(contents.get());
137 mainMenu_ = mainMenu.get();
138 mainMenu_->addItem
139 (tr("introduction"), introduction())->setPathComponent("");
140
141 mainMenu_->addItem
142 (tr("blog"), deferCreate(std::bind(&Home::blog, this)));
143
144 mainMenu_->addItem
145 (tr("features"), wrapView(&Home::features),
146 ContentLoading::Eager);
147
148 mainMenu_->addItem
149 (tr("documentation"), wrapView(&Home::documentation),
150 ContentLoading::Eager);
151
152 mainMenu_->addItem
153 (tr("examples"), examples(),
154 ContentLoading::Eager)->setPathComponent("examples/");
155
156 mainMenu_->addItem
157 (tr("download"), deferCreate(std::bind(&Home::download, this)),
158 ContentLoading::Eager);
159
160 mainMenu_->addItem
161 (tr("community"), wrapView(&Home::community),
162 ContentLoading::Eager);
163
164 mainMenu_->addItem
165 (tr("other-language"), wrapView(&Home::otherLanguage),
166 ContentLoading::Eager);
167
168 mainMenu_->itemSelectRendered().connect(this, &Home::updateTitle);
169
170 mainMenu_->itemSelected().connect(this, &Home::googleAnalyticsLogger);
171
172 // Make the menu be internal-path aware.
173 mainMenu_->setInternalPathEnabled("/");
174
175 sideBarContent_ = std::make_unique<WContainerWidget>();
176
177 result->bindWidget("languages", std::move(languagesDiv));
178 result->bindWidget("menu", std::move(mainMenu));
179 result->bindWidget("contents", std::move(contents));
180 result->bindWidget("sidebar", std::move(sideBarContent_));
181}
deferCreate
std::unique_ptr< DeferredWidget< Function > > deferCreate(Function f)
Definition Home.h:62
Home::community
std::unique_ptr< WWidget > community()
Definition Home.C:324
Home::download
std::unique_ptr< WWidget > download()
Definition Home.C:402
Home::googleAnalyticsLogger
void googleAnalyticsLogger()
Definition Home.C:430
Home::wrapView
std::unique_ptr< WWidget > wrapView(std::unique_ptr< WWidget >(Home::*createFunction)())
Definition Home.C:314
Home::otherLanguage
std::unique_ptr< WWidget > otherLanguage()
Definition Home.C:309
Home::documentation
std::unique_ptr< WWidget > documentation()
Definition Home.C:301
Home::examples
virtual std::unique_ptr< WWidget > examples()=0
Home::updateTitle
void updateTitle()
Definition Home.C:237
Home::features
std::unique_ptr< WWidget > features()
Definition Home.C:296
Home::mainMenu_
WMenu * mainMenu_
Definition Home.h:116
Home::sideBarContent_
std::unique_ptr< WContainerWidget > sideBarContent_
Definition Home.h:131
Home::introduction
std::unique_ptr< WWidget > introduction()
Definition Home.C:255
Lang::longDescription_
std::string longDescription_
Definition Home.h:33

## ◆ createQuoteForm()

virtual std::unique_ptr< WWidget > Home::createQuoteForm | ( |  | ) |
| protectedpure virtual

Implemented in JWtHome, and WtHome.

## ◆ documentation()

std::unique_ptr< WWidget > Home::documentation | ( |  | ) |
| private

Definition at line 301 of file Home.C.

302{
303 std::unique_ptr<WText> result
304 = std::make_unique<WText>(tr("home.documentation"));
305 result->setInternalPathEncoding(true);
306 return std::move(result);
307}

## ◆ download()

std::unique_ptr< WWidget > Home::download | ( |  | ) |
| private

Definition at line 402 of file Home.C.

403{
404 auto result = std::make_unique<WContainerWidget>();
405 result->addWidget(std::make_unique<WText>(tr("home.download")));
406
407 result->addWidget(std::make_unique<WText>(tr("home.download.license")));
408
409#ifdef WT_EMWEB_BUILD
410 result->addWidget(std::move(quoteForm()));
411#endif // WT_EMWEB_BUILD
412
413 result->addWidget(std::make_unique<WText>(tr("home.download.packages")));
414
415 auto releases = std::make_unique<WTable>();
416 readReleases(releases.get());
417 releases_ = result->addWidget(std::move(releases));
418
419 result->addWidget(std::make_unique<WText>(tr("home.download.other")));
420
421 return std::move(result);
422}
Home::releases_
WTable * releases_
Definition Home.h:94
Home::quoteForm
std::unique_ptr< WWidget > quoteForm()
Home::readReleases
void readReleases(WTable *releaseTable)
Definition Home.C:329

## ◆ examples()

virtual std::unique_ptr< WWidget > Home::examples | ( |  | ) |
| protectedpure virtual

Implemented in JWtHome, and WtHome.

## ◆ features()

std::unique_ptr< WWidget > Home::features | ( |  | ) |
| private

Definition at line 296 of file Home.C.

297{
298 return std::unique_ptr<WText>(std::make_unique<WText>(tr("home.features")));
299}

## ◆ filePrefix()

virtual std::string Home::filePrefix | ( |  | ) | const
| protectedpure virtual

Implemented in JWtHome, and WtHome.

## ◆ googleAnalyticsLogger()

void Home::googleAnalyticsLogger | ( |  | ) |

Definition at line 430 of file Home.C.

431{
432 doJavaScript("if (window.ga) ga('send','pageview',"
433 + WWebWidget::jsStringLiteral(environment().deploymentPath()
434 + internalPath()) + ");");
435}

## ◆ href()

std::string Home::href | ( | const std::string & | url,
|  | const std::string & | description )
| protected

Definition at line 319 of file Home.C.

320{
321 return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
322}

## ◆ init()

void Home::init | ( |  | ) |
| protected

Definition at line 63 of file Home.C.

64{
65 internalPathChanged().connect(this, &Home::setup);
66 internalPathChanged().connect(this, &Home::setLanguageFromPath);
67 internalPathChanged().connect(this, &Home::logInternalPath);
68
69 setup();
70
71 setLanguageFromPath();
72}
Home::setup
void setup()
Definition Home.C:74
Home::logInternalPath
void logInternalPath(const std::string &path)
Definition Home.C:244
Home::setLanguageFromPath
void setLanguageFromPath()
Definition Home.C:215

## ◆ introduction()

std::unique_ptr< WWidget > Home::introduction | ( |  | ) |
| private

Definition at line 255 of file Home.C.

256{
257 return std::make_unique<WText>(tr("home.intro"));
258}

## ◆ linkSourceBrowser()

std::unique_ptr< WWidget > Home::linkSourceBrowser | ( | const std::string & | examplePath | ) |
| protected

Definition at line 202 of file Home.C.

203{
204 /*
205 * Instead of using a WAnchor, which will not progress properly because
206 * it is wrapped with wrapView() (-- should we not fix that?), we use
207 * a WText which contains an anchor, and enable internal path encoding.
208 */
209 std::string path = "#/" + SRC_INTERNAL_PATH + "/" + example;
210 std::unique_ptr<WText> a(std::make_unique<WText>(tr("source-browser-link").arg(path)));
211 a->setInternalPathEncoding(true);
212 return std::move(a);
213}
SRC_INTERNAL_PATH
static const std::string SRC_INTERNAL_PATH
Definition Home.C:34

## ◆ logInternalPath()

void Home::logInternalPath | ( | const std::string & | path | ) |
| private

Definition at line 244 of file Home.C.

245{
246 // simulate an access log for the interal paths
247 log("path") << path;
248
249 // If this goes to /src, we need to invoke google analytics method too
250 if (path.size() >= 4 && path.substr(0, 4) == "/src") {
251 googleAnalyticsLogger();
252 }
253}

## ◆ otherLanguage()

std::unique_ptr< WWidget > Home::otherLanguage | ( |  | ) |
| private

Definition at line 309 of file Home.C.

310{
311 return std::unique_ptr<WText>(std::make_unique<WText>(tr("home.other-language")));
312}

## ◆ quoteForm()

std::unique_ptr< WWidget > Home::quoteForm | ( |  | ) |
| private

## ◆ readNews()

void Home::readNews | ( | WTable * | newsTable,
|  | const std::string & | newsfile )
| private

## ◆ readReleases()

void Home::readReleases | ( | WTable * | releaseTable | ) |
| protected

Definition at line 329 of file Home.C.

330{
331 std::ifstream f((filePrefix() + "releases.txt").c_str());
332
333 releaseTable->clear();
334
335 releaseTable->elementAt(0, 0)
336 ->addWidget(std::make_unique<WText>(tr("home.download.version")));
337 releaseTable->elementAt(0, 1)
338 ->addWidget(std::make_unique<WText>(tr("home.download.date")));
339 releaseTable->elementAt(0, 2)
340 ->addWidget(std::make_unique<WText>(tr("home.download.description")));
341
342 releaseTable->elementAt(0, 0)->resize(WLength(15, LengthUnit::FontEx),
343 WLength::Auto);
344 releaseTable->elementAt(0, 1)->resize(WLength(15, LengthUnit::FontEx),
345 WLength::Auto);
346
347 int row = 1;
348
349 while (f) {
350 std::string line;
351 getline(f, line);
352
353 if (f) {
354 typedef boost::tokenizer<boost::escaped_list_separator<char> >
355 CsvTokenizer;
356 CsvTokenizer tok(line);
357
358 CsvTokenizer::iterator i=tok.begin();
359
360 std::string fileName = *i;
361 std::string description = *(++i);
362 releaseTable->elementAt(row, 1)->addWidget(std::make_unique<WText>(*(++i)));
363 releaseTable->elementAt(row, 2)->addWidget(std::make_unique<WText>(*(++i)));
364
365 ++i;
366 std::string url = "http://prdownloads.sourceforge.net/witty/"
367 + fileName + "?download";
368 if (i != tok.end())
369 url = *i;
370
371 releaseTable->elementAt(row, 0)->addWidget
372 (std::make_unique<WText>(href(url, description)));
373
374 ++row;
375 }
376 }
377}
Home::href
std::string href(const std::string &url, const std::string &description)
Definition Home.C:319
Home::filePrefix
virtual std::string filePrefix() const =0

## ◆ setLanguage()

void Home::setLanguage | ( | int | language | ) |
| private

Definition at line 183 of file Home.C.

184{
185 if (homePage_) {
186 const Lang& l = languages[index];
187
188 setLocale(l.code_);
189
190 std::string langPath = l.path_;
191 mainMenu_->setInternalBasePath(langPath);
192 examplesMenu_->setInternalBasePath(langPath + "examples");
193 BlogView *blog = dynamic_cast<BlogView *>(findWidget("blog"));
194 if (blog)
195 blog->setInternalBasePath(langPath + "blog/");
196 updateTitle();
197
198 language_ = index;
199 }
200}
Home::examplesMenu_
WTabWidget * examplesMenu_
Definition Home.h:89
Lang::code_
std::string code_
Definition Home.h:33

## ◆ setLanguageFromPath()

void Home::setLanguageFromPath | ( |  | ) |
| private

Definition at line 215 of file Home.C.

216{
217 std::string langPath = internalPathNextPart("/");
218
219 if (langPath.empty())
220 langPath = '/';
221 else
222 langPath = '/' + langPath + '/';
223
224 int newLanguage = 0;
225
226 for (unsigned i = 0; i < languages.size(); ++i) {
227 if (languages[i].path_ == langPath) {
228 newLanguage = i;
229 break;
230 }
231 }
232
233 if (newLanguage != language_)
234 setLanguage(newLanguage);
235}
Home::setLanguage
void setLanguage(int language)
Definition Home.C:183

## ◆ setup()

void Home::setup | ( |  | ) |
| private

Definition at line 74 of file Home.C.

75{
76 /*
77 * This function switches between the two major components of the homepage,
78 * depending on the internal path:
79 * /src -> source viewer
80 * /... -> homepage
81 *
82 * FIXME: we should take into account language /cn/src ...
83 */
84 std::string base = internalPathNextPart("/");
85
86 if (base == SRC_INTERNAL_PATH) {
87 if (!sourceViewer_) {
88 root()->removeChild(homePage_);
89 homePage_ = nullptr;
90
91 root()->clear();
92
93 auto layout = std::make_unique<WVBoxLayout>();
94 layout->setContentsMargins(0, 0, 0, 0);
95 auto source = sourceViewer("/" + SRC_INTERNAL_PATH + "/");
96 sourceViewer_ = source.get();
97 layout->addWidget(std::move(source));
98
99 root()->setLayout(std::move(layout));
100 }
101 } else {
102 if (!homePage_) {
103 root()->removeChild(sourceViewer_);
104 sourceViewer_ = nullptr;
105 root()->clear();
106
107 createHome();
108
109 setLanguageFromPath();
110 }
111 }
112}
Home::createHome
void createHome()
Definition Home.C:114
Home::sourceViewer
virtual std::unique_ptr< WWidget > sourceViewer(const std::string &deployPath)=0

## ◆ sourceViewer()

virtual std::unique_ptr< WWidget > Home::sourceViewer | ( | const std::string & | deployPath | ) |
| protectedpure virtual

Implemented in JWtHome, and WtHome.

## ◆ status()

std::unique_ptr< WWidget > Home::status | ( |  | ) |
| private

Definition at line 291 of file Home.C.

292{
293 return std::make_unique<WText>(tr("home.status"));
294}

## ◆ tr()

WString Home::tr | ( | const char * | key | ) |
| protected

Definition at line 425 of file Home.C.

426{
427 return WString::tr(key);
428}

## ◆ updateTitle()

void Home::updateTitle | ( |  | ) |
| private

Definition at line 237 of file Home.C.

238{
239 if (mainMenu_->currentItem()) {
240 setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
241 }
242}

## ◆ wrapView()

std::unique_ptr< WWidget > Home::wrapView | ( | std::unique_ptr< WWidget >(Home::* | createFunction )() | ) |
| private

Definition at line 314 of file Home.C.

315{
316 return makeStaticModel(std::bind(createWidget, this));
317}
createWidget
std::unique_ptr< Wt::WApplication > createWidget(const Wt::WEnvironment &env, SimpleChatServer &server)
Definition simpleChat.C:148

## Member Data Documentation

## ◆ blogDb_

Dbo::SqlConnectionPool& Home::blogDb_
| private

Definition at line 98 of file Home.h.

## ◆ contents_

WStackedWidget* Home::contents_
| private

Definition at line 102 of file Home.h.

## ◆ examplesMenu_

WTabWidget* Home::examplesMenu_
| protected

Definition at line 89 of file Home.h.

## ◆ homePage_

WWidget* Home::homePage_
| private

Definition at line 99 of file Home.h.

## ◆ language_

int Home::language_
| private

Definition at line 118 of file Home.h.

## ◆ languages

std::vector<Lang> Home::languages
| private

Definition at line 133 of file Home.h.

## ◆ mainMenu_

WMenu* Home::mainMenu_
| private

Definition at line 116 of file Home.h.

## ◆ releases_

WTable* Home::releases_
| protected

Definition at line 94 of file Home.h.

## ◆ sideBarContent_

std::unique_ptr<WContainerWidget> Home::sideBarContent_
| private

Definition at line 131 of file Home.h.

## ◆ sourceViewer_

WWidget* Home::sourceViewer_
| private

Definition at line 100 of file Home.h.

The documentation for this class was generated from the following files:

- wt-homepage/Home.h
- wt-homepage/Home.C