This file is indexed.

/usr/lib/Wt/examples/simplechat/PopupChatWidget.C is in witty-examples 3.3.0-1build1.

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * 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:
//  - i18n

PopupChatWidget::PopupChatWidget(SimpleChatServer& server,
				 const std::string& id)
  : SimpleChatWidget(server),
    missedMessages_(0)
{
  setId(id);

  if (Wt::WApplication::instance()->environment().agentIsIE()) {
    if (Wt::WApplication::instance()->environment().agent()
	== Wt::WEnvironment::IE6)
      setPositionScheme(Wt::Absolute);
    else
      setPositionScheme(Wt::Fixed);
  }

  implementJavaScript
    (&PopupChatWidget::toggleSize,
     "{"
     """var s = $('#" + id + "');"
     """s.toggleClass('chat-maximized chat-minimized');"
     + Wt::WApplication::instance()->javaScriptClass()
     + ".layouts2.scheduleAdjust(true);"
     "}");

  online_ = false;
  minimized_ = true;
  setStyleClass("chat-widget chat-minimized");

  clear();
  addWidget(createBar());
  updateUsers();

  connect();
}

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;
}

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->clicked().connect(this, &PopupChatWidget::goOnline);

  bar->addWidget(toggleButton);

  title_ = new Wt::WText(bar);

  bar_ = bar;

  return bar;
}

void PopupChatWidget::toggleSize()
{
  minimized_ = !minimized_;
}

void PopupChatWidget::goOnline()
{
  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;
  }

  missedMessages_ = 0;
  bar_->removeStyleClass("alert");
}

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);
  bar->setMinimumSize(Wt::WLength::Auto, 20);
  layout->addWidget(messages, 1);
  layout->addWidget(messageEdit);

  setLayout(layout);
}

void PopupChatWidget::updateUsers()
{
  SimpleChatWidget::updateUsers();

  int count = server().users().size();

  if (!loggedIn()) {
    if (count == 0)
      title_->setText("Thoughts? Ventilate.");
    else if (count == 1)
      title_->setText("Chat: 1 user online");
    else
      title_->setText(Wt::WString("Chat: {1} users online").arg(count));
  } else {
    title_->setText(Wt::WString("Chat: <span class=\"self\">{1}</span>"
				" <span class=\"online\">({2} user{3})</span>")
		    .arg(userName()).arg(count).arg(count == 1 ? "" : "s"));
  }
}

void PopupChatWidget::newMessage()
{
  if (loggedIn() && minimized()) {
    ++missedMessages_;
    if (missedMessages_ == 1) {
      bar_->addStyleClass("alert");
    }
  }
}

bool PopupChatWidget::minimized() const
{
  return minimized_;
}