Wt examples  4.10.4
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 ()
 
- 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 Http::Cookie &cookie)
 
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 Http::Cookie &cookie)
 
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)
 
void suspend (std::chrono::seconds duration)
 
Signalunsuspended ()
 
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
 
void setHtmlAttribute (const std::string &name, const std::string &value)
 
WString htmlAttribute (const std::string &name) const
 
void setBodyAttribute (const std::string &name, const std::string &value)
 
WString bodyAttribute (const std::string &name) 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
 
void setHtmlAttribute (const std::string &name, const std::string &value)
 
WString htmlAttribute (const std::string &name) const
 
void setBodyAttribute (const std::string &name, const std::string &value)
 
WString bodyAttribute (const std::string &name) 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 std::unique_ptr< WWidgetexamples ()=0
 
virtual std::unique_ptr< WWidgetcreateQuoteForm ()=0
 
virtual std::unique_ptr< WWidgetsourceViewer (const std::string &deployPath)=0
 
virtual std::string filePrefix () const =0
 
void init ()
 
void addLanguage (const Lang &l)
 
std::unique_ptr< 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 ()
 
std::unique_ptr< WWidgetintroduction ()
 
std::unique_ptr< WWidgetblog ()
 
std::unique_ptr< WWidgetstatus ()
 
std::unique_ptr< WWidgetfeatures ()
 
std::unique_ptr< WWidgetdocumentation ()
 
std::unique_ptr< WWidgetcommunity ()
 
std::unique_ptr< WWidgetotherLanguage ()
 
std::unique_ptr< WWidgetdownload ()
 
std::unique_ptr< WWidgetquoteForm ()
 
void readNews (WTable *newsTable, const std::string &newsfile)
 
std::unique_ptr< WWidgetwrapView (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::SqlConnectionPoolblogDb_
 
WWidgethomePage_
 
WWidgetsourceViewer_
 
WStackedWidgetcontents_
 
WMenumainMenu_
 
int language_
 
std::unique_ptr< 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,
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 }
int language_
Definition: Home.h:118
WWidget * homePage_
Definition: Home.h:99
Dbo::SqlConnectionPool & blogDb_
Definition: Home.h:98
WWidget * sourceViewer_
Definition: Home.h:100
const WString & title() const
WMessageResourceBundle & messageResourceBundle()
void setTitle(const WString &title)
static std::string appRoot()
void useStyleSheet(const WLink &link, const std::string &media="all")
void setLocale(const WLocale &locale)
WApplication(const WEnvironment &environment)
void use(const std::string &path, bool loadInMemory=true)

◆ ~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); }
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 }
std::unique_ptr< WWidget > blog()
Definition: Home.C:260
void chatSetUser(const WString &name)
Definition: Home.C:277
Definition: Home.h:23
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 }
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();
139  (tr("introduction"), introduction())->setPathComponent("");
140 
142  (tr("blog"), deferCreate(std::bind(&Home::blog, this)));
143 
145  (tr("features"), wrapView(&Home::features),
146  ContentLoading::Eager);
147 
149  (tr("documentation"), wrapView(&Home::documentation),
150  ContentLoading::Eager);
151 
153  (tr("examples"), examples(),
154  ContentLoading::Eager)->setPathComponent("examples/");
155 
157  (tr("download"), deferCreate(std::bind(&Home::download, this)),
158  ContentLoading::Eager);
159 
161  (tr("community"), wrapView(&Home::community),
162  ContentLoading::Eager);
163 
165  (tr("other-language"), wrapView(&Home::otherLanguage),
166  ContentLoading::Eager);
167 
169 
171 
172  // Make the menu be internal-path aware.
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 }
std::unique_ptr< DeferredWidget< Function > > deferCreate(Function f)
Definition: Home.h:62
std::unique_ptr< WWidget > community()
Definition: Home.C:324
std::unique_ptr< WWidget > download()
Definition: Home.C:402
void googleAnalyticsLogger()
Definition: Home.C:430
std::unique_ptr< WWidget > wrapView(std::unique_ptr< WWidget >(Home::*createFunction)())
Definition: Home.C:314
std::unique_ptr< WWidget > otherLanguage()
Definition: Home.C:309
std::unique_ptr< WWidget > documentation()
Definition: Home.C:301
void updateTitle()
Definition: Home.C:237
std::unique_ptr< WWidget > features()
Definition: Home.C:296
WMenu * mainMenu_
Definition: Home.h:116
std::unique_ptr< WContainerWidget > sideBarContent_
Definition: Home.h:131
std::unique_ptr< WWidget > introduction()
Definition: Home.C:255
virtual std::unique_ptr< WWidget > examples()=0
WContainerWidget * root() const
virtual void addWidget(std::unique_ptr< WWidget > widget)
virtual void setPathComponent(const std::string &path)
Signal< WMenuItem * > & itemSelected()
WMenuItem * addItem(const WString &label, std::unique_ptr< WWidget > contents=nullptr, ContentLoading policy=ContentLoading::Lazy)
Signal< WMenuItem * > & itemSelectRendered()
void setInternalPathEnabled(const std::string &basePath="")
virtual void bindWidget(const std::string &varName, std::unique_ptr< WWidget > widget)
std::string longDescription_
Definition: Home.h:33

◆ createQuoteForm()

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

Implemented in WtHome, and JWtHome.

◆ 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 }
std::unique_ptr< WWidget > quoteForm()
WTable * releases_
Definition: Home.h:94
void readReleases(WTable *releaseTable)
Definition: Home.C:329

◆ examples()

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

Implemented in WtHome, and JWtHome.

◆ 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 WtHome, and JWtHome.

◆ 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 }
void doJavaScript(const std::string &javascript, bool afterLoaded=true)
std::string internalPath() const
const WEnvironment & environment() const

◆ 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 }
std::string url(const std::string &internalPath=std::string()) const

◆ init()

void Home::init ( )
protected

Definition at line 63 of file Home.C.

64 {
68 
69  setup();
70 
72 }
void setup()
Definition: Home.C:74
void logInternalPath(const std::string &path)
Definition: Home.C:244
void setLanguageFromPath()
Definition: Home.C:215
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
Signal< std::string > & internalPathChanged()

◆ 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 }
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") {
252  }
253 }
WLogEntry log(const std::string &type) const

◆ 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 }
std::string href(const std::string &url, const std::string &description)
Definition: Home.C:319
virtual std::string filePrefix() const =0
virtual void clear()
WTableCell * elementAt(int row, int column)
virtual void resize(const WLength &width, const WLength &height) override

◆ 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 }
WTabWidget * examplesMenu_
Definition: Home.h:89
WWidget * findWidget(const std::string &name)
void setInternalBasePath(const std::string &basePath)
void setInternalBasePath(const std::string &path)
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 }
void setLanguage(int language)
Definition: Home.C:183
std::string internalPathNextPart(const std::string &path) const

◆ 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_) {
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_) {
104  sourceViewer_ = nullptr;
105  root()->clear();
106 
107  createHome();
108 
110  }
111  }
112 }
void createHome()
Definition: Home.C:114
virtual std::unique_ptr< WWidget > sourceViewer(const std::string &deployPath)=0
virtual void clear()
void setLayout(std::unique_ptr< WLayout > layout)
std::unique_ptr< WObject > removeChild(WObject *child)

◆ sourceViewer()

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

Implemented in WtHome, and JWtHome.

◆ 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 }
WString text() const
WMenuItem * currentItem() const

◆ 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 }
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: