Permalink
Browse files

Add support for user additional settings

* The launcher will look up for a file named:

  /path/to/user/settings/<organizationName|organizationDomain>/<applicationName>AdditionalLauncherSettings[-<applicationRevision>]

If such file exists, library paths, paths and env variables settings will be
considered. Library paths and paths will be prepended. Env variable behavior
can be configured based on the location of the <env:VARNAME> statements. For example:

FOO=<env:FOO>:Something

or

FOO=Something:<env:FOO>

* It's also possible to configure the basename of the settings that is lookup.
This can be done by settings: userAdditionalSettingsFileBaseName

* <organizationDomain>, <organizationName>, <applicationName> and <applicationRevision>
are read from launcher settings. For example:

[Application]
organizationDomain=www.commontk.org
organizationName=Common ToolKit
name=CTKAppLauncher
revision=4810

* If application name is omitted, the following file will be looked up:

  /path/to/user/settings/<organizationName|organizationDomain>AdditionalLauncherSettings[-<applicationRevision>]

* If organization name is omitted, the following file will be looked up:

  /path/to/user/settings/<organizationDomain>/<applicationName>AdditionalLauncherSettings[-<applicationRevision>]

* If both organization name and domain are omitted, the following file will be looked up:

  /path/to/user/settings/Unknown Organization/<applicationName>AdditionalLauncherSettings[-<applicationRevision>]

* If organization name, domain and application name are omitted, the following file will be looked up:

  /path/to/user/settings/Unknown OrganizationAdditionalLauncherSettings[-<applicationRevision>]

* If application revision is omitted, prefix [-<applicationRevision>] will NOT
be considered.

* Add command line argument --launcher-ignore-user-additional-settings

See #10, #8
  • Loading branch information...
