Commit 50041fd0 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Simplify ProfileManager code

Now all the profiles are loaded in the constructor; I didn't see any
noticeable difference in loading times.

Also all the profiles are loaded anyway because ProfileList calls
ProfileManager::allProfiles() to populate the profiles menu ...etc.
parent 0e3c3aaf
Pipeline #87072 passed with stage
in 1 minute and 50 seconds
......@@ -53,6 +53,7 @@ ProfileManager::ProfileManager()
{
// load fallback profile
initFallbackProfile();
_defaultProfile = _fallbackProfile;
// lookup the default profile specified in <App>rc
// for stand-alone Konsole, appConfig is just konsolerc
......@@ -69,18 +70,7 @@ ProfileManager::ProfileManager()
defaultProfileFileName = group.readEntry("DefaultProfile", "");
}
_defaultProfile = _fallbackProfile;
if (!defaultProfileFileName.isEmpty()) {
// load the default profile
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + defaultProfileFileName);
if (!path.isEmpty()) {
Profile::Ptr profile = loadProfile(path);
if (profile) {
_defaultProfile = profile;
}
}
}
loadAllProfiles(defaultProfileFileName);
Q_ASSERT(_profiles.size() > 0);
Q_ASSERT(_defaultProfile);
......@@ -216,18 +206,15 @@ QStringList ProfileManager::availableProfileNames() const
return names;
}
void ProfileManager::loadAllProfiles()
void ProfileManager::loadAllProfiles(const QString &defaultProfileFileName)
{
if (_loadedAllProfiles) {
return;
}
const QStringList &paths = availableProfilePaths();
for (const QString &path : paths) {
loadProfile(path);
Profile::Ptr profile = loadProfile(path);
if (profile && !defaultProfileFileName.isEmpty() && path.endsWith(defaultProfileFileName)) {
_defaultProfile = profile;
}
}
_loadedAllProfiles = true;
}
void ProfileManager::saveSettings()
......@@ -363,7 +350,7 @@ void ProfileManager::changeProfile(Profile::Ptr profile, QHash<Profile::Property
// dialog
if (!origPath.isEmpty() && profile->path() != origPath) {
// this is needed to include the old profile too
_loadedAllProfiles = false;
loadAllProfiles();
const QList<Profile::Ptr> availableProfiles = ProfileManager::instance()->allProfiles();
for (const Profile::Ptr &oldProfile : availableProfiles) {
if (oldProfile->path() == origPath) {
......
......@@ -72,7 +72,7 @@ public:
* profile configuration file from disk and parsing it.
* Therefore it should only be done when necessary.
*/
void loadAllProfiles();
void loadAllProfiles(const QString &defaultProfileFileName = {});
/**
* Loads a profile from the specified path and registers
......@@ -227,8 +227,6 @@ private:
Profile::Ptr _defaultProfile;
Profile::Ptr _fallbackProfile;
bool _loadedAllProfiles = false; // set to true after loadAllProfiles has been called
struct ShortcutData {
Profile::Ptr profileKey;
QString profilePath;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment