mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-227 Basic implementation of support of language override in the GCS. The new preference is in the Environment/General dialog.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2298 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
bdb2982ca5
commit
b8af9da689
@ -39,6 +39,7 @@
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QTranslator>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#include <QtGui/QMessageBox>
|
||||
@ -212,6 +213,16 @@ int main(int argc, char **argv)
|
||||
QTranslator translator;
|
||||
QTranslator qtTranslator;
|
||||
QString locale = QLocale::system().name();
|
||||
|
||||
// Must be done before any QSettings class is created
|
||||
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
|
||||
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH));
|
||||
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
||||
const QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
|
||||
locale = settings.value("General/OverrideLanguage", locale).toString();
|
||||
|
||||
|
||||
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String(SHARE_PATH "/translations");
|
||||
if (translator.load(QLatin1String("openpilotgcs_") + locale, creatorTrPath)) {
|
||||
|
@ -117,9 +117,9 @@ MimeDatabase *CoreImpl::mimeDatabase() const
|
||||
return m_mainwindow->mimeDatabase();
|
||||
}
|
||||
|
||||
QSettings *CoreImpl::settings() const
|
||||
QSettings *CoreImpl::settings(QSettings::Scope scope) const
|
||||
{
|
||||
return m_mainwindow->settings();
|
||||
return m_mainwindow->settings(scope);
|
||||
}
|
||||
|
||||
SettingsDatabase *CoreImpl::settingsDatabase() const
|
||||
|
@ -62,7 +62,7 @@ public:
|
||||
ModeManager *modeManager() const;
|
||||
MimeDatabase *mimeDatabase() const;
|
||||
|
||||
QSettings *settings() const;
|
||||
QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const;
|
||||
SettingsDatabase *settingsDatabase() const;
|
||||
void readMainSettings(QSettings* qs);
|
||||
void saveMainSettings(QSettings* qs);
|
||||
|
@ -33,6 +33,10 @@
|
||||
#include <utils/consoleprocess.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtCore/QDir>
|
||||
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include "ui_generalsettings.h"
|
||||
|
||||
@ -64,12 +68,52 @@ QString GeneralSettings::trCategory() const
|
||||
return tr("Environment");
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
const QString currentLocale = language();
|
||||
|
||||
m_page->languageBox->addItem(tr("<System Language>"), QString());
|
||||
// need to add this explicitly, since there is no qm file for English
|
||||
m_page->languageBox->addItem(QLatin1String("English"), QLatin1String("C"));
|
||||
if (currentLocale == QLatin1String("C"))
|
||||
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
||||
|
||||
const QString creatorTrPath =
|
||||
Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
|
||||
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("qtcreator*.qm")));
|
||||
|
||||
Q_FOREACH(const QString &languageFile, languageFiles)
|
||||
{
|
||||
int start = languageFile.indexOf(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();
|
||||
QWidget *w = new QWidget(parent);
|
||||
m_page->setupUi(w);
|
||||
|
||||
QSettings* settings = Core::ICore::instance()->settings();
|
||||
fillLanguageBox();
|
||||
|
||||
m_page->colorButton->setColor(StyleHelper::baseColor());
|
||||
#ifdef Q_OS_UNIX
|
||||
m_page->terminalEdit->setText(ConsoleProcess::terminalEmulator(Core::ICore::instance()->settings()));
|
||||
@ -95,12 +139,15 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
|
||||
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());
|
||||
#ifdef Q_OS_UNIX
|
||||
ConsoleProcess::setTerminalEmulator(Core::ICore::instance()->settings(),
|
||||
m_page->terminalEdit->text());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void GeneralSettings::finish()
|
||||
@ -143,3 +190,29 @@ void GeneralSettings::showHelpForExternalEditor()
|
||||
mb->show();
|
||||
#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((QWidget*)Core::ICore::instance()->mainWindow(), tr("Restart required"),
|
||||
tr("The language change will take effect after a restart of the OpenPilot GCS."));
|
||||
}
|
||||
if (locale.isEmpty())
|
||||
settings->remove(QLatin1String("General/OverrideLanguage"));
|
||||
else
|
||||
settings->setValue(QLatin1String("General/OverrideLanguage"), locale);
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void resetInterfaceColor();
|
||||
void resetLanguage();
|
||||
void resetExternalEditor();
|
||||
void showHelpForExternalEditor();
|
||||
#ifdef Q_OS_UNIX
|
||||
@ -64,8 +65,13 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
void fillLanguageBox() const;
|
||||
QString language() const;
|
||||
void setLanguage(const QString&);
|
||||
Ui::GeneralSettings *m_page;
|
||||
QPointer<QWidget> m_dialog;
|
||||
QList<QTextCodec *> m_codecs;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@ -17,21 +17,21 @@
|
||||
<string>General settings</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="terminalLabel">
|
||||
<property name="text">
|
||||
<string>Terminal:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>External editor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<item row="10" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>When files are externally modified:</string>
|
||||
@ -41,7 +41,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="terminalEdit"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
@ -51,7 +51,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<item row="2" column="2">
|
||||
<widget class="QToolButton" name="resetTerminalButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset to default</string>
|
||||
@ -60,15 +60,15 @@
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="core.qrc">
|
||||
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<item row="8" column="1">
|
||||
<widget class="QLineEdit" name="externalEditorEdit"/>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<item row="8" column="2">
|
||||
<widget class="QToolButton" name="resetEditorButton">
|
||||
<property name="toolTip">
|
||||
<string>Reset to default</string>
|
||||
@ -77,12 +77,12 @@
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="core.qrc">
|
||||
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="3">
|
||||
<item row="8" column="3">
|
||||
<widget class="QToolButton" name="helpExternalEditorButton">
|
||||
<property name="text">
|
||||
<string>?</string>
|
||||
@ -104,7 +104,7 @@
|
||||
<string>R</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="core.qrc">
|
||||
<normaloff>:/core/images/reset.png</normaloff>:/core/images/reset.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@ -144,7 +144,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<item row="10" column="1">
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="margin">
|
||||
@ -194,6 +194,33 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Language:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="languageBox"/>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
@ -219,6 +246,8 @@
|
||||
<header>utils/qtcolorbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="core.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -174,12 +174,20 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QSettings *ICore::settings() const
|
||||
\fn QSettings *ICore::settings(QSettings::UserScope scope) const
|
||||
\brief Returns the application's main settings object.
|
||||
|
||||
You can use it to retrieve or set application wide settings
|
||||
(in contrast to session or project specific settings).
|
||||
|
||||
If \a scope is QSettings::UserScope (the default), the
|
||||
users settings will be read from the users settings, with
|
||||
a fallback to global settings provided with Qt Creator.
|
||||
|
||||
If \a scope is QSettings::SystemScope, only the system settings
|
||||
shipped with the current version of Qt Creator will be read. This
|
||||
functionality exists for internal purposes only.
|
||||
|
||||
\see settingsDatabase()
|
||||
*/
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "core_global.h"
|
||||
#include <QtCore/QObject>
|
||||
#include <QSettings>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QMainWindow;
|
||||
@ -84,7 +85,7 @@ public:
|
||||
virtual UAVGadgetInstanceManager *uavGadgetInstanceManager() const = 0;
|
||||
virtual MimeDatabase *mimeDatabase() const = 0;
|
||||
|
||||
virtual QSettings *settings() const = 0;
|
||||
virtual QSettings *settings(QSettings::Scope scope = QSettings::UserScope) const = 0;
|
||||
virtual SettingsDatabase *settingsDatabase() const = 0;
|
||||
virtual void readMainSettings(QSettings* qs) = 0;
|
||||
virtual void saveMainSettings(QSettings* qs) = 0;
|
||||
|
@ -109,8 +109,11 @@ 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("OpenPilot"), QLatin1String("OpenPilotGCS"), this)),
|
||||
m_globalSettings(new QSettings(QSettings::IniFormat, QSettings::SystemScope,
|
||||
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"), this)),
|
||||
m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
|
||||
QLatin1String("OpenPilotGCS"),
|
||||
this)),
|
||||
@ -785,6 +788,14 @@ MessageManager *MainWindow::messageManager() const
|
||||
return m_messageManager;
|
||||
}
|
||||
|
||||
QSettings *MainWindow::settings(QSettings::Scope scope) const
|
||||
{
|
||||
if (scope == QSettings::UserScope)
|
||||
return m_settings;
|
||||
else
|
||||
return m_globalSettings;
|
||||
}
|
||||
|
||||
VariableManager *MainWindow::variableManager() const
|
||||
{
|
||||
return m_variableManager;
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "eventfilteringmainwindow.h"
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QSettings>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSettings;
|
||||
@ -106,7 +107,7 @@ public:
|
||||
Core::ModeManager *modeManager() const;
|
||||
Core::MimeDatabase *mimeDatabase() const;
|
||||
|
||||
inline QSettings *settings() const { return m_settings; }
|
||||
QSettings *settings(QSettings::Scope scope) const;
|
||||
inline SettingsDatabase *settingsDatabase() const { return m_settingsDatabase; }
|
||||
IContext * currentContextObject() const;
|
||||
QStatusBar *statusBar() const;
|
||||
@ -170,6 +171,7 @@ private:
|
||||
QList<int> m_globalContext;
|
||||
QList<int> m_additionalContexts;
|
||||
QSettings *m_settings;
|
||||
QSettings *m_globalSettings;
|
||||
SettingsDatabase *m_settingsDatabase;
|
||||
ActionManagerPrivate *m_actionManager;
|
||||
MessageManager *m_messageManager;
|
||||
|
Loading…
Reference in New Issue
Block a user