Wt examples  3.7.1
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:
Inheritance graph
[legend]

Public Member Functions

 Home (const WEnvironment &env, Wt::Dbo::SqlConnectionPool &blogDb, const std::string &title, const std::string &resourceBundle, const std::string &cssPath)
 
virtual ~Home ()
 
void googleAnalyticsLogger ()
 
- Public Member Functions inherited from Wt::WApplication
 WApplication (const WEnvironment &environment)
 
 ~WApplication ()
 
const WEnvironmentenvironment () const
 
WContainerWidgetroot () const
 
WWidgetfindWidget (const std::string &name)
 
void setTitle (const WString &title)
 
const WStringtitle () const
 
const WStringcloseMessage () const
 
std::shared_ptr< WLocalizedStringslocalizedStrings ()
 
void setLocalizedStrings (const std::shared_ptr< WLocalizedStrings > &stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (std::unique_ptr< WWidget > widget, const std::string &domId)
 
std::string docRoot () const
 
void setConnectionMonitor (const std::string &jsObject)
 
std::string sessionId () const
 
void changeSessionId ()
 
void processEvents ()
 
virtual void waitForEvent ()
 
virtual void initialize ()
 
virtual void finalize ()
 
void setTwoPhaseRenderingThreshold (int size)
 
void setCookie (const std::string &name, const std::string &value, int maxAge, const std::string &domain="", const std::string &path="", bool secure=false)
 
void removeCookie (const std::string &name, const std::string &domain="", const std::string &path="")
 
void addMetaLink (const std::string &href, const std::string &rel, const std::string &media, const std::string &hreflang, const std::string &type, const std::string &sizes, bool disabled)
 
void removeMetaLink (const std::string &href)
 
void addMetaHeader (const std::string &name, const WString &content, const std::string &lang="")
 
void addMetaHeader (MetaHeaderType type, const std::string &name, const WString &content, const std::string &lang="")
 
WString metaHeader (MetaHeaderType type, const std::string &name) const
 
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
 
WLogEntry log (const std::string &type) const
 
void setLoadingIndicator (std::unique_ptr< WLoadingIndicator > indicator)
 
WLoadingIndicatorloadingIndicator () const
 
void quit ()
 
void quit (const WString &restartMessage)
 
bool hasQuit () const
 
::int64_t maximumRequestSize () const
 
Signal< ::int64_t > & requestTooLarge ()
 
void setConfirmCloseMessage (const WString &message)
 
void deferRendering ()
 
void resumeRendering ()
 
std::string encodeUntrustedUrl (const std::string &url) const
 
void pushExposedConstraint (WWidget *w)
 
WCssStyleSheetstyleSheet ()
 
void useStyleSheet (const WLink &link, const std::string &media="all")
 
void useStyleSheet (const WLink &link, const std::string &condition, const std::string &media)
 
void useStyleSheet (const WLinkedCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const std::shared_ptr< WTheme > &theme)
 
std::shared_ptr< WThemetheme () const
 
void setCssTheme (const std::string &name)
 
void setLayoutDirection (LayoutDirection direction)
 
LayoutDirection layoutDirection () const
 
void setBodyClass (const std::string &styleClass)
 
std::string bodyClass () const
 
void setHtmlClass (const std::string &styleClass)
 
std::string htmlClass () const
 
std::string url (const std::string &internalPath=std::string()) const
 
virtual std::string makeAbsoluteUrl (const std::string &url) const
 
std::string resolveRelativeUrl (const std::string &url) const
 
std::string bookmarkUrl () const
 
std::string bookmarkUrl (const std::string &internalPath) const
 
void setInternalPath (const std::string &path, bool emitChange=false)
 
void setInternalPathDefaultValid (bool valid)
 
bool internalPathDefaultValid () const
 
void setInternalPathValid (bool valid)
 
bool internalPathValid () const
 
std::string internalPath () const
 
std::string internalPathNextPart (const std::string &path) const
 
bool internalPathMatches (const std::string &path) const
 
Signal< std::string > & internalPathChanged ()
 
Signal< std::string > & internalPathInvalid ()
 
void redirect (const std::string &url)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
void attachThread (bool attach=true)
 
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
 
void addAutoJavaScript (const std::string &javascript)
 
void declareJavaScriptFunction (const std::string &name, const std::string &function)
 
bool require (const std::string &url, const std::string &symbol=std::string())
 
bool requireJQuery (const std::string &url)
 
bool customJQuery () const
 
void setJavaScriptClass (const std::string &className)
 
std::string javaScriptClass ()
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 
WCssStyleSheetstyleSheet ()
 
void useStyleSheet (const WLink &link, const std::string &media="all")
 
void useStyleSheet (const WLink &link, const std::string &condition, const std::string &media)
 
void useStyleSheet (const WLinkedCssStyleSheet &styleSheet, const std::string &condition="")
 
void removeStyleSheet (const WLink &link)
 
void setTheme (const std::shared_ptr< WTheme > &theme)
 
std::shared_ptr< WThemetheme () const
 
void setCssTheme (const std::string &name)
 
void setLayoutDirection (LayoutDirection direction)
 
LayoutDirection layoutDirection () const
 
void setBodyClass (const std::string &styleClass)
 
std::string bodyClass () const
 
void setHtmlClass (const std::string &styleClass)
 
std::string htmlClass () const
 
std::string url (const std::string &internalPath=std::string()) const
 
virtual std::string makeAbsoluteUrl (const std::string &url) const
 
std::string resolveRelativeUrl (const std::string &url) const
 
std::string bookmarkUrl () const
 
std::string bookmarkUrl (const std::string &internalPath) const
 
void setInternalPath (const std::string &path, bool emitChange=false)
 
void setInternalPathDefaultValid (bool valid)
 
bool internalPathDefaultValid () const
 
void setInternalPathValid (bool valid)
 
bool internalPathValid () const
 
std::string internalPath () const
 
std::string internalPathNextPart (const std::string &path) const
 
bool internalPathMatches (const std::string &path) const
 
Signal< std::string > & internalPathChanged ()
 
Signal< std::string > & internalPathInvalid ()
 
void redirect (const std::string &url)
 
void enableUpdates (bool enabled=true)
 
bool updatesEnabled () const
 
void triggerUpdate ()
 
void attachThread (bool attach=true)
 
void doJavaScript (const std::string &javascript, bool afterLoaded=true)
 
void addAutoJavaScript (const std::string &javascript)
 
void declareJavaScriptFunction (const std::string &name, const std::string &function)
 
bool require (const std::string &url, const std::string &symbol=std::string())
 
bool requireJQuery (const std::string &url)
 
bool customJQuery () const
 
void setJavaScriptClass (const std::string &className)
 
std::string javaScriptClass ()
 
EventSignal< WKeyEvent > & globalKeyWentDown ()
 
EventSignal< WKeyEvent > & globalKeyPressed ()
 
EventSignal< WKeyEvent > & globalKeyWentUp ()
 
EventSignalglobalEnterPressed ()
 
EventSignalglobalEscapePressed ()
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
virtual const std::string id () const
 
virtual void setObjectName (const std::string &name)
 
virtual std::string objectName () const
 
void resetLearnedSlots ()
 
void resetLearnedSlot (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

Protected Member Functions

virtual WWidgetexamples ()=0
 
virtual WWidgetcreateQuoteForm ()=0
 
virtual WWidgetsourceViewer (const std::string &deployPath)=0
 
virtual std::string filePrefix () const =0
 
void init ()
 
void addLanguage (const Lang &l)
 
WWidgetlinkSourceBrowser (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 Member Functions inherited from Wt::WApplication
virtual void notify (const WEvent &e)
 
virtual bool isExposed (WWidget *w) const
 
virtual void enableAjax ()
 
virtual void unload ()
 
virtual void idleTimeout ()
 
virtual void handleJavaScriptError (const std::string &errorText)
 
- Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * getStateless (Method method)
 

Protected Attributes

WTabWidgetexamplesMenu_
 
WTablereleases_
 

Private Member Functions

void createHome ()
 
WWidgetintroduction ()
 
WWidgetblog ()
 
WWidgetstatus ()
 
WWidgetfeatures ()
 
WWidgetdocumentation ()
 
WWidgetcommunity ()
 
WWidgetotherLanguage ()
 
WWidgetdownload ()
 
WWidgetquoteForm ()
 
void readNews (WTable *newsTable, const std::string &newsfile)
 
WWidgetwrapView (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

Wt::Dbo::SqlConnectionPoolblogDb_
 
WWidgethomePage_
 
WWidgetsourceViewer_
 
WStackedWidgetcontents_
 
WMenumainMenu_
 
int language_
 
WContainerWidgetsideBarContent_
 
std::vector< Langlanguages
 

Additional Inherited Members

- Public Types inherited from Wt::WApplication
typedef Wt::ApplicationCreator ApplicationCreator
 
typedef std::function< std::unique_ptr< WApplication >const WEnvironment &)> ApplicationCreator
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WApplication
static WApplicationinstance ()
 
static std::string resourcesUrl ()
 
static std::string relativeResourcesUrl ()
 
static std::string appRoot ()
 
static bool readConfigurationProperty (const std::string &name, std::string &value)
 

Detailed Description

Definition at line 67 of file Home.h.

Constructor & Destructor Documentation

◆ Home()

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

Definition at line 38 of file Home.C.

42  : WApplication(env),
43  releases_(0),
44  blogDb_(blogDb),
45  homePage_(0),
46  sourceViewer_(0)
47 {
48  messageResourceBundle().use(appRoot() + resourceBundle, false);
49 
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");
56  setTitle(title);
57 
58  setLocale("");
59  language_ = 0;
60 }
int language_
Definition: Home.h:118
WMessageResourceBundle & messageResourceBundle()
void setTitle(const WString &title)
const WString & title() const
void use(const std::string &path, bool loadInMemory=true)
Wt::Dbo::SqlConnectionPool & blogDb_
Definition: Home.h:98
WWidget * homePage_
Definition: Home.h:99
static std::string appRoot()
void useStyleSheet(const WLink &link, const std::string &media="all")
WWidget * sourceViewer_
Definition: Home.h:100
WTable * releases_
Definition: Home.h:94
void setLocale(const WLocale &locale)
WApplication(const WEnvironment &environment)

◆ ~Home()

Home::~Home ( )
virtual

Definition at line 34 of file Home.C.

35 {
36 }

Member Function Documentation

◆ addLanguage()

void Home::addLanguage ( const Lang l)
inlineprotected

Definition at line 86 of file Home.h.

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

◆ blog()

WWidget * Home::blog ( )
private

Definition at line 258 of file Home.C.

259 {
260  const Lang& l = languages[language_];
261  std::string langPath = l.path_;
262  BlogView *blog = new BlogView(langPath + "blog/",
263  blogDb_, "/wt/blog/feed/");
264  blog->setObjectName("blog");
265 
266  if (!blog->user().empty())
267  chatSetUser(blog->user());
268 
269  blog->userChanged().connect(this, &Home::chatSetUser);
270 
271  return blog;
272 }
std::string path_
Definition: Home.h:33
int language_
Definition: Home.h:118
std::vector< Lang > languages
Definition: Home.h:133
Definition: Home.h:23
Wt::Dbo::SqlConnectionPool & blogDb_
Definition: Home.h:98
WWidget * blog()
Definition: Home.C:258
void chatSetUser(const WString &name)
Definition: Home.C:274

◆ chatSetUser()

void Home::chatSetUser ( const WString name)
private

Definition at line 274 of file Home.C.

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

◆ community()

WWidget * Home::community ( )
private

Definition at line 320 of file Home.C.

321 {
322  return new WText(tr("home.community"));
323 }
WString tr(const char *key)
Definition: Home.C:421

◆ createHome()

void Home::createHome ( )
private

Definition at line 113 of file Home.C.

114 {
115  WTemplate *result = new WTemplate(tr("template"), root());
116  homePage_ = result;
117 
118  WContainerWidget *languagesDiv = new WContainerWidget();
119  languagesDiv->setId("top_languages");
120 
121  for (unsigned i = 0; i < languages.size(); ++i) {
122  if (i != 0)
123  new WText("- ", languagesDiv);
124 
125  const Lang& l = languages[i];
126 
127  new WAnchor(WLink(WLink::InternalPath, l.path_),
128  WString::fromUTF8(l.longDescription_), languagesDiv);
129  }
130 
131  WStackedWidget *contents = new WStackedWidget();
132  WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250);
133  contents->setTransitionAnimation(fade);
134  contents->setId("main_page");
135 
136  mainMenu_ = new WMenu(contents, Vertical);
137 
139  (tr("introduction"), introduction())->setPathComponent("");
140 
142  (tr("blog"), deferCreate(boost::bind(&Home::blog, this)));
143 
145  (tr("features"), wrapView(&Home::features), WMenuItem::PreLoading);
146 
148  (tr("documentation"), wrapView(&Home::documentation),
149  WMenuItem::PreLoading);
150 
152  (tr("examples"), examples(),
153  WMenuItem::PreLoading)->setPathComponent("examples/");
154 
156  (tr("download"), deferCreate(boost::bind(&Home::download, this)),
157  WMenuItem::PreLoading);
158 
160  (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading);
161 
163  (tr("other-language"), wrapView(&Home::otherLanguage),
164  WMenuItem::PreLoading);
165 
167 
169 
170  // Make the menu be internal-path aware.
172 
174 
175  result->bindWidget("languages", languagesDiv);
176  result->bindWidget("menu", mainMenu_);
177  result->bindWidget("contents", contents);
178  result->bindWidget("sidebar", sideBarContent_);
179 }
WMenuItem * addItem(const WString &label, std::unique_ptr< WWidget > contents=nullptr, ContentLoading policy=ContentLoading::Lazy)
std::string path_
Definition: Home.h:33
WWidget * wrapView(WWidget *(Home::*createFunction)())
Definition: Home.C:310
WWidget * introduction()
Definition: Home.C:253
WMenu * mainMenu_
Definition: Home.h:116
std::vector< Lang > languages
Definition: Home.h:133
void setTransitionAnimation(const WAnimation &animation, bool autoReverse=false)
virtual void bindWidget(const std::string &varName, std::unique_ptr< WWidget > widget)
virtual void setId(const std::string &id) override
virtual WWidget * examples()=0
std::string longDescription_
Definition: Home.h:33
Definition: Home.h:23
WString tr(const char *key)
Definition: Home.C:421
void updateTitle()
Definition: Home.C:235
WWidget * features()
Definition: Home.C:293
void setInternalPathEnabled(const std::string &basePath="")
Signal< WMenuItem *> & itemSelected()
DeferredWidget< Function > * deferCreate(Function f)
Definition: Home.h:62
WWidget * documentation()
Definition: Home.C:298
Signal< WMenuItem *> & itemSelectRendered()
WContainerWidget * root() const
WWidget * homePage_
Definition: Home.h:99
WWidget * otherLanguage()
Definition: Home.C:305
WContainerWidget * sideBarContent_
Definition: Home.h:131
WWidget * blog()
Definition: Home.C:258
WWidget * download()
Definition: Home.C:398
WWidget * community()
Definition: Home.C:320
virtual void setPathComponent(const std::string &path)
void googleAnalyticsLogger()
Definition: Home.C:426

◆ createQuoteForm()

virtual WWidget* Home::createQuoteForm ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

◆ documentation()

WWidget * Home::documentation ( )
private

Definition at line 298 of file Home.C.

299 {
300  WText *result = new WText(tr("home.documentation"));
301  result->setInternalPathEncoding(true);
302  return result;
303 }
WString tr(const char *key)
Definition: Home.C:421
void setInternalPathEncoding(bool enabled)

◆ download()

WWidget * Home::download ( )
private

Definition at line 398 of file Home.C.

399 {
400  WContainerWidget *result = new WContainerWidget();
401  result->addWidget(new WText(tr("home.download")));
402 
403  result->addWidget(new WText(tr("home.download.license")));
404 
405 #ifdef WT_EMWEB_BUILD
406  result->addWidget(quoteForm());
407 #endif // WT_EMWEB_BUILD
408 
409  result->addWidget(new WText(tr("home.download.packages")));
410 
411  releases_ = new WTable();
413  result->addWidget(releases_);
414 
415  result->addWidget(new WText(tr("home.download.other")));
416 
417  return result;
418 }
WWidget * quoteForm()
WString tr(const char *key)
Definition: Home.C:421
void readReleases(WTable *releaseTable)
Definition: Home.C:325
WTable * releases_
Definition: Home.h:94
virtual void addWidget(std::unique_ptr< WWidget > widget)

◆ examples()

virtual WWidget* Home::examples ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

◆ features()

WWidget * Home::features ( )
private

Definition at line 293 of file Home.C.

294 {
295  return new WText(tr("home.features"));
296 }
WString tr(const char *key)
Definition: Home.C:421

◆ filePrefix()

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

Implemented in JWtHome, and WtHome.

◆ googleAnalyticsLogger()

void Home::googleAnalyticsLogger ( )

Definition at line 426 of file Home.C.

427 {
428  doJavaScript("if (window.ga) ga('send','pageview',"
429  + WWebWidget::jsStringLiteral(environment().deploymentPath()
430  + internalPath()) + ");");
431 }
std::string internalPath() const
const WEnvironment & environment() const
void doJavaScript(const std::string &javascript, bool afterLoaded=true)

◆ href()

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

Definition at line 315 of file Home.C.

316 {
317  return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
318 }
std::string url(const std::string &internalPath=std::string()) const

◆ init()

void Home::init ( )
protected

Definition at line 62 of file Home.C.

63 {
67 
68  setup();
69 
71 }
void logInternalPath(const std::string &path)
Definition: Home.C:242
void setup()
Definition: Home.C:73
void setLanguageFromPath()
Definition: Home.C:213
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
Signal< std::string > & internalPathChanged()

◆ introduction()

WWidget * Home::introduction ( )
private

Definition at line 253 of file Home.C.

254 {
255  return new WText(tr("home.intro"));
256 }
WString tr(const char *key)
Definition: Home.C:421

◆ linkSourceBrowser()

WWidget * Home::linkSourceBrowser ( const std::string &  examplePath)
protected

Definition at line 200 of file Home.C.

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

◆ logInternalPath()

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

Definition at line 242 of file Home.C.

243 {
244  // simulate an access log for the interal paths
245  log("path") << path;
246 
247  // If this goes to /src, we need to invoke google analytics method too
248  if (path.size() >= 4 && path.substr(0, 4) == "/src") {
250  }
251 }
WLogEntry log(const std::string &type) const
void googleAnalyticsLogger()
Definition: Home.C:426

◆ otherLanguage()

WWidget * Home::otherLanguage ( )
private

Definition at line 305 of file Home.C.

306 {
307  return new WText(tr("home.other-language"));
308 }
WString tr(const char *key)
Definition: Home.C:421

◆ quoteForm()

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 325 of file Home.C.

326 {
327  std::ifstream f((filePrefix() + "releases.txt").c_str());
328 
329  releaseTable->clear();
330 
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")));
337 
338  releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx),
339  WLength::Auto);
340  releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx),
341  WLength::Auto);
342 
343  int row = 1;
344 
345  while (f) {
346  std::string line;
347  getline(f, line);
348 
349  if (f) {
350  typedef boost::tokenizer<boost::escaped_list_separator<char> >
351  CsvTokenizer;
352  CsvTokenizer tok(line);
353 
354  CsvTokenizer::iterator i=tok.begin();
355 
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)));
360 
361  ++i;
362  std::string url = "http://prdownloads.sourceforge.net/witty/"
363  + fileName + "?download";
364  if (i != tok.end())
365  url = *i;
366 
367  releaseTable->elementAt(row, 0)->addWidget
368  (new WText(href(url, description)));
369 
370  ++row;
371  }
372  }
373 }
std::string url(const std::string &internalPath=std::string()) const
WString tr(const char *key)
Definition: Home.C:421
virtual std::string filePrefix() const =0
WTableCell * elementAt(int row, int column)
std::string href(const std::string &url, const std::string &description)
Definition: Home.C:315
virtual void resize(const WLength &width, const WLength &height) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
virtual void clear()

