@ -36,8 +36,9 @@
@@ -36,8 +36,9 @@
Profile * Profile : : m_instance = nullptr ;
Profile : : Profile ( Private : : Profile * impl )
: m_impl ( impl )
Profile : : Profile ( Private : : Profile * impl , Private : : PathConverter * pathConverter )
: m_profileImpl ( impl )
, m_pathConverterImpl ( pathConverter )
{
ensureDirectoryExists ( SpecialFolder : : Cache ) ;
ensureDirectoryExists ( SpecialFolder : : Config ) ;
@ -48,11 +49,17 @@ Profile::Profile(Private::Profile *impl)
@@ -48,11 +49,17 @@ Profile::Profile(Private::Profile *impl)
// to generate correct call to ProfilePrivate::~ProfileImpl()
Profile : : ~ Profile ( ) = default ;
void Profile : : initialize ( const QString & rootProfilePath , const QString & configurationName )
void Profile : : initialize ( const QString & rootProfilePath , const QString & configurationName ,
bool convertPathsToProfileRelative )
{
m_instance = new Profile ( rootProfilePath . isEmpty ( )
? static_cast < Private : : Profile * > ( new Private : : DefaultProfile ( configurationName ) )
: static_cast < Private : : Profile * > ( new Private : : CustomProfile ( rootProfilePath , configurationName ) ) ) ;
QScopedPointer < Private : : Profile > profile ( rootProfilePath . isEmpty ( )
? static_cast < Private : : Profile * > ( new Private : : DefaultProfile ( configurationName ) )
: static_cast < Private : : Profile * > ( new Private : : CustomProfile ( rootProfilePath , configurationName ) ) ) ;
QScopedPointer < Private : : PathConverter > converter ( convertPathsToProfileRelative
? static_cast < Private : : PathConverter * > ( new Private : : Converter ( profile - > baseDirectory ( ) ) )
: static_cast < Private : : PathConverter * > ( new Private : : NoConvertConverter ( ) ) ) ;
m_instance = new Profile ( profile . take ( ) , converter . take ( ) ) ;
}
const Profile & Profile : : instance ( )
@ -65,16 +72,16 @@ QString Profile::location(SpecialFolder folder) const
@@ -65,16 +72,16 @@ QString Profile::location(SpecialFolder folder) const
QString result ;
switch ( folder ) {
case SpecialFolder : : Cache :
result = m_impl - > cacheLocation ( ) ;
result = m_prof ileI mpl - > cacheLocation ( ) ;
break ;
case SpecialFolder : : Config :
result = m_impl - > configLocation ( ) ;
result = m_prof ileI mpl - > configLocation ( ) ;
break ;
case SpecialFolder : : Data :
result = m_impl - > dataLocation ( ) ;
result = m_prof ileI mpl - > dataLocation ( ) ;
break ;
case SpecialFolder : : Downloads :
result = m_impl - > downloadLocation ( ) ;
result = m_prof ileI mpl - > downloadLocation ( ) ;
break ;
}
@ -85,12 +92,12 @@ QString Profile::location(SpecialFolder folder) const
@@ -85,12 +92,12 @@ QString Profile::location(SpecialFolder folder) const
QString Profile : : configurationName ( ) const
{
return m_impl - > configurationName ( ) ;
return m_prof ileI mpl - > configurationName ( ) ;
}
SettingsPtr Profile : : applicationSettings ( const QString & name ) const
{
return m_impl - > applicationSettings ( name ) ;
return m_prof ileI mpl - > applicationSettings ( name ) ;
}
void Profile : : ensureDirectoryExists ( SpecialFolder folder )
@ -99,3 +106,13 @@ void Profile::ensureDirectoryExists(SpecialFolder folder)
@@ -99,3 +106,13 @@ void Profile::ensureDirectoryExists(SpecialFolder folder)
if ( ! locationPath . isEmpty ( ) & & ! QDir ( ) . mkpath ( locationPath ) )
qFatal ( " Could not create required directory '%s' " , qPrintable ( locationPath ) ) ;
}
QString Profile : : toPortablePath ( const QString & absolutePath ) const
{
return m_pathConverterImpl - > toPortablePath ( absolutePath ) ;
}
QString Profile : : fromPortablePath ( const QString & portablePath ) const
{
return m_pathConverterImpl - > fromPortablePath ( portablePath ) ;
}