2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-19 16:59:18 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-01-19 16:59:18 +01:00
|
|
|
|
2016-02-02 18:26:51 +01:00
|
|
|
#pragma once
|
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
|
|
|
|
2014-05-12 15:19:13 +02:00
|
|
|
#include <QHash>
|
2013-03-25 17:13:18 +01:00
|
|
|
#include <QVariantMap>
|
2014-03-03 18:57:42 +01:00
|
|
|
#include <QMessageBox>
|
2013-03-25 17:13:18 +01:00
|
|
|
|
|
|
|
|
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:
|
2016-02-02 18:26:51 +01:00
|
|
|
explicit 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-28 18:32:09 +01:00
|
|
|
int currentVersion() const;
|
|
|
|
|
int firstSupportedVersion() const;
|
|
|
|
|
|
|
|
|
|
bool addVersionUpgrader(Internal::VersionUpgrader *upgrader); // takes ownership of upgrader
|
2014-02-28 16:13:34 +01:00
|
|
|
|
2014-03-03 18:57:42 +01:00
|
|
|
enum ProceedInfo { Continue, DiscardAndContinue };
|
2014-05-12 16:13:55 +02:00
|
|
|
typedef QHash<QMessageBox::StandardButton, ProceedInfo> ButtonMap;
|
2014-03-03 18:57:42 +01:00
|
|
|
class IssueInfo {
|
|
|
|
|
public:
|
|
|
|
|
IssueInfo() : defaultButton(QMessageBox::NoButton), escapeButton(QMessageBox::NoButton) { }
|
|
|
|
|
IssueInfo(const QString &t, const QString &m,
|
|
|
|
|
QMessageBox::StandardButton d = QMessageBox::NoButton,
|
|
|
|
|
QMessageBox::StandardButton e = QMessageBox::NoButton,
|
2014-05-12 16:13:55 +02:00
|
|
|
const ButtonMap &b = ButtonMap()) :
|
2014-03-03 18:57:42 +01:00
|
|
|
title(t), message(m), defaultButton(d), escapeButton(e), buttons(b)
|
|
|
|
|
{ }
|
|
|
|
|
IssueInfo(const IssueInfo &other) :
|
|
|
|
|
title(other.title),
|
|
|
|
|
message(other.message),
|
|
|
|
|
defaultButton(other.defaultButton),
|
|
|
|
|
escapeButton(other.escapeButton),
|
|
|
|
|
buttons(other.buttons)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
IssueInfo &operator = (const IssueInfo &other)
|
|
|
|
|
{
|
|
|
|
|
title = other.title;
|
|
|
|
|
message = other.message;
|
|
|
|
|
defaultButton = other.defaultButton;
|
|
|
|
|
escapeButton = other.escapeButton;
|
|
|
|
|
buttons = other.buttons;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString title;
|
|
|
|
|
QString message;
|
|
|
|
|
QMessageBox::StandardButton defaultButton;
|
|
|
|
|
QMessageBox::StandardButton escapeButton;
|
|
|
|
|
QHash<QMessageBox::StandardButton, ProceedInfo> buttons;
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-28 16:13:34 +01:00
|
|
|
protected:
|
|
|
|
|
QVariantMap readFile(const Utils::FileName &path) const;
|
2014-09-02 06:26:13 +03:00
|
|
|
QVariantMap upgradeSettings(const QVariantMap &data) const;
|
2014-03-03 18:57:42 +01:00
|
|
|
|
|
|
|
|
ProceedInfo reportIssues(const QVariantMap &data, const Utils::FileName &path, QWidget *parent) const;
|
|
|
|
|
|
2014-02-28 16:28:36 +01:00
|
|
|
virtual QVariantMap prepareSettings(const QVariantMap &data) const;
|
2014-03-04 12:39:35 +01:00
|
|
|
virtual QVariantMap prepareToSaveSettings(const QVariantMap &data) const;
|
2014-02-28 16:13:34 +01:00
|
|
|
|
2014-03-03 16:05:08 +01:00
|
|
|
virtual bool isBetterMatch(const QVariantMap &origData, const QVariantMap &newData) const;
|
|
|
|
|
|
2014-06-30 12:12:29 +02:00
|
|
|
virtual Utils::FileName backupName(const QVariantMap &data) const;
|
|
|
|
|
|
2014-03-03 18:57:42 +01:00
|
|
|
virtual IssueInfo findIssues(const QVariantMap &data, const Utils::FileName &path) const;
|
|
|
|
|
|
2010-01-19 16:59:18 +01:00
|
|
|
private:
|
2015-11-03 14:01:25 +01:00
|
|
|
Utils::FileNameList settingsFiles(const QString &suffix) const;
|
2017-11-15 12:38:44 +01:00
|
|
|
QByteArray settingsId() const;
|
2013-04-04 14:51:21 +02:00
|
|
|
QString defaultFileName(const QString &suffix) const;
|
2013-04-04 16:21:04 +02:00
|
|
|
void backupUserFile() const;
|
2011-09-15 11:32:15 +02:00
|
|
|
|
2014-02-27 18:50:22 +01:00
|
|
|
QVariantMap readUserSettings(QWidget *parent) const;
|
|
|
|
|
QVariantMap readSharedSettings(QWidget *parent) const;
|
|
|
|
|
QVariantMap mergeSettings(const QVariantMap &userMap, const QVariantMap &sharedMap) const;
|
2013-04-04 13:30:16 +02:00
|
|
|
|
2017-11-15 12:38:44 +01:00
|
|
|
static QByteArray settingsIdFromMap(const QVariantMap &data);
|
2014-03-03 18:57:42 +01:00
|
|
|
static QString differentEnvironmentMsg(const QString &projectName);
|
2014-02-27 17:19:22 +01:00
|
|
|
|
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);
|
2014-02-28 16:28:36 +01:00
|
|
|
|
|
|
|
|
protected:
|
2016-02-02 18:26:51 +01:00
|
|
|
QVariantMap prepareSettings(const QVariantMap &data) const override;
|
|
|
|
|
QVariantMap prepareToSaveSettings(const QVariantMap &data) const override;
|
2014-02-25 17:49:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2010-01-19 16:59:18 +01:00
|
|
|
} // namespace ProjectExplorer
|