Wt examples 3.3.12
Home.h
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7#ifndef HOME_H_
8#define HOME_H_
9
10#include <Wt/WApplication>
11#include <Wt/WContainerWidget>
12
13namespace Wt {
14 class WMenu;
15 class WStackedWidget;
16 class WTabWidget;
17 class WTreeNode;
18 class WTable;
19}
20
21using namespace Wt;
22
23struct Lang {
24 Lang(const std::string& code, const std::string& path,
25 const std::string& shortDescription,
26 const std::string& longDescription) :
27 code_(code),
28 path_(path),
29 shortDescription_(shortDescription),
30 longDescription_(longDescription) {
31 }
32
34};
35
36/*
37 * A utility container widget which defers creation of its single
38 * child widget until the container is loaded (which is done on-demand
39 * by a WMenu). The constructor takes the create function for the
40 * widget as a parameter.
41 *
42 * We use this to defer widget creation until needed.
43 */
44template <typename Function>
46{
47public:
48 DeferredWidget(Function f)
49 : f_(f) { }
50
51private:
52 void load() {
53 WContainerWidget::load();
54 if (count() == 0)
55 addWidget(f_());
56 }
57
58 Function f_;
59};
60
61template <typename Function>
63{
64 return new DeferredWidget<Function>(f);
65}
66
67class Home : public WApplication
68{
69public:
71 const std::string& title,
72 const std::string& resourceBundle, const std::string& cssPath);
73
74 virtual ~Home();
75
77
78protected:
79 virtual WWidget *examples() = 0;
80 virtual WWidget *createQuoteForm() = 0;
81 virtual WWidget *sourceViewer(const std::string &deployPath) = 0;
82 virtual std::string filePrefix() const = 0;
83
84 void init();
85
86 void addLanguage(const Lang& l) { languages.push_back(l); }
87 WWidget *linkSourceBrowser(const std::string& examplePath);
88
90
91 WString tr(const char *key);
92 std::string href(const std::string& url, const std::string& description);
93
95 void readReleases(WTable *releaseTable);
96
97private:
101
103
104 void createHome();
105
107 WWidget *blog();
108 WWidget *status();
109 WWidget *features();
113 WWidget *download();
115
117
119
120 void readNews(WTable *newsTable, const std::string& newsfile);
121
122 WWidget *wrapView(WWidget *(Home::*createFunction)());
123
124 void updateTitle();
125 void setLanguage(int language);
126 void setLanguageFromPath();
127 void setup();
128 void logInternalPath(const std::string& path);
129 void chatSetUser(const WString& name);
130
132
133 std::vector<Lang> languages;
134};
135
136#endif // HOME_H_
DeferredWidget< Function > * deferCreate(Function f)
Definition Home.h:62
void load()
Definition Home.h:52
DeferredWidget(Function f)
Definition Home.h:48
Function f_
Definition Home.h:58
Definition Home.h:68
void setup()
Definition Home.C:73
WWidget * otherLanguage()
Definition Home.C:305
WWidget * status()
Definition Home.C:288
WWidget * features()
Definition Home.C:293
void readNews(WTable *newsTable, const std::string &newsfile)
void createHome()
Definition Home.C:113
WStackedWidget * contents_
Definition Home.h:102
WTable * releases_
Definition Home.h:94
WWidget * download()
Definition Home.C:398
void addLanguage(const Lang &l)
Definition Home.h:86
WTabWidget * examplesMenu_
Definition Home.h:89
void googleAnalyticsLogger()
Definition Home.C:426
WWidget * blog()
Definition Home.C:258
WWidget * introduction()
Definition Home.C:253
WWidget * community()
Definition Home.C:320
std::string href(const std::string &url, const std::string &description)
Definition Home.C:315
WWidget * documentation()
Definition Home.C:298
int language_
Definition Home.h:118
void setLanguage(int language)
Definition Home.C:181
WWidget * homePage_
Definition Home.h:99
WWidget * wrapView(WWidget *(Home::*createFunction)())
Definition Home.C:310
void init()
Definition Home.C:62
WWidget * linkSourceBrowser(const std::string &examplePath)
Definition Home.C:200
void updateTitle()
Definition Home.C:235
virtual ~Home()
Definition Home.C:34
WString tr(const char *key)
Definition Home.C:421
virtual std::string filePrefix() const =0
WWidget * sourceViewer_
Definition Home.h:100
virtual WWidget * examples()=0
virtual WWidget * sourceViewer(const std::string &deployPath)=0
virtual WWidget * createQuoteForm()=0
WMenu * mainMenu_
Definition Home.h:116
void readReleases(WTable *releaseTable)
Definition Home.C:325
WContainerWidget * sideBarContent_
Definition Home.h:131
void logInternalPath(const std::string &path)
Definition Home.C:242
Wt::Dbo::SqlConnectionPool & blogDb_
Definition Home.h:98
std::vector< Lang > languages
Definition Home.h:133
WWidget * quoteForm()
void setLanguageFromPath()
Definition Home.C:213
void chatSetUser(const WString &name)
Definition Home.C:274
WEnvironment & env()
std::string url(const std::string &internalPath=std::string()) const
const WString & title() const
virtual int count() const
virtual void addWidget(WWidget *widget)
Definition Home.h:23
std::string longDescription_
Definition Home.h:33
Lang(const std::string &code, const std::string &path, const std::string &shortDescription, const std::string &longDescription)
Definition Home.h:24
std::string shortDescription_
Definition Home.h:33
std::string code_
Definition Home.h:33
std::string path_
Definition Home.h:33

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8