| 16 | | uploaderProgress = new QProgressDialog("Uploading...", "Cancel", 0, 100); |
| 17 | | connect(uploaderProgress, SIGNAL(canceled()), this, SLOT(terminate())); |
| 18 | | connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(readOutput())); |
| 19 | | connect(this, SIGNAL(readyReadStandardError()), this, SLOT(readError())); |
| | 16 | uploaderProgress = new QProgressDialog(); |
| | 17 | connect(uploaderProgress, SIGNAL(canceled()), this, SLOT(kill())); |
| | 18 | connect(uploaderProgress, SIGNAL(finished(int)), this, SLOT(onProgressDialogFinished(int))); |
| | 19 | connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(filterOutput())); |
| | 20 | connect(this, SIGNAL(readyReadStandardError()), this, SLOT(filterError())); |
| 35 | | //mainWindow->printOutput(readAll()); |
| 36 | | printf( "sam7: %s", qPrintable(QString(readAll()))); |
| 37 | | // QTextStream in(uploader); |
| 38 | | // QString line = in.readLine(); |
| 39 | | // while (!line.isNull()) |
| 40 | | // { |
| 41 | | // mainWindow->printOutput(line.append("\n")); |
| 42 | | // line = in.readLine(); |
| 43 | | // } |
| | 42 | QString output(readAllStandardOutput()); |
| | 43 | QRegExp re("upload progress: (\\d+)%"); |
| | 44 | int pos = 0; |
| | 45 | bool matched = false; |
| | 46 | while((pos = re.indexIn(output, pos)) != -1) |
| | 47 | { |
| | 48 | int progress = re.cap(1).toInt(); |
| | 49 | if(progress != uploaderProgress->value()) |
| | 50 | uploaderProgress->setValue(progress); |
| | 51 | pos += re.matchedLength(); |
| | 52 | matched = true; |
| | 53 | } |
| | 54 | if(!matched) |
| | 55 | qDebug("upload output: %s", qPrintable(output)); |
| 48 | | //mainWindow->printOutputError(readAll()); |
| 49 | | // QTextStream in(uploader); |
| 50 | | // QString line = in.readLine(); |
| 51 | | // while (!line.isNull()) |
| 52 | | // { |
| 53 | | // mainWindow->printOutputError(line.append("\n")); |
| 54 | | // line = in.readLine(); |
| 55 | | // } |
| | 60 | QString err(readAllStandardError()); |
| | 61 | if(err.startsWith("can't find boot agent")) |
| | 62 | mainWindow->statusMsg("Error - couldn't find an unprogrammed board to upload to."); |
| | 63 | else |
| | 64 | qDebug("upload err: %s", qPrintable(err)); |
| | 80 | |
| | 81 | /* |
| | 82 | The uploader has reported an error. |
| | 83 | Check what kind it was and print out a message to the user. |
| | 84 | */ |
| | 85 | void Uploader::onError(QProcess::ProcessError error) |
| | 86 | { |
| | 87 | QString msg; |
| | 88 | switch(error) |
| | 89 | { |
| | 90 | case QProcess::FailedToStart: |
| | 91 | msg = "uploader failed to start. sam7 is either missing, or doesn't have the correct permissions"; |
| | 92 | break; |
| | 93 | case QProcess::Crashed: |
| | 94 | msg = "uploader (sam7) was canceled or crashed."; |
| | 95 | break; |
| | 96 | case QProcess::Timedout: |
| | 97 | msg = "uploader (sam7) timed out."; |
| | 98 | break; |
| | 99 | case QProcess::WriteError: |
| | 100 | msg = "uploader (sam7) reported a write error."; |
| | 101 | break; |
| | 102 | case QProcess::ReadError: |
| | 103 | msg = "uploader (sam7) reported a read error."; |
| | 104 | break; |
| | 105 | case QProcess::UnknownError: |
| | 106 | msg = "uploader (sam7) - unknown error type."; |
| | 107 | break; |
| | 108 | } |
| | 109 | mainWindow->statusMsg("Error - " + msg); |
| | 110 | } |
| | 111 | |
| | 112 | /* |
| | 113 | The progress dialog was clicked out of, instead of the the cancel button being hit. |
| | 114 | Cancel it just the same. |
| | 115 | */ |
| | 116 | void Uploader::onProgressDialogFinished(int result) |
| | 117 | { |
| | 118 | if(result == QDialog::Rejected && state() == QProcess::Running) |
| | 119 | kill(); |
| | 120 | } |
| | 121 | |
| | 122 | |
| | 123 | |
| | 124 | |