openmw/apps/wizard/installationpage.cpp

187 lines
5.7 KiB
C++
Raw Normal View History

2013-12-08 21:35:57 +01:00
#include "installationpage.hpp"
#include <QDebug>
2013-12-24 19:38:21 +01:00
#include <QTextCodec>
#include <QFileInfo>
#include <QFileDialog>
#include <QMessageBox>
2013-12-08 22:58:29 +01:00
#include "mainwizard.hpp"
2013-12-24 19:38:21 +01:00
#include "inisettings.hpp"
2013-12-08 22:58:29 +01:00
Wizard::InstallationPage::InstallationPage(MainWizard *wizard) :
QWizardPage(wizard),
mWizard(wizard)
2013-12-08 21:35:57 +01:00
{
setupUi(this);
2013-12-26 18:02:34 +01:00
mFinished = false;
2013-12-08 21:35:57 +01:00
}
2013-12-08 22:58:29 +01:00
void Wizard::InstallationPage::initializePage()
{
2013-12-24 23:09:31 +01:00
QString path(field("installation.path").toString());
QStringList components(field("installation.components").toStringList());
logTextEdit->append(QString("Installing to %1").arg(path));
logTextEdit->append(QString("Installing %1.").arg(components.join(", ")));
2013-12-24 19:38:21 +01:00
installProgressBar->setMinimum(0);
// Set the progressbar maximum to a multiple of 100
// That way installing all three components would yield 300%
// When one component is done the bar will be filled by 33%
if (field("installation.new").toBool() == true)
{
installProgressBar->setMaximum((components.count() * 100));
}
else
{
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Tribunal"))
&& mWizard->mInstallations[path]->hasTribunal == false)
2013-12-24 19:38:21 +01:00
installProgressBar->setMaximum(100);
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Bloodmoon"))
&& mWizard->mInstallations[path]->hasBloodmoon == false)
2013-12-24 19:38:21 +01:00
installProgressBar->setMaximum(installProgressBar->maximum() + 100);
}
2013-12-25 18:52:34 +01:00
startInstallation();
}
2013-12-25 18:52:34 +01:00
void Wizard::InstallationPage::startInstallation()
{
QStringList components(field("installation.components").toStringList());
QString path(field("installation.path").toString());
QThread *thread = new QThread();
mUnshield = new UnshieldWorker();
mUnshield->moveToThread(thread);
qRegisterMetaType<Wizard::Component>("Wizard::Component");
connect(thread, SIGNAL(started()),
mUnshield, SLOT(extract()));
connect(mUnshield, SIGNAL(finished()),
thread, SLOT(quit()));
2013-12-25 18:52:34 +01:00
connect(mUnshield, SIGNAL(finished()),
mUnshield, SLOT(deleteLater()));
2013-12-25 18:52:34 +01:00
connect(mUnshield, SIGNAL(finished()),
thread, SLOT(deleteLater()));
connect(mUnshield, SIGNAL(finished()),
this, SLOT(installationFinished()), Qt::QueuedConnection);
2013-12-25 18:52:34 +01:00
connect(mUnshield, SIGNAL(error(QString)),
this, SLOT(installationError(QString)), Qt::QueuedConnection);
connect(mUnshield, SIGNAL(textChanged(QString)),
installProgressLabel, SLOT(setText(QString)), Qt::QueuedConnection);
2013-12-25 18:52:34 +01:00
connect(mUnshield, SIGNAL(textChanged(QString)),
logTextEdit, SLOT(append(QString)), Qt::QueuedConnection);
2013-12-25 18:52:34 +01:00
connect(mUnshield, SIGNAL(progressChanged(int)),
installProgressBar, SLOT(setValue(int)), Qt::QueuedConnection);
2013-12-26 18:02:34 +01:00
connect(mUnshield, SIGNAL(requestFileDialog(Wizard::Component)),
this, SLOT(showFileDialog(Wizard::Component)), Qt::QueuedConnection);
2013-12-25 18:52:34 +01:00
if (field("installation.new").toBool() == true)
{
// Always install Morrowind
mUnshield->setInstallComponent(Wizard::Component_Morrowind, true);
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Tribunal")))
mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Bloodmoon")))
mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
2013-12-25 18:52:34 +01:00
} else {
// Morrowind should already be installed
mUnshield->setInstallComponent(Wizard::Component_Morrowind, false);
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Tribunal"))
&& !mWizard->mInstallations[path]->hasTribunal)
mUnshield->setInstallComponent(Wizard::Component_Tribunal, true);
2013-12-25 18:52:34 +01:00
if (components.contains(QLatin1String("Bloodmoon"))
&& !mWizard->mInstallations[path]->hasBloodmoon)
mUnshield->setInstallComponent(Wizard::Component_Bloodmoon, true);
2013-12-25 18:52:34 +01:00
2013-12-26 18:02:34 +01:00
// Set the location of the Morrowind.ini to update
mUnshield->setIniPath(mWizard->mInstallations[path]->iniPath);
2013-12-26 18:02:34 +01:00
}
2013-12-25 18:52:34 +01:00
// Set the installation target path
mUnshield->setPath(path);
2013-12-25 18:52:34 +01:00
2013-12-26 18:02:34 +01:00
// Set the right codec to use for Morrowind.ini
QString language(field("installation.language").toString());
if (language == QLatin1String("Polish")) {
mUnshield->setIniCodec(QTextCodec::codecForName("windows-1250"));
2013-12-26 18:02:34 +01:00
}
else if (language == QLatin1String("Russian")) {
mUnshield->setIniCodec(QTextCodec::codecForName("windows-1251"));
2013-12-26 18:02:34 +01:00
}
else {
mUnshield->setIniCodec(QTextCodec::codecForName("windows-1252"));
2013-12-26 18:02:34 +01:00
}
thread->start();
}
void Wizard::InstallationPage::showFileDialog(Wizard::Component component)
{
QString fileName = QFileDialog::getOpenFileName(
this,
tr("Select installation file"),
QDir::rootPath(),
tr("InstallShield header files (*.hdr)"));
if (fileName.isEmpty()) {
qDebug() << "Cancel was clicked!";
return;
}
QFileInfo info(fileName);
mUnshield->setComponentPath(component, info.absolutePath());
2013-12-25 18:52:34 +01:00
}
void Wizard::InstallationPage::installationFinished()
{
qDebug() << "finished!";
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Installation finished"));
msgBox.setIcon(QMessageBox::Information);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText(tr("Installation completed sucessfully!"));
msgBox.exec();
2013-12-25 18:52:34 +01:00
mFinished = true;
2013-12-26 18:02:34 +01:00
emit completeChanged();
}
void Wizard::InstallationPage::installationError(const QString &text)
{
qDebug() << "error: " << text;
2013-12-25 18:52:34 +01:00
}
bool Wizard::InstallationPage::isComplete() const
{
return mFinished;
}
2013-12-08 22:58:29 +01:00
int Wizard::InstallationPage::nextId() const
{
return MainWizard::Page_Import;
}