forked from qt-creator/qt-creator
Move settings from Nokia to QtProject
Store settings in QtProject, not Nokia. Move them over to the new place if any settings in Nokia exist. Task-number: QTCREATOR-7976 Change-Id: I5af77923aa51016add9079b21e78d94d46f20010 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
committed by
Eike Ziller
parent
da2ae22036
commit
f0629b6b77
@@ -63,9 +63,16 @@ const char * const IDE_REVISION_STR = \"\";
|
||||
#ifdef IDE_SETTINGSVARIANT
|
||||
const char * const IDE_SETTINGSVARIANT_STR = STRINGIFY(IDE_SETTINGSVARIANT);
|
||||
#else
|
||||
const char * const IDE_SETTINGSVARIANT_STR = \"Nokia\";
|
||||
const char * const IDE_SETTINGSVARIANT_STR = \"QtProject\";
|
||||
#endif
|
||||
|
||||
#ifdef IDE_COPY_SETTINGS_FROM_VARIANT
|
||||
const char * const IDE_COPY_SETTINGS_FROM_VARIANT_STR = STRINGIFY(IDE_COPY_SETTINGS_FROM_VARIANT);
|
||||
#else
|
||||
const char * const IDE_COPY_SETTINGS_FROM_VARIANT_STR = \"Nokia\";
|
||||
#endif
|
||||
|
||||
|
||||
#undef IDE_VERSION
|
||||
#undef IDE_VERSION_STR
|
||||
#undef STRINGIFY
|
||||
|
||||
@@ -160,6 +160,33 @@ static inline int askMsgSendFailed()
|
||||
QMessageBox::Retry);
|
||||
}
|
||||
|
||||
// taken from utils/fileutils.cpp. We can not use utils here since that depends app_version.h.
|
||||
static bool copyRecursively(const QString &srcFilePath,
|
||||
const QString &tgtFilePath)
|
||||
{
|
||||
QFileInfo srcFileInfo(srcFilePath);
|
||||
if (srcFileInfo.isDir()) {
|
||||
QDir targetDir(tgtFilePath);
|
||||
targetDir.cdUp();
|
||||
if (!targetDir.mkdir(QFileInfo(tgtFilePath).fileName()))
|
||||
return false;
|
||||
QDir sourceDir(srcFilePath);
|
||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
const QString newSrcFilePath
|
||||
= srcFilePath + QLatin1Char('/') + fileName;
|
||||
const QString newTgtFilePath
|
||||
= tgtFilePath + QLatin1Char('/') + fileName;
|
||||
if (!copyRecursively(newSrcFilePath, newTgtFilePath))
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!QFile::copy(srcFilePath, tgtFilePath))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline QStringList getPluginPaths()
|
||||
{
|
||||
QStringList rc;
|
||||
@@ -200,6 +227,55 @@ static inline QStringList getPluginPaths()
|
||||
return rc;
|
||||
}
|
||||
|
||||
static QSettings *createUserSettings()
|
||||
{
|
||||
return new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
|
||||
QLatin1String("QtCreator"));
|
||||
}
|
||||
|
||||
static inline QSettings *userSettings()
|
||||
{
|
||||
QSettings *settings = createUserSettings();
|
||||
const QString fromVariant = QLatin1String(Core::Constants::IDE_COPY_SETTINGS_FROM_VARIANT_STR);
|
||||
if (fromVariant.isEmpty())
|
||||
return settings;
|
||||
|
||||
// Copy old settings to new ones:
|
||||
QFileInfo pathFi = QFileInfo(settings->fileName());
|
||||
if (pathFi.exists()) // already copied.
|
||||
return settings;
|
||||
|
||||
QDir destDir = pathFi.absolutePath();
|
||||
if (!destDir.exists())
|
||||
destDir.mkpath(pathFi.absolutePath());
|
||||
|
||||
QDir srcDir = destDir;
|
||||
srcDir.cdUp();
|
||||
if (!srcDir.cd(fromVariant))
|
||||
return settings;
|
||||
|
||||
if (srcDir == destDir) // Nothing to copy and no settings yet
|
||||
return settings;
|
||||
|
||||
QStringList entries = srcDir.entryList();
|
||||
foreach (const QString &file, entries) {
|
||||
const QString lowerFile = file.toLower();
|
||||
if (lowerFile.startsWith(QLatin1String("profiles.xml"))
|
||||
|| lowerFile.startsWith(QLatin1String("toolchains.xml"))
|
||||
|| lowerFile.startsWith(QLatin1String("qtversion.xml"))
|
||||
|| lowerFile.startsWith(QLatin1String("devices.xml"))
|
||||
|| lowerFile.startsWith(QLatin1String("qtcreator.")))
|
||||
QFile::copy(srcDir.absoluteFilePath(file), destDir.absoluteFilePath(file));
|
||||
if (file == QLatin1String("qtcreator"))
|
||||
copyRecursively(srcDir.absoluteFilePath(file), destDir.absoluteFilePath(file));
|
||||
}
|
||||
|
||||
// Make sure to use the copied settings:
|
||||
delete settings;
|
||||
return createUserSettings();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define SHARE_PATH "/../Resources"
|
||||
#else
|
||||
@@ -255,9 +331,8 @@ int main(int argc, char **argv)
|
||||
QCoreApplication::applicationDirPath() + QLatin1String(SHARE_PATH));
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
// plugin manager takes control of this settings object
|
||||
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
|
||||
QLatin1String("QtCreator"));
|
||||
QSettings *settings = userSettings();
|
||||
|
||||
QSettings *globalSettings = new QSettings(QSettings::IniFormat, QSettings::SystemScope,
|
||||
QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR),
|
||||
QLatin1String("QtCreator"));
|
||||
|
||||
Reference in New Issue
Block a user