35 return mProfileFolder;
41 if ( !QDir( mProfileFolder ).exists() )
43 error.
append( QObject::tr(
"Profile folder doesn't exist" ) );
50 const QDir dir( mProfileFolder );
57 QSettings::setDefaultFormat( QSettings::IniFormat );
58 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope,
folder() );
63 const QString dbFile = qgisDB();
64 QString profileAlias =
name();
68 if ( !QFile::exists( dbFile ) )
76 int result = database.
open( dbFile );
77 if ( result != SQLITE_OK )
83 if ( result == SQLITE_OK )
85 if ( preparedStatement.
step() == SQLITE_ROW )
88 if ( !
alias.isEmpty() )
98 const QString dbFile = qgisDB();
102 if ( !QFile::exists( dbFile ) )
104 error.
append( QObject::tr(
"qgis.db doesn't exist in the user's profile folder" ) );
111 int result = database.
open( dbFile );
112 if ( result != SQLITE_OK )
114 error.
append( QObject::tr(
"Unable to open qgis.db for update." ) );
118 const QString sql = QStringLiteral(
"INSERT OR REPLACE INTO tbl_config_variables VALUES ('ALIAS', %1);" ).arg(
122 if ( result != SQLITE_OK || preparedStatement.
step() != SQLITE_DONE )
124 error.
append( QObject::tr(
"Could not save alias to database: %1" ).arg( database.
errorMessage() ) );
132 const QStringList extensions = {
".svg",
".png",
".jpg",
".jpeg",
".gif",
".bmp"};
133 const QString basename = mProfileFolder + QDir::separator() +
"icon";
135 for (
const QString &extension : extensions )
137 const QString path = basename + extension;
138 if ( QFileInfo::exists( path ) )
139 return QIcon( path );
144QString QgsUserProfile::qgisDB()
const
146 return mProfileFolder + QDir::separator() +
"qgis.db";
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
A container for error messages.
void append(const QString &message, const QString &tag)
Append new error message.
static QString quotedString(const QString &value)
Returns a quoted string value, surround by ' characters and with special characters correctly escaped...
QgsUserProfile(const QString &folder)
Reference to an existing user profile folder.
const QString folder() const
The base folder for the user profile.
const QString name() const
The name for the user profile.
QgsError setAlias(const QString &alias) const
Set the alias of the profile.
const QString alias() const
Returns the alias for the user profile.
const QIcon icon() const
The icon for the user profile.
QgsError validate() const
Check of the profile is in a valid state.
void initSettings() const
Init the settings from the user folder.
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
QString errorMessage() const
Returns the most recent error message encountered by the database.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
int step()
Steps to the next record in the statement, returning the sqlite3 result code.