Ejemplo n.º 1
0
int ChatEventList::addEvent(const MUCCEVENT *muccevent) {
	int trimmed = 0;
	ChatEvent *event = new ChatEvent(muccevent);
	event->setPrev(eventListEnd);
	eventListEnd->setNext(event);
	eventListEnd=event;
	currentSize++;	
	if (currentSize>hiMaxSize) {
		while (currentSize>loMaxSize && eventListRoot.getNext()!=NULL) {
			delete eventListRoot.getNext();
			currentSize--;
			trimmed = 1;
		}
	}
//	Utils::log("#### eventList size = %d", currentSize);
	return trimmed;
}
Ejemplo n.º 2
0
void SimpleChatWidget::processChatEvent(const ChatEvent& event)
{
  WApplication *app = WApplication::instance();

  /*
   * This is where the "server-push" happens. The chat server posts to this
   * event from other sessions, see SimpleChatServer::postChatEvent()
   */

  /*
   * Format and append the line to the conversation.
   *
   * This is also the step where the automatic XSS filtering will kick in:
   * - if another user tried to pass on some JavaScript, it is filtered away.
   * - if another user did not provide valid XHTML, the text is automatically
   *   interpreted as PlainText
   */

  /*
   * If it is not a plain message, also update the user list.
   */
  if (event.type() != ChatEvent::Message) {
    if (event.type() == ChatEvent::Rename && event.user() == user_)
      user_ = event.data();

    updateUsers();
  }

  /*
   * This is the server call: we (schedule to) propagate the updated UI to
   * the client.
   *
   * This schedules an update and returns immediately
   */
  app->triggerUpdate();

  newMessage();

  /*
   * Anything else doesn't matter if we are not logged in.
   */
  if (!loggedIn())
    return;

  bool display = event.type() != ChatEvent::Message
    || !userList_
    || (users_.find(event.user()) != users_.end() && users_[event.user()]);

  if (display) {
    WText *w = new WText(messages_);

    /*
     * If it fails, it is because the content wasn't valid XHTML
     */
    if (!w->setText(event.formattedHTML(user_, XHTMLText))) {
      w->setText(event.formattedHTML(user_, PlainText));
      w->setTextFormat(XHTMLText);
    }

    w->setInline(false);
    w->setStyleClass("chat-msg");

    /*
     * Leave no more than 100 messages in the back-log
     */
    if (messages_->count() > 100)
      delete messages_->children()[0];

    /*
     * Little javascript trick to make sure we scroll along with new content
     */
    app->doJavaScript(messages_->jsRef() + ".scrollTop += "
		       + messages_->jsRef() + ".scrollHeight;");

    /* If this message belongs to another user, play a received sound */
    if (event.user() != user_ && messageReceived_)
      messageReceived_->play();
  }
}
Ejemplo n.º 3
0
void SimpleWebWidget::processChatEvent(const ChatEvent& event)

{

	WApplication *app = WApplication::instance();

	app->triggerUpdate();

	if (event.type() == ChatEvent::Status)
	{
		if (event.iflyvalue() == 0)
		{
			dialog->show();
		}
		else
		{
			dialog->hide();
		}
	}
	if (event.type() == ChatEvent::LatLon)
	{
		double tempLat;
		double tempLon;

		tempLat = event.iflydoublevalue();
		tempLon = event.iflydoublevalue2();

		map->clearOverlays();
		map->setCenter(Wt::WGoogleMap::Coordinate(tempLat, tempLon));
		map->addMarker(Wt::WGoogleMap::Coordinate(tempLat, tempLon));

	}

	if (event.type() == ChatEvent::LastWPT)
	{
		txtLastName->setText(event.wttext());
		txtLastAlt->setText(boost::lexical_cast<std::string>(event.iflyvalue()));
		txtLastATA->setText(event.wttext2());
		txtLastFuel->setText(boost::lexical_cast<std::string>(event.iflyvalue3()));
	}

	if (event.type() == ChatEvent::ActualWPT)
	{
		txtActName->setText(event.wttext());
		txtActETA->setText(event.wttext2());
		txtActFuel->setText(boost::lexical_cast<std::string>(event.iflyvalue2()));
		std::stringstream ss;
		ss << std::fixed << std::setprecision(2) << event.iflydoublevalue();
		txtActDTG->setText(ss.str());
	}

	if (event.type() == ChatEvent::NextWPT)
	{
		txtNextName->setText(event.wttext());
		txtNextETA->setText(event.wttext2());
		txtNextFuel->setText(boost::lexical_cast<std::string>(event.iflyvalue2()));

		std::stringstream ss;
		ss << std::fixed << std::setprecision(2) << event.iflydoublevalue();
		txtNextDTG->setText(ss.str());
	}

	if (event.type() == ChatEvent::Destination)
	{
		txtDestinationETA->setText(event.wttext());
		txtDestinationFuel->setText(boost::lexical_cast<std::string>(event.iflyvalue()));

		std::stringstream ss;
		ss << std::fixed << std::setprecision(2) << event.iflydoublevalue();
		txtDestinationDTG->setText(ss.str());
	}

	if (event.type() == ChatEvent::Alt)
	{
		int tempInt;

		tempInt = event.iflyvalue();
		std::string tempString = boost::lexical_cast<std::string>(tempInt);
		txtAlt->setText(tempString);
	}

	if (event.type() == ChatEvent::Speed)
	{
		int tempInt;

		tempInt = event.iflyvalue();
		std::string tempString = boost::lexical_cast<std::string>(tempInt);
		txtSpeed->setText(tempString);
	}

	if (event.type() == ChatEvent::Temperature)
	{
		int tempInt;

		tempInt = event.iflyvalue();
		std::string tempString = boost::lexical_cast<std::string>(tempInt);
		txtTemperature->setText(tempString);
	}

	if (event.type() == ChatEvent::OnGround)
	{
		if (event.iflyvalue() == 1)
		{
			txtOnGround->setText("Yes");
		}
		else
		{
			txtOnGround->setText("No");
		}
	}

	if (event.type() == ChatEvent::GroundPower)
	{
		if (event.iflyvalue() == 0)
		{
			btnGroundPower_->setStyleClass("btn-danger");
			btnGroundPower_->setText("Ground Power NA\nSet Parking Brake");
		}
		if (event.iflyvalue() == 1)
		{
			btnGroundPower_->setStyleClass("btn-success");
			btnGroundPower_->setText("Ground Power\nAvailable");
		}
		if (event.iflyvalue() == 2)
		{
			btnGroundPower_->setStyleClass("btn-primary");
			btnGroundPower_->setText("Ground Power\nConnected");
		}

	}

	if (event.type() == ChatEvent::GroundAir)
	{
		if (event.iflyvalue() == 0)
		{
			btnGroundAir_->setStyleClass("btn-danger");
			btnGroundAir_->setText("Ground Air NA\nSet Parking Brake");
		}
		if (event.iflyvalue() == 1)
		{
			btnGroundAir_->setStyleClass("btn-success");
			btnGroundAir_->setText("Ground Air\nAvailable");
		}
		if (event.iflyvalue() == 2)
		{
			btnGroundAir_->setStyleClass("btn-primary");
			btnGroundAir_->setText("Ground Air\nConnected");
		}

	}


	if (event.type() == ChatEvent::Oooi)
	{
		txtOut->setText(event.wttext());
		txtOff->setText(event.wttext2());
		txtOn->setText(event.wttext3());
		txtIn->setText(event.wttext4());
	}

	if (event.type() == ChatEvent::Door)
	{
		if (event.iflydata() == 1)
		{
			if (event.iflyvalue() == 0)
			{
				btnDoor1_->setStyleClass("btn-success");
				btnDoor1_->setText("Main door is CLOSED\nPress to open");
			}
			else
			{
				btnDoor1_->setStyleClass("btn-danger");
				btnDoor1_->setText("Main door is OPEN\nPress to close");
			}
		}
		if (event.iflydata() == 2)
		{
			if (event.iflyvalue() == 0)
			{
				btnDoor2_->setStyleClass("btn-success");
				btnDoor2_->setText("Cargo door is CLOSED\nPress to open");
			}
			else
			{
				btnDoor2_->setStyleClass("btn-danger");
				btnDoor2_->setText("Cargo door is OPEN\nPress to close");
			}
		}
		if (event.iflydata() == 3)
		{
			if (event.iflyvalue() == 0)
			{
				btnDoor3_->setStyleClass("btn-success");
				btnDoor3_->setText("Service door is CLOSED\nPress to open");
			}
			else
			{
				btnDoor3_->setStyleClass("btn-danger");
				btnDoor3_->setText("Service door is OPEN\nPress to close");
			}
		}
	}
	if (event.type() == ChatEvent::WxrMetarDep)
	{
		txtWxrDep->setText(event.wttext());
	}
	if (event.type() == ChatEvent::WxrTafDep)
	{
		txtWxrTafDep->setText(event.wttext());
	}
	if (event.type() == ChatEvent::WxrMetarArr)
	{
		txtWxrArr->setText(event.wttext());
	}
	if (event.type() == ChatEvent::WxrTafArr)
	{
		txtWxrTafArr->setText(event.wttext());
	}

	if (event.type() == ChatEvent::FlightInfo)
	{
		infoBox->setTitle(event.wttext());
	}

	if (event.type() == ChatEvent::GsxMenuText)
	{
	

		if (event.iflyvalue() == 0) {
			Wt:WString _temptitle = "GSX Menu / ";
			_temptitle = _temptitle + event.wttext();
			gsxBox->setTitle(_temptitle);
		}

		if (event.iflyvalue() == 1) { btnVirtualKey1_->setText(event.wttext()); btnVirtualKey1_->show(); }
		if (event.iflyvalue() == 2) { btnVirtualKey2_->setText(event.wttext()); btnVirtualKey2_->show(); }
		if (event.iflyvalue() == 3) { btnVirtualKey3_->setText(event.wttext()); btnVirtualKey3_->show(); }
		if (event.iflyvalue() == 4) { btnVirtualKey4_->setText(event.wttext()); btnVirtualKey4_->show(); }
		if (event.iflyvalue() == 5) { btnVirtualKey5_->setText(event.wttext()); btnVirtualKey5_->show(); }
		if (event.iflyvalue() == 6) { btnVirtualKey6_->setText(event.wttext()); btnVirtualKey6_->show(); }
		if (event.iflyvalue() == 7) { btnVirtualKey7_->setText(event.wttext()); btnVirtualKey7_->show(); }
		if (event.iflyvalue() == 8) { btnVirtualKey8_->setText(event.wttext()); btnVirtualKey8_->show(); }
		if (event.iflyvalue() == 9) { btnVirtualKey9_->setText(event.wttext()); btnVirtualKey9_->show(); }
		if (event.iflyvalue() == 10) { btnVirtualKey0_->setText(event.wttext()); btnVirtualKey0_->show(); }
	}

	if (event.type() == ChatEvent::GsxTextText)
	{
		txtGSXText->setText(event.wttext());
	}
}