Wt examples  3.2.2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Home Class Reference

#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 std::string &locale)
std::string locale () 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
::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
WCssStyleSheetstyleSheet ()
void useStyleSheet (const std::string &url)
void useStyleSheet (const std::string &url, const std::string &condition, const std::string &media="all")
void setCssTheme (const std::string &theme)
std::string cssTheme () const
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)
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 ()
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())
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
 WObject (WObject *parent=0)
virtual ~WObject ()
virtual const std::string id () const
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)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)
virtual void removeChild (WObject *child)
const std::vector< WObject * > & children () const
WObjectparent () const

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

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 appRoot ()
static bool readConfigurationProperty (const std::string &name, std::string &value)
- Public Attributes inherited from Wt::WApplication
 XMLHttpRequest
 DynamicScriptTag
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()

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.

: WApplication(env),
{
messageResourceBundle().use(appRoot() + resourceBundle, false);
useStyleSheet(cssPath + "/wt.css");
useStyleSheet(cssPath + "/wt_ie.css", "lt IE 7");
useStyleSheet("css/home.css");
useStyleSheet("css/sourceview.css");
setLocale("");
language_ = 0;
}
Home::~Home ( )
virtual

Definition at line 34 of file Home.C.

{
}

Member Function Documentation

void Home::addLanguage ( const Lang l)
inlineprotected

Definition at line 86 of file Home.h.

{ languages.push_back(l); }
WWidget * Home::blog ( )
private

Definition at line 254 of file Home.C.

{
const Lang& l = languages[language_];
std::string langPath = l.path_;
BlogView *blog = new BlogView(langPath + "blog/",
appRoot() + "blog.db", "/wt/blog/feed/");
blog->setObjectName("blog");
if (!blog->user().empty())
chatSetUser(blog->user());
blog->userChanged().connect(this, &Home::chatSetUser);
return blog;
}
void Home::chatSetUser ( const WString name)
private

Definition at line 270 of file Home.C.

{
("if (window.chat) "
"try {"
"""window.chat.emit(window.chat, 'login', "
"" "" + userName.jsStringLiteral() + "); "
"} catch (e) {"
"""window.chatUser = " + userName.jsStringLiteral() + ";"
"}"
"else "
"""window.chatUser = " + userName.jsStringLiteral() + ";");
}
WWidget * Home::community ( )
private

Definition at line 316 of file Home.C.

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

Definition at line 108 of file Home.C.

{
WTemplate *result = new WTemplate(tr("template"), root());
homePage_ = result;
WContainerWidget *languagesDiv = new WContainerWidget();
languagesDiv->setId("top_languages");
for (unsigned i = 0; i < languages.size(); ++i) {
if (i != 0)
new WText("- ", languagesDiv);
const Lang& l = languages[i];
new WAnchor(WLink(WLink::InternalPath, l.path_),
WString::fromUTF8(l.longDescription_), languagesDiv);
}
WStackedWidget *contents = new WStackedWidget();
WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250);
contents->setTransitionAnimation(fade);
contents->setId("main_page");
mainMenu_ = new WMenu(contents, Vertical);
(tr("introduction"), introduction())->setPathComponent("");
(tr("blog"), deferCreate(boost::bind(&Home::blog, this)));
(tr("features"), wrapView(&Home::features), WMenuItem::PreLoading);
(tr("documentation"), wrapView(&Home::documentation),
WMenuItem::PreLoading);
(tr("examples"), examples(),
WMenuItem::PreLoading)->setPathComponent("examples/");
(tr("download"), deferCreate(boost::bind(&Home::download, this)),
WMenuItem::PreLoading);
(tr("community"), wrapView(&Home::community), WMenuItem::PreLoading);
(tr("other-language"), wrapView(&Home::otherLanguage),
WMenuItem::PreLoading);
// Make the menu be internal-path aware.
result->bindWidget("languages", languagesDiv);
result->bindWidget("menu", mainMenu_);
result->bindWidget("contents", contents);
result->bindWidget("sidebar", sideBarContent_);
}
virtual WWidget* Home::createQuoteForm ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::documentation ( )
private

Definition at line 294 of file Home.C.

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

Definition at line 388 of file Home.C.

{
result->addWidget(new WText(tr("home.download")));
result->addWidget(new WText(tr("home.download.license")));
#ifdef WT_EMWEB_BUILD
result->addWidget(quoteForm());
#endif // WT_EMWEB_BUILD
result->addWidget(new WText(tr("home.download.packages")));
releases_ = new WTable();
result->addWidget(releases_);
result->addWidget(new WText(tr("home.download.other")));
return result;
}
virtual WWidget* Home::examples ( )
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::features ( )
private

Definition at line 289 of file Home.C.

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

Implemented in JWtHome, and WtHome.

void Home::googleAnalyticsLogger ( )

Definition at line 416 of file Home.C.

{
std::string googleCmd =
"if (window.pageTracker) {"
"""try {"
"" "setTimeout(function() {"
"" "window.pageTracker._trackPageview(\""
"" "}, 1000);"
"""} catch (e) { }"
"}";
doJavaScript(googleCmd);
}
std::string Home::href ( const std::string &  url,
const std::string &  description 
)
protected

Definition at line 311 of file Home.C.

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

Definition at line 57 of file Home.C.

WWidget * Home::introduction ( )
private

Definition at line 249 of file Home.C.

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

Definition at line 196 of file Home.C.

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

Definition at line 238 of file Home.C.

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

Definition at line 301 of file Home.C.

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

Definition at line 321 of file Home.C.

{
std::ifstream f((filePrefix() + "releases.txt").c_str());
releaseTable->clear();
releaseTable->elementAt(0, 0)
->addWidget(new WText(tr("home.download.version")));
releaseTable->elementAt(0, 1)
->addWidget(new WText(tr("home.download.date")));
releaseTable->elementAt(0, 2)
->addWidget(new WText(tr("home.download.description")));
releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx),
WLength::Auto);
releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx),
WLength::Auto);
int row = 1;
while (f) {
std::string line;
getline(f, line);
if (f) {
typedef boost::tokenizer<boost::escaped_list_separator<char> >
CsvTokenizer;
CsvTokenizer tok(line);
CsvTokenizer::iterator i=tok.begin();
std::string fileName = *i;
std::string description = *(++i);
releaseTable->elementAt(row, 0)->addWidget
(new WText(href("http://prdownloads.sourceforge.net/witty/"
+ fileName + "?download", description)));
releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i)));
releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i)));
++row;
}
}
}
void Home::setLanguage ( int  language)
private

Definition at line 177 of file Home.C.

{
if (homePage_) {
const Lang& l = languages[index];
std::string langPath = l.path_;
examplesMenu_->setInternalBasePath(langPath + "examples");
BlogView *blog = dynamic_cast<BlogView *>(findWidget("blog"));
if (blog)
blog->setInternalBasePath(langPath + "blog/");
language_ = index;
}
}
void Home::setLanguageFromPath ( )
private

Definition at line 209 of file Home.C.

{
std::string langPath = internalPathNextPart("/");
if (langPath.empty())
langPath = '/';
else
langPath = '/' + langPath + '/';
int newLanguage = 0;
for (unsigned i = 0; i < languages.size(); ++i) {
if (languages[i].path_ == langPath) {
newLanguage = i;
break;
}
}
if (newLanguage != language_)
setLanguage(newLanguage);
}
void Home::setup ( )
private

Definition at line 68 of file Home.C.

{
/*
* This function switches between the two major components of the homepage,
* depending on the internal path:
* /src -> source viewer
* /... -> homepage
*
* FIXME: we should take into account language /cn/src ...
*/
std::string base = internalPathNextPart("/");
if (base == SRC_INTERNAL_PATH) {
if (!sourceViewer_) {
delete homePage_;
homePage_ = 0;
root()->clear();
WVBoxLayout *layout = new WVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
root()->setLayout(layout);
}
} else {
if (!homePage_) {
delete sourceViewer_;
root()->clear();
}
}
}
virtual WWidget* Home::sourceViewer ( const std::string &  deployPath)
protectedpure virtual

Implemented in JWtHome, and WtHome.

WWidget * Home::status ( )
private

Definition at line 284 of file Home.C.

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

Definition at line 411 of file Home.C.

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

Definition at line 231 of file Home.C.

{
setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
}
}
WWidget * Home::wrapView ( WWidget *(Home::*)()  createFunction)
private

Definition at line 306 of file Home.C.

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

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 Mon Oct 29 2012 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2