QScriptValue PHIBaseItem::trigger( const QString &name, const QScriptValue &args, PHIDomEvent *de ) { if ( !isClientItem() ) return self(); if ( name==SL( "drop" ) && !de ) return self(); // drop can not be triggered manually PHIEventHash hash=data( DEventFunctions ).value<PHIEventHash>(); QScriptValueList functions=hash.values( name ); PHIDomEvent fake( name, this ); QScriptValue event, fn, res ; if ( de ) event=de->self(); else event=eventToScriptValue( scriptEngine(), &fake ); foreach ( fn, functions ) { if ( fn.isFunction() ) { res=fn.call( self(), QScriptValueList() << event << args ); } else if ( fn.isString() ) res=scriptEngine()->evaluate( fn.toString() ); if ( res.isError() ) { emit javaScriptError( res ); qDebug() << res.toString(); } else if ( de && res.isBool() ) if ( res.toBool()==false ) de->preventDefault(); } hash=data( DOneEventFunctions ).value<PHIEventHash>(); functions=hash.values( name ); foreach( fn, functions ) { if ( fn.isFunction() ) { res=fn.call( self(), QScriptValueList() << event << args ); } else if ( fn.isString() ) res=scriptEngine()->evaluate( fn.toString() ); if ( res.isError() ) { emit javaScriptError( res ); qDebug() << res.toString(); } else if ( de && res.isBool() ) if ( res.toBool()==false ) de->preventDefault(); } hash.remove( name ); setData( DOneEventFunctions, qVariantFromValue( hash ) ); return self(); }
QScriptValue SICliScriptDriver::callExtensionFunction(const QString& fn, const QVariantList& params) throw(QFException) { qfLogFuncFrame(); QScriptValue ret; QSettings settings; QString extension = settings.value("app/extensions/currentName").toString(); QString ext_property_name = extension; ext_property_name.replace('.', '_'); ext_property_name = "__sicli_extension_" + ext_property_name; if(extension.isEmpty()) return ret; QScriptValue mo = scriptEngine()->globalObject().property(ext_property_name); qfTrash() << "\t extension module object is undefined:" << mo.isUndefined() << "is valid:" << mo.isValid() << "is null:" << mo.isNull() << "is object:" << mo.isObject(); if(!mo.isValid()) { qfTrash() << "\t loading extension module object"; mo = constructedModuleObject(extension, QScriptValueList(), Qf::ThrowExc); /* if(!mo.isObject()) { QF_EXCEPTION(tr("Cann't load extension object '%1'").arg(extension)); //return ret; } */ scriptEngine()->globalObject().setProperty(ext_property_name, mo); qfTrash() << "\t loaded extension module object is undefined:" << mo.isUndefined() << "is valid:" << mo.isValid() << "is null:" << mo.isNull() << "is object:" << mo.isObject(); } { QScriptValueList args; foreach(QVariant v, params) args << variantToScriptValue(v); QScriptValue jsfn = mo.property(fn); if(jsfn.isFunction()) { //qfTrash() << "\t jsfn:" << jsfn.toString(); QScriptValue sv = callFunction(jsfn, mo, args, !Qf::ThrowExc); //qfInfo() << scriptValueToJsonString(sv); if(sv.isError()) { /// zprava ze skriptu, neco se nepodarilo //theApp()->emitLogRequest(QFLog::LOG_ERR, sv.property("message").toString() + "\n" + sv.property("debugInfo").toString()); theApp()->emitLogRequestPre(QFLog::LOG_ERR, sv.property("message").toString()); //qfError() << sv.property("message").toString(); } else ret = sv; } else { theApp()->emitLogRequest(QFLog::LOG_ERR, tr("Extension '%1' does not contains function '%2'").arg(extension).arg(fn)); //qfError() << "Extension" << extension << "does not contains function" << fn; } } return ret; }
QScriptValue PHILinkItem::hoverBgColor( const QScriptValue &c ) { if ( !isServerItem() ) return scriptEngine()->undefinedValue(); if ( !c.isValid() ) return PHI::colorToString( realHoverBgColor() ); setColor( PHIPalette::HoverBackground, PHIPalette::Custom, PHI::colorFromString( c.toString() ) ); return self(); }
bool SkDump::evaluate(SkAnimateMaker &maker) { SkAnimatorScript scriptEngine(maker, NULL, SkType_Int); SkScriptValue value; const char* cScript = script.c_str(); bool success = scriptEngine.evaluateScript(&cScript, &value); SkDebugf("%*s<dump script=\"%s\" answer=\" ", SkDisplayList::fIndent, "", script.c_str()); if (success == false) { SkDebugf("INVALID\" />\n"); return false; } switch (value.fType) { case SkType_Float: SkDebugf("%g\" />\n", SkScalarToFloat(value.fOperand.fScalar)); break; case SkType_Int: SkDebugf("%d\" />\n", value.fOperand.fS32); break; case SkType_String: SkDebugf("%s\" />\n", value.fOperand.fString->c_str()); break; default: return false; } return true; }
QScriptValue PHIEllipseItem::spanAngle( const QScriptValue &v ) { if ( !isServerItem() ) return scriptEngine()->undefinedValue(); if ( !v.isValid() ) return realSpanAngle(); setSpanAngle( v.toInt32() ); setDirtyFlag( DFDoNotCache ); return self(); }
void MultiDataInputInstance::saveSelectedRadioButtonOrCheckBox() { QAbstractButton *checkedButton = mButtonGroup->checkedButton(); if(checkedButton) setVariable(mVariable, checkedButton->text()); else setVariable(mVariable, scriptEngine()->nullValue()); }
void ChartDataCollector::collectData() { SqlQuery * qry=findQuery(m_query); if (!qry) return; Report::ChartInterface::_chartValue cv; bool ok; switch(m_chartDataSource) { case FromDatabase: if(!qry->record().field(m_valueField).isValid()) break; if(qry->record().field(m_keyField).isValid()) cv.key=qry->record().field(m_keyField).value().toString(); if(qry->record().field(m_colorField).isValid()) cv.color=qry->record().field(m_keyField).value().value<QColor>(); else cv.color=generateNextColor(); cv.value=qry->record().field(m_valueField).value().toDouble(&ok); if (ok) addChartValue(cv); break; case FromScript: if (!m_valueScript.length() || !scriptEngine()) break; cv.value=scriptEngine()->evaluate(m_valueScript).toVariant().toDouble(&ok); if (!ok) break; if (m_keyScript.length()) cv.key=scriptEngine()->evaluate(m_keyScript).toString(); if (m_colorScript.length()) cv.color=scriptEngine()->evaluate(m_colorScript).toVariant().value<QColor>(); else cv.color=generateNextColor(); addChartValue(cv); break; default: break; } }
ActionTools::WindowHandle WindowConditionInstance::findWindow() { ActionTools::WindowHandle foundWindow = ActionTools::WindowHandle::findWindow(mTitleRegExp); if(foundWindow.isValid()) { QRect windowRect = foundWindow.rect(); setVariable(mPosition, Code::Point::constructor(windowRect.topLeft(), scriptEngine())); setVariable(mSize, Code::Size::constructor(windowRect.size(), scriptEngine())); setVariable(mXCoordinate, windowRect.x()); setVariable(mYCoordinate, windowRect.y()); setVariable(mWidth, windowRect.width()); setVariable(mHeight, windowRect.height()); setVariable(mProcessId, foundWindow.processId()); return foundWindow; } return {}; }
void TreeThread::run() { m_root = boost::shared_ptr< NRoot >(new NRoot("Root")); Handle< NRoot > realRoot(m_root); boost::shared_ptr< NLog > log(new NLog()); boost::shared_ptr< NBrowser > browser(new NBrowser()); boost::shared_ptr< NTree > tree(new NTree(realRoot)); boost::shared_ptr< NPlugins > plugins(new NPlugins(CLIENT_PLUGINS)); boost::shared_ptr< NGeneric > uidir( new NGeneric( CLIENT_UI_DIR, "cf3.common.Group", CNode::LOCAL_NODE ) ); boost::shared_ptr< NetworkQueue > networkQueue( new NetworkQueue() ); boost::shared_ptr< NScriptEngine > scriptEngine( new NScriptEngine() ); Logger::instance().getStream(WARNING).addStringForwarder( log.get() ); Logger::instance().getStream(ERROR).addStringForwarder( log.get() ); Logger::instance().getStream(INFO).addStringForwarder( log.get() ); Logger::instance().getStream(INFO).setStamp(LogStream::STRING, "%type% "); Logger::instance().getStream(ERROR).setStamp(LogStream::STRING, "%type% "); Logger::instance().getStream(WARNING).setStamp(LogStream::STRING, "%type% "); // add components to the root uidir->add_component(log); uidir->add_component(browser); uidir->add_component(tree); uidir->add_component(networkQueue); uidir->add_component(plugins); uidir->add_component(scriptEngine); realRoot->add_component(uidir); // mark all components as basic m_root->mark_basic(); uidir->mark_basic(); log->mark_basic(); browser->mark_basic(); tree->mark_basic(); networkQueue->mark_basic(); plugins->mark_basic(); scriptEngine->mark_basic(); // set the root as model root tree->set_tree_root(realRoot); ThreadManager::instance().network().signal( "network_new_frame" ) ->connect( boost::bind(&TreeThread::new_signal, this, _1) ); m_mutex->unlock(); // m_waitCondition.wakeAll(); // execute the event loop exec(); }
QScriptValue PHIBaseItem::pos( const QScriptValue &x, const QScriptValue &y ) { if ( !x.isValid() ) { QPointF p=adjustedPos(); QScriptValue v=scriptEngine()->newObject(); v.setProperty( L1( "left" ), qRound( realX()+p.x() ) ); v.setProperty( L1( "top" ), qRound( realY()+p.y() ) ); v.setProperty( L1( "x" ), qRound( realX() ) ); v.setProperty( L1( "y" ), qRound( realY() ) ); return v; } setPos( x.toNumber(), y.toNumber() ); return self(); }
int main(int argc, char **argv) { udp::endpoint listenInterface; boost::asio::ip::address addr(boost::asio::ip::address::from_string("0.0.0.0")); listenInterface.address(addr); listenInterface.port(6370); std::string mapName; if(argc == 4) { addr = boost::asio::ip::address::from_string(argv[2]); listenInterface.address(addr); listenInterface.port(atoi(argv[3])); mapName = argv[1]; } else if(argc == 2) { mapName = argv[1]; } else if(argc != 2) { std::cerr << argv[0] << " CampaignName (ListenIpV4 Port)" << std::endl; return -1; } network::NetworkServer server(listenInterface); Ogre::Root root; nDebug << "ResourceGroupManager Pointer: " << std::hex << Ogre::ResourceGroupManager::getSingletonPtr() << std::dec << std::endl; new script::ScriptFileManager; auto manager = std::make_shared<campaign::Manager>(mapName); if(!manager->loadCampaignPath()) { logError() << "Did not find campaign " << mapName << " in the specified search paths!" << std::endl; return -1; } server.setObjectManager(manager->objectManager()); server.RegisterNetworkSystem(manager->scriptEngine()); server.loadRpcHandlerSpec(); campaign::ServerLogic logic(manager); // server.setRpcScriptEngine(manager->scriptEngine()); if(!logic.init()) { logError() << "Server logic could not be initialized, abort!" << std::endl; return -1; } server.setTimeoutCallback(0.05f, std::bind(&campaign::ServerLogic::step, &logic, 0.05f)); server.run(); delete Ogre::ResourceGroupManager::getSingleton()._getResourceManager("ScriptFile"); return 0; }
void FindImageInstance::searchFinished(const ActionTools::MatchingPointList &matchingPointList) { bool ok = true; if(matchingPointList.empty()) { setCurrentParameter(QStringLiteral("ifNotFound"), QStringLiteral("line")); QString line = evaluateSubParameter(ok, mIfNotFound.actionParameter()); if(!ok) return; if(mIfNotFound.action() == ActionTools::IfActionValue::GOTO) { setNextLine(line); executionEnded(); } else if(mIfNotFound.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; executionEnded(); } else if(mIfNotFound.action() == ActionTools::IfActionValue::WAIT) { mWaitTimer.start(mSearchDelay); } else executionEnded(); return; } if(mMaximumMatches == 1) { const ActionTools::MatchingPoint &bestMatchingPoint = matchingPointList.first(); QPoint position = bestMatchingPoint.position; if(mSource != WindowSource || !mWindowRelativePosition) position += mImagesToSearchIn.at(bestMatchingPoint.imageIndex).second.topLeft(); setVariable(mPositionVariableName, Code::Point::constructor(position, scriptEngine())); setVariable(mConfidenceVariableName, bestMatchingPoint.confidence); } else { QScriptValue arrayResult = scriptEngine()->newArray(matchingPointList.size()); QScriptValue arrayConfidenceResult = scriptEngine()->newArray(matchingPointList.size()); for(int i = 0; i < matchingPointList.size(); ++i) { const ActionTools::MatchingPoint &matchingPoint = matchingPointList.at(i); QPoint position = matchingPoint.position; if(mSource != WindowSource || !mWindowRelativePosition) position += mImagesToSearchIn.at(matchingPoint.imageIndex).second.topLeft(); arrayResult.setProperty(i, Code::Point::constructor(position, scriptEngine())); arrayConfidenceResult.setProperty(i, matchingPoint.confidence); } setVariable(mPositionVariableName, arrayResult); setVariable(mConfidenceVariableName, arrayConfidenceResult); } setCurrentParameter(QStringLiteral("ifFound"), QStringLiteral("line")); QString line = evaluateSubParameter(ok, mIfFound.actionParameter()); if(!ok) return; if(mIfFound.action() == ActionTools::IfActionValue::GOTO) { setNextLine(line); executionEnded(); } else if(mIfFound.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; executionEnded(); } else if(mIfFound.action() == ActionTools::IfActionValue::WAIT) { mWaitTimer.start(mSearchDelay); } else executionEnded(); }
void MultiDataInputInstance::accepted() { switch(mMode) { case ComboBoxMode: case EditableComboBoxMode: setVariable(mVariable, mComboBox->currentText()); break; case ListMode: { QList<QListWidgetItem *> selectedItems = mListWidget->selectedItems(); if(mMaximumChoiceCount <= 1) { if(selectedItems.isEmpty()) setVariable(mVariable, scriptEngine()->nullValue()); else setVariable(mVariable, selectedItems.first()->text()); } else { QScriptValue back = scriptEngine()->newArray(selectedItems.size()); for(int index = 0; index < selectedItems.size(); ++index) back.setProperty(index, selectedItems.at(index)->text()); setVariable(mVariable, back); } } break; case CheckboxMode: if(mMaximumChoiceCount <= 1) saveSelectedRadioButtonOrCheckBox(); else { QStringList selectedButtons; for(QAbstractButton *button: mButtonGroup->buttons()) { if(button->isChecked()) selectedButtons.append(button->text()); } QScriptValue back = scriptEngine()->newArray(selectedButtons.size()); for(int index = 0; index < selectedButtons.size(); ++index) back.setProperty(index, selectedButtons.at(index)); setVariable(mVariable, back); } break; case RadioButtonMode: { saveSelectedRadioButtonOrCheckBox(); } break; } closeDialog(); executionEnded(); }