00001 // This may look like C code, but it's really -*- C++ -*- 00002 /* 00003 * Copyright (C) 2008 Emweb bvba, Heverlee, Belgium. 00004 * 00005 * See the LICENSE file for terms of use. 00006 */ 00007 00008 #ifndef SIMPLECHATWIDGET_H_ 00009 #define SIMPLECHATWIDGET_H_ 00010 00011 #include <Wt/WContainerWidget> 00012 #include <Wt/WJavaScript> 00013 #include <Wt/WSound> 00014 00015 namespace Wt { 00016 class WApplication; 00017 class WPushButton; 00018 class WText; 00019 class WLineEdit; 00020 class WTextArea; 00021 } 00022 00023 class SimpleChatServer; 00024 class ChatEvent; 00025 00030 00033 class SimpleChatWidget : public Wt::WContainerWidget 00034 { 00035 public: 00038 SimpleChatWidget(SimpleChatServer& server, Wt::WContainerWidget *parent = 0); 00039 00042 ~SimpleChatWidget(); 00043 00046 void letLogin(); 00047 00052 bool startChat(const Wt::WString& user); 00053 00054 private: 00055 typedef std::map<Wt::WString, bool> UserMap; 00056 UserMap users_; 00057 00058 SimpleChatServer& server_; 00059 Wt::WApplication *app_; 00060 00061 Wt::JSlot clearInput_; 00062 00063 Wt::WString user_; 00064 00065 Wt::WLineEdit *userNameEdit_; 00066 Wt::WText *statusMsg_; 00067 00068 Wt::WContainerWidget *messages_; 00069 Wt::WContainerWidget *messageEditArea_; 00070 Wt::WTextArea *messageEdit_; 00071 Wt::WPushButton *sendButton_; 00072 Wt::WContainerWidget *userList_; 00073 00074 boost::signals::connection eventConnection_; 00075 00076 Wt::WSound messageReceived_; 00077 00078 void login(); 00079 void logout(); 00080 void send(); 00081 void updateUsers(); 00082 void updateUser(); 00083 00084 /* called from another session */ 00085 void processChatEvent(const ChatEvent& event); 00086 }; 00087 00090 #endif // SIMPLECHATWIDGET