forked from qt-creator/qt-creator
QtCreator: Add ability to specify text codec for default locale
On Windows you get one locale for unicode applications, and one for old non-unicode applications. Qt Creator uses QTextCodec::codecForLocale(), which would result in the "System" codec, which is mapped for the default language in the system. Task-number: QTCREATORBUG-24776 Change-Id: I64496cc440931d3bf6f09314bdfc7c29e01b9f4f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -60,6 +60,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -661,6 +662,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray overrideCodecForLocale = settings->value("General/OverrideCodecForLocale").toByteArray();
|
||||||
|
if (!overrideCodecForLocale.isEmpty())
|
||||||
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName(overrideCodecForLocale));
|
||||||
|
|
||||||
app.setDesktopFileName("org.qt-project.qtcreator.desktop");
|
app.setDesktopFileName("org.qt-project.qtcreator.desktop");
|
||||||
|
|
||||||
// Make sure we honor the system's proxy settings
|
// Make sure we honor the system's proxy settings
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/dialogs/restartdialog.h>
|
#include <coreplugin/dialogs/restartdialog.h>
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/checkablemessagebox.h>
|
#include <utils/checkablemessagebox.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
@@ -42,6 +43,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStyleHints>
|
#include <QStyleHints>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
@@ -50,6 +52,7 @@ namespace Internal {
|
|||||||
|
|
||||||
const char settingsKeyDPI[] = "Core/EnableHighDpiScaling";
|
const char settingsKeyDPI[] = "Core/EnableHighDpiScaling";
|
||||||
const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu";
|
const char settingsKeyShortcutsInContextMenu[] = "General/ShowShortcutsInContextMenu";
|
||||||
|
const char settingsKeyCodecForLocale[] = "General/OverrideCodecForLocale";
|
||||||
|
|
||||||
class GeneralSettingsWidget final : public IOptionsPageWidget
|
class GeneralSettingsWidget final : public IOptionsPageWidget
|
||||||
{
|
{
|
||||||
@@ -68,6 +71,9 @@ public:
|
|||||||
void fillLanguageBox() const;
|
void fillLanguageBox() const;
|
||||||
static QString language();
|
static QString language();
|
||||||
static void setLanguage(const QString&);
|
static void setLanguage(const QString&);
|
||||||
|
void fillCodecBox() const;
|
||||||
|
static QByteArray codecForLocale();
|
||||||
|
static void setCodecForLocale(const QByteArray&);
|
||||||
|
|
||||||
GeneralSettings *q;
|
GeneralSettings *q;
|
||||||
Ui::GeneralSettings m_ui;
|
Ui::GeneralSettings m_ui;
|
||||||
@@ -79,6 +85,7 @@ GeneralSettingsWidget::GeneralSettingsWidget(GeneralSettings *q)
|
|||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
fillLanguageBox();
|
fillLanguageBox();
|
||||||
|
fillCodecBox();
|
||||||
|
|
||||||
m_ui.colorButton->setColor(StyleHelper::requestedBaseColor());
|
m_ui.colorButton->setColor(StyleHelper::requestedBaseColor());
|
||||||
m_ui.resetWarningsButton->setEnabled(canResetWarnings());
|
m_ui.resetWarningsButton->setEnabled(canResetWarnings());
|
||||||
@@ -151,6 +158,8 @@ void GeneralSettingsWidget::apply()
|
|||||||
{
|
{
|
||||||
int currentIndex = m_ui.languageBox->currentIndex();
|
int currentIndex = m_ui.languageBox->currentIndex();
|
||||||
setLanguage(m_ui.languageBox->itemData(currentIndex, Qt::UserRole).toString());
|
setLanguage(m_ui.languageBox->itemData(currentIndex, Qt::UserRole).toString());
|
||||||
|
currentIndex = m_ui.codecBox->currentIndex();
|
||||||
|
setCodecForLocale(m_ui.codecBox->itemText(currentIndex).toLocal8Bit());
|
||||||
q->setShowShortcutsInContextMenu(m_ui.showShortcutsInContextMenus->isChecked());
|
q->setShowShortcutsInContextMenu(m_ui.showShortcutsInContextMenus->isChecked());
|
||||||
// Apply the new base color if accepted
|
// Apply the new base color if accepted
|
||||||
StyleHelper::setBaseColor(m_ui.colorButton->color());
|
StyleHelper::setBaseColor(m_ui.colorButton->color());
|
||||||
@@ -207,6 +216,35 @@ void GeneralSettingsWidget::setLanguage(const QString &locale)
|
|||||||
settings->setValueWithDefault(QLatin1String("General/OverrideLanguage"), locale, {});
|
settings->setValueWithDefault(QLatin1String("General/OverrideLanguage"), locale, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralSettingsWidget::fillCodecBox() const
|
||||||
|
{
|
||||||
|
const QByteArray currentCodec = codecForLocale();
|
||||||
|
|
||||||
|
QByteArrayList codecs = QTextCodec::availableCodecs();
|
||||||
|
Utils::sort(codecs);
|
||||||
|
for (const QByteArray &codec : qAsConst(codecs)) {
|
||||||
|
m_ui.codecBox->addItem(QString::fromLocal8Bit(codec));
|
||||||
|
if (codec == currentCodec)
|
||||||
|
m_ui.codecBox->setCurrentIndex(m_ui.codecBox->count() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray GeneralSettingsWidget::codecForLocale()
|
||||||
|
{
|
||||||
|
QSettings *settings = ICore::settings();
|
||||||
|
QByteArray codec = settings->value(settingsKeyCodecForLocale).toByteArray();
|
||||||
|
if (codec.isEmpty())
|
||||||
|
codec = QTextCodec::codecForLocale()->name();
|
||||||
|
return codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeneralSettingsWidget::setCodecForLocale(const QByteArray &codec)
|
||||||
|
{
|
||||||
|
QtcSettings *settings = ICore::settings();
|
||||||
|
settings->setValueWithDefault(settingsKeyCodecForLocale, codec, {});
|
||||||
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName(codec));
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralSettings::setShowShortcutsInContextMenu(bool show)
|
void GeneralSettings::setShowShortcutsInContextMenu(bool show)
|
||||||
{
|
{
|
||||||
ICore::settings()->setValueWithDefault(settingsKeyShortcutsInContextMenu,
|
ICore::settings()->setValueWithDefault(settingsKeyShortcutsInContextMenu,
|
||||||
|
@@ -17,15 +17,49 @@
|
|||||||
<string>User Interface</string>
|
<string>User Interface</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="1" column="0">
|
<item row="5" column="0">
|
||||||
<widget class="QLabel" name="themeLabel">
|
<widget class="QPushButton" name="resetWarningsButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter).</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Theme:</string>
|
<string comment="Button text">Reset Warnings</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/>
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="languageBox">
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimumContentsLength">
|
||||||
|
<number>20</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>285</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QCheckBox" name="dpiCheckbox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable high DPI scaling</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
@@ -73,50 +107,6 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="languageBox">
|
|
||||||
<property name="sizeAdjustPolicy">
|
|
||||||
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
|
|
||||||
</property>
|
|
||||||
<property name="minimumContentsLength">
|
|
||||||
<number>20</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>285</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="colorLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>Color:</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QPushButton" name="resetWarningsButton">
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter).</string>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string comment="Button text">Reset Warnings</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="languageLabel">
|
<widget class="QLabel" name="languageLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -124,13 +114,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QCheckBox" name="dpiCheckbox">
|
|
||||||
<property name="text">
|
|
||||||
<string>Enable high DPI scaling</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QCheckBox" name="showShortcutsInContextMenus">
|
<widget class="QCheckBox" name="showShortcutsInContextMenus">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -138,6 +121,57 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="themeLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Theme:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="colorLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Color:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<widget class="QLabel" name="codecForLocale">
|
||||||
|
<property name="text">
|
||||||
|
<string>Text codec for locale:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="1">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="codecBox">
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimumContentsLength">
|
||||||
|
<number>20</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user