Wt examples  3.2.1
/home/koen/project/wt/public-git/wt/examples/simplechat/SimpleChatWidget.h
Go to the documentation of this file.
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 #include "SimpleChatServer.h"
00016 
00017 namespace Wt {
00018   class WApplication;
00019   class WPushButton;
00020   class WText;
00021   class WLineEdit;
00022   class WTextArea;
00023 }
00024 
00025 class ChatEvent;
00026 
00031 
00034 class SimpleChatWidget : public Wt::WContainerWidget,
00035                          public SimpleChatServer::Client
00036 {
00037 public:
00040   SimpleChatWidget(SimpleChatServer& server, Wt::WContainerWidget *parent = 0);
00041 
00044   ~SimpleChatWidget();
00045 
00046   void connect();
00047   void disconnect();
00048 
00049 
00052   void letLogin();
00053 
00058   bool startChat(const Wt::WString& user);
00059 
00060   void logout();
00061 
00062   SimpleChatServer& server() { return server_; }
00063 
00064   int userCount() { return users_.size(); }
00065 
00066   const Wt::WString& userName() const { return user_; }
00067 
00068 protected:
00069   virtual void createLayout(Wt::WWidget *messages, Wt::WWidget *userList,
00070                             Wt::WWidget *messageEdit,
00071                             Wt::WWidget *sendButton, Wt::WWidget *logoutButton);
00072 
00073   virtual void updateUsers();
00074   virtual void newMessage();
00075 
00076   virtual void render(Wt::WFlags<Wt::RenderFlag> flags);
00077 
00078 protected:
00079   bool loggedIn() const;
00080 
00081 private:
00082   typedef std::map<Wt::WString, bool> UserMap;
00083   UserMap users_;
00084 
00085   SimpleChatServer&     server_;
00086   bool                  loggedIn_;
00087 
00088   Wt::JSlot             clearInput_;
00089 
00090   Wt::WString           user_;
00091 
00092   Wt::WLineEdit        *userNameEdit_;
00093   Wt::WText            *statusMsg_;
00094 
00095   Wt::WContainerWidget *messages_;
00096   Wt::WContainerWidget *messageEditArea_;
00097   Wt::WTextArea        *messageEdit_;
00098   Wt::WPushButton      *sendButton_;
00099   Wt::WContainerWidget *userList_;
00100 
00101   Wt::WSound* messageReceived_;
00102 
00103   void login();
00104   void send();
00105   void updateUser();
00106 
00107   /* called from another session */
00108   void processChatEvent(const ChatEvent& event);
00109 };
00110 
00113 #endif // SIMPLECHATWIDGET

Generated on Fri Mar 30 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1