1 parent 2e7e047 commit 8409dec6a66ea1c86eac4410c989fe3dedb6dcce @jcfr jcfr committed Nov 28, 2012
View
@@ -24,6 +24,7 @@
// --------------------------------------------------------------------------
ctkAppLauncherInternal::ctkAppLauncherInternal()
{
+ QSettings::setDefaultFormat(QSettings::IniFormat);
this->LauncherStarting = false;
this->Application = 0;
this->Initialized = false;
@@ -77,6 +78,34 @@ void ctkAppLauncherInternal::exit(int exitCode)
}
}
+// --------------------------------------------------------------------------
+QString ctkAppLauncherInternal::additionalSettingsDir()const
+{
+ QFileInfo fileInfo(QSettings().fileName());
+ return fileInfo.path();
+}
+
+// --------------------------------------------------------------------------
+QString ctkAppLauncherInternal::findUserAdditionalSettings()const
+{
+ QString prefix = QFileInfo(QSettings().fileName()).completeBaseName();
+ QString suffix;
+ if (!this->ApplicationRevision.isEmpty())
+ {
+ suffix = "-" + this->ApplicationRevision;
+ }
+ QString fileName =
+ QDir(this->additionalSettingsDir()).filePath(QString("%1%2%3.ini").
+ arg(prefix).
+ arg(this->UserAdditionalSettingsFileBaseName).
+ arg(suffix));
+ if (QFile::exists(fileName))
+ {
+ return fileName;
+ }
+ return QString();
+}
+
// --------------------------------------------------------------------------
bool ctkAppLauncherInternal::processSplashPathArgument()
{
@@ -125,9 +154,23 @@ bool ctkAppLauncherInternal::processAdditionalSettingsArgument()
return false;
}
- this->readSettings(additionalSettings, Self::AdditionalSettings);
+ return this->readSettings(additionalSettings, Self::AdditionalSettings);
+}
- return true;
+// --------------------------------------------------------------------------
+bool ctkAppLauncherInternal::processUserAdditionalSettings()
+{
+ if (this->ParsedArgs.value("launcher-ignore-user-additional-settings").toBool())
+ {
+ return true;
+ }
+
+ QString additionalSettings = this->findUserAdditionalSettings();
+ if(additionalSettings.isEmpty())
+ {
+ return true;
+ }
+ return this->readSettings(additionalSettings, Self::UserAdditionalSettings);
}
// --------------------------------------------------------------------------
@@ -390,6 +433,10 @@ bool ctkAppLauncherInternal::readSettings(const QString& fileName, int settingsT
{
settingsTypeDesc = QLatin1String(" additional");
}
+ if(settingsType == Self::UserAdditionalSettings)
+ {
+ settingsTypeDesc = QLatin1String(" user additional");
+ }
// Check if settings file exists
if (!QFile::exists(fileName))
@@ -429,6 +476,9 @@ bool ctkAppLauncherInternal::readSettings(const QString& fileName, int settingsT
bool noSplashScreen = settings.value("launcherNoSplashScreen", false).toBool();
this->LauncherNoSplashScreen = noSplashScreen;
+ this->UserAdditionalSettingsFileBaseName =
+ settings.value("userAdditionalSettingsFileBaseName", "AdditionalLauncherSettings").toString();
+
// Read default application to launch
QHash<QString, QString> applicationGroup = ctk::readKeyValuePairs(settings, "Application");
if (applicationGroup.contains("path"))
@@ -439,6 +489,27 @@ bool ctkAppLauncherInternal::readSettings(const QString& fileName, int settingsT
{
this->DefaultApplicationToLaunchArguments = applicationGroup["arguments"];
}
+ if(settingsType == Self::RegularSettings)
+ {
+ // Read revision, organization and application names
+ this->OrganizationName = applicationGroup["organizationName"];
+ this->OrganizationDomain = applicationGroup["organizationDomain"];
+ this->ApplicationName = applicationGroup["name"];
+ this->ApplicationRevision = applicationGroup["revision"];
+
+ if (!this->OrganizationName.isEmpty())
+ {
+ qApp->setOrganizationName(this->OrganizationName);
+ }
+ if (!this->OrganizationDomain.isEmpty())
+ {
+ qApp->setOrganizationDomain(this->OrganizationDomain);
+ }
+ if (!this->ApplicationName.isEmpty())
+ {
+ qApp->setApplicationName(this->ApplicationName);
+ }
+ }
// Read additional launcher arguments
QString helpShortArgument = settings.value("additionalLauncherHelpShortArgument").toString();
@@ -731,6 +802,8 @@ bool ctkAppLauncher::initialize(QString launcherFilePath)
"Launcher will print environment variables to be set, then exit");
parser.addArgument("launcher-additional-settings", "", QVariant::String,
"Additional settings file to consider");
+ parser.addArgument("launcher-ignore-user-additional-settings", "", QVariant::Bool,
+ "Ignore additional user settings");
parser.addArgument("launcher-generate-template", "", QVariant::Bool,
"Generate an example of setting file");
@@ -780,7 +853,13 @@ int ctkAppLauncher::processArguments()
return Self::ExitWithError;
}
- if (this->Internal->LauncherStarting)
+ bool reportInfo = this->Internal->LauncherStarting
+ || this->Internal->ParsedArgs.value("launcher-help").toBool()
+ || this->Internal->ParsedArgs.value("launcher-version").toBool()
+ || this->Internal->ParsedArgs.value("launcher-dump-environment").toBool()
+ || this->Internal->ParsedArgs.value("launcher-generate-template").toBool();
+
+ if (reportInfo)
{
this->Internal->reportInfo(
QString("LauncherDir [%1]").arg(this->Internal->LauncherDir));
@@ -789,7 +868,25 @@ int ctkAppLauncher::processArguments()
QString("LauncherName [%1]").arg(this->Internal->LauncherName));
this->Internal->reportInfo(
- QString("SettingsFileName [%1]").arg(this->findSettingFile()));
+ QString("OrganizationDomain [%1]").arg(this->Internal->OrganizationDomain));
+
+ this->Internal->reportInfo(
+ QString("OrganizationName [%1]").arg(this->Internal->OrganizationName));
+
+ this->Internal->reportInfo(
+ QString("ApplicationName [%1]").arg(this->Internal->ApplicationName));
+
+ this->Internal->reportInfo(
+ QString("ApplicationRevision [%1]").arg(this->Internal->ApplicationRevision));
+
+ this->Internal->reportInfo(
+ QString("SettingsFileName [%1]").arg(this->findSettingsFile()));
+
+ this->Internal->reportInfo(
+ QString("AdditionalSettingsDir [%1]").arg(this->Internal->additionalSettingsDir()));
+
+ this->Internal->reportInfo(
+ QString("AdditionalSettingsFileName [%1]").arg(this->findUserAdditionalSettings()));
}
if (this->Internal->ParsedArgs.value("launcher-help").toBool())
@@ -804,6 +901,11 @@ int ctkAppLauncher::processArguments()
return Self::ExitWithSuccess;
}
+ if (!this->Internal->processUserAdditionalSettings())
+ {
+ return Self::ExitWithError;
+ }
+
if (!this->Internal->processAdditionalSettingsArgument())
{
return Self::ExitWithError;
@@ -863,7 +965,7 @@ int ctkAppLauncher::processArguments()
}
// --------------------------------------------------------------------------
-QString ctkAppLauncher::findSettingFile()const
+QString ctkAppLauncher::findSettingsFile()const
{
if (!this->Internal->Initialized)
{
@@ -883,6 +985,12 @@ QString ctkAppLauncher::findSettingFile()const
return QString();
}
+// --------------------------------------------------------------------------
+QString ctkAppLauncher::findUserAdditionalSettings()const
+{
+ return this->Internal->findUserAdditionalSettings();
+}
+
// --------------------------------------------------------------------------
bool ctkAppLauncher::readSettings(const QString& fileName)
{
@@ -937,12 +1045,6 @@ bool ctkAppLauncher::writeSettings(const QString& outputFilePath)
return true;
}
-// --------------------------------------------------------------------------
-bool ctkAppLauncher::readAdditonalSettings(const QString& fileName)
-{
- return this->Internal->readSettings(fileName, ctkAppLauncherInternal::AdditionalSettings);
-}
-
// --------------------------------------------------------------------------
const QStringList& ctkAppLauncher::libraryPaths()const
{
@@ -1061,7 +1163,7 @@ int ctkAppLauncher::configure()
return ctkAppLauncher::ExitWithError;
}
- QString settingFileName = this->findSettingFile();
+ QString settingFileName = this->findSettingsFile();
this->Internal->ValidSettingsFile = this->readSettings(settingFileName);
View
@@ -74,16 +74,21 @@ class ctkAppLauncher : public QObject
/// Return associated settingsFileName
/// Will return an empty string if the object is NOT initialized or
/// if the file does NOT exist
- QString findSettingFile()const;
+ QString findSettingsFile()const;
+
+ /// Return user specific additional settings file associated with the \a ApplicationOrganization,
+ /// \a ApplicationName and \a ApplicationRevision read from the main settings.
+ /// The location of the additional settings file is expected to match the following name
+ /// and path: path/to/settings/<OrganisationName|DomainName>/<ApplicationName>(-<revision>).ini
+ /// If the settings file does NOT exist, an empty string will be returned.
+ /// \sa additionalSettingsDir()
+ QString findUserAdditionalSettings()const;
/// Read/Write settings
/// Will return False if the object is NOT initialized
bool readSettings(const QString& fileName);
bool writeSettings(const QString& outputFilePath);
- /// Read additional settings
- bool readAdditonalSettings(const QString& fileName);
-
/// Set/Get list of library paths
const QStringList& libraryPaths()const;
void setLibraryPaths(const QStringList& listOfLibraryPaths);
View
@@ -34,11 +34,19 @@ class ctkAppLauncherInternal : public QObject
/// \sa ctkAppLauncher::setApplication
void exit(int exitCode);
+ /// Return additional settings directory associated with the \a ApplicationOrganization
+ /// read from the main settings.
+ /// The location of the additional settings directory is expected to match the following
+ /// path: path/to/settings/<OrganisationName|DomainName>/
+ QString additionalSettingsDir()const;
+
+ QString findUserAdditionalSettings()const;
+
enum SettingsType
{
RegularSettings = 0,
- AdditionalSettings
- //AlternativeSettings
+ AdditionalSettings,
+ UserAdditionalSettings
};
bool readSettings(const QString& fileName, int settingsType);
@@ -50,6 +58,9 @@ class ctkAppLauncherInternal : public QObject
bool processScreenHideDelayMsArgument();
bool processAdditionalSettingsArgument();
+ /// \sa ctkAppLauncher::findUserAdditionalSettings()
+ bool processUserAdditionalSettings();
+
bool extractLauncherNameAndDir(const QString& applicationFilePath);
/// \brief Expand setting \a value
@@ -111,6 +122,11 @@ public slots:
QString LauncherDir;
QStringList LauncherSettingSubDirs;
bool ValidSettingsFile;
+ QString OrganizationName;
+ QString OrganizationDomain;
+ QString ApplicationName;
+ QString ApplicationRevision;
+ QString UserAdditionalSettingsFileBaseName;
QString LauncherAdditionalHelpShortArgument;
QString LauncherAdditionalHelpLongArgument;
QStringList LauncherAdditionalNoSplashArguments;
Oops, something went wrong.

0 comments on commit 8409dec

Please sign in to comment.