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
|
|
|
|
2014-02-27 12:47:13 +01:00
|
|
|
class SettingsAccessorPrivate;
|
|
|
|
|
|
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);
|
2014-02-25 17:49:57 +01:00
|
|
|
virtual ~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
|
|
|
|
2014-02-27 12:02:02 +01:00
|
|
|
QVariantMap restoreSettings(QWidget *parent) const;
|
2014-02-25 18:10:42 +01:00
|
|
|
bool saveSettings(const QVariantMap &data, QWidget *parent) const;
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2014-02-27 14:15:03 +01:00
|
|
|
static QVariantMap setVersionInMap(const QVariantMap &data, int version);
|
|
|
|
|
static int versionFromMap(const QVariantMap &data);
|
|
|
|
|
static int originalVersionFromMap(const QVariantMap &data);
|
|
|
|
|
static QVariantMap setOriginalVersionInMap(const QVariantMap &data, int version);
|
|
|
|
|
|
2014-02-25 17:49:57 +01:00
|
|
|
void addVersionUpgrader(Internal::VersionUpgrader *handler); // Takes ownership of the handler!
|
2010-01-19 16:59:18 +01:00
|
|
|
private:
|
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:
|
2014-02-27 14:15:03 +01:00
|
|
|
SettingsData() {}
|
|
|
|
|
SettingsData(const QVariantMap &map) : m_map(map) {}
|
2011-09-15 11:32:15 +02:00
|
|
|
|
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
|
|
|
Utils::FileName fileName() const { return m_fileName; }
|
2011-10-04 14:54:24 +02:00
|
|
|
|
2013-04-04 12:56:03 +02:00
|
|
|
QByteArray m_environmentId;
|
2011-09-15 11:32:15 +02:00
|
|
|
QVariantMap m_map;
|
2012-08-20 18:52:20 +02:00
|
|
|
Utils::FileName m_fileName;
|
2011-09-15 11:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
2014-02-27 11:46:07 +01:00
|
|
|
void upgradeSettings(SettingsData &data, int toVersion) const;
|
2013-04-04 16:19:17 +02:00
|
|
|
|
2014-02-27 12:02:02 +01:00
|
|
|
SettingsData readUserSettings(QWidget *parent) const;
|
|
|
|
|
SettingsData readSharedSettings(QWidget *parent) 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
|
|
|
|
2014-02-26 17:30:46 +01:00
|
|
|
bool readFile(SettingsData *settings, bool environmentSpecific) const;
|
|
|
|
|
bool writeFile(const SettingsData *settings, QWidget *parent) const;
|
2011-09-15 11:32:15 +02:00
|
|
|
|
2010-01-19 16:59:18 +01:00
|
|
|
int m_firstVersion;
|
|
|
|
|
int m_lastVersion;
|
2014-02-26 17:30:46 +01:00
|
|
|
QString m_userSuffix;
|
|
|
|
|
QString m_sharedSuffix;
|
2012-08-17 13:18:31 +02:00
|
|
|
|
|
|
|
|
Project *m_project;
|
2014-02-27 12:47:13 +01:00
|
|
|
|
|
|
|
|
SettingsAccessorPrivate *d;
|
|
|
|
|
|
|
|
|
|
friend class SettingsAccessorPrivate;
|
2010-01-19 16:59:18 +01:00
|
|
|
};
|
|
|
|
|
|
2014-02-25 17:49:57 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
class UserFileAccessor : public SettingsAccessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
UserFileAccessor(Project *project);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2010-01-19 16:59:18 +01:00
|
|
|
} // namespace ProjectExplorer
|
|
|
|
|
|
2013-03-12 12:13:07 +01:00
|
|
|
#endif // SETTINGSACCESSOR_H
|