Esempio n. 1
0
	void WriteRegistryInstance::startExecution()
	{
	#ifdef Q_OS_WIN
		bool ok = true;

		ActionTools::Registry::Key key = evaluateListElement<ActionTools::Registry::Key>(ok, ReadRegistryInstance::keys, "key");
		QString subKey = evaluateString(ok, "subKey");
		QString value = evaluateString(ok, "value");
        QScriptValue data = evaluateValue(ok, "data");

		if(!ok)
			return;

        switch(ActionTools::Registry::write(data.toVariant(), key, subKey, value))
		{
		case ActionTools::Registry::WriteCannotFindSubKey:
			setCurrentParameter("subKey");
			emit executionException(CannotFindSubKeyException, tr("Cannot find subKey \"%1\"").arg(subKey));
			return;
		case ActionTools::Registry::WriteCannotWriteValue:
			setCurrentParameter("value");
			emit executionException(CannotWriteValueException, tr("Cannot write value \"%1\"").arg(value));
			return;
		default:
			break;
		}
	#endif

		emit executionEnded();
	}
Esempio n. 2
0
	void WriteTextFileInstance::startExecution()
	{
		bool ok = true;

		QString filepath = evaluateString(ok, "file");
		QString text = evaluateString(ok, "text");
		Mode mode = evaluateListElement<Mode>(ok, modes, "mode");

		if(!ok)
			return;

		QFile file(filepath);
		if(!file.open(QIODevice::WriteOnly | QIODevice::Text | (mode == Truncate ? QIODevice::Truncate : QIODevice::Append)))
		{
			setCurrentParameter("file");
			emit executionException(CannotWriteFileException, tr("Cannot open file"));
			return;
		}

		QTextStream textStream(&file);

		textStream << text;

		file.close();

		emit executionEnded();
	}
Esempio n. 3
0
void WebDownloadInstance::finished()
{
    mFile.close();

    switch(mReply->error())
    {
    case QNetworkReply::NoError:
        if(mDestination == Variable)
            setVariable(mVariable, QString::fromUtf8(mReply->readAll()));

        emit executionEnded();
        break;
    case QNetworkReply::OperationCanceledError:
        if(mDestination == File)
            mFile.remove();

        emit executionEnded();
        break;
    default:
    {
        if(mDestination == File)
            mFile.remove();

        setCurrentParameter("url");

        emit executionException(DownloadException, tr("Download error: %1").arg(mReply->errorString()));
    }
    break;
    }

    mProgressDialog->close();

    mReply->deleteLater();
    mReply = 0;
}
Esempio n. 4
0
void WebDownloadInstance::startExecution()
{
    bool ok = true;

    QString urlString = evaluateString(ok, "url");
    mDestination = evaluateListElement<Destination>(ok, destinations, "destination");
    mVariable = evaluateVariable(ok, "variable");
    QString file = evaluateString(ok, "file");


    if(!ok)
        return;

    QUrl url(urlString);
    if(url.scheme() == QString())
        url = QUrl("http://" + urlString, QUrl::TolerantMode);

    if(!url.isValid())
    {
        setCurrentParameter("url");
        emit executionException(ActionTools::ActionException::BadParameterException, tr("Invalid URL"));
        return;
    }

    if(mDestination == File)
    {
        mFile.setFileName(file);
        if(!mFile.open(QIODevice::WriteOnly))
        {
            setCurrentParameter("file");
            emit executionException(CannotOpenFileException, tr("Cannot write to file"));
            return;
        }
    }

    mReply = mNetworkAccessManager->get(QNetworkRequest(url));

    connect(mReply, SIGNAL(finished()), this, SLOT(finished()));
    connect(mReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
    connect(mReply, SIGNAL(readyRead()), this, SLOT(readyRead()));

    mProgressDialog->setModal(false);
    mProgressDialog->setWindowTitle(tr("Downloading"));
    mProgressDialog->setLabelText(tr("Downloading..."));
    mProgressDialog->setMaximum(100);
    mProgressDialog->show();
}
Esempio n. 5
0
    void ActionInstance::validateParameterRange(bool &ok, int parameter, const QString &parameterName, const QString &parameterTranslatedName, int minimum, int maximum)
    {
        if(ok && (parameter < minimum || parameter > maximum))
        {
            ok = false;

            setCurrentParameter(parameterName);
            emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Invalid %1 value : %2").arg(parameterTranslatedName).arg(parameter));
            return;
        }
    }
Esempio n. 6
0
	SubParameter ActionInstance::retreiveSubParameter(const QString &parameterName, const QString &subParameterName)
	{
		setCurrentParameter(parameterName, subParameterName);

        SubParameter back = subParameter(parameterName, subParameterName);

        // Re-evaluate the field as code if it contains a single variable
		if(!back.isCode() && back.value().startsWith(QLatin1Char('$')))
        {
            QString stringValue = back.value();
            QString variableName = stringValue.right(stringValue.size() - 1);
            const QScriptValue &value = d->scriptEngine->globalObject().property(variableName);

            if(value.isValid())
            {
                back.setCode(true);
                back.setValue(variableName);
            }
        }

        return back;
	}
Esempio n. 7
0
    QString ActionInstance::evaluateEditableListElement(bool &ok, const Tools::StringListPair &listElements, const QString &parameterName, const QString &subParameterName)
    {
        if(!ok)
            return QString();

        const SubParameter &subParameter = retreiveSubParameter(parameterName, subParameterName);
        QString result;

        if(subParameter.isCode())
            result = evaluateCode(ok, subParameter).toString();
        else
            result = evaluateText(ok, subParameter);

        if(!ok)
            return QString();

        //Search in the translated items
        for(int i=0;i<listElements.second.size();++i)
        {
            if(listElements.second.at(i) == result)
                return listElements.first.at(i);
        }

        if(result.isEmpty())
        {
            ok = false;

            setCurrentParameter(parameterName, subParameterName);

            emit executionException(ActionException::InvalidParameterException, tr("Please choose a value for this field."));

            return QString();
        }

        return result;
    }
Esempio n. 8
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();
    }