Commit c72546fb authored by Rafael Roquetto's avatar Rafael Roquetto

BlackBerry: Enable selection of default API level

Task-number: QTCREATORBUG-11009

Change-Id: If11343a26134238854e64a0cf88ea91973615e69
Reviewed-by: default avatarDavid Kaspar <dkaspar@blackberry.com>
Reviewed-by: default avatarMehdi Fekari <mfekari@blackberry.com>
Reviewed-by: Nicolas Arnaud-Cormos's avatarNicolas Arnaud-Cormos <nicolas@kdab.com>
parent 5fb2f2d6
......@@ -54,7 +54,7 @@ BlackBerryCertificate::BlackBerryCertificate(const QString &fileName,
{
m_process->setProcessChannelMode(QProcess::MergedChannels);
m_process->setEnvironment(Utils::EnvironmentItem::toStringList(
BlackBerryConfigurationManager::instance().defaultQnxEnv()));
BlackBerryConfigurationManager::instance().defaultApiLevelEnv()));
}
void BlackBerryCertificate::load()
......
......@@ -53,6 +53,7 @@
#include <QMessageBox>
#include <QFileInfo>
#include <QDebug>
using namespace ProjectExplorer;
......@@ -65,6 +66,7 @@ const QLatin1String NDKLocationKey("NDKLocation"); // For 10.1 NDK support (< QT
const QLatin1String NDKEnvFileKey("NDKEnvFile");
const QLatin1String ManualNDKsGroup("ManualNDKs");
const QLatin1String ActiveNDKsGroup("ActiveNDKs");
const QLatin1String DefaultApiLevelKey("DefaultApiLevel");
}
static bool sortConfigurationsByVersion(const BlackBerryConfiguration *a, const BlackBerryConfiguration *b)
......@@ -73,7 +75,8 @@ static bool sortConfigurationsByVersion(const BlackBerryConfiguration *a, const
}
BlackBerryConfigurationManager::BlackBerryConfigurationManager(QObject *parent)
:QObject(parent)
: QObject(parent),
m_defaultApiLevel(0)
{
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
}
......@@ -107,6 +110,36 @@ void BlackBerryConfigurationManager::loadManualConfigurations()
settings->endGroup();
}
void BlackBerryConfigurationManager::loadDefaultApiLevel()
{
if (m_configs.isEmpty())
return;
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
const QString ndkEnvFile = settings->value(DefaultApiLevelKey).toString();
BlackBerryConfiguration *defaultApiLevel = 0;
// now check whether there is a cached value available to override it
foreach (BlackBerryConfiguration *config, m_configs) {
if (config->ndkEnvFile().toString() == ndkEnvFile) {
defaultApiLevel = config;
break;
}
}
if (defaultApiLevel)
setDefaultApiLevel(defaultApiLevel);
else
setDefaultApiLevel(m_configs.first());
settings->endGroup();
}
void BlackBerryConfigurationManager::loadAutoDetectedConfigurations()
{
QStringList activePaths = activeConfigurationNdkEnvPaths();
......@@ -130,6 +163,18 @@ void BlackBerryConfigurationManager::loadAutoDetectedConfigurations()
m_configs.first()->activate();
}
void BlackBerryConfigurationManager::setDefaultApiLevel(BlackBerryConfiguration *config)
{
if (config && !m_configs.contains(config)) {
qWarning() << "BlackBerryConfigurationManager::setDefaultApiLevel -"
" configuration does not belong to this instance: "
<< config->ndkEnvFile().toString();
return;
}
m_defaultApiLevel = config;
}
QStringList BlackBerryConfigurationManager::activeConfigurationNdkEnvPaths()
{
QStringList actives;
......@@ -169,6 +214,17 @@ void BlackBerryConfigurationManager::saveManualConfigurations()
settings->endGroup();
}
void BlackBerryConfigurationManager::saveDefaultApiLevel()
{
if (!m_defaultApiLevel)
return;
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->setValue(DefaultApiLevelKey, m_defaultApiLevel->ndkEnvFile().toString());
settings->endGroup();
}
void BlackBerryConfigurationManager::saveActiveConfigurationNdkEnvPath()
{
if (activeConfigurations().isEmpty())
......@@ -282,6 +338,16 @@ void BlackBerryConfigurationManager::removeConfiguration(BlackBerryConfiguration
clearConfigurationSettings(config);
m_configs.removeAt(m_configs.indexOf(config));
if (m_defaultApiLevel == config) {
if (m_configs.isEmpty())
setDefaultApiLevel(0);
else
setDefaultApiLevel(m_configs.first());
saveDefaultApiLevel();
}
delete config;
}
......@@ -325,16 +391,17 @@ BlackBerryConfiguration *BlackBerryConfigurationManager::configurationFromEnvFil
return 0;
}
// Returns a valid qnxEnv from a valid configuration;
// Needed by other classes to get blackberry process path (keys registration, debug token...)
QList<Utils::EnvironmentItem> BlackBerryConfigurationManager::defaultQnxEnv()
BlackBerryConfiguration *BlackBerryConfigurationManager::defaultApiLevel() const
{
foreach (BlackBerryConfiguration *config, m_configs) {
if (config->isActive() && config->qnxEnv().size())
return config->qnxEnv();
}
return m_defaultApiLevel;
}
QList<Utils::EnvironmentItem> BlackBerryConfigurationManager::defaultApiLevelEnv() const
{
if (!m_defaultApiLevel)
return QList<Utils::EnvironmentItem>();
return QList<Utils::EnvironmentItem>();
return m_defaultApiLevel->qnxEnv();
}
void BlackBerryConfigurationManager::loadSettings()
......@@ -345,6 +412,7 @@ void BlackBerryConfigurationManager::loadSettings()
clearInvalidConfigurations();
loadAutoDetectedConfigurations();
loadManualConfigurations();
loadDefaultApiLevel();
checkToolChainConfiguration();
emit settingsLoaded();
......@@ -374,6 +442,7 @@ void BlackBerryConfigurationManager::saveSettings()
{
saveActiveConfigurationNdkEnvPath();
saveManualConfigurations();
saveDefaultApiLevel();
}
BlackBerryConfigurationManager &BlackBerryConfigurationManager::instance()
......
......@@ -55,6 +55,7 @@ public:
QList<BlackBerryConfiguration*> manualConfigurations() const;
QList<BlackBerryConfiguration *> activeConfigurations() const;
BlackBerryConfiguration *configurationFromEnvFile(const Utils::FileName &envFile) const;
BlackBerryConfiguration *defaultApiLevel() const;
QString barsignerCskPath() const;
QString idTokenPath() const;
......@@ -63,9 +64,11 @@ public:
QString defaultDebugTokenPath() const;
void clearConfigurationSettings(BlackBerryConfiguration *config);
QList<Utils::EnvironmentItem> defaultQnxEnv();
// returns the environment for the default API level
QList<Utils::EnvironmentItem> defaultApiLevelEnv() const;
void loadAutoDetectedConfigurations();
void setDefaultApiLevel(BlackBerryConfiguration *config);
public slots:
void loadSettings();
......@@ -79,9 +82,12 @@ private:
BlackBerryConfigurationManager(QObject *parent = 0);
static BlackBerryConfigurationManager *m_instance;
QList<BlackBerryConfiguration*> m_configs;
BlackBerryConfiguration *m_defaultApiLevel;
void loadManualConfigurations();
void loadDefaultApiLevel();
void saveManualConfigurations();
void saveDefaultApiLevel();
void saveActiveConfigurationNdkEnvPath();
void clearInvalidConfigurations();
void setKitsAutoDetectionSource();
......
......@@ -62,7 +62,7 @@ BlackBerryDeviceConnection::BlackBerryDeviceConnection() :
void BlackBerryDeviceConnection::connectDevice(const ProjectExplorer::IDevice::ConstPtr &device)
{
Utils::Environment env = Utils::Environment::systemEnvironment();
env.modify(BlackBerryConfigurationManager::instance().defaultQnxEnv());
env.modify(BlackBerryConfigurationManager::instance().defaultApiLevelEnv());
m_process->setEnvironment(env.toStringList());
......
......@@ -57,7 +57,7 @@ void BlackBerryDeviceListDetector::detectDeviceList()
return;
m_process->setEnvironment(Utils::EnvironmentItem::toStringList(
BlackBerryConfigurationManager::instance().defaultQnxEnv()));
BlackBerryConfigurationManager::instance().defaultApiLevelEnv()));
const QString command = BlackBerryNdkProcess::resolveNdkToolPath(QLatin1String("blackberry-deploy"));
QStringList arguments;
arguments << QLatin1String("-devices");
......
......@@ -47,7 +47,7 @@ BlackBerryNdkProcess::BlackBerryNdkProcess(const QString &command, QObject *pare
{
m_process->setProcessChannelMode(QProcess::MergedChannels);
m_process->setEnvironment(Utils::EnvironmentItem::toStringList(
BlackBerryConfigurationManager::instance().defaultQnxEnv()));
BlackBerryConfigurationManager::instance().defaultApiLevelEnv()));
connect(m_process, SIGNAL(started()), this, SIGNAL(started()));
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
......@@ -59,7 +59,8 @@ BlackBerryNdkProcess::BlackBerryNdkProcess(const QString &command, QObject *pare
const QString BlackBerryNdkProcess::resolveNdkToolPath(const QString &tool)
{
QString toolPath;
QList<Utils::EnvironmentItem> qnxEnv = BlackBerryConfigurationManager::instance().defaultQnxEnv();
QList<Utils::EnvironmentItem> qnxEnv =
BlackBerryConfigurationManager::instance().defaultApiLevelEnv();
foreach (const Utils::EnvironmentItem &item, qnxEnv) {
if (item.name == QLatin1String("QNX_HOST") && !item.value.isEmpty()) {
toolPath = item.value
......
......@@ -31,6 +31,7 @@
#include "blackberryndksettingspage.h"
#include "blackberryndksettingswidget.h"
#include "blackberryconfigurationmanager.h"
#include "blackberryconfiguration.h"
#include "qnxconstants.h"
......@@ -70,6 +71,8 @@ void BlackBerryNDKSettingsPage::apply()
if (config->isActive())
config->deactivate();
}
BlackBerryConfigurationManager::instance().setDefaultApiLevel(m_widget->defaultApiLevel());
}
void BlackBerryNDKSettingsPage::finish()
......
......@@ -54,6 +54,7 @@ namespace Internal {
BlackBerryNDKSettingsWidget::BlackBerryNDKSettingsWidget(QWidget *parent) :
QWidget(parent),
m_ui(new Ui_BlackBerryNDKSettingsWidget),
m_defaultApiLevel(0),
m_autoDetectedNdks(0),
m_manualNdks(0)
{
......@@ -86,8 +87,10 @@ BlackBerryNDKSettingsWidget::BlackBerryNDKSettingsWidget(QWidget *parent) :
connect(m_ui->activateNdkTargetButton, SIGNAL(clicked()), this, SLOT(activateNdkTarget()));
connect(m_ui->deactivateNdkTargetButton, SIGNAL(clicked()), this, SLOT(deactivateNdkTarget()));
connect(m_ui->ndksTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(updateInfoTable(QTreeWidgetItem*)));
connect(m_ui->apiLevelCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setDefaultApiLevel(int)));
updateNdkList();
updateDefaultApiLevel();
}
void BlackBerryNDKSettingsWidget::setWizardMessageVisible(bool visible)
......@@ -111,6 +114,11 @@ QList<BlackBerryConfiguration *> BlackBerryNDKSettingsWidget::deactivatedTargets
return m_deactivatedTargets;
}
BlackBerryConfiguration *BlackBerryNDKSettingsWidget::defaultApiLevel() const
{
return m_defaultApiLevel;
}
void BlackBerryNDKSettingsWidget::launchBlackBerrySetupWizard() const
{
BlackBerrySigningUtils &blackBerryUtils = BlackBerrySigningUtils::instance();
......@@ -196,6 +204,7 @@ void BlackBerryNDKSettingsWidget::removeNdkTarget()
m_deactivatedTargets.removeOne(config);
m_bbConfigManager->removeConfiguration(config);
m_manualNdks->removeChild(m_ui->ndksTreeWidget->currentItem());
updateDefaultApiLevel();
emit targetsUpdated();
}
}
......@@ -270,6 +279,7 @@ void BlackBerryNDKSettingsWidget::uninstallNdkTarget()
void BlackBerryNDKSettingsWidget::handleInstallationFinished()
{
m_bbConfigManager->loadAutoDetectedConfigurations();
updateDefaultApiLevel();
updateNdkList();
}
......@@ -294,9 +304,53 @@ void BlackBerryNDKSettingsWidget::handleUninstallationFinished()
m_bbConfigManager->removeConfiguration(config);
updateDefaultApiLevel();
updateNdkList();
}
void BlackBerryNDKSettingsWidget::setDefaultApiLevel(int index)
{
if (index < 0)
return;
const QString ndkEnvFile = m_ui->apiLevelCombo->itemData(index).toString();
foreach (BlackBerryConfiguration *config, m_bbConfigManager->configurations()) {
if (config->ndkEnvFile().toString() == ndkEnvFile) {
m_defaultApiLevel = config;
return;
}
}
m_defaultApiLevel = 0;
qWarning("Cannot set default API level");
}
void BlackBerryNDKSettingsWidget::updateDefaultApiLevel()
{
m_ui->apiLevelCombo->clear();
if (m_bbConfigManager->configurations().isEmpty())
return;
foreach (BlackBerryConfiguration *config, m_bbConfigManager->configurations())
m_ui->apiLevelCombo->addItem(config->displayName(), config->ndkEnvFile().toString());
BlackBerryConfiguration *conf = m_bbConfigManager->defaultApiLevel();
if (!conf) {
m_ui->apiLevelCombo->setCurrentIndex(-1);
m_defaultApiLevel = 0;
return;
}
m_defaultApiLevel = conf;
const int currentIndex = m_ui->apiLevelCombo->findData(conf->ndkEnvFile().toString());
m_ui->apiLevelCombo->setCurrentIndex(currentIndex);
}
void BlackBerryNDKSettingsWidget::launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::Mode mode,
const QString& targetVersion)
{
......
......@@ -61,6 +61,8 @@ public:
QList<BlackBerryConfiguration *> activatedTargets();
QList<BlackBerryConfiguration *> deactivatedTargets();
BlackBerryConfiguration *defaultApiLevel() const;
signals:
void targetsUpdated();
......@@ -76,6 +78,8 @@ public slots:
void handleInstallationFinished();
void handleUninstallationFinished();
void updateUi(QTreeWidgetItem* item, BlackBerryConfiguration* config);
void setDefaultApiLevel(int index);
void updateDefaultApiLevel();
private:
void launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::Mode mode,
......@@ -83,6 +87,7 @@ private:
Ui_BlackBerryNDKSettingsWidget *m_ui;
BlackBerryConfigurationManager *m_bbConfigManager;
BlackBerryConfiguration *m_defaultApiLevel;
QTreeWidgetItem *m_autoDetectedNdks;
QTreeWidgetItem *m_manualNdks;
......
......@@ -147,152 +147,172 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTreeWidget" name="ndksTreeWidget">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QGroupBox" name="informationBox">
<property name="title">
<string>API Level Information</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="2" column="1">
<widget class="QLabel" name="versionLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="hostLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="baseNameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Host:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Target:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="targetLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default API level:</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addNdkButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeNdkButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="activateNdkTargetButton">
<property name="text">
<string>Activate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deactivateNdkTargetButton">
<property name="text">
<string>Deactivate</string>
</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 class="QComboBox" name="apiLevelCombo"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="ndksTreeWidget">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item row="1" column="1" rowspan="2">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="addNdkButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeNdkButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="activateNdkTargetButton">
<property name="text">
<string>Activate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deactivateNdkTargetButton">
<property name="text">
<string>Deactivate</string>
</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>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="informationBox">
<property name="title">
<string>API Level Information</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="2" column="1">
<widget class="QLabel" name="versionLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="hostLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="baseNameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Host:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Target:</string>
</property>
</widget>
</item>
<item row="4" column="1">