#include "pageinstall.h" #include #include #include #include #include PageInstall::PageInstall(const QString& title, InstallerSettings* settings) : InstallerPage(title), m_Settings(settings), m_clProc(0) { //QLabel* label = new QLabel( tr("") ) m_Output = new QTextEdit; m_Output->setReadOnly(true); m_LabelEta = new QLabel( tr("Eta: unknown") ); m_Progress = new QProgressBar(0); QHBoxLayout* hbox = new QHBoxLayout; hbox->addWidget(m_LabelEta); hbox->addWidget(m_Progress); QVBoxLayout* vbox = new QVBoxLayout; vbox->addWidget(m_Output); vbox->addLayout(hbox); m_Widget->setLayout(vbox); } void PageInstall::show() { emit changeNext(false); emit changePrev(false); qDebug() << "install show()"; emit changeNext(false); emit changePrev(false); if ( !m_clProc ) { m_clProc = new QProcess(this); connect( m_clProc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)) ); connect( m_clProc, SIGNAL(readyReadStandardOutput()), this, SLOT(showStdOut()) ); connect( m_clProc, SIGNAL(readyReadStandardError()), this, SLOT(showStdErr()) ); connect( m_clProc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onFinish(int,QProcess::ExitStatus)) ); QStringList args; args << QString("--disk=%1").arg(m_Settings->disk); args << QString("--set-hostname=%1").arg(m_Settings->host); args << QString("--set-format=%1").arg(m_Settings->fs); args << QString("--set-lang=%1").arg(m_Settings->language); args << QString("--set-timezone=%1").arg(m_Settings->timezone); m_clProc->start("calculate", args); } } bool PageInstall::validate() { return true; } void PageInstall::onError(QProcess::ProcessError error) { qDebug() << "failed to run process 'calculate' error=" << error ; onFinish(-error); } void PageInstall::showStdOut() { if (m_clProc) { // debug QString str = m_clProc->readAllStandardOutput(); // TODO: parse out m_Output->insertPlainText( str ); } } void PageInstall::showStdErr() { QString eta; QString progress; if (m_clProc) { QString str = m_clProc->readAllStandardError(); if ( str.contains("eta:") ) { QRegExp eta_regexp("\\b(\\d{1,2}:\\d{1,2}:\\d{1,2})\\b"); QRegExp percent_regexp("\\d{1,2}.%"); if ( eta_regexp.indexIn(str) ) eta = eta_regexp.cap(0); if ( percent_regexp.indexIn(str) ) progress = percent_regexp.cap(0); if ( !eta.isEmpty() ) m_LabelEta->setText( tr("Eta: %1").arg(eta) ); if ( !progress.isEmpty() ) m_Progress->setValue( progress.toInt() ); } } } void PageInstall::onFinish(int exitCode, QProcess::ExitStatus exitStatus) { qDebug() << "install onFinish()"; emit changeNext(true); emit changePrev(true); delete m_clProc; m_clProc = 0; }