Skip to content

Commit b11d224

Browse files
authored
Merge pull request #72 from commontk/launcherlib-add-pathsEnvVars
launcherlib: Add method "pathsEnvVars()"
2 parents c5aca79 + 21796ac commit b11d224

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

Base/ctkAppLauncher.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,10 @@ void ctkAppLauncherPrivate::buildEnvironment(QProcessEnvironment &env)
431431
}
432432

433433
// Path environment variables
434-
QHash<QString, QStringList> envPathsVars = q->additionalPathsVars();
435-
// Add LibraryPaths and Paths to map
436-
#ifdef Q_OS_WIN32
437-
envPathsVars["PATH"] = (q->paths() + q->libraryPaths());
438-
#else
439-
envPathsVars[q->libraryPathVariableName()] = q->libraryPaths();
440-
envPathsVars["PATH"] = q->paths();
441-
#endif
442-
foreach(const QString& key, envPathsVars.keys())
434+
QHash<QString, QStringList> pathsEnvVars = q->pathsEnvVars();
435+
foreach(const QString& key, pathsEnvVars.keys())
443436
{
444-
QString value = envPathsVars[key].join(this->PathSep);
437+
QString value = pathsEnvVars[key].join(this->PathSep);
445438
this->reportInfo(QString("Setting env. variable [%1]:%2").arg(key, value));
446439
if (env.contains(key))
447440
{

Base/ctkAppLauncherSettings.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,19 @@ QHash<QString, QString> ctkAppLauncherSettings::envVars(bool expand /* = true */
394394
return expand ? d->MapOfExpandedEnvVars : d->MapOfEnvVars;
395395
}
396396

397+
// --------------------------------------------------------------------------
398+
QHash<QString, QStringList> ctkAppLauncherSettings::pathsEnvVars(bool expand /* = true */) const
399+
{
400+
QHash<QString, QStringList> newVars = this->additionalPathsVars(expand);
401+
#ifdef Q_OS_WIN32
402+
newVars["PATH"] = (this->paths(expand) + this->libraryPaths(expand));
403+
#else
404+
newVars[this->libraryPathVariableName()] = this->libraryPaths(expand);
405+
newVars["PATH"] = this->paths(expand);
406+
#endif
407+
return newVars;
408+
}
409+
397410
// --------------------------------------------------------------------------
398411
QStringList ctkAppLauncherSettings::additionalPaths(const QString& variableName, bool expand /* = true */) const
399412
{

Base/ctkAppLauncherSettings.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class ctkAppLauncherSettingsPrivate;
118118
/// appLauncherSettings.readSettings("/path/to/AwesomeAppLauncherSetting.ini");
119119
///
120120
/// // Get values (read from both the main settings file and the additional one).
121+
/// qDebug() << appLauncherSettings.pathsEnvVars().value("PATH");
122+
/// qDebug() << appLauncherSettings.pathsEnvVars().value("LD_LIBRARY_PATH");
123+
/// qDebug() << appLauncherSettings.pathsEnvVars().value("PYTHONPATH");
124+
/// qDebug() << appLauncherSettings.envVars().value("FOO");
125+
/// // or
121126
/// qDebug() << appLauncherSettings.paths();
122127
/// qDebug() << appLauncherSettings.libraryPaths();
123128
/// qDebug() << appLauncherSettings.additionalPathsVars().value("PYTHONPATH");
@@ -165,6 +170,32 @@ class ctkAppLauncherSettings : public QObject
165170
/// \sa envVar(const QString& variableName, bool expand)
166171
QHash<QString, QString> envVars(bool expand = true) const;
167172

173+
/// \brief Get dictionnary of all list of paths.
174+
///
175+
/// These include list of paths associated with:
176+
///
177+
/// * \c General/additionalPathVariables group (see additionalPathsVars()).
178+
///
179+
/// * \c LibraryPaths group (see libraryPaths()).
180+
///
181+
/// * \c Paths group (see paths()).
182+
///
183+
/// Depending on the platform, list associated with the \c LibraryPaths and \c Paths
184+
/// groups are mapped with different environment variable names:
185+
///
186+
/// Variable name | Linux | MacOSX | Windows
187+
/// ----------------------|-----------------|-----------------|--------------------------|
188+
/// `LD_LIBRARY_PATH` | libraryPaths() | NA | NA |
189+
/// `DYLD_LIBRARY_PATH` | NA | libraryPaths() | NA |
190+
/// `PATH` | paths() | paths() | paths() + libraryPaths() |
191+
///
192+
/// \sa additionalPathsVars(bool expand)
193+
/// \sa libraryPaths(bool expand)
194+
/// \sa paths(bool expand)
195+
/// \sa libraryPathVariableName()
196+
///
197+
QHash<QString, QStringList> pathsEnvVars(bool expand = true) const;
198+
168199
/// \brief Get paths associated with \a variableName.
169200
///
170201
/// The returned list corresponds to the path list identified by one of

0 commit comments

Comments
 (0)