Commit 7be3909a authored by Rafael Roquetto's avatar Rafael Roquetto

Qnx: implement "Newest API level" option

The "Newest Api level" virtual option matches the most up-to-date version of
the installed APIs. If a more recent version is then afterwards installed, it
will point to it. Likewise, if the most recent version is uninstalled, it will
default to the next most up-to-date version.

Change-Id: Ic0609df92ff9108f897559e80a108e22c6bc11a0
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 542444c9
......@@ -54,7 +54,7 @@ BlackBerryCertificate::BlackBerryCertificate(const QString &fileName,
{
m_process->setProcessChannelMode(QProcess::MergedChannels);
m_process->setEnvironment(Utils::EnvironmentItem::toStringList(
BlackBerryConfigurationManager::instance().defaultApiLevelEnv()));
BlackBerryConfigurationManager::instance().defaultConfigurationEnv()));
}
void BlackBerryCertificate::load()
......
......@@ -66,7 +66,8 @@ 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");
const QLatin1String DefaultConfigurationKey("DefaultConfiguration");
const QLatin1String NewestConfigurationValue("Newest");
const QLatin1String BBConfigsFileVersionKey("Version");
const QLatin1String BBConfigDataKey("BBConfiguration.");
const QLatin1String BBConfigCountKey("BBConfiguration.Count");
......@@ -85,7 +86,7 @@ static bool sortConfigurationsByVersion(const BlackBerryConfiguration *a, const
BlackBerryConfigurationManager::BlackBerryConfigurationManager(QObject *parent)
: QObject(parent),
m_defaultApiLevel(0)
m_defaultConfiguration(0)
{
m_writer = new Utils::PersistentSettingsWriter(bbConfigSettingsFileName(),
QLatin1String("BlackBerryConfigurations"));
......@@ -108,6 +109,13 @@ void BlackBerryConfigurationManager::saveConfigurations()
}
data.insert(QLatin1String(BBConfigCountKey), count);
const QString newestConfig = (newestConfigurationEnabled())
? NewestConfigurationValue : defaultConfiguration()->ndkEnvFile().toString();
//save default configuration
data.insert(QLatin1String(DefaultConfigurationKey), newestConfig);
m_writer->save(data, Core::ICore::mainWindow());
}
......@@ -118,14 +126,29 @@ void BlackBerryConfigurationManager::restoreConfigurations()
return;
QVariantMap data = reader.restoreValues();
// load default configuration
const QString ndkEnvFile = data.value(DefaultConfigurationKey).toString();
// use newest API level
const bool useNewestConfiguration = (ndkEnvFile == NewestConfigurationValue);
int count = data.value(BBConfigCountKey, 0).toInt();
for (int i = 0; i < count; ++i) {
const QString key = BBConfigDataKey + QString::number(i);
if (!data.contains(key))
continue;
const QVariantMap dMap = data.value(key).toMap();
insertByVersion(new BlackBerryConfiguration(dMap));
BlackBerryConfiguration *config = new BlackBerryConfiguration(dMap);
insertByVersion(config);
if (!useNewestConfiguration && (config->ndkEnvFile().toString() == ndkEnvFile))
setDefaultConfiguration(config);
}
}
......@@ -161,36 +184,6 @@ 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()
{
foreach (const NdkInstallInformation &ndkInfo, QnxUtils::installedNdks()) {
......@@ -202,27 +195,21 @@ void BlackBerryConfigurationManager::loadAutoDetectedConfigurations()
}
}
void BlackBerryConfigurationManager::setDefaultApiLevel(BlackBerryConfiguration *config)
void BlackBerryConfigurationManager::setDefaultConfiguration(BlackBerryConfiguration *config)
{
if (config && !m_configs.contains(config)) {
qWarning() << "BlackBerryConfigurationManager::setDefaultApiLevel -"
qWarning() << "BlackBerryConfigurationManager::setDefaultConfiguration -"
" configuration does not belong to this instance: "
<< config->ndkEnvFile().toString();
return;
}
m_defaultApiLevel = config;
m_defaultConfiguration = config;
}
void BlackBerryConfigurationManager::saveDefaultApiLevel()
bool BlackBerryConfigurationManager::newestConfigurationEnabled() const
{
if (!m_defaultApiLevel)
return;
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->setValue(DefaultApiLevelKey, m_defaultApiLevel->ndkEnvFile().toString());
settings->endGroup();
return !m_defaultConfiguration;
}
void BlackBerryConfigurationManager::setKitsAutoDetectionSource()
......@@ -296,14 +283,8 @@ void BlackBerryConfigurationManager::removeConfiguration(BlackBerryConfiguration
m_configs.removeAt(m_configs.indexOf(config));
if (m_defaultApiLevel == config) {
if (m_configs.isEmpty())
setDefaultApiLevel(0);
else
setDefaultApiLevel(m_configs.first());
saveDefaultApiLevel();
}
if (defaultConfiguration() == config)
setDefaultConfiguration(0);
delete config;
}
......@@ -348,17 +329,26 @@ BlackBerryConfiguration *BlackBerryConfigurationManager::configurationFromEnvFil
return 0;
}
BlackBerryConfiguration *BlackBerryConfigurationManager::defaultApiLevel() const
BlackBerryConfiguration *BlackBerryConfigurationManager::defaultConfiguration() const
{
return m_defaultApiLevel;
if (m_configs.isEmpty())
return 0;
// !m_defaultConfiguration means use newest configuration
if (!m_defaultConfiguration)
return m_configs.first();
return m_defaultConfiguration;
}
QList<Utils::EnvironmentItem> BlackBerryConfigurationManager::defaultApiLevelEnv() const
QList<Utils::EnvironmentItem> BlackBerryConfigurationManager::defaultConfigurationEnv() const
{
if (!m_defaultApiLevel)
return QList<Utils::EnvironmentItem>();
const BlackBerryConfiguration *config = defaultConfiguration();
if (config)
return config->qnxEnv();
return m_defaultApiLevel->qnxEnv();
return QList<Utils::EnvironmentItem>();
}
void BlackBerryConfigurationManager::loadSettings()
......@@ -371,7 +361,6 @@ void BlackBerryConfigurationManager::loadSettings()
// For backward compatibility
loadManualConfigurations();
loadAutoDetectedConfigurations();
loadDefaultApiLevel();
checkToolChainConfiguration();
// If no target was/is activated, activate one since it's needed by
......@@ -385,7 +374,6 @@ void BlackBerryConfigurationManager::loadSettings()
void BlackBerryConfigurationManager::saveSettings()
{
saveConfigurations();
saveDefaultApiLevel();
}
BlackBerryConfigurationManager &BlackBerryConfigurationManager::instance()
......
......@@ -57,7 +57,7 @@ public:
QList<BlackBerryConfiguration*> manualConfigurations() const;
QList<BlackBerryConfiguration *> activeConfigurations() const;
BlackBerryConfiguration *configurationFromEnvFile(const Utils::FileName &envFile) const;
BlackBerryConfiguration *defaultApiLevel() const;
BlackBerryConfiguration *defaultConfiguration() const;
QString barsignerCskPath() const;
QString idTokenPath() const;
......@@ -67,10 +67,12 @@ public:
void clearConfigurationSettings(BlackBerryConfiguration *config);
// returns the environment for the default API level
QList<Utils::EnvironmentItem> defaultApiLevelEnv() const;
QList<Utils::EnvironmentItem> defaultConfigurationEnv() const;
void loadAutoDetectedConfigurations();
void setDefaultApiLevel(BlackBerryConfiguration *config);
void setDefaultConfiguration(BlackBerryConfiguration *config);
bool newestConfigurationEnabled() const;
public slots:
void loadSettings();
......@@ -84,10 +86,7 @@ private:
BlackBerryConfigurationManager(QObject *parent = 0);
QList<BlackBerryConfiguration*> m_configs;
BlackBerryConfiguration *m_defaultApiLevel;
void loadDefaultApiLevel();
void saveDefaultApiLevel();
BlackBerryConfiguration *m_defaultConfiguration;
Utils::PersistentSettingsWriter *m_writer;
......
......@@ -62,7 +62,7 @@ BlackBerryDeviceConnection::BlackBerryDeviceConnection() :
void BlackBerryDeviceConnection::connectDevice(const ProjectExplorer::IDevice::ConstPtr &device)
{
Utils::Environment env = Utils::Environment::systemEnvironment();
env.modify(BlackBerryConfigurationManager::instance().defaultApiLevelEnv());
env.modify(BlackBerryConfigurationManager::instance().defaultConfigurationEnv());
m_process->setEnvironment(env.toStringList());
......
......@@ -57,7 +57,7 @@ void BlackBerryDeviceListDetector::detectDeviceList()
return;
m_process->setEnvironment(Utils::EnvironmentItem::toStringList(
BlackBerryConfigurationManager::instance().defaultApiLevelEnv()));
BlackBerryConfigurationManager::instance().defaultConfigurationEnv()));
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().defaultApiLevelEnv()));
BlackBerryConfigurationManager::instance().defaultConfigurationEnv()));
connect(m_process, SIGNAL(started()), this, SIGNAL(started()));
connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)),
......@@ -60,7 +60,7 @@ const QString BlackBerryNdkProcess::resolveNdkToolPath(const QString &tool)
{
QString toolPath;
QList<Utils::EnvironmentItem> qnxEnv =
BlackBerryConfigurationManager::instance().defaultApiLevelEnv();
BlackBerryConfigurationManager::instance().defaultConfigurationEnv();
foreach (const Utils::EnvironmentItem &item, qnxEnv) {
if (item.name == QLatin1String("QNX_HOST") && !item.value.isEmpty()) {
toolPath = item.value
......
......@@ -72,7 +72,9 @@ void BlackBerryNDKSettingsPage::apply()
config->deactivate();
}
BlackBerryConfigurationManager::instance().setDefaultApiLevel(m_widget->defaultApiLevel());
BlackBerryConfigurationManager &manager = BlackBerryConfigurationManager::instance();
manager.setDefaultConfiguration(m_widget->defaultConfiguration());
}
void BlackBerryNDKSettingsPage::finish()
......
......@@ -56,11 +56,10 @@ static QIcon invalidConfigIcon(QLatin1String(":/projectexplorer/images/compile_e
BlackBerryNDKSettingsWidget::BlackBerryNDKSettingsWidget(QWidget *parent) :
QWidget(parent),
m_ui(new Ui_BlackBerryNDKSettingsWidget),
m_defaultApiLevel(0),
m_bbConfigManager(&BlackBerryConfigurationManager::instance()),
m_autoDetectedNdks(0),
m_manualNdks(0)
{
m_bbConfigManager = &BlackBerryConfigurationManager::instance();
m_ui->setupUi(this);
updateInfoTable(0);
......@@ -90,10 +89,10 @@ BlackBerryNDKSettingsWidget::BlackBerryNDKSettingsWidget(QWidget *parent) :
connect(m_ui->deactivateNdkTargetButton, SIGNAL(clicked()), this, SLOT(deactivateNdkTarget()));
connect(m_ui->cleanUpButton, SIGNAL(clicked()), this, SLOT(cleanUp()));
connect(m_ui->ndksTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(updateInfoTable(QTreeWidgetItem*)));
connect(m_ui->apiLevelCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setDefaultApiLevel(int)));
connect(this, SIGNAL(targetsUpdated()), this, SLOT(populateDefaultConfigurationCombo()));
updateNdkList();
updateDefaultApiLevel();
populateDefaultConfigurationCombo();
}
void BlackBerryNDKSettingsWidget::setWizardMessageVisible(bool visible)
......@@ -117,9 +116,12 @@ QList<BlackBerryConfiguration *> BlackBerryNDKSettingsWidget::deactivatedTargets
return m_deactivatedTargets;
}
BlackBerryConfiguration *BlackBerryNDKSettingsWidget::defaultApiLevel() const
BlackBerryConfiguration *BlackBerryNDKSettingsWidget::defaultConfiguration() const
{
return m_defaultApiLevel;
const int currentIndex = m_ui->apiLevelCombo->currentIndex();
return static_cast<BlackBerryConfiguration*>(
m_ui->apiLevelCombo->itemData(currentIndex).value<void*>());
}
void BlackBerryNDKSettingsWidget::launchBlackBerrySetupWizard() const
......@@ -235,7 +237,6 @@ void BlackBerryNDKSettingsWidget::removeNdkTarget()
m_deactivatedTargets.removeOne(config);
m_bbConfigManager->removeConfiguration(config);
m_manualNdks->removeChild(m_ui->ndksTreeWidget->currentItem());
updateDefaultApiLevel();
emit targetsUpdated();
}
}
......@@ -323,7 +324,6 @@ void BlackBerryNDKSettingsWidget::cleanUp()
void BlackBerryNDKSettingsWidget::handleInstallationFinished()
{
m_bbConfigManager->loadAutoDetectedConfigurations();
updateDefaultApiLevel();
updateNdkList();
}
......@@ -348,50 +348,36 @@ void BlackBerryNDKSettingsWidget::handleUninstallationFinished()
m_bbConfigManager->removeConfiguration(config);
updateDefaultApiLevel();
updateNdkList();
}
void BlackBerryNDKSettingsWidget::setDefaultApiLevel(int index)
void BlackBerryNDKSettingsWidget::populateDefaultConfigurationCombo()
{
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;
}
}
// prevent QComboBox::currentIndexChanged() from being emitted
m_ui->apiLevelCombo->clear();
m_defaultApiLevel = 0;
QList<BlackBerryConfiguration*> configurations = m_bbConfigManager->configurations();
qWarning("Cannot set default API level");
}
m_ui->apiLevelCombo->addItem(tr("Newest version"),
QVariant::fromValue(static_cast<void*>(0)));
void BlackBerryNDKSettingsWidget::updateDefaultApiLevel()
{
m_ui->apiLevelCombo->clear();
if (m_bbConfigManager->configurations().isEmpty())
if (configurations.isEmpty())
return;
foreach (BlackBerryConfiguration *config, m_bbConfigManager->configurations())
m_ui->apiLevelCombo->addItem(config->displayName(), config->ndkEnvFile().toString());
int configIndex = 0;
BlackBerryConfiguration *conf = m_bbConfigManager->defaultApiLevel();
BlackBerryConfiguration *defaultConfig = m_bbConfigManager->defaultConfiguration();
if (!conf) {
m_ui->apiLevelCombo->setCurrentIndex(-1);
m_defaultApiLevel = 0;
return;
foreach (BlackBerryConfiguration *config, configurations) {
m_ui->apiLevelCombo->addItem(config->displayName(),
QVariant::fromValue(static_cast<void*>(config)));
if (config == defaultConfig)
configIndex = m_ui->apiLevelCombo->count() - 1;
}
m_defaultApiLevel = conf;
const int currentIndex = (m_bbConfigManager->newestConfigurationEnabled()) ? 0 : configIndex;
const int currentIndex = m_ui->apiLevelCombo->findData(conf->ndkEnvFile().toString());
m_ui->apiLevelCombo->setCurrentIndex(currentIndex);
}
......
......@@ -61,7 +61,7 @@ public:
QList<BlackBerryConfiguration *> activatedTargets();
QList<BlackBerryConfiguration *> deactivatedTargets();
BlackBerryConfiguration *defaultApiLevel() const;
BlackBerryConfiguration *defaultConfiguration() const;
signals:
void targetsUpdated();
......@@ -79,8 +79,7 @@ public slots:
void handleInstallationFinished();
void handleUninstallationFinished();
void updateUi(QTreeWidgetItem* item, BlackBerryConfiguration* config);
void setDefaultApiLevel(int index);
void updateDefaultApiLevel();
void populateDefaultConfigurationCombo();
private:
void launchBlackBerryInstallerWizard(BlackBerryInstallerDataHandler::Mode mode,
......@@ -88,7 +87,6 @@ private:
Ui_BlackBerryNDKSettingsWidget *m_ui;
BlackBerryConfigurationManager *m_bbConfigManager;
BlackBerryConfiguration *m_defaultApiLevel;
QTreeWidgetItem *m_autoDetectedNdks;
QTreeWidgetItem *m_manualNdks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment