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:
parent
d377b417df
commit
b0cc3d1f5f
@ -55,7 +55,8 @@ static const char *fixedOptionsC =
|
|||||||
"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_OPTION1 = "-h";
|
||||||
static const char *HELP_OPTION2 = "-help";
|
static const char *HELP_OPTION2 = "-help";
|
||||||
@ -63,6 +64,7 @@ static const char *HELP_OPTION3 = "/h";
|
|||||||
static const char *HELP_OPTION4 = "--help";
|
static const char *HELP_OPTION4 = "--help";
|
||||||
static const char *VERSION_OPTION = "-version";
|
static const char *VERSION_OPTION = "-version";
|
||||||
static const char *CLIENT_OPTION = "-client";
|
static const char *CLIENT_OPTION = "-client";
|
||||||
|
static const char *SETTING_OPTION = "-D";
|
||||||
|
|
||||||
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
|
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
|
||||||
|
|
||||||
@ -198,6 +200,27 @@ static inline QStringList getPluginPaths()
|
|||||||
# define SHARE_PATH "/../share/openpilotgcs"
|
# define SHARE_PATH "/../share/openpilotgcs"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void overrideSettings(QSettings &settings, int argc, char **argv){
|
||||||
|
|
||||||
|
QMap<QString, QString> settingOptions;
|
||||||
|
// Options like -DMy/setting=test
|
||||||
|
QRegExp rx("([^=]+)=(.*)");
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while( i < argc ){
|
||||||
|
if ( QString("-D").compare(QString(argv[i++])) == 0 ){
|
||||||
|
if ( rx.indexIn(argv[i]) > -1 ){
|
||||||
|
settingOptions.insert(rx.cap(1), rx.cap(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QList<QString> keys = settingOptions.keys();
|
||||||
|
foreach ( QString key, keys ){
|
||||||
|
settings.setValue(key, settingOptions.value(key));
|
||||||
|
}
|
||||||
|
settings.sync();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
@ -210,18 +233,20 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv);
|
SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv);
|
||||||
|
|
||||||
QTranslator translator;
|
|
||||||
QTranslator qtTranslator;
|
|
||||||
QString locale = QLocale::system().name();
|
QString locale = QLocale::system().name();
|
||||||
|
|
||||||
// Must be done before any QSettings class is created
|
// Must be done before any QSettings class is created
|
||||||
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
|
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
|
||||||
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH));
|
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH));
|
||||||
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
||||||
const QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
|
||||||
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
|
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS"));
|
||||||
|
|
||||||
|
overrideSettings(settings, argc, argv);
|
||||||
locale = settings.value("General/OverrideLanguage", locale).toString();
|
locale = settings.value("General/OverrideLanguage", locale).toString();
|
||||||
|
|
||||||
|
QTranslator translator;
|
||||||
|
QTranslator qtTranslator;
|
||||||
|
|
||||||
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
|
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
|
||||||
+ QLatin1String(SHARE_PATH "/translations");
|
+ QLatin1String(SHARE_PATH "/translations");
|
||||||
@ -230,13 +255,13 @@ int main(int argc, char **argv)
|
|||||||
const QString &qtTrFile = QLatin1String("qt_") + locale;
|
const QString &qtTrFile = QLatin1String("qt_") + locale;
|
||||||
// Binary installer puts Qt tr files into creatorTrPath
|
// Binary installer puts Qt tr files into creatorTrPath
|
||||||
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) {
|
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) {
|
||||||
app.installTranslator(&translator);
|
QCoreApplication::installTranslator(&translator);
|
||||||
app.installTranslator(&qtTranslator);
|
QCoreApplication::installTranslator(&qtTranslator);
|
||||||
app.setProperty("qtc_locale", locale);
|
|
||||||
} else {
|
} else {
|
||||||
translator.load(QString()); // unload()
|
translator.load(QString()); // unload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.setProperty("qtc_locale", locale); // Do we need this?
|
||||||
|
|
||||||
// Load
|
// Load
|
||||||
ExtensionSystem::PluginManager pluginManager;
|
ExtensionSystem::PluginManager pluginManager;
|
||||||
@ -255,6 +280,7 @@ int main(int argc, char **argv)
|
|||||||
appOptions.insert(QLatin1String(HELP_OPTION4), false);
|
appOptions.insert(QLatin1String(HELP_OPTION4), false);
|
||||||
appOptions.insert(QLatin1String(VERSION_OPTION), false);
|
appOptions.insert(QLatin1String(VERSION_OPTION), false);
|
||||||
appOptions.insert(QLatin1String(CLIENT_OPTION), false);
|
appOptions.insert(QLatin1String(CLIENT_OPTION), false);
|
||||||
|
appOptions.insert(QLatin1String(SETTING_OPTION), true);
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
if (!pluginManager.parseOptions(arguments,
|
if (!pluginManager.parseOptions(arguments,
|
||||||
appOptions,
|
appOptions,
|
||||||
@ -329,4 +355,3 @@ int main(int argc, char **argv)
|
|||||||
QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
|
QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#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 Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@ -54,6 +55,8 @@ public:
|
|||||||
QWidget* createPage(QWidget *parent);
|
QWidget* createPage(QWidget *parent);
|
||||||
void apply();
|
void apply();
|
||||||
void finish();
|
void finish();
|
||||||
|
void readSettings(QSettings* qs);
|
||||||
|
void saveSettings(QSettings* qs);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void resetInterfaceColor();
|
void resetInterfaceColor();
|
||||||
@ -69,6 +72,7 @@ private:
|
|||||||
QString language() const;
|
QString language() const;
|
||||||
void setLanguage(const QString&);
|
void setLanguage(const QString&);
|
||||||
Ui::GeneralSettings *m_page;
|
Ui::GeneralSettings *m_page;
|
||||||
|
QString m_language;
|
||||||
QPointer<QWidget> m_dialog;
|
QPointer<QWidget> m_dialog;
|
||||||
QList<QTextCodec *> m_codecs;
|
QList<QTextCodec *> m_codecs;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user