You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
3.8 KiB
169 lines
3.8 KiB
#include "pageinstall.h"
|
|
|
|
#include <QtDebug>
|
|
#include <QFile>
|
|
|
|
#include <QBoxLayout>
|
|
#include <QLabel>
|
|
#include <QTextEdit>
|
|
#include <QProgressBar>
|
|
|
|
PageInstall::PageInstall(InstallerSettings* settings) :
|
|
InstallerPage( ),
|
|
m_Settings(settings),
|
|
m_clProc(0)
|
|
{
|
|
setupUi();
|
|
}
|
|
|
|
void PageInstall::setupUi()
|
|
{
|
|
m_Output = new QTextEdit;
|
|
m_Output->setReadOnly(true);
|
|
|
|
m_LabelEta = new QLabel;
|
|
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);
|
|
|
|
setLayout(vbox);
|
|
|
|
retranslateUi();
|
|
}
|
|
|
|
void PageInstall::retranslateUi()
|
|
{
|
|
setTitle( tr("Installing") );
|
|
|
|
m_LabelEta->setText( tr("Eta: unknown") );
|
|
}
|
|
|
|
|
|
void PageInstall::show()
|
|
{
|
|
qDebug() << "install show()";
|
|
|
|
emit changeNext(false);
|
|
emit changePrev(false);
|
|
|
|
if ( !m_clProc )
|
|
{
|
|
m_clProc = new QProcess(this);
|
|
|
|
#ifndef NO_INSTALL
|
|
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 << "--force";
|
|
|
|
if (m_Settings->builder)
|
|
args << "--build";
|
|
|
|
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);
|
|
|
|
args << QString("--set-erase=%1").arg( m_Settings->erase ? "yes" : "no" );
|
|
args << QString("--set-mbr=%1").arg( m_Settings->mbr ? "yes" : "no" );
|
|
args << QString("--set-uuid=%1").arg( m_Settings->uuid ? "yes" : "no" );
|
|
|
|
args << QString("--set-type=%1").arg( m_Settings->disktype );
|
|
args << QString("--set-video_drv=%1").arg( m_Settings->videodrv );
|
|
|
|
m_clProc->start("calculate", args);
|
|
#else
|
|
onFinish(0, QProcess::NormalExit);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
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();
|
|
/*
|
|
QFile debug("/tmp/cl-install-gui_stdout.txt");
|
|
if ( debug.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered) )
|
|
debug.write(str.toLocal8Bit());
|
|
*/
|
|
m_Output->insertPlainText( str );
|
|
m_Output->moveCursor(QTextCursor::EndOfBlock);
|
|
}
|
|
}
|
|
|
|
void PageInstall::showStdErr()
|
|
{
|
|
QString eta;
|
|
QString progress;
|
|
|
|
if (m_clProc)
|
|
{
|
|
QString str = m_clProc->readAllStandardError();
|
|
/*
|
|
QFile debug("/tmp/cl-install-gui_stderr.txt");
|
|
if ( debug.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered) )
|
|
debug.write(str.toLocal8Bit());
|
|
*/
|
|
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).replace(QRegExp("[^0-9]"), " ");
|
|
|
|
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);
|
|
|
|
if (exitCode == 0)
|
|
{
|
|
// instalation complete
|
|
emit changePrev(false);
|
|
}
|
|
|
|
m_Progress->setValue(100);
|
|
m_LabelEta->setText( tr("Eta: 0:00:00") );
|
|
|
|
delete m_clProc;
|
|
m_clProc = 0;
|
|
}
|
|
|