diff options
author | Tim Jenssen <tim.jenssen@nokia.com> | 2011-05-16 16:27:26 +0200 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@nokia.com> | 2011-05-16 17:23:03 +0200 |
commit | c570c8612a0ffa57e0b6f991c692c6fe9097dd66 (patch) | |
tree | 6406a5594fff8081d6645ed91137cadbc4d75c13 /installerbuilder | |
parent | db0e7385a192492580be4737ceecd4e0df0abb3e (diff) |
use qtcreatorpersistentsettings in registertoolchainoperation
Diffstat (limited to 'installerbuilder')
-rw-r--r-- | installerbuilder/libinstaller/registertoolchainoperation.cpp | 197 | ||||
-rw-r--r-- | installerbuilder/libinstaller/registertoolchainoperation.h | 2 |
2 files changed, 56 insertions, 143 deletions
diff --git a/installerbuilder/libinstaller/registertoolchainoperation.cpp b/installerbuilder/libinstaller/registertoolchainoperation.cpp index 905b6d1d3..f86620222 100644 --- a/installerbuilder/libinstaller/registertoolchainoperation.cpp +++ b/installerbuilder/libinstaller/registertoolchainoperation.cpp @@ -34,6 +34,7 @@ #include "persistentsettings.h" #include "qinstaller.h" #include "qtcreator_constants.h" +#include "qtcreatorpersistentsettings.h" #include <QString> #include <QFileInfo> @@ -69,6 +70,8 @@ bool RegisterToolChainOperation::performOperation() return false; } + QString toolChainsXmlFilePath; + const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); if (!installer) { setError(UserDefinedError); @@ -76,89 +79,39 @@ bool RegisterToolChainOperation::performOperation() return false; } const QString &rootInstallPath = installer->value(QLatin1String("TargetDir")); + toolChainsXmlFilePath = rootInstallPath + QLatin1String(ToolChainSettingsSuffixPath); + + QtCreatorToolChain toolChain; int argCounter = 0; - const QString &toolChainKey = args.at(argCounter++); //Qt SDK:gccPath - const QString &toolChainType = args.at(argCounter++); //where this toolchain is defined in QtCreator - const QString &displayName = args.at(argCounter++); //nice special Toolchain (Qt SDK) - const QString &abiString = args.at(argCounter++); //x86-windows-msys-pe-32bit - const QString &compilerPath = args.at(argCounter++); //gccPath - QString debuggerPath; - QString armVersion; - QString force32Bit; + toolChain.key = args.at(argCounter++); //Qt SDK:gccPath + toolChain.type = args.at(argCounter++); //where this toolchain is defined in QtCreator + toolChain.displayName = args.at(argCounter++); //nice special Toolchain (Qt SDK) + toolChain.abiString = args.at(argCounter++); //x86-windows-msys-pe-32bit + toolChain.compilerPath = QDir::toNativeSeparators(args.at(argCounter++)); //gccPath if (args.count() > argCounter) - debuggerPath = args.at(argCounter++); + toolChain.debuggerPath = QDir::toNativeSeparators(args.at(argCounter++)); if (args.count() > argCounter) - armVersion = args.at(argCounter++); + toolChain.armVersion = args.at(argCounter++); if (args.count() > argCounter) - force32Bit = args.at(argCounter++); + toolChain.force32Bit = args.at(argCounter++); - QString toolChainsXmlFilePath; - - toolChainsXmlFilePath = rootInstallPath + QLatin1String(ToolChainSettingsSuffixPath); + QtCreatorPersistentSettings creatorToolChainSettings; - QHash< QString, QVariantMap > toolChainHash; - - PersistentSettingsReader reader; - if (reader.load(toolChainsXmlFilePath)) { - QVariantMap data = reader.restoreValues(); - - // Check version: - int version = data.value(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 0).toInt(); - if (version < 1) { - setError(UserDefinedError); - setErrorString(tr("Toolchain settings xml file %1 has not the right version.") - .arg(toolChainsXmlFilePath)); - return false; - } - - int count = data.value(QLatin1String(TOOLCHAIN_COUNT_KEY), 0).toInt(); - for (int i = 0; i < count; ++i) { - const QString key = QLatin1String(TOOLCHAIN_DATA_KEY) + QString::number(i); - - const QVariantMap toolChainMap = data.value(key).toMap(); - - //gets the path variable, hope ".Path" will stay in QtCreator - QStringList pathContainingKeyList = - QStringList(toolChainMap.keys()).filter(QLatin1String(".Path")); - foreach(const QString& pathKey, pathContainingKeyList) { - QString path = toolChainMap.value(pathKey).toString(); - if (!path.isEmpty() && QFile::exists(path)) { - toolChainHash.insert(path, toolChainMap); - } - } - } + if (!creatorToolChainSettings.init(toolChainsXmlFilePath)) { + setError(UserDefinedError); + setErrorString(tr("Can't read from tool chains xml file(%1) correctly.") + .arg(toolChainsXmlFilePath)); + return false; } - QVariantMap newToolChainVariantMap; - - newToolChainVariantMap.insert(QLatin1String(ID_KEY), - QString(QLatin1String("%1:%2.%3")).arg(toolChainType, compilerPath, abiString)); - newToolChainVariantMap.insert(QLatin1String(DISPLAY_NAME_KEY), displayName); - newToolChainVariantMap.insert(QString(QLatin1String("ProjectExplorer.%1.Path")).arg(toolChainKey), - compilerPath); - newToolChainVariantMap.insert(QString(QLatin1String("ProjectExplorer.%1.TargetAbi")).arg(toolChainKey), - abiString); - newToolChainVariantMap.insert(QString(QLatin1String("ProjectExplorer.%1.Debugger")).arg(toolChainKey), - debuggerPath); - - toolChainHash.insert(compilerPath, newToolChainVariantMap); - - PersistentSettingsWriter writer; - writer.saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1); - - int count = 0; - - foreach (const QVariantMap &toolChainMap, toolChainHash.values()) { - if (toolChainMap.isEmpty()) - continue; - writer.saveValue(QLatin1String(TOOLCHAIN_DATA_KEY) + QString::number(count++), - toolChainMap); + if (!creatorToolChainSettings.addToolChain(toolChain)) { + setError(InvalidArguments); + setErrorString(tr("Some arguments are not right in %1 operation.") + .arg(name()).arg(args.count())); + return false; } - writer.saveValue(QLatin1String(TOOLCHAIN_COUNT_KEY), count); - writer.save(toolChainsXmlFilePath, QLatin1String("QtCreatorToolChains")); - - return true; + return creatorToolChainSettings.save(); } bool RegisterToolChainOperation::undoOperation() @@ -172,88 +125,48 @@ bool RegisterToolChainOperation::undoOperation() return false; } - const Installer* const installer = qVariantValue< Installer* >( value( QLatin1String( "installer" ) ) ); - const QString &rootInstallPath = installer->value(QLatin1String("TargetDir")); - if (rootInstallPath.isEmpty() || !QDir(rootInstallPath).exists()) { + QString toolChainsXmlFilePath; + + const Installer* const installer = qVariantValue<Installer*>(value(QLatin1String("installer"))); + if (!installer) { setError(UserDefinedError); - setErrorString(tr("The given TargetDir %1 is not a valid/existing dir.").arg(rootInstallPath)); + setErrorString(tr("Needed installer object in \"%1\" operation is empty.").arg(name())); return false; } + const QString &rootInstallPath = installer->value(QLatin1String("TargetDir")); + toolChainsXmlFilePath = rootInstallPath + QLatin1String(ToolChainSettingsSuffixPath); + + QtCreatorToolChain toolChain; int argCounter = 0; - const QString &toolChainKey = args.at(argCounter++); //Qt SDK:gccPath - Q_UNUSED(toolChainKey) - const QString &toolChainType = args.at(argCounter++); //where this toolchain is defined in QtCreator - const QString &displayName = args.at(argCounter++); //nice special Toolchain (Qt SDK) - Q_UNUSED(displayName) - const QString &abiString = args.at(argCounter++); //x86-windows-msys-pe-32bit - const QString &compilerPath = args.at(argCounter++); //gccPath - QString debuggerPath; - QString armVersion; - QString force32Bit; + toolChain.key = args.at(argCounter++); //Qt SDK:gccPath + toolChain.type = args.at(argCounter++); //where this toolchain is defined in QtCreator + toolChain.displayName = args.at(argCounter++); //nice special Toolchain (Qt SDK) + toolChain.abiString = args.at(argCounter++); //x86-windows-msys-pe-32bit + toolChain.compilerPath = QDir::toNativeSeparators(args.at(argCounter++)); //gccPath if (args.count() > argCounter) - debuggerPath = args.at(argCounter++); + toolChain.debuggerPath = QDir::toNativeSeparators(args.at(argCounter++)); if (args.count() > argCounter) - armVersion = args.at(argCounter++); + toolChain.armVersion = args.at(argCounter++); if (args.count() > argCounter) - force32Bit = args.at(argCounter++); - - const QString uniqueToolChainKey = - QString(QLatin1String("%1:%2.%3")).arg(toolChainType, compilerPath, abiString); - QString toolChainsXmlFilePath; - - toolChainsXmlFilePath = rootInstallPath + QLatin1String(ToolChainSettingsSuffixPath); + toolChain.force32Bit = args.at(argCounter++); - QHash< QString, QVariantMap > toolChainHash; + QtCreatorPersistentSettings creatorToolChainSettings; - PersistentSettingsReader reader; - if (reader.load(toolChainsXmlFilePath)) { - QVariantMap data = reader.restoreValues(); - - // Check version: - int version = data.value(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 0).toInt(); - if (version < 1) { - setError(UserDefinedError); - setErrorString(tr("Toolchain settings xml file %1 has not the right version.") - .arg(toolChainsXmlFilePath)); - return false; - } - - int count = data.value(QLatin1String(TOOLCHAIN_COUNT_KEY), 0).toInt(); - for (int i = 0; i < count; ++i) { - const QString key = QLatin1String(TOOLCHAIN_DATA_KEY) + QString::number(i); - - const QVariantMap toolChainMap = data.value(key).toMap(); - - //gets the path variable, hope ".Path" will stay in QtCreator - QStringList pathContainingKeyList = - QStringList(toolChainMap.keys()).filter(QLatin1String(".Path")); - foreach (const QString& pathKey, pathContainingKeyList) { - QString path = toolChainMap.value(pathKey).toString(); - QString currentUniqueToolChainKey = toolChainMap.value(QLatin1String(ID_KEY)).toString(); - Q_ASSERT(!currentUniqueToolChainKey.isEmpty()); - if (!path.isEmpty() && QFile::exists(path) - && uniqueToolChainKey != currentUniqueToolChainKey) { - toolChainHash.insert(path, toolChainMap); - } - } - } + if (!creatorToolChainSettings.init(toolChainsXmlFilePath)) { + setError(UserDefinedError); + setErrorString(tr("Can't read from tool chains xml file(%1) correctly.") + .arg(toolChainsXmlFilePath)); + return false; } - PersistentSettingsWriter writer; - writer.saveValue(QLatin1String(TOOLCHAIN_FILE_VERSION_KEY), 1); - - int count = 0; - - foreach (const QVariantMap &toolChainMap, toolChainHash.values()) { - if (toolChainMap.isEmpty()) - continue; - writer.saveValue(QLatin1String(TOOLCHAIN_DATA_KEY) + QString::number(count++), - toolChainMap); + if (!creatorToolChainSettings.removeToolChain(toolChain)) { + setError(InvalidArguments); + setErrorString(tr("Some arguments are not right in %1 operation.") + .arg(name()).arg(args.count())); + return false; } - writer.saveValue(QLatin1String(TOOLCHAIN_COUNT_KEY), count); - writer.save(toolChainsXmlFilePath, QLatin1String("QtCreatorToolChains")); - return true; + return creatorToolChainSettings.save(); } bool RegisterToolChainOperation::testOperation() diff --git a/installerbuilder/libinstaller/registertoolchainoperation.h b/installerbuilder/libinstaller/registertoolchainoperation.h index 4fce9bc7a..29d773f4e 100644 --- a/installerbuilder/libinstaller/registertoolchainoperation.h +++ b/installerbuilder/libinstaller/registertoolchainoperation.h @@ -60,6 +60,6 @@ public: KDUpdater::UpdateOperation* clone() const; }; -}; // namespace +} // namespace #endif // REGISTERTOOLCHAINOPERATION_H |