Changeset View
Changeset View
Standalone View
Standalone View
sddmauthhelper.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. | ||
14 | 14 | | |||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | 17 | */ | ||
18 | #include "sddmauthhelper.h" | 18 | #include "sddmauthhelper.h" | ||
19 | 19 | | |||
20 | #include <unistd.h> | ||||
21 | | ||||
22 | #include <QDebug> | ||||
23 | #include <QDir> | ||||
20 | #include <QFile> | 24 | #include <QFile> | ||
21 | #include <QFileInfo> | 25 | #include <QFileInfo> | ||
22 | #include <QDir> | | |||
23 | #include <QSharedPointer> | | |||
24 | #include <QDebug> | | |||
25 | #include <QMimeType> | | |||
26 | #include <QMimeDatabase> | 26 | #include <QMimeDatabase> | ||
27 | #include <QMimeType> | ||||
28 | #include <QProcess> | ||||
29 | #include <QSharedPointer> | ||||
27 | 30 | | |||
28 | #include <KLocalizedString> | | |||
29 | #include <KZip> | | |||
30 | #include <KTar> | | |||
31 | #include <KArchive> | 31 | #include <KArchive> | ||
32 | #include <KConfig> | 32 | #include <KConfig> | ||
33 | #include <KConfigGroup> | 33 | #include <KConfigGroup> | ||
34 | #include <KLocalizedString> | ||||
35 | #include <KTar> | ||||
36 | #include <KUser> | ||||
37 | #include <KZip> | ||||
ngraham: This change to alphabetize the includes is good, but should be done in another commit (feel… | |||||
filipf: https://cgit.kde.org/sddm-kcm.git/commit/?id=edaae61c36de21dda224b3e40d9abc1d5e8c057a | |||||
34 | 38 | | |||
35 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | 39 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | ||
36 | { | 40 | { | ||
37 | QFile file(filePath); | 41 | QFile file(filePath); | ||
38 | if(!file.exists()) { | 42 | if(!file.exists()) { | ||
39 | // If we are creating the config file, ensure it is world-readable: if | 43 | // If we are creating the config file, ensure it is world-readable: if | ||
40 | // we don't do that, KConfig will create a file which is only readable | 44 | // we don't do that, KConfig will create a file which is only readable | ||
41 | // by root | 45 | // by root | ||
42 | file.open(QIODevice::WriteOnly); | 46 | file.open(QIODevice::WriteOnly); | ||
43 | file.close(); | 47 | file.close(); | ||
44 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | 48 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | ||
45 | } | 49 | } | ||
46 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | 50 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | ||
47 | } | 51 | } | ||
48 | 52 | | |||
53 | void SddmAuthHelper::copyFile(const QString &source, const QString &destination) | ||||
54 | { | ||||
55 | KUser sddmUser(QStringLiteral("sddm")); | ||||
56 | KUser sddmGroup(QStringLiteral("sddm")); | ||||
davidedmundson: do we need two objects representing the same user? | |||||
57 | //QDir cacheDir(QStringLiteral("/var/lib/sddm/.cache/")); | ||||
58 | | ||||
ngraham: Don't ignore the error if the removal fails | |||||
59 | if (QFile::exists(destination)) { | ||||
60 | QFile::remove(destination); | ||||
61 | } | ||||
ngraham: Don't ignore the error if the copy fails | |||||
62 | | ||||
63 | QFile::copy(source, destination); | ||||
ngraham: Don't ignore the error if the chown fails | |||||
64 | const char* destinationConverted = destination.toLocal8Bit().data(); | ||||
65 | chown(destinationConverted, sddmUser.userId().nativeId(), sddmGroup.groupId().nativeId()); | ||||
66 | //cacheDir.removeRecursively(); | ||||
67 | } | ||||
68 | | ||||
69 | ActionReply SddmAuthHelper::sync(const QVariantMap &args) | ||||
70 | { | ||||
71 | if (!args[QStringLiteral("fontconfig")].isNull()) { | ||||
72 | QDir sourceDirectory(args[QStringLiteral("fontconfig")].toString()); | ||||
Ditto for this and other mkpath() calls. Errors should be handled, even with something as simple as a dialog box saying, "Could not create <path>!" ngraham: Ditto for this and other `mkpath()` calls. Errors should be handled, even with something as… | |||||
73 | QString source(args[QStringLiteral("fontconfig")].toString()); | ||||
74 | QStringList sourceFileEntries = sourceDirectory.entryList (QDir::Files); | ||||
75 | QStringList sourceDirEntries = sourceDirectory.entryList (QDir::AllDirs); | ||||
76 | QDir destination(QStringLiteral("/var/lib/sddm/.config/fontconfig/")); | ||||
davidedmundson: Don't hardcode /var/lib/sddm
KUser("sddm").homeDir() would be better
| |||||
77 | | ||||
78 | if (!destination.exists()) { | ||||
79 | QDir().mkpath(QStringLiteral("/var/lib/sddm/.config/fontconfig/")); | ||||
80 | } | ||||
81 | | ||||
82 | // for every source folder create a folder in destination location | ||||
83 | for (int i = 0; i<sourceDirEntries.count(); i++) { | ||||
84 | QString directoriesSource = source + QDir::separator() + sourceDirEntries[i]; | ||||
85 | QString directoriesDestination = (QStringLiteral("/var/lib/sddm/.config/fontconfig/")) + QDir::separator() + sourceDirEntries[i]; | ||||
86 | sourceDirectory.mkpath(directoriesDestination); | ||||
87 | copyFile(directoriesSource, directoriesDestination); | ||||
88 | } | ||||
89 | | ||||
90 | // for every source file copy into destination location | ||||
91 | for (int i = 0; i<sourceFileEntries.count(); i++) { | ||||
92 | QString filesSource = source + QDir::separator() + sourceFileEntries[i]; | ||||
93 | QString filesDestination = (QStringLiteral("/var/lib/sddm/.config/fontconfig/")) + QDir::separator() + sourceFileEntries[i]; | ||||
94 | copyFile(filesSource, filesDestination); | ||||
what would happen if:
davidedmundson: what would happen if:
- there is no /var/lib/sddm/.config yet
- the user hasn't got a… | |||||
95 | } | ||||
96 | } | ||||
97 | | ||||
98 | // copy kdeglobals (color scheme) | ||||
99 | if (!args[QStringLiteral("kdeglobals")].isNull()) { | ||||
100 | const QString source = args[QStringLiteral("kdeglobals")].toString(); | ||||
101 | const QString destination = QStringLiteral("/var/lib/sddm/.config/kdeglobals"); | ||||
102 | copyFile(source, destination); | ||||
103 | } | ||||
104 | | ||||
105 | // copy plasmarc (icons, UI style) | ||||
106 | if (!args[QStringLiteral("plasmarc")].isNull()) { | ||||
107 | const QString source = args[QStringLiteral("plasmarc")].toString(); | ||||
108 | const QString destination = QStringLiteral("/var/lib/sddm/.config/plasmarc"); | ||||
109 | copyFile(source, destination); | ||||
110 | } | ||||
111 | return ActionReply::SuccessReply(); | ||||
112 | } | ||||
113 | | ||||
114 | ActionReply SddmAuthHelper::reset(const QVariantMap &args) | ||||
115 | { | ||||
116 | QDir fontconfigDir(QStringLiteral("/var/lib/sddm/.config/fontconfig")); | ||||
117 | //QDir cacheDir(QStringLiteral("/var/lib/sddm/.cache/")); | ||||
118 | if (!args[QStringLiteral("sddmUserConfig")].isNull()) { | ||||
What's the point of this argument when you hardcode/evaluate it so much in this file. davidedmundson: What's the point of this argument when you hardcode/evaluate it so much in this file. | |||||
Initially it was supposed to be a check that the Reset button was pressed (because that's when the argument would get emitted), but I'll check if it can be removed now. filipf: Initially it was supposed to be a check that the Reset button was pressed (because that's when… | |||||
119 | fontconfigDir.removeRecursively(); | ||||
120 | QFile::remove(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("kdeglobals")); | ||||
121 | QFile::remove(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("plasmarc")); | ||||
122 | //cacheDir.removeRecursively(); | ||||
123 | } | ||||
124 | return ActionReply::SuccessReply(); | ||||
125 | } | ||||
126 | | ||||
49 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | 127 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | ||
50 | { | 128 | { | ||
51 | ActionReply reply = ActionReply::HelperErrorReply(); | 129 | ActionReply reply = ActionReply::HelperErrorReply(); | ||
52 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | 130 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | ||
53 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | 131 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | ||
54 | QSharedPointer<KConfig> themeConfig; | 132 | QSharedPointer<KConfig> themeConfig; | ||
55 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | 133 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | ||
56 | 134 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 289 | { | |||
225 | 303 | | |||
226 | if (!dir.removeRecursively()) { | 304 | if (!dir.removeRecursively()) { | ||
227 | return ActionReply::HelperErrorReply(); | 305 | return ActionReply::HelperErrorReply(); | ||
228 | } | 306 | } | ||
229 | 307 | | |||
230 | return ActionReply::SuccessReply(); | 308 | return ActionReply::SuccessReply(); | ||
231 | } | 309 | } | ||
232 | 310 | | |||
233 | | ||||
234 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | 311 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | ||
235 | 312 | | |||
236 | #include "moc_sddmauthhelper.cpp" | 313 | #include "moc_sddmauthhelper.cpp" | ||
237 | |
This change to alphabetize the includes is good, but should be done in another commit (feel free to commit directly) as it doesn't directly pertain to the changes here.