2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +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.
|
2008-12-02 14:17:16 +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
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "generalsettings.h"
|
2009-11-27 16:12:12 +01:00
|
|
|
#include "coreconstants.h"
|
2013-01-10 20:46:06 +02:00
|
|
|
#include "icore.h"
|
|
|
|
|
#include "infobar.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-31 15:39:49 +01:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLibraryInfo>
|
2014-06-05 13:18:35 +02:00
|
|
|
#include <QMessageBox>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSettings>
|
2009-11-20 16:55:23 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "ui_generalsettings.h"
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2010-01-04 15:19:29 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
GeneralSettings::GeneralSettings()
|
|
|
|
|
: m_page(0), m_dialog(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-08-14 13:25:31 +02:00
|
|
|
setId(Constants::SETTINGS_ID_INTERFACE);
|
|
|
|
|
setDisplayName(tr("Interface"));
|
2014-11-16 10:52:41 +02:00
|
|
|
setCategory(Constants::SETTINGS_CATEGORY_CORE);
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Core", Constants::SETTINGS_TR_CATEGORY_CORE));
|
2016-09-20 10:47:09 +02:00
|
|
|
setCategoryIcon(Utils::Icon(Constants::SETTINGS_CATEGORY_CORE_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
static bool hasQmFilesForLocale(const QString &locale, const QString &creatorTrPath)
|
|
|
|
|
{
|
|
|
|
|
static const QString qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
|
|
|
|
|
2013-01-16 15:30:21 +01:00
|
|
|
const QString trFile = QLatin1String("/qt_") + locale + QLatin1String(".qm");
|
|
|
|
|
return QFile::exists(qtTrPath + trFile) || QFile::exists(creatorTrPath + trFile);
|
2010-01-05 16:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettings::fillLanguageBox() const
|
|
|
|
|
{
|
2010-03-15 18:52:04 +01:00
|
|
|
const QString currentLocale = language();
|
|
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
m_page->languageBox->addItem(tr("<System Language>"), QString());
|
2010-01-06 14:55:14 +01:00
|
|
|
// need to add this explicitly, since there is no qm file for English
|
|
|
|
|
m_page->languageBox->addItem(QLatin1String("English"), QLatin1String("C"));
|
2010-03-15 18:52:04 +01:00
|
|
|
if (currentLocale == QLatin1String("C"))
|
|
|
|
|
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
2010-01-05 16:33:30 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
const QString creatorTrPath = ICore::resourcePath() + QLatin1String("/translations");
|
2010-04-12 11:29:38 +02:00
|
|
|
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("qtcreator*.qm")));
|
2010-01-05 16:33:30 +01:00
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
foreach (const QString &languageFile, languageFiles) {
|
2010-05-04 10:33:39 +02:00
|
|
|
int start = languageFile.indexOf(QLatin1Char('_'))+1;
|
2010-01-05 16:33:30 +01:00
|
|
|
int end = languageFile.lastIndexOf(QLatin1Char('.'));
|
|
|
|
|
const QString locale = languageFile.mid(start, end-start);
|
|
|
|
|
// no need to show a language that creator will not load anyway
|
|
|
|
|
if (hasQmFilesForLocale(locale, creatorTrPath)) {
|
2012-11-14 17:26:16 +01:00
|
|
|
QLocale tmpLocale(locale);
|
|
|
|
|
QString languageItem = QLocale::languageToString(tmpLocale.language()) + QLatin1String(" (")
|
|
|
|
|
+ QLocale::countryToString(tmpLocale.country()) + QLatin1Char(')');
|
|
|
|
|
m_page->languageBox->addItem(languageItem, locale);
|
2010-01-05 16:33:30 +01:00
|
|
|
if (locale == currentLocale)
|
|
|
|
|
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *GeneralSettings::widget()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_page = new Ui::GeneralSettings();
|
|
|
|
|
m_widget = new QWidget;
|
|
|
|
|
m_page->setupUi(m_widget);
|
|
|
|
|
|
|
|
|
|
fillLanguageBox();
|
|
|
|
|
|
|
|
|
|
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
|
2015-05-12 15:18:26 +02:00
|
|
|
m_page->resetWarningsButton->setEnabled(canResetWarnings());
|
2013-12-03 14:17:03 +01:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_page->resetColorButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &GeneralSettings::resetInterfaceColor);
|
|
|
|
|
connect(m_page->resetWarningsButton, &QAbstractButton::clicked,
|
|
|
|
|
this, &GeneralSettings::resetWarnings);
|
2009-11-20 16:55:23 +01:00
|
|
|
}
|
2011-02-10 16:55:35 +01:00
|
|
|
return m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void GeneralSettings::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_page) // wasn't shown, can't be changed
|
|
|
|
|
return;
|
2010-01-05 16:33:30 +01:00
|
|
|
int currentIndex = m_page->languageBox->currentIndex();
|
|
|
|
|
setLanguage(m_page->languageBox->itemData(currentIndex, Qt::UserRole).toString());
|
2008-12-02 12:01:29 +01:00
|
|
|
// Apply the new base color if accepted
|
|
|
|
|
StyleHelper::setBaseColor(m_page->colorButton->color());
|
2016-01-20 22:20:59 +02:00
|
|
|
m_page->themeChooser->apply();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 12:14:59 +01:00
|
|
|
void GeneralSettings::finish()
|
|
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2009-02-02 12:14:59 +01:00
|
|
|
delete m_page;
|
2010-12-02 18:28:16 +01:00
|
|
|
m_page = 0;
|
2009-02-02 12:14:59 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void GeneralSettings::resetInterfaceColor()
|
|
|
|
|
{
|
2010-05-27 16:07:52 +02:00
|
|
|
m_page->colorButton->setColor(StyleHelper::DEFAULT_BASE_COLOR);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-10 20:46:06 +02:00
|
|
|
void GeneralSettings::resetWarnings()
|
|
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
InfoBar::clearGloballySuppressed();
|
|
|
|
|
CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings());
|
2013-03-05 19:37:41 +02:00
|
|
|
m_page->resetWarningsButton->setEnabled(false);
|
2013-01-10 20:46:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-12 15:18:26 +02:00
|
|
|
bool GeneralSettings::canResetWarnings() const
|
|
|
|
|
{
|
|
|
|
|
return InfoBar::anyGloballySuppressed()
|
2015-09-01 11:39:39 +02:00
|
|
|
|| CheckableMessageBox::hasSuppressedQuestions(ICore::settings());
|
2015-05-12 15:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
void GeneralSettings::resetLanguage()
|
|
|
|
|
{
|
|
|
|
|
// system language is default
|
|
|
|
|
m_page->languageBox->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString GeneralSettings::language() const
|
|
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2010-01-05 16:33:30 +01:00
|
|
|
return settings->value(QLatin1String("General/OverrideLanguage")).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettings::setLanguage(const QString &locale)
|
|
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
QSettings *settings = ICore::settings();
|
2010-01-05 16:33:30 +01:00
|
|
|
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale)
|
2016-01-13 11:34:58 +01:00
|
|
|
QMessageBox::information(ICore::mainWindow(), tr("Restart Required"),
|
2010-01-05 16:33:30 +01:00
|
|
|
tr("The language change will take effect after a restart of Qt Creator."));
|
2014-06-05 13:18:35 +02:00
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
if (locale.isEmpty())
|
|
|
|
|
settings->remove(QLatin1String("General/OverrideLanguage"));
|
|
|
|
|
else
|
|
|
|
|
settings->setValue(QLatin1String("General/OverrideLanguage"), locale);
|
|
|
|
|
}
|
2014-06-05 13:18:35 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|