@@ -798,16 +798,47 @@ int main( int argc, char *argv[] )
798
798
QCoreApplication::setAttribute ( Qt::AA_DisableWindowContextHelpButton, true );
799
799
#endif
800
800
801
- QgsSettings settings;
801
+ // SetUp the QgsSettings Global Settings:
802
+ // - use the path specified with --globalsettingsfile path,
803
+ // - use the environment if not found
804
+ // - use a default location as a fallback
805
+ if ( globalsettingsfile.isEmpty () )
806
+ {
807
+ globalsettingsfile = getenv ( " QGIS_GLOBAL_SETTINGS_FILE" );
808
+ }
809
+
810
+ if ( globalsettingsfile.isEmpty () )
811
+ {
812
+ QString default_globalsettingsfile = QgsApplication::pkgDataPath () + " /qgis_global_settings.ini" ;
813
+ if ( QFile::exists ( default_globalsettingsfile ) )
814
+ {
815
+ globalsettingsfile = default_globalsettingsfile;
816
+ }
817
+ }
818
+
819
+ if ( !globalsettingsfile.isEmpty () )
820
+ {
821
+ if ( ! QgsSettings::setGlobalSettingsPath ( globalsettingsfile ) )
822
+ {
823
+ QgsMessageLog::logMessage ( QStringLiteral ( " Invalid globalsettingsfile path: %1" ).arg ( globalsettingsfile ), QStringLiteral ( " QGIS" ) );
824
+ }
825
+ else
826
+ {
827
+ QgsMessageLog::logMessage ( QStringLiteral ( " Successfully loaded globalsettingsfile path: %1" ).arg ( globalsettingsfile ), QStringLiteral ( " QGIS" ) );
828
+ }
829
+ }
830
+
831
+ QSettings *globalSettings = new QSettings ( globalsettingsfile, QSettings::IniFormat );
832
+ globalSettings->setIniCodec ( " UTF-8" );
802
833
if ( configLocalStorageLocation.isEmpty () )
803
834
{
804
835
if ( getenv ( " QGIS_CUSTOM_CONFIG_PATH" ) )
805
836
{
806
837
configLocalStorageLocation = getenv ( " QGIS_CUSTOM_CONFIG_PATH" );
807
838
}
808
- else if ( settings. contains ( QStringLiteral ( " profilesPath" ), QgsSettings::Core ) )
839
+ else if ( globalSettings-> contains ( QStringLiteral ( " core/ profilesPath" ) ) )
809
840
{
810
- configLocalStorageLocation = settings. value ( QStringLiteral ( " profilesPath" ), " " , QgsSettings::Core ).toString ();
841
+ configLocalStorageLocation = globalSettings-> value ( QStringLiteral ( " core/ profilesPath" ), " " ).toString ();
811
842
QgsDebugMsg ( QString ( " Loading profiles path from global config at %1" ).arg ( configLocalStorageLocation ) );
812
843
}
813
844
@@ -817,6 +848,7 @@ int main( int argc, char *argv[] )
817
848
configLocalStorageLocation = QStandardPaths::standardLocations ( QStandardPaths::AppDataLocation ).value ( 0 );
818
849
}
819
850
}
851
+ delete globalSettings;
820
852
821
853
QString rootProfileFolder = QgsUserProfileManager::resolveProfilesFolder ( configLocalStorageLocation );
822
854
QgsUserProfileManager manager ( rootProfileFolder );
@@ -825,49 +857,26 @@ int main( int argc, char *argv[] )
825
857
profileName = profile->name ();
826
858
delete profile;
827
859
860
+ // We can't use QgsSettings until this point because the format and
861
+ // folder isn't set until profile is fetch.
862
+ // Should be cleaned up in future to make this cleaner.
863
+ QgsSettings settings;
864
+
828
865
QgsDebugMsg ( " User profile details:" );
829
866
QgsDebugMsg ( QString ( " \t - %1" ).arg ( profileName ) );
830
867
QgsDebugMsg ( QString ( " \t - %1" ).arg ( profileFolder ) );
831
868
QgsDebugMsg ( QString ( " \t - %1" ).arg ( rootProfileFolder ) );
832
869
833
870
QgsApplication myApp ( argc, argv, myUseGuiFlag, profileFolder );
834
871
835
- // SetUp the QgsSettings Global Settings:
836
- // - use the path specified with --globalsettingsfile path,
837
- // - use the environment if not found
838
- // - use a default location as a fallback
839
- if ( globalsettingsfile.isEmpty () )
840
- {
841
- globalsettingsfile = getenv ( " QGIS_GLOBAL_SETTINGS_FILE" );
842
- }
843
- if ( globalsettingsfile.isEmpty () )
844
- {
845
- QString default_globalsettingsfile = QgsApplication::pkgDataPath () + " /qgis_global_settings.ini" ;
846
- if ( QFile::exists ( default_globalsettingsfile ) )
847
- {
848
- globalsettingsfile = default_globalsettingsfile;
849
- }
850
- }
851
- if ( !globalsettingsfile.isEmpty () )
852
- {
853
- if ( ! QgsSettings::setGlobalSettingsPath ( globalsettingsfile ) )
854
- {
855
- QgsMessageLog::logMessage ( QStringLiteral ( " Invalid globalsettingsfile path: %1" ).arg ( globalsettingsfile ), QStringLiteral ( " QGIS" ) );
856
- }
857
- else
858
- {
859
- QgsMessageLog::logMessage ( QStringLiteral ( " Successfully loaded globalsettingsfile path: %1" ).arg ( globalsettingsfile ), QStringLiteral ( " QGIS" ) );
860
- }
861
- }
862
-
863
872
// Settings migration is only supported on the default profile for now.
864
873
if ( profileName == " default" )
865
874
{
866
875
// Note: this flag is ka version number so that we can reset it once we change the version.
867
876
// Note2: Is this a good idea can we do it better.
868
877
869
878
int firstRunVersion = settings.value ( QStringLiteral ( " migration/firstRunVersionFlag" ), 0 ).toInt ();
870
- bool showWelcome = ( firstRunVersion == 0 || Qgis::QGIS_VERSION_INT > firstRunVersion );
879
+ bool showWelcome = ( firstRunVersion == 0 || Qgis::QGIS_VERSION_INT > firstRunVersion );
871
880
872
881
std::unique_ptr< QgsVersionMigration > migration ( QgsVersionMigration::canMigrate ( 20000 , Qgis::QGIS_VERSION_INT ) );
873
882
if ( migration && ( mySettingsMigrationForce || migration->requiresMigration () ) )
0 commit comments