Wt examples  3.3.1
Classes | Typedefs | Functions
Chat example

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

WApplicationcreateApplication (const WEnvironment &env, SimpleChatServer &server)
 
WApplicationcreateWidget (const WEnvironment &env, SimpleChatServer &server)
 
int main (int argc, char **argv)
 
 ChatApplication::ChatApplication (const WEnvironment &env, SimpleChatServer &server)
 Create a new instance. More...
 
void ChatApplication::javaScriptTest ()
 
void ChatApplication::emptyFunc ()
 
void ChatApplication::addChatWidget ()
 Add another chat client. More...
 
 ChatWidget::ChatWidget (const WEnvironment &env, SimpleChatServer &server)
 

Detailed Description

Typedef Documentation

typedef boost::function<void (const ChatEvent&)> ChatEventCallback

Definition at line 81 of file SimpleChatServer.h.

Function Documentation

void ChatApplication::addChatWidget ( )
private

Add another chat client.

Definition at line 90 of file simpleChat.C.

91 {
92  SimpleChatWidget *chatWidget2 = new SimpleChatWidget(server_, root());
93  chatWidget2->setStyleClass("chat");
94 }
SimpleChatServer & server_
Definition: simpleChat.C:35
A self-contained chat widget.
WContainerWidget * root() const
virtual void setStyleClass(const WString &styleClass)=0
ChatApplication::ChatApplication ( const WEnvironment env,
SimpleChatServer server 
)

Create a new instance.

Definition at line 47 of file simpleChat.C.

49  : WApplication(env),
50  server_(server),
51  env_(env)
52 {
53  setTitle("Wt Chat");
54  useStyleSheet("chatapp.css");
55 
56  messageResourceBundle().use(appRoot() + "simplechat");
57 
59 
60  root()->addWidget(new WText(WString::tr("introduction")));
61 
62  SimpleChatWidget *chatWidget =
64  chatWidget->setStyleClass("chat");
65 
66  root()->addWidget(new WText(WString::tr("details")));
67 
68  WPushButton *b = new WPushButton("I'm schizophrenic ...", root());
69  b->clicked().connect(b, &WPushButton::hide);
70  b->clicked().connect(this, &ChatApplication::addChatWidget);
71 }
SimpleChatServer & server_
Definition: simpleChat.C:35
void javaScriptTest()
Definition: simpleChat.C:73
WMessageResourceBundle & messageResourceBundle()
A self-contained chat widget.
void setTitle(const WString &title)
void addChatWidget()
Add another chat client.
Definition: simpleChat.C:90
const WEnvironment & env_
Definition: simpleChat.C:37
void use(const std::string &path, bool loadInMemory=true)
static std::string appRoot()
void useStyleSheet(const WLink &link, const std::string &media="all")
WContainerWidget * root() const
virtual void setStyleClass(const WString &styleClass)=0
WApplication(const WEnvironment &environment)
ChatWidget::ChatWidget ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 107 of file simpleChat.C.

108  : WApplication(env),
109  login_(this, "login")
110 {
111  setCssTheme("");
112  useStyleSheet("chatwidget.css");
113  useStyleSheet("chatwidget_ie6.css", "lt IE 7");
114 
115  const std::string *div = env.getParameter("div");
116  std::string defaultDiv = "div";
117  if (!div)
118  div = &defaultDiv;
119 
120  if (div) {
121  setJavaScriptClass(*div);
122  PopupChatWidget *chatWidget = new PopupChatWidget(server, *div);
123  bindWidget(chatWidget, *div);
124 
126 
127  std::string chat = javaScriptClass();
128  doJavaScript("if (window." + chat + "User) "
129  + chat + ".emit(" + chat + ", 'login', " + chat + "User);"
130  + "document.body.appendChild(" + chatWidget->jsRef() + ");");
131  } else {
132  std::cerr << "Missing: parameter: 'div'" << std::endl;
133  quit();
134  }
135 }
const std::string * getParameter(const std::string &name) const
std::string javaScriptClass()
Wt::Signals::connection connect(const F &function)
void bindWidget(WWidget *widget, const std::string &domId)
void setJavaScriptClass(const std::string &className)
A popup chat widget.
void useStyleSheet(const WLink &link, const std::string &media="all")
JSignal< WString > login_
Definition: simpleChat.C:104
void doJavaScript(const std::string &javascript, bool afterLoaded=true)
void setCssTheme(const std::string &name)
void setName(const Wt::WString &name)
WApplication(const WEnvironment &environment)
WApplication* createApplication ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 137 of file simpleChat.C.

139 {
140  return new ChatApplication(env, server);
141 }
A chat demo application.
Definition: simpleChat.C:27
WApplication* createWidget ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 143 of file simpleChat.C.

144 {
145  return new ChatWidget(env, server);
146 }
A chat application widget.
Definition: simpleChat.C:98
void ChatApplication::emptyFunc ( )
private

Definition at line 87 of file simpleChat.C.

88 {}
void ChatApplication::javaScriptTest ( )
private

Definition at line 73 of file simpleChat.C.

74 {
75  if(!env_.javaScript()){
76  javaScriptError_ = new WText(WString::tr("serverpushwarning"), root());
77 
78  // The 5 second timer is a fallback for real server push. The updated
79  // server state will piggy back on the response to this timeout.
80  timer_ = new Wt::WTimer(root());
81  timer_->setInterval(5000);
82  timer_->timeout().connect(this, &ChatApplication::emptyFunc);
83  timer_->start();
84  }
85 }
bool javaScript() const
Wt::WTimer * timer_
Definition: simpleChat.C:38
void start()
Wt::WText * javaScriptError_
Definition: simpleChat.C:36
EventSignal< WMouseEvent > & timeout()
const WEnvironment & env_
Definition: simpleChat.C:37
void setInterval(int msec)
void emptyFunc()
Definition: simpleChat.C:87
WContainerWidget * root() const
int main ( int  argc,
char **  argv 
)

Definition at line 148 of file simpleChat.C.

149 {
150  Wt::WServer server(argv[0]);
151  SimpleChatServer chatServer(server);
152 
153  server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
154 
155  /*
156  * We add two entry points: one for the full-window application,
157  * and one for a widget that can be integrated in another page.
158  */
159  server.addEntryPoint(Wt::Application,
160  boost::bind(createApplication, _1,
161  boost::ref(chatServer)));
162  server.addEntryPoint(Wt::WidgetSet,
163  boost::bind(createWidget, _1,
164  boost::ref(chatServer)), "/chat.js");
165 
166  if (server.start()) {
167  int sig = Wt::WServer::waitForShutdown();
168  std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
169  server.stop();
170  }
171 }
WApplication * createApplication(const WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:137
static WT_API int waitForShutdown(const char *restartWatchFile=0)
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:143
A simple chat server.

Generated on Wed Jun 11 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.7