Wt examples  3.3.0
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 
13 namespace Wt {
14  class WMenu;
15  class WStackedWidget;
16  class WTabWidget;
17  class WTreeNode;
18  class WTable;
19 }
20 
21 using namespace Wt;
22 
23 struct 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 
33  std::string code_, path_, shortDescription_, longDescription_;
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  */
44 template <typename Function>
46 {
47 public:
48  DeferredWidget(Function f)
49  : f_(f) { }
50 
51 private:
52  void load() {
54  if (count() == 0)
55  addWidget(f_());
56  }
57 
58  Function f_;
59 };
60 
61 template <typename Function>
63 {
64  return new DeferredWidget<Function>(f);
65 }
66 
67 class Home : public WApplication
68 {
69 public:
70  Home(const WEnvironment& env,
71  const std::string& title,
72  const std::string& resourceBundle, const std::string& cssPath);
73 
74  virtual ~Home();
75 
76  void googleAnalyticsLogger();
77 
78 protected:
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 
97 private:
100 
102 
103  void createHome();
104 
105  WWidget *introduction();
106  WWidget *blog();
107  WWidget *status();
108  WWidget *features();
109  WWidget *documentation();
110  WWidget *community();
111  WWidget *otherLanguage();
112  WWidget *download();
113  WWidget *quoteForm();
114 
116 
118 
119  void readNews(WTable *newsTable, const std::string& newsfile);
120 
121  WWidget *wrapView(WWidget *(Home::*createFunction)());
122 
123  void updateTitle();
124  void setLanguage(int language);
125  void setLanguageFromPath();
126  void setup();
127  void logInternalPath(const std::string& path);
128  void chatSetUser(const WString& name);
129 
131 
132  std::vector<Lang> languages;
133 };
134 
135 #endif // HOME_H_

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