[QGIS Commit] r13951 - in trunk/qgis: python/core src/app src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Jul 21 09:12:48 EDT 2010


Author: wonder
Date: 2010-07-21 13:12:47 +0000 (Wed, 21 Jul 2010)
New Revision: 13951

Modified:
   trunk/qgis/python/core/qgsapplication.sip
   trunk/qgis/src/app/main.cpp
   trunk/qgis/src/core/qgsapplication.cpp
   trunk/qgis/src/core/qgsapplication.h
Log:
[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)"


Modified: trunk/qgis/python/core/qgsapplication.sip
===================================================================
--- trunk/qgis/python/core/qgsapplication.sip	2010-07-21 10:10:43 UTC (rev 13950)
+++ trunk/qgis/python/core/qgsapplication.sip	2010-07-21 13:12:47 UTC (rev 13951)
@@ -58,7 +58,7 @@
 
   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 @@
             // 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);

Modified: trunk/qgis/src/app/main.cpp
===================================================================
--- trunk/qgis/src/app/main.cpp	2010-07-21 10:10:43 UTC (rev 13950)
+++ trunk/qgis/src/app/main.cpp	2010-07-21 13:12:47 UTC (rev 13951)
@@ -100,6 +100,7 @@
             << "\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 @@
   // 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 @@
         {"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,9 +378,13 @@
           break;
 
         case 'o':
-          QSettings::setPath( QSettings::NativeFormat, QSettings::UserScope, optarg );
+          QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optarg );
           break;
 
+        case 'c':
+          configpath = optarg;
+          break;
+
         case '?':
           usage( argv[0] );
           return 2;   // XXX need standard exit codes
@@ -445,8 +455,13 @@
     }
     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
     {
       myFileList.append( QDir::convertSeparators( QFileInfo( QFile::decodeName( argv[i] ) ).absoluteFilePath() ) );
@@ -476,8 +491,15 @@
               ).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)
   myApp.setWindowIcon( QPixmap( qgis_xpm ) );        // Linux

Modified: trunk/qgis/src/core/qgsapplication.cpp
===================================================================
--- trunk/qgis/src/core/qgsapplication.cpp	2010-07-21 10:10:43 UTC (rev 13950)
+++ trunk/qgis/src/core/qgsapplication.cpp	2010-07-21 13:12:47 UTC (rev 13951)
@@ -39,6 +39,7 @@
 QString QgsApplication::mPkgDataPath;
 QString QgsApplication::mThemeName;
 QStringList QgsApplication::mDefaultSvgPaths;
+QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" );
 
 /*!
   \class QgsApplication
@@ -53,7 +54,7 @@
   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 @@
   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::qgisSettingsDirPath()
 {
-  return QDir::homePath() + QString( "/.qgis/" );
+  return mConfigPath;
 }
 
 /*!

Modified: trunk/qgis/src/core/qgsapplication.h
===================================================================
--- trunk/qgis/src/core/qgsapplication.h	2010-07-21 10:10:43 UTC (rev 13950)
+++ trunk/qgis/src/core/qgsapplication.h	2010-07-21 13:12:47 UTC (rev 13951)
@@ -26,7 +26,8 @@
 {
     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 @@
     static QString mPkgDataPath;
     static QString mThemeName;
     static QStringList mDefaultSvgPaths;
+
+    static QString mConfigPath;
 };
 
 #endif



More information about the QGIS-commit mailing list