Wt examples  3.3.5
/usr/src/RPM/BUILD/wt-3.3.5-rc2/examples/wt-homepage/Home.h
Go to the documentation of this file.
00001 // This may look like C code, but it's really -*- C++ -*-
00002 /*
00003  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
00004  *
00005  * See the LICENSE file for terms of use.
00006  */
00007 #ifndef HOME_H_
00008 #define HOME_H_
00009 
00010 #include <Wt/WApplication>
00011 #include <Wt/WContainerWidget>
00012 
00013 namespace Wt {
00014   class WMenu;
00015   class WStackedWidget;
00016   class WTabWidget;
00017   class WTreeNode;
00018   class WTable;
00019 }
00020 
00021 using namespace Wt;
00022 
00023 struct Lang {
00024   Lang(const std::string& code, const std::string& path,
00025        const std::string& shortDescription,
00026        const std::string& longDescription) :
00027     code_(code),
00028     path_(path),
00029     shortDescription_(shortDescription),
00030     longDescription_(longDescription) {
00031   }
00032 
00033   std::string code_, path_, shortDescription_, longDescription_;
00034 };
00035 
00036 /*
00037  * A utility container widget which defers creation of its single
00038  * child widget until the container is loaded (which is done on-demand
00039  * by a WMenu). The constructor takes the create function for the
00040  * widget as a parameter.
00041  *
00042  * We use this to defer widget creation until needed.
00043  */
00044 template <typename Function>
00045 class DeferredWidget : public WContainerWidget
00046 {
00047 public:
00048   DeferredWidget(Function f)
00049     : f_(f) { }
00050 
00051 private:
00052   void load() {
00053     WContainerWidget::load();
00054     if (count() == 0)
00055       addWidget(f_());
00056   }
00057 
00058   Function f_;
00059 };
00060 
00061 template <typename Function>
00062 DeferredWidget<Function> *deferCreate(Function f)
00063 {
00064   return new DeferredWidget<Function>(f);
00065 }
00066 
00067 class Home : public WApplication
00068 {
00069 public:
00070   Home(const WEnvironment& env, Wt::Dbo::SqlConnectionPool& blogDb,
00071        const std::string& title,
00072        const std::string& resourceBundle, const std::string& cssPath);
00073   
00074   virtual ~Home();
00075 
00076   void googleAnalyticsLogger();
00077 
00078 protected:
00079   virtual WWidget *examples() = 0;
00080   virtual WWidget *createQuoteForm() = 0;
00081   virtual WWidget *sourceViewer(const std::string &deployPath) = 0;
00082   virtual std::string filePrefix() const = 0;
00083 
00084   void init();
00085   
00086   void addLanguage(const Lang& l) { languages.push_back(l); }
00087   WWidget *linkSourceBrowser(const std::string& examplePath);
00088 
00089   WTabWidget *examplesMenu_;
00090   
00091   WString tr(const char *key);
00092   std::string href(const std::string& url, const std::string& description);
00093 
00094   WTable *releases_;
00095   void readReleases(WTable *releaseTable);
00096 
00097 private:
00098   Wt::Dbo::SqlConnectionPool& blogDb_;
00099   WWidget *homePage_;
00100   WWidget *sourceViewer_;
00101 
00102   WStackedWidget *contents_;
00103 
00104   void createHome();
00105 
00106   WWidget *introduction();
00107   WWidget *blog();
00108   WWidget *status();
00109   WWidget *features();
00110   WWidget *documentation();
00111   WWidget *community();
00112   WWidget *otherLanguage();
00113   WWidget *download();
00114   WWidget *quoteForm();
00115 
00116   WMenu *mainMenu_;
00117 
00118   int language_;
00119 
00120   void readNews(WTable *newsTable, const std::string& newsfile);
00121   
00122   WWidget *wrapView(WWidget *(Home::*createFunction)());
00123 
00124   void updateTitle();
00125   void setLanguage(int language);
00126   void setLanguageFromPath();
00127   void setup();
00128   void logInternalPath(const std::string& path);
00129   void chatSetUser(const WString& name);
00130 
00131   WContainerWidget *sideBarContent_;
00132   
00133   std::vector<Lang> languages;
00134 };
00135 
00136 #endif // HOME_H_

Generated on Tue Mar 22 2016 for the C++ Web Toolkit (Wt) by doxygen 1.7.6.1