diff --git a/kcm_sddm.actions b/kcm_sddm.actions --- a/kcm_sddm.actions +++ b/kcm_sddm.actions @@ -295,3 +295,15 @@ Description[zh_TW]=移除先前安裝的 SDDM 主題 Policy=auth_admin Persistence=session + +[org.kde.kcontrol.kcmsddm.sync] +Name=Synchronize Settings +Description=Synchronizes user settings with SDDM settings +Policy=auth_admin +Persistence=session + +[org.kde.kcontrol.kcmsddm.reset] +Name=Reset Settings +Description=Resets SDDM settings so there are not user settings +Policy=auth_admin +Persistence=session diff --git a/sddmauthhelper.h b/sddmauthhelper.h --- a/sddmauthhelper.h +++ b/sddmauthhelper.h @@ -24,10 +24,16 @@ class SddmAuthHelper: public QObject { Q_OBJECT + public Q_SLOTS: + ActionReply sync(const QVariantMap &args); + ActionReply reset(const QVariantMap &args); ActionReply save(const QVariantMap &args); ActionReply installtheme(const QVariantMap &args); ActionReply uninstalltheme(const QVariantMap &args); + +public: + void copyFile (const QString &source, const QString &destination); }; #endif //SDDMAUTHHELPER_H diff --git a/sddmauthhelper.cpp b/sddmauthhelper.cpp --- a/sddmauthhelper.cpp +++ b/sddmauthhelper.cpp @@ -17,6 +17,8 @@ */ #include "sddmauthhelper.h" +#include + #include #include #include @@ -30,6 +32,7 @@ #include #include #include +#include #include static QSharedPointer openConfig(const QString &filePath) @@ -46,6 +49,86 @@ return QSharedPointer(new KConfig(file.fileName(), KConfig::SimpleConfig)); } +void SddmAuthHelper::copyFile(const QString &source, const QString &destination) +{ + KUser sddmUser(QStringLiteral("sddm")); + + if (QFile::exists(destination)) { + QFile::remove(destination); + } + + QFile::copy(source, destination); + const char* destinationConverted = destination.toLocal8Bit().data(); + if (chown(destinationConverted, sddmUser.userId().nativeId(), sddmUser.groupId().nativeId())) { + return; + } +} + +ActionReply SddmAuthHelper::sync(const QVariantMap &args) +{ + QDir sddmConfigLocation(args[QStringLiteral("sddmUserConfig")].toString()); + if (!sddmConfigLocation.exists()) { + QDir().mkpath(sddmConfigLocation.path()); + } + + // copy fontconfig (font, font rendering) + if (!args[QStringLiteral("fontconfig")].isNull()) { + QDir fontconfigSource(args[QStringLiteral("fontconfig")].toString()); + QStringList sourceFileEntries = fontconfigSource.entryList (QDir::Files); + QStringList sourceDirEntries = fontconfigSource.entryList (QDir::AllDirs); + QDir fontconfigDestination(sddmConfigLocation.path() + QStringLiteral("/fontconfig")); + + if (!fontconfigDestination.exists()) { + QDir().mkpath(fontconfigDestination.path()); + } + + if (sourceFileEntries.count() != 0) { + for (int i = 0; igroup(groupName).writeEntry(keyName, iterator.value()); sddmOldConfig->group(groupName).deleteEntry(keyName); @@ -230,8 +313,6 @@ return ActionReply::SuccessReply(); } - KAUTH_HELPER_MAIN("org.kde.kcontrol.kcmsddm", SddmAuthHelper) #include "moc_sddmauthhelper.cpp" - diff --git a/src/advanceconfig.h b/src/advanceconfig.h --- a/src/advanceconfig.h +++ b/src/advanceconfig.h @@ -41,6 +41,10 @@ Q_SIGNALS: void changed(bool changed=true); +public Q_SLOTS: + void syncSettingsChanged(); + void resetSettingsChanged(); + private Q_SLOTS: void slotUidRangeChanged(); diff --git a/src/advanceconfig.cpp b/src/advanceconfig.cpp --- a/src/advanceconfig.cpp +++ b/src/advanceconfig.cpp @@ -24,8 +24,12 @@ #include "usersmodel.h" #include +#include #include +#include +#include +#include #include #include @@ -38,6 +42,7 @@ { configUi = new Ui::AdvanceConfig(); configUi->setupUi(this); + configUi->syncExplanation->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); load(); @@ -54,6 +59,9 @@ // manually emit changed signal since QCheckBox::clicked will pass false to changed() when unchecked connect(configUi->autoLogin, &QCheckBox::clicked, this, [this] { emit changed(); }); connect(configUi->reloginAfterQuit, &QAbstractButton::clicked, this, [this] { emit changed(); }); + + connect(configUi->syncSettings, &QPushButton::clicked, this, &AdvanceConfig::syncSettingsChanged); + connect(configUi->resetSettings, &QPushButton::clicked, this, &AdvanceConfig::resetSettingsChanged); } AdvanceConfig::~AdvanceConfig() @@ -160,3 +168,68 @@ return true; } + +void AdvanceConfig::syncSettingsChanged() +{ + const QString fontconfigPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("fontconfig"), QStandardPaths::LocateDirectory); + const QString kdeglobalsPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("kdeglobals")); + const QString plasmarcPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("plasmarc")); + const QString sddmUserConfigPath = KUser("sddm").homeDir() + QStringLiteral("/.config"); + + if (fontconfigPath.isEmpty()) { + qDebug() << "fontconfig folder not found"; + } + if (kdeglobalsPath.isEmpty()) { + qDebug() << "kdeglobals file not found"; + } + if (plasmarcPath.isEmpty()) { + qDebug() << "plasmarc file not found"; + } + + QVariantMap args; + args[QStringLiteral("fontconfig")] = fontconfigPath; + args[QStringLiteral("kdeglobals")] = kdeglobalsPath; + args[QStringLiteral("plasmarc")] = plasmarcPath; + args[QStringLiteral("sddmUserConfig")] = sddmUserConfigPath; + + KAuth::Action syncAction(QStringLiteral("org.kde.kcontrol.kcmsddm.sync")); + syncAction.setHelperId(QStringLiteral("org.kde.kcontrol.kcmsddm")); + syncAction.setArguments(args); + + auto job = syncAction.execute(); + job->exec(); + + if (job->error()){ + qDebug() << "Synchronization failed"; + qDebug() << job->errorString(); + qDebug() << job->errorText(); + } else { + changed(false); + //syncStatus->setText(i18n("synced")); + qDebug() << "Synchronization successful"; + } +} + +void AdvanceConfig::resetSettingsChanged() +{ + const QString sddmUserConfigPath = KUser("sddm").homeDir() + QStringLiteral("/.config"); + + QVariantMap args; + args[QStringLiteral("sddmUserConfig")] = sddmUserConfigPath; + + KAuth::Action resetAction(QStringLiteral("org.kde.kcontrol.kcmsddm.reset")); + resetAction.setHelperId(QStringLiteral("org.kde.kcontrol.kcmsddm")); + resetAction.setArguments(args); + + auto job = resetAction.execute(); + job->exec(); + + if (job->error()){ + qDebug() << "Reset failed"; + qDebug() << job->errorString(); + qDebug() << job->errorText(); + } else { + changed(false); + qDebug() << "Reset successful"; + } +} diff --git a/src/ui/advanceconfig.ui b/src/ui/advanceconfig.ui --- a/src/ui/advanceconfig.ui +++ b/src/ui/advanceconfig.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 326 + 547 + 435 @@ -19,20 +19,15 @@ Qt::AlignHCenter|Qt::AlignTop + + + + Automatically log in: + + + - - 0 - - - 0 - - - 0 - - - 0 - @@ -82,6 +77,42 @@ + + + + Qt::Vertical + + + + 8 + 8 + + + + + + + + Cursor theme: + + + + + + + + + + Qt::Vertical + + + + 8 + 8 + + + + @@ -122,15 +153,28 @@ + + + + Qt::Vertical + + + + 8 + 8 + + + + Halt command: - + 250 @@ -147,34 +191,24 @@ - + 250 0 - - + + - Automatically log in: + Settings synchronization: - - - - - - - Cursor theme: - - - - - + + Qt::Vertical @@ -186,31 +220,54 @@ - - - - Qt::Vertical + + + + + + Sync + + + + + + + + + + Reset + + + + + + + + + + + + + 0 + 0 + - + - 8 - 8 + 320 + 70 - - - - - - Qt::Vertical + + Settings synchronization allows you to transfer your theme customization (color scheme, font, font rendering, icon and Plasma theme) to SDDM. - - - 8 - 8 - + + false - + + true + +