/usr/lib/Wt/examples/simplechat/PopupChatWidget.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 | /*
* Copyright (C) 2010 Emweb bvba, Heverlee, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WImage>
#include <Wt/WText>
#include <Wt/WVBoxLayout>
#include "PopupChatWidget.h"
#include "SimpleChatServer.h"
// TODO:
// - oher color for jwt ?
// - i18n
PopupChatWidget::PopupChatWidget(SimpleChatServer& server)
: SimpleChatWidget(server)
{
if (Wt::WApplication::instance()->environment().agentIsIE()) {
if (Wt::WApplication::instance()->environment().agent() == Wt::WEnvironment::IE6)
setPositionScheme(Wt::Absolute);
else
setPositionScheme(Wt::Fixed);
}
online_ = false;
minimize();
}
void PopupChatWidget::setName(const Wt::WString& name)
{
if (name.empty())
return;
if (online_) {
int tries = 1;
Wt::WString n = name;
while (!server().changeName(name_, n))
n = name + boost::lexical_cast<std::string>(++tries);
name_ = n;
} else
name_ = name;
}
void PopupChatWidget::minimize()
{
if (!online_) {
clear();
addWidget(createBar());
title_->setText("Thoughts? Ventilate.");
}
setStyleClass("chat-widget chat-minimized");
}
Wt::WContainerWidget *PopupChatWidget::createBar()
{
Wt::WContainerWidget *bar = new Wt::WContainerWidget();
bar->setStyleClass("chat-bar");
Wt::WText *toggleButton = new Wt::WText();
toggleButton->setInline(false);
toggleButton->setStyleClass("chat-minmax");
bar->clicked().connect(this, &PopupChatWidget::toggleSize);
bar->addWidget(toggleButton);
title_ = new Wt::WText(bar);
return bar;
}
void PopupChatWidget::toggleSize()
{
if (styleClass() == "chat-widget chat-minimized")
maximize();
else
minimize();
}
void PopupChatWidget::createLayout(Wt::WWidget *messages,
Wt::WWidget *userList,
Wt::WWidget *messageEdit,
Wt::WWidget *sendButton,
Wt::WWidget *logoutButton)
{
Wt::WVBoxLayout *layout = new Wt::WVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
Wt::WContainerWidget *bar = createBar();
layout->addWidget(bar);
layout->addWidget(messages, 1);
layout->addWidget(messageEdit);
setLayout(layout);
}
void PopupChatWidget::updateUsers()
{
SimpleChatWidget::updateUsers();
int count = server().users().size();
if (count == 1)
title_->setText("Chat: 1 user online");
else
title_->setText("Chat: "
+ boost::lexical_cast<std::string>(count) + " users online");
}
void PopupChatWidget::maximize()
{
if (!online_) {
online_ = true;
int tries = 1;
Wt::WString name = name_;
if (name.empty())
name = server().suggestGuest();
while (!startChat(name)) {
if (name_.empty())
name = server().suggestGuest();
else
name = name_ + boost::lexical_cast<std::string>(++tries);
}
name_ = name;
}
setStyleClass("chat-widget chat-maximized");
}
|