2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +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
|
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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
|
|
****************************************************************************/
|
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"
|
2014-04-17 12:47:38 +02:00
|
|
|
#include "patchtool.h"
|
|
|
|
|
#include "vcsmanager.h"
|
2014-07-18 17:11:57 +02:00
|
|
|
#include "editormanager/editormanager_p.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-10-31 15:39:49 +01:00
|
|
|
#include <utils/checkablemessagebox.h>
|
|
|
|
|
#include <utils/consoleprocess.h>
|
2014-06-05 13:18:35 +02:00
|
|
|
#include <utils/environment.h>
|
2013-03-14 10:44:46 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2010-01-04 15:19:29 +01:00
|
|
|
#include <utils/unixutils.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>
|
2014-06-05 13:18:35 +02:00
|
|
|
#include <QTextStream>
|
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
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId(Core::Constants::SETTINGS_ID_ENVIRONMENT);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayName(tr("General"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(Core::Constants::SETTINGS_CATEGORY_CORE);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE));
|
|
|
|
|
setCategoryIcon(QLatin1String(Core::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());
|
2014-07-18 17:11:57 +02:00
|
|
|
m_page->reloadBehavior->setCurrentIndex(EditorManagerPrivate::reloadSetting());
|
2013-12-03 14:17:03 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost()) {
|
|
|
|
|
const QStringList availableTerminals = ConsoleProcess::availableTerminalEmulators();
|
2014-06-05 13:18:35 +02:00
|
|
|
const QString currentTerminal = ConsoleProcess::terminalEmulator(ICore::settings(), false);
|
2013-12-03 14:17:03 +01:00
|
|
|
m_page->terminalComboBox->addItems(availableTerminals);
|
|
|
|
|
m_page->terminalComboBox->lineEdit()->setText(currentTerminal);
|
|
|
|
|
m_page->terminalComboBox->lineEdit()->setPlaceholderText(ConsoleProcess::defaultTerminalEmulator());
|
|
|
|
|
} else {
|
|
|
|
|
m_page->terminalLabel->hide();
|
|
|
|
|
m_page->terminalComboBox->hide();
|
|
|
|
|
m_page->resetTerminalButton->hide();
|
|
|
|
|
}
|
2011-05-10 20:43:03 +02:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()) {
|
2014-06-05 13:18:35 +02:00
|
|
|
m_page->externalFileBrowserEdit->setText(UnixUtils::fileBrowser(ICore::settings()));
|
2013-12-03 14:17:03 +01:00
|
|
|
} else {
|
|
|
|
|
m_page->externalFileBrowserLabel->hide();
|
|
|
|
|
m_page->externalFileBrowserEdit->hide();
|
|
|
|
|
m_page->resetFileBrowserButton->hide();
|
|
|
|
|
m_page->helpExternalFileBrowserButton->hide();
|
2013-03-14 10:44:46 +01:00
|
|
|
}
|
2009-02-02 12:14:59 +01:00
|
|
|
|
2014-04-17 12:47:38 +02:00
|
|
|
const QString patchToolTip = tr("Command used for reverting diff chunks.");
|
|
|
|
|
m_page->patchCommandLabel->setToolTip(patchToolTip);
|
|
|
|
|
m_page->patchChooser->setToolTip(patchToolTip);
|
2014-06-05 13:18:35 +02:00
|
|
|
m_page->patchChooser->setExpectedKind(PathChooser::ExistingCommand);
|
2014-04-17 12:47:38 +02:00
|
|
|
m_page->patchChooser->setHistoryCompleter(QLatin1String("General.PatchCommand.History"));
|
2014-06-05 13:18:35 +02:00
|
|
|
m_page->patchChooser->setPath(PatchTool::patchCommand());
|
2014-07-18 17:11:57 +02:00
|
|
|
m_page->autoSaveCheckBox->setChecked(EditorManagerPrivate::autoSaveEnabled());
|
|
|
|
|
m_page->autoSaveInterval->setValue(EditorManagerPrivate::autoSaveInterval());
|
2014-06-05 13:18:35 +02:00
|
|
|
m_page->resetWarningsButton->setEnabled(InfoBar::anyGloballySuppressed()
|
|
|
|
|
|| CheckableMessageBox::hasSuppressedQuestions(ICore::settings()));
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
connect(m_page->resetColorButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(resetInterfaceColor()));
|
|
|
|
|
connect(m_page->resetWarningsButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(resetWarnings()));
|
|
|
|
|
if (HostOsInfo::isAnyUnixHost()) {
|
|
|
|
|
connect(m_page->resetTerminalButton, SIGNAL(clicked()), this, SLOT(resetTerminal()));
|
|
|
|
|
if (!HostOsInfo::isMacHost()) {
|
|
|
|
|
connect(m_page->resetFileBrowserButton, SIGNAL(clicked()), this, SLOT(resetFileBrowser()));
|
|
|
|
|
connect(m_page->helpExternalFileBrowserButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(showHelpForFileBrowser()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-17 12:47:38 +02:00
|
|
|
|
|
|
|
|
updatePath();
|
|
|
|
|
|
2014-06-05 13:18:35 +02:00
|
|
|
connect(VcsManager::instance(), SIGNAL(configurationChanged(const IVersionControl*)),
|
2014-04-17 12:47:38 +02:00
|
|
|
this, SLOT(updatePath()));
|
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());
|
2014-07-18 17:11:57 +02:00
|
|
|
EditorManagerPrivate::setReloadSetting(IDocument::ReloadSetting(m_page->reloadBehavior->currentIndex()));
|
2013-03-14 10:44:46 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost()) {
|
2014-06-05 13:18:35 +02:00
|
|
|
ConsoleProcess::setTerminalEmulator(ICore::settings(),
|
2013-03-14 10:44:46 +01:00
|
|
|
m_page->terminalComboBox->lineEdit()->text());
|
|
|
|
|
if (!HostOsInfo::isMacHost()) {
|
2014-06-05 13:18:35 +02:00
|
|
|
UnixUtils::setFileBrowser(ICore::settings(),
|
|
|
|
|
m_page->externalFileBrowserEdit->text());
|
2013-03-14 10:44:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-05 13:18:35 +02:00
|
|
|
PatchTool::setPatchCommand(m_page->patchChooser->path());
|
2014-07-18 17:11:57 +02:00
|
|
|
EditorManagerPrivate::setAutoSaveEnabled(m_page->autoSaveCheckBox->isChecked());
|
|
|
|
|
EditorManagerPrivate::setAutoSaveInterval(m_page->autoSaveInterval->value());
|
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
|
|
|
}
|
|
|
|
|
|
2009-04-09 20:09:10 +02:00
|
|
|
void GeneralSettings::resetTerminal()
|
|
|
|
|
{
|
2013-03-14 10:44:46 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost())
|
2014-07-23 09:53:06 +02:00
|
|
|
m_page->terminalComboBox->lineEdit()->clear();
|
2009-04-09 20:09:10 +02:00
|
|
|
}
|
2010-01-04 15:19:29 +01:00
|
|
|
|
|
|
|
|
void GeneralSettings::resetFileBrowser()
|
|
|
|
|
{
|
2013-03-14 10:44:46 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
|
|
|
|
|
m_page->externalFileBrowserEdit->setText(UnixUtils::defaultFileBrowser());
|
2012-03-19 10:04:17 +01:00
|
|
|
}
|
2009-04-09 20:09:10 +02:00
|
|
|
|
2014-04-17 12:47:38 +02:00
|
|
|
void GeneralSettings::updatePath()
|
|
|
|
|
{
|
2014-06-05 13:18:35 +02:00
|
|
|
Environment env = Environment::systemEnvironment();
|
|
|
|
|
QStringList toAdd = VcsManager::additionalToolsPath();
|
2014-08-23 01:19:53 +02:00
|
|
|
env.appendOrSetPath(toAdd.join(HostOsInfo::pathListSeparator()));
|
2014-04-17 12:47:38 +02:00
|
|
|
m_page->patchChooser->setEnvironment(env);
|
|
|
|
|
}
|
2010-01-04 15:19:29 +01:00
|
|
|
|
2010-03-11 14:28:47 +01:00
|
|
|
void GeneralSettings::variableHelpDialogCreator(const QString &helpText)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (m_dialog) {
|
2010-03-11 14:28:47 +01:00
|
|
|
if (m_dialog->text() != helpText)
|
|
|
|
|
m_dialog->setText(helpText);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_dialog->show();
|
2013-04-15 12:53:34 +02:00
|
|
|
ICore::raiseWindow(m_dialog);
|
2008-12-02 12:01:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QMessageBox *mb = new QMessageBox(QMessageBox::Information,
|
|
|
|
|
tr("Variables"),
|
2010-01-04 15:19:29 +01:00
|
|
|
helpText,
|
|
|
|
|
QMessageBox::Close,
|
2011-02-10 16:55:35 +01:00
|
|
|
m_widget);
|
2008-12-02 12:01:29 +01:00
|
|
|
mb->setWindowModality(Qt::NonModal);
|
|
|
|
|
m_dialog = mb;
|
|
|
|
|
mb->show();
|
|
|
|
|
}
|
2010-01-04 15:19:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void GeneralSettings::showHelpForFileBrowser()
|
|
|
|
|
{
|
2013-03-14 10:44:46 +01:00
|
|
|
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost())
|
|
|
|
|
variableHelpDialogCreator(UnixUtils::fileBrowserHelpText());
|
2012-03-19 10:04:17 +01: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)
|
2014-06-05 13:18:35 +02: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
|