Skip to content
Permalink
Browse files
Merge pull request #5102 from nyalldawson/socket_error
Fix QSocketNotifier error on startup
  • Loading branch information
nyalldawson committed 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.
@@ -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.
@@ -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

};
@@ -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();

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

0 comments on commit 8e12757

Please sign in to comment.