Skip to content
Permalink
Browse files

Load default profile name from global

Also adds overrideLocalProfile to ignore local profiles.ini file
  • Loading branch information
NathanW2 committed Jul 24, 2017
1 parent e37f682 commit 12c634cef3a11d139f9437970ceeaab43caddcce
@@ -8,7 +8,6 @@




class QgsUserProfile
{
%Docstring
@@ -95,6 +95,12 @@ class QgsUserProfileManager : QObject
QString defaultProfileName() const;
%Docstring
Returns the name of the default profile that has been set in .default.
First checks profile.ini in \\profiles folder
Then checks defaultProfile in global settings
Finally returns "default" if all else fails
.. note::

Setting overrideLocalProfile in global settings will always ignore profiles.ini
:return: The name of the default profile.
:rtype: str
%End
@@ -821,9 +821,9 @@ int main( int argc, char *argv[] )
{
configLocalStorageLocation = getenv( "QGIS_CUSTOM_CONFIG_PATH" );
}
else if ( settings.contains( "profiles-path", QgsSettings::Core ) )
else if ( settings.contains( "profilesPath", QgsSettings::Core ) )

This comment has been minimized.

Copy link
@elpaso

elpaso Jul 25, 2017

Contributor

I guess this is more an "app" setting, perhaps QgsSettings::App would be a more appropriate namespace.

{
configLocalStorageLocation = settings.value( "profiles-path", "", QgsSettings::Core ).toString();
configLocalStorageLocation = settings.value( "profilesPath", "", QgsSettings::Core ).toString();
QgsDebugMsg( QString( "Loading profiles path from global config at %1" ).arg( configLocalStorageLocation ) );
}

@@ -1,4 +1,3 @@

/***************************************************************************
qgsuserprofile.h
--------------------------------------
@@ -17,6 +17,7 @@
#include "qgsuserprofile.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgssettings.h"

#include <QFile>
#include <QDir>
@@ -80,14 +81,22 @@ bool QgsUserProfileManager::rootLocationIsSet() const

QString QgsUserProfileManager::defaultProfileName() const
{
QString profileName = "default";
mSettings->value( "/defaultProfile", "default" );
return profileName;
QString defaultName = "default";
// If the profiles.ini doesn't have the default profile we grab it from
// global settings as it might be set by the admin.
// If the overrideProfile flag is set then no matter what the profiles.ini says we always take the
// global profile.
QgsSettings globalSettings;
if ( !mSettings->contains( "/core/defaultProfile" ) || globalSettings.value( "overrideLocalProfile", false, QgsSettings::Core ).toBool() )
{
return globalSettings.value( "defaultProfile", defaultName, QgsSettings::Core ).toString();
}
return mSettings->value( "/core/defaultProfile", defaultName ).toString();
}

void QgsUserProfileManager::setDefaultProfileName( const QString &name )
{
mSettings->setValue( "/defaultProfile", name );
mSettings->setValue( "/core/defaultProfile", name );
mSettings->sync();
}

@@ -100,6 +100,10 @@ class CORE_EXPORT QgsUserProfileManager : public QObject

/**
* Returns the name of the default profile that has been set in .default.
* First checks profile.ini in \\profiles folder
* Then checks defaultProfile in global settings
* Finally returns "default" if all else fails
* \note Setting overrideLocalProfile in global settings will always ignore profiles.ini
* \return The name of the default profile.
*/
QString defaultProfileName() const;

3 comments on commit 12c634c

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Jul 24, 2017

@elpaso This adds the override for default profile name. Also added a over switch to force a profile name from the global settings which I thought might be handy.

@NathanW2

This comment has been minimized.

Copy link
Member Author

@NathanW2 NathanW2 replied Jul 24, 2017

More odd that it didn't error local for me.

@elpaso

This comment has been minimized.

Copy link
Contributor

@elpaso elpaso replied Jul 25, 2017

@NathanW2 the settings implementation looks good to me.

A few Notes/Questions

  • perhaps app namespace would be more appropriate than core for this implementation
  • why don't you use QgsSettings for mSettings too? Even if you don't plan to store anything in the global settings file, you'd get namespaces for free and (mostly) the same API of standard QSettings
Please sign in to comment.
You can’t perform that action at this time.