void mainWin::slotReadPkgOutput() { QString line, tmp, cur, tot, fname; int curItem, totItem; bool ok; while (uProc->canReadLine()) { line = uProc->readLine().simplified(); qDebug() << line; // Empty line? We can skip it if ( line.isEmpty() ) continue; tmp = line; tmp.truncate(50); // Flags we can parse out and not show the user // Check if we have crashed into a conflict and ask the user what to do if ( line.indexOf("PKGCONFLICTS: ") == 0 ) { tmp = line; tmp.replace("PKGCONFLICTS: ", ""); ConflictList = tmp; continue; } if ( line.indexOf("PKGREPLY: ") == 0 ) { QString ans; tmp = line; tmp.replace("PKGREPLY: ", ""); QMessageBox msgBox; msgBox.setText(tr("The following packages are causing conflicts with the selected changes and can be automatically removed. Continue?") + "\n" + ConflictList); msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); msgBox.setDetailedText(getConflictDetailText()); msgBox.setDefaultButton(QMessageBox::No); if ( msgBox.exec() == QMessageBox::Yes) { // We will try to fix conflicts ans="yes"; } else { // We will fail :( QMessageBox::warning(this, tr("Package Conflicts"), tr("You may need to manually fix the conflicts before trying again."), QMessageBox::Ok, QMessageBox::Ok); ans="no"; } QFile pkgTrig( tmp ); if ( pkgTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &pkgTrig ); streamTrig << ans; pkgTrig.close(); } continue; } if ( line.indexOf("FETCH: ") == 0 ) { progressUpdate->setValue(progressUpdate->value() + 1); tmp = line; tmp = tmp.remove(0, tmp.lastIndexOf("/") + 1); progressUpdate->setRange(0, 0); progressUpdate->setValue(0); curFileText = tr("Downloading: %1").arg(tmp); textStatus->setText(tr("Downloading: %1").arg(tmp)); continue; } if ( line.indexOf("FETCHDONE") == 0 ) continue; if ( line.indexOf("SIZE: ") == 0 ) { bool ok, ok2; line.replace("SIZE: ", ""); line.replace("DOWNLOADED: ", ""); line.replace("SPEED: ", ""); line.section(" ", 0, 0).toInt(&ok); line.section(" ", 1, 1).toInt(&ok2); if ( ok && ok2 ) { QString unit; int tot = line.section(" ", 0, 0).toInt(&ok); int cur = line.section(" ", 1, 1).toInt(&ok2); QString percent = QString::number( (float)(cur * 100)/tot ); QString speed = line.section(" ", 2, 3); // Get the MB downloaded / total if ( tot > 2048 ) { unit="MB"; tot = tot / 1024; cur = cur / 1024; } else { unit="KB"; } QString ProgressString=QString("(%1" + unit + " of %2" + unit + " at %3)").arg(cur).arg(tot).arg(speed); progressUpdate->setRange(0, tot); progressUpdate->setValue(cur); textStatus->setText(curFileText + " " + ProgressString); } continue; } // Now show output on GUI textDisplayOut->insertPlainText(line + "\n"); textDisplayOut->moveCursor(QTextCursor::End); // Any other flags to look for? ///////////////////////////////////////////////////// if ( line.indexOf("to be downloaded") != -1 ) { textStatus->setText(tr("Downloading packages...")); curUpdate = 0; progressUpdate->setValue(0); continue; } if ( line.indexOf("Checking integrity") == 0 ) { textStatus->setText(line); uPackages = true; dPackages = false; curUpdate = 0; progressUpdate->setValue(0); progressUpdate->setRange(0, 0); progressUpdate->setValue(0); continue; } if ( uPackages ) { if ( line.indexOf("[") == 0 ) { tmp=line.section("]", 1, 1); textStatus->setText(tmp); tmp=line.section("/", 0, 0).replace("[", ""); tmp.toInt(&ok); if (ok) { curItem=tmp.toInt(&ok); tmp=line.section("/", 1, 1).section("]", 0, 0); tmp.toInt(&ok); if (ok) { totItem=tmp.toInt(&ok); progressUpdate->setRange(0, totItem); progressUpdate->setValue(curItem); } } } continue; } } // end of while }
void DLProcess::parsePKGLine(QString line){ // KPM!! // TODO 12-12-2013 // No JSON in Qt4, once we move to Qt5, replace this hack // with the new JSON parser // Moved 2/18/14 to this class from pc-pkgmanager by Ken Moore //qDebug() << " -- pkg line:" << line; // Look for a download status update if ( line.indexOf("\"INFO_FETCH") != -1 && line.indexOf("\"url\"") != -1 ) { QString file, dl, tot; line.remove(0, line.indexOf("\"url") + 8); line.truncate(line.lastIndexOf("}")); // Get the file basename file = line; //qDebug() << "DL File:" << file; file.truncate(line.indexOf("\"")); file = file.section("/",-1).section(".txz",0,0); //replace the QFileInfo method below (Ken) //QFileInfo tFile; //tFile.setFile(file); //file = tFile.baseName(); // Get the download / total dl = line.section(":", 2, 2).section(",", 0, 0); tot = line.section(":", 3, 3).section("}", 0, 0); dl = dl.simplified(); tot = tot.simplified(); //These are in bytes, need to convert to kilobytes before sending it on... dl = QString::number( dl.toLongLong()/1024 ); tot = QString::number( tot.toLongLong()/1024 ); //Now calculate the stats and emit the signal calculateStats(dl, tot, "", file); } else if ( line.indexOf("PKGCONFLICTS: ") == 0 ) { QString tmp = line; tmp.replace("PKGCONFLICTS: ", ""); ConflictList = tmp; } else if ( line.indexOf("PKGREPLY: ") == 0 ) { QString ans; QString tmp = line; tmp.replace("PKGREPLY: ", ""); QMessageBox msgBox(parentW); msgBox.setText(tr("The following packages are causing conflicts with the selected changes and can be automatically removed. Continue?") + "\n" + ConflictList); msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); msgBox.setDetailedText(getConflictDetailText()); msgBox.setDefaultButton(QMessageBox::No); if ( msgBox.exec() == QMessageBox::Yes) { // We will try to fix conflicts ans="yes"; } else { // We will fail :( QMessageBox::warning(parentW, tr("Package Conflicts"), tr("You may need to manually fix the conflicts before trying again."), QMessageBox::Ok, QMessageBox::Ok); ans="no"; } QFile pkgTrig( tmp ); if ( pkgTrig.open( QIODevice::WriteOnly ) ) { QTextStream streamTrig( &pkgTrig ); streamTrig << ans; pkgTrig.close(); ConflictList.clear(); //already sent an answer - clear the internal list } }else{ //Just emit the message //line.remove(0, line.indexOf("\"msg") + 8); //line.truncate(line.lastIndexOf("\"")); emit UpdateMessage(line); return; } }