2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2013-03-12 12:13:07 +01:00
|
|
|
#ifndef SETTINGSACCESSOR_H
|
|
|
|
|
#define SETTINGSACCESSOR_H
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2012-08-20 18:52:20 +02:00
|
|
|
#include <utils/fileutils.h>
|
2013-03-25 17:13:18 +01:00
|
|
|
|
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
|
|
namespace Utils { class PersistentSettingsWriter; }
|
2011-09-15 11:32:15 +02:00
|
|
|
|
2010-01-19 16:59:18 +01:00
|
|
|
namespace ProjectExplorer {
|
|
|
|
|
|
|
|
|
|
class Project;
|
|
|
|
|
|
2014-02-20 17:00:19 +01:00
|
|
|
namespace Internal { class VersionUpgrader; }
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2011-09-15 11:32:15 +02:00
|
|
|
class SettingsAccessor
|
2010-01-19 16:59:18 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2012-08-17 13:18:31 +02:00
|
|
|
SettingsAccessor(Project *project);
|
2011-09-15 11:32:15 +02:00
|
|
|
~SettingsAccessor();
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2012-08-17 13:18:31 +02:00
|
|
|
Project *project() const;
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2012-08-17 13:18:31 +02:00
|
|
|
QVariantMap restoreSettings() const;
|
|
|
|
|
bool saveSettings(const QVariantMap &map) const;
|
2010-01-19 16:59:18 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Takes ownership of the handler!
|
2014-02-20 17:00:19 +01:00
|
|
|
void addVersionUpgrader(Internal::VersionUpgrader *handler);
|
2013-04-04 16:19:17 +02:00
|
|
|
|
2013-04-04 14:51:21 +02:00
|
|
|
QStringList findSettingsFiles(const QString &suffix) const;
|
2013-05-07 13:28:02 +02:00
|
|
|
static QByteArray creatorId();
|
2013-04-04 14:51:21 +02:00
|
|
|
QString defaultFileName(const QString &suffix) const;
|
|
|
|
|
int currentVersion() const;
|
2013-04-04 16:21:04 +02:00
|
|
|
void backupUserFile() const;
|
2011-09-15 11:32:15 +02:00
|
|
|
|
|
|
|
|
// The relevant data from the settings currently in use.
|
|
|
|
|
class SettingsData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SettingsData() : m_version(-1), m_usingBackup(false) {}
|
|
|
|
|
SettingsData(const QVariantMap &map) : m_version(-1), m_usingBackup(false), m_map(map) {}
|
|
|
|
|
|
2011-10-04 14:54:24 +02:00
|
|
|
void clear();
|
|
|
|
|
bool isValid() const;
|
2013-04-04 12:56:03 +02:00
|
|
|
QByteArray environmentId() const { return m_environmentId; }
|
2013-04-04 14:51:21 +02:00
|
|
|
int version() const { return m_version; }
|
|
|
|
|
Utils::FileName fileName() const { return m_fileName; }
|
2011-10-04 14:54:24 +02:00
|
|
|
|
2011-09-15 11:32:15 +02:00
|
|
|
int m_version;
|
2013-04-04 12:56:03 +02:00
|
|
|
QByteArray m_environmentId;
|
2011-09-15 11:32:15 +02:00
|
|
|
bool m_usingBackup;
|
|
|
|
|
QVariantMap m_map;
|
2012-08-20 18:52:20 +02:00
|
|
|
Utils::FileName m_fileName;
|
2011-09-15 11:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
2013-04-04 16:19:17 +02:00
|
|
|
void incrementVersion(SettingsData &data) const;
|
|
|
|
|
|
2013-04-04 13:30:16 +02:00
|
|
|
SettingsData readUserSettings() const;
|
2013-04-04 16:19:17 +02:00
|
|
|
SettingsData readSharedSettings() const;
|
2013-04-04 14:51:21 +02:00
|
|
|
SettingsData findBestSettings(const QStringList &candidates) const;
|
2013-04-04 16:19:17 +02:00
|
|
|
SettingsData mergeSettings(const SettingsData &user, const SettingsData &shared) const;
|
2013-04-04 13:30:16 +02:00
|
|
|
|
2011-09-15 11:32:15 +02:00
|
|
|
// The entity which actually reads/writes to the settings file.
|
|
|
|
|
class FileAccessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2013-04-04 16:22:11 +02:00
|
|
|
FileAccessor(const QString &defaultSuffix,
|
2011-09-15 11:32:15 +02:00
|
|
|
const QString &environmentSuffix,
|
2011-09-15 15:44:49 +02:00
|
|
|
bool envSpecific,
|
2012-08-17 13:18:31 +02:00
|
|
|
SettingsAccessor *accessor);
|
|
|
|
|
~FileAccessor();
|
|
|
|
|
|
|
|
|
|
bool readFile(SettingsData *settings) const;
|
|
|
|
|
bool writeFile(const SettingsData *settings) const;
|
2011-09-15 11:32:15 +02:00
|
|
|
|
2012-08-17 13:18:31 +02:00
|
|
|
QString suffix() const { return m_suffix; }
|
2011-09-15 11:32:15 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void assignSuffix(const QString &defaultSuffix, const QString &environmentSuffix);
|
|
|
|
|
|
|
|
|
|
QString m_suffix;
|
|
|
|
|
bool m_environmentSpecific;
|
2012-08-17 13:18:31 +02:00
|
|
|
SettingsAccessor *m_accessor;
|
|
|
|
|
mutable Utils::PersistentSettingsWriter *m_writer;
|
2011-09-15 11:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
2014-02-20 17:00:19 +01:00
|
|
|
QMap<int, Internal::VersionUpgrader *> m_handlers;
|
2010-01-19 16:59:18 +01:00
|
|
|
int m_firstVersion;
|
|
|
|
|
int m_lastVersion;
|
2011-09-15 11:32:15 +02:00
|
|
|
const FileAccessor m_userFileAcessor;
|
2011-09-15 15:44:49 +02:00
|
|
|
const FileAccessor m_sharedFileAcessor;
|
2012-08-17 13:18:31 +02:00
|
|
|
|
|
|
|
|
Project *m_project;
|
2010-01-19 16:59:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
2013-03-12 12:13:07 +01:00
|
|
|
#endif // SETTINGSACCESSOR_H
|