From 5810335f554fdce83d3c91634b664c0a2d8574e9 Mon Sep 17 00:00:00 2001 From: dt Date: Thu, 12 May 2011 11:53:58 +0200 Subject: [PATCH] QtVersion: Add support code for the sdk --- src/plugins/qt4projectmanager/baseqtversion.cpp | 5 + src/plugins/qt4projectmanager/baseqtversion.h | 1 + src/plugins/qt4projectmanager/qtoptionspage.cpp | 1 + src/plugins/qt4projectmanager/qtversionmanager.cpp | 146 ++++++++++++++++++++- 4 files changed, 151 insertions(+), 2 deletions(-) diff --git a/src/plugins/qt4projectmanager/baseqtversion.cpp b/src/plugins/qt4projectmanager/baseqtversion.cpp index af0203550d..e2e83df962 100644 --- a/src/plugins/qt4projectmanager/baseqtversion.cpp +++ b/src/plugins/qt4projectmanager/baseqtversion.cpp @@ -332,6 +332,11 @@ QString BaseQtVersion::autodetectionSource() const return m_autodetectionSource; } +void BaseQtVersion::setAutoDetectionSource(const QString &autodetectionSource) +{ + m_autodetectionSource = autodetectionSource; +} + QString BaseQtVersion::displayName() const { return m_displayName; diff --git a/src/plugins/qt4projectmanager/baseqtversion.h b/src/plugins/qt4projectmanager/baseqtversion.h index 9314b81cfb..60c9f9a49e 100644 --- a/src/plugins/qt4projectmanager/baseqtversion.h +++ b/src/plugins/qt4projectmanager/baseqtversion.h @@ -202,6 +202,7 @@ protected: void ensureMkSpecParsed() const; virtual void parseMkSpec(ProFileEvaluator *) const; private: + void setAutoDetectionSource(const QString &autodetectionSource); static int getUniqueId(); void ctor(const QString &qmakePath); void updateSourcePath() const; diff --git a/src/plugins/qt4projectmanager/qtoptionspage.cpp b/src/plugins/qt4projectmanager/qtoptionspage.cpp index 3faaa4e17b..6de04de535 100644 --- a/src/plugins/qt4projectmanager/qtoptionspage.cpp +++ b/src/plugins/qt4projectmanager/qtoptionspage.cpp @@ -732,6 +732,7 @@ void QtOptionsPageWidget::updateWidgets() m_configurationWidget = version->createConfigurationWidget(); if (m_configurationWidget) { m_versionUi->formLayout->addRow(m_configurationWidget); + m_configurationWidget->setEnabled(!version->isAutodetected()); connect(m_configurationWidget, SIGNAL(changed()), this, SLOT(qtVersionChanged())); } diff --git a/src/plugins/qt4projectmanager/qtversionmanager.cpp b/src/plugins/qt4projectmanager/qtversionmanager.cpp index 18b1dc08b2..669ad7381e 100644 --- a/src/plugins/qt4projectmanager/qtversionmanager.cpp +++ b/src/plugins/qt4projectmanager/qtversionmanager.cpp @@ -73,6 +73,10 @@ using ProjectExplorer::DebuggingHelperLibrary; static const char QTVERSION_DATA_KEY[] = "QtVersion."; static const char QTVERSION_TYPE_KEY[] = "QtVersion.Type"; static const char QTVERSION_COUNT_KEY[] = "QtVersion.Count"; +static const char OLDQTVERSION_COUNT_KEY[] = "QtVersion.Old.Count"; +static const char OLDQTVERSION_DATA_KEY[] = "QtVersion.Old."; +static const char OLDQTVERSION_SDKSOURCE[] = "QtVersion.Old.SdkSource"; +static const char OLDQTVERSION_PATH[] = "QtVersion.Old.Path"; static const char QTVERSION_FILE_VERSION_KEY[] = "Version"; static const char QTVERSION_FILENAME[] = "/qtversion.xml"; @@ -202,8 +206,146 @@ bool QtVersionManager::restoreQtVersions() void QtVersionManager::updateFromInstaller() { - // TODO implement for the sdk - return; + bool debug = true; + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + QList factories = pm->getObjects(); + ProjectExplorer::PersistentSettingsReader reader; + if (!reader.load(Core::ICore::instance()->resourcePath() + + QLatin1String("/Nokia") + QLatin1String(QTVERSION_FILENAME))) + return; + + QVariantMap data = reader.restoreValues(); + + if (debug) { + qDebug()<< "======= Existing qt versions ======="; + foreach (BaseQtVersion *version, m_versions) { + qDebug() << version->qmakeCommand() << "id:"<uniqueId(); + qDebug() << " autodetection source:"<< version->autodetectionSource(); + qDebug() << ""; + } + } + + int oldcount = data.value(QLatin1String(OLDQTVERSION_COUNT_KEY), 0).toInt(); + for (int i=0; i < oldcount; ++i) { + const QString key = QString::fromLatin1(OLDQTVERSION_DATA_KEY) +QString::number(i); + if (!data.contains(key)) + break; + QVariantMap map = data.value(key).toMap(); + QString path = map.value(OLDQTVERSION_PATH).toString(); +#ifdef Q_OS_WIN + path = path.toLower(); +#endif + QString autodetectionSource = map.value(OLDQTVERSION_SDKSOURCE).toString(); + foreach (BaseQtVersion *v, m_versions) { + if (v->qmakeCommand() == path) { + if (v->autodetectionSource().isEmpty()) { + v->setAutoDetectionSource(autodetectionSource); + } else { + if (debug) + qDebug() << "## Conflicting autodetictonSource for"<autodetectionSource(); + } + // No break, we want to mark all qt versions matching that path + // There's no way for us to decide whether this qt was added + // by the user or by the installer, so we treat them all as coming + // from the installer. Thus removing/updating them deletes/updates them all + // Note: This only applies to versions that are marked via QtVersion.Old + } + } + } + + if (debug) { + qDebug()<< "======= After using OLD QtVersion data to mark versions ======="; + foreach (BaseQtVersion *version, m_versions) { + qDebug() << version->qmakeCommand() << "id:"<uniqueId(); + qDebug() << " autodetection source:"<< version->autodetectionSource(); + qDebug() << ""; + } + + qDebug()<< "======= Adding sdk versions ======="; + } + QStringList sdkVersions; + int count = data.value(QLatin1String(QTVERSION_COUNT_KEY), 0).toInt(); + for (int i = 0; i < count; ++i) { + const QString key = QString::fromLatin1(QTVERSION_DATA_KEY) + QString::number(i); + if (!data.contains(key)) + break; + + QVariantMap qtversionMap = data.value(key).toMap(); + const QString type = qtversionMap.value(QTVERSION_TYPE_KEY).toString(); + const QString autoDetectionSource = qtversionMap.value(QLatin1String("autodetectionSource")).toString(); + sdkVersions << autoDetectionSource; + int id = -1; // see BaseQtVersion::fromMap() + QtVersionFactory *factory = 0; + foreach (QtVersionFactory *f, factories) { + if (f->canRestore(type)) { + factory = f; + } + } + if (!factory) { + if (debug) + qDebug("Warning: Unable to find factory for type '%s'", qPrintable(type)); + continue; + } + // First try to find a existing qt version to update + bool restored = false; + foreach (BaseQtVersion *v, m_versions) { + if (v->autodetectionSource() == autoDetectionSource) { + id = v->uniqueId(); + if (debug) + qDebug() << " Qt version found with same autodetection source" << autoDetectionSource << " => Migrating id:" << id; + removeVersion(v); + qtversionMap[QLatin1String("Id")] = id; + + if (BaseQtVersion *qtv = factory->restore(qtversionMap)) { + Q_ASSERT(qtv->isAutodetected()); + addVersion(qtv); + restored = true; + } + } + } + // Create a new qtversion + if (!restored) { // didn't replace any existing versions + if (debug) + qDebug() << " No Qt version found matching" << autoDetectionSource << " => Creating new version"; + if (BaseQtVersion *qtv = factory->restore(qtversionMap)) { + Q_ASSERT(qtv->isAutodetected()); + addVersion(qtv); + restored = true; + } + } + if (!restored) + if (debug) + qDebug("Warning: Unable to update qtversion '%s' from sdk installer.", + qPrintable(autoDetectionSource)); + } + + if (debug) { + qDebug() << "======= Before removing outdated sdk versions ======="; + foreach (BaseQtVersion *version, m_versions) { + qDebug() << version->qmakeCommand() << "id:"<uniqueId(); + qDebug() << " autodetection source:"<< version->autodetectionSource(); + qDebug() << ""; + } + } + foreach (BaseQtVersion *qtVersion, QtVersionManager::instance()->versions()) { + if (qtVersion->autodetectionSource().startsWith("SDK.")) { + if (!sdkVersions.contains(qtVersion->autodetectionSource())) { + if (debug) + qDebug() << " removing version"<autodetectionSource(); + removeVersion(qtVersion); + } + } + } + + if (debug) { + qDebug()<< "======= End result ======="; + foreach (BaseQtVersion *version, m_versions) { + qDebug() << version->qmakeCommand() << "id:"<uniqueId(); + qDebug() << " autodetection source:"<< version->autodetectionSource(); + qDebug() << ""; + } + } } void QtVersionManager::saveQtVersions() -- 2.11.0