Wt examples  3.3.0
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, 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 ()
 
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

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,
const std::string &  title,
const std::string &  resourceBundle,
const std::string &  cssPath 
)

Definition at line 38 of file Home.C.

40  : WApplication(env),
41  releases_(0),
42  homePage_(0),
43  sourceViewer_(0)
44 {
45  messageResourceBundle().use(appRoot() + resourceBundle, false);
46 
47  useStyleSheet(cssPath + "/wt.css");
48  useStyleSheet(cssPath + "/wt_ie.css", "lt IE 7");
49  useStyleSheet("css/home.css");
50  useStyleSheet("css/sourceview.css");
51  useStyleSheet("css/chatwidget.css");
52  useStyleSheet("css/chatwidget_ie6.css", "lt IE 7");
53  setTitle(title);
54 
55  setLocale("");
56  language_ = 0;
57 }
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 255 of file Home.C.

256 {
257  const Lang& l = languages[language_];
258  std::string langPath = l.path_;
259  BlogView *blog = new BlogView(langPath + "blog/",
260  appRoot() + "blog.db", "/wt/blog/feed/");
261  blog->setObjectName("blog");
262 
263  if (!blog->user().empty())
264  chatSetUser(blog->user());
265 
266  blog->userChanged().connect(this, &Home::chatSetUser);
267 
268  return blog;
269 }
void Home::chatSetUser ( const WString name)
private

Definition at line 271 of file Home.C.

272 {
273  WApplication::instance()->doJavaScript
274  ("if (window.chat && window.chat.emit) {"
275  """try {"
276  "" "window.chat.emit(window.chat, 'login', "
277  "" "" + userName.jsStringLiteral() + "); "
278  """} catch (e) {"
279  "" "window.chatUser=" + userName.jsStringLiteral() + ";"
280  """}"
281  "} else "
282  """window.chatUser=" + userName.jsStringLiteral() + ";");
283 }
WWidget * Home::community ( )
private

Definition at line 317 of file Home.C.

318 {
319  return new WText(tr("home.community"));
320 }
void Home::createHome ( )
private

Definition at line 110 of file Home.C.

111 {
112  WTemplate *result = new WTemplate(tr("template"), root());
113  homePage_ = result;
114 
115  WContainerWidget *languagesDiv = new WContainerWidget();
116  languagesDiv->setId("top_languages");
117 
118  for (unsigned i = 0; i < languages.size(); ++i) {
119  if (i != 0)
120  new WText("- ", languagesDiv);
121 
122  const Lang& l = languages[i];
123 
124  new WAnchor(WLink(WLink::InternalPath, l.path_),
125  WString::fromUTF8(l.longDescription_), languagesDiv);
126  }
127 
128  WStackedWidget *contents = new WStackedWidget();
129  WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250);
130  contents->setTransitionAnimation(fade);
131  contents->setId("main_page");
132 
133  mainMenu_ = new WMenu(contents, Vertical);
134 
136  (tr("introduction"), introduction())->setPathComponent("");
137 
139  (tr("blog"), deferCreate(boost::bind(&Home::blog, this)));
140 
142  (tr("features"), wrapView(&Home::features), WMenuItem::PreLoading);
143 
145  (tr("documentation"), wrapView(&Home::documentation),
146  WMenuItem::PreLoading);
147 
149  (tr("examples"), examples(),
150  WMenuItem::PreLoading)->setPathComponent("examples/");
151 
153  (tr("download"), deferCreate(boost::bind(&Home::download, this)),
154  WMenuItem::PreLoading);
155 
157  (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading);
158 
160  (tr("other-language"), wrapView(&Home::otherLanguage),
161  WMenuItem::PreLoading);
162 
164 
166 
167  // Make the menu be internal-path aware.
169 
171 
172  result->bindWidget("languages", languagesDiv);
173  result->bindWidget("menu", mainMenu_);
174  result->bindWidget("contents", contents);
175  result->bindWidget("sidebar", sideBarContent_);
176 }
virtual WWidget* Home::createQuoteForm ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::documentation ( )
private

Definition at line 295 of file Home.C.

296 {
297  WText *result = new WText(tr("home.documentation"));
298  result->setInternalPathEncoding(true);
299  return result;
300 }
WWidget * Home::download ( )
private

Definition at line 389 of file Home.C.

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

Implemented in JWtHome, and WtHome.

WWidget * Home::features ( )
private

Definition at line 290 of file Home.C.

291 {
292  return new WText(tr("home.features"));
293 }
virtual std::string Home::filePrefix ( ) const
protectedpure virtual

Implemented in JWtHome, and WtHome.

void Home::googleAnalyticsLogger ( )

Definition at line 417 of file Home.C.

418 {
419  std::string googleCmd =
420  "if (window.pageTracker) {"
421  """try {"
422  "" "setTimeout(function() {"
423  "" "window.pageTracker._trackPageview(\""
424  + environment().deploymentPath() + internalPath() + "\");"
425  "" "}, 1000);"
426  """} catch (e) { }"
427  "}";
428 
429  doJavaScript(googleCmd);
430 }
std::string Home::href ( const std::string &  url,
const std::string &  description 
)
protected

Definition at line 312 of file Home.C.

313 {
314  return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
315 }
void Home::init ( )
protected

Definition at line 59 of file Home.C.

60 {
61  internalPathChanged().connect(this, &Home::setup);
64 
65  setup();
66 
68 }
WWidget * Home::introduction ( )
private

Definition at line 250 of file Home.C.

251 {
252  return new WText(tr("home.intro"));
253 }
WWidget * Home::linkSourceBrowser ( const std::string &  examplePath)
protected

Definition at line 197 of file Home.C.

198 {
199  /*
200  * Instead of using a WAnchor, which will not progress properly because
201  * it is wrapped with wrapView() (-- should we not fix that?), we use
202  * a WText which contains an anchor, and enable internal path encoding.
203  */
204  std::string path = "#/" + SRC_INTERNAL_PATH + "/" + example;
205  WText *a = new WText(tr("source-browser-link").arg(path));
206  a->setInternalPathEncoding(true);
207  return a;
208 }
void Home::logInternalPath ( const std::string &  path)
private

Definition at line 239 of file Home.C.

240 {
241  // simulate an access log for the interal paths
242  log("path") << path;
243 
244  // If this goes to /src, we need to invoke google analytics method too
245  if (path.size() >= 4 && path.substr(0, 4) == "/src") {
247  }
248 }
WWidget * Home::otherLanguage ( )
private

Definition at line 302 of file Home.C.

303 {
304  return new WText(tr("home.other-language"));
305 }
WWidget* Home::quoteForm ( )
private
void Home::readNews ( WTable newsTable,
const std::string &  newsfile 
)
private
void Home::readReleases ( WTable releaseTable)
protected

Definition at line 322 of file Home.C.

323 {
324  std::ifstream f((filePrefix() + "releases.txt").c_str());
325 
326  releaseTable->clear();
327 
328  releaseTable->elementAt(0, 0)
329  ->addWidget(new WText(tr("home.download.version")));
330  releaseTable->elementAt(0, 1)
331  ->addWidget(new WText(tr("home.download.date")));
332  releaseTable->elementAt(0, 2)
333  ->addWidget(new WText(tr("home.download.description")));
334 
335  releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx),
336  WLength::Auto);
337  releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx),
338  WLength::Auto);
339 
340  int row = 1;
341 
342  while (f) {
343  std::string line;
344  getline(f, line);
345 
346  if (f) {
347  typedef boost::tokenizer<boost::escaped_list_separator<char> >
348  CsvTokenizer;
349  CsvTokenizer tok(line);
350 
351  CsvTokenizer::iterator i=tok.begin();
352 
353  std::string fileName = *i;
354  std::string description = *(++i);
355  releaseTable->elementAt(row, 0)->addWidget
356  (new WText(href("http://prdownloads.sourceforge.net/witty/"
357  + fileName + "?download", description)));
358  releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i)));
359  releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i)));
360 
361  ++row;
362  }
363  }
364 }
void Home::setLanguage ( int  language)
private

Definition at line 178 of file Home.C.

179 {
180  if (homePage_) {
181  const Lang& l = languages[index];
182 
183  setLocale(l.code_);
184 
185  std::string langPath = l.path_;
186  mainMenu_->setInternalBasePath(langPath);
187  examplesMenu_->setInternalBasePath(langPath + "examples");
188  BlogView *blog = dynamic_cast<BlogView *>(findWidget("blog"));
189  if (blog)
190  blog->setInternalBasePath(langPath + "blog/");
191  updateTitle();
192 
193  language_ = index;
194  }
195 }
void Home::setLanguageFromPath ( )
private

Definition at line 210 of file Home.C.

211 {
212  std::string langPath = internalPathNextPart("/");
213 
214  if (langPath.empty())
215  langPath = '/';
216  else
217  langPath = '/' + langPath + '/';
218 
219  int newLanguage = 0;
220 
221  for (unsigned i = 0; i < languages.size(); ++i) {
222  if (languages[i].path_ == langPath) {
223  newLanguage = i;
224  break;
225  }
226  }
227 
228  if (newLanguage != language_)
229  setLanguage(newLanguage);
230 }
void Home::setup ( )
private

Definition at line 70 of file Home.C.

71 {
72  /*
73  * This function switches between the two major components of the homepage,
74  * depending on the internal path:
75  * /src -> source viewer
76  * /... -> homepage
77  *
78  * FIXME: we should take into account language /cn/src ...
79  */
80  std::string base = internalPathNextPart("/");
81 
82  if (base == SRC_INTERNAL_PATH) {
83  if (!sourceViewer_) {
84  delete homePage_;
85  homePage_ = 0;
86 
87  root()->clear();
88 
90  WVBoxLayout *layout = new WVBoxLayout();
91  layout->setContentsMargins(0, 0, 0, 0);
92  layout->addWidget(sourceViewer_);
93  root()->setLayout(layout);
94  }
95  } else {
96  if (!homePage_) {
97  delete sourceViewer_;
98  sourceViewer_ = 0;
99 
100  root()->clear();
101 
102  createHome();
103  root()->addWidget(homePage_);
104 
106  }
107  }
108 }
virtual WWidget* Home::sourceViewer ( const std::string &  deployPath)
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::status ( )
private

Definition at line 285 of file Home.C.

286 {
287  return new WText(tr("home.status"));
288 }
WString Home::tr ( const char *  key)
protected

Definition at line 412 of file Home.C.

413 {
414  return WString::tr(key);
415 }
void Home::updateTitle ( )
private

Definition at line 232 of file Home.C.

233 {
234  if (mainMenu_->currentItem()) {
235  setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
236  }
237 }
WWidget * Home::wrapView ( WWidget *(Home::*)()  createFunction)
private

Definition at line 307 of file Home.C.

308 {
309  return makeStaticModel(boost::bind(createWidget, this));
310 }

Member Data Documentation

WStackedWidget* Home::contents_
private

Definition at line 101 of file Home.h.

WTabWidget* Home::examplesMenu_
protected

Definition at line 89 of file Home.h.

WWidget* Home::homePage_
private

Definition at line 98 of file Home.h.

int Home::language_
private

Definition at line 117 of file Home.h.

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

Definition at line 132 of file Home.h.

WMenu* Home::mainMenu_
private

Definition at line 115 of file Home.h.

WTable* Home::releases_
protected

Definition at line 94 of file Home.h.

WContainerWidget* Home::sideBarContent_
private

Definition at line 130 of file Home.h.

WWidget* Home::sourceViewer_
private

Definition at line 99 of file Home.h.


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

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1