forked from qt-creator/qt-creator
SettingsAccessor: Shed of UserFileAccessor
So far only instantiates the .user file specific upgraders. Change-Id: I9a16dfe4c3c61093ea1231413495eec2e8fe648e Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Daniel Teske <daniel.teske@digia.com>
This commit is contained in:
@@ -91,7 +91,7 @@ public:
|
|||||||
Core::Context m_projectContext;
|
Core::Context m_projectContext;
|
||||||
Core::Context m_projectLanguages;
|
Core::Context m_projectLanguages;
|
||||||
QVariantMap m_pluginSettings;
|
QVariantMap m_pluginSettings;
|
||||||
SettingsAccessor *m_accessor;
|
Internal::UserFileAccessor *m_accessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
ProjectPrivate::ProjectPrivate() :
|
ProjectPrivate::ProjectPrivate() :
|
||||||
@@ -302,14 +302,14 @@ void Project::saveSettings()
|
|||||||
{
|
{
|
||||||
emit aboutToSaveSettings();
|
emit aboutToSaveSettings();
|
||||||
if (!d->m_accessor)
|
if (!d->m_accessor)
|
||||||
d->m_accessor = new SettingsAccessor(this);
|
d->m_accessor = new Internal::UserFileAccessor(this);
|
||||||
d->m_accessor->saveSettings(toMap());
|
d->m_accessor->saveSettings(toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::restoreSettings()
|
bool Project::restoreSettings()
|
||||||
{
|
{
|
||||||
if (!d->m_accessor)
|
if (!d->m_accessor)
|
||||||
d->m_accessor = new SettingsAccessor(this);
|
d->m_accessor = new Internal::UserFileAccessor(this);
|
||||||
QVariantMap map(d->m_accessor->restoreSettings());
|
QVariantMap map(d->m_accessor->restoreSettings());
|
||||||
bool ok = fromMap(map);
|
bool ok = fromMap(map);
|
||||||
if (ok)
|
if (ok)
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ const char SHARED_SETTINGS[] = "SharedSettings";
|
|||||||
class UserFileVersion0Upgrader : public VersionUpgrader
|
class UserFileVersion0Upgrader : public VersionUpgrader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserFileVersion0Upgrader(SettingsAccessor *a) : m_accessor(a) { }
|
UserFileVersion0Upgrader(UserFileAccessor *a) : m_accessor(a) { }
|
||||||
|
|
||||||
int version() const { return 0; }
|
int version() const { return 0; }
|
||||||
QString backupExtension() const { return QLatin1String("1.3"); }
|
QString backupExtension() const { return QLatin1String("1.3"); }
|
||||||
@@ -129,7 +129,7 @@ private:
|
|||||||
QVariantMap convertRunConfigurations(const QVariantMap &map) const;
|
QVariantMap convertRunConfigurations(const QVariantMap &map) const;
|
||||||
QVariantMap convertBuildSteps(const QVariantMap &map) const;
|
QVariantMap convertBuildSteps(const QVariantMap &map) const;
|
||||||
|
|
||||||
SettingsAccessor *m_accessor;
|
UserFileAccessor *m_accessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Version 1 is used in master post Qt Creator 1.3.x.
|
// Version 1 is used in master post Qt Creator 1.3.x.
|
||||||
@@ -138,7 +138,7 @@ private:
|
|||||||
class UserFileVersion1Upgrader : public VersionUpgrader
|
class UserFileVersion1Upgrader : public VersionUpgrader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserFileVersion1Upgrader(SettingsAccessor *a) : m_accessor(a) { }
|
UserFileVersion1Upgrader(UserFileAccessor *a) : m_accessor(a) { }
|
||||||
int version() const { return 1; }
|
int version() const { return 1; }
|
||||||
QString backupExtension() const { return QLatin1String("1.3+git"); }
|
QString backupExtension() const { return QLatin1String("1.3+git"); }
|
||||||
QVariantMap upgrade(const QVariantMap &map);
|
QVariantMap upgrade(const QVariantMap &map);
|
||||||
@@ -162,7 +162,7 @@ private:
|
|||||||
QString displayName;
|
QString displayName;
|
||||||
};
|
};
|
||||||
|
|
||||||
SettingsAccessor *m_accessor;
|
UserFileAccessor *m_accessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Version 2 is used in master post Qt Creator 2.0 alpha.
|
// Version 2 is used in master post Qt Creator 2.0 alpha.
|
||||||
@@ -255,7 +255,7 @@ public:
|
|||||||
class UserFileVersion11Upgrader : public VersionUpgrader
|
class UserFileVersion11Upgrader : public VersionUpgrader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserFileVersion11Upgrader(SettingsAccessor *a) : m_accessor(a) { }
|
UserFileVersion11Upgrader(UserFileAccessor *a) : m_accessor(a) { }
|
||||||
~UserFileVersion11Upgrader();
|
~UserFileVersion11Upgrader();
|
||||||
|
|
||||||
int version() const { return 11; }
|
int version() const { return 11; }
|
||||||
@@ -286,7 +286,7 @@ private:
|
|||||||
QHash<int, QString> m_qtVersionExtras;
|
QHash<int, QString> m_qtVersionExtras;
|
||||||
|
|
||||||
QHash<Kit *, QVariantMap> m_targets;
|
QHash<Kit *, QVariantMap> m_targets;
|
||||||
SettingsAccessor *m_accessor;
|
UserFileAccessor *m_accessor;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Version 12 reflects the move of environment settings from CMake/Qt4/Custom into
|
// Version 12 reflects the move of environment settings from CMake/Qt4/Custom into
|
||||||
@@ -378,24 +378,13 @@ static QVariantMap processHandlerNodes(const HandlerNode &node, const QVariantMa
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
// UserFileAccessor
|
// UserFileAccessor:
|
||||||
// -------------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
SettingsAccessor::SettingsAccessor(Project *project) :
|
UserFileAccessor::UserFileAccessor(Project *project)
|
||||||
m_firstVersion(-1),
|
: SettingsAccessor(project)
|
||||||
m_lastVersion(-1),
|
|
||||||
m_userFileAcessor(QLatin1String(".user"),
|
|
||||||
QString::fromLocal8Bit(qgetenv("QTC_EXTENSION")),
|
|
||||||
true,
|
|
||||||
this),
|
|
||||||
m_sharedFileAcessor(QLatin1String(".shared"),
|
|
||||||
QString::fromLocal8Bit(qgetenv("QTC_SHARED_EXTENSION")),
|
|
||||||
false,
|
|
||||||
this),
|
|
||||||
m_project(project)
|
|
||||||
{
|
{
|
||||||
QTC_CHECK(m_project);
|
// Register Upgraders:
|
||||||
|
|
||||||
addVersionUpgrader(new UserFileVersion0Upgrader(this));
|
addVersionUpgrader(new UserFileVersion0Upgrader(this));
|
||||||
addVersionUpgrader(new UserFileVersion1Upgrader(this));
|
addVersionUpgrader(new UserFileVersion1Upgrader(this));
|
||||||
addVersionUpgrader(new UserFileVersion2Upgrader);
|
addVersionUpgrader(new UserFileVersion2Upgrader);
|
||||||
@@ -413,6 +402,22 @@ SettingsAccessor::SettingsAccessor(Project *project) :
|
|||||||
addVersionUpgrader(new UserFileVersion14Upgrader);
|
addVersionUpgrader(new UserFileVersion14Upgrader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsAccessor::SettingsAccessor(Project *project) :
|
||||||
|
m_firstVersion(-1),
|
||||||
|
m_lastVersion(-1),
|
||||||
|
m_userFileAcessor(QLatin1String(".user"),
|
||||||
|
QString::fromLocal8Bit(qgetenv("QTC_EXTENSION")),
|
||||||
|
true,
|
||||||
|
this),
|
||||||
|
m_sharedFileAcessor(QLatin1String(".shared"),
|
||||||
|
QString::fromLocal8Bit(qgetenv("QTC_SHARED_EXTENSION")),
|
||||||
|
false,
|
||||||
|
this),
|
||||||
|
m_project(project)
|
||||||
|
{
|
||||||
|
QTC_CHECK(m_project);
|
||||||
|
}
|
||||||
|
|
||||||
SettingsAccessor::~SettingsAccessor()
|
SettingsAccessor::~SettingsAccessor()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_handlers);
|
qDeleteAll(m_handlers);
|
||||||
|
|||||||
@@ -46,17 +46,15 @@ class SettingsAccessor
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SettingsAccessor(Project *project);
|
SettingsAccessor(Project *project);
|
||||||
~SettingsAccessor();
|
virtual ~SettingsAccessor();
|
||||||
|
|
||||||
Project *project() const;
|
Project *project() const;
|
||||||
|
|
||||||
QVariantMap restoreSettings() const;
|
QVariantMap restoreSettings() const;
|
||||||
bool saveSettings(const QVariantMap &map) const;
|
bool saveSettings(const QVariantMap &map) const;
|
||||||
|
|
||||||
|
void addVersionUpgrader(Internal::VersionUpgrader *handler); // Takes ownership of the handler!
|
||||||
private:
|
private:
|
||||||
// Takes ownership of the handler!
|
|
||||||
void addVersionUpgrader(Internal::VersionUpgrader *handler);
|
|
||||||
|
|
||||||
QStringList findSettingsFiles(const QString &suffix) const;
|
QStringList findSettingsFiles(const QString &suffix) const;
|
||||||
static QByteArray creatorId();
|
static QByteArray creatorId();
|
||||||
QString defaultFileName(const QString &suffix) const;
|
QString defaultFileName(const QString &suffix) const;
|
||||||
@@ -123,6 +121,14 @@ private:
|
|||||||
Project *m_project;
|
Project *m_project;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
class UserFileAccessor : public SettingsAccessor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UserFileAccessor(Project *project);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace ProjectExplorer
|
} // namespace ProjectExplorer
|
||||||
|
|
||||||
#endif // SETTINGSACCESSOR_H
|
#endif // SETTINGSACCESSOR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user