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; }
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(); }
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(); }
void TextInstance::startExecution() { bool ok = true; mText = evaluateString(ok, "text"); int pause = evaluateInteger(ok, "pause"); if(pause < 0) pause = 0; mTimer->setInterval(pause); mCurrentCharacter = 0; if(!ok) return; if(pause == 0) { if(!mKeyboardDevice.writeText(mText)) { emit executionException(FailedToSendInputException, tr("Unable to write the text")); return; } QTimer::singleShot(1, this, SIGNAL(executionEnded())); } else { pressNextKey(); mTimer->start(); } }
void Executer::executeCurrentAction() { //Skip disabled actions if(mCurrentActionIndex >= 0) { while(mCurrentActionIndex < mScript->actionCount() && canExecuteAction(mCurrentActionIndex) != CanExecute) ++mCurrentActionIndex; } if(mCurrentActionIndex < 0 || mCurrentActionIndex >= mScript->actionCount()) { stopExecution(); return; } int nextLine = mCurrentActionIndex + 2; if(nextLine > mScript->actionCount()) nextLine = -1; QScriptValue script = mScriptEngine->globalObject().property("Script"); script.setProperty("nextLine", mScriptEngine->newVariant(QVariant(nextLine))); script.setProperty("line", mCurrentActionIndex + 1, QScriptValue::ReadOnly); ActionTools::ActionInstance *actionInstance = currentActionInstance(); const ActionTools::ExceptionActionInstancesHash &exceptionActionInstancesHash = actionInstance->exceptionActionInstances(); const ActionTools::ActionException::ExceptionActionInstance &exceptionAction = exceptionActionInstancesHash.value(ActionTools::ActionException::CodeErrorException); mShowDebuggerOnCodeError = (exceptionAction.action() == ActionTools::ActionException::StopExecutionExceptionAction); mExecutionWindow->setCurrentActionName(actionInstance->definition()->name()); mExecutionWindow->setCurrentActionColor(actionInstance->color()); connect(actionInstance, SIGNAL(executionEnded()), this, SLOT(actionExecutionEnded())); connect(actionInstance, SIGNAL(executionException(int,QString)), this, SLOT(executionException(int,QString))); connect(actionInstance, SIGNAL(disableAction(bool)), this, SLOT(disableAction(bool))); connect(actionInstance, SIGNAL(showProgressDialog(QString,int)), this, SLOT(showProgressDialog(QString,int))); connect(actionInstance, SIGNAL(updateProgressDialog(int)), this, SLOT(updateProgressDialog(int))); connect(actionInstance, SIGNAL(updateProgressDialog(QString)), this, SLOT(updateProgressDialog(QString))); connect(actionInstance, SIGNAL(hideProgressDialog()), this, SLOT(hideProgressDialog())); connect(actionInstance, SIGNAL(consolePrint(QString)), this, SLOT(consolePrint(QString))); connect(actionInstance, SIGNAL(consolePrintWarning(QString)), this, SLOT(consolePrintWarning(QString))); connect(actionInstance, SIGNAL(consolePrintError(QString)), this, SLOT(consolePrintError(QString))); mExecutionStatus = PrePause; mExecutionTimer.start(); mExecutionTime.start(); if(currentActionInstance()->pauseBefore() + mPauseBefore > 0) { mExecutionWindow->setProgressEnabled(true); mExecutionWindow->setProgressMinimum(0); mExecutionWindow->setProgressMaximum(currentActionInstance()->pauseBefore() + mPauseBefore); mExecutionWindow->setProgressValue(0); } else mExecutionWindow->setProgressEnabled(false); mExecutionEnded = true; }
void SendMailInstance::mailSent(int mailID) { Q_UNUSED(mailID) cleanup(); emit executionEnded(); }
void DataInputInstance::dataEntered(const QString &value) { setVariable(mVariable, value); mInputDialog->disconnect(); mInputDialog->close(); emit executionEnded(); }
void MessageBoxInstance::buttonClicked() { bool ok = true; QString line; if(mMessageBox->clickedButton() == mMessageBox->button(QMessageBox::Yes)) { line = evaluateSubParameter(ok, mIfYes.actionParameter()); if(!ok) { closeAndDelete(); return; } if(mIfYes.action() == ActionTools::IfActionValue::GOTO) setNextLine(line); else if(mIfYes.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) { closeAndDelete(); return; } } } else if(mMessageBox->clickedButton() == mMessageBox->button(QMessageBox::No)) { line = evaluateSubParameter(ok, mIfNo.actionParameter()); if(!ok) { closeAndDelete(); return; } if(mIfNo.action() == ActionTools::IfActionValue::GOTO) setNextLine(line); else if(mIfNo.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) { closeAndDelete(); return; } } } closeAndDelete(); emit executionEnded(); }
void PlaySoundInstance::startExecution() { bool ok = true; QString file = evaluateString(ok, "file"); int volume = evaluateInteger(ok, "volume"); mBlocking = evaluateBoolean(ok, "blocking"); bool looping = evaluateBoolean(ok, "looping"); bool isUrl = evaluateBoolean(ok, "url"); int playbackRate = evaluateInteger(ok, "playbackRate"); if(!ok) return; mMediaPlaylist->clear(); QUrl url; if(isUrl) url = QUrl(file); else url = QUrl::fromLocalFile(file); if(!mMediaPlaylist->addMedia(url)) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to load file %1: %2").arg(file).arg(mMediaPlayer->errorString())); return; } mMediaPlaylist->setPlaybackMode(looping ? QMediaPlaylist::Loop : QMediaPlaylist::CurrentItemOnce); mMediaPlayer->setPlaybackRate(playbackRate / 100.0f); mMediaPlayer->setVolume(volume); mMediaPlayer->play(); if(mMediaPlayer->error() != QMediaPlayer::NoError) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to play file %1: %2").arg(file).arg(mMediaPlayer->errorString())); return; } if(!mBlocking) emit executionEnded(); }
void TextInstance::pressNextKey() { if(!mKeyboardDevice.writeText(QString(mText.at(mCurrentCharacter)))) { mTimer->stop(); emit executionException(FailedToSendInputException, tr("Unable to write the text")); return; } ++mCurrentCharacter; if(mCurrentCharacter >= mText.size()) { mTimer->stop(); QTimer::singleShot(1, this, SIGNAL(executionEnded())); return; } }
void WindowConditionInstance::checkWindow() { ActionTools::WindowHandle foundWindow = findWindow(); if((foundWindow.isValid() && mCondition == Exists) || (!foundWindow.isValid() && mCondition == DontExists)) { bool ok = true; QString line = evaluateSubParameter(ok, mIfTrue.actionParameter()); if(!ok) return; if(mIfTrue.action() == ActionTools::IfActionValue::GOTO) setNextLine(line); else if(mIfTrue.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; } mTimer.stop(); 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(); }
void SendMailInstance::canceled() { cleanup(); emit executionEnded(); }
void WindowConditionInstance::startExecution() { bool ok = true; QString title = evaluateString(ok, QStringLiteral("title")); mCondition = evaluateListElement<Condition>(ok, conditions, QStringLiteral("condition")); mIfTrue = evaluateIfAction(ok, QStringLiteral("ifTrue")); ActionTools::IfActionValue ifFalse = evaluateIfAction(ok, QStringLiteral("ifFalse")); mPosition = evaluateVariable(ok, QStringLiteral("position")); mSize = evaluateVariable(ok, QStringLiteral("size")); mXCoordinate = evaluateVariable(ok, QStringLiteral("xCoordinate")); mYCoordinate = evaluateVariable(ok, QStringLiteral("yCoordinate")); mWidth = evaluateVariable(ok, QStringLiteral("width")); mHeight = evaluateVariable(ok, QStringLiteral("height")); mProcessId = evaluateVariable(ok, QStringLiteral("processId")); if(!ok) return; mTitleRegExp = QRegExp(title, Qt::CaseSensitive, QRegExp::WildcardUnix); ActionTools::WindowHandle foundWindow = findWindow(); if((foundWindow.isValid() && mCondition == Exists) || (!foundWindow.isValid() && mCondition == DontExists)) { QString line = evaluateSubParameter(ok, mIfTrue.actionParameter()); if(!ok) return; if(mIfTrue.action() == ActionTools::IfActionValue::GOTO) setNextLine(line); else if(mIfTrue.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; } executionEnded(); } else { QString line = evaluateSubParameter(ok, ifFalse.actionParameter()); if(!ok) return; if(ifFalse.action() == ActionTools::IfActionValue::GOTO) { setNextLine(line); executionEnded(); } else if(ifFalse.action() == ActionTools::IfActionValue::CALLPROCEDURE) { if(!callProcedure(line)) return; executionEnded(); } else if(ifFalse.action() == ActionTools::IfActionValue::WAIT) { connect(&mTimer, &QTimer::timeout, this, &WindowConditionInstance::checkWindow); mTimer.setInterval(100); mTimer.start(); } else executionEnded(); } }
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 SystemInstance::startExecution() { bool ok = true; auto operation = evaluateListElement<Operation>(ok, operations, QStringLiteral("operation")); bool force = evaluateBoolean(ok, QStringLiteral("force")); if(!ok) return; SystemSession systemSession; switch(operation) { case Logout: if(!systemSession.logout(force)) { emit executionException(NotAvailable, tr("Logout is not available")); return; } break; case Restart: if(!systemSession.restart(force)) { emit executionException(NotAvailable, tr("Restart is not available")); return; } break; case Shutdown: if(!systemSession.shutdown(force)) { emit executionException(NotAvailable, tr("Shutdown is not available")); return; } break; case Suspend: if(!systemSession.suspend(force)) { emit executionException(NotAvailable, tr("Suspend is not available")); return; } break; case Hibernate: if(!systemSession.hibernate(force)) { emit executionException(NotAvailable, tr("Hibernate is not available")); return; } break; case LockScreen: if(!systemSession.lockScreen()) { emit executionException(NotAvailable, tr("Lock is not available")); return; } break; case StartScreenSaver: if(!systemSession.startScreenSaver()) { emit executionException(NotAvailable, tr("Start screen saver is not available")); return; } break; } executionEnded(); }
void PlaySoundInstance::stateChanged(QMediaPlayer::State state) { if(state == QMediaPlayer::StoppedState) emit executionEnded(); }
void MultiDataInputInstance::rejected() { closeDialog(); executionEnded(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); itptr=new SLangWrapper(); waitImgs << ":/progress/prog0.png" << ":/progress/prog1.png" << ":/progress/prog2.png" << ":/progress/prog3.png" << ":/progress/prog4.png" << ":/progress/prog5.png" << ":/progress/prog6.png" << ":/progress/prog7.png"; waitTimer = new QTimer(this); waitTimer->setInterval(100); waitTimer->setSingleShot(false); connect(waitTimer,SIGNAL(timeout()),this,SLOT(onProgressTimerTick())); connect(itptr,SIGNAL(executionStarted()),this,SLOT(onScriptRunning())); connect(itptr,SIGNAL(executionEnded()),this,SLOT(onScriptStoped())); connect(ui->lwApi,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(on_pbExecute_clicked())); ce = new CodeEditor(this); ui->wtPanel->insertTab(1,ce,tr("Code")); ui->wtPanel->setCurrentIndex(0); codeFileManager = new CodeFile(this); connect(codeFileManager,SIGNAL(setFilenameIndicator(QString)),this,SLOT(onFilenameIndicatorChanged(QString))); PlaneTextConsoleInterface * cis = new PlaneTextConsoleInterface(); cis->setParent(this); cis->setPlaneTextEdit(ui->consoleView); cis->setProgressBar(ui->progressBar); itptr->setConsoleInterface(cis); ci=cis; hfm = new HexFilesMenager(this); hfm->setTabWidget(ui->twHex); hfm->setInfoLine(ui->hexInfoLine); itptr->setMemoryInterface(hfm); imp = new ImportExportMenager(this); imp->setHexFilesMenager(hfm); imp->setConsoleInterfaceMenager(ci); onScriptStoped(); driverWindow = new DriverDialog(this); driverWindow->setModal(true); cis->print("Hardware configuration:\n"); cis->print("COM port: "+driverWindow->getCurrentComPort()->description()+"\n"); cis->print("LPT port: "+driverWindow->getCurrentLptPort()->description()+"\n"); cis->print("I2C port: "+driverWindow->getCurrentI2cPort()->description()+"\n"); optionWindow = new OptionsDialog(this); optionWindow->setModal(true); codeFileManager->setCodeEditor(ce); codeFileManager->setSelectTreeWidget(ui->twScriptCatalog); connect(optionWindow,SIGNAL(updateScriptLibrary(QStringList)),codeFileManager,SLOT(updateLibrary(QStringList))); optionWindow->sendPathList(); //connect(ti,SIGNAL(addPageSignal(QByteArray,QString)),this,SLOT(addNewHexPage(QByteArray,QString))); //connect(ti,SIGNAL(overwritePageSignal(QByteArray*)),this,SLOT(overwriteHexPage(QByteArray*)),Qt::QueuedConnection); connect(hfm,SIGNAL(enableFilePrcessing(bool)),ui->menuHex,SLOT(setEnabled(bool))); connect(ce,SIGNAL(textChanged()),this,SLOT(scriptChanged())); use_settings; if (settings.value("saveGui",0).toInt()==2) { settings.beginGroup("Window"); this->setGeometry(settings.value("Geometry",this->geometry()).toRect()); this->restoreState(settings.value("State",this->saveState()).toByteArray()); settings.endGroup(); } installEventFilter(this); helpWindow = new HelpWindow(this); emit hexPageCountChange(); }