|
Wt examples
3.3.5
|
Classes | |
| class | PopupChatWidget |
| A popup chat widget. More... | |
| class | ChatApplication |
| A chat demo application. More... | |
| class | ChatWidget |
| A chat application widget. More... | |
| class | ChatEvent |
| Encapsulate a chat event. More... | |
| class | SimpleChatServer |
| A simple chat server. More... | |
| class | SimpleChatWidget |
| A self-contained chat widget. More... | |
Typedefs | |
| typedef boost::function< void(const ChatEvent &)> | ChatEventCallback |
Functions | |
| WApplication * | createApplication (const WEnvironment &env, SimpleChatServer &server) |
| WApplication * | createWidget (const WEnvironment &env, SimpleChatServer &server) |
| int | main (int argc, char **argv) |
| ChatApplication::ChatApplication (const WEnvironment &env, SimpleChatServer &server) | |
| Create a new instance. | |
| void | ChatApplication::javaScriptTest () |
| void | ChatApplication::emptyFunc () |
| void | ChatApplication::addChatWidget () |
| Add another chat client. | |
| ChatWidget::ChatWidget (const WEnvironment &env, SimpleChatServer &server) | |
| typedef boost::function<void (const ChatEvent&)> ChatEventCallback |
Definition at line 81 of file SimpleChatServer.h.
| void ChatApplication::addChatWidget | ( | ) | [private] |
Add another chat client.
Definition at line 90 of file simpleChat.C.
{
SimpleChatWidget *chatWidget2 = new SimpleChatWidget(server_, root());
chatWidget2->setStyleClass("chat");
}
| ChatApplication::ChatApplication | ( | const WEnvironment & | env, |
| SimpleChatServer & | server | ||
| ) |
Create a new instance.
Definition at line 47 of file simpleChat.C.
: WApplication(env),
server_(server),
env_(env)
{
setTitle("Wt Chat");
useStyleSheet("chatapp.css");
messageResourceBundle().use(appRoot() + "simplechat");
javaScriptTest();
root()->addWidget(new WText(WString::tr("introduction")));
SimpleChatWidget *chatWidget =
new SimpleChatWidget(server_, root());
chatWidget->setStyleClass("chat");
root()->addWidget(new WText(WString::tr("details")));
WPushButton *b = new WPushButton("I'm schizophrenic ...", root());
b->clicked().connect(b, &WPushButton::hide);
b->clicked().connect(this, &ChatApplication::addChatWidget);
}
| ChatWidget::ChatWidget | ( | const WEnvironment & | env, |
| SimpleChatServer & | server | ||
| ) |
Definition at line 107 of file simpleChat.C.
: WApplication(env),
login_(this, "login")
{
setCssTheme("");
useStyleSheet("chatwidget.css");
useStyleSheet("chatwidget_ie6.css", "lt IE 7");
messageResourceBundle().use(appRoot() + "simplechat");
const std::string *div = env.getParameter("div");
std::string defaultDiv = "div";
if (!div)
div = &defaultDiv;
if (div) {
setJavaScriptClass(*div);
PopupChatWidget *chatWidget = new PopupChatWidget(server, *div);
bindWidget(chatWidget, *div);
login_.connect(chatWidget, &PopupChatWidget::setName);
std::string chat = javaScriptClass();
doJavaScript("if (window." + chat + "User) "
+ chat + ".emit(" + chat + ", 'login', " + chat + "User);"
+ "document.body.appendChild(" + chatWidget->jsRef() + ");");
} else {
std::cerr << "Missing: parameter: 'div'" << std::endl;
quit();
}
}
| WApplication* createApplication | ( | const WEnvironment & | env, |
| SimpleChatServer & | server | ||
| ) |
Definition at line 139 of file simpleChat.C.
{
return new ChatApplication(env, server);
}
| WApplication* createWidget | ( | const WEnvironment & | env, |
| SimpleChatServer & | server | ||
| ) |
Definition at line 145 of file simpleChat.C.
{
return new ChatWidget(env, server);
}
| void ChatApplication::emptyFunc | ( | ) | [private] |
Definition at line 87 of file simpleChat.C.
{}
| void ChatApplication::javaScriptTest | ( | ) | [private] |
Definition at line 73 of file simpleChat.C.
{
if(!env_.javaScript()){
javaScriptError_ = new WText(WString::tr("serverpushwarning"), root());
// The 5 second timer is a fallback for real server push. The updated
// server state will piggy back on the response to this timeout.
timer_ = new Wt::WTimer(root());
timer_->setInterval(5000);
timer_->timeout().connect(this, &ChatApplication::emptyFunc);
timer_->start();
}
}
| int main | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 150 of file simpleChat.C.
{
Wt::WServer server(argc, argv, WTHTTP_CONFIGURATION);
SimpleChatServer chatServer(server);
/*
* We add two entry points: one for the full-window application,
* and one for a widget that can be integrated in another page.
*/
server.addEntryPoint(Wt::Application,
boost::bind(createApplication, _1,
boost::ref(chatServer)));
server.addEntryPoint(Wt::WidgetSet,
boost::bind(createWidget, _1,
boost::ref(chatServer)), "/chat.js");
if (server.start()) {
int sig = Wt::WServer::waitForShutdown();
std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
server.stop();
}
}
1.7.6.1