Esempio n. 1
0
 /**
 * @brief Gives you a nice pair of buttons
 *
 * @param parent Parent Widget
 */
 ButtonBar(const WString& button1Text="", const WString& button2Text="", WContainerWidget* parent=0) : MoreAwesomeTemplate(parent) {
     WString btn1Text = button1Text.empty() ? WString::tr("OK") : button1Text;
     WString btn2Text = button2Text.empty() ? WString::tr("Cancel") : button2Text;
     setTemplateText(tr("button-bar"));
     setStyleClass("yui-gb button-bar");
     bindAndCreateWidget(_btn1, "btn-1", btn1Text);
     bindAndCreateWidget(_btn2, "btn-2", btn2Text);
 }
Esempio n. 2
0
std::vector<WLinkedCssStyleSheet> WBootstrapTheme::styleSheets() const
{
  std::vector<WLinkedCssStyleSheet> result;

  std::string themeDir = resourcesUrl();
  std::stringstream themeVersionDir;
  themeVersionDir << themeDir << static_cast<unsigned int>(version_) << "/";

  result.push_back(WLinkedCssStyleSheet
		   (WLink(themeVersionDir.str() + "bootstrap.css")));

  WApplication *app = WApplication::instance();
 
  if (responsive_) {
    if (version_ == BootstrapVersion::v2)
      result.push_back(WLinkedCssStyleSheet
		       (WLink(themeVersionDir.str()
			      + "bootstrap-responsive.css")));
    else if (app) {
      WString v = app->metaHeader(MetaHeaderType::Meta, "viewport");
      if (v.empty())
	app->addMetaHeader("viewport",
			   "width=device-width, initial-scale=1");
    }
  }

  result.push_back(WLinkedCssStyleSheet
		   (WLink(themeVersionDir.str() + "wt.css")));

  return result;
}
Esempio n. 3
0
bool XSSFilterRemoveScript(WString& text)
{
  if (text.empty())
    return true;

  std::string result = "<span>" + text.toUTF8() + "</span>";
  char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !

  try {
    xml_document<> doc;
    doc.parse<parse_comment_nodes
      | parse_validate_closing_tags
      | parse_validate_utf8
      | parse_xhtml_entity_translation>(ctext);

    XSSSanitize(doc.first_node());

    WStringStream out;
    print(out.back_inserter(), *doc.first_node(), print_no_indenting);
    result = out.str();
  } catch (parse_error& e) {
    LOG_ERROR("Error reading XHTML string: " << e.what());
    return false;
  }

  if (result.length() < 13)
    result.clear();
  else
    result = result.substr(6, result.length() - 13);

  text = WString::fromUTF8(result);

  return true;
}
Esempio n. 4
0
void EncodeRefs(WString& text, WFlags<RefEncoderOption> options)
{
  if (text.empty())
    return;

  std::string result = "<span>" + text.toUTF8() + "</span>";
  char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay !

  WApplication *app = WApplication::instance();

  try {
    xml_document<> doc;
    doc.parse<parse_comment_nodes
      | parse_validate_closing_tags
      | parse_validate_utf8
      | parse_xhtml_entity_translation>(ctext);

    EncodeRefs(doc.first_node(), app, options);

    WStringStream out;
    print(out.back_inserter(), *doc.first_node(), print_no_indenting);

    result = out.str();
  } catch (parse_error& e) {
    LOG_ERROR("Error reading XHTML string: " << e.what());
    return;
  }

  if (result.length() < 13)
    result.clear();
  else
    result = result.substr(6, result.length() - 13);

  text = WString::fromUTF8(result);
}
Esempio n. 5
0
void SimpleChatWidget::changeName(const WString& name)
{
  if (!name.empty()) {
    if (server_.changeName(user_, name))
      user_ = name;
  }
}
Esempio n. 6
0
 ServerSideValidator(
     const WString& validMsg="", const WString& invalidMsg="", const WString& emptyMsg="",
     bool isMandatory=false, WObject* parent=0)
     : WValidator(isMandatory, parent), _validMsg(validMsg), _invalidMsg(invalidMsg)
 {
     if (!emptyMsg.empty())
         setInvalidBlankText(emptyMsg);
 }
Esempio n. 7
0
void WTreeTable::setTreeRoot(std::unique_ptr<WTreeTableNode> root,
			     const WString& h)
{
  root->setTable(this);
  tree_->setTreeRoot(std::move(root));

  header(0)->setText(h.empty() ? "&nbsp;" : h);
}
Esempio n. 8
0
	void OnSearchTermChanged(const WString& search)
	{
		if(search.empty())
			m_selectionWheel->ClearFilter();
		else
		{
			String utf8Search = Utility::ConvertToUTF8(search);
			Map<int32, MapIndex*> filter = m_mapDatabase.FindMaps(utf8Search);
			m_selectionWheel->SetFilter(filter);
		}
	}
