20 #include <QTextStream> 22 #include <QSqlDatabase> 33 return mProfileFolder;
39 if ( !QDir( mProfileFolder ).exists() )
41 error.
append( QObject::tr(
"Profile folder doesn't exist" ) );
48 QDir dir( mProfileFolder );
55 QSettings::setDefaultFormat( QSettings::IniFormat );
56 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope,
folder() );
61 QFile qgisPrivateDbFile( qgisDB() );
65 if ( !qgisPrivateDbFile.exists() )
70 QSqlDatabase db = QSqlDatabase::addDatabase( QStringLiteral(
"QSQLITE" ), QStringLiteral(
"userprofile" ) );
71 db.setDatabaseName( qgisDB() );
76 query.prepare( QStringLiteral(
"SELECT value FROM tbl_config_variables WHERE variable = 'ALIAS'" ) );
77 QString profileAlias =
name();
82 QString
alias = query.value( 0 ).toString();
83 if ( !alias.isEmpty() )
94 QFile qgisPrivateDbFile( qgisDB() );
96 if ( !qgisPrivateDbFile.exists() )
98 error.
append( QObject::tr(
"qgis.db doesn't exist in the user's profile folder" ) );
102 QSqlDatabase db = QSqlDatabase::addDatabase( QStringLiteral(
"QSQLITE" ), QStringLiteral(
"userprofile" ) );
103 db.setDatabaseName( qgisDB() );
106 error.
append( QObject::tr(
"Unable to open qgis.db for update." ) );
111 QString sql = QStringLiteral(
"INSERT OR REPLACE INTO tbl_config_variables VALUES ('ALIAS', :alias);" );
112 query.prepare( sql );
113 query.bindValue( QStringLiteral(
":alias" ), alias );
116 error.
append( QObject::tr(
"Could not save alias to database: %1" ).arg( query.lastError().text() ) );
124 QString path = mProfileFolder + QDir::separator() +
"icon.svg";
125 if ( !QDir( path ).exists() )
129 return QIcon( path );
132 QString QgsUserProfile::qgisDB()
const 134 return mProfileFolder + QDir::separator() +
"qgis.db";
const QString name() const
The name for the user profile.
QgsError setAlias(const QString &alias)
Set the alias of the profile.
QgsError validate() const
Check of the profile is in a valid state.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
void append(const QString &message, const QString &tag)
Append new error message.
const QIcon icon() const
The icon for the user profile.
QgsError is container for error messages (report).
QgsUserProfile(const QString &folder)
Reference to a existing user profile folder.
const QString folder() const
The base folder for the user profile.
const QString alias() const
Returns the alias for the user profile.
void initSettings() const
Init the settings from the user folder.