Changeset View
Changeset View
Standalone View
Standalone View
src/advanceconfig.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | #include "advanceconfig.h" | 17 | #include "advanceconfig.h" | ||
18 | #include "ui_advanceconfig.h" | 18 | #include "ui_advanceconfig.h" | ||
19 | #include "config.h" | 19 | #include "config.h" | ||
20 | #include "cursortheme/thememodel.h" | | |||
21 | #include "cursortheme/sortproxymodel.h" | | |||
22 | #include "cursortheme/cursortheme.h" | | |||
23 | #include "sessionmodel.h" | 20 | #include "sessionmodel.h" | ||
24 | #include "usersmodel.h" | 21 | #include "usersmodel.h" | ||
25 | 22 | | |||
26 | #include <QDebug> | 23 | #include <QDebug> | ||
24 | #include <QFontDatabase> | ||||
27 | #include <QIntValidator> | 25 | #include <QIntValidator> | ||
26 | #include <QStandardPaths> | ||||
28 | 27 | | |||
28 | #include <KAuth/KAuthActionReply> | ||||
29 | #include <kauthexecutejob.h> | ||||
29 | #include <KConfigGroup> | 30 | #include <KConfigGroup> | ||
30 | #include <KUser> | 31 | #include <KUser> | ||
31 | 32 | | |||
32 | const int MIN_UID = 1000; | 33 | const int MIN_UID = 1000; | ||
33 | const int MAX_UID = 60000; | 34 | const int MAX_UID = 60000; | ||
34 | 35 | | |||
35 | AdvanceConfig::AdvanceConfig(const KSharedConfigPtr &config, QWidget *parent) : | 36 | AdvanceConfig::AdvanceConfig(const KSharedConfigPtr &config, QWidget *parent) : | ||
36 | QWidget(parent), | 37 | QWidget(parent), | ||
37 | mConfig(config) | 38 | mConfig(config) | ||
38 | { | 39 | { | ||
39 | configUi = new Ui::AdvanceConfig(); | 40 | configUi = new Ui::AdvanceConfig(); | ||
40 | configUi->setupUi(this); | 41 | configUi->setupUi(this); | ||
42 | configUi->syncExplanation->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | ||||
41 | 43 | | |||
42 | load(); | 44 | load(); | ||
43 | 45 | | |||
44 | connect(configUi->userList, SIGNAL(activated(int)), SIGNAL(changed())); | 46 | connect(configUi->userList, SIGNAL(activated(int)), SIGNAL(changed())); | ||
45 | connect(configUi->sessionList, SIGNAL(activated(int)), SIGNAL(changed())); | 47 | connect(configUi->sessionList, SIGNAL(activated(int)), SIGNAL(changed())); | ||
46 | connect(configUi->haltCommand, SIGNAL(textChanged(QString)), SIGNAL(changed())); | 48 | connect(configUi->haltCommand, SIGNAL(textChanged(QString)), SIGNAL(changed())); | ||
47 | connect(configUi->rebootCommand, SIGNAL(textChanged(QString)), SIGNAL(changed())); | 49 | connect(configUi->rebootCommand, SIGNAL(textChanged(QString)), SIGNAL(changed())); | ||
48 | connect(configUi->cursorList, SIGNAL(activated(int)), SIGNAL(changed())); | | |||
49 | connect(configUi->minimumUid, SIGNAL(textChanged(QString)), SIGNAL(changed())); | 50 | connect(configUi->minimumUid, SIGNAL(textChanged(QString)), SIGNAL(changed())); | ||
50 | connect(configUi->minimumUid, &QLineEdit::textChanged, this, &AdvanceConfig::slotUidRangeChanged); | 51 | connect(configUi->minimumUid, &QLineEdit::textChanged, this, &AdvanceConfig::slotUidRangeChanged); | ||
51 | connect(configUi->maximumUid, SIGNAL(textChanged(QString)), SIGNAL(changed())); | 52 | connect(configUi->maximumUid, SIGNAL(textChanged(QString)), SIGNAL(changed())); | ||
52 | connect(configUi->maximumUid, &QLineEdit::textChanged, this, &AdvanceConfig::slotUidRangeChanged); | 53 | connect(configUi->maximumUid, &QLineEdit::textChanged, this, &AdvanceConfig::slotUidRangeChanged); | ||
53 | 54 | | |||
54 | // manually emit changed signal since QCheckBox::clicked will pass false to changed() when unchecked | 55 | // manually emit changed signal since QCheckBox::clicked will pass false to changed() when unchecked | ||
55 | connect(configUi->autoLogin, &QCheckBox::clicked, this, [this] { emit changed(); }); | 56 | connect(configUi->autoLogin, &QCheckBox::clicked, this, [this] { emit changed(); }); | ||
56 | connect(configUi->reloginAfterQuit, &QAbstractButton::clicked, this, [this] { emit changed(); }); | 57 | connect(configUi->reloginAfterQuit, &QAbstractButton::clicked, this, [this] { emit changed(); }); | ||
58 | | ||||
59 | connect(configUi->syncSettings, &QPushButton::clicked, this, &AdvanceConfig::syncSettingsChanged); | ||||
60 | connect(configUi->resetSettings, &QPushButton::clicked, this, &AdvanceConfig::resetSettingsChanged); | ||||
57 | } | 61 | } | ||
58 | 62 | | |||
59 | AdvanceConfig::~AdvanceConfig() | 63 | AdvanceConfig::~AdvanceConfig() | ||
60 | { | 64 | { | ||
61 | delete configUi; | 65 | delete configUi; | ||
62 | } | 66 | } | ||
63 | 67 | | |||
64 | void AdvanceConfig::load() | 68 | void AdvanceConfig::load() | ||
65 | { | 69 | { | ||
66 | //Cursor themes | | |||
67 | CursorThemeModel *cursorModel = new CursorThemeModel(this); | | |||
68 | proxyCursorModel = new SortProxyModel(this); | | |||
69 | proxyCursorModel->setSourceModel(cursorModel); | | |||
70 | proxyCursorModel->setFilterCaseSensitivity(Qt::CaseSensitive); | | |||
71 | proxyCursorModel->sort(Qt::DisplayRole, Qt::AscendingOrder); | | |||
72 | | ||||
73 | configUi->cursorList->setModel(proxyCursorModel); | | |||
74 | QString currentCursor = mConfig->group("Theme").readEntry("CursorTheme", ""); | | |||
75 | QModelIndex cursorIndex = proxyCursorModel->findIndex(currentCursor); | | |||
76 | configUi->cursorList->setCurrentIndex(cursorIndex.row() < 0 ? 0 : cursorIndex.row()); | | |||
77 | | ||||
78 | //User list | 70 | //User list | ||
79 | int minUid, maxUid; | 71 | int minUid, maxUid; | ||
80 | minUid = mConfig->group("Users").readEntry("MinimumUid", MIN_UID); | 72 | minUid = mConfig->group("Users").readEntry("MinimumUid", MIN_UID); | ||
81 | maxUid = mConfig->group("Users").readEntry("MaximumUid", MAX_UID); | 73 | maxUid = mConfig->group("Users").readEntry("MaximumUid", MAX_UID); | ||
82 | 74 | | |||
83 | userModel = new UsersModel(this); | 75 | userModel = new UsersModel(this); | ||
84 | configUi->userList->setModel(userModel); | 76 | configUi->userList->setModel(userModel); | ||
85 | userModel->populate( minUid, maxUid ); | 77 | userModel->populate( minUid, maxUid ); | ||
Show All 22 Lines | |||||
108 | configUi->haltCommand->setUrl(QUrl::fromLocalFile(mConfig->group("General").readEntry("HaltCommand"))); | 100 | configUi->haltCommand->setUrl(QUrl::fromLocalFile(mConfig->group("General").readEntry("HaltCommand"))); | ||
109 | configUi->rebootCommand->setUrl(QUrl::fromLocalFile(mConfig->group("General").readEntry("RebootCommand"))); | 101 | configUi->rebootCommand->setUrl(QUrl::fromLocalFile(mConfig->group("General").readEntry("RebootCommand"))); | ||
110 | } | 102 | } | ||
111 | 103 | | |||
112 | QVariantMap AdvanceConfig::save() | 104 | QVariantMap AdvanceConfig::save() | ||
113 | { | 105 | { | ||
114 | QVariantMap args; | 106 | QVariantMap args; | ||
115 | 107 | | |||
116 | qDebug() << "idx:" << configUi->cursorList->currentIndex(); | | |||
117 | | ||||
118 | QModelIndex cursorIndex = configUi->cursorList->model()->index(configUi->cursorList->currentIndex(),0); | | |||
119 | if (cursorIndex.isValid()) { | | |||
120 | const CursorTheme *cursorTheme = proxyCursorModel->theme(cursorIndex); | | |||
121 | if (cursorTheme) | | |||
122 | args[QStringLiteral("kde_settings.conf/Theme/CursorTheme")] = cursorTheme->name(); | | |||
123 | } | | |||
124 | | ||||
125 | args[QStringLiteral("kde_settings.conf/Autologin/User")] = ( configUi->autoLogin->isChecked() ) ? configUi->userList->currentText() : QString(); | 108 | args[QStringLiteral("kde_settings.conf/Autologin/User")] = ( configUi->autoLogin->isChecked() ) ? configUi->userList->currentText() : QString(); | ||
126 | args[QStringLiteral("kde_settings.conf/Autologin/Session")] = ( configUi->autoLogin->isChecked() ) ? configUi->sessionList->currentData() : QString(); | 109 | args[QStringLiteral("kde_settings.conf/Autologin/Session")] = ( configUi->autoLogin->isChecked() ) ? configUi->sessionList->currentData() : QString(); | ||
127 | 110 | | |||
128 | args[QStringLiteral("kde_settings.conf/Autologin/Relogin")] = configUi->reloginAfterQuit->isChecked(); | 111 | args[QStringLiteral("kde_settings.conf/Autologin/Relogin")] = configUi->reloginAfterQuit->isChecked(); | ||
129 | //TODO session | 112 | //TODO session | ||
130 | 113 | | |||
131 | int minUid = configUi->minimumUid->text().toInt(); | 114 | int minUid = configUi->minimumUid->text().toInt(); | ||
132 | int maxUid = configUi->maximumUid->text().toInt(); | 115 | int maxUid = configUi->maximumUid->text().toInt(); | ||
Show All 22 Lines | |||||
155 | 138 | | |||
156 | bool AdvanceConfig::isUidRangeValid(int minUid, int maxUid) const | 139 | bool AdvanceConfig::isUidRangeValid(int minUid, int maxUid) const | ||
157 | { | 140 | { | ||
158 | if (minUid < 0 || minUid > maxUid) | 141 | if (minUid < 0 || minUid > maxUid) | ||
159 | return false; | 142 | return false; | ||
160 | 143 | | |||
161 | return true; | 144 | return true; | ||
162 | } | 145 | } | ||
146 | | ||||
147 | void AdvanceConfig::syncSettingsChanged() | ||||
148 | { | ||||
149 | KConfig config(QStringLiteral("kcminputrc")); | ||||
davidedmundson: why? | |||||
I need the identifier to delete the entry in the config file (done in sddmauthhelper.cpp), the value is not important so I just set whatever. Any smarter way of doing this? filipf: I need the identifier to delete the entry in the config file (done in sddmauthhelper.cpp), the… | |||||
args[QStringLiteral("kde_settings.conf/Theme/CursorTheme")] = QVariant(); Then in sddmauthhelper, something like if (fileName == QLatin1String("kde_settings.conf")) { if (iterator.value().isValid()) { sddmConfig->group(groupName).writeEntry(keyName, iterator.value()); } else { sddmConfig->group(groupName).deleteEntry(keyName); } sddmOldConfig->group(groupName).deleteEntry(keyName); } } davidedmundson: args[QStringLiteral("kde_settings.conf/Theme/CursorTheme")] = QVariant();
Then in… | |||||
150 | KConfigGroup configGroup(&config, "Mouse"); | ||||
151 | QVariant cursorTheme = configGroup.readEntry("cursorTheme", QString()); | ||||
152 | | ||||
153 | const QString fontconfigPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("fontconfig"), QStandardPaths::LocateDirectory); | ||||
154 | const QString kdeglobalsPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("kdeglobals")); | ||||
155 | const QString plasmarcPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QStringLiteral("plasmarc")); | ||||
156 | const QString sddmUserConfigPath = KUser("sddm").homeDir() + QStringLiteral("/.config"); | ||||
157 | | ||||
158 | if (fontconfigPath.isEmpty()) { | ||||
159 | qDebug() << "fontconfig folder not found"; | ||||
160 | } | ||||
161 | if (kdeglobalsPath.isEmpty()) { | ||||
162 | qDebug() << "kdeglobals file not found"; | ||||
163 | } | ||||
164 | if (plasmarcPath.isEmpty()) { | ||||
165 | qDebug() << "plasmarc file not found"; | ||||
166 | } | ||||
167 | | ||||
168 | QVariantMap args; | ||||
169 | args[QStringLiteral("kde_settings.conf")] = QString {QLatin1String(SDDM_CONFIG_DIR "/") + QStringLiteral("kde_settings.conf")}; | ||||
170 | args[QStringLiteral("sddm.conf")] = QLatin1String(SDDM_CONFIG_FILE); | ||||
171 | args[QStringLiteral("kde_settings.conf/Theme/CursorTheme")] = cursorTheme; | ||||
172 | args[QStringLiteral("fontconfig")] = fontconfigPath; | ||||
173 | args[QStringLiteral("kdeglobals")] = kdeglobalsPath; | ||||
174 | args[QStringLiteral("plasmarc")] = plasmarcPath; | ||||
175 | args[QStringLiteral("sddmUserConfig")] = sddmUserConfigPath; | ||||
176 | | ||||
177 | KAuth::Action syncAction(QStringLiteral("org.kde.kcontrol.kcmsddm.sync")); | ||||
178 | syncAction.setHelperId(QStringLiteral("org.kde.kcontrol.kcmsddm")); | ||||
179 | syncAction.setArguments(args); | ||||
180 | | ||||
181 | auto job = syncAction.execute(); | ||||
182 | job->exec(); | ||||
183 | | ||||
184 | if (job->error()){ | ||||
185 | qDebug() << "Synchronization failed"; | ||||
186 | qDebug() << job->errorString(); | ||||
187 | qDebug() << job->errorText(); | ||||
188 | } else { | ||||
189 | changed(false); | ||||
190 | //syncStatus->setText(i18n("synced")); | ||||
191 | qDebug() << "Synchronization successful"; | ||||
192 | } | ||||
193 | } | ||||
194 | | ||||
195 | void AdvanceConfig::resetSettingsChanged() | ||||
196 | { | ||||
197 | const QString sddmUserConfigPath = KUser("sddm").homeDir() + QStringLiteral("/.config"); | ||||
198 | | ||||
199 | QVariantMap args; | ||||
200 | args[QStringLiteral("kde_settings.conf")] = QString {QLatin1String(SDDM_CONFIG_DIR "/") + QStringLiteral("kde_settings.conf")}; | ||||
201 | args[QStringLiteral("sddm.conf")] = QLatin1String(SDDM_CONFIG_FILE); | ||||
202 | args[QStringLiteral("sddmUserConfig")] = sddmUserConfigPath; | ||||
203 | args[QStringLiteral("kde_settings.conf/Theme/CursorTheme")] = QStringLiteral("nothing"); | ||||
204 | | ||||
205 | KAuth::Action resetAction(QStringLiteral("org.kde.kcontrol.kcmsddm.reset")); | ||||
206 | resetAction.setHelperId(QStringLiteral("org.kde.kcontrol.kcmsddm")); | ||||
207 | resetAction.setArguments(args); | ||||
208 | | ||||
209 | auto job = resetAction.execute(); | ||||
210 | job->exec(); | ||||
211 | | ||||
212 | if (job->error()){ | ||||
213 | qDebug() << "Reset failed"; | ||||
214 | qDebug() << job->errorString(); | ||||
215 | qDebug() << job->errorText(); | ||||
216 | } else { | ||||
217 | changed(false); | ||||
218 | qDebug() << "Reset successful"; | ||||
219 | } | ||||
220 | } |
why?