Esempio n. 9
0
void WSuggestionPopup::addSuggestion(const WString& suggestionText,
				     const WString& suggestionValue)
{
  int row = model_->rowCount();

  if (model_->insertRow(row)) {
    model_->setData(row, modelColumn_, boost::any(suggestionText), DisplayRole);
    if (!suggestionValue.empty())
      model_->setData(row, modelColumn_, boost::any(suggestionValue), UserRole);
  }
}
Esempio n. 10
0
void WInPlaceEdit::setText(const WString& text)
{
  empty_ = text.empty();

  if (!empty_)
    text_->setText(text);
  else
    text_->setText(placeholderText());

  edit_->setText(text);
}
Esempio n. 11
0
void WAnchor::setText(const WString& text)
{
  if (!text_) {
    text_ = new WText(text, this);
  } else
    if (!text.empty())
      text_->setText(text);
    else {
      delete text_;
      text_ = 0;
    }
}
Esempio n. 12
0
void SettingsPage::addSetting(const string& settingName, WFormWidget* widget)
{
  WString label = wtr(settingName + ".label");
  WString helpText = wtr(settingName + ".description");
  
  WLabel *labelWidget = WW<WLabel>(label).css("control-label");
  labelWidget->setBuddy(widget);
  WContainerWidget *control = WW<WContainerWidget>().css("controls").add(widget);
  if(!helpText.empty()) {
    control->addWidget(WW<WText>(helpText).css("help-block") );
  }
  addWidget(WW<WContainerWidget>().css("control-group")
    .add(labelWidget)
    .add( control ));
}
Esempio n. 13
0
WMenuItem::WMenuItem(bool separator, const WString& text)
  : separator_(true),
    triggered_(this)
{
  create(std::string(), WString::Empty, 0, LazyLoading);

  separator_ = separator;
  selectable_ = false;
  internalPathEnabled_ = false;

  if (!text.empty()) {
    text_ = new WLabel(this);
    text_->setTextFormat(PlainText);
    text_->setText(text);
  }
}
Esempio n. 14
0
WMenuItem::WMenuItem(bool separator, const WString& text)
  : separator_(true)
{
  create(std::string(), WString::Empty, nullptr, ContentLoading::Lazy);

  separator_ = separator;
  selectable_ = false;
  internalPathEnabled_ = false;

  if (!text.empty()) {
    text_ = new WLabel();
    addWidget(std::unique_ptr<WWidget>(text_));
    text_->setTextFormat(TextFormat::Plain);
    text_->setText(text);
  }
}
Esempio n. 15
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);
}
Esempio n. 16
0
WWidget *WItemDelegate::update(WWidget *widget, const WModelIndex& index,
			       WFlags<ViewItemRenderFlag> flags)
{
  bool editing = widget && widget->find("t") == 0;

  if (flags & RenderEditing) {
    if (!editing) {
      widget = createEditor(index, flags);
      WInteractWidget *iw = dynamic_cast<WInteractWidget *>(widget);
      if (iw) {
	// Disable drag & drop and selection behaviour
	iw->mouseWentDown().preventPropagation();
	iw->clicked().preventPropagation();
      }
    }
  } else {
    if (editing)
      widget = 0;
  }

  WidgetRef widgetRef(widget);

  bool isNew = false;

  if (!(flags & RenderEditing)) {
    if (!widgetRef.w) {
      isNew = true;
      IndexText *t = new IndexText(index);
      t->setObjectName("t");
      if (index.isValid() && !(index.flags() & ItemIsXHTMLText))
	t->setTextFormat(PlainText);
      t->setWordWrap(true);
      widgetRef.w = t;
    }

    if (!index.isValid())
      return widgetRef.w;

    bool haveCheckBox = false;

    boost::any checkedData = index.data(CheckStateRole);
    if (!checkedData.empty()) {
      haveCheckBox = true;
      CheckState state =
	(checkedData.type() == typeid(bool) ?
	   (boost::any_cast<bool>(checkedData) ? Checked : Unchecked)
	   : (checkedData.type() == typeid(CheckState) ?
	      boost::any_cast<CheckState>(checkedData) : Unchecked));
      IndexCheckBox *icb =
        checkBox(widgetRef, index, true, index.flags() & ItemIsTristate);
      icb->setCheckState(state);
      icb->setEnabled(index.flags() & ItemIsUserCheckable);
    } else if (!isNew)
      delete checkBox(widgetRef, index, false);

    boost::any linkData = index.data(LinkRole);
    if (!linkData.empty()) {
      WLink link = boost::any_cast<WLink>(linkData);
      IndexAnchor *a = anchorWidget(widgetRef, index);
      a->setLink(link);
      if (link.type() == WLink::Resource)
	a->setTarget(TargetNewWindow);
    }

    IndexText *t = textWidget(widgetRef, index);

    WString label = asString(index.data(), textFormat_);
    if (label.empty() && haveCheckBox)
      label = WString::fromUTF8(" ");
    t->setText(label);

    std::string iconUrl = asString(index.data(DecorationRole)).toUTF8();
    if (!iconUrl.empty()) {
      iconWidget(widgetRef, index, true)->setImageLink(WLink(iconUrl));
    } else if (!isNew)
      delete iconWidget(widgetRef, index, false);
  }

  if (index.flags() & ItemHasDeferredTooltip){
    widgetRef.w->setDeferredToolTip(true, (index.flags() & ItemIsXHTMLText) ?
                                      XHTMLText : PlainText);
  } else {
  WString tooltip = asString(index.data(ToolTipRole));
  if (!tooltip.empty() || !isNew)
    widgetRef.w->setToolTip(tooltip,
			    (index.flags() & ItemIsXHTMLText) ? 
			    XHTMLText : PlainText);
  }

  WT_USTRING sc = asString(index.data(StyleClassRole));

  if (flags & RenderSelected)
    sc += WT_USTRING::fromUTF8
      (" " + WApplication::instance()->theme()->activeClass());

  if (flags & RenderEditing)
    sc += WT_USTRING::fromUTF8(" Wt-delegate-edit");

  widgetRef.w->setStyleClass(sc);

  if (index.flags() & ItemIsDropEnabled)
    widgetRef.w->setAttributeValue("drop", WString::fromUTF8("true"));
  else
    if (!widgetRef.w->attributeValue("drop").empty())
      widgetRef.w->setAttributeValue("drop", WString::fromUTF8("f"));

  return widgetRef.w;
}
Esempio n. 17
0
	bool AccountManager::loadAccounts()
	{        
		bool noLoadAccount = HAS_OPTION( m_serviceProvider, "noaccounts" );

		if( noLoadAccount == true )
		{
			return true;
		}

		FilePath accountsPath = CONFIG_VALUE( m_serviceProvider, "Game", "AccountsPath", STRINGIZE_STRING_LOCAL( m_serviceProvider, "accounts.ini" ) );

		bool accountsExist = FILE_SERVICE(m_serviceProvider)
            ->existFile( CONST_STRING(m_serviceProvider, user), accountsPath, nullptr );

		if( accountsExist == false )
		{
			LOGGER_WARNING(m_serviceProvider)( "AccountManager::loadAccounts not exist accounts '%s'"
				, accountsPath.c_str()
				);

			return true;
		}
        
		InputStreamInterfacePtr file = FILE_SERVICE(m_serviceProvider)
            ->openInputFile( CONST_STRING(m_serviceProvider, user), accountsPath, false );

        if( file == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts open accounts failed '%s'"
                , accountsPath.c_str()
                );

            return false;
        }
		
		IniUtil::IniStore ini;
		if( IniUtil::loadIni( ini, file, m_serviceProvider ) == false )
		{
			LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts parsing accounts failed '%s'"
				, accountsPath.c_str()
				);

			return false;
		}

		file = nullptr;

		//unsigned int playerCount;

		//config.getSettingUInt( L"SETTINGS", L"AccountCount", playerCount );
        if( IniUtil::getIniValue( ini, "SETTINGS", "AccountEnumerator", m_playerEnumerator, m_serviceProvider ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts get AccountEnumerator failed '%s'"
                , accountsPath.c_str()
                );

            return false;
        }

		if( IniUtil::getIniValue( ini, "SETTINGS", "DefaultAccountID", m_defaultAccountID, m_serviceProvider ) == false )
        {
            LOGGER_INFO(m_serviceProvider)( "AccountManager::loadAccounts get DefaultAccountID failed '%s'"
                , accountsPath.c_str()
                );
        }           

		WString selectAccountID;
		if( IniUtil::getIniValue( ini, "SETTINGS", "SelectAccountID", selectAccountID, m_serviceProvider ) == false )
        {
            LOGGER_INFO(m_serviceProvider)( "AccountManager::loadAccounts get SelectAccountID failed '%s'"
                , accountsPath.c_str()
                );
        }   
        
        TVectorWString values;
		if( IniUtil::getIniValue( ini, "ACCOUNTS", "Account", values, m_serviceProvider ) == false )
        {
            LOGGER_INFO(m_serviceProvider)( "AccountManager::loadAccounts get ACCOUNTS failed '%s'"
                , accountsPath.c_str()
                );
        }  

        AccountInterfacePtr validAccount = nullptr;

		for( TVectorWString::const_iterator
			it = values.begin(), 
			it_end = values.end();
		it != it_end;
		++it )
		{
			const WString & name = *it;

			AccountInterfacePtr account = this->loadAccount_( name );

            if( account == nullptr )
            {
                LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccountsInfo invalid load account '%ls'"
                    , name.c_str()
                    );

                continue;
            }

            validAccount = account;

			m_accounts.insert( std::make_pair( name, account ) );
		}

		if( selectAccountID.empty() == false )
		{
            LOGGER_INFO(m_serviceProvider)( "AccountManager::loadAccounts select account '%ls'"
                , selectAccountID.c_str()
                );

			if( this->selectAccount( selectAccountID ) == false )
            {
                LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts invalid set select account '%ls'"
                    , selectAccountID.c_str()
                    );

                return false;
            }
		}
        else if( m_defaultAccountID.empty() == false )
        {
            LOGGER_INFO(m_serviceProvider)( "AccountManager::loadAccounts set default account '%ls'"
                , m_defaultAccountID.c_str()
                );

            if( this->selectAccount( m_defaultAccountID ) == false )
            {
                LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts invalid set default account '%ls'"
                    , m_defaultAccountID.c_str()
                    );

                return false;
            }
        }
        else if( validAccount != nullptr )
        {
            const WString & accountID = validAccount->getName();

            LOGGER_WARNING(m_serviceProvider)( "AccountManager::loadAccounts set valid account '%ls'"
                , accountID.c_str()
                );

            if( this->selectAccount( accountID ) == false )
            {
                LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccounts invalid set valid account '%ls'"
                    , accountID.c_str()
                    );

                return false;
            }
        }
        else
        {
            LOGGER_INFO(m_serviceProvider)("AccountManager::loadAccounts invalid set any accounts"
                );
        }
		
		return true;
	}
