Wt examples 4.7.1
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
WtHome Class Reference

#include <WtHome.h>

Inheritance diagram for WtHome:
Inheritance graph
[legend]

Public Member Functions

 WtHome (const WEnvironment &env, Dbo::SqlConnectionPool &blogDb)
 
- Public Member Functions inherited from Home
 Home (const WEnvironment &env, Dbo::SqlConnectionPool &blogDb, const std::string &title, const std::string &resourceBundle, const std::string &cssPath)
 
virtual ~Home ()
 
void googleAnalyticsLogger ()
 

Protected Member Functions

virtual std::unique_ptr< WWidget > examples () override
 
virtual std::unique_ptr< WWidget > createQuoteForm () override
 
virtual std::unique_ptr< WWidget > sourceViewer (const std::string &internalPath) override
 
virtual std::string filePrefix () const override
 
- Protected Member Functions inherited from Home
virtual std::unique_ptr< WWidget > examples ()=0
 
virtual std::unique_ptr< WWidget > createQuoteForm ()=0
 
virtual std::unique_ptr< WWidget > sourceViewer (const std::string &deployPath)=0
 
virtual std::string filePrefix () const =0
 
void init ()
 
void addLanguage (const Lang &l)
 
std::unique_ptr< WWidget > linkSourceBrowser (const std::string &examplePath)
 
WString tr (const char *key)
 
std::string href (const std::string &url, const std::string &description)
 
void readReleases (WTable *releaseTable)
 

Private Member Functions

std::unique_ptr< WWidget > example (const char *textKey, const std::string &sourceDir)
 
std::unique_ptr< WWidget > helloWorldExample ()
 
std::unique_ptr< WWidget > chartExample ()
 
std::unique_ptr< WWidget > homepageExample ()
 
std::unique_ptr< WWidget > treeviewExample ()
 
std::unique_ptr< WWidget > gitExample ()
 
std::unique_ptr< WWidget > chatExample ()
 
std::unique_ptr< WWidget > composerExample ()
 
std::unique_ptr< WWidget > widgetGalleryExample ()
 
std::unique_ptr< WWidget > hangmanExample ()
 
std::unique_ptr< WWidget > wrapView (std::unique_ptr< WWidget >(WtHome::*createFunction)())
 

Private Attributes

std::string wtExamplePath_
 

Additional Inherited Members

- Protected Attributes inherited from Home
WTabWidget * examplesMenu_
 
WTable * releases_
 

Detailed Description

Definition at line 16 of file WtHome.h.

Constructor & Destructor Documentation

◆ WtHome()

WtHome::WtHome ( const WEnvironment &  env,
Dbo::SqlConnectionPool &  blogDb 
)

Definition at line 29 of file WtHome.C.

30 : Home(env, blogDb, "Wt, C++ Web Toolkit", "wt-home", "css/wt")
31{
32 addLanguage(Lang("en", "/", "en", "English"));
33 addLanguage(Lang("cn", "/cn/", "汉语", "中文 (Chinese)"));
34 addLanguage(Lang("ru", "/ru/", "ру", "Русский (Russian)"));
35
36 char* wtExamplePath = getenv("WT_EXAMPLE_PATH");
37 if (wtExamplePath)
38 wtExamplePath_ = wtExamplePath;
39 else
40 wtExamplePath_ = "..";
41
42 init();
43}
Home(const WEnvironment &env, Dbo::SqlConnectionPool &blogDb, const std::string &title, const std::string &resourceBundle, const std::string &cssPath)
Definition: Home.C:40
void addLanguage(const Lang &l)
Definition: Home.h:86
void init()
Definition: Home.C:63
std::string wtExamplePath_
Definition: WtHome.h:28
Definition: Home.h:23

Member Function Documentation

◆ chartExample()

std::unique_ptr< WWidget > WtHome::chartExample ( )
private

Definition at line 59 of file WtHome.C.

60{
61 return example("home.examples.chart", "charts");
62}
std::unique_ptr< WWidget > example(const char *textKey, const std::string &sourceDir)
Definition: WtHome.C:45

◆ chatExample()

std::unique_ptr< WWidget > WtHome::chatExample ( )
private

Definition at line 79 of file WtHome.C.

80{
81 return example("home.examples.chat", "simplechat");
82}

◆ composerExample()

std::unique_ptr< WWidget > WtHome::composerExample ( )
private

Definition at line 84 of file WtHome.C.

85{
86 return example("home.examples.composer", "composer");
87}

◆ createQuoteForm()

std::unique_ptr< WWidget > WtHome::createQuoteForm ( )
overrideprotectedvirtual

Implements Home.

Definition at line 153 of file WtHome.C.

154{
155#ifdef WT_EMWEB_BUILD
156 return std::make_unique<QuoteForm>(QuoteForm::Wt);
157#else
158 return nullptr;
159#endif
160}

◆ example()

std::unique_ptr< WWidget > WtHome::example ( const char *  textKey,
const std::string &  sourceDir 
)
private

Definition at line 45 of file WtHome.C.

46{
47 auto result = std::make_unique<WContainerWidget>();
48 WText *w = result->addWidget(std::make_unique<WText>(tr(textKey)));
49 w->setInternalPathEncoding(true);
50 result->addWidget(linkSourceBrowser(sourceDir));
51 return std::move(result);
52}
std::unique_ptr< WWidget > linkSourceBrowser(const std::string &examplePath)
Definition: Home.C:202
WString tr(const char *key)
Definition: Home.C:425

