GCC Code Coverage Report


Directory: ./
File: src/gui/settings.cc
Date: 2024-08-14 11:04:57
Exec Total Coverage
Lines: 0 419 0.0%
Branches: 0 1890 0.0%

Line Branch Exec Source
1 // Copyright (c) 2015, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of gepetto-viewer.
5 // gepetto-viewer is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // gepetto-viewer is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // gepetto-viewer. If not, see <http://www.gnu.org/licenses/>.
16
17 #include <QDir>
18 #include <QSettings>
19 #include <QStyleFactory>
20 #include <QtDebug>
21 #include <gepetto/gui/dialog/dialogloadenvironment.hh>
22 #include <gepetto/gui/dialog/dialogloadrobot.hh>
23 #include <gepetto/gui/mainwindow.hh>
24 #include <gepetto/gui/settings.hh>
25 #include <osg/ArgumentParser>
26 #include <osg/DisplaySettings>
27
28 #if GEPETTO_GUI_HAS_PYTHONQT
29 #include <gepetto/gui/pythonwidget.hh>
30 #endif
31
32 #include "../log.hh"
33
34 namespace gepetto {
35 namespace gui {
36 Settings::Settings(const char* installDir)
37 : configurationFile("settings"),
38 predifinedRobotConf("robots"),
39 predifinedEnvConf("environments"),
40 stateConf(".state"),
41 verbose(false),
42 noPlugin(false),
43 useNameService(false),
44 refreshRate(30),
45 captureDirectory(),
46 captureFilename("screenshot"),
47 captureExtension("png"),
48 ffmpeg(FFMPEG),
49 installDirectory(installDir)
50 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
51 ,
52 appStyle("cleanlooks")
53 #else
54 ,
55 appStyle("fusion")
56 #endif
57
58 ,
59 mw(0) {
60 QDir user(QDir::home());
61 const char path[] = "Pictures/gepetto-gui";
62 user.mkpath(path);
63 user.cd(path);
64 captureDirectory = user.absolutePath().toStdString();
65
66 ffmpegInputOptions << "-r"
67 << "25";
68 ffmpegOutputOptions << "-vf"
69 << "scale=trunc(iw/2)*2:trunc(ih/2)*2"
70 << "-r"
71 << "25"
72 << "-vcodec"
73 << "libx264";
74 }
75
76 void Settings::setupPaths() const {
77 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
78 if (env.contains("GEPETTO_GUI_SETTINGS_DIR")) {
79 QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
80 env.value("GEPETTO_GUI_SETTINGS_DIR"));
81 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope,
82 env.value("GEPETTO_GUI_SETTINGS_DIR"));
83 } else {
84 QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
85 installDirectory + "/etc");
86 QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope,
87 installDirectory + "/etc");
88 }
89
90 if (env.contains("GEPETTO_GUI_PLUGIN_DIRS")) {
91 foreach (QString p, env.value("GEPETTO_GUI_PLUGIN_DIRS").split(':')) {
92 PluginManager::addPluginDir(p + "/gepetto-gui-plugins");
93 }
94 }
95 foreach (QString p, env.value("LD_LIBRARY_PATH").split(':')) {
96 PluginManager::addPluginDir(p + "/gepetto-gui-plugins");
97 }
98 PluginManager::addPluginDir(installDirectory + "/lib/gepetto-gui-plugins");
99 }
100
101 int Settings::initSettings(int argc, char* argv[]) {
102 // 1. Declare the supported options.
103 osg::ArgumentParser arguments(&argc, argv);
104 osg::ApplicationUsage* au(arguments.getApplicationUsage());
105 au->setApplicationName(arguments.getApplicationName());
106 au->setCommandLineUsage(arguments.getApplicationName() + " [options]");
107
108 au->addCommandLineOption("-v or --verbose", "Activate verbose output");
109 au->addCommandLineOption("-g or --generate-config-files",
110 "generate configuration files in " +
111 installDirectory.toStdString() +
112 "/etc and quit");
113 au->addCommandLineOption("-c or --config-file",
114 "set the configuration file (do not include .conf)",
115 configurationFile);
116 au->addCommandLineOption("--log", "set the file where logs are written",
117 logFile);
118 au->addCommandLineOption(
119 "--predefined-robots",
120 "set the predefined robots configuration file (do not include .conf)",
121 predifinedRobotConf);
122 au->addCommandLineOption("--predefined-environments",
123 "set the predefined environments configuration file "
124 "(do not include .conf)",
125 predifinedEnvConf);
126 au->addCommandLineOption("--add-robot",
127 "Add a robot (a list of comma sperated string)");
128 au->addCommandLineOption(
129 "--add-env", "Add an environment (a list of comma sperated string)");
130 au->addCommandLineOption("-p or --load-plugin", "load the plugin");
131 #if GEPETTO_GUI_HAS_PYTHONQT
132 au->addCommandLineOption("-q or --load-pyplugin",
133 "load the PythonQt module as a plugin");
134 au->addCommandLineOption("-x or --run-pyscript",
135 "run a script into the PythonQt console");
136 #endif
137 au->addCommandLineOption("-P or --no-plugin", "do not load any plugin");
138 au->addCommandLineOption("-w or --auto-write-settings",
139 "write the settings in the configuration file");
140 au->addCommandLineOption("--no-viewer-server",
141 "do not start the Gepetto Viewer server");
142 au->addCommandLineOption(
143 "--use-nameservice",
144 "The server will be registered to the Omni NameService");
145
146 // 2. Read configuration files
147 if (arguments.read("-c", configurationFile) ||
148 arguments.read("--config-file", configurationFile)) {
149 }
150 if (arguments.read("--predefined-robots", predifinedRobotConf)) {
151 }
152 if (arguments.read("--predefined-environments", predifinedEnvConf)) {
153 }
154 fromFiles();
155 arguments.read("--log", logFile);
156
157 // 3. Read other command line arguments
158 bool genAndQuit = false;
159 int retVal = 0;
160
161 // Declare the supported options.
162 osg::ApplicationUsage::Type help(arguments.readHelpType());
163
164 osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
165 ds->readCommandLine(arguments); // populate the help message.
166
167 verbose = (arguments.read("-v") || arguments.read("--verbose"));
168 genAndQuit =
169 (arguments.read("-g") || arguments.read("--generate-config-files"));
170 noPlugin = (arguments.read("-P") || arguments.read("--no-plugin"));
171 autoWriteSettings =
172 (arguments.read("-w") || arguments.read("--auto-write-settings"));
173 bool startViewerServer = (!arguments.read("--no-viewer-server"));
174 while (arguments.read("--use-nameservice", useNameService)) {
175 }
176
177 std::string opt;
178 while (arguments.read("--add-robot", opt)) addRobotFromString(opt);
179 while (arguments.read("--add-env", opt)) addEnvFromString(opt);
180 if (startViewerServer) {
181 // TODO omniorbserver.so should be the first plugin
182 // because of ORB::init...
183 // addPlugin ("omniorbserver.so", true);
184 pluginsToInit_.prepend("omniorbserver.so");
185 pluginManager_.declarePlugin("omniorbserver.so");
186 }
187 while (arguments.read("-p", opt) || arguments.read("--load-plugin", opt))
188 addPlugin(QString::fromStdString(opt), !noPlugin);
189 while (arguments.read("-q", opt) || arguments.read("--load-pyplugin", opt))
190 addPyPlugin(QString::fromStdString(opt), !noPlugin);
191 while (arguments.read("-x", opt) || arguments.read("--run-pyscript", opt))
192 addPyScript(QString::fromStdString(opt));
193
194 for (int i = 0; i < arguments.argc() - 1;) {
195 if (strncmp(arguments.argv()[i], "-ORB", 4) == 0) {
196 addOmniORB(arguments.argv()[i], arguments.argv()[i + 1]);
197 arguments.remove(i, 2);
198 } else
199 ++i;
200 }
201
202 arguments.reportRemainingOptionsAsUnrecognized(osg::ArgumentParser::BENIGN);
203 if (arguments.errors(osg::ArgumentParser::CRITICAL)) {
204 arguments.writeErrorMessages(std::cout);
205 retVal = 2;
206 } else if (arguments.errors(osg::ArgumentParser::BENIGN)) {
207 arguments.writeErrorMessages(std::cout);
208 }
209
210 if (!omniORBargv_.contains("-ORBendPoint"))
211 addOmniORB("-ORBendPoint", ":::12321");
212
213 if (genAndQuit && retVal < 1) retVal = 1;
214
215 if (help != osg::ApplicationUsage::NO_HELP) {
216 arguments.getApplicationUsage()->write(std::cout, help, 80, true);
217 if (help & osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE) {
218 const std::string tab(" ");
219 const char nl = '\n';
220 std::cout << "---------- gepetto-gui specific variables ---------" << nl
221 << nl << tab << "GEPETTO_GUI_SETTINGS_DIR" << nl << nl << tab
222 << tab << "Configure the system configuration directory." << nl
223 << nl << tab << "GEPETTO_GUI_PLUGIN_DIRS" << nl << nl << tab
224 << tab << "Configure the plugin search directories."
225 << std::endl;
226 }
227 if (retVal < 1) retVal = 1;
228 }
229 if (verbose) print(std::cout) << std::endl;
230 if (genAndQuit) writeSettings();
231
232 if (!logFile.empty()) setLogFile(logFile.c_str());
233
234 return retVal;
235 }
236
237 void Settings::fromFiles() {
238 readRobotFile();
239 readEnvFile();
240 readSettingFile();
241 }
242
243 void Settings::writeSettings() {
244 writeRobotFile();
245 writeEnvFile();
246 writeSettingFile();
247 }
248
249 void Settings::initPlugins() {
250 foreach (QString name, pluginsToInit_) {
251 pluginManager_.loadPlugin(name);
252 pluginManager_.initPlugin(name);
253 }
254 foreach (QString name, pyplugins_) {
255 pluginManager_.loadPyPlugin(name);
256 }
257 #if GEPETTO_GUI_HAS_PYTHONQT
258 PythonWidget* pw = mw->pythonWidget();
259 // TODO Wouldn't it be better to do this later ?
260 foreach (QString fileName, pyscripts_) {
261 pw->runScript(fileName);
262 }
263 #else
264 foreach (QString fileName, pyscripts_) {
265 logError(
266 "gepetto-viewer was compiled without GEPETTO_GUI_HAS_"
267 "PYTHONQT flag. Cannot not load Python script " +
268 fileName);
269 }
270 #endif
271 }
272
273 void Settings::restoreState() const {
274 QSettings settings(QSettings::SystemScope,
275 QCoreApplication::organizationName(),
276 getQSettingsFileName(stateConf));
277 if (settings.status() != QSettings::NoError) {
278 qDebug() << "Could not restore the window state from"
279 << settings.fileName();
280 } else {
281 settings.beginGroup("mainWindow");
282 mw->restoreGeometry(settings.value("geometry").toByteArray());
283 mw->restoreState(settings.value("state").toByteArray());
284 mw->centralWidget()->setVisible(
285 settings.value("centralWidgetVisibility", true).toBool());
286 settings.endGroup();
287 #if GEPETTO_GUI_HAS_PYTHONQT
288 mw->pythonWidget()->restoreHistory(settings);
289 #endif
290 }
291 }
292
293 void Settings::restoreDockWidgetsState() const {
294 QSettings settings(QSettings::SystemScope,
295 QCoreApplication::organizationName(),
296 getQSettingsFileName(stateConf));
297 if (settings.status() != QSettings::NoError) {
298 qDebug() << "Could not restore the dock widget state from"
299 << settings.fileName();
300 } else {
301 settings.beginGroup("mainWindow");
302 mw->restoreState(settings.value("state").toByteArray());
303 settings.endGroup();
304 }
305 }
306
307 void Settings::saveState() const {
308 QSettings settings(QSettings::SystemScope,
309 QCoreApplication::organizationName(),
310 getQSettingsFileName(stateConf));
311 if (settings.status() != QSettings::NoError) {
312 qDebug() << "Could not save the window state to" << settings.fileName();
313 } else {
314 settings.beginGroup("mainWindow");
315 settings.setValue("geometry", mw->saveGeometry());
316 settings.setValue("state", mw->saveState());
317 settings.setValue("centralWidgetVisibility",
318 mw->centralWidget()->isVisible());
319 settings.endGroup();
320 #if GEPETTO_GUI_HAS_PYTHONQT
321 mw->pythonWidget()->saveHistory(settings);
322 #endif
323 }
324 }
325
326 void Settings::setMainWindow(gepetto::gui::MainWindow* main) { mw = main; }
327
328 std::ostream& Settings::print(std::ostream& os) {
329 const char tab = '\t';
330 const char nl = '\n';
331 os << nl << "Configuration:" << nl << tab
332 << "Configuration file: " << tab << configurationFile << nl
333 << tab << "Log file: " << tab
334 << (logFile.empty() ? "standard output" : logFile) << nl << tab
335 << "Predefined robots: " << tab << predifinedRobotConf << nl
336 << tab << "Predefined environments: " << tab << predifinedEnvConf
337 << nl << tab << "User configuration search path: " << tab
338 << QFileInfo(QSettings(QSettings::UserScope,
339 QCoreApplication::organizationName(), " ")
340 .fileName())
341 .absolutePath()
342 .toStdString()
343 << nl << tab << "System configuration search path:" << tab
344 << QFileInfo(QSettings(QSettings::SystemScope,
345 QCoreApplication::organizationName(), " ")
346 .fileName())
347 .absolutePath()
348 .toStdString()
349
350 << nl << nl << "Options:" << nl << tab
351 << "Verbose: " << tab << verbose << nl << tab
352 << "No plugin: " << tab << noPlugin << nl << tab
353 << "Use omni name service: " << tab << useNameService << nl
354 << tab << "Refresh rate: " << tab << refreshRate
355
356 << nl << nl << "Screen capture options:" << nl << tab
357 << "Directory: " << tab << captureDirectory << nl
358 << tab << "Filename: " << tab << captureFilename
359 << nl << tab << "Extension: " << tab
360 << captureExtension << nl << tab
361 << "ffmpeg command: " << tab << ffmpeg.toStdString()
362 << nl << tab << "ffmpeg input options: " << tab
363 << ffmpegInputOptions.join(" ").toStdString() << nl << tab
364 << "ffmpeg output options: " << tab
365 << ffmpegOutputOptions.join(" ").toStdString()
366
367 << nl << nl << "omniORB configuration";
368 for (int i = 1; i < omniORBargv_.size(); i += 2)
369 os << nl << tab << omniORBargv_[i - 1].toStdString() << " = "
370 << omniORBargv_[i].toStdString();
371 return os;
372 }
373
374 QString Settings::getQSettingsFileName(const std::string& settingsName) const {
375 QString name(QString::fromStdString(settingsName));
376 QString ext(".conf");
377 // Remove extension
378 if (name.endsWith(ext)) name = name.left(name.size() - ext.size());
379 return name;
380 }
381
382 void Settings::readRobotFile() {
383 QSettings robot(QSettings::SystemScope, QCoreApplication::organizationName(),
384 getQSettingsFileName(predifinedRobotConf));
385 if (robot.status() != QSettings::NoError) {
386 logError(QString("Unable to open configuration file ") + robot.fileName());
387 } else {
388 foreach (QString name, robot.childGroups()) {
389 robot.beginGroup(name);
390 QString robotName = robot.value("RobotName", name).toString();
391 DialogLoadRobot::addRobotDefinition(
392 name, robotName, robot.value("RootJointType", "freeflyer").toString(),
393 robot.value("ModelName", robotName).toString(),
394 robot.value("Package", "").toString(),
395 robot.value("URDFSuffix", "").toString(),
396 robot.value("SRDFSuffix", "").toString());
397 robot.endGroup();
398 }
399 log(QString("Read configuration file ") + robot.fileName());
400 }
401 }
402
403 void Settings::readEnvFile() {
404 QSettings env(QSettings::SystemScope, QCoreApplication::organizationName(),
405 getQSettingsFileName(predifinedEnvConf));
406 if (env.status() != QSettings::NoError) {
407 logError(QString("Unable to open configuration file ") + env.fileName());
408 } else {
409 foreach (QString name, env.childGroups()) {
410 env.beginGroup(name);
411 QString envName = env.value("EnvironmentName", name).toString();
412 DialogLoadEnvironment::addEnvironmentDefinition(
413 name, envName, env.value("Package", "").toString(),
414 env.value("URDFFilename").toString(),
415 env.value("URDFSuffix").toString(),
416 env.value("SRDFSuffix").toString());
417 env.endGroup();
418 }
419 log(QString("Read configuration file ") + env.fileName());
420 }
421 }
422
423 #define GET_PARAM(what, type, variantMethod) \
424 { \
425 QVariant param(env.value(#what, what)); \
426 if (param.canConvert<type>()) \
427 what = param.variantMethod(); \
428 else \
429 logError("Setting viewer/" #what " should be an " #type "."); \
430 }
431
432 void Settings::readSettingFile() {
433 QSettings env(QSettings::SystemScope, QCoreApplication::organizationName(),
434 getQSettingsFileName(configurationFile));
435 if (env.status() != QSettings::NoError) {
436 logError(QString("Unable to open configuration file ") + env.fileName());
437 } else {
438 osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
439 env.beginGroup("viewer");
440 GET_PARAM(refreshRate, int, toInt);
441 int nbMultiSamples = 4;
442 GET_PARAM(nbMultiSamples, int, toInt);
443 ds->setNumMultiSamples(nbMultiSamples);
444
445 QString appStyle;
446 GET_PARAM(appStyle, QString, toString);
447 if (!appStyle.isNull()) {
448 if (QStyleFactory::keys().contains(appStyle, Qt::CaseInsensitive))
449 this->appStyle = appStyle;
450 else {
451 logError("Available application styles are " +
452 QStyleFactory::keys().join(", "));
453 logError("Requested value is " + appStyle);
454 logError("Current value is " + this->appStyle);
455 }
456 }
457
458 GET_PARAM(useNameService, bool, toBool);
459 env.endGroup();
460
461 env.beginGroup("plugins");
462 foreach (QString name, env.childKeys()) {
463 addPlugin(name, (noPlugin) ? false : env.value(name, true).toBool());
464 }
465 env.endGroup();
466
467 env.beginGroup("pyplugins");
468 foreach (QString name, env.childKeys()) {
469 addPyPlugin(name, (noPlugin) ? false : env.value(name, true).toBool());
470 }
471 env.endGroup();
472
473 env.beginGroup("omniORB");
474 foreach (QString name, env.childKeys()) {
475 addOmniORB("-ORB" + name, env.value(name).toString());
476 }
477 env.endGroup();
478
479 env.beginGroup("ffmpeg");
480 ffmpeg = env.value("command", ffmpeg).toString();
481 ffmpegInputOptions =
482 env.value("input_options", ffmpegInputOptions).toStringList();
483 ffmpegOutputOptions =
484 env.value("output_options", ffmpegOutputOptions).toStringList();
485 env.endGroup();
486
487 env.beginGroup("settings");
488 logFile = env.value("log", QString::fromStdString(logFile))
489 .toString()
490 .toStdString();
491 env.endGroup();
492 log(QString("Read configuration file ") + env.fileName());
493 }
494 }
495
496 void Settings::writeRobotFile() {
497 QSettings robot(QSettings::SystemScope, QCoreApplication::organizationName(),
498 getQSettingsFileName(predifinedRobotConf));
499 if (!robot.isWritable()) {
500 log(QString("Configuration file ") + robot.fileName() +
501 QString(" is not writable."));
502 return;
503 }
504 foreach (DialogLoadRobot::RobotDefinition rd,
505 DialogLoadRobot::getRobotDefinitions()) {
506 if (rd.name_.isEmpty()) continue;
507 robot.beginGroup(rd.name_);
508 robot.setValue("RobotName", rd.robotName_);
509 robot.setValue("ModelName", rd.modelName_);
510 robot.setValue("RootJointType", rd.rootJointType_);
511 robot.setValue("Package", rd.package_);
512 robot.setValue("URDFSuffix", rd.urdfSuf_);
513 robot.setValue("SRDFSuffix", rd.srdfSuf_);
514 robot.endGroup();
515 }
516 log(QString("Wrote configuration file ") + robot.fileName());
517 }
518
519 void Settings::writeEnvFile() {
520 QSettings env(QSettings::SystemScope, QCoreApplication::organizationName(),
521 getQSettingsFileName(predifinedEnvConf));
522 if (!env.isWritable()) {
523 logError(QString("Configuration file") + env.fileName() +
524 QString("is not writable."));
525 return;
526 }
527 foreach (DialogLoadEnvironment::EnvironmentDefinition ed,
528 DialogLoadEnvironment::getEnvironmentDefinitions()) {
529 if (ed.name_.isEmpty()) continue;
530 env.beginGroup(ed.name_);
531 env.setValue("RobotName", ed.envName_);
532 env.setValue("Package", ed.package_);
533 env.setValue("URDFFilename", ed.urdfFilename_);
534 env.endGroup();
535 }
536 log(QString("Wrote configuration file ") + env.fileName());
537 }
538
539 void Settings::writeSettingFile() {
540 QSettings env(QSettings::SystemScope, QCoreApplication::organizationName(),
541 getQSettingsFileName(configurationFile));
542 if (!env.isWritable()) {
543 logError(QString("Configuration file") + env.fileName() +
544 QString("is not writable."));
545 return;
546 }
547
548 osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
549 env.beginGroup("viewer");
550 env.setValue("refreshRate", refreshRate);
551 env.setValue("nbMultiSamples", ds->getNumMultiSamples());
552 env.setValue("useNameService", useNameService);
553 env.setValue("appStyle", appStyle);
554 env.endGroup();
555
556 env.beginGroup("plugins");
557 for (PluginManager::Map::const_iterator p =
558 pluginManager_.plugins().constBegin();
559 p != pluginManager_.plugins().constEnd(); p++) {
560 env.setValue(p.key(), (noPlugin) ? false : p.value()->isLoaded());
561 }
562 env.endGroup();
563
564 env.beginGroup("pyplugins");
565 for (PluginManager::PyMap::const_iterator p =
566 pluginManager_.pyplugins().constBegin();
567 p != pluginManager_.pyplugins().constEnd(); p++) {
568 env.setValue(p.key(), (noPlugin)
569 ? false
570 : pluginManager_.isPyPluginLoaded(p.key()) ||
571 pyplugins_.contains(p.key()));
572 }
573 env.endGroup();
574
575 env.beginGroup("omniORB");
576 for (int i = 1; i < omniORBargv_.size(); i += 2)
577 env.setValue(omniORBargv_[i - 1].mid(4), omniORBargv_[i]);
578 env.endGroup();
579
580 env.beginGroup("ffmpeg");
581 env.setValue("command", ffmpeg);
582 env.setValue("input_options", ffmpegInputOptions);
583 env.setValue("output_options", ffmpegInputOptions);
584 env.endGroup();
585
586 env.beginGroup("settings");
587 env.setValue("log", QString::fromStdString(logFile));
588 env.endGroup();
589 log(QString("Wrote configuration file ") + env.fileName());
590 }
591
592 const char** Settings::makeOmniORBargs(int& argc) {
593 argc = omniORBargv_.size();
594 const char** argv = new const char*[argc];
595 for (int i = 0; i < argc; ++i) {
596 const QString& v = omniORBargv_[i];
597 argv[i] = strdup(v.toLocal8Bit().constData());
598 }
599 return argv;
600 }
601
602 QVariant Settings::getSetting(const QString& key,
603 const QVariant& defaultValue) {
604 QSettings env(QSettings::SystemScope, QCoreApplication::organizationName(),
605 getQSettingsFileName(configurationFile));
606 if (env.status() == QSettings::NoError) {
607 return env.value(key, defaultValue);
608 }
609 return defaultValue;
610 }
611
612 void Settings::addRobotFromString(const std::string& rbtStr) {
613 QString rbt = QString::fromStdString(rbtStr);
614 QStringList split = rbt.split(",", QString::KeepEmptyParts);
615 if (split.size() != 7) {
616 logError("Robot string is not of length 7");
617 logError(rbt);
618 return;
619 }
620 DialogLoadRobot::addRobotDefinition(split[0], split[1], split[2].toLower(),
621 split[3], split[4], split[5], split[6]);
622 }
623
624 void Settings::addEnvFromString(const std::string& envStr) {
625 QString env = QString::fromStdString(envStr);
626 QStringList split = env.split(",", QString::KeepEmptyParts);
627 if (split.size() != 6) {
628 logError("Environment string is not of length 6");
629 logError(env);
630 return;
631 }
632 DialogLoadEnvironment::addEnvironmentDefinition(split[0], split[1], split[2],
633 split[3], split[4], split[5]);
634 }
635
636 void Settings::addPlugin(const QString& plg, bool init) {
637 if (init) pluginsToInit_.append(plg);
638 pluginManager_.declarePlugin(plg);
639 }
640
641 void Settings::addPyPlugin(const QString& plg, bool init) {
642 if (init) pyplugins_.append(plg);
643 pluginManager_.declarePyPlugin(plg);
644 }
645
646 void Settings::addPyScript(const QString& fileName) {
647 pyscripts_.append(fileName);
648 }
649
650 void Settings::addOmniORB(const QString& arg, const QString& value) {
651 int i = omniORBargv_.indexOf(arg);
652 if (i == -1)
653 omniORBargv_ << arg << value;
654 else
655 omniORBargv_[i + 1] = value;
656 }
657
658 void Settings::log(const QString& t) {
659 if (!verbose) return;
660 if (mw)
661 mw->log(t);
662 else
663 gepetto::log() << t.toLocal8Bit().constData() << std::endl;
664 }
665
666 void Settings::logError(const QString& t) {
667 if (mw)
668 mw->logError(t);
669 else
670 qWarning() << t;
671 }
672 } // namespace gui
673 } // namespace gepetto
674