forked from qt-creator/qt-creator
Make it possible to override the language settings in Creator.
Platform-dependent behavior is not good enough for a lot of people it seems. Reviewed-By: con
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QTranslator>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
@@ -179,6 +180,12 @@ int main(int argc, char **argv)
|
||||
QTranslator translator;
|
||||
QTranslator qtTranslator;
|
||||
QString locale = QLocale::system().name();
|
||||
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
||||
const QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String("Nokia"), QLatin1String("QtCreator"));
|
||||
locale = settings.value("General/OverrideLanguage", locale).toString();
|
||||
|
||||
|
||||
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String(SHARE_PATH "/translations");
|
||||
if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) {
|
||||
|
@@ -38,9 +38,13 @@
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QMainWindow>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include "ui_generalsettings.h"
|
||||
|
||||
@@ -73,6 +77,38 @@ QString GeneralSettings::trCategory() const
|
||||
return QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE);
|
||||
}
|
||||
|
||||
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");
|
||||
return QFile::exists(qtTrPath+'/'+trFile) || QFile::exists(creatorTrPath+'/'+trFile);
|
||||
}
|
||||
|
||||
void GeneralSettings::fillLanguageBox() const
|
||||
{
|
||||
m_page->languageBox->addItem(tr("<System Language>"), QString());
|
||||
|
||||
const QString creatorTrPath =
|
||||
Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
|
||||
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("*.qm")));
|
||||
const QString currentLocale = language();
|
||||
|
||||
Q_FOREACH(const QString languageFile, languageFiles)
|
||||
{
|
||||
int start = languageFile.lastIndexOf(QLatin1Char('_'))+1;
|
||||
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)) {
|
||||
m_page->languageBox->addItem(QLocale::languageToString(QLocale(locale).language()), locale);
|
||||
if (locale == currentLocale)
|
||||
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
{
|
||||
m_page = new Ui::GeneralSettings();
|
||||
@@ -80,6 +116,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
m_page->setupUi(w);
|
||||
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
Q_UNUSED(settings)
|
||||
fillLanguageBox();
|
||||
m_page->colorButton->setColor(StyleHelper::baseColor());
|
||||
m_page->externalEditorEdit->setText(EditorManager::instance()->externalEditor());
|
||||
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadBehavior());
|
||||
@@ -103,6 +141,8 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
this, SLOT(resetInterfaceColor()));
|
||||
connect(m_page->resetEditorButton, SIGNAL(clicked()),
|
||||
this, SLOT(resetExternalEditor()));
|
||||
connect(m_page->resetLanguageButton, SIGNAL(clicked()),
|
||||
this, SLOT(resetLanguage()));
|
||||
connect(m_page->helpExternalEditorButton, SIGNAL(clicked()),
|
||||
this, SLOT(showHelpForExternalEditor()));
|
||||
#ifdef Q_OS_UNIX
|
||||
@@ -132,6 +172,8 @@ bool GeneralSettings::matches(const QString &s) const
|
||||
|
||||
void GeneralSettings::apply()
|
||||
{
|
||||
int currentIndex = m_page->languageBox->currentIndex();
|
||||
setLanguage(m_page->languageBox->itemData(currentIndex, Qt::UserRole).toString());
|
||||
// Apply the new base color if accepted
|
||||
StyleHelper::setBaseColor(m_page->colorButton->color());
|
||||
EditorManager::instance()->setExternalEditor(m_page->externalEditorEdit->text());
|
||||
@@ -205,3 +247,29 @@ void GeneralSettings::showHelpForFileBrowser()
|
||||
variableHelpDialogCreator(UnixUtils::fileBrowserHelpText());
|
||||
}
|
||||
#endif
|
||||
|
||||
void GeneralSettings::resetLanguage()
|
||||
{
|
||||
// system language is default
|
||||
m_page->languageBox->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
QString GeneralSettings::language() const
|
||||
{
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
return settings->value(QLatin1String("General/OverrideLanguage")).toString();
|
||||
}
|
||||
|
||||
void GeneralSettings::setLanguage(const QString &locale)
|
||||
{
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale)
|
||||
{
|
||||
QMessageBox::information(Core::ICore::instance()->mainWindow(), tr("Restart required"),
|
||||
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);
|
||||
}
|
||||
|
@@ -60,6 +60,7 @@ public:
|
||||
private slots:
|
||||
void resetInterfaceColor();
|
||||
void resetExternalEditor();
|
||||
void resetLanguage();
|
||||
void showHelpForExternalEditor();
|
||||
#ifdef Q_OS_UNIX
|
||||
# ifndef Q_OS_MAC
|
||||
@@ -71,6 +72,9 @@ private slots:
|
||||
|
||||
private:
|
||||
void variableHelpDialogCreator(const QString& helpText);
|
||||
void fillLanguageBox() const;
|
||||
QString language() const;
|
||||
void setLanguage(const QString&);
|
||||
Ui::GeneralSettings *m_page;
|
||||
QString m_searchKeywords;
|
||||
QPointer<QWidget> m_dialog;
|
||||
|
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>363</width>
|
||||
<height>296</height>
|
||||
<width>408</width>
|
||||
<height>295</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@@ -23,7 +23,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="colorLabel">
|
||||
<property name="text">
|
||||
<string>User &interface color:</string>
|
||||
<string>User interface color:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>colorButton</cstring>
|
||||
@@ -80,14 +80,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="terminalLabel">
|
||||
<property name="text">
|
||||
<string>Terminal:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="3" column="1">
|
||||
<layout class="QHBoxLayout" name="terminalHorizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="terminalEdit"/>
|
||||
@@ -108,14 +108,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="editorLabel">
|
||||
<property name="text">
|
||||
<string>External editor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="4" column="1">
|
||||
<layout class="QHBoxLayout" name="editorHorizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="externalEditorEdit"/>
|
||||
@@ -143,14 +143,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="externalFileBrowserLabel">
|
||||
<property name="text">
|
||||
<string>External file browser:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="modifiedLabel">
|
||||
<property name="text">
|
||||
<string>When files are externally modified:</string>
|
||||
@@ -160,7 +160,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QComboBox" name="reloadBehavior">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
@@ -188,7 +188,7 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="5" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
@@ -220,6 +220,34 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="languageLabel">
|
||||
<property name="text">
|
||||
<string>User interface language:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QComboBox" name="languageBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="resetLanguageButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset to default</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="core.qrc">
|
||||
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -245,6 +273,21 @@
|
||||
<header location="global">utils/qtcolorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>colorButton</tabstop>
|
||||
<tabstop>resetButton</tabstop>
|
||||
<tabstop>languageBox</tabstop>
|
||||
<tabstop>resetLanguageButton</tabstop>
|
||||
<tabstop>terminalEdit</tabstop>
|
||||
<tabstop>resetTerminalButton</tabstop>
|
||||
<tabstop>externalEditorEdit</tabstop>
|
||||
<tabstop>resetEditorButton</tabstop>
|
||||
<tabstop>helpExternalEditorButton</tabstop>
|
||||
<tabstop>externalFileBrowserEdit</tabstop>
|
||||
<tabstop>resetFileBrowserButton</tabstop>
|
||||
<tabstop>helpExternalFileBrowserButton</tabstop>
|
||||
<tabstop>reloadBehavior</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="core.qrc"/>
|
||||
</resources>
|
||||
|
@@ -114,6 +114,7 @@ MainWindow::MainWindow() :
|
||||
m_uniqueIDManager(new UniqueIDManager()),
|
||||
m_globalContext(QList<int>() << Constants::C_GLOBAL_ID),
|
||||
m_additionalContexts(m_globalContext),
|
||||
// keep this in sync with main() in app/main.cpp
|
||||
m_settings(new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String("Nokia"), QLatin1String("QtCreator"), this)),
|
||||
m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
|
||||
|
Reference in New Issue
Block a user