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 | | ||||
20 | #include <QDebug> | 22 | #include <QDebug> | ||
21 | #include <QDir> | 23 | #include <QDir> | ||
22 | #include <QFile> | 24 | #include <QFile> | ||
23 | #include <QFileInfo> | 25 | #include <QFileInfo> | ||
24 | #include <QMimeDatabase> | 26 | #include <QMimeDatabase> | ||
25 | #include <QMimeType> | 27 | #include <QMimeType> | ||
26 | #include <QSharedPointer> | 28 | #include <QSharedPointer> | ||
27 | 29 | | |||
28 | #include <KArchive> | 30 | #include <KArchive> | ||
29 | #include <KConfig> | 31 | #include <KConfig> | ||
30 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
31 | #include <KLocalizedString> | 33 | #include <KLocalizedString> | ||
32 | #include <KTar> | 34 | #include <KTar> | ||
35 | #include <KUser> | ||||
33 | #include <KZip> | 36 | #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 | 37 | | |||
35 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | 38 | static QSharedPointer<KConfig> openConfig(const QString &filePath) | ||
36 | { | 39 | { | ||
37 | QFile file(filePath); | 40 | QFile file(filePath); | ||
38 | if(!file.exists()) { | 41 | if(!file.exists()) { | ||
39 | // If we are creating the config file, ensure it is world-readable: if | 42 | // 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 | 43 | // we don't do that, KConfig will create a file which is only readable | ||
41 | // by root | 44 | // by root | ||
42 | file.open(QIODevice::WriteOnly); | 45 | file.open(QIODevice::WriteOnly); | ||
43 | file.close(); | 46 | file.close(); | ||
44 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | 47 | file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther); | ||
45 | } | 48 | } | ||
46 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | 49 | return QSharedPointer<KConfig>(new KConfig(file.fileName(), KConfig::SimpleConfig)); | ||
47 | } | 50 | } | ||
48 | 51 | | |||
52 | void SddmAuthHelper::copyFile(const QString &source, const QString &destination) | ||||
53 | { | ||||
54 | KUser sddmUser(QStringLiteral("sddm")); | ||||
55 | | ||||
davidedmundson: do we need two objects representing the same user? | |||||
56 | if (QFile::exists(destination)) { | ||||
57 | QFile::remove(destination); | ||||
ngraham: Don't ignore the error if the removal fails | |||||
58 | } | ||||
59 | | ||||
60 | QFile::copy(source, destination); | ||||
ngraham: Don't ignore the error if the copy fails | |||||
61 | const char* destinationConverted = destination.toLocal8Bit().data(); | ||||
62 | chown(destinationConverted, sddmUser.userId().nativeId(), sddmUser.groupId().nativeId()); | ||||
ngraham: Don't ignore the error if the chown fails | |||||
63 | } | ||||
64 | | ||||
65 | ActionReply SddmAuthHelper::sync(const QVariantMap &args) | ||||
66 | { | ||||
67 | // copy fontconfig (font, font rendering) | ||||
68 | if (!args[QStringLiteral("fontconfig")].isNull()) { | ||||
69 | QDir fontconfigSource(args[QStringLiteral("fontconfig")].toString()); | ||||
70 | QStringList sourceFileEntries = fontconfigSource.entryList (QDir::Files); | ||||
71 | QStringList sourceDirEntries = fontconfigSource.entryList (QDir::AllDirs); | ||||
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… | |||||
72 | QDir fontconfigDestination(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/fontconfig")); | ||||
73 | | ||||
74 | if (!fontconfigDestination.exists()) { | ||||
75 | QDir().mkpath(fontconfigDestination.path()); | ||||
davidedmundson: Don't hardcode /var/lib/sddm
KUser("sddm").homeDir() would be better
| |||||
76 | } | ||||
77 | | ||||
78 | for (int i = 0; i<sourceDirEntries.count(); i++) { | ||||
79 | QString directoriesSource = fontconfigSource.path() + QDir::separator() + sourceDirEntries[i]; | ||||
80 | QString directoriesDestination = fontconfigDestination.path() + QDir::separator() + sourceDirEntries[i]; | ||||
81 | fontconfigSource.mkpath(directoriesDestination); | ||||
82 | copyFile(directoriesSource, directoriesDestination); | ||||
83 | } | ||||
84 | | ||||
85 | for (int i = 0; i<sourceFileEntries.count(); i++) { | ||||
86 | QString filesSource = fontconfigSource.path() + QDir::separator() + sourceFileEntries[i]; | ||||
87 | QString filesDestination = fontconfigDestination.path() + QDir::separator() + sourceFileEntries[i]; | ||||
88 | copyFile(filesSource, filesDestination); | ||||
89 | } | ||||
90 | } | ||||
91 | | ||||
92 | // copy kdeglobals (color scheme) | ||||
93 | if (!args[QStringLiteral("kdeglobals")].isNull()) { | ||||
what would happen if:
davidedmundson: what would happen if:
- there is no /var/lib/sddm/.config yet
- the user hasn't got a… | |||||
94 | QDir kdeglobalsSource(args[QStringLiteral("kdeglobals")].toString()); | ||||
95 | QDir kdeglobalsDestination(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/kdeglobals")); | ||||
96 | copyFile(kdeglobalsSource.path(), kdeglobalsDestination.path()); | ||||
97 | } | ||||
98 | | ||||
99 | // copy plasmarc (icons, UI style) | ||||
100 | if (!args[QStringLiteral("plasmarc")].isNull()) { | ||||
101 | QDir plasmarcSource(args[QStringLiteral("plasmarc")].toString()); | ||||
102 | QDir plasmarcDestination(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/plasmarc")); | ||||
103 | copyFile(plasmarcSource.path(), plasmarcDestination.path()); | ||||
104 | } | ||||
105 | | ||||
106 | return ActionReply::SuccessReply(); | ||||
107 | } | ||||
108 | | ||||
109 | ActionReply SddmAuthHelper::reset(const QVariantMap &args) | ||||
110 | { | ||||
111 | QDir fontconfigDir(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/fontconfig")); | ||||
112 | | ||||
113 | fontconfigDir.removeRecursively(); | ||||
114 | QFile::remove(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/kdeglobals")); | ||||
115 | QFile::remove(args[QStringLiteral("sddmUserConfig")].toString() + QStringLiteral("/plasmarc")); | ||||
116 | | ||||
117 | return ActionReply::SuccessReply(); | ||||
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… | |||||
118 | | ||||
119 | } | ||||
120 | | ||||
49 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | 121 | ActionReply SddmAuthHelper::save(const QVariantMap &args) | ||
50 | { | 122 | { | ||
51 | ActionReply reply = ActionReply::HelperErrorReply(); | 123 | ActionReply reply = ActionReply::HelperErrorReply(); | ||
52 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | 124 | QSharedPointer<KConfig> sddmConfig = openConfig(args[QStringLiteral("kde_settings.conf")].toString()); | ||
53 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | 125 | QSharedPointer<KConfig> sddmOldConfig = openConfig(args[QStringLiteral("sddm.conf")].toString()); | ||
54 | QSharedPointer<KConfig> themeConfig; | 126 | QSharedPointer<KConfig> themeConfig; | ||
55 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | 127 | QString themeConfigFile = args[QStringLiteral("theme.conf.user")].toString(); | ||
56 | 128 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 283 | { | |||
225 | 297 | | |||
226 | if (!dir.removeRecursively()) { | 298 | if (!dir.removeRecursively()) { | ||
227 | return ActionReply::HelperErrorReply(); | 299 | return ActionReply::HelperErrorReply(); | ||
228 | } | 300 | } | ||
229 | 301 | | |||
230 | return ActionReply::SuccessReply(); | 302 | return ActionReply::SuccessReply(); | ||
231 | } | 303 | } | ||
232 | 304 | | |||
233 | | ||||
234 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | 305 | KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) | ||
235 | 306 | | |||
236 | #include "moc_sddmauthhelper.cpp" | 307 | #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.