diff --git a/sddmauthhelper.cpp b/sddmauthhelper.cpp index 648b24c..3b923ca 100644 --- a/sddmauthhelper.cpp +++ b/sddmauthhelper.cpp @@ -1,81 +1,113 @@ /* Copyright 2013 by Reza Fatahilah Shah Copyright 2011, 2012 David Edmundson This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "sddmauthhelper.h" #include +#include +#include #include +#include #include #include static QSharedPointer openConfig(const QString &filePath) { QFile file(filePath); if(!file.exists()) { // If we are creating the config file, ensure it is world-readable: if // we don't do that, KConfig will create a file which is only readable // by root file.open(QIODevice::WriteOnly); file.close(); file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); } return QSharedPointer(new KConfig(file.fileName(), KConfig::SimpleConfig)); } ActionReply SddmAuthHelper::save(const QVariantMap &args) { ActionReply reply = ActionReply::HelperErrorReply(); QSharedPointer sddmConfig = openConfig(args["sddm.conf"].toString()); QSharedPointer themeConfig; QString themeConfigFile = args["theme.conf.user"].toString(); if (!themeConfigFile.isEmpty()) { themeConfig = openConfig(themeConfigFile); } QMap::const_iterator iterator; for (iterator = args.constBegin() ; iterator != args.constEnd() ; ++iterator) { if (iterator.key() == "sddm.conf" || iterator.key() == "theme.conf.user") continue; QStringList configFields = iterator.key().split('/'); QSharedPointer config; QString fileName = configFields[0]; QString groupName = configFields[1]; QString keyName = configFields[2]; if (fileName == "sddm.conf") { sddmConfig->group(groupName).writeEntry(keyName, iterator.value()); } else if (fileName == "theme.conf.user" && !themeConfig.isNull()) { - themeConfig->group(groupName).writeEntry(keyName, iterator.value()); + QFileInfo themeConfigFileInfo(themeConfigFile); + QDir configRootDirectory = themeConfigFileInfo.absoluteDir(); + + if (keyName == "background") { + QFileInfo newBackgroundFileInfo(iterator.value().toString()); + QString previousBackground = themeConfig->group(groupName).readEntry(keyName); + + bool backgroundChanged = newBackgroundFileInfo.fileName() != previousBackground; + if (backgroundChanged) { + if (!previousBackground.isEmpty()) { + QString previousBackgroundPath = configRootDirectory.filePath(previousBackground); + if (QFile::remove(previousBackgroundPath)) { + qDebug() << "Removed previous background " << previousBackgroundPath; + } + } + + if (newBackgroundFileInfo.exists()) { + QString newBackgroundPath = configRootDirectory.filePath(newBackgroundFileInfo.fileName()); + qDebug() << "Copying background from " << newBackgroundFileInfo.absoluteFilePath() << " to " << newBackgroundPath; + if (QFile::copy(newBackgroundFileInfo.absoluteFilePath(), newBackgroundPath)) { + QFile::setPermissions(newBackgroundPath, QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); + themeConfig->group(groupName).writeEntry(keyName, newBackgroundFileInfo.fileName()); + } + } else { + themeConfig->group(groupName).deleteEntry(keyName); + } + } + } else { + themeConfig->group(groupName).writeEntry(keyName, iterator.value()); + } } } sddmConfig->sync(); if (!themeConfig.isNull()) themeConfig->sync(); return ActionReply::SuccessReply(); } KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper); #include "moc_sddmauthhelper.cpp"