Skip to content

Commit

Permalink
Merge pull request #5102 from nyalldawson/socket_error
Browse files Browse the repository at this point in the history
Fix QSocketNotifier error on startup
  • Loading branch information
nyalldawson authored Sep 2, 2017
2 parents 56040c4 + bbd0beb commit 8e12757
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
30 changes: 29 additions & 1 deletion python/core/qgsuserprofilemanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ class QgsUserProfileManager : QObject
:rtype: str
%End

void setNewProfileNotificationEnabled( bool enabled );
%Docstring
Sets whether the manager should watch for the creation of new user profiles and emit
the profilesChanged() signal when this occurs. By default new profile notification
is disabled.

Before calling this, ensure that the correct root location has been set via
calling setRootLocation().

.. seealso:: isNewProfileNotificationEnabled()
%End

bool isNewProfileNotificationEnabled() const;
%Docstring
Returns whether the manager is watching for the creation of new user profiles and emitting
the profilesChanged() signal when this occurs. By default new profile notification
is disabled.

.. seealso:: setNewProfileNotificationEnabled()
:rtype: bool
%End

bool rootLocationIsSet() const;
%Docstring
Check if the root location has been set for the manager.
Expand Down Expand Up @@ -169,9 +191,15 @@ class QgsUserProfileManager : QObject

signals:

void profilesChanged( );
void profilesChanged();
%Docstring
Emitted when the list of profiles is changed.

This signal will only be emitted when isNewProfileNotificationEnabled() is true.
By default new profile notification is disabled.

.. seealso:: isNewProfileNotificationEnabled()
.. seealso:: setNewProfileNotificationEnabled()
%End

};
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
mUserProfileManager = new QgsUserProfileManager( QString(), this );
mUserProfileManager->setRootLocation( rootProfileLocation );
mUserProfileManager->setActiveUserProfile( activeProfile );
mUserProfileManager->setNewProfileNotificationEnabled( true );
connect( mUserProfileManager, &QgsUserProfileManager::profilesChanged, this, &QgisApp::refreshProfileMenu );
endProfile();

Expand Down
34 changes: 23 additions & 11 deletions src/core/qgsuserprofilemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
QgsUserProfileManager::QgsUserProfileManager( const QString &rootLocation, QObject *parent )
: QObject( parent )
{
mWatcher.reset( new QFileSystemWatcher() );
setRootLocation( rootLocation );
connect( mWatcher.get(), &QFileSystemWatcher::directoryChanged, this, [this]
{
emit profilesChanged();
} );
}

QString QgsUserProfileManager::resolveProfilesFolder( const QString &basePath )
Expand Down Expand Up @@ -62,16 +57,33 @@ void QgsUserProfileManager::setRootLocation( const QString &rootProfileLocation
{
mRootProfilePath = rootProfileLocation;

if ( !mWatcher->directories().isEmpty() )
{
mWatcher->removePaths( mWatcher->directories() );
}
//updates (or removes) profile file watcher for new root location
setNewProfileNotificationEnabled( mWatchProfiles );

if ( !mRootProfilePath.isEmpty() && QDir( mRootProfilePath ).exists() )
mSettings.reset( new QSettings( settingsFile(), QSettings::IniFormat ) );
}

void QgsUserProfileManager::setNewProfileNotificationEnabled( bool enabled )
{
mWatchProfiles = enabled;
if ( mWatchProfiles && !mRootProfilePath.isEmpty() && QDir( mRootProfilePath ).exists() )
{
mWatcher.reset( new QFileSystemWatcher() );
mWatcher->addPath( mRootProfilePath );
connect( mWatcher.get(), &QFileSystemWatcher::directoryChanged, this, [this]
{
emit profilesChanged();
} );
}
mSettings.reset( new QSettings( settingsFile(), QSettings::IniFormat ) );
else
{
mWatcher.reset();
}
}

bool QgsUserProfileManager::isNewProfileNotificationEnabled() const
{
return static_cast< bool >( mWatcher.get() );
}

bool QgsUserProfileManager::rootLocationIsSet() const
Expand Down
30 changes: 29 additions & 1 deletion src/core/qgsuserprofilemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ class CORE_EXPORT QgsUserProfileManager : public QObject
*/
QString rootLocation() { return mRootProfilePath; }

/**
* Sets whether the manager should watch for the creation of new user profiles and emit
* the profilesChanged() signal when this occurs. By default new profile notification
* is disabled.
*
* Before calling this, ensure that the correct root location has been set via
* calling setRootLocation().
*
* \see isNewProfileNotificationEnabled()
*/
void setNewProfileNotificationEnabled( bool enabled );

/**
* Returns whether the manager is watching for the creation of new user profiles and emitting
* the profilesChanged() signal when this occurs. By default new profile notification
* is disabled.
*
* \see setNewProfileNotificationEnabled()
*/
bool isNewProfileNotificationEnabled() const;

/**
* Check if the root location has been set for the manager.
* \return True if the root location has been set.
Expand Down Expand Up @@ -168,11 +189,18 @@ class CORE_EXPORT QgsUserProfileManager : public QObject

/**
* Emitted when the list of profiles is changed.
*
* This signal will only be emitted when isNewProfileNotificationEnabled() is true.
* By default new profile notification is disabled.
*
* \see isNewProfileNotificationEnabled()
* \see setNewProfileNotificationEnabled()
*/
void profilesChanged( );
void profilesChanged();

private:

bool mWatchProfiles = false;
std::unique_ptr<QFileSystemWatcher> mWatcher;

QString mRootProfilePath;
Expand Down

0 comments on commit 8e12757

Please sign in to comment.