Wt examples  3.7.1
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>
12 #include <Wt/WJavaScript>
13 #include <Wt/WSound>
14 
15 #include "SimpleChatServer.h"
16 
17 namespace Wt {
18  class WApplication;
19  class WPushButton;
20  class WText;
21  class WLineEdit;
22  class WTextArea;
23 }
24 
25 class ChatEvent;
26 
31 
36 {
37 public:
41 
45 
46  void connect();
47  void disconnect();
48 
49 
52  void letLogin();
53 
58  bool startChat(const Wt::WString& user);
59 
60  void logout();
61 
62  SimpleChatServer& server() { return server_; }
63 
64  int userCount() { return users_.size(); }
65 
66  const Wt::WString& userName() const { return user_; }
67 
68 protected:
69  virtual void createLayout(Wt::WWidget *messages, Wt::WWidget *userList,
70  Wt::WWidget *messageEdit,
71  Wt::WWidget *sendButton, Wt::WWidget *logoutButton);
72 
73  virtual void updateUsers();
74  virtual void newMessage();
75 
76  virtual void render(Wt::WFlags<Wt::RenderFlag> flags);
77 
78 protected:
79  bool loggedIn() const;
80 
81 private:
82  typedef std::map<Wt::WString, bool> UserMap;
83  UserMap users_;
84 
86  bool loggedIn_;
87 
89 
91 
94 
99 
101 
102  void login();
103  void changeName(const Wt::WString& name);
104  void send();
105  void updateUser();
106 
107  /* called from another session */
108  void processChatEvent(const ChatEvent& event);
109 };
110 
113 #endif // SIMPLECHATWIDGET
Wt::WContainerWidget * messages_
SimpleChatServer & server_
Wt::WContainerWidget * userList_
Wt::WText * statusMsg_
Wt::WTextArea * messageEdit_
std::map< Wt::WString, bool > UserMap
Wt::WPushButton * sendButton_
Encapsulate a chat event.
SimpleChatServer & server()
A self-contained chat widget.
Wt::WLineEdit * userNameEdit_
const Wt::WString & userName() const
A simple chat server.
Wt::WSound * messageReceived_

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13