A self-contained chat widget.
More...
#include <SimpleChatWidget.h>
|
virtual void | createLayout (Wt::WWidget *messages, Wt::WWidget *userList, Wt::WWidget *messageEdit, Wt::WWidget *sendButton, Wt::WWidget *logoutButton) |
|
virtual void | updateUsers () |
|
virtual void | newMessage () |
|
virtual void | render (Wt::WFlags< Wt::RenderFlag > flags) |
|
bool | loggedIn () const |
|
|
typedef std::map< Wt::WString, bool > | UserMap |
|
A self-contained chat widget.
Definition at line 34 of file SimpleChatWidget.h.
§ UserMap
§ SimpleChatWidget()
SimpleChatWidget::SimpleChatWidget |
( |
SimpleChatServer & |
server, |
|
|
Wt::WContainerWidget * |
parent = 0 |
|
) |
| |
Create a chat widget that will connect to the given server.
Definition at line 28 of file SimpleChatWidget.C.
30 : WContainerWidget(parent),
Wt::WString suggestGuest()
Get a suggestion for a guest user name.
§ ~SimpleChatWidget()
SimpleChatWidget::~SimpleChatWidget |
( |
| ) |
|
§ changeName()
void SimpleChatWidget::changeName |
( |
const Wt::WString & |
name | ) |
|
|
private |
Definition at line 305 of file SimpleChatWidget.C.
bool changeName(const Wt::WString &user, const Wt::WString &newUser)
Changes the name.
§ connect()
void SimpleChatWidget::connect |
( |
| ) |
|
Definition at line 46 of file SimpleChatWidget.C.
50 Wt::WApplication::instance()->enableUpdates(
true);
bool connect(Client *client, const ChatEventCallback &handleEvent)
Connects to the chat server.
§ createLayout()
void SimpleChatWidget::createLayout |
( |
Wt::WWidget * |
messages, |
|
|
Wt::WWidget * |
userList, |
|
|
Wt::WWidget * |
messageEdit, |
|
|
Wt::WWidget * |
sendButton, |
|
|
Wt::WWidget * |
logoutButton |
|
) |
| |
|
protectedvirtual |
Reimplemented in PopupChatWidget.
Definition at line 108 of file SimpleChatWidget.C.
130 WVBoxLayout *vLayout =
new WVBoxLayout();
133 WHBoxLayout *hLayout =
new WHBoxLayout();
136 hLayout->addWidget(messages, 1);
137 messages->setStyleClass(
"chat-msgs");
140 hLayout->addWidget(userList);
141 userList->setStyleClass(
"chat-users");
143 hLayout->setResizable(0,
true);
146 vLayout->addLayout(hLayout, 1);
149 vLayout->addWidget(messageEdit);
150 messageEdit->setStyleClass(
"chat-noedit");
153 hLayout =
new WHBoxLayout();
156 hLayout->addWidget(sendButton);
159 hLayout->addWidget(logoutButton);
162 vLayout->addLayout(hLayout, 0, AlignLeft);
§ disconnect()
void SimpleChatWidget::disconnect |
( |
| ) |
|
Definition at line 53 of file SimpleChatWidget.C.
56 Wt::WApplication::instance()->enableUpdates(
false);
bool disconnect(Client *client)
Disconnect from the chat server.
§ letLogin()
void SimpleChatWidget::letLogin |
( |
| ) |
|
Show a simple login screen.
Definition at line 59 of file SimpleChatWidget.C.
63 WVBoxLayout *vLayout =
new WVBoxLayout();
66 WHBoxLayout *hLayout =
new WHBoxLayout();
67 vLayout->addLayout(hLayout, 0, AlignTop | AlignLeft);
69 hLayout->addWidget(
new WLabel(
"User name:"), 0, AlignMiddle);
73 WPushButton *b =
new WPushButton(
"Login");
74 hLayout->addWidget(b, 0, AlignMiddle);
§ loggedIn()
bool SimpleChatWidget::loggedIn |
( |
| ) |
const |
|
protected |
§ login()
void SimpleChatWidget::login |
( |
| ) |
|
|
private |
§ logout()
void SimpleChatWidget::logout |
( |
| ) |
|
Definition at line 97 of file SimpleChatWidget.C.
void logout(const Wt::WString &user)
Logout from the server.
§ newMessage()
void SimpleChatWidget::newMessage |
( |
| ) |
|
|
protectedvirtual |
§ processChatEvent()
void SimpleChatWidget::processChatEvent |
( |
const ChatEvent & |
event | ) |
|
|
private |
Definition at line 358 of file SimpleChatWidget.C.
360 WApplication *app = WApplication::instance();
392 app->triggerUpdate();
414 w->setTextFormat(XHTMLText);
418 w->setStyleClass(
"chat-msg");
429 app->doJavaScript(
messages_->jsRef() +
".scrollTop += " 430 +
messages_->jsRef() +
".scrollHeight;");
Type type() const
Get the event type.
const Wt::WString & data() const
Get the extra data for this event.
const Wt::WString formattedHTML(const Wt::WString &user, Wt::TextFormat format) const
Get the message formatted as HTML, rendered for the given user.
const Wt::WString & user() const
Get the user who caused the event.
§ render()
void SimpleChatWidget::render |
( |
Wt::WFlags< Wt::RenderFlag > |
flags | ) |
|
|
protectedvirtual |
Definition at line 172 of file SimpleChatWidget.C.
174 if (flags & RenderFull) {
178 doJavaScript(
"setTimeout(function() { " 180 +
messages_->jsRef() +
".scrollHeight;}, 0);");
184 WContainerWidget::render(flags);
§ send()
void SimpleChatWidget::send |
( |
| ) |
|
|
private |
Definition at line 313 of file SimpleChatWidget.C.
void sendMessage(const Wt::WString &user, const Wt::WString &message)
Send a message on behalve of a user.
§ server()
§ startChat()
bool SimpleChatWidget::startChat |
( |
const Wt::WString & |
user | ) |
|
Start a chat for the given user.
Returns false if the user could not login.
Definition at line 187 of file SimpleChatWidget.C.
209 messages_->setOverflow(WContainerWidget::OverflowAuto);
210 userList_->setOverflow(WContainerWidget::OverflowAuto);
213 WPushButton *logoutButton =
new WPushButton(
"Logout");
231 (
"function(o, e) { setTimeout(function() {" 244 WApplication::instance()->setConnectionMonitor(
246 "'onChange':function(type, newV) {" 247 "var connected = window.monitor.status.connectionStatus != 0;" 253 +
messageEdit_->jsRef() +
".placeholder='connection lost';" 275 WInPlaceEdit *nameEdit =
new WInPlaceEdit();
276 nameEdit->addStyleClass(
"name-edit");
277 nameEdit->setButtonsEnabled(
false);
278 nameEdit->setText(
user_);
281 WTemplate *joinMsg =
new WTemplate(tr(
"join-msg.template"),
messages_);
282 joinMsg->bindWidget(
"name", nameEdit);
283 joinMsg->setStyleClass(
"chat-msg");
295 if (!logoutButton->parent())
bool login(const Wt::WString &user)
Try to login with given user name.
§ updateUser()
void SimpleChatWidget::updateUser |
( |
| ) |
|
|
private |
Definition at line 352 of file SimpleChatWidget.C.
354 WCheckBox *b =
dynamic_cast<WCheckBox *
>(sender());
355 users_[b->text()] = b->isChecked();
§ updateUsers()
void SimpleChatWidget::updateUsers |
( |
| ) |
|
|
protectedvirtual |
Reimplemented in PopupChatWidget.
Definition at line 319 of file SimpleChatWidget.C.
329 for (SimpleChatServer::UserSet::iterator i = users.begin();
330 i != users.end(); ++i) {
331 WCheckBox *w =
new WCheckBox(escapeText(*i),
userList_);
334 UserMap::const_iterator j = oldUsers.find(*i);
335 if (j != oldUsers.end())
336 w->setChecked(j->second);
340 users_[*i] = w->isChecked();
344 w->setStyleClass(
"chat-self");
UserSet users()
Get the users currently logged in.
std::set< Wt::WString > UserSet
Typedef for a collection of user names.
§ userCount()
int SimpleChatWidget::userCount |
( |
| ) |
|
|
inline |
§ userName()
const Wt::WString& SimpleChatWidget::userName |
( |
| ) |
const |
|
inline |
§ clearInput_
Wt::JSlot SimpleChatWidget::clearInput_ |
|
private |
§ loggedIn_
bool SimpleChatWidget::loggedIn_ |
|
private |
§ messageEdit_
Wt::WTextArea* SimpleChatWidget::messageEdit_ |
|
private |
§ messageReceived_
Wt::WSound* SimpleChatWidget::messageReceived_ |
|
private |
§ messages_
Wt::WContainerWidget* SimpleChatWidget::messages_ |
|
private |
§ sendButton_
Wt::WPushButton* SimpleChatWidget::sendButton_ |
|
private |
§ server_
§ statusMsg_
Wt::WText* SimpleChatWidget::statusMsg_ |
|
private |
§ user_
Wt::WString SimpleChatWidget::user_ |
|
private |
§ userList_
Wt::WContainerWidget* SimpleChatWidget::userList_ |
|
private |
§ userNameEdit_
Wt::WLineEdit* SimpleChatWidget::userNameEdit_ |
|
private |
§ users_
The documentation for this class was generated from the following files: