Home Class Reference

#include <Home.h>

Inheritance diagram for Home:

Inheritance graph
[legend]

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)
WWidgetlinkSourceBrowser (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

WWidgetinitHome ()
WWidgetintroduction ()
WWidgetnews ()
WWidgetstatus ()
WWidgetfeatures ()
WWidgetdocumentation ()
WWidgetcommunity ()
WWidgetotherLanguage ()
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_
WTablerecentNews_
WTablehistoricalNews_
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 
)

Definition at line 50 of file Home.C.

00052   : WApplication(env),
00053     recentNews_(0),
00054     historicalNews_(0),
00055     releases_(0),
00056     homePage_(0),
00057     sourceViewer_(0)
00058 {
00059   messageResourceBundle().use(resourceBundle, false);
00060   useStyleSheet(cssPath + "/wt.css");
00061   useStyleSheet(cssPath + "/wt_ie.css", "lt IE 7");
00062   useStyleSheet("home.css");
00063   useStyleSheet("sourceview.css");
00064   setTitle(title);
00065 
00066   setLocale("");
00067   language_ = 0;
00068 }

Home::~Home (  )  [virtual]

Definition at line 46 of file Home.C.

00047 {
00048 }


Member Function Documentation

void Home::googleAnalyticsLogger (  ) 

Definition at line 401 of file Home.C.

00402 {
00403   std::string googleCmd = 
00404     "if (pageTracker)"
00405     "  pageTracker._trackPageview(\"" + environment().deploymentPath() +
00406     internalPath() + "\");";
00407 
00408   doJavaScript(googleCmd);
00409 }

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

Implemented in JWtHome, and WtHome.

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

Implemented in JWtHome, and WtHome.

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

Implemented in JWtHome, and WtHome.

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

Implemented in JWtHome, and WtHome.

void Home::init (  )  [protected]

Definition at line 70 of file Home.C.

00071 {
00072   internalPathChanged().connect(SLOT(this, Home::setup));
00073   internalPathChanged().connect(SLOT(this, Home::setLanguageFromPath));
00074   internalPathChanged().connect(SLOT(this, Home::logInternalPath));
00075 
00076   setup();
00077 }

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

Definition at line 85 of file Home.h.

00085 { languages.push_back(l); }

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

Definition at line 214 of file Home.C.

00215 {
00216   WAnchor *a = new WAnchor("", tr("source-browser"));
00217   a->setRefInternalPath("/" + SRC_INTERNAL_PATH + "/" + example);
00218   return a;
00219 }

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

Definition at line 396 of file Home.C.

00397 {
00398   return WString::tr(key);
00399 }

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

Definition at line 309 of file Home.C.

00310 {
00311   return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
00312 }

void Home::readReleases ( WTable releaseTable  )  [protected]

Definition at line 352 of file Home.C.

00353 {
00354   std::ifstream f((filePrefix() + "releases.txt").c_str());
00355 
00356   releaseTable->clear();
00357 
00358   releaseTable->elementAt(0, 0)
00359     ->addWidget(new WText(tr("home.download.version")));
00360   releaseTable->elementAt(0, 1)
00361     ->addWidget(new WText(tr("home.download.date")));
00362   releaseTable->elementAt(0, 2)
00363     ->addWidget(new WText(tr("home.download.description")));
00364 
00365   releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx),
00366                                         WLength::Auto);
00367   releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx),
00368                                         WLength::Auto);
00369 
00370   int row = 1;
00371 
00372   while (f) {
00373     std::string line;
00374     getline(f, line);
00375 
00376     if (f) {
00377       typedef boost::tokenizer<boost::escaped_list_separator<char> >
00378         CsvTokenizer;
00379       CsvTokenizer tok(line);
00380 
00381       CsvTokenizer::iterator i=tok.begin();
00382 
00383       std::string fileName = *i;
00384       std::string description = *(++i);
00385       releaseTable->elementAt(row, 0)->addWidget
00386         (new WText(href("http://prdownloads.sourceforge.net/witty/" 
00387                         + fileName + "?download", description)));
00388       releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i)));
00389       releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i)));
00390 
00391       ++row;
00392     }
00393   }
00394 }

WWidget * Home::initHome (  )  [private]

