Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

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 ()
WWidgetblog ()
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)
void chatSetUser (const WString &name)

Private Attributes

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

Detailed Description

Definition at line 67 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 37 of file Home.C.

  : WApplication(env),
    releases_(0),
    homePage_(0),
    sourceViewer_(0)
{
  messageResourceBundle().use(appRoot() + 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;
}
Home::~Home (  ) [virtual]

Definition at line 33 of file Home.C.

{
}

Member Function Documentation

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

Definition at line 86 of file Home.h.

{ languages.push_back(l); }
WWidget * Home::blog (  ) [private]

Definition at line 239 of file Home.C.

{
  BlogView *blog = new BlogView("/blog/", appRoot() + "blog.db", "/wt/blog/feed/");

  if (!blog->user().empty())
    chatSetUser(blog->user());

  blog->userChanged().connect(this, &Home::chatSetUser);

  return blog;
}
void Home::chatSetUser ( const WString name ) [private]

Definition at line 251 of file Home.C.

{
  WApplication::instance()->doJavaScript
    ("if (window.chat) "
     """window.chat.emit(window.chat, 'login', "
     ""                   "" + userName.jsStringLiteral() + "); "
     "else "
     """window.chatUser = " + userName.jsStringLiteral() + ";");
}
WWidget * Home::community (  ) [private]

Definition at line 291 of file Home.C.

{
  return new WText(tr("home.community"));
}
WWidget * Home::documentation (  ) [private]

Definition at line 271 of file Home.C.

{
  return new WText(tr("home.documentation"));
}
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 266 of file Home.C.

{
  return new WText(tr("home.features"));
}
virtual std::string Home::filePrefix (  ) const [protected, pure virtual]

Implemented in JWtHome, and WtHome.

void Home::googleAnalyticsLogger (  )

Definition at line 345 of file Home.C.

{
  std::string googleCmd = 
    "if (window.pageTracker) {"
    """try {"
    ""  "window.pageTracker._trackPageview(\""
    + environment().deploymentPath() + internalPath() + "\");"
    """} catch (e) { }"
    "}";

  doJavaScript(googleCmd);
}
std::string Home::href ( const std::string &  url,
const std::string &  description 
) [protected]

Definition at line 286 of file Home.C.

{
  return "<a href=\"" + url + "\" target=\"_blank\">" + description + "</a>";
}
void Home::init (  ) [protected]

Definition at line 55 of file Home.C.

WWidget * Home::initHome (  ) [private]

Definition at line 102 of file Home.C.

{
  WTemplate *result = new WTemplate(tr("template"), root());

  WContainerWidget *languagesDiv = new WContainerWidget();
  languagesDiv->setId("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_);
  }

  WStackedWidget *contents = new WStackedWidget();
  contents->setId("main_page");

  mainMenu_ = new WMenu(contents, Vertical);
  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(this, &Home::updateTitle);

  mainMenu_->itemSelected().connect(this, &Home::googleAnalyticsLogger);

  // Make the menu be internal-path aware.
  mainMenu_->setInternalPathEnabled("/");

  sideBarContent_ = new WContainerWidget();

  result->bindWidget("languages", languagesDiv);
  result->bindWidget("menu", mainMenu_);
  result->bindWidget("contents", contents);
  result->bindWidget("sidebar", sideBarContent_);

  return result;
}
WWidget * Home::introduction (  ) [private]

Definition at line 234 of file Home.C.

{
  return new WText(tr("home.intro"));
}
WWidget * Home::linkSourceBrowser ( const std::string &  examplePath ) [protected]

Definition at line 187 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 223 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]

Definition at line 276 of file Home.C.

{
  return new WText(tr("home.other-language"));
}
void Home::readNews ( WTable newsTable,
const std::string &  newsfile 
) [private]
void Home::readReleases ( WTable releaseTable ) [protected]

Definition at line 296 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 171 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 194 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 66 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]

Implemented in JWtHome, and WtHome.

WWidget * Home::status (  ) [private]

Definition at line 261 of file Home.C.

{
  return new WText(tr("home.status"));
}
WString Home::tr ( const char *  key ) [protected]

Definition at line 340 of file Home.C.

{
  return WString::tr(key);
}
void Home::updateTitle (  ) [private]

Definition at line 216 of file Home.C.

{
  if (mainMenu_->currentItem()) {
    setTitle(tr("wt") + " - " + mainMenu_->currentItem()->text());
  }
}
WWidget * Home::wrapView ( WWidget *(Home::*)()  createFunction ) [private]

Definition at line 281 of file Home.C.

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

Member Data Documentation

Definition at line 101 of file Home.h.

Definition at line 89 of file Home.h.

Definition at line 98 of file Home.h.

int Home::language_ [private]

Definition at line 115 of file Home.h.

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

Definition at line 130 of file Home.h.

WMenu* Home::mainMenu_ [private]

Definition at line 113 of file Home.h.

WTable* Home::releases_ [protected]

Definition at line 94 of file Home.h.

Definition at line 128 of file Home.h.

Definition at line 99 of file Home.h.


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

Generated on Fri Feb 4 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2