368 lines
12 KiB
C++
Raw Normal View History

2011-02-21 16:30:31 +01:00
/**************************************************************************
**
** This file is part of Qt SDK**
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).*
**
** Contact: Nokia Corporation qt-info@nokia.com**
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception version
** 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you are unsure which license is appropriate for your use, please contact
** (qt-info@nokia.com).
**
**************************************************************************/
#include "installerbasecommons.h"
#include <common/installersettings.h>
2011-02-28 10:50:52 +01:00
#include <messageboxhandler.h>
2011-02-21 16:30:31 +01:00
#include <qinstaller.h>
#include <qinstallercomponent.h>
2011-02-28 10:50:52 +01:00
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>
#include <QtGui/QLabel>
2011-03-01 12:27:41 +01:00
#include <QtGui/QProgressBar>
#include <QtGui/QRadioButton>
#include <QtGui/QStackedWidget>
2011-02-28 10:50:52 +01:00
#include <QtGui/QVBoxLayout>
using namespace QInstaller;
2011-02-21 16:30:31 +01:00
2011-03-01 12:27:41 +01:00
// -- IntroductionPageImpl
IntroductionPageImpl::IntroductionPageImpl(QInstaller::Installer *installer)
: QInstaller::IntroductionPage(installer)
{
QWidget *widget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout(widget);
2011-03-01 12:27:41 +01:00
m_packageManager = new QRadioButton(tr("Package manager"), this);
2011-03-01 12:27:41 +01:00
layout->addWidget(m_packageManager);
m_packageManager->setChecked(installer->isPackageManager());
connect(m_packageManager, SIGNAL(toggled(bool)), this, SLOT(setPackageManager(bool)));
2011-03-01 12:27:41 +01:00
m_updateComponents = new QRadioButton(tr("Update components"), this);
2011-03-01 12:27:41 +01:00
layout->addWidget(m_updateComponents);
m_updateComponents->setChecked(installer->isUpdater());
connect(m_updateComponents, SIGNAL(toggled(bool)), this, SLOT(setUpdater(bool)));
2011-03-01 12:27:41 +01:00
m_removeAllComponents = new QRadioButton(tr("Remove all components"), this);
2011-03-01 12:27:41 +01:00
layout->addWidget(m_removeAllComponents);
m_removeAllComponents->setChecked(installer->isUninstaller());
connect(m_removeAllComponents, SIGNAL(toggled(bool)), this, SLOT(setUninstaller(bool)));
2011-03-01 12:27:41 +01:00
connect(m_removeAllComponents, SIGNAL(toggled(bool)), installer,
SLOT(setCompleteUninstallation(bool)));
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
m_label = new QLabel(this);
m_label->setWordWrap(true);
m_label->setText(tr("Retrieving information from remote installation sources..."));
layout->addWidget(m_label);
m_progressBar = new QProgressBar(this);
m_progressBar->setRange(0, 0);
layout->addWidget(m_progressBar);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
widget->setLayout(layout);
setWidget(widget);
2011-03-01 12:27:41 +01:00
installer->setCompleteUninstallation(installer->isUninstaller());
}
int IntroductionPageImpl::nextId() const
{
if (installer()->isUninstaller())
return Installer::ReadyForInstallation;
if (installer()->isUpdater() || installer()->isPackageManager())
return Installer::ComponentSelection;
2011-03-01 12:27:41 +01:00
return QInstaller::IntroductionPage::nextId();
}
void IntroductionPageImpl::showAll()
2011-03-01 12:27:41 +01:00
{
showWidgets(true);
}
void IntroductionPageImpl::hideAll()
{
showWidgets(false);
2011-03-01 12:27:41 +01:00
}
void IntroductionPageImpl::showMetaInfoUdate()
{
showWidgets(false);
m_label->setVisible(true);
m_progressBar->setVisible(true);
2011-03-01 12:27:41 +01:00
}
void IntroductionPageImpl::showMaintenanceTools()
{
showWidgets(true);
m_label->setVisible(false);
m_progressBar->setVisible(false);
2011-03-01 12:27:41 +01:00
}
void IntroductionPageImpl::setMaintenanceToolsEnabled(bool enable)
{
m_packageManager->setEnabled(enable);
m_updateComponents->setEnabled(enable);
m_removeAllComponents->setEnabled(enable);
}
2011-03-01 12:27:41 +01:00
void IntroductionPageImpl::message(KDJob *job, const QString &msg)
{
Q_UNUSED(job)
m_label->setText(msg);
}
void IntroductionPageImpl::setUpdater(bool value)
{
if (value) {
installer()->setUpdater();
emit initUpdater();
}
}
void IntroductionPageImpl::setUninstaller(bool value)
{
if (value)
installer()->setUninstaller();
}
void IntroductionPageImpl::setPackageManager(bool value)
{
if (value) {
installer()->setPackageManager();
emit initPackageManager();
}
}
void IntroductionPageImpl::showWidgets(bool show)
{
m_label->setVisible(show);
m_progressBar->setVisible(show);
m_packageManager->setVisible(show);
m_updateComponents->setVisible(show);
m_removeAllComponents->setVisible(show);
}
2011-03-01 12:27:41 +01:00
2011-02-28 10:50:52 +01:00
// -- TargetDirectoryPageImpl
/*!
A custom target directory selection based due to the no-space restriction...
*/
TargetDirectoryPageImpl::TargetDirectoryPageImpl(Installer *installer)
: TargetDirectoryPage(installer)
2011-02-21 16:30:31 +01:00
{
QPalette palette;
palette.setColor(QPalette::WindowText, Qt::red);
m_warningLabel = new QLabel(this);
m_warningLabel->setPalette(palette);
2011-02-28 10:50:52 +01:00
insertWidget(m_warningLabel, QLatin1String("MessageLabel"), 2);
2011-02-21 16:30:31 +01:00
}
2011-02-28 10:50:52 +01:00
QString TargetDirectoryPageImpl::targetDirWarning() const
{
if (targetDir().contains(QLatin1Char(' ')))
2011-02-21 16:30:31 +01:00
return TargetDirectoryPageImpl::tr("The installation path must not contain any space.");
return QString();
}
bool TargetDirectoryPageImpl::isComplete() const
{
const QString warning = targetDirWarning();
m_warningLabel->setText(warning);
return warning.isEmpty();
}
2011-02-28 10:50:52 +01:00
bool TargetDirectoryPageImpl::askQuestion(const QString &identifier, const QString &message)
{
QMessageBox::StandardButton bt =
MessageBoxHandler::warning(MessageBoxHandler::currentBestSuitParent(), identifier,
TargetDirectoryPageImpl::tr("Warning"), message, QMessageBox::Yes | QMessageBox::No);
QTimer::singleShot(100, wizard()->page(nextId()), SLOT(repaint()));
2011-02-21 16:30:31 +01:00
return bt == QMessageBox::Yes;
}
2011-02-28 10:50:52 +01:00
bool TargetDirectoryPageImpl::failWithWarning(const QString &identifier, const QString &message)
{
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), identifier,
TargetDirectoryPageImpl::tr("Warning"), message);
QTimer::singleShot(100, wizard()->page(nextId()), SLOT(repaint()));
2011-02-21 16:30:31 +01:00
return false;
}
bool TargetDirectoryPageImpl::validatePage()
{
2011-02-28 10:50:52 +01:00
if (!isVisible())
2011-02-21 16:30:31 +01:00
return true;
if (targetDir().isEmpty()) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("forbiddenTargetDirectory"), tr("Error"),
tr( "The install directory cannot be empty, please specify a valid folder"), QMessageBox::Ok);
return false;
}
2011-01-03 16:53:26 +02:00
QString remove = installer()->value(QLatin1String("RemoveTargetDir"));
if (!QVariant(remove).toBool())
return true;
2011-02-21 16:30:31 +01:00
const QDir dir(targetDir());
if (dir.exists() && dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty())
return true;
QFileInfo fi(targetDir());
if (fi.isDir()) {
if (dir == QDir::root()) {
2011-02-21 16:30:31 +01:00
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
2011-02-28 10:50:52 +01:00
QLatin1String("forbiddenTargetDirectory"), tr("Error"),
tr("As the install directory is completely deleted installing in %1 is forbidden")
.arg(QDir::rootPath()), QMessageBox::Ok);
2011-02-21 16:30:31 +01:00
return false;
}
2011-02-28 10:50:52 +01:00
QString fileName = installer()->settings().uninstallerName();
#if defined(Q_WS_MAC)
if (QFileInfo(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).isBundle())
fileName += QLatin1String(".app/Contents/MacOS/") + fileName;
#elif defined(Q_OS_WIN)
fileName += QLatin1String(".exe");
#endif
QFileInfo fi2(targetDir() + QDir::separator() + fileName);
2011-02-28 10:50:52 +01:00
if (fi2.exists()) {
return askQuestion(QLatin1String("overwriteTargetDirectory"),
TargetDirectoryPageImpl::tr("The folder you selected exists already and "
"contains an installation.\nDo you want to overwrite it?"));
}
return askQuestion(QLatin1String("overwriteTargetDirectory"),
tr("You have selected an existing, non-empty folder for installation.\n"
"Note that it will be completely wiped on uninstallation of this application.\n"
"It is not advisable to install into this folder as installation might fail.\n"
"Do you want to continue?"));
} else if (fi.isFile() || fi.isSymLink()) {
MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
QLatin1String("WrongTargetDirectory"), tr("Error"),
tr("You have selected an existing file or symlink, please choose a different target for "
"installation."), QMessageBox::Ok);
return false;
2011-02-21 16:30:31 +01:00
}
return true;
}
2011-02-28 10:50:52 +01:00
// -- QtInstallerGui
QtInstallerGui::QtInstallerGui(Installer *installer)
: Gui(installer, 0)
2011-02-21 16:30:31 +01:00
{
2011-03-01 12:28:09 +01:00
setPage(Installer::Introduction, new IntroductionPageImpl(installer));
2011-02-28 10:50:52 +01:00
setPage(Installer::TargetDirectory, new TargetDirectoryPageImpl(installer));
setPage(Installer::ComponentSelection, new ComponentSelectionPage(m_installer));
setPage(Installer::LicenseCheck, new LicenseAgreementPage(installer));
2011-02-21 16:30:31 +01:00
#ifdef Q_OS_WIN
2011-02-28 10:50:52 +01:00
setPage(Installer::StartMenuSelection, new StartMenuDirectoryPage(installer));
2011-02-21 16:30:31 +01:00
#endif
2011-02-28 10:50:52 +01:00
setPage(Installer::ReadyForInstallation, new ReadyForInstallationPage(installer));
setPage(Installer::PerformInstallation, new PerformInstallationPage(installer));
setPage(Installer::InstallationFinished, new FinishedPage(installer));
2011-02-21 16:30:31 +01:00
bool ok = false;
2011-02-28 10:50:52 +01:00
const int startPage = installer->value(QLatin1String("GuiStartPage")).toInt(&ok);
if(ok)
setStartId(startPage);
2011-02-21 16:30:31 +01:00
}
void QtInstallerGui::init()
{
2011-03-16 17:08:51 +01:00
if (m_installer->components(true, AllMode).count() == 1) {
Q_ASSERT(!m_installer->components(false, AllMode).isEmpty());
m_installer->components(false, AllMode).first()->setSelected(true);
wizardPageVisibilityChangeRequested(false, Installer::ComponentSelection);
2011-02-21 16:30:31 +01:00
}
}
2011-02-28 10:50:52 +01:00
2011-02-21 16:30:31 +01:00
// -- QtUninstallerGui
2011-02-28 10:50:52 +01:00
QtUninstallerGui::QtUninstallerGui(Installer *installer)
: Gui(installer, 0)
2011-02-21 16:30:31 +01:00
{
2011-03-01 12:28:09 +01:00
setPage(Installer::Introduction, new IntroductionPageImpl(installer));
2011-02-28 10:50:52 +01:00
setPage(Installer::ComponentSelection, new ComponentSelectionPage(m_installer));
setPage(Installer::LicenseCheck, new LicenseAgreementPage(installer));
setPage(Installer::ReadyForInstallation, new ReadyForInstallationPage(installer));
setPage(Installer::PerformInstallation, new PerformInstallationPage(installer));
setPage(Installer::InstallationFinished, new FinishedPage(installer));
if (installer->isPackageManager() || installer->isUpdater()) {
2011-02-28 10:50:52 +01:00
RestartPage *p = new RestartPage(installer);
2011-02-21 16:30:31 +01:00
connect(p, SIGNAL(restart()), this, SIGNAL(gotRestarted()));
2011-02-28 10:50:52 +01:00
setPage(Installer::InstallationFinished + 1, p);
setPage(Installer::InstallationFinished + 2, new Page(installer));
2011-02-21 16:30:31 +01:00
}
}
void QtUninstallerGui::init()
{
const bool visible = !m_installer->components(false, m_installer->runMode()).isEmpty();
wizardPageVisibilityChangeRequested(visible, Installer::ComponentSelection);
wizardPageVisibilityChangeRequested(visible, Installer::LicenseCheck);
2011-02-21 16:30:31 +01:00
}
int QtUninstallerGui::nextId() const
{
const int next = QWizard::nextId();
2011-02-28 10:50:52 +01:00
if (next == Installer::LicenseCheck) {
2011-02-21 16:30:31 +01:00
const int nextNextId = pageIds().value(pageIds().indexOf(next)+ 1, -1);
if (!m_installer->isPackageManager() && !m_installer->isUpdater())
return nextNextId;
QList<Component*> components = m_installer->componentsToInstall(m_installer->runMode());
2011-02-21 16:30:31 +01:00
if (components.isEmpty())
return nextNextId;
bool foundLicense = false;
2011-02-28 10:50:52 +01:00
foreach (Component* component, components) {
2011-02-21 16:30:31 +01:00
if (component->isInstalled())
continue;
foundLicense |= !component->licenses().isEmpty();
}
return foundLicense ? next : nextNextId;
}
return next;
}