bool WFormModel::validateField(Field field) { if (!isVisible(field)) return true; FieldMap::iterator i = fields_.find(field); if (i != fields_.end()) { FieldData& d = i->second; if (d.validator) setValidation(field, d.validator->validate(asString(valueText(field)))); else setValidation(field, Valid); return d.validation.state() == WValidator::Valid; } else return true; }
bool AuthModel::validateField(Field field) { if (field == RememberMeField) return true; User user = users().findWithIdentity(Identity::LoginName, valueText(LoginNameField)); if (field == LoginNameField) { if (user.isValid()) setValid(LoginNameField); else { setValidation (LoginNameField, WValidator::Result(ValidationState::Invalid, WString::tr("Wt.Auth.user-name-invalid"))); throttlingDelay_ = 0; } return user.isValid(); } else if (field == PasswordField) { if (user.isValid()) { PasswordResult r = passwordAuth()->verifyPassword(user, valueText(PasswordField)); switch (r) { case PasswordResult::PasswordInvalid: setValidation (PasswordField, WValidator::Result(ValidationState::Invalid, WString::tr("Wt.Auth.password-invalid"))); if (passwordAuth()->attemptThrottlingEnabled()) throttlingDelay_ = passwordAuth()->delayForNextAttempt(user); return false; case PasswordResult::LoginThrottling: setValidation (PasswordField, WValidator::Result(ValidationState::Invalid, WString::tr("Wt.Auth.password-info"))); setValidated(PasswordField, false); throttlingDelay_ = passwordAuth()->delayForNextAttempt(user); LOG_SECURE("throttling: " << throttlingDelay_ << " seconds for " << user.identity(Identity::LoginName)); return false; case PasswordResult::PasswordValid: setValid(PasswordField); return true; } /* unreachable */ return false; } else return false; } else return false; }
void CAppRegistry::Save() { CSingleLock lock(m_lock); TiXmlElement rootElement("registry"); CStdString key; for (RegistryDataIterator keyIter = m_data.begin(); keyIter != m_data.end(); keyIter++) { key = keyIter->first; RegistryValue& values = keyIter->second; for (size_t i = 0; i < values.size(); i++) { TiXmlElement valueElement("value"); valueElement.SetAttribute("id", key.c_str()); TiXmlText valueText(values[i]); valueElement.InsertEndChild(valueText); rootElement.InsertEndChild(valueElement); } } TiXmlDocument xmlDoc; xmlDoc.InsertEndChild(rootElement); ::CreateDirectory(m_dir, NULL); xmlDoc.SaveFile(m_fileName); }
void ValueSelector::showEvent(QShowEvent *e) { QMaemo5ValueButton::showEvent(e); if (valueText().isEmpty()) { m_selector->setCurrentIndex(0); } }
QString DrFloatOption::fixedVal() { QStringList vals = QStringList::split("|", get("fixedvals"), false); if(vals.count() == 0) return valueText(); float d(0); QString val; for(QStringList::Iterator it = vals.begin(); it != vals.end(); ++it) { float thisVal = (*it).toFloat(); if(val.isEmpty() || fabs(thisVal - m_value) < d) { d = fabs(thisVal - m_value); val = *it; } } if(val.isEmpty()) return valueText(); else return val; }
DrBase *DrListOption::clone() { DrListOption *opt = static_cast< DrListOption * >(DrBase::clone()); QPtrListIterator< DrBase > it(m_choices); for(; it.current(); ++it) opt->addChoice(it.current()->clone()); opt->setValueText(valueText()); return static_cast< DrBase * >(opt); }
WValidator::State WFormWidget::validate() { if (validator()) { WValidator::Result result = validator()->validate(valueText()); toggleStyleClass("Wt-invalid", result.state() != WValidator::Valid, true); setToolTip(result.message()); validated_.emit(result); return result.state(); } else return WValidator::Valid; }
bool authModel::validateField(Field field) { if(field == RememberMeField) return true; y::ldap::account & account = ldapServer.getAccount(UID(valueText(LoginNameField))); if(field == LoginNameField) { if(!account.isNew()) { setValid(LoginNameField); return true; } else { setValidation(LoginNameField, Wt::WValidator::Result(Wt::WValidator::Invalid, Wt::WString::tr("Wt.Auth.user-name-invalid"))); return false; } } if(field == PasswordField) { if(account.isNew()) return false; if(ldapServer.auth(account.dn(), PASSWORD(valueText(PasswordField)))) { setValid(PasswordField); Wt::Auth::User user = users().findWithIdentity(Wt::Auth::Identity::LoginName, account.uid().get().db()); if(!user.isValid()) { Wt::Auth::User user = users().registerNew(); user.addIdentity(Wt::Auth::Identity::LoginName, account.uid().get().db()); } return true; } else { setValidation(PasswordField, Wt::WValidator::Result(Wt::WValidator::Invalid, Wt::WString::tr("Wt.Auth.password-invalid"))); return false; } } return true; }
void WFormWidget::render(WFlags<RenderFlag> flags) { if ((flags & RenderFull)) { if (flags_.test(BIT_JS_OBJECT)) defineJavaScript(true); if (validator()) { WValidator::Result result = validator()->validate(valueText()); WApplication::instance()->theme() ->applyValidationStyle(this, result, ValidationInvalidStyle); } } WInteractWidget::render(flags); }
bool AuthModel::login(Login& login) { if (valid()) { User user = users().findWithIdentity(Identity::LoginName, valueText(LoginNameField)); cpp17::any v = value(RememberMeField); if (loginUser(login, user)) { reset(); if (cpp17::any_has_value(v) && cpp17::any_cast<bool>(v) == true) setRememberMeCookie(user); return true; } else return false; } else return false; }
WValidator::State WFormWidget::validate() { if (validator()) { WValidator::Result result = validator()->validate(valueText()); if (isRendered()) WApplication::instance()->theme() ->applyValidationStyle(this, result, ValidationInvalidStyle); if (validationToolTip_ != result.message()) { validationToolTip_ = result.message(); flags_.set(BIT_VALIDATION_CHANGED); repaint(); } validated_.emit(result); return result.state(); } else return WValidator::Valid; }
bool AuthModel::login(Login& login) { if (valid()) { User user = users().findWithIdentity(Identity::LoginName, valueText(LoginNameField)); boost::any v = value(RememberMeField); const AuthService *s = baseAuth(); if (loginUser(login, user)) { reset(); if (!v.empty() && boost::any_cast<bool>(v) == true) { WApplication *app = WApplication::instance(); app->setCookie(s->authTokenCookieName(), s->createAuthToken(user), s->authTokenValidity() * 60); } return true; } else return false; } else return false; }
DrBase *DrBase::clone() { DrBase *opt(0); switch(type()) { case Main: opt = new DrMain; break; case Group: opt = new DrGroup; break; case String: opt = new DrStringOption; break; case Integer: opt = new DrIntegerOption; break; case Float: opt = new DrFloatOption; break; case List: opt = new DrListOption; break; case Boolean: opt = new DrBooleanOption; break; default: opt = new DrBase; break; } opt->m_map = m_map; opt->m_name = m_name; opt->m_conflict = m_conflict; opt->setValueText(valueText()); return opt; }
void DrBase::getOptions(QMap< QString, QString > &opts, bool incldef) { QString val = valueText(); if(incldef || get("persistent") == "1" || get("default") != val) opts[name()] = val; }
void UserDetailsModel::save(const Wt::Auth::User& authUser) { Wt::Dbo::ptr<User> user = session_.user(authUser); user.modify()->favouritePet = valueText(FavouritePetField).toUTF8(); }
QString DrBase::prettyText() { return valueText(); }
//------------------------------------------------------------------------------ // //------------------------------------------------------------------------------ void tNavigationPage::paint( QPainter* pPainter, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget ) { Q_UNUSED( pOption ); Q_UNUSED( pWidget ); //Draw table QList<tDataType> displayDataTypes; //TODO: need to do FTW displayDataTypes << DATA_TYPE_COG << DATA_TYPE_SPEED_SOG << DATA_TYPE_BEARING << DATA_TYPE_DISTANCE_TO_TURN << DATA_TYPE_FUEL_TO_TURN; QRect tableRect = AvailableRect(); //tableRect.setBottom(tableRect.bottom()-50); tableRect.setLeft(tableRect.left()+90); tableRect.setWidth(161); tableRect.setHeight(142); pPainter->setPen( QPen( Qt::black, 2.0, Qt::SolidLine, Qt::RoundCap ) ); //draw left and top borders pPainter->drawLine(tableRect.topLeft(), tableRect.topRight()); pPainter->drawLine(tableRect.topLeft(), tableRect.bottomLeft()); static int lineHeight = 28; int lineOffset = 0; for (QList<tDataType>::iterator dataTypeIter = displayDataTypes.begin(); dataTypeIter != displayDataTypes.end(); ++dataTypeIter) { //Text QString currentLabel = tDigitalData::Caption( *dataTypeIter, true ); QRect textRect = tableRect; textRect.setTop(tableRect.top() + lineOffset); textRect.setLeft(tableRect.left() + 1); textRect.setHeight(lineHeight); textRect.setWidth(52); //pPainter->setPen( QPen( QColor(128,128,128) ) ); //pPainter->setBrush(Qt::red); pPainter->fillRect(textRect, QBrush(QColor(187,187,187))); pPainter->drawText( textRect, Qt::AlignCenter, currentLabel ); //Value QFont currentFont = pPainter->font(); currentFont.setBold(true); pPainter->setFont(currentFont); QRect valueRect = textRect; valueRect.setLeft( textRect.left()+textRect.width() ); valueRect.setWidth(61); //TODO: use a timer to only get this when required QString valueText("-"); float navValue; bool navValueValid = tDigitalData(tDataId( *dataTypeIter )).ValidValue( navValue ); if ( navValueValid ) { valueText = QString("%1").arg(navValue); } pPainter->drawText( valueRect, Qt::AlignVCenter | Qt::AlignRight, valueText ); currentFont.setBold(false); pPainter->setFont(currentFont); //Units if (navValueValid) { QRect unitsRect = valueRect; unitsRect.setLeft( valueRect.left()+valueRect.width() + 5 ); unitsRect.setWidth(47); pPainter->drawText( unitsRect, Qt::AlignVCenter | Qt::AlignLeft, tDigitalData(tDataId( *dataTypeIter )).UnitStr() ); } //Separator int rowY = tableRect.y() + lineOffset; QLine rowSeparator(tableRect.x(), rowY, tableRect.right(), rowY ); pPainter->drawLine(rowSeparator); lineOffset += lineHeight; //Get position data tDigitalData position( (tDataId( DATA_TYPE_POSITION )) ); tRCoord posValue(0,0); bool posValid = position.ValidValue( posValue ); QString latitudeValue("-"); QString longitudeValue("-"); //tCoordinate posCoord = tCoordinate( posValue ); if (posValid) { //TODO: find out if this logic exists in a common place double dblDeg; int deg; double min; char hem; dblDeg = RadiansToDegrees( posValue.RLat() ); hem = dblDeg < 0 ? 'S' : 'N'; dblDeg = qAbs(dblDeg); deg = (int)dblDeg; min = 60 * (dblDeg - deg); //latitudeValue = QString("%1:%2'%3").arg(deg).arg(min).arg(hem); latitudeValue = QString("%1 %2").arg( posValue.RLat()).arg(hem); dblDeg = RadiansToDegrees( posValue.RLon() ); hem = dblDeg < 0 ? 'W' : 'E'; dblDeg = qAbs(dblDeg); deg = (int)dblDeg; min = 60 * (dblDeg - deg); //longitudeValue = QString("%1:%2'%3").arg(deg).arg(min).arg(hem); longitudeValue = QString("%1 %2").arg(posValue.RLon()).arg(hem); } //Lat/Lon display QRect latTextRect = AvailableRect(); latTextRect.setTop(tableRect.bottom()+10); latTextRect.setWidth(latTextRect.width()/2); latTextRect.setHeight(25); pPainter->drawText( latTextRect, Qt::AlignCenter, QString("Latitude").toUpper() ); //TODO: look at translation? QRect latValueRect = latTextRect; latValueRect.setTop(latTextRect.bottom()); latValueRect.setLeft(latTextRect.left()+4); latValueRect.setWidth(latTextRect.width()-8); latValueRect.setHeight(latTextRect.height()); pPainter->drawRect(latValueRect); pPainter->drawText( latValueRect, Qt::AlignCenter, latitudeValue ); //TODO: look at translation? QRect lonTextRect = latTextRect; lonTextRect.setLeft(latTextRect.right()); lonTextRect.setTop(latTextRect.top()); lonTextRect.setWidth(latTextRect.width()); pPainter->drawText( lonTextRect, Qt::AlignCenter, QString("Longitude").toUpper() ); //TODO: look at translation? QRect lonValueRect = lonTextRect; lonValueRect.setTop(lonTextRect.bottom()); lonValueRect.setLeft(lonTextRect.left()+4); lonValueRect.setWidth(lonTextRect.width()-8); lonValueRect.setHeight(lonTextRect.height()); pPainter->drawRect(lonValueRect); pPainter->drawText( lonValueRect, Qt::AlignCenter, longitudeValue ); //TODO: look at translation? } //draw bottom border pPainter->drawLine(tableRect.bottomLeft(), tableRect.bottomRight()); }
bool XMLLodDefinitionSerializer::exportScript(const LodDefinitionPtr& lodDef, const std::string& fileName) const { if (fileName == "") { return false; } TiXmlDocument xmlDoc; if (!oslink::directory(mExportDirectory).isExisting()) { S_LOG_INFO("Creating directory " << mExportDirectory); oslink::directory::mkdir(mExportDirectory.c_str()); } // <lod>...</lod> TiXmlElement rootElem("lod"); { // <automatic enabled="true|false" /> TiXmlElement autElem("automatic"); autElem.SetAttribute("enabled", lodDef->getUseAutomaticLod() ? "true" : "false"); // <manual>...</manual> TiXmlElement manElem("manual"); { // <type>user|automatic</type> TiXmlElement typeElem("type"); TiXmlText typeText(lodDef->getType() == LodDefinition::LT_AUTOMATIC_VERTEX_REDUCTION ? "automatic" : "user"); typeElem.InsertEndChild(typeText); manElem.InsertEndChild(typeElem); // <strategy>distance|pixelcount</strategy> TiXmlElement strategyElem("strategy"); TiXmlText strategyText(lodDef->getStrategy() == LodDefinition::LS_DISTANCE ? "distance" : "pixelcount"); strategyElem.InsertEndChild(strategyText); manElem.InsertEndChild(strategyElem); // <level>...</level> <level>...</level> <level>...</level> const LodDefinition::LodDistanceMap& manualLod = lodDef->getManualLodData(); LodDefinition::LodDistanceMap::const_iterator it; for (it = manualLod.begin(); it != manualLod.end(); it++) { // <level distance="10">...</level> TiXmlElement levelElem("level"); levelElem.SetAttribute("distance", Ogre::StringConverter::toString(it->first)); const LodDistance& dist = it->second; { if (lodDef->getType() == LodDefinition::LT_USER_CREATED_MESH) { // <meshName>.../test.mesh</meshName> TiXmlElement meshElem("meshName"); TiXmlText meshText(dist.getMeshName()); meshElem.InsertEndChild(meshText); levelElem.InsertEndChild(meshElem); } else { // <method>constant|proportional</method> TiXmlElement methodElem("method"); const char* pMethodText; switch (dist.getReductionMethod()) { case Ogre::LodLevel::VRM_PROPORTIONAL: pMethodText = "proportional"; break; case Ogre::LodLevel::VRM_CONSTANT: pMethodText = "constant"; break; case Ogre::LodLevel::VRM_COLLAPSE_COST: pMethodText = "collapsecost"; break; default: assert(0); break; } TiXmlText methodText(pMethodText); methodElem.InsertEndChild(methodText); // <value>0.5</value> TiXmlElement valueElem("value"); TiXmlText valueText(Ogre::StringConverter::toString(dist.getReductionValue())); valueElem.InsertEndChild(valueText); levelElem.InsertEndChild(methodElem); levelElem.InsertEndChild(valueElem); } } manElem.InsertEndChild(levelElem); } } rootElem.InsertEndChild(autElem); rootElem.InsertEndChild(manElem); } xmlDoc.InsertEndChild(rootElem); S_LOG_INFO("Saved file " << (mExportDirectory + fileName)); return xmlDoc.SaveFile((mExportDirectory + fileName).c_str()); }