2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** 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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/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
|
|
|
|
|
** 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
|
|
|
****************************************************************************/
|
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"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
#include <utils/qtcolorbutton.h>
|
2009-04-09 20:09:10 +02:00
|
|
|
#include <utils/consoleprocess.h>
|
2010-01-04 15:19:29 +01:00
|
|
|
#include <utils/unixutils.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-04-09 20:09:10 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2009-11-20 16:55:23 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QMessageBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
|
#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
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
2010-01-04 15:19:29 +01:00
|
|
|
|
2009-01-12 13:51:14 +01:00
|
|
|
GeneralSettings::GeneralSettings():
|
2010-12-02 18:28:16 +01:00
|
|
|
m_page(0), m_dialog(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2012-05-22 11:17:13 +02:00
|
|
|
setId(QLatin1String(Core::Constants::SETTINGS_ID_ENVIRONMENT));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
const QString trFile = QLatin1String("qt_") + locale + QLatin1String(".qm");
|
2011-12-22 14:44:14 +01:00
|
|
|
return QFile::exists(qtTrPath + QLatin1Char('/') + trFile)
|
|
|
|
|
|| QFile::exists(creatorTrPath + QLatin1Char('/') + 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
|
|
|
|
|
|
|
|
const QString creatorTrPath =
|
2012-01-24 15:36:40 +01:00
|
|
|
Core::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
|
|
|
|
2010-02-01 14:00:07 +01:00
|
|
|
Q_FOREACH(const QString &languageFile, languageFiles)
|
2010-01-05 16:33:30 +01:00
|
|
|
{
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-12 13:51:14 +01:00
|
|
|
QWidget *GeneralSettings::createPage(QWidget *parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-04-30 16:09:57 +02:00
|
|
|
m_page = new Ui::GeneralSettings();
|
2011-02-10 16:55:35 +01:00
|
|
|
m_widget = new QWidget(parent);
|
|
|
|
|
m_page->setupUi(m_widget);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = Core::ICore::settings();
|
2010-11-01 16:29:45 +01:00
|
|
|
Q_UNUSED(settings) // Windows
|
|
|
|
|
|
2010-01-05 16:33:30 +01:00
|
|
|
fillLanguageBox();
|
2010-04-13 19:13:12 +02:00
|
|
|
|
2010-03-03 11:02:13 +01:00
|
|
|
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
|
2010-03-19 10:28:05 +01:00
|
|
|
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting());
|
2009-04-09 20:09:10 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
2012-08-29 09:13:42 +02:00
|
|
|
const QStringList availableTerminals = ConsoleProcess::availableTerminalEmulators();
|
|
|
|
|
const QString currentTerminal = ConsoleProcess::terminalEmulator(settings);
|
|
|
|
|
m_page->terminalComboBox->addItems(availableTerminals);
|
|
|
|
|
m_page->terminalComboBox->lineEdit()->setText(currentTerminal);
|
2009-04-09 20:09:10 +02:00
|
|
|
#else
|
|
|
|
|
m_page->terminalLabel->hide();
|
2012-08-29 09:13:42 +02:00
|
|
|
m_page->terminalComboBox->hide();
|
2009-04-09 20:09:10 +02:00
|
|
|
m_page->resetTerminalButton->hide();
|
|
|
|
|
#endif
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-04 15:19:29 +01:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
|
|
|
|
m_page->externalFileBrowserEdit->setText(UnixUtils::fileBrowser(settings));
|
|
|
|
|
#else
|
|
|
|
|
m_page->externalFileBrowserLabel->hide();
|
|
|
|
|
m_page->externalFileBrowserEdit->hide();
|
|
|
|
|
m_page->resetFileBrowserButton->hide();
|
2010-03-19 17:14:37 +01:00
|
|
|
m_page->helpExternalFileBrowserButton->hide();
|
2010-01-04 15:19:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
2011-05-10 20:43:03 +02:00
|
|
|
m_page->autoSaveCheckBox->setChecked(EditorManager::instance()->autoSaveEnabled());
|
|
|
|
|
m_page->autoSaveInterval->setValue(EditorManager::instance()->autoSaveInterval());
|
|
|
|
|
|
2013-01-10 20:39:13 +02:00
|
|
|
connect(m_page->resetColorButton, SIGNAL(clicked()),
|
2008-12-02 12:01:29 +01:00
|
|
|
this, SLOT(resetInterfaceColor()));
|
2009-04-09 20:09:10 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
|
connect(m_page->resetTerminalButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(resetTerminal()));
|
2010-01-04 15:19:29 +01:00
|
|
|
#ifndef Q_OS_MAC
|
|
|
|
|
connect(m_page->resetFileBrowserButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(resetFileBrowser()));
|
|
|
|
|
connect(m_page->helpExternalFileBrowserButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(showHelpForFileBrowser()));
|
|
|
|
|
#endif
|
2009-04-09 20:09:10 +02:00
|
|
|
#endif
|
2009-02-02 12:14:59 +01:00
|
|
|
|
2009-11-20 16:55:23 +01:00
|
|
|
if (m_searchKeywords.isEmpty()) {
|
2010-12-01 14:35:36 +01:00
|
|
|
QLatin1Char sep(' ');
|
|
|
|
|
QTextStream(&m_searchKeywords)
|
|
|
|
|
<< m_page->interfaceBox->title() << sep
|
|
|
|
|
<< m_page->colorLabel->text() << sep
|
|
|
|
|
<< m_page->languageLabel->text() << sep
|
|
|
|
|
<< m_page->systemBox->title() << sep
|
|
|
|
|
<< m_page->terminalLabel->text() << sep
|
|
|
|
|
<< m_page->modifiedLabel->text();
|
2009-11-20 16:55:23 +01:00
|
|
|
m_searchKeywords.remove(QLatin1Char('&'));
|
|
|
|
|
}
|
2011-02-10 16:55:35 +01:00
|
|
|
return m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-20 16:55:23 +01:00
|
|
|
bool GeneralSettings::matches(const QString &s) const
|
|
|
|
|
{
|
|
|
|
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
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());
|
2012-02-14 16:43:51 +01:00
|
|
|
EditorManager::instance()->setReloadSetting(IDocument::ReloadSetting(m_page->reloadBehavior->currentIndex()));
|
2009-04-09 20:09:10 +02:00
|
|
|
#ifdef Q_OS_UNIX
|
2012-01-24 15:36:40 +01:00
|
|
|
ConsoleProcess::setTerminalEmulator(Core::ICore::settings(),
|
2012-08-29 09:13:42 +02:00
|
|
|
m_page->terminalComboBox->lineEdit()->text());
|
2010-01-04 15:19:29 +01:00
|
|
|
#ifndef Q_OS_MAC
|
2012-01-24 15:36:40 +01:00
|
|
|
Utils::UnixUtils::setFileBrowser(Core::ICore::settings(), m_page->externalFileBrowserEdit->text());
|
2010-01-04 15:19:29 +01:00
|
|
|
#endif
|
2009-04-09 20:09:10 +02:00
|
|
|
#endif
|
2011-05-10 20:43:03 +02:00
|
|
|
EditorManager::instance()->setAutoSaveEnabled(m_page->autoSaveCheckBox->isChecked());
|
|
|
|
|
EditorManager::instance()->setAutoSaveInterval(m_page->autoSaveInterval->value());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-02-02 12:14:59 +01:00
|
|
|
void GeneralSettings::finish()
|
|
|
|
|
{
|
2010-12-02 18:28:16 +01:00
|
|
|
if (!m_page) // page was never shown
|
|
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
|
2009-04-09 20:09:10 +02:00
|
|
|
void GeneralSettings::resetTerminal()
|
|
|
|
|
{
|
2012-03-19 10:04:17 +01:00
|
|
|
#if defined(Q_OS_UNIX)
|
2012-08-29 09:13:42 +02:00
|
|
|
m_page->terminalComboBox->lineEdit()->setText(ConsoleProcess::defaultTerminalEmulator());
|
2012-03-19 10:04:17 +01:00
|
|
|
#endif
|
2009-04-09 20:09:10 +02:00
|
|
|
}
|
2010-01-04 15:19:29 +01:00
|
|
|
|
|
|
|
|
void GeneralSettings::resetFileBrowser()
|
|
|
|
|
{
|
2012-03-19 10:04:17 +01:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
2010-01-04 15:19:29 +01:00
|
|
|
m_page->externalFileBrowserEdit->setText(UnixUtils::defaultFileBrowser());
|
2009-04-09 20:09:10 +02:00
|
|
|
#endif
|
2012-03-19 10:04:17 +01:00
|
|
|
}
|
2009-04-09 20:09:10 +02:00
|
|
|
|
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();
|
|
|
|
|
m_dialog->raise();
|
|
|
|
|
m_dialog->activateWindow();
|
|
|
|
|
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()
|
|
|
|
|
{
|
2012-03-19 10:04:17 +01:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
2010-01-04 15:19:29 +01:00
|
|
|
variableHelpDialogCreator(UnixUtils::fileBrowserHelpText());
|
|
|
|
|
#endif
|
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
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings* settings = Core::ICore::settings();
|
2010-01-05 16:33:30 +01:00
|
|
|
return settings->value(QLatin1String("General/OverrideLanguage")).toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GeneralSettings::setLanguage(const QString &locale)
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings* settings = Core::ICore::settings();
|
2010-01-05 16:33:30 +01:00
|
|
|
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale)
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QMessageBox::information(Core::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."));
|
|
|
|
|
}
|
|
|
|
|
if (locale.isEmpty())
|
|
|
|
|
settings->remove(QLatin1String("General/OverrideLanguage"));
|
|
|
|
|
else
|
|
|
|
|
settings->setValue(QLatin1String("General/OverrideLanguage"), locale);
|
|
|
|
|
}
|