Skip to content

Commit 19506e9

Browse files
author
wonder
committed
[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
1 parent 5578096 commit 19506e9

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

python/core/qgsapplication.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
5858

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

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

76-
sipCpp = new sipQgsApplication(nargc, argv, a1);
76+
sipCpp = new sipQgsApplication(nargc, argv, a1, *a2);
7777

7878
// Now modify the original list.
7979
qtgui_UpdatePyArgv(a0, argc, argv);

src/app/main.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void usage( std::string const & appName )
100100
<< "\t[--nologo]\thide splash screen\n"
101101
<< "\t[--noplugins]\tdon't restore plugins on startup\n"
102102
<< "\t[--optionspath path]\tuse the given QSettings path\n"
103+
<< "\t[--configpath path]\tuse the given path for all user configuration\n"
103104
<< "\t[--help]\t\tthis text\n\n"
104105
<< " FILES:\n"
105106
<< " Files specified on the command line can include rasters,\n"
@@ -288,6 +289,10 @@ int main( int argc, char *argv[] )
288289
// which is useful for testing
289290
QString myTranslationCode;
290291

292+
// The user can specify a path which will override the default path of custom
293+
// user settings (~/.qgis) and it will be used for QSettings INI file
294+
QString configpath;
295+
291296
#ifndef WIN32
292297
if ( !bundleclicked( argc, argv ) )
293298
{
@@ -314,13 +319,14 @@ int main( int argc, char *argv[] )
314319
{"project", required_argument, 0, 'p'},
315320
{"extent", required_argument, 0, 'e'},
316321
{"optionspath", required_argument, 0, 'o'},
322+
{"configpath", required_argument, 0, 'c'},
317323
{0, 0, 0, 0}
318324
};
319325

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

323-
optionChar = getopt_long( argc, argv, "swhlpeo",
329+
optionChar = getopt_long( argc, argv, "swhlpeoc",
324330
long_options, &option_index );
325331

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

374380
case 'o':
375-
QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, optarg );
381+
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optarg );
382+
break;
383+
384+
case 'c':
385+
configpath = optarg;
376386
break;
377387

378388
case '?':
@@ -445,7 +455,12 @@ int main( int argc, char *argv[] )
445455
}
446456
else if ( i + 1 < argc && ( arg == "--optionspath" || arg == "-o" ) )
447457
{
448-
QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, argv[++i] );
458+
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, argv[++i] );
459+
}
460+
else if ( i + 1 < argc && ( arg == "--configpath" || arg == "-c" ) )
461+
{
462+
configpath = argv[++i];
463+
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
449464
}
450465
else
451466
{
@@ -476,7 +491,14 @@ int main( int argc, char *argv[] )
476491
).toUtf8().constData();
477492
exit( 1 ); //exit for now until a version of qgis is capabable of running non interactive
478493
}
479-
QgsApplication myApp( argc, argv, myUseGuiFlag );
494+
495+
if ( !configpath.isEmpty() )
496+
{
497+
// tell QSettings to use INI format and save the file in custom config path
498+
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, configpath );
499+
}
500+
501+
QgsApplication myApp( argc, argv, myUseGuiFlag, configpath );
480502

481503
// (if Windows/Mac, use icon from resource)
482504
#if ! defined(Q_WS_WIN) && ! defined(Q_WS_MAC)

src/core/qgsapplication.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ QString QgsApplication::mPluginPath;
3939
QString QgsApplication::mPkgDataPath;
4040
QString QgsApplication::mThemeName;
4141
QStringList QgsApplication::mDefaultSvgPaths;
42+
QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );
4243

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

69+
if ( !customConfigPath.isEmpty() )
70+
{
71+
mConfigPath = customConfigPath + "/"; // make sure trailing slash is included
72+
}
73+
6874
mDefaultSvgPaths << mPkgDataPath + QString( "/svg/" );
6975
mDefaultSvgPaths << qgisSettingsDirPath() + QString( "svg/" );
7076
}
@@ -284,7 +290,7 @@ const QString QgsApplication::qgisSpatialiteDbTemplatePath()
284290
*/
285291
const QString QgsApplication::qgisSettingsDirPath()
286292
{
287-
return QDir::homePath() + QString( "/.qgis/" );
293+
return mConfigPath;
288294
}
289295

290296
/*!

src/core/qgsapplication.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class CORE_EXPORT QgsApplication: public QApplication
2626
{
2727
Q_OBJECT
2828
public:
29-
QgsApplication( int & argc, char ** argv, bool GUIenabled );
29+
//! @note customConfigDir parameter added in v1.6
30+
QgsApplication( int & argc, char ** argv, bool GUIenabled, QString customConfigPath = QString() );
3031
virtual ~QgsApplication();
3132

3233
//! Catch exceptions when sending event to receiver.
@@ -197,6 +198,8 @@ class CORE_EXPORT QgsApplication: public QApplication
197198
static QString mPkgDataPath;
198199
static QString mThemeName;
199200
static QStringList mDefaultSvgPaths;
201+
202+
static QString mConfigPath;
200203
};
201204

202205
#endif

0 commit comments

Comments
 (0)