Skip to content

Commit

Permalink
[FEATURE] Added --configpath option that overrides the default path (…
Browse files Browse the repository at this point in the history
…~/.qgis) for user configuration and forces QSettings to use this directory, too.\

This allows users to e.g. carry QGIS installation on a flash drive together with all plugins and settings.

Developed for Faunalia (http://www.faunalia.it) with funding from Regione Toscana - Sistema Informativo per la Gestione del Territorio e dell' Ambiente [RT-SIGTA].
For the project: "Sviluppo di prodotti software GIS open-source basati sui prodotti QuantumGIS e Postgis (CIG 037728516E)"


git-svn-id: http://svn.osgeo.org/qgis/trunk@13951 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 21, 2010
1 parent 5578096 commit 19506e9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/core/qgsapplication.sip
Expand Up @@ -58,7 +58,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)

public:
//QgsApplication(int argc, char ** argv, bool GUIenabled);
QgsApplication(SIP_PYLIST argv, bool GUIenabled) /PostHook=__pyQtQAppHook__/ [(int &argc, char **argv, bool GUIenabled)];
QgsApplication(SIP_PYLIST argv, bool GUIenabled, QString customConfigPath = QString() ) /PostHook=__pyQtQAppHook__/ [(int &argc, char **argv, bool GUIenabled, QString customConfigPath = QString() )];
%MethodCode
// The Python interface is a list of argument strings that is modified.

Expand All @@ -73,7 +73,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
// Create it now the arguments are right.
static int nargc = argc;

sipCpp = new sipQgsApplication(nargc, argv, a1);
sipCpp = new sipQgsApplication(nargc, argv, a1, *a2);

// Now modify the original list.
qtgui_UpdatePyArgv(a0, argc, argv);
Expand Down
30 changes: 26 additions & 4 deletions src/app/main.cpp
Expand Up @@ -100,6 +100,7 @@ void usage( std::string const & appName )
<< "\t[--nologo]\thide splash screen\n"
<< "\t[--noplugins]\tdon't restore plugins on startup\n"
<< "\t[--optionspath path]\tuse the given QSettings path\n"
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
<< "\t[--help]\t\tthis text\n\n"
<< " FILES:\n"
<< " Files specified on the command line can include rasters,\n"
Expand Down Expand Up @@ -288,6 +289,10 @@ int main( int argc, char *argv[] )
// which is useful for testing
QString myTranslationCode;

// The user can specify a path which will override the default path of custom
// user settings (~/.qgis) and it will be used for QSettings INI file
QString configpath;

#ifndef WIN32
if ( !bundleclicked( argc, argv ) )
{
Expand All @@ -314,13 +319,14 @@ int main( int argc, char *argv[] )
{"project", required_argument, 0, 'p'},
{"extent", required_argument, 0, 'e'},
{"optionspath", required_argument, 0, 'o'},
{"configpath", required_argument, 0, 'c'},
{0, 0, 0, 0}
};

/* getopt_long stores the option index here. */
int option_index = 0;

optionChar = getopt_long( argc, argv, "swhlpeo",
optionChar = getopt_long( argc, argv, "swhlpeoc",
long_options, &option_index );

/* Detect the end of the options. */
Expand Down Expand Up @@ -372,7 +378,11 @@ int main( int argc, char *argv[] )
break;

case 'o':
QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, optarg );
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optarg );
break;

case 'c':
configpath = optarg;
break;

case '?':
Expand Down Expand Up @@ -445,7 +455,12 @@ int main( int argc, char *argv[] )
}
else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) )
{
QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, argv[++i] );
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, argv[++i] );
}
else if ( i + 1 < argc && ( arg == "--configpath" || arg == "-c" ) )
{
configpath = argv[++i];
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
}
else
{
Expand Down Expand Up @@ -476,7 +491,14 @@ int main( int argc, char *argv[] )
).toUtf8().constData();
exit( 1 ); //exit for now until a version of qgis is capabable of running non interactive
}
QgsApplication myApp( argc, argv, myUseGuiFlag );

if ( !configpath.isEmpty() )
{
// tell QSettings to use INI format and save the file in custom config path
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
}

QgsApplication myApp( argc, argv, myUseGuiFlag, configpath );

// (if Windows/Mac, use icon from resource)
#if ! defined(Q_WS_WIN) && ! defined(Q_WS_MAC)
Expand Down
10 changes: 8 additions & 2 deletions src/core/qgsapplication.cpp
Expand Up @@ -39,6 +39,7 @@ QString QgsApplication::mPluginPath;
QString QgsApplication::mPkgDataPath;
QString QgsApplication::mThemeName;
QStringList QgsApplication::mDefaultSvgPaths;
QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );

/*!
\class QgsApplication
Expand All @@ -53,7 +54,7 @@ QStringList QgsApplication::mDefaultSvgPaths;
so that platform-conditional code is minimized and paths are easier
to change due to centralization.
*/
QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled )
QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, QString customConfigPath )
: QApplication( argc, argv, GUIenabled )
{
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32)
Expand All @@ -65,6 +66,11 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled )
setPrefixPath( myPrefix, true );
#endif

if ( !customConfigPath.isEmpty() )
{
mConfigPath = customConfigPath + "/"; // make sure trailing slash is included
}

mDefaultSvgPaths << mPkgDataPath + QString( "/svg/" );
mDefaultSvgPaths << qgisSettingsDirPath() + QString( "svg/" );
}
Expand Down Expand Up @@ -284,7 +290,7 @@ const QString QgsApplication::qgisSpatialiteDbTemplatePath()
*/
const QString QgsApplication::qgisSettingsDirPath()
{
return QDir::homePath() + QString( "/.qgis/" );
return mConfigPath;
}

/*!
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsapplication.h
Expand Up @@ -26,7 +26,8 @@ class CORE_EXPORT QgsApplication: public QApplication
{
Q_OBJECT
public:
QgsApplication( int & argc, char ** argv, bool GUIenabled );
//! @note customConfigDir parameter added in v1.6
QgsApplication( int & argc, char ** argv, bool GUIenabled, QString customConfigPath = QString() );
virtual ~QgsApplication();

//! Catch exceptions when sending event to receiver.
Expand Down Expand Up @@ -197,6 +198,8 @@ class CORE_EXPORT QgsApplication: public QApplication
static QString mPkgDataPath;
static QString mThemeName;
static QStringList mDefaultSvgPaths;

static QString mConfigPath;
};

#endif

0 comments on commit 19506e9

Please sign in to comment.