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.
178 lines
3.7 KiB
178 lines
3.7 KiB
#include "pageinstall.h"
|
|
|
|
#include <QBoxLayout>
|
|
#include <QLabel>
|
|
#include <QTextEdit>
|
|
#include <QProgressBar>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QDebug>
|
|
|
|
#include "calculateconfig.h"
|
|
|
|
PageInstall::PageInstall() :
|
|
InstallerPage(),
|
|
m_clProc(0)
|
|
{
|
|
setupUi();
|
|
}
|
|
|
|
void PageInstall::setupUi()
|
|
{
|
|
m_Output = new QTextEdit;
|
|
m_Output->setReadOnly(true);
|
|
QFont font = m_Output->currentFont();
|
|
font.setFamily("Droid Sans Mono");
|
|
font.setPointSize(8);
|
|
m_Output->setFont( font );
|
|
m_Output->setLineWrapMode( QTextEdit::NoWrap );
|
|
|
|
// 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()";
|
|
m_Progress->setMaximum(100);
|
|
m_Output->clear();
|
|
|
|
CalculateConfig* clConf = CalculateConfig::instance();
|
|
|
|
emit changeNext(false);
|
|
emit changePrev(false);
|
|
|
|
if ( !m_clProc )
|
|
{
|
|
// check password for user
|
|
QStringList passwdNeed = clConf->getPasswordUsers();
|
|
qDebug() << "Passwords need: " + passwdNeed.join(",");
|
|
|
|
QStringList passwd;
|
|
foreach(const QString& user, passwdNeed)
|
|
{
|
|
if (user == "root")
|
|
{
|
|
passwd << clConf->getValue("gui_root_psw").toString();
|
|
}
|
|
else
|
|
{
|
|
for (int i(0); i != clConf->getValue("gui_users").toStringList().count(); ++i)
|
|
{
|
|
if ( clConf->getValue("gui_users").toStringList().at(i) == user )
|
|
{
|
|
passwd << clConf->getValue("gui_passwds").toStringList().at(i);
|
|
break;
|
|
}
|
|
qDebug() << "Unknown user " << user;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
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(finished(int,QProcess::ExitStatus)), this, SLOT(onFinish(int,QProcess::ExitStatus)) );
|
|
|
|
QStringList args = CalculateConfig::instance()->getInstallParameters();
|
|
|
|
qDebug() << "Start: cl-install ";
|
|
|
|
foreach(const QString& arg, args)
|
|
qDebug() << arg;
|
|
|
|
m_clProc->setStandardErrorFile("/var/log/calculate/cl-install-gui-err.log");
|
|
|
|
m_clProc->start( "cl-install -f --color never -P " + args.join(" ") );
|
|
|
|
m_Progress->setMinimum(0);
|
|
m_Progress->setMaximum(0);
|
|
|
|
m_clProc->write( (passwd.join("\n") + "\n").toLocal8Bit() );
|
|
|
|
}
|
|
}
|
|
|
|
void PageInstall::onError(QProcess::ProcessError error)
|
|
{
|
|
m_Progress->setMinimum(0);
|
|
m_Progress->setMaximum(100);
|
|
qDebug() << "failed to run process 'calculate' error=" << error ;
|
|
onFinish(-error);
|
|
}
|
|
|
|
void PageInstall::showStdOut()
|
|
{
|
|
if (m_clProc)
|
|
{
|
|
QString str = m_clProc->readAllStandardOutput();
|
|
|
|
// skip fan (/|\-)
|
|
str.replace("\x08/", "");
|
|
str.replace("\x08\\", "");
|
|
str.replace("\x08-", "");
|
|
str.replace("\x08|", "");
|
|
|
|
m_Output->moveCursor(QTextCursor::End);
|
|
m_Output->insertPlainText( str );
|
|
}
|
|
}
|
|
|
|
void PageInstall::onFinish(int exitCode, QProcess::ExitStatus exitStatus)
|
|
{
|
|
qDebug() << "install onFinish() " << exitCode;
|
|
|
|
m_Progress->setMinimum(0);
|
|
m_Progress->setMaximum(100);
|
|
|
|
emit changeNext(true);
|
|
emit changePrev(true);
|
|
|
|
if (exitCode == 0)
|
|
{
|
|
m_Progress->setValue(100);
|
|
|
|
// instalation complete
|
|
emit changePrev(false);
|
|
}
|
|
else
|
|
{
|
|
m_Output->moveCursor(QTextCursor::End);
|
|
m_Output->insertPlainText(
|
|
tr("Error. Additional information in /var/log/calculate/cl-install-gui-err.log")
|
|
);
|
|
}
|
|
|
|
m_Progress->setValue(100);
|
|
// m_LabelEta->setText( tr("Eta: 0:00:00") );
|
|
|
|
disconnect(m_clProc);
|
|
delete m_clProc;
|
|
m_clProc = 0;
|
|
}
|
|
|