Example #1
0
QProcess::ProcessChannel QProcessProto::readChannel() const
{
  QProcess *item = qscriptvalue_cast<QProcess*>(thisObject());
  if (item)
    return item->readChannel();
  return QProcess::ProcessChannel();
}
// Static utilities: Keep running as long as it gets data.
bool SynchronousProcess::readDataFromProcess(QProcess &p, int timeOutMS,
                                             QByteArray *stdOut, QByteArray *stdErr,
                                             bool showTimeOutMessageBox)
{
    if (syncDebug)
        qDebug() << ">readDataFromProcess" << timeOutMS;
    if (p.state() != QProcess::Running) {
        qWarning("readDataFromProcess: Process in non-running state passed in.");
        return false;
    }

    QTC_ASSERT(p.readChannel() == QProcess::StandardOutput, return false)

    // Keep the process running until it has no longer has data
    bool finished = false;
    bool hasData = false;
    do {
        finished = p.waitForFinished(timeOutMS);
        hasData = false;
        // First check 'stdout'
        if (p.bytesAvailable()) { // applies to readChannel() only
            hasData = true;
            const QByteArray newStdOut = p.readAllStandardOutput();
            if (stdOut)
                stdOut->append(newStdOut);
        }
        // Check 'stderr' separately. This is a special handling
        // for 'git pull' and the like which prints its progress on stderr.
        const QByteArray newStdErr = p.readAllStandardError();
        if (!newStdErr.isEmpty()) {
            hasData = true;
            if (stdErr)
                stdErr->append(newStdErr);
        }
        // Prompt user, pretend we have data if says 'No'.
        const bool hang = !hasData && !finished;
        if (hang && showTimeOutMessageBox) {
            if (!askToKill())
                hasData = true;
        }
    } while (hasData && !finished);
    if (syncDebug)
        qDebug() << "<readDataFromProcess" << finished;
    return finished;
}
Example #3
0
void Area::saveEdit(int del){

    //temporary file for the text edition

    QFile newph("temp.ph");

    newph.open(QIODevice::WriteOnly | QIODevice::Truncate);
    QTextStream flux(&newph);
    flux.setCodec("UTF-8");    

    QString *file = new QString("temp.ph");
    QString fileXML("tempXML.xml");
    std::string phFile = file->toStdString();

    try{

        //Save new text into new file
        if(this->textArea->toPlainText().isEmpty()){

            throw textAreaEmpty_exception();
        }

        flux << this->textArea->toPlainText() << endl;

        newph.close();        

        if(del == 0){

            emit makeTempXML();
        }

        // render graph
        PHPtr myPHPtr = PHIO::parseFile(phFile);
        this->myArea->setPHPtr(myPHPtr);
        myPHPtr->render();
        PHScenePtr scene = myPHPtr->getGraphicsScene();
        this->myArea->setScene(&*scene);

        // delete the current sortsTree and groupsTree
        this->treeArea->sortsTree->clear();
        //this->treeArea->groupsTree->clear();
        // set the pointer of the treeArea
        this->treeArea->myPHPtr = myPHPtr;
        //set the pointer of the treeArea
        this->treeArea->myArea = this->myArea;
        // build the tree in the treeArea
        this->treeArea->build();

        this->indicatorEdit->setVisible(false);       
        this->saveTextEdit->setDefault(false);
        this->textArea->incrementeNberTextChange();        
        this->typeOfCancel = 0;
        this->saveTextEdit->setEnabled(false);        
        this->textArea->setNberEdit(0);
        this->cancelTextEdit->setShortcut(QKeySequence());

        this->setOldText();

        newph.remove();

        this->mainWindow->importXMLMetadata(fileXML);
    }
    catch(textAreaEmpty_exception & e){

        QMessageBox::critical(this, "Error !", "You cannot update from an empty text area !");
    }
    catch(ph_parse_error & argh){

        //Catch a parsing error !
        //Put the exception into a QMessageBox critical

        QString phc = "phc";
        QStringList args;
        args << "-l" << "dump" << "-i" << QString::fromUtf8(phFile.c_str()) << "--no-debug";
        QProcess *phcProcess = new QProcess();
        phcProcess->start(phc, args);
        if (!phcProcess->waitForStarted())
            throw pint_program_not_found() << file_info("phc");

        phcProcess->readChannel();

        // read result
        QByteArray stderr;
        QByteArray stdout;
        while (!phcProcess->waitForFinished()) {
            stderr += phcProcess->readAllStandardError();
            stdout += phcProcess->readAllStandardOutput();
        }
        stderr += phcProcess->readAllStandardError();
        stdout += phcProcess->readAllStandardOutput();
        delete phcProcess;

        //Use split function to only keep the line number

        QStringList list = QString(stderr).split('"');
        QStringList list2 = list[1].split(":");
        QStringList list3 = list2[0].split(" ");

        //One or more of your expressions are wrong !
        newph.remove();
        QMessageBox::critical(this, "Syntax error !", "One or more of your expressions are wrong !\nNear "+list3[0]+" "+list3[1]+" of dump");
        //return NULL;
    }
    catch(sort_not_found& sort){

        //Catch a error if the user delete a sort before associated actions !

        QMessageBox::critical(this, "Error !", "Delete the associated actions before the process !");
    }
}