Wt examples  3.3.2
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
 
WLocalizedStringslocalizedStrings ()
 
void setLocalizedStrings (WLocalizedStrings *stringResolver)
 
WMessageResourceBundlemessageResourceBundle ()
 
void setLocale (const WLocale &locale)
 
const WLocalelocale () const
 
virtual void refresh ()
 
void bindWidget (WWidget *widget, const std::string &domId)
 
std::string docRoot () const
 
std::string sessionId () const
 
void changeSessionId ()
 
void processEvents ()
 
virtual void waitForEvent ()
 
void setAjaxMethod (AjaxMethod method)
 
AjaxMethod ajaxMethod () const
 
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="")
 
void removeMetaHeader (MetaHeaderType type, const std::string &name="")
 
WLogEntry log (const std::string &type) const
 
void setLoadingIndicator (WLoadingIndicator *indicator)
 
WLoadingIndicatorloadingIndicator () const
 
void quit ()
 
bool isQuited () const
 
bool hasQuit () const
 
::int64_t maximumRequestSize () const
 
Signal< ::int64_t > & requestTooLarge ()
 
void setConfirmCloseMessage (const WString &message)
 
void deferRendering ()
 
void resumeRendering ()
 
boost::function< void()> bind (const F &f)
 
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 WCssStyleSheet &styleSheet, const std::string &condition="")
 
void setTheme (const WTheme *theme)
 
const 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
 
std::string internalSubPath (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 ()
 
UpdateLock getUpdateLock ()
 
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 ()
 

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 ()
 

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
enum  AjaxMethod
 
typedef Wt::ApplicationCreator ApplicationCreator
 
typedef boost::function
< WApplication *(const
WEnvironment &)> 
ApplicationCreator
 
- 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)
 
- Public Attributes inherited from Wt::WApplication
 XMLHttpRequest
 
 DynamicScriptTag
 

Detailed Description

Definition at line 67 of file Home.h.

Constructor & Destructor Documentation

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 }
Home::~Home ( )
virtual

Definition at line 34 of file Home.C.

35 {
36 }

Member Function Documentation

void Home::addLanguage ( const Lang l)
inlineprotected

Definition at line 86 of file Home.h.

86 { languages.push_back(l); }
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 }
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 }
WWidget * Home::community ( )
private

Definition at line 320 of file Home.C.

321 {
322  return new WText(tr("home.community"));
323 }
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 }
virtual WWidget* Home::createQuoteForm ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

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 }
WWidget * Home::download ( )
private

Definition at line 392 of file Home.C.

393 {
394  WContainerWidget *result = new WContainerWidget();
395  result->addWidget(new WText(tr("home.download")));
396 
397  result->addWidget(new WText(tr("home.download.license")));
398 
399 #ifdef WT_EMWEB_BUILD
400  result->addWidget(quoteForm());
401 #endif // WT_EMWEB_BUILD
402 
403  result->addWidget(new WText(tr("home.download.packages")));
404 
405  releases_ = new WTable();
407  result->addWidget(releases_);
408 
409  result->addWidget(new WText(tr("home.download.other")));
410 
411  return result;
412 }
virtual WWidget* Home::examples ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::features ( )
private

Definition at line 293 of file Home.C.

294 {
295  return new WText(tr("home.features"));
296 }
virtual std::string Home::filePrefix ( ) const
protectedpure virtual

Implemented in JWtHome, and WtHome.

void Home::googleAnalyticsLogger ( )

Definition at line 420 of file Home.C.

421 {
422  doJavaScript("ga('send','pageview','"
423  + environment().deploymentPath() + internalPath() + "');");
424 }
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 }
void Home::init ( )
protected

Definition at line 62 of file Home.C.

63 {
64  internalPathChanged().connect(this, &Home::setup);
67 
68  setup();
69 
71 }
WWidget * Home::introduction ( )
private

Definition at line 253 of file Home.C.

254 {
255  return new WText(tr("home.intro"));
256 }
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 }
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 }
WWidget * Home::otherLanguage ( )
private

Definition at line 305 of file Home.C.

306 {
307  return new WText(tr("home.other-language"));
308 }
WWidget* Home::quoteForm ( )
private
void Home::readNews ( WTable newsTable,
const std::string &  newsfile 
)
private
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, 0)->addWidget
359  (new WText(href("http://prdownloads.sourceforge.net/witty/"
360  + fileName + "?download", description)));
361  releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i)));
362  releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i)));
363 
364  ++row;
365  }
366  }
367 }
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 }
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 }
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();
106  root()->addWidget(homePage_);
107 
109  }
110  }
111 }
virtual WWidget* Home::sourceViewer ( const std::string &  deployPath)
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::status ( )
private

Definition at line 288 of file Home.C.

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

Definition at line 415 of file Home.C.

416 {
417  return WString::tr(key);
418 }
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 }
WWidget * Home::wrapView ( WWidget *(Home::*)()  createFunction)
private

Definition at line 310 of file Home.C.

311 {
312  return makeStaticModel(boost::bind(createWidget, this));
313 }

Member Data Documentation

Wt::Dbo::SqlConnectionPool& Home::blogDb_
private

Definition at line 98 of file Home.h.

WStackedWidget* Home::contents_
private

Definition at line 102 of file Home.h.

WTabWidget* Home::examplesMenu_
protected

Definition at line 89 of file Home.h.

WWidget* Home::homePage_
private

Definition at line 99 of file Home.h.

int Home::language_
private

Definition at line 118 of file Home.h.

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

Definition at line 133 of file Home.h.

WMenu* Home::mainMenu_
private

Definition at line 116 of file Home.h.

WTable* Home::releases_
protected

Definition at line 94 of file Home.h.

WContainerWidget* Home::sideBarContent_
private

Definition at line 131 of file Home.h.

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 Wed Mar 12 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.4