[FEATURE] Added --configpath option that overrides the default path (~/.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
This commit is contained in:
wonder 2010-07-21 13:12:47 +00:00
parent 5578096443
commit 19506e9cdd
4 changed files with 40 additions and 9 deletions

View File

@ -58,7 +58,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
public: public:
//QgsApplication(int argc, char ** argv, bool GUIenabled); //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 %MethodCode
// The Python interface is a list of argument strings that is modified. // The Python interface is a list of argument strings that is modified.
@ -73,7 +73,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
// Create it now the arguments are right. // Create it now the arguments are right.
static int nargc = argc; static int nargc = argc;
sipCpp = new sipQgsApplication(nargc, argv, a1); sipCpp = new sipQgsApplication(nargc, argv, a1, *a2);
// Now modify the original list. // Now modify the original list.
qtgui_UpdatePyArgv(a0, argc, argv); qtgui_UpdatePyArgv(a0, argc, argv);

View File

@ -100,6 +100,7 @@ void usage( std::string const & appName )
<< "\t[--nologo]\thide splash screen\n" << "\t[--nologo]\thide splash screen\n"
<< "\t[--noplugins]\tdon't restore plugins on startup\n" << "\t[--noplugins]\tdon't restore plugins on startup\n"
<< "\t[--optionspath path]\tuse the given QSettings path\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" << "\t[--help]\t\tthis text\n\n"
<< " FILES:\n" << " FILES:\n"
<< " Files specified on the command line can include rasters,\n" << " Files specified on the command line can include rasters,\n"
@ -288,6 +289,10 @@ int main( int argc, char *argv[] )
// which is useful for testing // which is useful for testing
QString myTranslationCode; 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 #ifndef WIN32
if ( !bundleclicked( argc, argv ) ) if ( !bundleclicked( argc, argv ) )
{ {
@ -314,13 +319,14 @@ int main( int argc, char *argv[] )
{"project", required_argument, 0, 'p'}, {"project", required_argument, 0, 'p'},
{"extent", required_argument, 0, 'e'}, {"extent", required_argument, 0, 'e'},
{"optionspath", required_argument, 0, 'o'}, {"optionspath", required_argument, 0, 'o'},
{"configpath", required_argument, 0, 'c'},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
/* getopt_long stores the option index here. */ /* getopt_long stores the option index here. */
int option_index = 0; int option_index = 0;
optionChar = getopt_long( argc, argv, "swhlpeo", optionChar = getopt_long( argc, argv, "swhlpeoc",
long_options, &option_index ); long_options, &option_index );
/* Detect the end of the options. */ /* Detect the end of the options. */
@ -372,7 +378,11 @@ int main( int argc, char *argv[] )
break; break;
case 'o': case 'o':
QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, optarg ); QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optarg );
break;
case 'c':
configpath = optarg;
break; break;
case '?': case '?':
@ -445,7 +455,12 @@ int main( int argc, char *argv[] )
} }
else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) ) 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 else
{ {
@ -476,7 +491,14 @@ int main( int argc, char *argv[] )
).toUtf8().constData(); ).toUtf8().constData();
exit( 1 ); //exit for now until a version of qgis is capabable of running non interactive 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 Windows/Mac, use icon from resource)
#if ! defined(Q_WS_WIN) && ! defined(Q_WS_MAC) #if ! defined(Q_WS_WIN) && ! defined(Q_WS_MAC)

View File

@ -39,6 +39,7 @@ QString QgsApplication::mPluginPath;
QString QgsApplication::mPkgDataPath; QString QgsApplication::mPkgDataPath;
QString QgsApplication::mThemeName; QString QgsApplication::mThemeName;
QStringList QgsApplication::mDefaultSvgPaths; QStringList QgsApplication::mDefaultSvgPaths;
QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );
/*! /*!
\class QgsApplication \class QgsApplication
@ -53,7 +54,7 @@ QStringList QgsApplication::mDefaultSvgPaths;
so that platform-conditional code is minimized and paths are easier so that platform-conditional code is minimized and paths are easier
to change due to centralization. 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 ) : QApplication( argc, argv, GUIenabled )
{ {
#if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32) #if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32)
@ -65,6 +66,11 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled )
setPrefixPath( myPrefix, true ); setPrefixPath( myPrefix, true );
#endif #endif
if ( !customConfigPath.isEmpty() )
{
mConfigPath = customConfigPath + "/"; // make sure trailing slash is included
}
mDefaultSvgPaths << mPkgDataPath + QString( "/svg/" ); mDefaultSvgPaths << mPkgDataPath + QString( "/svg/" );
mDefaultSvgPaths << qgisSettingsDirPath() + QString( "svg/" ); mDefaultSvgPaths << qgisSettingsDirPath() + QString( "svg/" );
} }
@ -284,7 +290,7 @@ const QString QgsApplication::qgisSpatialiteDbTemplatePath()
*/ */
const QString QgsApplication::qgisSettingsDirPath() const QString QgsApplication::qgisSettingsDirPath()
{ {
return QDir::homePath() + QString( "/.qgis/" ); return mConfigPath;
} }
/*! /*!

View File

@ -26,7 +26,8 @@ class CORE_EXPORT QgsApplication: public QApplication
{ {
Q_OBJECT Q_OBJECT
public: 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(); virtual ~QgsApplication();
//! Catch exceptions when sending event to receiver. //! Catch exceptions when sending event to receiver.
@ -197,6 +198,8 @@ class CORE_EXPORT QgsApplication: public QApplication
static QString mPkgDataPath; static QString mPkgDataPath;
static QString mThemeName; static QString mThemeName;
static QStringList mDefaultSvgPaths; static QStringList mDefaultSvgPaths;
static QString mConfigPath;
}; };
#endif #endif