Commit 0feaa769 authored by Kurt Hindenburg's avatar Kurt Hindenburg

simplify ProfileWriter class as there is no longer multiple versions

parent e281b226
......@@ -56,7 +56,7 @@ class ProfileGroup;
class KONSOLEPRIVATE_EXPORT Profile : public QSharedData
{
friend class KDE4ProfileReader;
friend class KDE4ProfileWriter;
friend class ProfileWriter;
friend class ProfileGroup;
public:
......
......@@ -339,7 +339,7 @@ Profile::Ptr ProfileManager::fallbackProfile() const
QString ProfileManager::saveProfile(Profile::Ptr profile)
{
ProfileWriter* writer = new KDE4ProfileWriter;
ProfileWriter* writer = new ProfileWriter();
QString newPath = writer->getPath(profile);
......@@ -513,9 +513,10 @@ void ProfileManager::setDefaultProfile(Profile::Ptr profile)
void ProfileManager::saveDefaultProfile()
{
QString path = _defaultProfile->path();
ProfileWriter* writer = new ProfileWriter();
if (path.isEmpty()) {
path = KDE4ProfileWriter().getPath(_defaultProfile);
path = writer->getPath(_defaultProfile);
}
QFileInfo fileInfo(path);
......@@ -523,6 +524,8 @@ void ProfileManager::saveDefaultProfile()
KSharedConfigPtr appConfig = KSharedConfig::openConfig();
KConfigGroup group = appConfig->group("Desktop Entry");
group.writeEntry("DefaultProfile", fileInfo.fileName());
delete writer;
}
QSet<Profile::Ptr> ProfileManager::findFavorites()
......
......@@ -37,8 +37,11 @@ using namespace Konsole;
// FIXME: A dup line from Profile.cpp - redo these
static const char GENERAL_GROUP[] = "General";
ProfileWriter::ProfileWriter() = default;
ProfileWriter::~ProfileWriter() = default;
// All profiles changes are stored under users' local account
QString KDE4ProfileWriter::getPath(const Profile::Ptr profile)
QString ProfileWriter::getPath(const Profile::Ptr profile)
{
// If any changes are made to this location, check that programs using
// the Konsole part can write/save profiles
......@@ -46,7 +49,7 @@ QString KDE4ProfileWriter::getPath(const Profile::Ptr profile)
return localDataLocation % QLatin1String("/") % profile->untranslatedName() % QLatin1String(".profile");
}
void KDE4ProfileWriter::writeProperties(KConfig& config,
void ProfileWriter::writeProperties(KConfig& config,
const Profile::Ptr profile,
const Profile::PropertyInfo* properties)
{
......@@ -69,7 +72,7 @@ void KDE4ProfileWriter::writeProperties(KConfig& config,
properties++;
}
}
bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile::Ptr profile)
bool ProfileWriter::writeProfile(const QString& path , const Profile::Ptr profile)
{
KConfig config(path, KConfig::NoGlobals);
......@@ -96,4 +99,3 @@ bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile::Ptr pr
return true;
}
......@@ -28,32 +28,24 @@ class KConfig;
namespace Konsole {
/** Interface for all classes which can write profile settings to a file. */
class ProfileWriter
class KONSOLEPRIVATE_EXPORT ProfileWriter
{
public:
virtual ~ProfileWriter()
{
}
ProfileWriter();
~ProfileWriter();
/**
* Returns a suitable path-name for writing
* @p profile to. The path-name should be accepted by
* the corresponding ProfileReader class.
*/
virtual QString getPath(const Profile::Ptr profile) = 0;
QString getPath(const Profile::Ptr profile);
/**
* Writes the properties and values from @p profile to the file specified
* by @p path. This profile should be readable by the corresponding
* ProfileReader class.
*/
virtual bool writeProfile(const QString &path, const Profile::Ptr profile) = 0;
};
/** Writes a KDE 4 .profile file. */
class KONSOLEPRIVATE_EXPORT KDE4ProfileWriter : public ProfileWriter
{
public:
QString getPath(const Profile::Ptr profile) Q_DECL_OVERRIDE;
bool writeProfile(const QString &path, const Profile::Ptr profile) Q_DECL_OVERRIDE;
bool writeProfile(const QString &path, const Profile::Ptr profile);
private:
void writeProperties(KConfig &config, const Profile::Ptr profile,
......
......@@ -192,7 +192,7 @@ void ProfileTest::testProfileFileNames()
{
Profile::Ptr profile = Profile::Ptr(new Profile);
QFileInfo fileInfo;
ProfileWriter *writer = new KDE4ProfileWriter;
ProfileWriter *writer = new ProfileWriter();
profile->setProperty(Profile::UntranslatedName, QStringLiteral("Indiana"));
fileInfo.setFile(writer->getPath(profile));
......
Markdown is supported
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