Exemplo n.º 1
0
std::string WText::RichText::formattedText() const
{
  if (format == PlainText)
    return escapeText(text, true).toUTF8();
  else
    return text.toUTF8();
}
Exemplo n.º 2
0
void InvoiceFormatter::formatPatientData(StringBuffer &buf, InvoiceData &invoice) {
	buf.Cat("[*A1 " + AsString(t_("Patient:")) + "] [A1 " 
		+ invoice.patient_name + ", " + invoice.patient_species);
	if (!invoice.patient_breed.IsEmpty())
		buf.Cat(" (" + invoice.patient_breed + ")");
	buf.Cat("&]");
	buf.Cat("[A1 " + escapeText(invoice.rec_text) + "] ");
}
Exemplo n.º 3
0
void WPushButton::updateDom(DomElement& element, bool all)
{
  if (textChanged_ || all) {
    element
      .setProperty(Wt::PropertyInnerHTML,
		   text_.literal()
		   ? toUTF8(escapeText(text_.value()))
		   : toUTF8(text_.value()));
    textChanged_ = false;
  }

  WFormWidget::updateDom(element, all);
}
Exemplo n.º 4
0
void WGroupBox::updateDom(DomElement& element, bool all)
{
  if (titleChanged_) {
    DomElement *legend
      = DomElement::getForUpdate(formName() + "l", DomElement::LEGEND);
    legend->setProperty(Wt::PropertyInnerHTML,
			toUTF8(escapeText(title_.value())));
    titleChanged_ = false;
  }

  WContainerWidget::updateDom(element, all);

  renderOk();
}
Exemplo n.º 5
0
void WTemplate::bindString(const std::string& varName, const WString& value,
			   TextFormat textFormat)
{
  WWidget *w = resolveWidget(varName);
  if (w)
    bindWidget(varName, 0);

  WString v = value;

  if (textFormat == XHTMLText && v.literal()) {
    if (!removeScript(v))
      v = escapeText(v, true);
  } else if (textFormat == PlainText)
    v = escapeText(v, true);

  StringMap::const_iterator i = strings_.find(varName);

  if (i == strings_.end() || i->second != v.toUTF8()) {
    strings_[varName] = v.toUTF8();

    changed_ = true;
    repaint(RepaintInnerHtml);  
  }
}
Exemplo n.º 6
0
DomElement *WGroupBox::createDomElement()
{
  DomElement *result = DomElement::createNew(DomElement::FIELDSET);
  result->setId(this);

  DomElement *legend = DomElement::createNew(DomElement::LEGEND);
  legend->setId(formName() + "l");
  legend->setProperty(Wt::PropertyInnerHTML,
		      toUTF8(escapeText(title_.value())));
  result->addChild(legend);

  createDomChildren(*result);

  updateDom(*result, true);

  return result;
}
Exemplo n.º 7
0
void WGroupBox::updateDom(DomElement& element, bool all)
{
  if (all || titleChanged_) {
    DomElement *legend;
    if (all) {
      legend = DomElement::createNew(DomElement_LEGEND);
      legend->setId(id() + "l");
    } else
      legend = DomElement::getForUpdate(id() + "l", DomElement_LEGEND);

    legend->setProperty(Wt::PropertyInnerHTML, escapeText(title_).toUTF8());
    element.addChild(legend);

    titleChanged_ = false;
  }

  WContainerWidget::updateDom(element, all);
}
Exemplo n.º 8
0
Arquivo: WText.C Projeto: LifeGo/wt
std::string WText::formattedText() const
{
  if (text_.format == PlainText)
    return escapeText(text_.text, true).toUTF8();
  else {
    WApplication *app = WApplication::instance();
    if (flags_.test(BIT_ENCODE_INTERNAL_PATHS)
	|| app->session()->hasSessionIdInUrl()) {
      WFlags<RefEncoderOption> options;
      if (flags_.test(BIT_ENCODE_INTERNAL_PATHS))
	options |= EncodeInternalPaths;
      if (app->session()->hasSessionIdInUrl())
	options |= EncodeRedirectTrampoline;
      return EncodeRefs(text_.text, options).toUTF8();
    } else
      return text_.text.toUTF8();
  }
}
Exemplo n.º 9
0
void WComboBox::updateDom(DomElement& element, bool all)
{
  if (itemsChanged_ || all) {
    if (!all)
      element.removeAllChildren();

    for (int i = 0; i < count(); ++i) {
      DomElement *item = DomElement::createNew(DomElement_OPTION);
      item->setProperty(PropertyValue, boost::lexical_cast<std::string>(i));
      item->setProperty(PropertyInnerHTML,
			escapeText(asString(model_->data(i, modelColumn_)))
			.toUTF8());
      if (isSelected(i))
	item->setProperty(PropertySelected, "true");

      WString sc = asString(model_->data(i, modelColumn_, StyleClassRole));
      if (!sc.empty())
	item->setProperty(PropertyClass, sc.toUTF8());

      element.addChild(item);
    }

    itemsChanged_ = false;
    selectionChanged_ = false;
  }

  if (selectionChanged_) {
    element.setProperty(PropertySelectedIndex,
			boost::lexical_cast<std::string>(currentIndex_));
    selectionChanged_ = false;
  }

  if (!currentlyConnected_
      && (activated_.isConnected() || sactivated_.isConnected())) {
    currentlyConnected_ = true;
    changed().connect(this, &WComboBox::propagateChange);
  }

  WFormWidget::updateDom(element, all);
}
Exemplo n.º 10
0
void TopicEdit::focusInEvent ( QFocusEvent * )
{
	setText(escapeText(m_topicText));
}
Exemplo n.º 11
0
  void startDownload()
  {
    // Enable server push
    wApp->enableUpdates(true);

    rssText_->setText("");
    resultText_->setText("");
    addText("Resolving hostname...");
    startButton_->setText("Busy...");
    /*
     * Name resolving may take a while, so entertain the user
     * already with the updates so far. As this slot is invoked
     * by the browser (caused by the user clicking the 'start'
     * button), we can use processEvents() to send the changes
     * we made to the widget tree up till here back to the browser
     */
    wApp->processEvents();

    struct addrinfo *info;
    if (getaddrinfo(HOSTNAME, "http", 0, &info) == 0) {
      socket_ = ::socket(info->ai_family, info->ai_socktype, info->ai_protocol);
      /*
       * Install notifiers for read and write events. These will end up
       * in a call to select, and activated() will be called whenever
       * select decides that the socket is ready for read or write.
       */
      readNotifier_ = new Wt::WSocketNotifier(socket_,
          Wt::WSocketNotifier::Read, this);
      readNotifier_->setEnabled(false); // Linux fires this on connect, weird
      readNotifier_->activated().connect(this, &RssReader::read);
      writeNotifier_ = new Wt::WSocketNotifier(socket_,
          Wt::WSocketNotifier::Write, this);
      writeNotifier_->activated().connect(this, &RssReader::write);

      // Set sockets to non-blocking
#ifndef WT_WIN32
      int flags = ::fcntl(socket_, F_GETFL, 0);
      flags |= O_NONBLOCK;
      ::fcntl(socket_, F_SETFL, flags);
#else
      u_long enabled = 1;
      ::ioctlsocket(socket_, FIONBIO, &enabled);
#endif
      // Perform a non-blocking connect. POSIX specifies that the socket
      // will be marked as ready for write when the connect call completes.
      int err = ::connect(socket_, info->ai_addr, info->ai_addrlen);
#ifndef WT_WIN32
      int err2 = errno;
#else
      int err2 = GetLastError();
#endif
      freeaddrinfo(info);

      addText(" Done!<br/>Connecting...");
      wApp->processEvents();

      if (err == 0) {
        // connected, proceed immediately to 'writing'
        state_ = WRITE;
        // write() will be invoked automatically by the notifier.
      } else if (err == -1) {
#ifndef WT_WIN32
        if (err2 == EINPROGRESS) {
#else
        if (err2 == WSAEWOULDBLOCK) {
#endif
          state_ = CONNECT;
          // The writeNotifier will be fired when connected
        } else {
          addText(" Problem with connect(). Giving up.<br/>");
          cleanup();
        }
      }
    } else {
      addText("Terminating: could not resolve web service host: " HOSTNAME);
      cleanup();
    }
  }

  void write()
  {
    const char request[] = "GET " URL_PATH " HTTP/1.1\r\n"
      "Host: " HOSTNAME "\r\n"
      "Connection: Close\r\n\r\n";

    switch(state_) {
    case CONNECT:
      {
        int err;
        socklen_t len = sizeof err;
        getsockopt(socket_, SOL_SOCKET, SO_ERROR, (char *)&err, &len);
        if (err != 0) {
          addText(" connect() failed. Giving up.<br/>");
          cleanup();
        } else {
          addText(" Connected!<br/>Writing data");
          state_ = WRITE;
        }
      }
      break;
    case WRITE:
      {
        addText(".");
        // write in bits for demonstration purposes only
        int len = (std::min<int>)(10, (sizeof request) - bytesSent_);
        int retval = ::send(socket_, request + bytesSent_, len, 0);
        if (retval >= 0) {
          bytesSent_ += retval;
          if (bytesSent_ >= (int)(sizeof request)) {
            addText(" Done!<br/>Reading data");
            state_ = READ;
            // We don't need any further notifications that we can
            // keep writing
            writeNotifier_->setEnabled(false);
            readNotifier_->setEnabled(true);
          }
        } else {
#ifndef WT_WIN32
          if (errno != EAGAIN) {
#else
          if (GetLastError() == WSAEWOULDBLOCK) {
#endif
            addText("send() failed. Giving up.<br/>");
            cleanup();
          }
        }
      }
      break;
      case READ:
	break;
    }
  }

  void read()
  {
    addText(".");
    char buf[128];
    int retval = ::recv(socket_, buf, sizeof buf, 0);
    if (retval == 0) {
      // 'orderly shutdown'
      addText(" Done! (Remote end closed connection)<br/>");
      cleanup();
    } else if (retval < 0) {
#ifndef WT_WIN32
      if (errno != EAGAIN) {
#else
      if (GetLastError() == WSAEWOULDBLOCK) {
#endif
        // Euh.. all done?
        addText("recv failed. Giving up.<br/>");
        cleanup();
      }
    } else {
      inStream_.write(buf, retval);
    }
  }

  void cleanup()
  {
    /*
     * It is mandatory not to have notifiers on closed sockets,
     * as select() fails miserably in this case. Disable (or even
     * better, delete) the notifiers before you close the sockets.
     */
    delete readNotifier_;
    delete writeNotifier_;
    readNotifier_ = writeNotifier_ = 0;
#ifdef WT_WIN32
    closesocket(socket_);
#else
    close(socket_);
#endif
    socket_ = 0;
    state_ = CONNECT;
    bytesSent_ = 0;
    startButton_->setText("Again");
    startButton_->enable();
    rssText_->setText("<pre>" +
        escapeText(Wt::WString::fromUTF8(inStream_.str())) + "</pre>");
    addText("Finished!<br/>Run again?<br/>");
    inStream_.str("");
    wApp->enableUpdates(false);
  }
};
Exemplo n.º 12
0
void WPushButton::updateDom(DomElement& element, bool all)
{
  if (all) {
    element.setAttribute("type", "button");
    element.setProperty(PropertyClass, "Wt-btn");
  }

  if (flags_.test(BIT_ICON_CHANGED) || (all && !icon_.isNull())) {
    DomElement *image = DomElement::createNew(DomElement_IMG);
    image->setProperty(PropertySrc, icon_.url());
    image->setId("im" + formName());
    element.insertChildAt(image, 0);
    flags_.set(BIT_ICON_RENDERED);
  }

  if (flags_.test(BIT_TEXT_CHANGED) || all) {
    element
      .setProperty(Wt::PropertyInnerHTML,
		   text_.literal() ? escapeText(text_, true).toUTF8()
		   : text_.toUTF8());
    flags_.reset(BIT_TEXT_CHANGED);
  }

  if (flags_.test(BIT_LINK_CHANGED) || (all && !link_.isNull())) {
    if (!link_.isNull()) {
      WApplication *app = WApplication::instance();

      if (!redirectJS_) {
	redirectJS_ = new JSlot();
	clicked().connect(*redirectJS_);

	if (!app->environment().ajax())
	  clicked().connect(this, &WPushButton::doRedirect);
      }

      if (link_.type() == WLink::InternalPath)
	redirectJS_->setJavaScript
	  ("function(){"
	   WT_CLASS ".history.navigate(" + jsStringLiteral(link_.internalPath())
	   + ",true);"
	   "}");
      else
	if (linkTarget_ == TargetNewWindow)
	  redirectJS_->setJavaScript
	    ("function(){"
	     "window.open(" + jsStringLiteral(link_.url()) + ");"
	     "}");
	else
	  redirectJS_->setJavaScript
	    ("function(){"
	     "window.location=" + jsStringLiteral(link_.url()) + ";"
	     "}");
      clicked().senderRepaint(); // XXX only for Java port necessary
    } else {
      delete redirectJS_;
      redirectJS_ = 0;
    }
  }

  WFormWidget::updateDom(element, all);
}