diff --git a/src/Profile.cpp b/src/Profile.cpp index ae7daf676..1dd852204 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -36,6 +36,9 @@ #include #include +// System +#include + // Konsole #include "ShellCommand.h" @@ -235,13 +238,9 @@ QString KDE4ProfileWriter::getPath(const Profile* info) if ( info->isPropertySet(Profile::Path) ) newPath=info->path(); - // if the path is not specified, use the profile name + ".profile" - if ( newPath.isEmpty() ) - newPath = info->name() + ".profile"; - - QFileInfo fileInfo(newPath); - if (!fileInfo.isAbsolute()) - newPath = KGlobal::dirs()->saveLocation("data","konsole/") + newPath; + // if the path is not specified, not absolute or not writable use the profile name + ".profile" + if ( newPath.isEmpty() || !QFileInfo(newPath).isAbsolute() || !KStandardDirs::checkAccess(newPath, W_OK) ) + newPath = KGlobal::dirs()->saveLocation("data","konsole/") + info->name() + ".profile"; qDebug() << "Saving profile under name: " << newPath; @@ -251,7 +250,7 @@ void KDE4ProfileWriter::writeStandardElement(KConfigGroup& group , const Profil Profile::Property attribute) { QString name = Profile::primaryNameForProperty(attribute); - + if ( profile->isPropertySet(attribute) ) group.writeEntry(name,profile->property(attribute)); } diff --git a/src/SessionManager.cpp b/src/SessionManager.cpp index 7e37c20fd..bd7c48248 100644 --- a/src/SessionManager.cpp +++ b/src/SessionManager.cpp @@ -301,14 +301,11 @@ QString SessionManager::defaultProfileKey() const return _defaultProfile; } -QString SessionManager::saveProfile(const QString& path , Profile* info) +QString SessionManager::saveProfile(Profile* info) { ProfileWriter* writer = new KDE4ProfileWriter; - QString newPath = path; - - if ( newPath.isEmpty() ) - newPath = writer->getPath(info); + QString newPath = writer->getPath(info); writer->writeProfile(newPath,info); @@ -347,21 +344,7 @@ void SessionManager::changeProfile(const QString& key , emit profileChanged(key); if ( persistant ) - { - // save the changes to disk - // the path may be empty here, in which case it is up - // to the profile writer to generate or request a path name - if ( info->isPropertySet(Profile::Path) ) - { - qDebug() << "Profile saved to existing path: " << info->path(); - info->setProperty(Profile::Path,saveProfile(info->path(),info)); - } - else - { - qDebug() << "Profile saved to new path."; - info->setProperty(Profile::Path,saveProfile(QString(),info)); - } - } + info->setProperty(Profile::Path,saveProfile(info)); } void SessionManager::applyProfile(const QString& key , bool modifiedPropertiesOnly) { diff --git a/src/SessionManager.h b/src/SessionManager.h index 2599099f5..d24d3632f 100644 --- a/src/SessionManager.h +++ b/src/SessionManager.h @@ -290,9 +290,9 @@ private: void saveFavorites(); // saves a profile to a file // returns the path to which the profile was saved, which will - // be the same as the 'path' argument if valid or a newly generated path + // be the same as the path property of profile if valid or a newly generated path // otherwise - QString saveProfile(const QString& path , Profile* profile); + QString saveProfile(Profile* profile); // applies updates to the profile associated with @p key // to all sessions currently using that profile