示例#1
0
void Session::open() {

    try {
        setSessionState(SigningIn);

        ScriptEngine *engine = ScriptEngine::instance();
        m_scriptObject = engine->evaluate("new SessionHandler()");
        if (engine->hasUncaughtException()) {
            LogUtil::logException("Script Exception: %1\n"
                                  "In Session::open()", engine->uncaughtException());
            return;
        }

        QScriptValue setSession = m_scriptObject.property("setSession");
        QScriptValueList args;
        args.append(engine->toScriptValue(this));
        setSession.call(m_scriptObject, args);

        if (engine->hasUncaughtException()) {
            LogUtil::logException("Script Exception: %1\n"
                                  "In Session::open()", engine->uncaughtException());
        }
    } catch (GameException &exception) {
        LogUtil::logError("Exception in Session::open(): %1", exception.what());
    }
}
示例#2
0
void Session::processSignIn(const QString &data) {

    try {
        switch (m_sessionState) {
            case SessionClosed:
                break;

            case SigningIn: {
                QScriptValue processSignIn = m_scriptObject.property("processSignIn");
                QScriptValueList args;
                args.append(data.trimmed());
                processSignIn.call(m_scriptObject, args);
                break;
            }

            case SignedIn: {
                CommandEvent event(m_player, data);
                event.process();
                break;
            }
        }

        ScriptEngine *engine = ScriptEngine::instance();
        if (engine->hasUncaughtException()) {
            LogUtil::logException("Script Exception: %1\n"
                                  "In Session::processSignIn()", engine->uncaughtException());
        }
    } catch (GameException &exception) {
        LogUtil::logError("Exception in Session::processSignIn(): %1", exception.what());
    }
}
示例#3
0
/*!
 \brief

 \param tag
 \param fileInfo
 \param log
 \return bool
*/
bool PlayList::evaluateScript( Tag* tag, const QFileInfo& fileInfo, QString *log, QString *extInf, QString *sortBy ) const {

    if(script_.isEmpty()){
        return true;
    }

    ScriptEngine engine;
    QHash<QString,QVariant> frameFields = guiSettings->value("frameFields").toHash();

    //add all possible/specified id3v2 frames/ape items etc. to script, with empty array as value
    QHash< QString, QHash<QString,QStringList> > tagFrames = tag->frames(); //returns both ID3v2,asf,mp4,xiph and APE frames/items
    QStringList frameTypes = frameFields.keys(); //defined list of possible frames
    for(int j=0;j<frameTypes.size();j++){
        QString type = frameTypes[j]; //e.g. APE, ID3V2 etc.
        QStringList frameTypeKeys = frameFields[type].toStringList();
        QScriptValue array = engine.newArray(frameTypeKeys.size());
        QHash<QString,QStringList> tagTypeFrames = tagFrames[type];
        QStringList tagTypeFramesKeys = tagTypeFrames.keys();
        //loop for instance all ID3V2 frames
        QScriptValue v = engine.newArray(0);
        for(int i=0;i<frameTypeKeys.size();i++){
            v.setProperty(0, QScriptValue(&engine, "")); //set default value an empty array
            array.setProperty(frameTypeKeys[i].toUpper(), v);
        }//now add all frames from current tag
        for(int i=0;i<tagTypeFramesKeys.size();i++){
            QStringList list = tagTypeFrames[tagTypeFramesKeys[i]];
            for(int k=0;k<list.size();k++){
                v.setProperty(k, list[k]);
            }
            array.setProperty(tagTypeFramesKeys[i].toUpper(), v);
        }
        engine.globalObject().setProperty(type,array);
    }


    //add tag data  as variables to script
    engine.globalObject().setProperty("ARTIST",tag->artist());
    engine.globalObject().setProperty("ALBUM",tag->album());
    engine.globalObject().setProperty("GENRE",tag->genre());
    engine.globalObject().setProperty("TITLE",tag->title());
    engine.globalObject().setProperty("COMMENT",tag->comment());
    engine.globalObject().setProperty("YEAR",tag->year());
    engine.globalObject().setProperty("TRACK",tag->track());
    engine.globalObject().setProperty("LENGTH",tag->length());
    engine.globalObject().setProperty("BITRATE",tag->bitRate());
    engine.globalObject().setProperty("SAMPLERATE",tag->sampleRate());
    engine.globalObject().setProperty("CHANNELS",tag->channels());
    engine.globalObject().setProperty("TAGOK",tag->tagOk());
    engine.globalObject().setProperty("AUDIOPROPERTIESOK",tag->audioPropertiesOk());

    engine.globalObject().setProperty("FILENAME",fileInfo.fileName());
    engine.globalObject().setProperty("FILEPATH",fileInfo.filePath());    

    QScriptValue result = engine.evaluate( script_ );

    *extInf = engine.globalObject().property("EXTINF").toString();
    *sortBy = "";
    QScriptValue sortByValue = engine.globalObject().property("SORTBY");
    if( sortByValue.isValid() ){
        *sortBy = sortByValue.toString();
    }

    if( engine.hasUncaughtException() ){
        QString err = engine.uncaughtExceptionBacktrace().join("\n");
        log->append(err);
        return false;
    }
    bool res=false;
    if( result.isBool() ){
        res = result.toBool();
    }else{
        log->append("\nResult of evaluated script is not boolean");
    }
    return res;

}