◆ setLanguage()

void Home::setLanguage ( int  language)
private

Definition at line 181 of file Home.C.

182 {
183  if (homePage_) {
184  const Lang& l = languages[index];
185 
186  setLocale(l.code_);
187 
188  std::string langPath = l.path_;
189  mainMenu_->setInternalBasePath(langPath);
190  examplesMenu_->setInternalBasePath(langPath + "examples");
191  BlogView *blog = dynamic_cast<BlogView *>(findWidget("blog"));
192  if (blog)
193  blog->setInternalBasePath(langPath + "blog/");
194  updateTitle();
195 
196  language_ = index;
197  }
198 }
std::string path_
Definition: Home.h:33
int language_
Definition: Home.h:118
WMenu * mainMenu_
Definition: Home.h:116
std::vector< Lang > languages
Definition: Home.h:133
Definition: Home.h:23
void updateTitle()
Definition: Home.C:235
WWidget * homePage_
Definition: Home.h:99
void setInternalBasePath(const std::string &path)
WWidget * findWidget(const std::string &name)
WTabWidget * examplesMenu_
Definition: Home.h:89
WWidget * blog()
Definition: Home.C:258
void setInternalBasePath(const std::string &basePath)
std::string code_
Definition: Home.h:33
void setLocale(const WLocale &locale)

