Wt examples  3.3.0
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::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 63 of file simpleChat.C.

64 {
65  SimpleChatWidget *chatWidget2 = new SimpleChatWidget(server_, root());
66  chatWidget2->setStyleClass("chat");
67 }
ChatApplication::ChatApplication ( const WEnvironment env,
SimpleChatServer server 
)

Create a new instance.

Definition at line 41 of file simpleChat.C.

43  : WApplication(env),
44  server_(server)
45 {
46  setTitle("Wt Chat");
47  useStyleSheet("chatapp.css");
48 
49  messageResourceBundle().use(appRoot() + "simplechat");
50 
51  root()->addWidget(new WText(WString::tr("introduction")));
52 
53  SimpleChatWidget *chatWidget = new SimpleChatWidget(server_, root());
54  chatWidget->setStyleClass("chat");
55 
56  root()->addWidget(new WText(WString::tr("details")));
57 
58  WPushButton *b = new WPushButton("I'm schizophrenic ...", root());
59  b->clicked().connect(b, &WPushButton::hide);
60  b->clicked().connect(this, &ChatApplication::addChatWidget);
61 }
ChatWidget::ChatWidget ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 80 of file simpleChat.C.

81  : WApplication(env),
82  login_(this, "login")
83 {
84  setCssTheme("");
85  useStyleSheet("chatwidget.css");
86  useStyleSheet("chatwidget_ie6.css", "lt IE 7");
87 
88  const std::string *div = env.getParameter("div");
89  std::string defaultDiv = "div";
90  if (!div)
91  div = &defaultDiv;
92 
93  if (div) {
94  setJavaScriptClass(*div);
95  PopupChatWidget *chatWidget = new PopupChatWidget(server, *div);
96  bindWidget(chatWidget, *div);
97 
99 
100  std::string chat = javaScriptClass();
101  doJavaScript("if (window." + chat + "User) "
102  + chat + ".emit(" + chat + ", 'login', " + chat + "User);"
103  + "document.body.appendChild(" + chatWidget->jsRef() + ");");
104  } else {
105  std::cerr << "Missing: parameter: 'div'" << std::endl;
106  quit();
107  }
108 }
WApplication* createApplication ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 110 of file simpleChat.C.

112 {
113  return new ChatApplication(env, server);
114 }
WApplication* createWidget ( const WEnvironment env,
SimpleChatServer server 
)

Definition at line 116 of file simpleChat.C.

117 {
118  return new ChatWidget(env, server);
119 }
int main ( int  argc,
char **  argv 
)

Definition at line 121 of file simpleChat.C.

122 {
123  Wt::WServer server(argv[0]);
124  SimpleChatServer chatServer(server);
125 
126  server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
127 
128  /*
129  * We add two entry points: one for the full-window application,
130  * and one for a widget that can be integrated in another page.
131  */
132  server.addEntryPoint(Wt::Application,
133  boost::bind(createApplication, _1,
134  boost::ref(chatServer)));
135  server.addEntryPoint(Wt::WidgetSet,
136  boost::bind(createWidget, _1,
137  boost::ref(chatServer)), "/chat.js");
138 
139  if (server.start()) {
140  int sig = Wt::WServer::waitForShutdown();
141  std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
142  server.stop();
143  }
144 }

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1