GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/gui/settings.cc Lines: 1 348 0.3 %
Date: 2020-05-14 11:23:33 Branches: 2 1744 0.1 %

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

3
} // namespace gepetto