Skip to content

Commit

Permalink
Load default profile name from global
Browse files Browse the repository at this point in the history
Also adds overrideLocalProfile to ignore local profiles.ini file
  • Loading branch information
NathanW2 committed Jul 24, 2017
1 parent e37f682 commit 12c634c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 0 additions & 1 deletion python/core/qgsuserprofile.sip
Expand Up @@ -8,7 +8,6 @@




class QgsUserProfile
{
%Docstring
Expand Down
6 changes: 6 additions & 0 deletions python/core/qgsuserprofilemanager.sip
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/main.cpp
Expand Up @@ -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 ) );
}

Expand Down
1 change: 0 additions & 1 deletion src/core/qgsuserprofile.h
@@ -1,4 +1,3 @@

/***************************************************************************
qgsuserprofile.h
--------------------------------------
Expand Down
17 changes: 13 additions & 4 deletions src/core/qgsuserprofilemanager.cpp
Expand Up @@ -17,6 +17,7 @@
#include "qgsuserprofile.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgssettings.h"

#include <QFile>
#include <QDir>
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsuserprofilemanager.h
Expand Up @@ -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;
Expand Down

3 comments on commit 12c634c

@NathanW2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@elpaso
Copy link
Contributor

@elpaso elpaso commented on 12c634c Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.