◆ examples()

std::unique_ptr< WWidget > WtHome::examples ( )
overrideprotectedvirtual

Implements Home.

Definition at line 99 of file WtHome.C.

100{
101 auto result = std::make_unique<WContainerWidget>();
102
103 auto intro = std::make_unique<WText>(tr("home.examples"));
104 intro->setInternalPathEncoding(true);
105 result->addWidget(std::move(intro));
106
107 examplesMenu_ = result->addWidget(std::make_unique<WTabWidget>());
108
109 WAnimation animation(AnimationEffect::SlideInFromRight, TimingFunction::EaseIn);
110 examplesMenu_->contentsStack()->setTransitionAnimation(animation, true);
111
112 /*
113 * The following code is functionally equivalent to:
114 *
115 * examplesMenu_->addTab(helloWorldExample(), "Hello world");
116 *
117 * However, we optimize here for memory consumption (it is a homepage
118 * after all, and we hope to be slashdotted some day)
119 *
120 * Therefore, we wrap all the static content (including the tree
121 * widgets), into WViewWidgets with static models. In this way the
122 * widgets are not actually stored in memory on the server.
123 */
124
125 // The call ->setPathComponent() is to use "/examples/" instead of
126 // "/examples/hello_world" as internal path
128 tr("hello-world"))->setPathComponent("");
130 tr("widget-gallery"));
132 tr("charts"));
134 tr("wt-homepage"));
136 tr("treeview"));
138 tr("git"));
140 tr("chat"));
142 tr("mail-composer"));
144 tr("hangman"));
145
146 // Enable internal paths for the example menu
147 examplesMenu_->setInternalPathEnabled("/examples");
148 examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger);
149
150 return std::move(result);
151}
WTabWidget * examplesMenu_
Definition: Home.h:89
void googleAnalyticsLogger()
Definition: Home.C:430
std::unique_ptr< WWidget > wrapView(std::unique_ptr< WWidget >(WtHome::*createFunction)())
Definition: WtHome.C:167
std::unique_ptr< WWidget > composerExample()
Definition: WtHome.C:84
std::unique_ptr< WWidget > widgetGalleryExample()
Definition: WtHome.C:89
std::unique_ptr< WWidget > treeviewExample()
Definition: WtHome.C:69
std::unique_ptr< WWidget > chartExample()
Definition: WtHome.C:59
std::unique_ptr< WWidget > chatExample()
Definition: WtHome.C:79
std::unique_ptr< WWidget > homepageExample()
Definition: WtHome.C:64
std::unique_ptr< WWidget > gitExample()
Definition: WtHome.C:74
std::unique_ptr< WWidget > hangmanExample()
Definition: WtHome.C:94
std::unique_ptr< WWidget > helloWorldExample()
Definition: WtHome.C:54

◆ filePrefix()

virtual std::string WtHome::filePrefix ( ) const
inlineoverrideprotectedvirtual

Implements Home.

Definition at line 25 of file WtHome.h.

25{ return "wt-"; }

◆ gitExample()

std::unique_ptr< WWidget > WtHome::gitExample ( )
private

Definition at line 74 of file WtHome.C.

75{
76 return example("home.examples.git", "gitmodel");
77}

◆ hangmanExample()

std::unique_ptr< WWidget > WtHome::hangmanExample ( )
private

Definition at line 94 of file WtHome.C.

95{
96 return example("home.examples.hangman", "hangman");
97}

◆ helloWorldExample()

std::unique_ptr< WWidget > WtHome::helloWorldExample ( )
private

Definition at line 54 of file WtHome.C.

55{
56 return example("home.examples.hello", "hello");
57}

◆ homepageExample()

std::unique_ptr< WWidget > WtHome::homepageExample ( )
private

Definition at line 64 of file WtHome.C.

65{
66 return example("home.examples.wt", "wt-homepage");
67}

◆ sourceViewer()

std::unique_ptr< WWidget > WtHome::sourceViewer ( const std::string &  internalPath)
overrideprotectedvirtual

Implements Home.

Definition at line 162 of file WtHome.C.

163{
164 return std::make_unique<ExampleSourceViewer>(deployPath, wtExamplePath_ + "/", "CPP");
165}

◆ treeviewExample()

std::unique_ptr< WWidget > WtHome::treeviewExample ( )
private

Definition at line 69 of file WtHome.C.

70{
71 return example("home.examples.treeview", "treeview-dragdrop");
72}

◆ widgetGalleryExample()

std::unique_ptr< WWidget > WtHome::widgetGalleryExample ( )
private

Definition at line 89 of file WtHome.C.

90{
91 return example("home.examples.widgetgallery", "widgetgallery");
92}

◆ wrapView()

std::unique_ptr< WWidget > WtHome::wrapView ( std::unique_ptr< WWidget >(WtHome::*)()  createFunction)
private

Definition at line 167 of file WtHome.C.

168{
169 return makeStaticModel(std::bind(createWidget, this));
170}
std::unique_ptr< Wt::WApplication > createWidget(const Wt::WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:148

Member Data Documentation

◆ wtExamplePath_

std::string WtHome::wtExamplePath_
private

Definition at line 28 of file WtHome.h.


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

Generated on Fri May 6 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.3