00001 // This may look like C code, but it's really -*- C++ -*- 00002 /* 00003 * Copyright (C) 2007 Koen Deforche 00004 * 00005 * See the LICENSE file for terms of use. 00006 */ 00007 00008 #ifndef SIMPLECHATWIDGET_H_ 00009 #define SIMPLECHATWIDGET_H_ 00010 00011 #include <WCompositeWidget> 00012 #include <WSignal> 00013 00014 namespace Wt { 00015 class WApplication; 00016 class WContainerWidget; 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::WCompositeWidget 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 Wt::WContainerWidget *layout_; 00056 SimpleChatServer& server_; 00057 Wt::WApplication *app_; 00058 00059 Wt::WString user_; 00060 00061 Wt::WLineEdit *userNameEdit_; 00062 Wt::WText *statusMsg_; 00063 00064 Wt::WContainerWidget *messages_; 00065 Wt::WContainerWidget *messageEditArea_; 00066 Wt::WTextArea *messageEdit_; 00067 Wt::WPushButton *sendButton_; 00068 Wt::WContainerWidget *userList_; 00069 00070 boost::signals::connection eventConnection_; 00071 00072 void login(); 00073 void logout(); 00074 void send(); 00075 void updateUsers(); 00076 00077 /* called from another session */ 00078 void processChatEvent(const ChatEvent& event); 00079 00080 void onEditBlur(); 00081 void onEditFocus(); 00082 }; 00083 00086 #endif // SIMPLECHATWIDGET