Home Class Reference

#include <Home.h>

Inherits Wt::WApplication.

Inherited by JWtHome, and WtHome.

List of all members.

Public Member Functions

 Home (const WEnvironment &env, const std::string &title, const std::string &resourceBundle, const std::string &cssPath)
virtual ~Home ()
void googleAnalyticsLogger ()

Protected Member Functions

virtual WWidgetexamples ()=0
virtual WWidgetdownload ()=0
virtual WWidgetsourceViewer (const std::string &deployPath)=0
virtual std::string filePrefix () const =0
void init ()
void addLanguage (const Lang &l)
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)

Protected Attributes

WTabWidgetexamplesMenu_
WTablereleases_

Private Member Functions

WWidget * initHome ()
WWidget * introduction ()
WWidget * blog ()
WWidget * status ()
WWidget * features ()
WWidget * documentation ()
WWidget * community ()
WWidget * otherLanguage ()
void readNews (WTable *newsTable, const std::string &newsfile)
WWidgetwrapView (WWidget *(Home::*createFunction)())
void updateTitle ()
void setLanguage (int language)
void setLanguageFromPath ()
void setup ()
void logInternalPath (const std::string &path)

Private Attributes

WWidgethomePage_
WWidgetsourceViewer_
WStackedWidgetcontents_
WMenumainMenu_
int language_
WContainerWidgetsideBarContent_
std::vector< Langlanguages

Detailed Description

Definition at line 66 of file Home.h.


Constructor & Destructor Documentation

Home::Home ( const WEnvironment env,
const std::string &  title,
const std::string &  resourceBundle,
const std::string &  cssPath 
)
Home::~Home (  )  [virtual]

Definition at line 43 of file Home.C.

00044 {
00045 }


Member Function Documentation

void Home::addLanguage ( const Lang l  )  [inline, protected]

Definition at line 85 of file Home.h.

00085 { languages.push_back(l); }

WWidget * Home::blog (  )  [private]

Definition at line 261 of file Home.C.

00262 {
00263   return new BlogView("/blog/", "blog.db", "/wt/blog/feed/");
00264 }

WWidget * Home::community (  )  [private]

Definition at line 296 of file Home.C.

00297 {
00298   return new WText(tr("home.community"));
00299 }

WWidget * Home::documentation (  )  [private]

Definition at line 276 of file Home.C.

00277 {
00278   return new WText(tr("home.documentation"));
00279 }

virtual WWidget* Home::download (  )  [protected, pure virtual]

Implemented in JWtHome, and WtHome.

virtual WWidget* Home::examples (  )  [protected, pure virtual]

Implemented in JWtHome, and WtHome.

WWidget * Home::features (  )  [private]

Definition at line 271 of file Home.C.

00272 {
00273   return new WText(tr("home.features"));
00274 }

virtual std::string Home::filePrefix (  )  const [protected, pure virtual]

Implemented in JWtHome, and WtHome.

void Home::googleAnalyticsLogger (  ) 

Definition at line 350 of file Home.C.

00351 {
00352   std::string googleCmd = 
00353     "if (window.pageTracker)"
00354     "  window.pageTracker._trackPageview(\"" + environment().deploymentPath() +
00355     internalPath() + "\");";
00356 
00357   doJavaScript(googleCmd);
00358 }

std::string Home::href ( const std::string &  url,
const std::string &  description 
) [protected]

Definition at line 291 of file Home.C.

00292 {
00293   return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
00294 }

void Home::init (  )  [protected]

Definition at line 65 of file Home.C.

00066 {
00067   internalPathChanged().connect(SLOT(this, Home::setup));
00068   internalPathChanged().connect(SLOT(this, Home::setLanguageFromPath));
00069   internalPathChanged().connect(SLOT(this, Home::logInternalPath));
00070 
00071   setup();
00072 }

WWidget * Home::initHome (  )  [private]

Definition at line 110 of file Home.C.

