1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-232 gcs configuration: Override configuration on comand line

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2725 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
erhard 2011-02-04 21:24:55 +00:00 committed by erhard
parent d377b417df
commit b0cc3d1f5f
4 changed files with 466 additions and 422 deletions

View File

@ -1,332 +1,357 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file main.cpp * @file main.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @brief * @brief
* @see The GNU Public License (GPL) Version 3 * @see The GNU Public License (GPL) Version 3
* @defgroup * @defgroup
* @{ * @{
* *
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "qtsingleapplication.h" #include "qtsingleapplication.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h> #include <extensionsystem/pluginspec.h>
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QLibraryInfo> #include <QtCore/QLibraryInfo>
#include <QtCore/QTranslator> #include <QtCore/QTranslator>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include <QtGui/QMessageBox> #include <QtGui/QMessageBox>
#include <QtGui/QApplication> #include <QtGui/QApplication>
#include <QtGui/QMainWindow> #include <QtGui/QMainWindow>
enum { OptionIndent = 4, DescriptionIndent = 24 }; enum { OptionIndent = 4, DescriptionIndent = 24 };
static const char *appNameC = "OpenPilot GCS"; static const char *appNameC = "OpenPilot GCS";
static const char *corePluginNameC = "Core"; static const char *corePluginNameC = "Core";
static const char *fixedOptionsC = static const char *fixedOptionsC =
" [OPTION]... [FILE]...\n" " [OPTION]... [FILE]...\n"
"Options:\n" "Options:\n"
" -help Display this help\n" " -help Display this help\n"
" -version Display program version\n" " -version Display program version\n"
" -client Attempt to connect to already running instance\n"; " -client Attempt to connect to already running instance\n"
" -D key=value Override preference e.g: -D General/OverrideLanguage=de\n";
static const char *HELP_OPTION1 = "-h";
static const char *HELP_OPTION2 = "-help"; static const char *HELP_OPTION1 = "-h";
static const char *HELP_OPTION3 = "/h"; static const char *HELP_OPTION2 = "-help";
static const char *HELP_OPTION4 = "--help"; static const char *HELP_OPTION3 = "/h";
static const char *VERSION_OPTION = "-version"; static const char *HELP_OPTION4 = "--help";
static const char *CLIENT_OPTION = "-client"; static const char *VERSION_OPTION = "-version";
static const char *CLIENT_OPTION = "-client";
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet; static const char *SETTING_OPTION = "-D";
// Helpers for displaying messages. Note that there is no console on Windows. typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
#ifdef Q_OS_WIN
// Format as <pre> HTML // Helpers for displaying messages. Note that there is no console on Windows.
static inline void toHtml(QString &t) #ifdef Q_OS_WIN
{ // Format as <pre> HTML
t.replace(QLatin1Char('&'), QLatin1String("&amp;")); static inline void toHtml(QString &t)
t.replace(QLatin1Char('<'), QLatin1String("&lt;")); {
t.replace(QLatin1Char('>'), QLatin1String("&gt;")); t.replace(QLatin1Char('&'), QLatin1String("&amp;"));
t.insert(0, QLatin1String("<html><pre>")); t.replace(QLatin1Char('<'), QLatin1String("&lt;"));
t.append(QLatin1String("</pre></html>")); t.replace(QLatin1Char('>'), QLatin1String("&gt;"));
} t.insert(0, QLatin1String("<html><pre>"));
t.append(QLatin1String("</pre></html>"));
static void displayHelpText(QString t) // No console on Windows. }
{
toHtml(t); static void displayHelpText(QString t) // No console on Windows.
QMessageBox::information(0, QLatin1String(appNameC), t); {
} toHtml(t);
QMessageBox::information(0, QLatin1String(appNameC), t);
static void displayError(const QString &t) // No console on Windows. }
{
QMessageBox::critical(0, QLatin1String(appNameC), t); static void displayError(const QString &t) // No console on Windows.
} {
QMessageBox::critical(0, QLatin1String(appNameC), t);
#else }
static void displayHelpText(const QString &t) #else
{
qWarning("%s", qPrintable(t)); static void displayHelpText(const QString &t)
} {
qWarning("%s", qPrintable(t));
static void displayError(const QString &t) }
{
qCritical("%s", qPrintable(t)); static void displayError(const QString &t)
} {
qCritical("%s", qPrintable(t));
#endif }
static void printVersion(const ExtensionSystem::PluginSpec *coreplugin, #endif
const ExtensionSystem::PluginManager &pm)
{ static void printVersion(const ExtensionSystem::PluginSpec *coreplugin,
QString version; const ExtensionSystem::PluginManager &pm)
QTextStream str(&version); {
str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n"; QString version;
pm.formatPluginVersions(str); QTextStream str(&version);
str << '\n' << coreplugin->copyright() << '\n'; str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n";
displayHelpText(version); pm.formatPluginVersions(str);
} str << '\n' << coreplugin->copyright() << '\n';
displayHelpText(version);
static void printHelp(const QString &a0, const ExtensionSystem::PluginManager &pm) }
{
QString help; static void printHelp(const QString &a0, const ExtensionSystem::PluginManager &pm)
QTextStream str(&help); {
str << "Usage: " << a0 << fixedOptionsC; QString help;
ExtensionSystem::PluginManager::formatOptions(str, OptionIndent, DescriptionIndent); QTextStream str(&help);
pm.formatPluginOptions(str, OptionIndent, DescriptionIndent); str << "Usage: " << a0 << fixedOptionsC;
displayHelpText(help); ExtensionSystem::PluginManager::formatOptions(str, OptionIndent, DescriptionIndent);
} pm.formatPluginOptions(str, OptionIndent, DescriptionIndent);
displayHelpText(help);
static inline QString msgCoreLoadFailure(const QString &why) }
{
return QCoreApplication::translate("Application", "Failed to load core: %1").arg(why); static inline QString msgCoreLoadFailure(const QString &why)
} {
return QCoreApplication::translate("Application", "Failed to load core: %1").arg(why);
static inline QString msgSendArgumentFailed() }
{
return QCoreApplication::translate("Application", "Unable to send command line arguments to the already running instance. It appears to be not responding."); static inline QString msgSendArgumentFailed()
} {
return QCoreApplication::translate("Application", "Unable to send command line arguments to the already running instance. It appears to be not responding.");
// Prepare a remote argument: If it is a relative file, add the current directory }
// since the the central instance might be running in a different directory.
// Prepare a remote argument: If it is a relative file, add the current directory
static inline QString prepareRemoteArgument(const QString &a) // since the the central instance might be running in a different directory.
{
QFileInfo fi(a); static inline QString prepareRemoteArgument(const QString &a)
if (!fi.exists()) {
return a; QFileInfo fi(a);
if (fi.isRelative()) if (!fi.exists())
return fi.absoluteFilePath(); return a;
return a; if (fi.isRelative())
} return fi.absoluteFilePath();
return a;
// Send the arguments to an already running instance of OpenPilot GCS }
static bool sendArguments(SharedTools::QtSingleApplication &app, const QStringList &arguments)
{ // Send the arguments to an already running instance of OpenPilot GCS
if (!arguments.empty()) { static bool sendArguments(SharedTools::QtSingleApplication &app, const QStringList &arguments)
// Send off arguments {
const QStringList::const_iterator acend = arguments.constEnd(); if (!arguments.empty()) {
for (QStringList::const_iterator it = arguments.constBegin(); it != acend; ++it) { // Send off arguments
if (!app.sendMessage(prepareRemoteArgument(*it))) { const QStringList::const_iterator acend = arguments.constEnd();
displayError(msgSendArgumentFailed()); for (QStringList::const_iterator it = arguments.constBegin(); it != acend; ++it) {
return false; if (!app.sendMessage(prepareRemoteArgument(*it))) {
} displayError(msgSendArgumentFailed());
} return false;
} }
// Special empty argument means: Show and raise (the slot just needs to be triggered) }
if (!app.sendMessage(QString())) { }
displayError(msgSendArgumentFailed()); // Special empty argument means: Show and raise (the slot just needs to be triggered)
return false; if (!app.sendMessage(QString())) {
} displayError(msgSendArgumentFailed());
return true; return false;
} }
return true;
static inline QStringList getPluginPaths() }
{
QStringList rc; static inline QStringList getPluginPaths()
// Figure out root: Up one from 'bin' {
QDir rootDir = QApplication::applicationDirPath(); QStringList rc;
rootDir.cdUp(); // Figure out root: Up one from 'bin'
const QString rootDirPath = rootDir.canonicalPath(); QDir rootDir = QApplication::applicationDirPath();
// 1) "plugins" (Win/Linux) rootDir.cdUp();
QString pluginPath = rootDirPath; const QString rootDirPath = rootDir.canonicalPath();
pluginPath += QLatin1Char('/'); // 1) "plugins" (Win/Linux)
pluginPath += QLatin1String(GCS_LIBRARY_BASENAME); QString pluginPath = rootDirPath;
pluginPath += QLatin1Char('/'); pluginPath += QLatin1Char('/');
pluginPath += QLatin1String("openpilotgcs"); pluginPath += QLatin1String(GCS_LIBRARY_BASENAME);
pluginPath += QLatin1Char('/'); pluginPath += QLatin1Char('/');
pluginPath += QLatin1String("plugins"); pluginPath += QLatin1String("openpilotgcs");
rc.push_back(pluginPath); pluginPath += QLatin1Char('/');
// 2) "PlugIns" (OS X) pluginPath += QLatin1String("plugins");
pluginPath = rootDirPath; rc.push_back(pluginPath);
pluginPath += QLatin1Char('/'); // 2) "PlugIns" (OS X)
pluginPath += QLatin1String("PlugIns"); pluginPath = rootDirPath;
rc.push_back(pluginPath); pluginPath += QLatin1Char('/');
return rc; pluginPath += QLatin1String("PlugIns");
} rc.push_back(pluginPath);
return rc;
#ifdef Q_OS_MAC }
# define SHARE_PATH "/../Resources"
#else #ifdef Q_OS_MAC
# define SHARE_PATH "/../share/openpilotgcs" # define SHARE_PATH "/../Resources"
#endif #else
# define SHARE_PATH "/../share/openpilotgcs"
int main(int argc, char **argv) #endif
{
#ifdef Q_OS_MAC static void overrideSettings(QSettings &settings, int argc, char **argv){
// increase the number of file that can be opened in OpenPilot GCS
struct rlimit rl; QMap<QString, QString> settingOptions;
getrlimit(RLIMIT_NOFILE, &rl); // Options like -DMy/setting=test
rl.rlim_cur = rl.rlim_max; QRegExp rx("([^=]+)=(.*)");
setrlimit(RLIMIT_NOFILE, &rl);
#endif int i = 0;
while( i < argc ){
SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv); if ( QString("-D").compare(QString(argv[i++])) == 0 ){
if ( rx.indexIn(argv[i]) > -1 ){
QTranslator translator; settingOptions.insert(rx.cap(1), rx.cap(2));
QTranslator qtTranslator; }
QString locale = QLocale::system().name(); }
}
// Must be done before any QSettings class is created QList<QString> keys = settingOptions.keys();
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, foreach ( QString key, keys ){
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH)); settings.setValue(key, settingOptions.value(key));
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp }
const QSettings settings(QSettings::IniFormat, QSettings::UserScope, settings.sync();
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS")); }
locale = settings.value("General/OverrideLanguage", locale).toString();
int main(int argc, char **argv)
{
const QString &creatorTrPath = QCoreApplication::applicationDirPath() #ifdef Q_OS_MAC
+ QLatin1String(SHARE_PATH "/translations"); // increase the number of file that can be opened in OpenPilot GCS
if (translator.load(QLatin1String("openpilotgcs_") + locale, creatorTrPath)) { struct rlimit rl;
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath); getrlimit(RLIMIT_NOFILE, &rl);
const QString &qtTrFile = QLatin1String("qt_") + locale; rl.rlim_cur = rl.rlim_max;
// Binary installer puts Qt tr files into creatorTrPath setrlimit(RLIMIT_NOFILE, &rl);
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) { #endif
app.installTranslator(&translator);
app.installTranslator(&qtTranslator); SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv);
app.setProperty("qtc_locale", locale);
} else { QString locale = QLocale::system().name();
translator.load(QString()); // unload()
} // Must be done before any QSettings class is created
} QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH));
// Load // keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
ExtensionSystem::PluginManager pluginManager; QSettings settings(QSettings::IniFormat, QSettings::UserScope,
pluginManager.setFileExtension(QLatin1String("pluginspec")); QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
const QStringList pluginPaths = getPluginPaths(); overrideSettings(settings, argc, argv);
pluginManager.setPluginPaths(pluginPaths); locale = settings.value("General/OverrideLanguage", locale).toString();
const QStringList arguments = app.arguments(); QTranslator translator;
QMap<QString, QString> foundAppOptions; QTranslator qtTranslator;
if (arguments.size() > 1) {
QMap<QString, bool> appOptions; const QString &creatorTrPath = QCoreApplication::applicationDirPath()
appOptions.insert(QLatin1String(HELP_OPTION1), false); + QLatin1String(SHARE_PATH "/translations");
appOptions.insert(QLatin1String(HELP_OPTION2), false); if (translator.load(QLatin1String("openpilotgcs_") + locale, creatorTrPath)) {
appOptions.insert(QLatin1String(HELP_OPTION3), false); const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
appOptions.insert(QLatin1String(HELP_OPTION4), false); const QString &qtTrFile = QLatin1String("qt_") + locale;
appOptions.insert(QLatin1String(VERSION_OPTION), false); // Binary installer puts Qt tr files into creatorTrPath
appOptions.insert(QLatin1String(CLIENT_OPTION), false); if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) {
QString errorMessage; QCoreApplication::installTranslator(&translator);
if (!pluginManager.parseOptions(arguments, QCoreApplication::installTranslator(&qtTranslator);
appOptions, } else {
&foundAppOptions, translator.load(QString()); // unload()
&errorMessage)) { }
displayError(errorMessage); }
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager); app.setProperty("qtc_locale", locale); // Do we need this?
return -1;
} // Load
} ExtensionSystem::PluginManager pluginManager;
pluginManager.setFileExtension(QLatin1String("pluginspec"));
const PluginSpecSet plugins = pluginManager.plugins();
ExtensionSystem::PluginSpec *coreplugin = 0; const QStringList pluginPaths = getPluginPaths();
foreach (ExtensionSystem::PluginSpec *spec, plugins) { pluginManager.setPluginPaths(pluginPaths);
if (spec->name() == QLatin1String(corePluginNameC)) {
coreplugin = spec; const QStringList arguments = app.arguments();
break; QMap<QString, QString> foundAppOptions;
} if (arguments.size() > 1) {
} QMap<QString, bool> appOptions;
if (!coreplugin) { appOptions.insert(QLatin1String(HELP_OPTION1), false);
QString nativePaths = QDir::toNativeSeparators(pluginPaths.join(QLatin1String(","))); appOptions.insert(QLatin1String(HELP_OPTION2), false);
const QString reason = QCoreApplication::translate("Application", "Could not find 'Core.pluginspec' in %1").arg(nativePaths); appOptions.insert(QLatin1String(HELP_OPTION3), false);
displayError(msgCoreLoadFailure(reason)); appOptions.insert(QLatin1String(HELP_OPTION4), false);
return 1; appOptions.insert(QLatin1String(VERSION_OPTION), false);
} appOptions.insert(QLatin1String(CLIENT_OPTION), false);
if (coreplugin->hasError()) { appOptions.insert(QLatin1String(SETTING_OPTION), true);
displayError(msgCoreLoadFailure(coreplugin->errorString())); QString errorMessage;
return 1; if (!pluginManager.parseOptions(arguments,
} appOptions,
if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) { &foundAppOptions,
printVersion(coreplugin, pluginManager); &errorMessage)) {
return 0; displayError(errorMessage);
} printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
if (foundAppOptions.contains(QLatin1String(HELP_OPTION1)) return -1;
|| foundAppOptions.contains(QLatin1String(HELP_OPTION2)) }
|| foundAppOptions.contains(QLatin1String(HELP_OPTION3)) }
|| foundAppOptions.contains(QLatin1String(HELP_OPTION4))) {
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager); const PluginSpecSet plugins = pluginManager.plugins();
return 0; ExtensionSystem::PluginSpec *coreplugin = 0;
} foreach (ExtensionSystem::PluginSpec *spec, plugins) {
if (spec->name() == QLatin1String(corePluginNameC)) {
const bool isFirstInstance = !app.isRunning(); coreplugin = spec;
if (!isFirstInstance && foundAppOptions.contains(QLatin1String(CLIENT_OPTION))) break;
return sendArguments(app, pluginManager.arguments()) ? 0 : -1; }
}
pluginManager.loadPlugins(); if (!coreplugin) {
if (coreplugin->hasError()) { QString nativePaths = QDir::toNativeSeparators(pluginPaths.join(QLatin1String(",")));
displayError(msgCoreLoadFailure(coreplugin->errorString())); const QString reason = QCoreApplication::translate("Application", "Could not find 'Core.pluginspec' in %1").arg(nativePaths);
return 1; displayError(msgCoreLoadFailure(reason));
} return 1;
{ }
QStringList errors; if (coreplugin->hasError()) {
foreach (ExtensionSystem::PluginSpec *p, pluginManager.plugins()) displayError(msgCoreLoadFailure(coreplugin->errorString()));
if (p->hasError()) return 1;
errors.append(p->errorString()); }
if (!errors.isEmpty()) if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) {
QMessageBox::warning(0, printVersion(coreplugin, pluginManager);
QCoreApplication::translate("Application", "OpenPilot GCS - Plugin loader messages"), return 0;
errors.join(QString::fromLatin1("\n\n"))); }
} if (foundAppOptions.contains(QLatin1String(HELP_OPTION1))
|| foundAppOptions.contains(QLatin1String(HELP_OPTION2))
if (isFirstInstance) { || foundAppOptions.contains(QLatin1String(HELP_OPTION3))
// Set up lock and remote arguments for the first instance only. || foundAppOptions.contains(QLatin1String(HELP_OPTION4))) {
// Silently fallback to unconnected instances for any subsequent printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
// instances. return 0;
app.initialize(); }
QObject::connect(&app, SIGNAL(messageReceived(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString)));
} const bool isFirstInstance = !app.isRunning();
QObject::connect(&app, SIGNAL(fileOpenRequest(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString))); if (!isFirstInstance && foundAppOptions.contains(QLatin1String(CLIENT_OPTION)))
return sendArguments(app, pluginManager.arguments()) ? 0 : -1;
// Do this after the event loop has started
QTimer::singleShot(100, &pluginManager, SLOT(startTests())); pluginManager.loadPlugins();
return app.exec(); if (coreplugin->hasError()) {
} displayError(msgCoreLoadFailure(coreplugin->errorString()));
return 1;
}
{
QStringList errors;
foreach (ExtensionSystem::PluginSpec *p, pluginManager.plugins())
if (p->hasError())
errors.append(p->errorString());
if (!errors.isEmpty())
QMessageBox::warning(0,
QCoreApplication::translate("Application", "OpenPilot GCS - Plugin loader messages"),
errors.join(QString::fromLatin1("\n\n")));
}
if (isFirstInstance) {
// Set up lock and remote arguments for the first instance only.
// Silently fallback to unconnected instances for any subsequent
// instances.
app.initialize();
QObject::connect(&app, SIGNAL(messageReceived(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString)));
}
QObject::connect(&app, SIGNAL(fileOpenRequest(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString)));
// Do this after the event loop has started
QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
return app.exec();
}