Definition at line 115 of file Home.C.

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

WWidget * Home::introduction (  )  [private]

Definition at line 260 of file Home.C.

00261 {
00262   return new WText(tr("home.intro"));
00263 }

WWidget * Home::news (  )  [private]

Definition at line 265 of file Home.C.

00266 {
00267   WContainerWidget *result = new WContainerWidget();
00268 
00269   result->addWidget(new WText(tr("home.news")));
00270 
00271   result->addWidget(new WText(tr("home.latest-news")));
00272   recentNews_ = new WTable();
00273   readNews(recentNews_, filePrefix() + "latest-news.txt");
00274   result->addWidget(recentNews_);
00275 
00276   result->addWidget(new WText(tr("home.historical-news")));
00277   historicalNews_ = new WTable();
00278   readNews(historicalNews_, filePrefix() + "historical-news.txt");
00279   result->addWidget(historicalNews_);
00280 
00281   return result;
00282 }

WWidget * Home::status (  )  [private]

Definition at line 284 of file Home.C.

00285 {
00286   return new WText(tr("home.status"));
00287 }

WWidget * Home::features (  )  [private]

Definition at line 289 of file Home.C.

00290 {
00291   return new WText(tr("home.features"));
00292 }

WWidget * Home::documentation (  )  [private]

Definition at line 294 of file Home.C.

00295 {
00296   return new WText(tr("home.documentation"));
00297 }

WWidget * Home::community (  )  [private]

Definition at line 314 of file Home.C.

00315 {
00316   return new WText(tr("home.community"));
00317 }

WWidget * Home::otherLanguage (  )  [private]

Definition at line 299 of file Home.C.

00300 {
00301   return new WText(tr("home.other-language"));
00302 }

void Home::readNews ( WTable newsTable,
const std::string &  newsfile 
) [private]

Definition at line 319 of file Home.C.

00320 {
00321   std::ifstream f(newsfile.c_str());
00322 
00323   newsTable->clear();
00324 
00325   int row = 0;
00326 
00327   while (f) {
00328     std::string line;
00329     getline(f, line);
00330 
00331     if (f) {
00332       typedef boost::tokenizer<boost::escaped_list_separator<char> >
00333         CsvTokenizer;
00334       CsvTokenizer tok(line);
00335 
00336       CsvTokenizer::iterator i=tok.begin();
00337 
00338       newsTable->elementAt(row, 0)->
00339         addWidget(new WText("<p><b>" + *i + "</b></p>"));
00340       newsTable->elementAt(row, 0)
00341         ->setContentAlignment(AlignCenter | AlignTop);
00342       newsTable->elementAt(row, 0)
00343         ->resize(WLength(16, WLength::FontEx), WLength::Auto);
00344       newsTable
00345         ->elementAt(row, 1)->addWidget(new WText("<p>" + *(++i) + "</p>"));
00346 
00347       ++row;
00348     }
00349   }
00350 }

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

Definition at line 304 of file Home.C.

00305 {
00306   return makeStaticModel(boost::bind(createWidget, this));
00307 }

void Home::updateTitle (  )  [private]

Definition at line 243 of file Home.C.

00244 {
00245   if (mainMenu_->currentItem()) {
00246     setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
00247   }
00248 }

void Home::setLanguage ( int  language  )  [private]

Definition at line 198 of file Home.C.

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

void Home::setLanguageFromPath (  )  [private]

Definition at line 221 of file Home.C.

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

void Home::setup (  )  [private]

Definition at line 79 of file Home.C.

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

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

Definition at line 250 of file Home.C.

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


Member Data Documentation

Definition at line 88 of file Home.h.

WTable* Home::releases_ [protected]

Definition at line 93 of file Home.h.

Definition at line 97 of file Home.h.

Definition at line 98 of file Home.h.

Definition at line 100 of file Home.h.

Definition at line 112 of file Home.h.

Definition at line 113 of file Home.h.

WMenu* Home::mainMenu_ [private]

Definition at line 115 of file Home.h.

int Home::language_ [private]

Definition at line 117 of file Home.h.

Definition at line 129 of file Home.h.

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

Definition at line 131 of file Home.h.


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

Generated on Tue Nov 3 15:34:40 2009 for Wt by doxygen 1.5.6