Wt examples  4.9.2
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
26class SimpleChatWidget : public Wt::WContainerWidget,
28{
29public:
33
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
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;
76
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
Encapsulate a chat event.
A simple chat server.
A self-contained chat widget.
bool startChat(const Wt::WString &user)
Start a chat for the given user.
virtual void updateUsers()
void updateUser(Wt::WCheckBox *b)
SimpleChatServer & server()
Wt::WContainerWidget * messages_
Wt::WTextArea * messageEdit_
Wt::WLineEdit * userNameEdit_
void letLogin()
Show a simple login screen.
std::unique_ptr< Wt::WSound > messageReceived_
bool loggedIn() const
Wt::WText * statusMsg_
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)
virtual void render(Wt::WFlags< Wt::RenderFlag > flags)
Wt::Core::observing_ptr< Wt::WContainerWidget > userList_
SimpleChatServer & server_
virtual void newMessage()
Wt::Core::observing_ptr< Wt::WPushButton > sendButton_
void changeName(const Wt::WString &name)
const Wt::WString & userName() const
void processChatEvent(const ChatEvent &event)
std::map< Wt::WString, bool > UserMap
~SimpleChatWidget()
Delete a chat widget.