View File

@ -111,8 +111,6 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
QWidget *w = new QWidget(parent); QWidget *w = new QWidget(parent);
m_page->setupUi(w); m_page->setupUi(w);
/* TODO: Clean this: settings not used, Core::ICore::instance()->settings() shouldn't be used, since not externally configurable */
QSettings* settings = Core::ICore::instance()->settings();
fillLanguageBox(); fillLanguageBox();
m_page->colorButton->setColor(StyleHelper::baseColor()); m_page->colorButton->setColor(StyleHelper::baseColor());
@ -156,6 +154,26 @@ void GeneralSettings::finish()
delete m_page; delete m_page;
} }
void GeneralSettings::readSettings(QSettings* qs)
{
qs->beginGroup(QLatin1String("General"));
m_language = qs->value(QLatin1String("OverrideLanguage"),QLocale::system().name()).toString();
qs->endGroup();
}
void GeneralSettings::saveSettings(QSettings* qs)
{
qs->beginGroup(QLatin1String("General"));
if (m_language.isEmpty())
qs->remove(QLatin1String("OverrideLanguage"));
else
qs->setValue(QLatin1String("OverrideLanguage"), m_language);
qs->endGroup();
}
void GeneralSettings::resetInterfaceColor() void GeneralSettings::resetInterfaceColor()
{ {
m_page->colorButton->setColor(0x666666); m_page->colorButton->setColor(0x666666);
@ -200,20 +218,15 @@ void GeneralSettings::resetLanguage()
QString GeneralSettings::language() const QString GeneralSettings::language() const
{ {
QSettings* settings = Core::ICore::instance()->settings(); return m_language;
return settings->value(QLatin1String("General/OverrideLanguage")).toString();
} }
void GeneralSettings::setLanguage(const QString &locale) void GeneralSettings::setLanguage(const QString &locale)
{ {
QSettings* settings = Core::ICore::instance()->settings(); if (m_language != locale)
if (settings->value(QLatin1String("General/OverrideLanguage")).toString() != locale)
{ {
QMessageBox::information((QWidget*)Core::ICore::instance()->mainWindow(), tr("Restart required"), QMessageBox::information((QWidget*)Core::ICore::instance()->mainWindow(), tr("Restart required"),
tr("The language change will take effect after a restart of the OpenPilot GCS.")); tr("The language change will take effect after a restart of the OpenPilot GCS."));
m_language = locale;
} }
if (locale.isEmpty())
settings->remove(QLatin1String("General/OverrideLanguage"));
else
settings->setValue(QLatin1String("General/OverrideLanguage"), locale);
} }

View File

@ -1,80 +1,84 @@
/** /**
****************************************************************************** ******************************************************************************
* *
* @file generalsettings.h * @file generalsettings.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
* @addtogroup GCSPlugins GCS Plugins * @addtogroup GCSPlugins GCS Plugins
* @{ * @{
* @addtogroup CorePlugin Core Plugin * @addtogroup CorePlugin Core Plugin
* @{ * @{
* @brief The Core GCS plugin * @brief The Core GCS plugin
*****************************************************************************/ *****************************************************************************/
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but * This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU General Public License along * You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef GENERALSETTINGS_H #ifndef GENERALSETTINGS_H
#define GENERALSETTINGS_H #define GENERALSETTINGS_H
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QtCore/QPointer> #include <QtCore/QPointer>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QSettings>
namespace Core {
namespace Internal { namespace Core {
namespace Internal {
namespace Ui {
class GeneralSettings; namespace Ui {
} class GeneralSettings;
}
class GeneralSettings : public IOptionsPage
{ class GeneralSettings : public IOptionsPage
Q_OBJECT {
Q_OBJECT
public:
GeneralSettings(); public:
GeneralSettings();
QString id() const;
QString trName() const; QString id() const;
QString category() const; QString trName() const;
QString trCategory() const; QString category() const;
QWidget* createPage(QWidget *parent); QString trCategory() const;
void apply(); QWidget* createPage(QWidget *parent);
void finish(); void apply();
void finish();
private slots: void readSettings(QSettings* qs);
void resetInterfaceColor(); void saveSettings(QSettings* qs);
void resetLanguage();
void resetExternalEditor(); private slots:
void showHelpForExternalEditor(); void resetInterfaceColor();
#ifdef Q_OS_UNIX void resetLanguage();
void resetTerminal(); void resetExternalEditor();
#endif void showHelpForExternalEditor();
#ifdef Q_OS_UNIX
private: void resetTerminal();
void fillLanguageBox() const; #endif
QString language() const;
void setLanguage(const QString&); private:
Ui::GeneralSettings *m_page; void fillLanguageBox() const;
QPointer<QWidget> m_dialog; QString language() const;
QList<QTextCodec *> m_codecs; void setLanguage(const QString&);
Ui::GeneralSettings *m_page;
}; QString m_language;
QPointer<QWidget> m_dialog;
} // namespace Internal QList<QTextCodec *> m_codecs;
} // namespace Core
};
#endif // GENERALSETTINGS_H
} // namespace Internal
} // namespace Core
#endif // GENERALSETTINGS_H

View File

@ -1009,6 +1009,7 @@ void MainWindow::readSettings(QSettings* qs)
qs = m_settings; qs = m_settings;
} }
m_generalSettings->readSettings(qs);
m_actionManager->readSettings(qs); m_actionManager->readSettings(qs);
qs->beginGroup(QLatin1String(settingsGroup)); qs->beginGroup(QLatin1String(settingsGroup));
@ -1069,6 +1070,7 @@ void MainWindow::saveSettings(QSettings* qs)
m_viewManager->saveSettings(qs); m_viewManager->saveSettings(qs);
m_actionManager->saveSettings(qs); m_actionManager->saveSettings(qs);
m_generalSettings->saveSettings(qs);
} }