mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[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:
parent
5578096443
commit
19506e9cdd
@ -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.
|
||||
|
||||
@ -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);
|
||||
|
@ -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"
|
||||
@ -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 ) )
|
||||
{
|
||||
@ -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. */
|
||||
@ -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 '?':
|
||||
@ -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
|
||||
{
|
||||
@ -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)
|
||||
|
@ -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
|
||||
@ -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)
|
||||
@ -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/" );
|
||||
}
|
||||
@ -284,7 +290,7 @@ const QString QgsApplication::qgisSpatialiteDbTemplatePath()
|
||||
*/
|
||||
const QString QgsApplication::qgisSettingsDirPath()
|
||||
{
|
||||
return QDir::homePath() + QString( "/.qgis/" );
|
||||
return mConfigPath;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -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.
|
||||
@ -197,6 +198,8 @@ class CORE_EXPORT QgsApplication: public QApplication
|
||||
static QString mPkgDataPath;
|
||||
static QString mThemeName;
|
||||
static QStringList mDefaultSvgPaths;
|
||||
|
||||
static QString mConfigPath;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user