00001
00002
00003
00004
00005
00006
00007 #include "WtHome.h"
00008
00009 #include <Wt/WAnchor>
00010 #include <Wt/WEnvironment>
00011 #include <Wt/WLogger>
00012 #include <Wt/WMenuItem>
00013 #include <Wt/WTable>
00014 #include <Wt/WTabWidget>
00015 #include <Wt/WText>
00016 #include <Wt/WTreeNode>
00017 #include <Wt/WViewWidget>
00018 #include <Wt/WWidget>
00019
00020 #include "ExampleSourceViewer.h"
00021
00022 WtHome::WtHome(const WEnvironment& env)
00023 : Home(env, "Wt, C++ Web Toolkit", "wt-home", "css/wt")
00024 {
00025 addLanguage(Lang("en", "/", "en", "English"));
00026 addLanguage(Lang("cn", "/cn/", "汉语", "中文 (Chinese)"));
00027
00028 char* wtExamplePath = getenv("WT_EXAMPLE_PATH");
00029 if (wtExamplePath)
00030 wtExamplePath_ = wtExamplePath;
00031 else
00032 wtExamplePath_ = "../";
00033
00034 init();
00035 }
00036
00037 WWidget *WtHome::example(const char *textKey, const std::string& sourceDir)
00038 {
00039 WContainerWidget *result = new WContainerWidget();
00040 new WText(tr(textKey), result);
00041 result->addWidget(linkSourceBrowser(sourceDir));
00042 return result;
00043 }
00044
00045 WWidget *WtHome::helloWorldExample()
00046 {
00047 return example("home.examples.hello", "hello");
00048 }
00049
00050 WWidget *WtHome::chartExample()
00051 {
00052 return example("home.examples.chart", "charts");
00053 }
00054
00055 WWidget *WtHome::homepageExample()
00056 {
00057 return example("home.examples.wt", "wt-homepage");
00058 }
00059
00060 WWidget *WtHome::treeviewExample()
00061 {
00062 return example("home.examples.treeview", "treeview-dragdrop");
00063 }
00064
00065 WWidget *WtHome::gitExample()
00066 {
00067 return example("home.examples.git", "gitmodel");
00068 }
00069
00070 WWidget *WtHome::chatExample()
00071 {
00072 return example("home.examples.chat", "simplechat");
00073 }
00074
00075 WWidget *WtHome::composerExample()
00076 {
00077 return example("home.examples.composer", "composer");
00078 }
00079
00080 WWidget *WtHome::widgetGalleryExample()
00081 {
00082 return example("home.examples.widgetgallery", "widgetgallery");
00083 }
00084
00085 WWidget *WtHome::examples()
00086 {
00087 WContainerWidget *result = new WContainerWidget();
00088
00089 result->addWidget(new WText(tr("home.examples")));
00090
00091 examplesMenu_ = new WTabWidget(AlignTop | AlignJustify, result);
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 examplesMenu_->addTab(wrapView(&WtHome::helloWorldExample),
00109 tr("hello-world"))->setPathComponent("");
00110 examplesMenu_->addTab(wrapView(&WtHome::chartExample),
00111 tr("charts"));
00112 examplesMenu_->addTab(wrapView(&WtHome::homepageExample),
00113 tr("wt-homepage"));
00114 examplesMenu_->addTab(wrapView(&WtHome::treeviewExample),
00115 tr("treeview"));
00116 examplesMenu_->addTab(wrapView(&WtHome::gitExample),
00117 tr("git"));
00118 examplesMenu_->addTab(wrapView(&WtHome::chatExample),
00119 tr("chat"));
00120 examplesMenu_->addTab(wrapView(&WtHome::composerExample),
00121 tr("mail-composer"));
00122 examplesMenu_->addTab(wrapView(&WtHome::widgetGalleryExample),
00123 tr("widget-gallery"));
00124
00125
00126 examplesMenu_->setInternalPathEnabled("/examples");
00127 examplesMenu_->currentChanged().connect(SLOT(this, Home::googleAnalyticsLogger));
00128
00129 return result;
00130 }
00131
00132 WWidget *WtHome::download()
00133 {
00134 WContainerWidget *result = new WContainerWidget();
00135 result->addWidget(new WText(tr("home.download")));
00136 result->addWidget(new WText(tr("home.download.license")));
00137 result->addWidget(new WText(tr("home.download.requirements")));
00138 result->addWidget(new WText(tr("home.download.cvs")));
00139 result->addWidget(new WText(tr("home.download.packages")));
00140
00141 releases_ = new WTable();
00142 readReleases(releases_);
00143 result->addWidget(releases_);
00144
00145 result->addWidget
00146 (new WText("<p>Older releases are still available at "
00147 + href("http://sourceforge.net/project/showfiles.php?"
00148 "group_id=153710#files",
00149 "sourceforge.net")
00150 + "</p>"));
00151
00152 return result;
00153 }
00154
00155 WWidget *WtHome::sourceViewer(const std::string& deployPath)
00156 {
00157 return new ExampleSourceViewer(deployPath, wtExamplePath_ + "/", "CPP");
00158 }
00159
00160 WWidget *WtHome::wrapView(WWidget *(WtHome::*createWidget)())
00161 {
00162 return makeStaticModel(boost::bind(createWidget, this));
00163 }
00164
00165 WApplication *createWtHomeApplication(const WEnvironment& env)
00166 {
00167
00168
00169
00170 const std::string *historyKey = env.getParameter("historyKey");
00171
00172 if (historyKey) {
00173 const char *mainStr[]
00174 = { "main:0", "/",
00175 "main:1", "/news",
00176 "main:2", "/features",
00177 "main:4", "/examples",
00178 "main:3", "/documentation",
00179 "main:5", "/download",
00180 "main:6", "/community" };
00181
00182 const char *exampleStr[]
00183 = { "example:0", "/examples",
00184 "example:1", "/examples/charts",
00185 "example:2", "/examples/wt-homepage",
00186 "example:3", "/examples/treelist",
00187 "example:4", "/examples/hangman",
00188 "example:5", "/examples/chat",
00189 "example:6", "/examples/mail-composer",
00190 "example:7", "/examples/drag-and-drop",
00191 "example:8", "/examples/file-explorer",
00192 "example:9", "/examples/calendar" };
00193
00194 if (historyKey->find("main:4") != std::string::npos) {
00195 for (unsigned i = 0; i < 10; ++i)
00196 if (historyKey->find(exampleStr[i*2]) != std::string::npos) {
00197 WApplication *app = new WApplication(env);
00198 app->log("notice") << "redirecting old style URL '"
00199 << *historyKey << "' to internal path: '"
00200 << exampleStr[i*2+1] << "'";
00201 app->redirect(app->bookmarkUrl(exampleStr[i*2+1]));
00202 app->quit();
00203 return app;
00204 }
00205 } else
00206 for (unsigned i = 0; i < 6; ++i)
00207 if (historyKey->find(mainStr[i*2]) != std::string::npos) {
00208 WApplication *app = new WApplication(env);
00209
00210 app->log("notice") << "redirecting old style URL '"
00211 << *historyKey << "' to internal path: '"
00212 << mainStr[i*2+1] << "'";
00213 app->redirect(app->bookmarkUrl(mainStr[i*2+1]));
00214 app->quit();
00215 return app;
00216 }
00217
00218
00219 }
00220
00221 return new WtHome(env);
00222 }