LCOV - code coverage report
Current view: top level - core - qgsuserprofilemanager.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 2 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                         qgsuserprofilemanager.h
       3                 :            :      --------------------------------------
       4                 :            :     Date                 :  Jul-2017
       5                 :            :     Copyright            : (C) 2017 by Nathan Woodrow
       6                 :            :     Email                : woodrow.nathan at gmail dot com
       7                 :            :  ***************************************************************************
       8                 :            :  *                                                                         *
       9                 :            :  *   This program is free software; you can redistribute it and/or modify  *
      10                 :            :  *   it under the terms of the GNU General Public License as published by  *
      11                 :            :  *   the Free Software Foundation; either version 2 of the License, or     *
      12                 :            :  *   (at your option) any later version.                                   *
      13                 :            :  *                                                                         *
      14                 :            :  ***************************************************************************/
      15                 :            : #ifndef QGSUSERPROFILEMANAGER_H
      16                 :            : #define QGSUSERPROFILEMANAGER_H
      17                 :            : 
      18                 :            : #include <QSettings>
      19                 :            : #include <QFileSystemWatcher>
      20                 :            : 
      21                 :            : 
      22                 :            : #include "qgis_sip.h"
      23                 :            : #include "qgis_core.h"
      24                 :            : #include "qgserror.h"
      25                 :            : #include "qgsuserprofile.h"
      26                 :            : 
      27                 :            : #include <memory>
      28                 :            : 
      29                 :            : /**
      30                 :            :  * \ingroup core
      31                 :            :  * \brief User profile manager is used to manager list, and manage user profiles on the users machine.
      32                 :            :  *
      33                 :            :  * In QGIS 3 all settings, plugins, etc were moved into a %APPDATA%/profiles folder for each platform.
      34                 :            :  * This allows for manage different user profiles per machine vs the single default one that was allowed in the
      35                 :            :  * past.
      36                 :            :  *
      37                 :            :  * A user profile is all settings and anything that used to be found in .qgis3 in the users home folder.
      38                 :            :  *
      39                 :            :  * \since QGIS 3.0
      40                 :            :  */
      41                 :          0 : class CORE_EXPORT QgsUserProfileManager : public QObject
      42                 :            : {
      43                 :          0 :     Q_OBJECT
      44                 :            : 
      45                 :            :   public:
      46                 :            : 
      47                 :            :     /**
      48                 :            :      * User profile manager used to manage user profiles for the instance of QGIS.
      49                 :            :      */
      50                 :            :     QgsUserProfileManager( const QString &rootLocation = QString(), QObject *parent = nullptr );
      51                 :            : 
      52                 :            :     /**
      53                 :            :      * Resolves the profiles folder for the given path. Path will have \\profiles appended to the path
      54                 :            :      * \param basePath The base path to resolve the path from to append the \\profiles folder to.
      55                 :            :      * \return The root path to store user profiles.
      56                 :            :      */
      57                 :            :     static QString resolveProfilesFolder( const QString &basePath = QString() );
      58                 :            : 
      59                 :            :     /**
      60                 :            :      * Returns the profile from the given root profile location.
      61                 :            :      * If no name is given it returns a profile called "default".
      62                 :            :      * By default will create the profile folder if not found.
      63                 :            :      * By default will init the user settings.
      64                 :            :      * \param defaultProfile The profile name to find. Empty profile name will return "default" for the name.
      65                 :            :      * \param createNew Create the profile folder if it doesn't exist.
      66                 :            :      * \param initSettings if the settings should be initialized
      67                 :            :      * \return The user profile
      68                 :            :      * \note Returns a new QgsUserProfile. Ownership transferred to caller.
      69                 :            :      */
      70                 :            :     QgsUserProfile *getProfile( const QString &defaultProfile = "default", bool createNew = true, bool initSettings = true ) SIP_FACTORY;
      71                 :            : 
      72                 :            :     /**
      73                 :            :      * Set the root profile location for the profile manager. All profiles are loaded from this
      74                 :            :      * location. Will also contain a profiles.ini for holding profile settings.
      75                 :            :      * \param rootProfileLocation Path to the top level profile folder which contains folders for each profile.
      76                 :            :      */
      77                 :            :     void setRootLocation( const QString &rootProfileLocation );
      78                 :            : 
      79                 :            :     /**
      80                 :            :      * Returns the path to the root profiles location.
      81                 :            :      * \return The root path to the profiles folder.
      82                 :            :      */
      83                 :            :     QString rootLocation() { return mRootProfilePath; }
      84                 :            : 
      85                 :            :     /**
      86                 :            :      * Sets whether the manager should watch for the creation of new user profiles and emit
      87                 :            :      * the profilesChanged() signal when this occurs. By default new profile notification
      88                 :            :      * is disabled.
      89                 :            :      *
      90                 :            :      * Before calling this, ensure that the correct root location has been set via
      91                 :            :      * calling setRootLocation().
      92                 :            :      *
      93                 :            :      * \see isNewProfileNotificationEnabled()
      94                 :            :      */
      95                 :            :     void setNewProfileNotificationEnabled( bool enabled );
      96                 :            : 
      97                 :            :     /**
      98                 :            :      * Returns whether the manager is watching for the creation of new user profiles and emitting
      99                 :            :      * the profilesChanged() signal when this occurs. By default new profile notification
     100                 :            :      * is disabled.
     101                 :            :      *
     102                 :            :      * \see setNewProfileNotificationEnabled()
     103                 :            :      */
     104                 :            :     bool isNewProfileNotificationEnabled() const;
     105                 :            : 
     106                 :            :     /**
     107                 :            :      * Check if the root location has been set for the manager.
     108                 :            :      * \return TRUE if the root location has been set.
     109                 :            :      */
     110                 :            :     bool rootLocationIsSet() const;
     111                 :            : 
     112                 :            :     /**
     113                 :            :      * Returns a list of all found profile names.
     114                 :            :      */
     115                 :            :     QStringList allProfiles() const;
     116                 :            : 
     117                 :            :     /**
     118                 :            :      * Check if a profile exists.
     119                 :            :      * \return FALSE if the profile can't be found.
     120                 :            :      */
     121                 :            :     bool profileExists( const QString &name ) const;
     122                 :            : 
     123                 :            :     /**
     124                 :            :      * Returns the name of the default profile that has been set in .default.
     125                 :            :      * First checks profile.ini in \\profiles folder
     126                 :            :      * Then checks defaultProfile in global settings
     127                 :            :      * Finally returns "default" if all else fails
     128                 :            :      * \return The name of the default profile.
     129                 :            :      * \note Setting overrideLocalProfile in global settings will always ignore profiles.ini
     130                 :            :      */
     131                 :            :     QString defaultProfileName() const;
     132                 :            : 
     133                 :            :     /**
     134                 :            :      * Sets the default profile name. The default profile name is used when loading QGIS
     135                 :            :      * with no arguments.
     136                 :            :      * \param name The name of the profile to save.
     137                 :            :      */
     138                 :            :     void setDefaultProfileName( const QString &name );
     139                 :            : 
     140                 :            :     /**
     141                 :            :      * Set the default profile name from the current active profile.
     142                 :            :      */
     143                 :            :     void setDefaultFromActive();
     144                 :            : 
     145                 :            :     /**
     146                 :            :      * Returns the profile found for a given name.
     147                 :            :      * \param name The name of the profile to return.
     148                 :            :      * \return A QgsUserprofile pointing to the location of the user profile.
     149                 :            :      */
     150                 :            :     QgsUserProfile *profileForName( const QString &name ) const SIP_FACTORY;
     151                 :            : 
     152                 :            :     /**
     153                 :            :      * Create a user profile given by the name
     154                 :            :      * \param name
     155                 :            :      * \return A QgsError which report if there was any error creating the user profile.
     156                 :            :      */
     157                 :            :     QgsError createUserProfile( const QString &name );
     158                 :            : 
     159                 :            :     /**
     160                 :            :      * Deletes a profile from the root profiles folder.
     161                 :            :      * \param name The name of the profile to delete.
     162                 :            :      * \return A QgsError with a message if the profile failed to be deleted.
     163                 :            :      * \note There is no undo on this as it deletes the folder from the machine.
     164                 :            :      */
     165                 :            :     QgsError deleteProfile( const QString &name );
     166                 :            : 
     167                 :            :     /**
     168                 :            :      * The currently active user profile.
     169                 :            :      * \return The currently active user profile.
     170                 :            :      */
     171                 :            :     QgsUserProfile *userProfile();
     172                 :            : 
     173                 :            :     /**
     174                 :            :      * Sets the active profile in the manager.
     175                 :            :      * This can only be set once.
     176                 :            :      * Setting this again does nothing.
     177                 :            :      *
     178                 :            :      * \param profile The name of the active profile
     179                 :            :      */
     180                 :            :     void setActiveUserProfile( const QString &profile );
     181                 :            : 
     182                 :            :     /**
     183                 :            :      * Starts a new instance of QGIS for the given profile.
     184                 :            :      * \param name The profile to start QGIS with.
     185                 :            :      */
     186                 :            :     void loadUserProfile( const QString &name );
     187                 :            : 
     188                 :            :   signals:
     189                 :            : 
     190                 :            :     /**
     191                 :            :      * Emitted when the list of profiles is changed.
     192                 :            :      *
     193                 :            :      * This signal will only be emitted when isNewProfileNotificationEnabled() is TRUE.
     194                 :            :      * By default new profile notification is disabled.
     195                 :            :      *
     196                 :            :      * \see isNewProfileNotificationEnabled()
     197                 :            :      * \see setNewProfileNotificationEnabled()
     198                 :            :      */
     199                 :            :     void profilesChanged();
     200                 :            : 
     201                 :            :   private:
     202                 :            : 
     203                 :            :     bool mWatchProfiles = false;
     204                 :            :     std::unique_ptr<QFileSystemWatcher> mWatcher;
     205                 :            : 
     206                 :            :     QString mRootProfilePath;
     207                 :            : 
     208                 :            :     std::unique_ptr<QgsUserProfile> mUserProfile;
     209                 :            : 
     210                 :            :     QString settingsFile() const;
     211                 :            : 
     212                 :            :     std::unique_ptr< QSettings > mSettings;
     213                 :            : };
     214                 :            : 
     215                 :            : // clazy:excludeall=qstring-allocations
     216                 :            : 
     217                 :            : #endif // QGSUSERPROFILEMANAGER_H

Generated by: LCOV version 1.14