◆ setLanguageFromPath()

void Home::setLanguageFromPath ( )
private

Definition at line 213 of file Home.C.

214 {
215  std::string langPath = internalPathNextPart("/");
216 
217  if (langPath.empty())
218  langPath = '/';
219  else
220  langPath = '/' + langPath + '/';
221 
222  int newLanguage = 0;
223 
224  for (unsigned i = 0; i < languages.size(); ++i) {
225  if (languages[i].path_ == langPath) {
226  newLanguage = i;
227  break;
228  }
229  }
230 
231  if (newLanguage != language_)
232  setLanguage(newLanguage);
233 }
int language_
Definition: Home.h:118
std::vector< Lang > languages
Definition: Home.h:133
void setLanguage(int language)
Definition: Home.C:181
std::string internalPathNextPart(const std::string &path) const

◆ setup()

void Home::setup ( )
private

Definition at line 73 of file Home.C.

74 {
75  /*
76  * This function switches between the two major components of the homepage,
77  * depending on the internal path:
78  * /src -> source viewer
79  * /... -> homepage
80  *
81  * FIXME: we should take into account language /cn/src ...
82  */
83  std::string base = internalPathNextPart("/");
84 
85  if (base == SRC_INTERNAL_PATH) {
86  if (!sourceViewer_) {
87  delete homePage_;
88  homePage_ = 0;
89 
90  root()->clear();
91 
93  WVBoxLayout *layout = new WVBoxLayout();
94  layout->setContentsMargins(0, 0, 0, 0);
95  layout->addWidget(sourceViewer_);
96  root()->setLayout(layout);
97  }
98  } else {
99  if (!homePage_) {
100  delete sourceViewer_;
101  sourceViewer_ = 0;
102 
103  root()->clear();
104 
105  createHome();
107 
109  }
110  }
111 }
void setLayout(std::unique_ptr< WLayout > layout)
void addWidget(std::unique_ptr< WWidget > widget, int stretch, WFlags< AlignmentFlag > alignment)
virtual WWidget * sourceViewer(const std::string &deployPath)=0
static const std::string SRC_INTERNAL_PATH
Definition: Home.C:32
virtual void clear()
void setContentsMargins(int left, int top, int right, int bottom)
WContainerWidget * root() const
WWidget * homePage_
Definition: Home.h:99
void setLanguageFromPath()
Definition: Home.C:213
std::string internalPathNextPart(const std::string &path) const
void createHome()
Definition: Home.C:113
WWidget * sourceViewer_
Definition: Home.h:100
virtual void addWidget(std::unique_ptr< WWidget > widget)

◆ sourceViewer()

virtual WWidget* Home::sourceViewer ( const std::string &  deployPath)
protectedpure virtual

Implemented in JWtHome, and WtHome.

◆ status()

WWidget * Home::status ( )
private

Definition at line 288 of file Home.C.

289 {
290  return new WText(tr("home.status"));
291 }
WString tr(const char *key)
Definition: Home.C:421

◆ tr()

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

Definition at line 421 of file Home.C.

422 {
423  return WString::tr(key);
424 }

◆ updateTitle()

void Home::updateTitle ( )
private

Definition at line 235 of file Home.C.

236 {
237  if (mainMenu_->currentItem()) {
238  setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
239  }
240 }
WMenu * mainMenu_
Definition: Home.h:116
void setTitle(const WString &title)
WString text() const
WString tr(const char *key)
Definition: Home.C:421
WMenuItem * currentItem() const

◆ wrapView()

WWidget * Home::wrapView ( WWidget *(Home::*)()  createFunction)
private

Definition at line 310 of file Home.C.

311 {
312  return makeStaticModel(boost::bind(createWidget, this));
313 }
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:145

Member Data Documentation

◆ blogDb_

Wt::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_

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:

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13