Commit 59a578d4 authored by El Mehdi Fekari's avatar El Mehdi Fekari Committed by Mehdi Fekari

Qnx: Install/uninstall NDK targets

Basic implementation of an install/uninstall targets utility.

Note: This does not support 10.1 NKDs.

Change-Id: I3bb29ef467dd24a121ee59e11abb2237dcff696a
Reviewed-by: Nicolas Arnaud-Cormos's avatarNicolas Arnaud-Cormos <nicolas@kdab.com>
parent 668a50b7
......@@ -65,6 +65,8 @@ public:
QMultiMap<QString, QString> defaultQnxEnv();
void loadAutoDetectedConfigurations();
public slots:
void loadSettings();
void saveSettings();
......@@ -78,7 +80,6 @@ private:
QList<BlackBerryConfiguration*> m_configs;
void loadManualConfigurations();
void loadAutoDetectedConfigurations();
void saveManualConfigurations();
void saveActiveConfigurationNdkEnvPath();
void clearInvalidConfigurations();
......
/**************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved
**
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "blackberryinstallwizard.h"
#include "blackberryinstallwizardpages.h"
#include <QAbstractButton>
#include <QMessageBox>
using namespace Qnx;
using namespace Qnx::Internal;
BlackBerryInstallWizard::BlackBerryInstallWizard(BlackBerryInstallerDataHandler::Mode mode,
const QString& version,
QWidget *parent)
: QWizard(parent)
, m_ndkPage(0)
, m_targetPage(0)
{
setWindowTitle(tr("BlackBerry NDK Installation Wizard"));
m_data.mode = mode;
m_data.version = version;
if (m_data.mode != BlackBerryInstallerDataHandler::UninstallMode) {
m_optionPage = new BlackBerryInstallWizardOptionPage(m_data, this);
m_ndkPage = new BlackBerryInstallWizardNdkPage(m_data, this);
m_targetPage = new BlackBerryInstallWizardTargetPage(m_data, this);
setPage(OptionPage, m_optionPage);
setPage(NdkPageId, m_ndkPage);
setPage(TargetPageId, m_targetPage);
}
m_processPage = new BlackBerryInstallWizardProcessPage(m_data, this);
m_finalPage = new BlackBerryInstallWizardFinalPage(m_data, this);
connect(m_finalPage, SIGNAL(done()), this, SIGNAL(processFinished()));
disconnect(button(CancelButton), SIGNAL(clicked()), this, SLOT(reject()));
connect(button(CancelButton), SIGNAL(clicked()), this, SLOT(handleProcessCancelled()));
setPage(ProcessPageId, m_processPage);
setPage(FinalPageId, m_finalPage);
m_finalPage->setCommitPage(true);
setOption(DisabledBackButtonOnLastPage, true);
}
void BlackBerryInstallWizard::handleProcessCancelled()
{
if ((m_targetPage && m_targetPage->isProcessRunning())
|| m_processPage->isProcessRunning()) {
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Confirmation"),
tr("Are you sure you want to cancel?"),
QMessageBox::Yes | QMessageBox::No);
if (answer == QMessageBox::No)
return;
}
reject();
}
/**************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved
**
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BLACKBERRYDEVICECONFIGURATIONWIZARD_H
#define QNX_INTERNAL_BLACKBERRYDEVICECONFIGURATIONWIZARD_H
#include <QProcess>
#include <QWizard>
namespace Qnx {
namespace Internal {
class BlackBerryInstallWizardOptionPage;
class BlackBerryInstallWizardNdkPage;
class BlackBerryInstallWizardTargetPage;
class BlackBerryInstallWizardProcessPage;
class BlackBerryInstallWizardFinalPage;
class BlackBerryInstallerDataHandler {
public:
enum Mode {
InstallMode,
UninstallMode,
ManuallMode
};
QString ndkPath;
QString target;
QString version;
int exitCode;
QProcess::ExitStatus exitStatus;
Mode mode;
};
class BlackBerryInstallWizard : public QWizard
{
Q_OBJECT
public:
enum PageId {
OptionPage,
NdkPageId,
TargetPageId,
ProcessPageId,
FinalPageId
};
explicit BlackBerryInstallWizard(BlackBerryInstallerDataHandler::Mode mode = BlackBerryInstallerDataHandler::InstallMode,
const QString& version = QString(),
QWidget *parent = 0);
signals:
void processFinished();
private slots:
void handleProcessCancelled();
private:
BlackBerryInstallWizardOptionPage *m_optionPage;
BlackBerryInstallWizardNdkPage *m_ndkPage;
BlackBerryInstallWizardTargetPage *m_targetPage;
BlackBerryInstallWizardProcessPage *m_processPage;
BlackBerryInstallWizardFinalPage *m_finalPage;
BlackBerryInstallerDataHandler m_data;
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYDEVICECONFIGURATIONWIZARD_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BlackBerryInstallWizardNdkPage</class>
<widget class="QWidget" name="Qnx::Internal::BlackBerryInstallWizardNdkPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Select NDK Path</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="ndkPathListWidget"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
This diff is collapsed.
/**************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved
**
** Contact: BlackBerry (qt@blackberry.com)
** Contact: KDAB (info@kdab.com)
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, 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, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QNX_INTERNAL_BLACKBERRYINSTALLWIZARDPAGES_H
#define QNX_INTERNAL_BLACKBERRYINSTALLWIZARDPAGES_H
#include <QWizardPage>
#include <QListWidgetItem>
#include "blackberryinstallwizard.h"
#include <utils/pathchooser.h>
QT_BEGIN_NAMESPACE
class QProcess;
class QRadioButton;
class QVBoxLayout;
QT_END_NAMESPACE
namespace Qnx {
namespace Internal {
class Ui_BlackBerryInstallWizardNdkPage;
class Ui_BlackBerryInstallWizardTargetPage;
class Ui_BlackBerryInstallWizardProcessPage;
class NdkPathChooser : public Utils::PathChooser
{
Q_OBJECT
public:
enum Mode {
InstallMode, // Select a valid 10.2 NDK path
ManualMode // Select a target bbnk-env file path
};
NdkPathChooser(Mode mode, QWidget *parent = 0);
virtual bool validatePath(const QString &path, QString *errorMessage);
private:
Mode m_mode;
};
class BlackBerryInstallWizardOptionPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryInstallWizardOptionPage(BlackBerryInstallerDataHandler &data, QWidget *parent = 0);
void initializePage();
bool isComplete() const;
int nextId() const;
protected slots:
void handleOptionChanged();
void handlePathChanged(const QString &envFilePath);
signals:
void installModeChanged();
private:
QVBoxLayout *m_layout;
QRadioButton* m_installButton;
QRadioButton* m_addButton;
NdkPathChooser* m_envFileChooser;
BlackBerryInstallerDataHandler &m_data;
};
class BlackBerryInstallWizardNdkPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryInstallWizardNdkPage(BlackBerryInstallerDataHandler &data, QWidget *parent = 0);
~BlackBerryInstallWizardNdkPage();
void initializePage();
bool isComplete() const;
protected slots:
void setNdkPath();
void setManualNdkPath();
private:
Ui_BlackBerryInstallWizardNdkPage *m_ui;
BlackBerryInstallerDataHandler &m_data;
NdkPathChooser* m_ndkPathChooser;
QListWidgetItem* m_manual;
bool m_validNdkPath;
};
class BlackBerryInstallWizardTargetPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryInstallWizardTargetPage(BlackBerryInstallerDataHandler &data, QWidget *parent = 0);
~BlackBerryInstallWizardTargetPage();
void initializePage();
bool isComplete() const;
bool isProcessRunning() const;
protected slots:
void targetsListProcessFinished();
void setTarget();
private:
BlackBerryInstallerDataHandler &m_data;
Ui_BlackBerryInstallWizardTargetPage *m_ui;
bool m_isTargetValid;
QProcess *m_targetListProcess;
void initTargetsTreeWidget();
void updateAvailableTargetsList();
};
class BlackBerryInstallWizardProcessPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryInstallWizardProcessPage(BlackBerryInstallerDataHandler &data,
QWidget *parent = 0);
~BlackBerryInstallWizardProcessPage();
void initializePage();
bool isComplete() const;
bool isProcessRunning() const;
protected slots:
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
private:
Ui_BlackBerryInstallWizardProcessPage *m_ui;
BlackBerryInstallerDataHandler &m_data;
QProcess *m_targetProcess;
void processTarget();
};
class BlackBerryInstallWizardFinalPage : public QWizardPage
{
Q_OBJECT
public:
explicit BlackBerryInstallWizardFinalPage(BlackBerryInstallerDataHandler &data, QWidget *parent = 0);
void initializePage();
signals:
void done();
private:
BlackBerryInstallerDataHandler &m_data;
};
} // namespace Internal
} // namespace Qnx
#endif // QNX_INTERNAL_BLACKBERRYINSTALLWIZARDPAGES_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BlackBerryInstallWizardProcessPage</class>
<widget class="QWidget" name="Qnx::Internal::BlackBerryInstallWizardProcessPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please wait...</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Qnx::Internal::BlackBerryInstallWizardTargetPage</class>
<widget class="QWidget" name="Qnx::Internal::BlackBerryInstallWizardTargetPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>543</width>
<height>373</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please select target:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="targetsTreeWidget">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -60,13 +60,28 @@ BlackBerryNDKSettingsWidget::BlackBerryNDKSettingsWidget(QWidget *parent) :
m_bbConfigManager = &BlackBerryConfigurationManager::instance();
m_ui->setupUi(this);
m_ui->removeNdkButton->setEnabled(false);
m_ui->activateNdkTargetButton->setEnabled(false);
m_ui->deactivateNdkTargetButton->setEnabled(false);
m_activatedTargets << m_bbConfigManager->activeConfigurations();
initNdkList();
m_ui->ndksTreeWidget->header()->setResizeMode(QHeaderView::Stretch);
m_ui->ndksTreeWidget->header()->setStretchLastSection(false);
m_ui->ndksTreeWidget->setHeaderItem(new QTreeWidgetItem(QStringList() << tr("NDK") << tr("NDK Environment File")));
m_ui->ndksTreeWidget->setTextElideMode(Qt::ElideNone);
m_ui->ndksTreeWidget->setColumnCount(2);
m_autoDetectedNdks = new QTreeWidgetItem(m_ui->ndksTreeWidget);
m_autoDetectedNdks->setText(0, tr("Auto-Detected"));
m_autoDetectedNdks->setFirstColumnSpanned(true);
m_autoDetectedNdks->setFlags(Qt::ItemIsEnabled);
m_manualNdks = new QTreeWidgetItem(m_ui->ndksTreeWidget);
m_manualNdks->setText(0, tr("Manual"));
m_manualNdks->setFirstColumnSpanned(true);
m_manualNdks->setFlags(Qt::ItemIsEnabled);
m_ui->ndksTreeWidget->expandAll();
updateNdkList();
connect(m_ui->wizardButton, SIGNAL(clicked()), this, SLOT(launchBlackBerrySetupWizard()));
connect(m_ui->addNdkButton, SIGNAL(clicked()), this, SLOT(addNdkTarget()));
......@@ -146,13 +161,16 @@ void BlackBerryNDKSettingsWidget::updateInfoTable(QTreeWidgetItem* currentItem)
void BlackBerryNDKSettingsWidget::updateNdkList()
{
qDeleteAll(m_autoDetectedNdks->takeChildren());
qDeleteAll(m_manualNdks->takeChildren());
foreach (BlackBerryConfiguration *config, m_bbConfigManager->configurations()) {
QTreeWidgetItem *parent = config->isAutoDetected() ? m_autoDetectedNdks : m_manualNdks;
QTreeWidgetItem *item = new QTreeWidgetItem(parent);
item->setText(0, config->displayName());
item->setText(1, config->ndkEnvFile().toString());
QFont font;
font.setBold(config->isActive());
font.setBold(config->isActive() || m_activatedTargets.contains(config));
item->setFont(0, font);
item->setFont(1, font);
}
......@@ -165,25 +183,7 @@ void BlackBerryNDKSettingsWidget::updateNdkList()
void BlackBerryNDKSettingsWidget::addNdkTarget()
{
QString selectedPath = QFileDialog::getOpenFileName(0, tr("Select the NDK Environment file"),
QString(), tr("BlackBerry Environment File (*.sh *.bat)"));
if (selectedPath.isEmpty() || !QFileInfo(selectedPath).exists())
return;
BlackBerryConfiguration *config = m_bbConfigManager->configurationFromEnvFile(Utils::FileName::fromString(selectedPath));
if (!config) {
config = new BlackBerryConfiguration(Utils::FileName::fromString(selectedPath), false);
if (!m_bbConfigManager->addConfiguration(config)) {
delete config;
return;
}
QTreeWidgetItem *item = new QTreeWidgetItem(m_manualNdks);
item->setText(0, selectedPath.split(QDir::separator()).last());
item->setText(1, selectedPath);
updateInfoTable(item);
}
launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::InstallMode);
}
void BlackBerryNDKSettingsWidget::removeNdkTarget()
......@@ -193,6 +193,16 @@ void BlackBerryNDKSettingsWidget::removeNdkTarget()
QString ndk = m_ui->ndksTreeWidget->currentItem()->text(0);
QString envFilePath = m_ui->ndksTreeWidget->currentItem()->text(1);
BlackBerryConfiguration *config = m_bbConfigManager->configurationFromEnvFile(Utils::FileName::fromString(envFilePath));
if (!config)
return;
if (config->isAutoDetected()) {
uninstallNdkTarget();
return;
}
QMessageBox::StandardButton button =
QMessageBox::question(Core::ICore::mainWindow(),
tr("Clean BlackBerry 10 Configuration"),
......@@ -200,11 +210,8 @@ void BlackBerryNDKSettingsWidget::removeNdkTarget()
QMessageBox::Yes | QMessageBox::No);
if (button == QMessageBox::Yes) {
BlackBerryConfiguration *config = m_bbConfigManager->configurationFromEnvFile(Utils::FileName::fromString(envFilePath));
if (config) {
m_bbConfigManager->removeConfiguration(config);
m_manualNdks->removeChild(m_ui->ndksTreeWidget->currentItem());
}
m_bbConfigManager->removeConfiguration(config);
m_manualNdks->removeChild(m_ui->ndksTreeWidget->currentItem());
}
}
......@@ -255,30 +262,62 @@ void BlackBerryNDKSettingsWidget::updateUi(QTreeWidgetItem *item, BlackBerryConf
m_ui->deactivateNdkTargetButton->setEnabled((m_activatedTargets.contains(config))
&& m_activatedTargets.size() > 1
&& config->isAutoDetected());
m_ui->removeNdkButton->setEnabled(!config->isAutoDetected());
m_ui->removeNdkButton->setEnabled(true);
}
void BlackBerryNDKSettingsWidget::initNdkList()
void BlackBerryNDKSettingsWidget::uninstallNdkTarget()
{
m_ui->ndksTreeWidget->header()->setResizeMode(QHeaderView::Stretch);
m_ui->ndksTreeWidget->header()->setStretchLastSection(false);
m_ui->ndksTreeWidget->setHeaderItem(new QTreeWidgetItem(QStringList() << tr("NDK") << tr("NDK Environment File")));
m_ui->ndksTreeWidget->setTextElideMode(Qt::ElideNone);
m_ui->ndksTreeWidget->setColumnCount(2);
m_autoDetectedNdks = new QTreeWidgetItem(m_ui->ndksTreeWidget);
m_autoDetectedNdks->setText(0, tr("Auto-Detected"));
m_autoDetectedNdks->setFirstColumnSpanned(true);
m_autoDetectedNdks->setFlags(Qt::ItemIsEnabled);
m_manualNdks = new QTreeWidgetItem(m_ui->ndksTreeWidget);
m_manualNdks->setText(0, tr("Manual"));
m_manualNdks->setFirstColumnSpanned(true);
m_manualNdks->setFlags(Qt::ItemIsEnabled);
const QMessageBox::StandardButton answer = QMessageBox::question(this, tr("Confirmation"),
tr("Are you sure you want to uninstall %1?").
arg(m_ui->baseNameLabel->text()),
QMessageBox::Yes | QMessageBox::No);
m_ui->ndksTreeWidget->expandAll();
if (answer == QMessageBox::Yes)
launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::UninstallMode, m_ui->versionLabel->text());
}
void BlackBerryNDKSettingsWidget::handleInstallationFinished()
{
m_bbConfigManager->loadAutoDetectedConfigurations();
updateNdkList();
}
void BlackBerryNDKSettingsWidget::handleUninstallationFinished()
{
if (!m_ui->ndksTreeWidget->currentItem())
return;
QString targetName = m_ui->ndksTreeWidget->currentItem()->text(0);
QString envFilePath = m_ui->ndksTreeWidget->currentItem()->text(1);
// Check if the target is corrrecly uninstalled
foreach (const NdkInstallInformation &ndk, QnxUtils::installedNdks()) {
if (ndk.name == targetName)
return;
}
BlackBerryConfiguration *config = m_bbConfigManager->configurationFromEnvFile(Utils::FileName::fromString(envFilePath));
if (m_activatedTargets.contains(config))
m_activatedTargets.removeAt(m_activatedTargets.indexOf(config));
else if (m_deactivatedTargets.contains(config))
m_deactivatedTargets.removeAt(m_deactivatedTargets.indexOf(config));
m_bbConfigManager->removeConfiguration(config);
updateNdkList();
}
void BlackBerryNDKSettingsWidget::launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::Mode mode,
const QString& targetVersion)
{
BlackBerryInstallWizard wizard(mode, targetVersion, this);
if (mode == BlackBerryInstallerDataHandler::InstallMode)
connect(&wizard, SIGNAL(processFinished()), this, SLOT(handleInstallationFinished()));
else
connect(&wizard, SIGNAL(processFinished()), this, SLOT(handleUninstallationFinished()));
wizard.exec();
}
} // namespace Internal