#include <Home.h>
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 WWidget * | examples ()=0 |
virtual WWidget * | download ()=0 |
virtual WWidget * | sourceViewer (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 | |
WTabWidget * | examplesMenu_ |
WTable * | releases_ |
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) |
WWidget * | wrapView (WWidget *(Home::*createFunction)()) |
void | updateTitle () |
void | setLanguage (int language) |
void | setLanguageFromPath () |
void | setup () |
void | logInternalPath (const std::string &path) |
Private Attributes | |
WWidget * | homePage_ |
WWidget * | sourceViewer_ |
WStackedWidget * | contents_ |
WMenu * | mainMenu_ |
int | language_ |
WContainerWidget * | sideBarContent_ |
std::vector< Lang > | languages |
Definition at line 66 of file Home.h.
Home::Home | ( | const WEnvironment & | env, |
const std::string & | title, | ||
const std::string & | resourceBundle, | ||
const std::string & | cssPath | ||
) |
Definition at line 47 of file Home.C.
: WApplication(env), releases_(0), homePage_(0), sourceViewer_(0) { messageResourceBundle().use(resourceBundle, false); useStyleSheet(cssPath + "/wt.css"); useStyleSheet(cssPath + "/wt_ie.css", "lt IE 7"); useStyleSheet("css/home.css"); useStyleSheet("css/sourceview.css"); setTitle(title); setLocale(""); language_ = 0; }
void Home::addLanguage | ( | const Lang & | l ) | [inline, protected] |
WWidget * Home::blog | ( | ) | [private] |
WWidget * Home::community | ( | ) | [private] |
WWidget * Home::documentation | ( | ) | [private] |
WWidget * Home::features | ( | ) | [private] |
virtual std::string Home::filePrefix | ( | ) | const [protected, pure virtual] |
void Home::googleAnalyticsLogger | ( | ) |
Definition at line 350 of file Home.C.
{ std::string googleCmd = "if (window.pageTracker)" " window.pageTracker._trackPageview(\"" + environment().deploymentPath() + internalPath() + "\");"; doJavaScript(googleCmd); }
std::string Home::href | ( | const std::string & | url, |
const std::string & | description | ||
) | [protected] |
void Home::init | ( | ) | [protected] |
Definition at line 65 of file Home.C.
{ internalPathChanged().connect(SLOT(this, Home::setup)); internalPathChanged().connect(SLOT(this, Home::setLanguageFromPath)); internalPathChanged().connect(SLOT(this, Home::logInternalPath)); setup(); }
WWidget * Home::initHome | ( | ) | [private] |
Definition at line 110 of file Home.C.
{ WContainerWidget *result = new WContainerWidget(root()); Div *topWrapper = new Div(result, "top_wrapper"); Div *topContent = new Div(topWrapper, "top_content"); Div *languagesDiv = new Div(topContent, "top_languages"); for (unsigned i = 0; i < languages.size(); ++i) { if (i != 0) new WText("- ", languagesDiv); const Lang& l = languages[i]; WAnchor *a = new WAnchor("", WString::fromUTF8(l.longDescription_), languagesDiv); a->setRefInternalPath(l.path_); } WText *topWt = new WText(tr("top_wt"), topContent); topWt->setInline(false); topWt->setId("top_wt"); WText *bannerWt = new WText(tr("banner_wrapper"), result); bannerWt->setId("banner_wrapper"); Div *mainWrapper = new Div(result, "main_wrapper"); Div *mainContent = new Div(mainWrapper, "main_content"); Div *mainMenu = new Div(mainContent, "main_menu"); WStackedWidget *contents = new WStackedWidget(); contents->setId("main_page"); mainMenu_ = new WMenu(contents, Vertical, mainMenu); mainMenu_->setRenderAsList(true); mainMenu_->addItem (tr("introduction"), introduction())->setPathComponent(""); mainMenu_->addItem (tr("blog"), deferCreate(boost::bind(&Home::blog, this))); mainMenu_->addItem (tr("features"), wrapView(&Home::features), WMenuItem::PreLoading); mainMenu_->addItem (tr("documentation"), wrapView(&Home::documentation), WMenuItem::PreLoading); mainMenu_->addItem (tr("examples"), examples(), WMenuItem::PreLoading)->setPathComponent("examples/"); mainMenu_->addItem (tr("download"), deferCreate(boost::bind(&Home::download, this)), WMenuItem::PreLoading); mainMenu_->addItem (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading); mainMenu_->addItem (tr("other-language"), wrapView(&Home::otherLanguage), WMenuItem::PreLoading); mainMenu_->itemSelectRendered().connect(SLOT(this, Home::updateTitle)); mainMenu_->itemSelected().connect(SLOT(this, Home::googleAnalyticsLogger)); // Make the menu be internal-path aware. mainMenu_->setInternalPathEnabled("/"); sideBarContent_ = new WContainerWidget(mainMenu); mainContent->addWidget(contents); WContainerWidget *clearAll = new WContainerWidget(mainContent); clearAll->setStyleClass("clearall"); WText *footerWrapper = new WText(tr("footer_wrapper"), result); footerWrapper->setId("footer_wrapper"); return result; }
WWidget * Home::introduction | ( | ) | [private] |
WWidget * Home::linkSourceBrowser | ( | const std::string & | examplePath ) | [protected] |
Definition at line 209 of file Home.C.
{ WAnchor *a = new WAnchor("", tr("source-browser")); a->setRefInternalPath("/" + SRC_INTERNAL_PATH + "/" + example); return a; }
void Home::logInternalPath | ( | const std::string & | path ) | [private] |
Definition at line 245 of file Home.C.
{ // simulate an access log for the interal paths log("path") << path; // If this goes to /src, we need to invoke google analytics method too if (path.size() >= 4 && path.substr(0, 4) == "/src") { googleAnalyticsLogger(); } }
WWidget * Home::otherLanguage | ( | ) | [private] |
void Home::readNews | ( | WTable * | newsTable, |
const std::string & | newsfile | ||
) | [private] |
void Home::readReleases | ( | WTable * | releaseTable ) | [protected] |
Definition at line 301 of file Home.C.
{ std::ifstream f((filePrefix() + "releases.txt").c_str()); releaseTable->clear(); releaseTable->elementAt(0, 0) ->addWidget(new WText(tr("home.download.version"))); releaseTable->elementAt(0, 1) ->addWidget(new WText(tr("home.download.date"))); releaseTable->elementAt(0, 2) ->addWidget(new WText(tr("home.download.description"))); releaseTable->elementAt(0, 0)->resize(WLength(15, WLength::FontEx), WLength::Auto); releaseTable->elementAt(0, 1)->resize(WLength(15, WLength::FontEx), WLength::Auto); int row = 1; while (f) { std::string line; getline(f, line); if (f) { typedef boost::tokenizer<boost::escaped_list_separator<char> > CsvTokenizer; CsvTokenizer tok(line); CsvTokenizer::iterator i=tok.begin(); std::string fileName = *i; std::string description = *(++i); releaseTable->elementAt(row, 0)->addWidget (new WText(href("http://prdownloads.sourceforge.net/witty/" + fileName + "?download", description))); releaseTable->elementAt(row, 1)->addWidget(new WText(*(++i))); releaseTable->elementAt(row, 2)->addWidget(new WText(*(++i))); ++row; } } }
void Home::setLanguage | ( | int | language ) | [private] |
Definition at line 193 of file Home.C.
{ if (homePage_) { const Lang& l = languages[index]; setLocale(l.code_); std::string langPath = l.path_; mainMenu_->setInternalBasePath(langPath); examplesMenu_->setInternalBasePath(langPath + "examples"); updateTitle(); language_ = index; } }
void Home::setLanguageFromPath | ( | ) | [private] |
Definition at line 216 of file Home.C.
{ std::string langPath = internalPathNextPart("/"); if (langPath.empty()) langPath = '/'; else langPath = '/' + langPath + '/'; int newLanguage = 0; for (unsigned i = 0; i < languages.size(); ++i) { if (languages[i].path_ == langPath) { newLanguage = i; break; } } if (newLanguage != language_) setLanguage(newLanguage); }
void Home::setup | ( | ) | [private] |
Definition at line 74 of file Home.C.
{ /* * This function switches between the two major components of the homepage, * depending on the internal path: * /src -> source viewer * /... -> homepage */ std::string base = internalPathNextPart("/"); if (base == SRC_INTERNAL_PATH) { if (!sourceViewer_) { delete homePage_; homePage_ = 0; root()->clear(); sourceViewer_ = sourceViewer("/" + SRC_INTERNAL_PATH + "/"); WVBoxLayout *layout = new WVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(sourceViewer_); root()->setLayout(layout); } } else { if (!homePage_) { delete sourceViewer_; sourceViewer_ = 0; root()->clear(); homePage_ = initHome(); root()->addWidget(homePage_); } } }
virtual WWidget* Home::sourceViewer | ( | const std::string & | deployPath ) | [protected, pure virtual] |
WWidget * Home::status | ( | ) | [private] |
WString Home::tr | ( | const char * | key ) | [protected] |
Definition at line 345 of file Home.C.
{ return WString::tr(key); }
void Home::updateTitle | ( | ) | [private] |
Definition at line 238 of file Home.C.
{ if (mainMenu_->currentItem()) { setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text()); } }
WStackedWidget* Home::contents_ [private] |
WTabWidget* Home::examplesMenu_ [protected] |
WWidget* Home::homePage_ [private] |
int Home::language_ [private] |
std::vector<Lang> Home::languages [private] |
WMenu* Home::mainMenu_ [private] |
WTable* Home::releases_ [protected] |
WContainerWidget* Home::sideBarContent_ [private] |
WWidget* Home::sourceViewer_ [private] |