Wt examples: simplechat/SimpleChatWidget.h Source File

Wt examples 4.10.4

Loading...
Searching...
No Matches
SimpleChatWidget.h
Go to the documentation of this file.
1// This may look like C code, but it's really -*- C++ -*-
2/*
3 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
4 *
5 * See the LICENSE file for terms of use.
6 */
7
8#ifndef SIMPLECHATWIDGET_H_
9#define SIMPLECHATWIDGET_H_
10
11#include <Wt/WContainerWidget.h>
12#include <Wt/WJavaScript.h>
13#include <Wt/WSound.h>
14
15#include "SimpleChatServer.h"
16
17class ChatEvent;
18
23
26 class SimpleChatWidget : public Wt::WContainerWidget,
27 public SimpleChatServer::Client
28{
29public:
32 SimpleChatWidget(SimpleChatServer& server);
33
36 ~SimpleChatWidget();
37
38 void connect();
39 void disconnect();
40
41
44 void letLogin();
45
50 bool startChat(const Wt::WString& user);
51
52 void logout();
53
54 SimpleChatServer& server() { return server_; }
55
56 int userCount() { return users_.size(); }
57
58 const Wt::WString& userName() const { return user_; }
59
60protected:
61 virtual void createLayout(std::unique_ptr<Wt::WWidget> messages, std::unique_ptr<Wt::WWidget> userList,
62 std::unique_ptr<Wt::WWidget> messageEdit,
63 std::unique_ptr<Wt::WWidget> sendButton, std::unique_ptr<Wt::WWidget> logoutButton);
64
65 virtual void updateUsers();
66 virtual void newMessage();
67
68 virtual void render(Wt::WFlags<Wt::RenderFlag> flags);
69
70protected:
71 bool loggedIn() const;
72
73private:
74 typedef std::map<Wt::WString, bool> UserMap;
75 UserMap users_;
76
77 SimpleChatServer& server_;
78 bool loggedIn_;
79
80 Wt::JSlot clearInput_;
81
82 Wt::WString user_;
83
84 Wt::WLineEdit *userNameEdit_;
85 Wt::WText *statusMsg_;
86
87 Wt::WContainerWidget *messages_;
88 Wt::WTextArea *messageEdit_;
89 Wt::Core::observing_ptr<Wt::WPushButton> sendButton_;
90 Wt::Core::observing_ptr<Wt::WContainerWidget> userList_;
91
92 std::unique_ptr<Wt::WSound> messageReceived_;
93
94 void login();
95 void changeName(const Wt::WString& name);
96 void send();
97 void updateUser(Wt::WCheckBox *b);
98
99 /* called from another session */
100 void processChatEvent(const ChatEvent& event);
101};
102
105#endif // SIMPLECHATWIDGET
SimpleChatServer.h
ChatEvent
Encapsulate a chat event.
Definition SimpleChatServer.h:30
SimpleChatServer::Client
Definition SimpleChatServer.h:91
SimpleChatServer
A simple chat server.
Definition SimpleChatServer.h:85
SimpleChatWidget
A self-contained chat widget.
Definition SimpleChatWidget.h:28
SimpleChatWidget::startChat
bool startChat(const Wt::WString &user)
Start a chat for the given user.
Definition SimpleChatWidget.C:191
SimpleChatWidget::updateUsers
virtual void updateUsers()
Definition SimpleChatWidget.C:320
SimpleChatWidget::updateUser
void updateUser(Wt::WCheckBox *b)
Definition SimpleChatWidget.C:353
SimpleChatWidget::server
SimpleChatServer & server()
Definition SimpleChatWidget.h:54
SimpleChatWidget::messages_
Wt::WContainerWidget * messages_
Definition SimpleChatWidget.h:87
SimpleChatWidget::messageEdit_
Wt::WTextArea * messageEdit_
Definition SimpleChatWidget.h:88
SimpleChatWidget::user_
Wt::WString user_
Definition SimpleChatWidget.h:82
SimpleChatWidget::connect
void connect()
Definition SimpleChatWidget.C:43
SimpleChatWidget::userNameEdit_
Wt::WLineEdit * userNameEdit_
Definition SimpleChatWidget.h:84
SimpleChatWidget::SimpleChatWidget
SimpleChatWidget(SimpleChatServer &server)
Create a chat widget that will connect to the given server.
Definition SimpleChatWidget.C:26
SimpleChatWidget::letLogin
void letLogin()
Show a simple login screen.
Definition SimpleChatWidget.C:56
SimpleChatWidget::disconnect
void disconnect()
Definition SimpleChatWidget.C:50
SimpleChatWidget::clearInput_
Wt::JSlot clearInput_
Definition SimpleChatWidget.h:80
SimpleChatWidget::messageReceived_
std::unique_ptr< Wt::WSound > messageReceived_
Definition SimpleChatWidget.h:92
SimpleChatWidget::userCount
int userCount()
Definition SimpleChatWidget.h:56
SimpleChatWidget::loggedIn_
bool loggedIn_
Definition SimpleChatWidget.h:78
SimpleChatWidget::loggedIn
bool loggedIn() const
Definition SimpleChatWidget.C:171
SimpleChatWidget::statusMsg_
Wt::WText * statusMsg_
Definition SimpleChatWidget.h:85
SimpleChatWidget::createLayout
virtual void createLayout(std::unique_ptr< Wt::WWidget > messages, std::unique_ptr< Wt::WWidget > userList, std::unique_ptr< Wt::WWidget > messageEdit, std::unique_ptr< Wt::WWidget > sendButton, std::unique_ptr< Wt::WWidget > logoutButton)
Definition SimpleChatWidget.C:109
SimpleChatWidget::UserMap
std::map< Wt::WString, bool > UserMap
Definition SimpleChatWidget.h:74
SimpleChatWidget::render
virtual void render(Wt::WFlags< Wt::RenderFlag > flags)
Definition SimpleChatWidget.C:176
SimpleChatWidget::userList_
Wt::Core::observing_ptr< Wt::WContainerWidget > userList_
Definition SimpleChatWidget.h:90
SimpleChatWidget::server_
SimpleChatServer & server_
Definition SimpleChatWidget.h:77
SimpleChatWidget::newMessage
virtual void newMessage()
Definition SimpleChatWidget.C:350
SimpleChatWidget::sendButton_
Wt::Core::observing_ptr< Wt::WPushButton > sendButton_
Definition SimpleChatWidget.h:89
SimpleChatWidget::changeName
void changeName(const Wt::WString &name)
Definition SimpleChatWidget.C:306
SimpleChatWidget::logout
void logout()
Definition SimpleChatWidget.C:98
SimpleChatWidget::userName
const Wt::WString & userName() const
Definition SimpleChatWidget.h:58
SimpleChatWidget::processChatEvent
void processChatEvent(const ChatEvent &event)
Definition SimpleChatWidget.C:358
SimpleChatWidget::send
void send()
Definition SimpleChatWidget.C:314
SimpleChatWidget::login
void login()
Definition SimpleChatWidget.C:84
SimpleChatWidget::~SimpleChatWidget
~SimpleChatWidget()
Delete a chat widget.
Definition SimpleChatWidget.C:37
SimpleChatWidget::users_
UserMap users_
Definition SimpleChatWidget.h:75