00111 {
00112   WContainerWidget *result = new WContainerWidget(root());
00113   Div *topWrapper = new Div(result, "top_wrapper");
00114   Div *topContent = new Div(topWrapper, "top_content");
00115 
00116   Div *languagesDiv = new Div(topContent, "top_languages");
00117 
00118   for (unsigned i = 0; i < languages.size(); ++i) {
00119     if (i != 0)
00120       new WText("- ", languagesDiv);
00121 
00122     const Lang& l = languages[i];
00123 
00124     WAnchor *a = new WAnchor("", WString::fromUTF8(l.longDescription_),
00125                              languagesDiv);
00126     a->setRefInternalPath(l.path_);
00127   }
00128 
00129   WText *topWt = new WText(tr("top_wt"), topContent);
00130   topWt->setInline(false);
00131   topWt->setId("top_wt");
00132 
00133   WText *bannerWt = new WText(tr("banner_wrapper"), result);
00134   bannerWt->setId("banner_wrapper");
00135 
00136   Div *mainWrapper = new Div(result, "main_wrapper");
00137   Div *mainContent = new Div(mainWrapper, "main_content");
00138   Div *mainMenu = new Div(mainContent, "main_menu");
00139 
00140   WStackedWidget *contents = new WStackedWidget();
00141   contents->setId("main_page");
00142 
00143   mainMenu_ = new WMenu(contents, Vertical, mainMenu);
00144   mainMenu_->setRenderAsList(true);
00145 
00146   mainMenu_->addItem
00147     (tr("introduction"), introduction())->setPathComponent("");
00148 
00149   mainMenu_->addItem
00150     (tr("blog"), deferCreate(boost::bind(&Home::blog, this)));
00151 
00152   mainMenu_->addItem
00153     (tr("features"), wrapView(&Home::features),  WMenuItem::PreLoading);
00154 
00155   mainMenu_->addItem
00156     (tr("documentation"), wrapView(&Home::documentation),
00157      WMenuItem::PreLoading);
00158 
00159   mainMenu_->addItem
00160     (tr("examples"), examples(),
00161      WMenuItem::PreLoading)->setPathComponent("examples/");
00162 
00163   mainMenu_->addItem
00164     (tr("download"), deferCreate(boost::bind(&Home::download, this)),
00165      WMenuItem::PreLoading);
00166 
00167   mainMenu_->addItem
00168     (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading);
00169 
00170   mainMenu_->addItem
00171     (tr("other-language"), wrapView(&Home::otherLanguage),
00172      WMenuItem::PreLoading);
00173 
00174   mainMenu_->itemSelectRendered().connect(SLOT(this, Home::updateTitle));
00175 
00176   mainMenu_->itemSelected().connect(SLOT(this, Home::googleAnalyticsLogger));
00177 
00178   // Make the menu be internal-path aware.
00179   mainMenu_->setInternalPathEnabled("/");
00180 
00181   sideBarContent_ = new WContainerWidget(mainMenu);
00182 
00183   mainContent->addWidget(contents);
00184   WContainerWidget *clearAll = new WContainerWidget(mainContent);
00185   clearAll->setStyleClass("clearall");
00186 
00187   WText *footerWrapper = new WText(tr("footer_wrapper"), result);
00188   footerWrapper->setId("footer_wrapper");
00189 
00190   return result;
00191 }

WWidget * Home::introduction (  )  [private]

Definition at line 256 of file Home.C.

00257 {
00258   return new WText(tr("home.intro"));
00259 }

WWidget * Home::linkSourceBrowser ( const std::string &  examplePath  )  [protected]

Definition at line 209 of file Home.C.

00210 {
00211   WAnchor *a = new WAnchor("", tr("source-browser"));
00212   a->setRefInternalPath("/" + SRC_INTERNAL_PATH + "/" + example);
00213   return a;
00214 }

void Home::logInternalPath ( const std::string &  path  )  [private]

Definition at line 245 of file Home.C.

00246 {
00247   // simulate an access log for the interal paths
00248   log("path") << path;
00249 
00250   // If this goes to /src, we need to invoke google analytics method too
00251   if (path.size() >= 4 && path.substr(0, 4) == "/src") {
00252     googleAnalyticsLogger();
00253   }
00254 }

WWidget * Home::otherLanguage (  )  [private]

Definition at line 281 of file Home.C.

00282 {
00283   return new WText(tr("home.other-language"));
00284 }

void Home::readNews ( WTable newsTable,
const std::string &  newsfile 
) [private]
void Home::readReleases ( WTable releaseTable  )  [protected]
void Home::setLanguage ( int  language  )  [private]

Definition at line 193 of file Home.C.

00194 {
00195   if (homePage_) {
00196     const Lang& l = languages[index];
00197 
00198     setLocale(l.code_);
00199 
00200     std::string langPath = l.path_;
00201     mainMenu_->setInternalBasePath(langPath);
00202     examplesMenu_->setInternalBasePath(langPath + "examples");
00203     updateTitle();
00204 
00205     language_ = index;
00206   }
00207 }

void Home::setLanguageFromPath (  )  [private]

Definition at line 216 of file Home.C.

00217 {
00218   std::string langPath = internalPathNextPart("/");
00219 
00220   if (langPath.empty())
00221     langPath = '/';
00222   else
00223     langPath = '/' + langPath + '/';
00224 
00225   int newLanguage = 0;
00226 
00227   for (unsigned i = 0; i < languages.size(); ++i) {
00228     if (languages[i].path_ == langPath) {
00229       newLanguage = i;
00230       break;
00231     }
00232   }
00233 
00234   if (newLanguage != language_)
00235     setLanguage(newLanguage);
00236 }

void Home::setup (  )  [private]

Definition at line 74 of file Home.C.

00075 {
00076   /*
00077    * This function switches between the two major components of the homepage,
00078    * depending on the internal path:
00079    * /src -> source viewer
00080    * /... -> homepage
00081    */
00082   std::string base = internalPathNextPart("/");
00083 
00084   if (base == SRC_INTERNAL_PATH) {
00085     if (!sourceViewer_) {
00086       delete homePage_;
00087       homePage_ = 0;
00088 
00089       root()->clear();
00090 
00091       sourceViewer_ = sourceViewer("/" + SRC_INTERNAL_PATH + "/");
00092       WVBoxLayout *layout = new WVBoxLayout();
00093       layout->setContentsMargins(0, 0, 0, 0);
00094       layout->addWidget(sourceViewer_);
00095       root()->setLayout(layout);
00096     }
00097   } else {
00098     if (!homePage_) {
00099       delete sourceViewer_;
00100       sourceViewer_ = 0;
00101 
00102       root()->clear();
00103 
00104       homePage_ = initHome();
00105       root()->addWidget(homePage_);
00106     }
00107   }
00108 }

virtual WWidget* Home::sourceViewer ( const std::string &  deployPath  )  [protected, pure virtual]

Implemented in JWtHome, and WtHome.

WWidget * Home::status (  )  [private]

Definition at line 266 of file Home.C.

00267 {
00268   return new WText(tr("home.status"));
00269 }

WString Home::tr ( const char *  key  )  [protected]

Definition at line 345 of file Home.C.

00346 {
00347   return WString::tr(key);
00348 }

void Home::updateTitle (  )  [private]

Definition at line 238 of file Home.C.

00239 {
00240   if (mainMenu_->currentItem()) {
00241     setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
00242   }
00243 }

WWidget* Home::wrapView ( WWidget *(Home::*)()  createFunction  )  [private]

Member Data Documentation

Definition at line 100 of file Home.h.

Definition at line 88 of file Home.h.

Definition at line 97 of file Home.h.

int Home::language_ [private]

Definition at line 114 of file Home.h.

std::vector<Lang> Home::languages [private]

Definition at line 128 of file Home.h.

WMenu* Home::mainMenu_ [private]

Definition at line 112 of file Home.h.

WTable* Home::releases_ [protected]

Definition at line 93 of file Home.h.

Definition at line 126 of file Home.h.

Definition at line 98 of file Home.h.


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

Generated on Thu May 13 05:16:01 2010 for Wt by doxygen 1.6.3