mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
Merge remote-tracking branch 'origin/filnet/OP-769_remove_hardcoded_en_locale' into next
This commit is contained in:
commit
78d47e4185
@ -26,6 +26,57 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/*
|
||||
The GCS locale is set to the system locale by default unless the "hidden" setting General/Locale has a value.
|
||||
The user can not change General/Locale from the Options dialog.
|
||||
|
||||
The GCS language will default to the GCS locale unless the General/OverrideLanguage has a value.
|
||||
The user can change General/OverrideLanguage to any available language from the Options dialog.
|
||||
|
||||
Both General/Locale and General/OverrideLanguage can be set from the command line or through the the factory defaults file.
|
||||
|
||||
The -D option is used to permanently set a user setting.
|
||||
|
||||
The -reset switch will clear all the user settings and will trigger a reload of the factory defaults.
|
||||
|
||||
You can combine it with the -config-file=<file> command line argument to quickly switch between multiple settings files.
|
||||
|
||||
[code]
|
||||
openpilotgcs -reset -config-file ./MyOpenPilotGCS.xml
|
||||
[/code]
|
||||
|
||||
Relative paths are relative to <install dir>/share/openpilotgcs/default_configurations/
|
||||
|
||||
The specified file will be used to load the factory defaults from but only when the user settings are empty.
|
||||
If the user settings are not empty the file will not be used.
|
||||
This switch is useful on the 1st run when the user settings are empty or in combination with -reset.
|
||||
|
||||
|
||||
Quickly switch configurations
|
||||
|
||||
[code]
|
||||
openpilotgcs -reset -config-file <relative or absolute path>
|
||||
[/code]
|
||||
|
||||
Configuring GCS from installer
|
||||
|
||||
The -D option is used to permanently set a user setting.
|
||||
|
||||
If the user chooses to start GCS at the end of the installer:
|
||||
|
||||
[code]
|
||||
openpilotgcs -D General/OverrideLanguage=de
|
||||
[/code]
|
||||
|
||||
If the user chooses not to start GCS at the end of the installer, you still need to configure GCS.
|
||||
In that case you can use -exit-after-config
|
||||
|
||||
[code]
|
||||
openpilotgcs -D General/OverrideLanguage=de -exit-after-config
|
||||
[/code]
|
||||
|
||||
*/
|
||||
|
||||
#include "qtsingleapplication.h"
|
||||
#include "utils/xmlconfig.h"
|
||||
#include "gcssplashscreen.h"
|
||||
@ -35,6 +86,7 @@
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include <QtCore/QDebug>
|
||||
@ -48,292 +100,415 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QSplashScreen>
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
namespace {
|
||||
|
||||
enum { OptionIndent = 4, DescriptionIndent = 24 };
|
||||
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
|
||||
typedef QMap<QString, bool> AppOptions;
|
||||
typedef QMap<QString, QString> AppOptionValues;
|
||||
|
||||
static const char *appNameC = "OpenPilot GCS";
|
||||
static const char *corePluginNameC = "Core";
|
||||
static const char *fixedOptionsC =
|
||||
" [OPTION]... [FILE]...\n"
|
||||
"Options:\n"
|
||||
" -help Display this help\n"
|
||||
" -version Display program version\n"
|
||||
" -client Attempt to connect to already running instance\n"
|
||||
" -clean-config Delete all existing configuration settings\n"
|
||||
" -exit-after-config Exit GCS after manipulating configuration settings\n"
|
||||
" -D key=value Override configuration settings e.g: -D General/OverrideLanguage=de\n"
|
||||
" -configfile=value Default configuration file to load if settings file is empty\n";
|
||||
static const char *HELP_OPTION1 = "-h";
|
||||
static const char *HELP_OPTION2 = "-help";
|
||||
static const char *HELP_OPTION3 = "/h";
|
||||
static const char *HELP_OPTION4 = "--help";
|
||||
static const char *VERSION_OPTION = "-version";
|
||||
static const char *CLIENT_OPTION = "-client";
|
||||
static const char *CONFIG_OPTION = "-D";
|
||||
static const char *CLEAN_CONFIG_OPTION = "-clean-config";
|
||||
static const char *EXIT_AFTER_CONFIG_OPTION = "-exit-after-config";
|
||||
const int OptionIndent = 4;
|
||||
const int DescriptionIndent = 24;
|
||||
|
||||
typedef QList<ExtensionSystem::PluginSpec *> PluginSpecSet;
|
||||
const QLatin1String APP_NAME("OpenPilot GCS");
|
||||
|
||||
// Helpers for displaying messages. Note that there is no console on Windows.
|
||||
#ifdef Q_OS_WIN
|
||||
// Format as <pre> HTML
|
||||
static inline void toHtml(QString &t)
|
||||
{
|
||||
t.replace(QLatin1Char('&'), QLatin1String("&"));
|
||||
t.replace(QLatin1Char('<'), QLatin1String("<"));
|
||||
t.replace(QLatin1Char('>'), QLatin1String(">"));
|
||||
t.insert(0, QLatin1String("<html><pre>"));
|
||||
t.append(QLatin1String("</pre></html>"));
|
||||
}
|
||||
const QLatin1String CORE_PLUGIN_NAME("Core");
|
||||
|
||||
static void displayHelpText(QString t) // No console on Windows.
|
||||
{
|
||||
toHtml(t);
|
||||
QMessageBox::information(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)
|
||||
{
|
||||
qWarning("%s", qPrintable(t));
|
||||
}
|
||||
|
||||
static void displayError(const QString &t)
|
||||
{
|
||||
qCritical("%s", qPrintable(t));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void printVersion(const ExtensionSystem::PluginSpec *coreplugin,
|
||||
const ExtensionSystem::PluginManager &pm)
|
||||
{
|
||||
QString version;
|
||||
QTextStream str(&version);
|
||||
str << '\n' << appNameC << ' ' << coreplugin->version()<< " based on Qt " << qVersion() << "\n\n";
|
||||
pm.formatPluginVersions(str);
|
||||
str << '\n' << coreplugin->copyright() << '\n';
|
||||
displayHelpText(version);
|
||||
}
|
||||
|
||||
static void printHelp(const QString &a0, const ExtensionSystem::PluginManager &pm)
|
||||
{
|
||||
QString help;
|
||||
QTextStream str(&help);
|
||||
str << "Usage: " << a0 << fixedOptionsC;
|
||||
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 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.
|
||||
|
||||
static inline QString prepareRemoteArgument(const QString &a)
|
||||
{
|
||||
QFileInfo fi(a);
|
||||
if (!fi.exists())
|
||||
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)
|
||||
{
|
||||
if (!arguments.empty()) {
|
||||
// Send off arguments
|
||||
const QStringList::const_iterator acend = arguments.constEnd();
|
||||
for (QStringList::const_iterator it = arguments.constBegin(); it != acend; ++it) {
|
||||
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());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline QStringList getPluginPaths()
|
||||
{
|
||||
QStringList rc;
|
||||
// Figure out root: Up one from 'bin'
|
||||
QDir rootDir = QApplication::applicationDirPath();
|
||||
rootDir.cdUp();
|
||||
const QString rootDirPath = rootDir.canonicalPath();
|
||||
// 1) "plugins" (Win/Linux)
|
||||
QString pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String(GCS_LIBRARY_BASENAME);
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("openpilotgcs");
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("plugins");
|
||||
rc.push_back(pluginPath);
|
||||
// 2) "PlugIns" (OS X)
|
||||
pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("Plugins");
|
||||
rc.push_back(pluginPath);
|
||||
return rc;
|
||||
}
|
||||
const QLatin1String SETTINGS_ORG_NAME("OpenPilot");
|
||||
const QLatin1String SETTINGS_APP_NAME("OpenPilotGCS_config");
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
# define SHARE_PATH "/../Resources"
|
||||
const QLatin1String SHARE_PATH("/../Resources");
|
||||
#else
|
||||
# define SHARE_PATH "/../share/openpilotgcs"
|
||||
const QLatin1String SHARE_PATH("/../share/openpilotgcs");
|
||||
#endif
|
||||
|
||||
static void overrideSettings(QSettings &settings, int argc, char **argv){
|
||||
const char *DEFAULT_CONFIG_FILENAME = "OpenPilotGCS.xml";
|
||||
|
||||
QMap<QString, QString> settingOptions;
|
||||
// Options like -DMy/setting=test
|
||||
QRegExp rx("([^=]+)=(.*)");
|
||||
const char *fixedOptionsC = " [OPTION]... [FILE]...\n"
|
||||
"Options:\n"
|
||||
" -help Display this help\n"
|
||||
" -version Display application version\n"
|
||||
" -no-splash Don't display splash screen\n"
|
||||
" -client Attempt to connect to already running instance\n"
|
||||
" -D <key>=<value> Permanently set a user setting, e.g: -D General/OverrideLanguage=de\n"
|
||||
" -reset Reset user settings to factory defaults.\n"
|
||||
" -config-file <file> Specify alternate factory defaults settings file (used with -reset)\n"
|
||||
" -exit-after-config Exit after manipulating configuration settings\n";
|
||||
|
||||
for(int i = 0; i < argc; ++i ){
|
||||
if ( QString(CONFIG_OPTION).compare(QString(argv[i])) == 0 ){
|
||||
if ( rx.indexIn(argv[++i]) > -1 ){
|
||||
settingOptions.insert(rx.cap(1), rx.cap(2));
|
||||
const QLatin1String HELP1_OPTION("-h");
|
||||
const QLatin1String HELP2_OPTION("-help");
|
||||
const QLatin1String HELP3_OPTION("/h");
|
||||
const QLatin1String HELP4_OPTION("--help");
|
||||
const QLatin1String VERSION_OPTION("-version");
|
||||
const QLatin1String NO_SPLASH_OPTION("-no-splash");
|
||||
const QLatin1String CLIENT_OPTION("-client");
|
||||
const QLatin1String CONFIG_OPTION("-D");
|
||||
const QLatin1String RESET_OPTION("-reset");
|
||||
const QLatin1String CONFIG_FILE_OPTION("-config-file");
|
||||
const QLatin1String EXIT_AFTER_CONFIG_OPTION("-exit-after-config");
|
||||
|
||||
// Helpers for displaying messages. Note that there is no console on Windows.
|
||||
void displayHelpText(QString t)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
// No console on Windows. (???)
|
||||
// TODO there is a console on windows and popups are not always desired
|
||||
t.replace(QLatin1Char('&'), QLatin1String("&"));
|
||||
t.replace(QLatin1Char('<'), QLatin1String("<"));
|
||||
t.replace(QLatin1Char('>'), QLatin1String(">"));
|
||||
t.insert(0, QLatin1String("<html><pre>"));
|
||||
t.append(QLatin1String("</pre></html>"));
|
||||
QMessageBox::information(0, APP_NAME, t);
|
||||
#else
|
||||
qWarning("%s", qPrintable(t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void displayError(const QString &t)
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
// No console on Windows. (???)
|
||||
// TODO there is a console on windows and popups are not always desired
|
||||
QMessageBox::critical(0, APP_NAME, t);
|
||||
#else
|
||||
qCritical("%s", qPrintable(t));
|
||||
#endif
|
||||
}
|
||||
|
||||
void printVersion(const ExtensionSystem::PluginSpec *corePlugin, const ExtensionSystem::PluginManager &pm)
|
||||
{
|
||||
QString version;
|
||||
QTextStream str(&version);
|
||||
str << '\n' << APP_NAME << ' ' << corePlugin->version() << " based on Qt " << qVersion() << "\n\n";
|
||||
pm.formatPluginVersions(str);
|
||||
str << '\n' << corePlugin->copyright() << '\n';
|
||||
displayHelpText(version);
|
||||
}
|
||||
|
||||
void printHelp(const QString &appExecName, const ExtensionSystem::PluginManager &pm)
|
||||
{
|
||||
QString help;
|
||||
QTextStream str(&help);
|
||||
str << "Usage: " << appExecName << fixedOptionsC;
|
||||
ExtensionSystem::PluginManager::formatOptions(str, OptionIndent, DescriptionIndent);
|
||||
pm.formatPluginOptions(str, OptionIndent, DescriptionIndent);
|
||||
displayHelpText(help);
|
||||
}
|
||||
|
||||
inline QString msgCoreLoadFailure(const QString &reason)
|
||||
{
|
||||
return QCoreApplication::translate("Application", "Failed to load core plug-in, reason is: %1").arg(reason);
|
||||
}
|
||||
|
||||
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.
|
||||
inline QString prepareRemoteArgument(const QString &arg)
|
||||
{
|
||||
QFileInfo fi(arg);
|
||||
if (!fi.exists()) {
|
||||
return arg;
|
||||
}
|
||||
if (fi.isRelative()) {
|
||||
return fi.absoluteFilePath();
|
||||
}
|
||||
return arg;
|
||||
}
|
||||
|
||||
// Send the arguments to an already running instance of application
|
||||
bool sendArguments(SharedTools::QtSingleApplication &app, const QStringList &arguments)
|
||||
{
|
||||
if (!arguments.empty()) {
|
||||
// Send off arguments
|
||||
const QStringList::const_iterator acend = arguments.constEnd();
|
||||
for (QStringList::const_iterator it = arguments.constBegin(); it != acend; ++it) {
|
||||
if (!app.sendMessage(prepareRemoteArgument(*it))) {
|
||||
displayError(msgSendArgumentFailed());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( QString(CLEAN_CONFIG_OPTION).compare(QString(argv[i])) == 0 ){
|
||||
settings.clear();
|
||||
// Special empty argument means: Show and raise (the slot just needs to be triggered)
|
||||
if (!app.sendMessage(QString())) {
|
||||
displayError(msgSendArgumentFailed());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void systemInit()
|
||||
{
|
||||
#ifdef Q_OS_MAC
|
||||
// increase the number of file that can be opened in application
|
||||
struct rlimit rl;
|
||||
getrlimit(RLIMIT_NOFILE, &rl);
|
||||
rl.rlim_cur = rl.rlim_max;
|
||||
setrlimit(RLIMIT_NOFILE, &rl);
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline QStringList getPluginPaths()
|
||||
{
|
||||
QStringList rc;
|
||||
// Figure out root: Up one from 'bin'
|
||||
QDir rootDir = QApplication::applicationDirPath();
|
||||
rootDir.cdUp();
|
||||
const QString rootDirPath = rootDir.canonicalPath();
|
||||
// 1) "plugins" (Win/Linux)
|
||||
QString pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String(GCS_LIBRARY_BASENAME);
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("openpilotgcs");
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("plugins");
|
||||
rc.push_back(pluginPath);
|
||||
// 2) "PlugIns" (OS X)
|
||||
pluginPath = rootDirPath;
|
||||
pluginPath += QLatin1Char('/');
|
||||
pluginPath += QLatin1String("Plugins");
|
||||
rc.push_back(pluginPath);
|
||||
return rc;
|
||||
}
|
||||
|
||||
AppOptions options()
|
||||
{
|
||||
AppOptions appOptions;
|
||||
appOptions.insert(HELP1_OPTION, false);
|
||||
appOptions.insert(HELP2_OPTION, false);
|
||||
appOptions.insert(HELP3_OPTION, false);
|
||||
appOptions.insert(HELP4_OPTION, false);
|
||||
appOptions.insert(VERSION_OPTION, false);
|
||||
appOptions.insert(NO_SPLASH_OPTION, false);
|
||||
appOptions.insert(CLIENT_OPTION, false);
|
||||
appOptions.insert(CONFIG_OPTION, true);
|
||||
appOptions.insert(RESET_OPTION, false);
|
||||
appOptions.insert(CONFIG_FILE_OPTION, true);
|
||||
appOptions.insert(EXIT_AFTER_CONFIG_OPTION, false);
|
||||
return appOptions;
|
||||
}
|
||||
|
||||
AppOptionValues parseCommandLine(SharedTools::QtSingleApplication &app,
|
||||
ExtensionSystem::PluginManager &pluginManager, QString &errorMessage)
|
||||
{
|
||||
AppOptionValues appOptionValues;
|
||||
const QStringList arguments = app.arguments();
|
||||
if (arguments.size() > 1) {
|
||||
AppOptions appOptions = options();
|
||||
pluginManager.parseOptions(arguments, appOptions, &appOptionValues, &errorMessage);
|
||||
}
|
||||
return appOptionValues;
|
||||
}
|
||||
|
||||
void loadFactoryDefaults(QSettings &settings, AppOptionValues &appOptionValues)
|
||||
{
|
||||
QDir directory(QCoreApplication::applicationDirPath() + SHARE_PATH + QString("/default_configurations"));
|
||||
qDebug() << "Looking for factory defaults configuration files in:" << directory.absolutePath();
|
||||
|
||||
QString fileName;
|
||||
|
||||
// check if command line option -config-file contains a file name
|
||||
QString commandLine = appOptionValues.value(CONFIG_FILE_OPTION);
|
||||
if (!commandLine.isEmpty()) {
|
||||
QFileInfo fi(commandLine);
|
||||
if (fi.isRelative()) {
|
||||
// file name specified on command line has a relative path
|
||||
commandLine = directory.absolutePath() + QDir::separator() + commandLine;
|
||||
}
|
||||
if (QFile::exists(commandLine)) {
|
||||
fileName = commandLine;
|
||||
qDebug() << "Configuration file" << fileName << "specified on command line will be loaded.";
|
||||
} else {
|
||||
qWarning() << "Configuration file" << commandLine << "specified on command line does not exist.";
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
// check default file
|
||||
if (QFile::exists(directory.absolutePath() + QDir::separator() + DEFAULT_CONFIG_FILENAME)) {
|
||||
// use default file name
|
||||
fileName = directory.absolutePath() + QDir::separator() + DEFAULT_CONFIG_FILENAME;
|
||||
qDebug() << "Default configuration file" << fileName << "will be loaded.";
|
||||
} else {
|
||||
qWarning() << "No default configuration file found in" << directory.absolutePath();
|
||||
}
|
||||
}
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
// TODO should we exit violently?
|
||||
qCritical() << "No default configuration file found!";
|
||||
return;
|
||||
}
|
||||
|
||||
// create settings from file
|
||||
QSettings qs(fileName, XmlConfig::XmlSettingsFormat);
|
||||
|
||||
// transfer loaded settings to application settings
|
||||
QStringList keys = qs.allKeys();
|
||||
foreach(QString key, keys) {
|
||||
settings.setValue(key, qs.value(key));
|
||||
}
|
||||
|
||||
qDebug() << "Configuration file" << fileName << "was loaded.";
|
||||
}
|
||||
|
||||
void overrideSettings(QSettings &settings, int argc, char **argv)
|
||||
{
|
||||
// Options like -D My/setting=test
|
||||
QRegExp rx("([^=]+)=(.*)");
|
||||
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
if (CONFIG_OPTION == QString(argv[i])) {
|
||||
if (rx.indexIn(argv[++i]) > -1) {
|
||||
QString key = rx.cap(1);
|
||||
QString value = rx.cap(2);
|
||||
qDebug() << "User setting" << key << "set to value" << value;
|
||||
settings.setValue(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
void loadTranslators(QString language, QTranslator &translator, QTranslator &qtTranslator)
|
||||
{
|
||||
const QString &creatorTrPath = QCoreApplication::applicationDirPath() + SHARE_PATH
|
||||
+ QLatin1String("/translations");
|
||||
if (translator.load(QLatin1String("openpilotgcs_") + language, creatorTrPath)) {
|
||||
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||||
const QString &qtTrFile = QLatin1String("qt_") + language;
|
||||
// Binary installer puts Qt tr files into creatorTrPath
|
||||
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) {
|
||||
QCoreApplication::installTranslator(&translator);
|
||||
QCoreApplication::installTranslator(&qtTranslator);
|
||||
} else {
|
||||
// unload()
|
||||
translator.load(QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<QString> keys = settingOptions.keys();
|
||||
foreach ( QString key, keys ){
|
||||
settings.setValue(key, settingOptions.value(key));
|
||||
}
|
||||
settings.sync();
|
||||
}
|
||||
} // namespace anonymous
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// increase the number of file that can be opened in OpenPilot GCS
|
||||
struct rlimit rl;
|
||||
getrlimit(RLIMIT_NOFILE, &rl);
|
||||
rl.rlim_cur = rl.rlim_max;
|
||||
setrlimit(RLIMIT_NOFILE, &rl);
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
QApplication::setAttribute(Qt::AA_X11InitThreads, true);
|
||||
#endif
|
||||
// low level init
|
||||
systemInit();
|
||||
|
||||
//Set the default locale to EN, if this is not set the system locale will be used
|
||||
//and as of now we dont want that behaviour.
|
||||
QLocale::setDefault(QLocale::English);
|
||||
// create application
|
||||
SharedTools::QtSingleApplication app(APP_NAME, argc, argv);
|
||||
|
||||
SharedTools::QtSingleApplication app((QLatin1String(appNameC)), argc, argv);
|
||||
|
||||
//Open Splashscreen
|
||||
GCSSplashScreen splash;
|
||||
splash.show();
|
||||
|
||||
QString locale = QLocale::system().name();
|
||||
|
||||
// Must be done before any QSettings class is created
|
||||
QSettings::setPath(XmlConfig::XmlSettingsFormat, QSettings::SystemScope,
|
||||
QCoreApplication::applicationDirPath()+QLatin1String(SHARE_PATH));
|
||||
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
||||
QSettings settings(XmlConfig::XmlSettingsFormat, QSettings::UserScope,
|
||||
QLatin1String("OpenPilot"), QLatin1String("OpenPilotGCS_config"));
|
||||
|
||||
overrideSettings(settings, argc, argv);
|
||||
locale = settings.value("General/OverrideLanguage", locale).toString();
|
||||
|
||||
QTranslator translator;
|
||||
QTranslator qtTranslator;
|
||||
|
||||
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
|
||||
+ QLatin1String(SHARE_PATH "/translations");
|
||||
if (translator.load(QLatin1String("openpilotgcs_") + locale, creatorTrPath)) {
|
||||
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||||
const QString &qtTrFile = QLatin1String("qt_") + locale;
|
||||
// Binary installer puts Qt tr files into creatorTrPath
|
||||
if (qtTranslator.load(qtTrFile, qtTrPath) || qtTranslator.load(qtTrFile, creatorTrPath)) {
|
||||
QCoreApplication::installTranslator(&translator);
|
||||
QCoreApplication::installTranslator(&qtTranslator);
|
||||
} else {
|
||||
translator.load(QString()); // unload()
|
||||
}
|
||||
}
|
||||
app.setProperty("qtc_locale", locale); // Do we need this?
|
||||
|
||||
splash.showProgressMessage(QObject::tr("Application starting..."));
|
||||
|
||||
// Load
|
||||
// initialize the plugin manager
|
||||
ExtensionSystem::PluginManager pluginManager;
|
||||
pluginManager.setFileExtension(QLatin1String("pluginspec"));
|
||||
pluginManager.setPluginPaths(getPluginPaths());
|
||||
|
||||
const QStringList pluginPaths = getPluginPaths();
|
||||
pluginManager.setPluginPaths(pluginPaths);
|
||||
|
||||
const QStringList arguments = app.arguments();
|
||||
QMap<QString, QString> foundAppOptions;
|
||||
if (arguments.size() > 1) {
|
||||
QMap<QString, bool> appOptions;
|
||||
appOptions.insert(QLatin1String(HELP_OPTION1), false);
|
||||
appOptions.insert(QLatin1String(HELP_OPTION2), false);
|
||||
appOptions.insert(QLatin1String(HELP_OPTION3), false);
|
||||
appOptions.insert(QLatin1String(HELP_OPTION4), false);
|
||||
appOptions.insert(QLatin1String(VERSION_OPTION), false);
|
||||
appOptions.insert(QLatin1String(CLIENT_OPTION), false);
|
||||
appOptions.insert(QLatin1String(CONFIG_OPTION), true);
|
||||
appOptions.insert(QLatin1String(CLEAN_CONFIG_OPTION), false);
|
||||
appOptions.insert(QLatin1String(EXIT_AFTER_CONFIG_OPTION), false);
|
||||
QString errorMessage;
|
||||
if (!pluginManager.parseOptions(arguments,
|
||||
appOptions,
|
||||
&foundAppOptions,
|
||||
&errorMessage)) {
|
||||
displayError(errorMessage);
|
||||
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
|
||||
return -1;
|
||||
}
|
||||
// parse command line
|
||||
qDebug() << "Command line" << app.arguments();
|
||||
QString errorMessage;
|
||||
AppOptionValues appOptionValues = parseCommandLine(app, pluginManager, errorMessage);
|
||||
if (!errorMessage.isEmpty()) {
|
||||
// this will display two popups : one error popup + one usage string popup
|
||||
// TODO merge two popups into one.
|
||||
displayError(errorMessage);
|
||||
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// load user settings
|
||||
// Must be done before any QSettings class is created
|
||||
// keep this in sync with the MainWindow ctor in coreplugin/mainwindow.cpp
|
||||
QString settingsPath = QCoreApplication::applicationDirPath() + SHARE_PATH;
|
||||
qDebug() << "Loading system settings from" << settingsPath;
|
||||
QSettings::setPath(XmlConfig::XmlSettingsFormat, QSettings::SystemScope, settingsPath);
|
||||
qDebug() << "Loading user settings from" << SETTINGS_ORG_NAME << "/" << SETTINGS_APP_NAME;
|
||||
QSettings settings(XmlConfig::XmlSettingsFormat, QSettings::UserScope, SETTINGS_ORG_NAME, SETTINGS_APP_NAME);
|
||||
|
||||
// need to reset all user settings?
|
||||
if (appOptionValues.contains(RESET_OPTION)) {
|
||||
qDebug() << "Resetting user settings!";
|
||||
settings.clear();
|
||||
}
|
||||
|
||||
// check if we have user settings
|
||||
if (!settings.allKeys().count()) {
|
||||
// no user settings, load the factory defaults
|
||||
qDebug() << "No user settings found, loading factory defaults...";
|
||||
loadFactoryDefaults(settings, appOptionValues);
|
||||
}
|
||||
|
||||
// override settings with command line provided values
|
||||
// take notice that the overridden values will be saved in the user settings and will continue to be effective
|
||||
// in subsequent GCS runs
|
||||
overrideSettings(settings, argc, argv);
|
||||
|
||||
// initialize GCS locale
|
||||
// use the value defined by the General/Locale setting or default to system Locale.
|
||||
// the General/Locale setting is not available in the Options dialog, it is a hidden setting but can still be changed:
|
||||
// - through the command line
|
||||
// - editing the factory defaults XML file before 1st launch
|
||||
// - editing the user XML file
|
||||
QString localeName = settings.value("General/Locale", QLocale::system().name()).toString();
|
||||
QLocale::setDefault(localeName);
|
||||
|
||||
// some debugging
|
||||
qDebug() << "main - system locale:" << QLocale::system().name();
|
||||
qDebug() << "main - GCS locale:" << QLocale().name();
|
||||
|
||||
// load translation file
|
||||
// the language used is defined by the General/OverrideLanguage setting (defaults to GCS locale)
|
||||
// if the translation file for the given language is not found, GCS will default to built in English.
|
||||
QString language = settings.value("General/OverrideLanguage", localeName).toString();
|
||||
qDebug() << "main - language:" << language;
|
||||
QTranslator translator;
|
||||
QTranslator qtTranslator;
|
||||
loadTranslators(language, translator, qtTranslator);
|
||||
|
||||
app.setProperty("qtc_locale", localeName); // Do we need this?
|
||||
|
||||
if (appOptionValues.contains(EXIT_AFTER_CONFIG_OPTION)) {
|
||||
qDebug() << "main - exiting after config!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// open the splash screen
|
||||
GCSSplashScreen *splash = 0;
|
||||
if (!appOptionValues.contains(NO_SPLASH_OPTION)) {
|
||||
splash = new GCSSplashScreen();
|
||||
// show splash
|
||||
splash->showProgressMessage(QObject::tr("Application starting..."));
|
||||
splash->show();
|
||||
// connect to track progress of plugin manager
|
||||
QObject::connect(&pluginManager, SIGNAL(pluginAboutToBeLoaded(ExtensionSystem::PluginSpec*)), splash,
|
||||
SLOT(showPluginLoadingProgress(ExtensionSystem::PluginSpec*)));
|
||||
}
|
||||
|
||||
// find and load core plugin
|
||||
const PluginSpecSet plugins = pluginManager.plugins();
|
||||
ExtensionSystem::PluginSpec *coreplugin = 0;
|
||||
foreach (ExtensionSystem::PluginSpec *spec, plugins) {
|
||||
if (spec->name() == QLatin1String(corePluginNameC)) {
|
||||
if (spec->name() == CORE_PLUGIN_NAME) {
|
||||
coreplugin = spec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!coreplugin){
|
||||
QString nativePaths = QDir::toNativeSeparators(pluginPaths.join(QLatin1String(",")));
|
||||
const QString reason = QCoreApplication::translate("Application", "Could not find 'Core.pluginspec' in %1").arg(nativePaths);
|
||||
if (!coreplugin) {
|
||||
QString nativePaths = QDir::toNativeSeparators(getPluginPaths().join(QLatin1String(",")));
|
||||
const QString reason = QCoreApplication::translate("Application", "Could not find 'Core.pluginspec' in %1").arg(
|
||||
nativePaths);
|
||||
displayError(msgCoreLoadFailure(reason));
|
||||
return 1;
|
||||
}
|
||||
@ -341,26 +516,21 @@ int main(int argc, char **argv)
|
||||
displayError(msgCoreLoadFailure(coreplugin->errorString()));
|
||||
return 1;
|
||||
}
|
||||
if (foundAppOptions.contains(QLatin1String(VERSION_OPTION))) {
|
||||
|
||||
if (appOptionValues.contains(VERSION_OPTION)) {
|
||||
printVersion(coreplugin, pluginManager);
|
||||
return 0;
|
||||
}
|
||||
if (foundAppOptions.contains(QLatin1String(EXIT_AFTER_CONFIG_OPTION))) {
|
||||
return 0;
|
||||
}
|
||||
if (foundAppOptions.contains(QLatin1String(HELP_OPTION1))
|
||||
|| foundAppOptions.contains(QLatin1String(HELP_OPTION2))
|
||||
|| foundAppOptions.contains(QLatin1String(HELP_OPTION3))
|
||||
|| foundAppOptions.contains(QLatin1String(HELP_OPTION4))) {
|
||||
if (appOptionValues.contains(HELP1_OPTION) || appOptionValues.contains(HELP2_OPTION)
|
||||
|| appOptionValues.contains(HELP3_OPTION) || appOptionValues.contains(HELP4_OPTION)) {
|
||||
printHelp(QFileInfo(app.applicationFilePath()).baseName(), pluginManager);
|
||||
return 0;
|
||||
}
|
||||
const bool isFirstInstance = !app.isRunning();
|
||||
if (!isFirstInstance && foundAppOptions.contains(QLatin1String(CLIENT_OPTION)))
|
||||
return sendArguments(app, pluginManager.arguments()) ? 0 : -1;
|
||||
|
||||
QObject::connect(&pluginManager, SIGNAL(pluginAboutToBeLoaded(ExtensionSystem::PluginSpec*)),
|
||||
&splash, SLOT(showPluginLoadingProgress(ExtensionSystem::PluginSpec*)));
|
||||
const bool isFirstInstance = !app.isRunning();
|
||||
if (!isFirstInstance && appOptionValues.contains(CLIENT_OPTION)) {
|
||||
return sendArguments(app, pluginManager.arguments()) ? 0 : -1;
|
||||
}
|
||||
|
||||
pluginManager.loadPlugins();
|
||||
|
||||
@ -371,19 +541,21 @@ int main(int argc, char **argv)
|
||||
|
||||
{
|
||||
QStringList errors;
|
||||
foreach (ExtensionSystem::PluginSpec *p, pluginManager.plugins())
|
||||
if (p->hasError())
|
||||
foreach (ExtensionSystem::PluginSpec *p, pluginManager.plugins()) {
|
||||
if (p->hasError()) {
|
||||
errors.append(p->errorString());
|
||||
if (!errors.isEmpty())
|
||||
}
|
||||
}
|
||||
if (!errors.isEmpty()) {
|
||||
QMessageBox::warning(0,
|
||||
QCoreApplication::translate("Application", "OpenPilot GCS - Plugin loader messages"),
|
||||
errors.join(QString::fromLatin1("\n\n")));
|
||||
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.
|
||||
// Silently fallback to unconnected instances for any subsequent instances.
|
||||
app.initialize();
|
||||
QObject::connect(&app, SIGNAL(messageReceived(QString)), coreplugin->plugin(), SLOT(remoteArgument(QString)));
|
||||
}
|
||||
@ -392,15 +564,17 @@ int main(int argc, char **argv)
|
||||
// Do this after the event loop has started
|
||||
QTimer::singleShot(100, &pluginManager, SLOT(startTests()));
|
||||
|
||||
//Update message and postpone closing of splashscreen 3 seconds
|
||||
splash.showProgressMessage(QObject::tr("Application started."));
|
||||
QTimer::singleShot(1500, &splash, SLOT(close()));
|
||||
if (splash) {
|
||||
// close and delete splash
|
||||
splash->close();
|
||||
delete splash;
|
||||
}
|
||||
|
||||
qDebug() << "main() took" << timer.elapsed() << "ms";
|
||||
qDebug() << "main - main took" << timer.elapsed() << "ms";
|
||||
|
||||
int ret = app.exec();
|
||||
|
||||
qDebug() << "GCS ran for" << timer.elapsed() << "ms";
|
||||
qDebug() << "main - GCS ran for" << timer.elapsed() << "ms";
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1,22 +1,27 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = Core
|
||||
DEFINES += CORE_LIBRARY
|
||||
|
||||
QT += declarative \
|
||||
xml \
|
||||
network \
|
||||
script \
|
||||
svg \
|
||||
sql
|
||||
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../libs/utils/utils.pri)
|
||||
include(../../shared/scriptwrapper/scriptwrapper.pri)
|
||||
include(coreplugin_dependencies.pri)
|
||||
|
||||
INCLUDEPATH += dialogs \
|
||||
uavgadgetmanager \
|
||||
actionmanager
|
||||
|
||||
DEPENDPATH += dialogs \
|
||||
uavgadgetmanager \
|
||||
actionmanager
|
||||
|
||||
SOURCES += mainwindow.cpp \
|
||||
tabpositionindicator.cpp \
|
||||
fancyactionbar.cpp \
|
||||
@ -64,8 +69,8 @@ SOURCES += mainwindow.cpp \
|
||||
workspacesettings.cpp \
|
||||
uavconfiginfo.cpp \
|
||||
authorsdialog.cpp \
|
||||
telemetrymonitorwidget.cpp \
|
||||
dialogs/importsettings.cpp
|
||||
telemetrymonitorwidget.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
tabpositionindicator.h \
|
||||
fancyactionbar.h \
|
||||
@ -126,20 +131,22 @@ HEADERS += mainwindow.h \
|
||||
uavconfiginfo.h \
|
||||
authorsdialog.h \
|
||||
iconfigurableplugin.h \
|
||||
telemetrymonitorwidget.h \
|
||||
dialogs/importsettings.h
|
||||
telemetrymonitorwidget.h
|
||||
|
||||
FORMS += dialogs/settingsdialog.ui \
|
||||
dialogs/shortcutsettings.ui \
|
||||
generalsettings.ui \
|
||||
uavgadgetoptionspage.ui \
|
||||
workspacesettings.ui \
|
||||
dialogs/importsettings.ui
|
||||
workspacesettings.ui
|
||||
|
||||
RESOURCES += core.qrc \
|
||||
fancyactionbar.qrc
|
||||
|
||||
unix:!macx {
|
||||
images.files = images/openpilot_logo_*.png
|
||||
images.files = images/qtcreator_logo_*.png
|
||||
images.path = /share/pixmaps
|
||||
INSTALLS += images
|
||||
}
|
||||
|
||||
OTHER_FILES += Core.pluginspec
|
||||
|
@ -1,57 +0,0 @@
|
||||
#include "importsettings.h"
|
||||
#include "ui_importsettings.h"
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <utils/xmlconfig.h>
|
||||
#include <QTimer>
|
||||
|
||||
importSettings::importSettings(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::importSettings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->cbConfigs, SIGNAL(currentIndexChanged(int)), this, SLOT(updateDetails(int)));
|
||||
connect(ui->btnLoad, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
QTimer::singleShot(500, this, SLOT(repaint()));
|
||||
}
|
||||
|
||||
void importSettings::loadFiles(QString path)
|
||||
{
|
||||
QDir myDir(path);
|
||||
QStringList filters;
|
||||
filters << "*.xml";
|
||||
QStringList list = myDir.entryList(filters,QDir::Files);
|
||||
int x = 0;
|
||||
foreach(QString fileStr, list) {
|
||||
fileInfo *info = new fileInfo;
|
||||
QSettings settings(path+QDir::separator() + fileStr, XmlConfig::XmlSettingsFormat);
|
||||
settings.beginGroup("General");
|
||||
info->description = settings.value("Description", "None").toString();
|
||||
info->details = settings.value("Details", "None").toString();
|
||||
settings.endGroup();
|
||||
info->file = path + QDir::separator() + fileStr;
|
||||
configList.insert(x,info);
|
||||
ui->cbConfigs->addItem(info->description, x);
|
||||
++x;
|
||||
}
|
||||
}
|
||||
|
||||
void importSettings::updateDetails(int index)
|
||||
{
|
||||
fileInfo *info = configList.value(ui->cbConfigs->itemData(index).toInt());
|
||||
ui->lblDetails->setText(info->details);
|
||||
}
|
||||
|
||||
QString importSettings::choosenConfig()
|
||||
{
|
||||
fileInfo *info = configList.value(ui->cbConfigs->itemData(ui->cbConfigs->currentIndex()).toInt());
|
||||
return info->file;
|
||||
}
|
||||
|
||||
importSettings::~importSettings()
|
||||
{
|
||||
foreach(fileInfo * info,configList.values()) {
|
||||
delete info;
|
||||
}
|
||||
delete ui;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
#ifndef IMPORTSETTINGS_H
|
||||
#define IMPORTSETTINGS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMap>
|
||||
namespace Ui {
|
||||
class importSettings;
|
||||
}
|
||||
|
||||
class importSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
struct fileInfo {
|
||||
QString file;
|
||||
QString description;
|
||||
QString details;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit importSettings(QWidget *parent = 0);
|
||||
~importSettings();
|
||||
|
||||
void loadFiles(QString path);
|
||||
QString choosenConfig();
|
||||
|
||||
private:
|
||||
Ui::importSettings *ui;
|
||||
QMap<int,fileInfo*> configList;
|
||||
|
||||
private slots:
|
||||
void updateDetails(int);
|
||||
};
|
||||
|
||||
#endif // IMPORTSETTINGS_H
|
@ -1,82 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>importSettings</class>
|
||||
<widget class="QDialog" name="importSettings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>373</width>
|
||||
<height>167</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>OpenPilotGCS</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>No configuration file could be found.
|
||||
Please choose from one of the default configurations</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbConfigs"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblDetails">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnLoad">
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<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>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -45,11 +45,11 @@ using namespace Core::Internal;
|
||||
|
||||
GeneralSettings::GeneralSettings():
|
||||
m_saveSettingsOnExit(true),
|
||||
m_dialog(0),
|
||||
m_autoConnect(true),
|
||||
m_autoSelect(true),
|
||||
m_useUDPMirror(false),
|
||||
m_useExpertMode(false)
|
||||
m_useExpertMode(false),
|
||||
m_dialog(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -88,23 +88,23 @@ void GeneralSettings::fillLanguageBox() const
|
||||
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"))
|
||||
if (currentLocale == QLatin1String("C")) {
|
||||
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
||||
}
|
||||
|
||||
const QString creatorTrPath =
|
||||
Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
|
||||
const QString creatorTrPath = Core::ICore::instance()->resourcePath() + QLatin1String("/translations");
|
||||
const QStringList languageFiles = QDir(creatorTrPath).entryList(QStringList(QLatin1String("openpilotgcs*.qm")));
|
||||
|
||||
Q_FOREACH(const QString &languageFile, languageFiles)
|
||||
{
|
||||
int start = languageFile.indexOf(QLatin1Char('_'))+1;
|
||||
foreach(QString languageFile, languageFiles) {
|
||||
int start = languageFile.indexOf(QLatin1Char('_')) + 1;
|
||||
int end = languageFile.lastIndexOf(QLatin1Char('.'));
|
||||
const QString locale = languageFile.mid(start, end-start);
|
||||
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)
|
||||
if (locale == currentLocale) {
|
||||
m_page->languageBox->setCurrentIndex(m_page->languageBox->count() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -114,8 +114,11 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
m_page = new Ui::GeneralSettings();
|
||||
QWidget *w = new QWidget(parent);
|
||||
m_page->setupUi(w);
|
||||
|
||||
fillLanguageBox();
|
||||
connect(m_page->checkAutoConnect,SIGNAL(stateChanged(int)),this,SLOT(slotAutoConnect(int)));
|
||||
|
||||
connect(m_page->checkAutoConnect, SIGNAL(stateChanged(int)), this, SLOT(slotAutoConnect(int)));
|
||||
|
||||
m_page->checkBoxSaveOnExit->setChecked(m_saveSettingsOnExit);
|
||||
m_page->checkAutoConnect->setChecked(m_autoConnect);
|
||||
m_page->checkAutoSelect->setChecked(m_autoSelect);
|
||||
@ -123,8 +126,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
|
||||
m_page->cbExpertMode->setChecked(m_useExpertMode);
|
||||
m_page->colorButton->setColor(StyleHelper::baseColor());
|
||||
|
||||
connect(m_page->resetButton, SIGNAL(clicked()),
|
||||
this, SLOT(resetInterfaceColor()));
|
||||
connect(m_page->resetButton, SIGNAL(clicked()), this, SLOT(resetInterfaceColor()));
|
||||
|
||||
return w;
|
||||
}
|
||||
@ -148,26 +150,28 @@ void GeneralSettings::finish()
|
||||
delete m_page;
|
||||
}
|
||||
|
||||
void GeneralSettings::readSettings(QSettings* qs)
|
||||
void GeneralSettings::readSettings(QSettings *qs)
|
||||
{
|
||||
qs->beginGroup(QLatin1String("General"));
|
||||
m_language = qs->value(QLatin1String("OverrideLanguage"),QLocale::system().name()).toString();
|
||||
m_saveSettingsOnExit = qs->value(QLatin1String("SaveSettingsOnExit"),m_saveSettingsOnExit).toBool();
|
||||
m_autoConnect = qs->value(QLatin1String("AutoConnect"),m_autoConnect).toBool();
|
||||
m_autoSelect = qs->value(QLatin1String("AutoSelect"),m_autoSelect).toBool();
|
||||
m_useUDPMirror = qs->value(QLatin1String("UDPMirror"),m_useUDPMirror).toBool();
|
||||
m_useExpertMode = qs->value(QLatin1String("ExpertMode"),m_useExpertMode).toBool();
|
||||
m_language = qs->value(QLatin1String("OverrideLanguage"), QLocale::system().name()).toString();
|
||||
m_saveSettingsOnExit = qs->value(QLatin1String("SaveSettingsOnExit"), m_saveSettingsOnExit).toBool();
|
||||
m_autoConnect = qs->value(QLatin1String("AutoConnect"), m_autoConnect).toBool();
|
||||
m_autoSelect = qs->value(QLatin1String("AutoSelect"), m_autoSelect).toBool();
|
||||
m_useUDPMirror = qs->value(QLatin1String("UDPMirror"), m_useUDPMirror).toBool();
|
||||
m_useExpertMode = qs->value(QLatin1String("ExpertMode"), m_useExpertMode).toBool();
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void GeneralSettings::saveSettings(QSettings* qs)
|
||||
void GeneralSettings::saveSettings(QSettings *qs)
|
||||
{
|
||||
qs->beginGroup(QLatin1String("General"));
|
||||
|
||||
if (m_language.isEmpty())
|
||||
if (m_language.isEmpty()) {
|
||||
qs->remove(QLatin1String("OverrideLanguage"));
|
||||
else
|
||||
}
|
||||
else {
|
||||
qs->setValue(QLatin1String("OverrideLanguage"), m_language);
|
||||
}
|
||||
|
||||
qs->setValue(QLatin1String("SaveSettingsOnExit"), m_saveSettingsOnExit);
|
||||
qs->setValue(QLatin1String("AutoConnect"), m_autoConnect);
|
||||
@ -217,8 +221,8 @@ void GeneralSettings::setLanguage(const QString &locale)
|
||||
{
|
||||
if (m_language != locale) {
|
||||
if (!locale.isEmpty()) {
|
||||
QMessageBox::information((QWidget*)Core::ICore::instance()->mainWindow(), tr("Restart required"),
|
||||
tr("The language change will take effect after a restart of the OpenPilot GCS."));
|
||||
QMessageBox::information((QWidget*) Core::ICore::instance()->mainWindow(), tr("Restart required"),
|
||||
tr("The language change will take effect after a restart of the OpenPilot GCS."));
|
||||
}
|
||||
m_language = locale;
|
||||
}
|
||||
@ -251,8 +255,10 @@ bool GeneralSettings::useExpertMode() const
|
||||
|
||||
void GeneralSettings::slotAutoConnect(int value)
|
||||
{
|
||||
if (value==Qt::Checked)
|
||||
if (value==Qt::Checked) {
|
||||
m_page->checkAutoSelect->setEnabled(false);
|
||||
else
|
||||
}
|
||||
else {
|
||||
m_page->checkAutoSelect->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ private:
|
||||
QList<QTextCodec *> m_codecs;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
||||
|
@ -85,14 +85,12 @@
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QElapsedTimer>
|
||||
#include "dialogs/importsettings.h"
|
||||
#include <QDir>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Core::Internal;
|
||||
|
||||
static const char *uriListMimeFormatC = "text/uri-list";
|
||||
static const char *DEFAULT_CONFIG_FILENAME = "OpenPilotGCS.xml";
|
||||
|
||||
enum { debugMainWindow = 0 };
|
||||
|
||||
@ -269,66 +267,9 @@ void MainWindow::modeChanged(Core::IMode */*mode*/)
|
||||
void MainWindow::extensionsInitialized()
|
||||
{
|
||||
QSettings *qs = m_settings;
|
||||
if (!qs->allKeys().count()) {
|
||||
// no user settings, so try to load some default ones
|
||||
QDir directory(QCoreApplication::applicationDirPath());
|
||||
#ifdef Q_OS_MAC
|
||||
directory.cdUp();
|
||||
directory.cd("Resources");
|
||||
#else
|
||||
directory.cdUp();
|
||||
directory.cd("share");
|
||||
directory.cd("openpilotgcs");
|
||||
#endif
|
||||
directory.cd("default_configurations");
|
||||
|
||||
qDebug() << "Looking for configuration files in:" << directory.absolutePath();
|
||||
|
||||
QString filename;
|
||||
// check if command line contains a config file name
|
||||
QString commandLine;
|
||||
foreach(QString str, qApp->arguments()) {
|
||||
if (str.contains("configfile")) {
|
||||
commandLine = str.split("=").at(1);
|
||||
}
|
||||
}
|
||||
if (!commandLine.isEmpty() && QFile::exists(directory.absolutePath() + QDir::separator() + commandLine)) {
|
||||
// use file name specified on command line
|
||||
filename = directory.absolutePath() + QDir::separator() + commandLine;
|
||||
qDebug() << "Configuration file" << filename << "specified on command line will be loaded.";
|
||||
} else if (QFile::exists(directory.absolutePath() + QDir::separator() + DEFAULT_CONFIG_FILENAME)) {
|
||||
// use default file name
|
||||
filename = directory.absolutePath() + QDir::separator() + DEFAULT_CONFIG_FILENAME;
|
||||
qDebug() << "Default configuration file" << filename << "will be loaded.";
|
||||
} else {
|
||||
// prompt user for default file name
|
||||
qDebug() << "Default configuration file" << directory.absolutePath() << QDir::separator()
|
||||
<< DEFAULT_CONFIG_FILENAME << "was not found.";
|
||||
importSettings *dialog = new importSettings(this);
|
||||
dialog->loadFiles(directory.absolutePath());
|
||||
dialog->exec();
|
||||
filename = dialog->choosenConfig();
|
||||
delete dialog;
|
||||
qDebug() << "Configuration file" << filename << "was selected and will be loaded.";
|
||||
}
|
||||
|
||||
// create settings from file
|
||||
qs = new QSettings(filename, XmlConfig::XmlSettingsFormat);
|
||||
|
||||
// transfer loaded settings to application settings
|
||||
QStringList keys = qs->allKeys();
|
||||
foreach(QString key, keys) {
|
||||
m_settings->setValue(key, qs->value(key));
|
||||
}
|
||||
|
||||
// and delete loaded settings
|
||||
delete qs;
|
||||
qs = m_settings;
|
||||
|
||||
qDebug() << "Configuration file" << filename << "was loaded.";
|
||||
}
|
||||
|
||||
qs->beginGroup("General");
|
||||
|
||||
m_config_description = qs->value("Description", "none").toString();
|
||||
m_config_details = qs->value("Details", "none").toString();
|
||||
m_config_stylesheet = qs->value("StyleSheet", "none").toString();
|
||||
|
Loading…
Reference in New Issue
Block a user