2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2016 Vasiliy Sorokin
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03: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.
|
2011-10-25 23:14:27 +03: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.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
|
2014-06-13 11:19:54 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2017-01-05 17:13:42 +01:00
|
|
|
#include <utils/theme/theme.h>
|
2014-05-19 12:21:28 +02:00
|
|
|
|
2012-02-24 09:43:52 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
namespace Todo {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
void Settings::save(QSettings *settings) const
|
|
|
|
|
{
|
2017-01-06 17:44:51 +01:00
|
|
|
if (!keywordsEdited)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-02-24 09:43:52 +01:00
|
|
|
settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
|
|
|
|
|
settings->setValue(QLatin1String(Constants::SCANNING_SCOPE), scanningScope);
|
|
|
|
|
|
|
|
|
|
settings->beginWriteArray(QLatin1String(Constants::KEYWORDS_LIST));
|
|
|
|
|
if (const int size = keywords.size()) {
|
|
|
|
|
const QString nameKey = QLatin1String("name");
|
|
|
|
|
const QString colorKey = QLatin1String("color");
|
2015-11-16 16:45:05 +01:00
|
|
|
const QString iconTypeKey = QLatin1String("iconType");
|
2012-02-24 09:43:52 +01:00
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
settings->setValue(nameKey, keywords.at(i).name);
|
|
|
|
|
settings->setValue(colorKey, keywords.at(i).color);
|
2015-11-16 16:45:05 +01:00
|
|
|
settings->setValue(iconTypeKey, static_cast<int>(keywords.at(i).iconType));
|
2012-02-24 09:43:52 +01:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
settings->endArray();
|
|
|
|
|
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
settings->sync();
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-16 16:45:05 +01:00
|
|
|
// Compatibility helper for transition from 3.6 to higher
|
|
|
|
|
// TODO: remove in 4.0
|
|
|
|
|
IconType resourceToTypeKey(const QString &key)
|
|
|
|
|
{
|
|
|
|
|
if (key.contains(QLatin1String("error")))
|
|
|
|
|
return IconType::Error;
|
|
|
|
|
else if (key.contains(QLatin1String("warning")))
|
|
|
|
|
return IconType::Warning;
|
|
|
|
|
return IconType::Info;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void Settings::load(QSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
setDefault();
|
|
|
|
|
|
2012-02-24 09:43:52 +01:00
|
|
|
settings->beginGroup(QLatin1String(Constants::SETTINGS_GROUP));
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2012-02-24 09:43:52 +01:00
|
|
|
scanningScope = static_cast<ScanningScope>(settings->value(QLatin1String(Constants::SCANNING_SCOPE),
|
2016-03-03 13:48:07 +01:00
|
|
|
ScanningScopeCurrentFile).toInt());
|
2016-08-31 15:19:27 +02:00
|
|
|
if (scanningScope >= ScanningScopeMax)
|
|
|
|
|
scanningScope = ScanningScopeCurrentFile;
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
KeywordList newKeywords;
|
2015-05-18 22:47:20 +03:00
|
|
|
const int keywordsSize = settings->beginReadArray(QLatin1String(Constants::KEYWORDS_LIST));
|
|
|
|
|
if (keywordsSize > 0) {
|
2012-02-24 09:43:52 +01:00
|
|
|
const QString nameKey = QLatin1String("name");
|
|
|
|
|
const QString colorKey = QLatin1String("color");
|
2015-11-16 16:45:05 +01:00
|
|
|
const QString iconResourceKey = QLatin1String("iconResource"); // Legacy since 3.7 TODO: remove in 4.0
|
|
|
|
|
const QString iconTypeKey = QLatin1String("iconType");
|
2015-05-18 22:47:20 +03:00
|
|
|
for (int i = 0; i < keywordsSize; ++i) {
|
2011-10-25 23:14:27 +03:00
|
|
|
settings->setArrayIndex(i);
|
|
|
|
|
Keyword keyword;
|
2012-02-24 09:43:52 +01:00
|
|
|
keyword.name = settings->value(nameKey).toString();
|
|
|
|
|
keyword.color = settings->value(colorKey).value<QColor>();
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = settings->contains(iconTypeKey) ?
|
|
|
|
|
static_cast<IconType>(settings->value(iconTypeKey).toInt())
|
|
|
|
|
: resourceToTypeKey(settings->value(iconResourceKey).toString());
|
2011-10-25 23:14:27 +03:00
|
|
|
newKeywords << keyword;
|
|
|
|
|
}
|
|
|
|
|
keywords = newKeywords;
|
2017-01-06 17:44:51 +01:00
|
|
|
keywordsEdited = true; // Otherwise they wouldn't have been saved
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
settings->endArray();
|
|
|
|
|
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Settings::setDefault()
|
|
|
|
|
{
|
|
|
|
|
scanningScope = ScanningScopeCurrentFile;
|
2017-01-05 17:13:42 +01:00
|
|
|
Utils::Theme *theme = Utils::creatorTheme();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
keywords.clear();
|
|
|
|
|
|
|
|
|
|
Keyword keyword;
|
|
|
|
|
|
|
|
|
|
keyword.name = QLatin1String("TODO");
|
2016-07-20 21:24:00 +03:00
|
|
|
keyword.iconType = IconType::Todo;
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = theme->color(Utils::Theme::OutputPanes_NormalMessageTextColor);
|
2011-10-25 23:14:27 +03:00
|
|
|
keywords.append(keyword);
|
|
|
|
|
|
|
|
|
|
keyword.name = QLatin1String("NOTE");
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = IconType::Info;
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = theme->color(Utils::Theme::OutputPanes_NormalMessageTextColor);
|
2011-10-25 23:14:27 +03:00
|
|
|
keywords.append(keyword);
|
|
|
|
|
|
|
|
|
|
keyword.name = QLatin1String("FIXME");
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = IconType::Error;
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = theme->color(Utils::Theme::OutputPanes_ErrorMessageTextColor);
|
2011-10-25 23:14:27 +03:00
|
|
|
keywords.append(keyword);
|
|
|
|
|
|
|
|
|
|
keyword.name = QLatin1String("BUG");
|
2016-07-20 21:24:00 +03:00
|
|
|
keyword.iconType = IconType::Bug;
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = theme->color(Utils::Theme::OutputPanes_ErrorMessageTextColor);
|
2011-10-25 23:14:27 +03:00
|
|
|
keywords.append(keyword);
|
|
|
|
|
|
|
|
|
|
keyword.name = QLatin1String("WARNING");
|
2015-11-16 16:45:05 +01:00
|
|
|
keyword.iconType = IconType::Warning;
|
2017-01-05 17:13:42 +01:00
|
|
|
keyword.color = theme->color(Utils::Theme::OutputPanes_WarningMessageTextColor);
|
2011-10-25 23:14:27 +03:00
|
|
|
keywords.append(keyword);
|
2017-01-06 17:44:51 +01:00
|
|
|
|
|
|
|
|
keywordsEdited = false;
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Settings::equals(const Settings &other) const
|
|
|
|
|
{
|
|
|
|
|
return (keywords == other.keywords)
|
2017-01-06 17:44:51 +01:00
|
|
|
&& (scanningScope == other.scanningScope)
|
|
|
|
|
&& (keywordsEdited == other.keywordsEdited);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator ==(Settings &s1, Settings &s2)
|
|
|
|
|
{
|
|
|
|
|
return s1.equals(s2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator !=(Settings &s1, Settings &s2)
|
|
|
|
|
{
|
|
|
|
|
return !s1.equals(s2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Todo
|
|
|
|
|
|