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 SimpleChatServer& server_; 00056 Wt::WApplication *app_; 00057 00058 Wt::JSlot clearInput_; 00059 00060 Wt::WString user_; 00061 00062 Wt::WLineEdit *userNameEdit_; 00063 Wt::WText *statusMsg_; 00064 00065 Wt::WContainerWidget *messages_; 00066 Wt::WContainerWidget *messageEditArea_; 00067 Wt::WTextArea *messageEdit_; 00068 Wt::WPushButton *sendButton_; 00069 Wt::WContainerWidget *userList_; 00070 00071 boost::signals::connection eventConnection_; 00072 00073 Wt::WSound messageReceived_; 00074 00075 void login(); 00076 void logout(); 00077 void send(); 00078 void updateUsers(); 00079 00080 /* called from another session */ 00081 void processChatEvent(const ChatEvent& event); 00082 00083 void onEditBlur(); 00084 void onEditFocus(); 00085 }; 00086 00089 #endif // SIMPLECHATWIDGET