Wt examples  3.2.3
/home/koen/project/wt/public-git/wt/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,
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   WWidget *homePage_;
00099   WWidget *sourceViewer_;
00100 
00101   WStackedWidget *contents_;
00102 
00103   void createHome();
00104 
00105   WWidget *introduction();
00106   WWidget *blog();
00107   WWidget *status();
00108   WWidget *features();
00109   WWidget *documentation();
00110   WWidget *community();
00111   WWidget *otherLanguage();
00112   WWidget *download();
00113   WWidget *quoteForm();
00114 
00115   WMenu *mainMenu_;
00116 
00117   int language_;
00118 
00119   void readNews(WTable *newsTable, const std::string& newsfile);
00120   
00121   WWidget *wrapView(WWidget *(Home::*createFunction)());
00122 
00123   void updateTitle();
00124   void setLanguage(int language);
00125   void setLanguageFromPath();
00126   void setup();
00127   void logInternalPath(const std::string& path);
00128   void chatSetUser(const WString& name);
00129 
00130   WContainerWidget *sideBarContent_;
00131   
00132   std::vector<Lang> languages;
00133 };
00134 
00135 #endif // HOME_H_

Generated on Thu Nov 1 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1