/usr/lib/Wt/examples/simplechat/simpleChat.C is in witty-examples 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | /*
* Copyright (C) 2008 Emweb bvba, Heverlee, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
#include <Wt/WPushButton>
#include <Wt/WServer>
#include <Wt/WText>
#include "SimpleChatServer.h"
#include "PopupChatWidget.h"
using namespace Wt;
/**
* @addtogroup chatexample
*/
/*@{*/
/*! \brief A chat demo application.
*/
class ChatApplication : public WApplication
{
public:
/*! \brief Create a new instance.
*/
ChatApplication(const WEnvironment& env, SimpleChatServer& server);
private:
SimpleChatServer& server_;
/*! \brief Add another chat client.
*/
void addChatWidget();
};
ChatApplication::ChatApplication(const WEnvironment& env,
SimpleChatServer& server)
: WApplication(env),
server_(server)
{
setTitle("Wt Chat");
useStyleSheet("chatapp.css");
messageResourceBundle().use(appRoot() + "simplechat");
root()->addWidget(new WText(WString::tr("introduction")));
SimpleChatWidget *chatWidget = new SimpleChatWidget(server_, root());
chatWidget->setStyleClass("chat");
root()->addWidget(new WText(WString::tr("details")));
WPushButton *b = new WPushButton("I'm schizophrenic ...", root());
b->clicked().connect(b, &WPushButton::hide);
b->clicked().connect(this, &ChatApplication::addChatWidget);
}
void ChatApplication::addChatWidget()
{
SimpleChatWidget *chatWidget2 = new SimpleChatWidget(server_, root());
chatWidget2->setStyleClass("chat");
}
/*! \brief A chat application widget.
*/
class ChatWidget : public WApplication
{
public:
ChatWidget(const WEnvironment& env, SimpleChatServer& server);
private:
JSignal<WString> login_;
};
ChatWidget::ChatWidget(const WEnvironment& env, SimpleChatServer& server)
: WApplication(env),
login_(this, "login")
{
useStyleSheet("chatwidget.css");
useStyleSheet("chatwidget_ie6.css", "lt IE 7");
const std::string *div = env.getParameter("div");
std::string defaultDiv = "div";
if (!div)
div = &defaultDiv;
if (div) {
setJavaScriptClass(*div);
PopupChatWidget *chatWidget = new PopupChatWidget(server);
bindWidget(chatWidget, *div);
login_.connect(chatWidget, &PopupChatWidget::setName);
std::string chat = javaScriptClass();
doJavaScript("if (window." + chat + "User) "
+ chat + ".emit(" + chat + ", 'login', " + chat + "User);"
+ "document.body.appendChild(" + chatWidget->jsRef() + ");");
} else {
std::cerr << "Missing: parameter: 'div'" << std::endl;
quit();
}
}
WApplication *createApplication(const WEnvironment& env,
SimpleChatServer& server)
{
return new ChatApplication(env, server);
}
WApplication *createWidget(const WEnvironment& env, SimpleChatServer& server)
{
return new ChatWidget(env, server);
}
int main(int argc, char **argv)
{
Wt::WServer server(argv[0]);
SimpleChatServer chatServer(server);
server.setServerConfiguration(argc, argv, WTHTTP_CONFIGURATION);
/*
* We add two entry points: one for the full-window application,
* and one for a widget that can be integrated in another page.
*/
server.addEntryPoint(Wt::Application,
boost::bind(createApplication, _1,
boost::ref(chatServer)));
server.addEntryPoint(Wt::WidgetSet,
boost::bind(createWidget, _1,
boost::ref(chatServer)), "/chat.js");
if (server.start()) {
int sig = Wt::WServer::waitForShutdown();
std::cerr << "Shutting down: (signal = " << sig << ")" << std::endl;
server.stop();
}
}
/*@}*/
|