Esempio n. 18
0
WT_BOSTREAM& Response::out()
{
  if (!headersCommitted_) {
    if (!continuation_ &&
	(resource_->dispositionType() != WResource::NoDisposition
	 || !resource_->suggestedFileName().empty())) {
      std::string theDisposition;

      switch (resource_->dispositionType()) {
      default:
      case WResource::Inline:
        theDisposition = "inline";
        break;
      case WResource::Attachment:
        theDisposition = "attachment";
        break;
      }

      WString fileName = resource_->suggestedFileName();

      if (!fileName.empty()) {
	if (resource_->dispositionType() == WResource::NoDisposition) {
	  // backward compatibility-ish with older Wt versions
	  theDisposition = "attachment";
	}

	// Browser incompatibility hell: internatianalized filename suggestions
	// First filename is for browsers that don't support RFC 5987
	// Second filename is for browsers that do support RFC 5987
	std::string fileField;
	// We cannot query wApp here, because wApp doesn't exist for
	// static resources.
	bool isIE = response_->userAgent().find("MSIE") != std::string::npos;
	bool isChrome = response_->userAgent().find("Chrome")
	  != std::string::npos;

	if (isIE || isChrome) {
	  // filename="foo-%c3%a4-%e2%82%ac.html"
	  // Note: IE never converts %20 back to space, so avoid escaping
	  // IE wil also not url decode the filename if the file has no ASCII
	  // extension (e.g. .txt)
	  fileField = "filename=\"" +
	    Utils::urlEncode(fileName.toUTF8(), " ") + "\";";
	} else {
	  // Binary UTF-8 sequence: for FF3, Safari, Chrome, Chrome9
	  fileField = "filename=\"" + fileName.toUTF8() + "\";";
	}
	// Next will be picked by RFC 5987 in favour of the
	// one without specified encoding (Chrome9, 
	fileField += Utils::EncodeHttpHeaderField("filename", fileName);
	addHeader("Content-Disposition", theDisposition + ";" + fileField);
      } else {
	addHeader("Content-Disposition", theDisposition);
      }
    }

    headersCommitted_ = true;
  }

  if (out_)
    return *out_;
  else
    return response_->out();
}
Esempio n. 19
0
void WTreeTable::setTreeRoot(WTreeTableNode *root, const WString& h)
{
  tree_->setTreeRoot(root);
  header(0)->setText(h.empty() ? "&nbsp;" : h);
  root->setTable(this);
}