diff --git a/src/ProfileManager.h b/src/ProfileManager.h --- a/src/ProfileManager.h +++ b/src/ProfileManager.h @@ -159,13 +159,6 @@ */ Profile::Ptr defaultProfile() const; - /** - * Returns a Profile object with hard-coded settings which is always available. - * This can be used as a parent for new profiles which provides suitable default settings - * for all properties. - */ - Profile::Ptr fallbackProfile() const; - /** * Specifies whether a profile should be included in the user's * list of favorite profiles. @@ -276,7 +269,6 @@ QSet _favorites; // list of favorite profiles Profile::Ptr _defaultProfile; - Profile::Ptr _fallbackProfile; bool _loadedAllProfiles; // set to true after loadAllProfiles has been called bool _loadedFavorites; // set to true after loadFavorites has been called diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp --- a/src/ProfileManager.cpp +++ b/src/ProfileManager.cpp @@ -68,48 +68,62 @@ qStableSort(list.begin(), list.end(), profileNameLessThan); } +static QString entryOrDefault(KConfigGroup group, QString key, QString defaultValue) { + QString read = group.readEntry(key, ""); + + if (read.isEmpty()) { + return defaultValue; + } + + return read; +} + +static Profile::Ptr loadDefaultOrCreateEmpty(ProfileManager *manager, QString path) { + Profile::Ptr profile = manager->loadProfile(path); + + if (!profile) { + profile = Profile::Ptr(new Profile()); + profile->useFallback(); + profile->setProperty(Profile::Path, path); + profile->setHidden(false); + } + + return profile; +} + ProfileManager::ProfileManager() : _profiles(QSet()) , _favorites(QSet()) , _defaultProfile(nullptr) - , _fallbackProfile(nullptr) , _loadedAllProfiles(false) , _loadedFavorites(false) , _shortcuts(QMap()) , _profileList(nullptr) { - //load fallback profile - _fallbackProfile = Profile::Ptr(new Profile()); - _fallbackProfile->useFallback(); - addProfile(_fallbackProfile); + const QString fallbackDefaultProfile = QDir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)).filePath(QStringLiteral("konsole/default.profile")); + const QString sharedConfigFilename = QStringLiteral("konsolerc"); + const QString configGroupName = QStringLiteral("Desktop Entry"); + const QString defaultProfileEntry = QStringLiteral("DefaultProfile"); + + // if the hosting application of konsolepart does not specify its own + // default profile, use the default profile of stand-alone Konsole. + const KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(sharedConfigFilename); + const KConfigGroup konsoleGroup = konsoleConfig->group(configGroupName); + + const QString konsoleConfigDefaultProfile = entryOrDefault(konsoleGroup, defaultProfileEntry, fallbackDefaultProfile); // lookup the default profile specified in rc // for stand-alone Konsole, appConfig is just konsolerc // for konsolepart, appConfig might be yakuakerc, dolphinrc, katerc... - KSharedConfigPtr appConfig = KSharedConfig::openConfig(); - KConfigGroup group = appConfig->group("Desktop Entry"); - QString defaultProfileFileName = group.readEntry("DefaultProfile", ""); + const KSharedConfigPtr appConfig = KSharedConfig::openConfig(); + const KConfigGroup appGroup = appConfig->group(configGroupName); - // if the hosting application of konsolepart does not specify its own - // default profile, use the default profile of stand-alone Konsole. - if (defaultProfileFileName.isEmpty()) { - KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(QStringLiteral("konsolerc")); - group = konsoleConfig->group("Desktop Entry"); - defaultProfileFileName = group.readEntry("DefaultProfile", ""); - } + const QString configFile = entryOrDefault(appGroup, defaultProfileEntry, konsoleConfigDefaultProfile); - _defaultProfile = _fallbackProfile; - if (!defaultProfileFileName.isEmpty()) { - // load the default profile - const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("konsole/") + defaultProfileFileName); + _defaultProfile = loadDefaultOrCreateEmpty(this, configFile); - if (!path.isEmpty()) { - Profile::Ptr profile = loadProfile(path); - if (profile) { - _defaultProfile = profile; - } - } - } + _profiles.insert(_defaultProfile); + _favorites.insert(_defaultProfile); Q_ASSERT(_profiles.count() > 0); Q_ASSERT(_defaultProfile); @@ -130,11 +144,6 @@ Profile::Ptr ProfileManager::loadProfile(const QString& shortPath) { - // the fallback profile has a 'special' path name, "FALLBACK/" - if (shortPath == _fallbackProfile->path()) { - return _fallbackProfile; - } - QString path = shortPath; // add a suggested suffix and relative prefix if missing @@ -175,8 +184,8 @@ PopStackOnExit popGuardOnExit(recursionGuard); if (recursionGuard.contains(path)) { - qCDebug(KonsoleDebug) << "Ignoring attempt to load profile recursively from" << path; - return _fallbackProfile; + qWarning("Attempt to load profile recursively; will load empty profile"); + return Profile::Ptr(new Profile()); } else { recursionGuard.push(path); } @@ -184,7 +193,8 @@ // load the profile ProfileReader reader; - Profile::Ptr newProfile = Profile::Ptr(new Profile(fallbackProfile())); + Profile::Ptr newProfile = Profile::Ptr(new Profile()); + newProfile->useFallback(); newProfile->setProperty(Profile::Path, path); QString parentProfilePath; @@ -253,11 +263,6 @@ QList havingIndices; for (const auto & i : list) { - // dis-regard the fallback profile - if (i->path() == _fallbackProfile->path()) { - continue; - } - if (i->menuIndexAsInt() == 0) { lackingIndices.append(i); } else { @@ -331,10 +336,6 @@ { return _defaultProfile; } -Profile::Ptr ProfileManager::fallbackProfile() const -{ - return _fallbackProfile; -} QString ProfileManager::saveProfile(const Profile::Ptr &profile) { @@ -360,46 +361,7 @@ // never save a profile with empty name into disk! persistent = persistent && !profile->name().isEmpty(); - Profile::Ptr newProfile; - - // If we are asked to store the fallback profile (which has an - // invalid path by design), we reset the path to an empty string - // which will make the profile writer automatically generate a - // proper path. - if (persistent && profile->path() == _fallbackProfile->path()) { - - // Generate a new name, so it is obvious what is actually built-in - // in the profile manager - QList existingProfiles = allProfiles(); - QStringList existingProfileNames; - foreach(Profile::Ptr existingProfile, existingProfiles) { - existingProfileNames.append(existingProfile->name()); - } - - int nameSuffix = 1; - QString newName; - QString newTranslatedName; - do { - newName = QStringLiteral("Profile ") + QString::number(nameSuffix); - newTranslatedName = i18nc("The default name of a profile", "Profile #%1", nameSuffix); - // TODO: remove the # above and below - too many issues - newTranslatedName.remove(QLatin1Char('#')); - nameSuffix++; - } while (existingProfileNames.contains(newName)); - - newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile())); - newProfile->clone(profile, true); - newProfile->setProperty(Profile::UntranslatedName, newName); - newProfile->setProperty(Profile::Name, newTranslatedName); - newProfile->setProperty(Profile::MenuIndex, QStringLiteral("0")); - newProfile->setHidden(false); - - addProfile(newProfile); - setDefaultProfile(newProfile); - - } else { - newProfile = profile; - }; + Profile::Ptr newProfile = profile; // insert the changes into the existing Profile instance QListIterator iter(propertyMap.keys()); @@ -455,10 +417,6 @@ void ProfileManager::addProfile(const Profile::Ptr &profile) { - if (_profiles.isEmpty()) { - _defaultProfile = profile; - } - _profiles.insert(profile); emit profileAdded(profile); diff --git a/src/SessionController.cpp b/src/SessionController.cpp --- a/src/SessionController.cpp +++ b/src/SessionController.cpp @@ -625,7 +625,7 @@ action->setText(i18n("Edit Current Profile...")); action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); - _switchProfileMenu = new KActionMenu(i18n("Switch Profile"), this); + _switchProfileMenu = new KActionMenu(i18n("Favorite Profiles"), this); collection->addAction(QStringLiteral("switch-profile"), _switchProfileMenu); // History diff --git a/src/settings/ProfileSettings.cpp b/src/settings/ProfileSettings.cpp --- a/src/settings/ProfileSettings.cpp +++ b/src/settings/ProfileSettings.cpp @@ -300,7 +300,7 @@ Q_ASSERT(sourceProfile); - auto newProfile = Profile::Ptr(new Profile(ProfileManager::instance()->fallbackProfile())); + auto newProfile = Profile::Ptr(new Profile()); newProfile->clone(sourceProfile, true); newProfile->setProperty(Profile::Name, i18nc("@item This will be used as part of the file name", "New Profile")); newProfile->setProperty(Profile::UntranslatedName, QStringLiteral("New Profile"));