1/*
2 Copyright (C) 1997 Thomas Tanghus (tanghus@earthling.net)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kdm-gen.h"
21
22#include "kbackedcombobox.h"
23
24#include <KDialog>
25#include <KFontRequester>
26#include <KLocale>
27#include <KConfig>
28#include <KConfigGroup>
29#include <KStandardDirs>
30#include <KLanguageButton>
31
32#include <QCheckBox>
33#include <QGroupBox>
34#include <QPushButton>
35#include <QFormLayout>
36#include <QVBoxLayout>
37
38extern KConfig *config;
39
40KDMGeneralWidget::KDMGeneralWidget(QWidget *parent)
41 : QWidget(parent)
42{
43 QString wtstr;
44
45 QBoxLayout *ml = new QVBoxLayout(this);
46
47 QGroupBox *box = new QGroupBox(i18nc("@title:group 'man locale' ...", "Locale"), this);
48 ml->addWidget(box);
49 QFormLayout *fl = new QFormLayout(box);
50
51 // The Language group box
52 langcombo = new KLanguageButton(box);
53 langcombo->showLanguageCodes(true);
54 langcombo->loadAllLanguages();
55 connect(langcombo, SIGNAL(activated(QString)), SIGNAL(changed()));
56 fl->addRow(i18n("&Language:"), langcombo);
57 wtstr = i18n(
58 "Here you can choose the language used by KDM. This setting does not "
59 "affect a user's personal settings; that will take effect after login.");
60 langcombo->setWhatsThis(wtstr);
61
62 QBoxLayout *mlml = new QHBoxLayout();
63 ml->addItem(mlml);
64
65 box = new QGroupBox(i18nc("@title:group", "Appearance"), this);
66 mlml->addWidget(box);
67
68 fl = new QFormLayout(box);
69
70 useThemeCheck = new QCheckBox(i18n("&Use themed greeter\n(Warning: poor accessibility)"), box);
71 connect(useThemeCheck, SIGNAL(toggled(bool)), SLOT(slotUseThemeChanged()));
72 useThemeCheck->setWhatsThis(i18n(
73 "Enable this if you would like to use a themed Login Manager.<br>"
74 "Note that the themed greeter is challenged accessibility-wise (keyboard usage), "
75 "and themes may lack support for features like a user list or alternative "
76 "authentication methods."));
77 fl->addRow(useThemeCheck);
78
79 guicombo = new KBackedComboBox(box);
80 guicombo->insertItem("", i18n("<placeholder>default</placeholder>"));
81 loadGuiStyles(guicombo);
82 guicombo->model()->sort(0);
83
84 connect(guicombo, SIGNAL(activated(int)), SIGNAL(changed()));
85 fl->addRow(i18n("GUI s&tyle:"), guicombo);
86 wtstr = i18n(
87 "You can choose a basic GUI style here that will be used by KDM only.");
88 guicombo->setWhatsThis(wtstr);
89
90 colcombo = new KBackedComboBox(box);
91 colcombo->insertItem("", i18n("<placeholder>default</placeholder>"));
92 loadColorSchemes(colcombo);
93 colcombo->model()->sort(0);
94 connect(colcombo, SIGNAL(activated(int)), SIGNAL(changed()));
95 fl->addRow(i18n("Color sche&me:"), colcombo);
96 wtstr = i18n(
97 "You can choose a basic Color Scheme here that will be used by KDM only.");
98 colcombo->setWhatsThis(wtstr);
99
100 box = new QGroupBox(i18nc("@title:group", "Fonts"), this);
101 mlml->addSpacing(KDialog::spacingHint());
102 mlml->addWidget(box);
103 fl = new QFormLayout(box);
104
105 stdFontChooser = new KFontRequester(box);
106 stdFontChooser->setWhatsThis(i18n(
107 "This changes the font which is used for all the text in the login manager "
108 "except for the greeting and failure messages."));
109 connect(stdFontChooser, SIGNAL(fontSelected(QFont)), SIGNAL(changed()));
110 fl->addRow(i18nc("... font", "&General:"), stdFontChooser);
111
112 failFontChooser = new KFontRequester(box);
113 failFontChooser->setWhatsThis(i18n(
114 "This changes the font which is used for failure messages in the login manager."));
115 connect(failFontChooser, SIGNAL(fontSelected(QFont)), SIGNAL(changed()));
116 fl->addRow(i18nc("font for ...", "&Failure:"), failFontChooser);
117
118 greetingFontChooser = new KFontRequester(box);
119 greetingFontChooser->setWhatsThis(i18n(
120 "This changes the font which is used for the login manager's greeting."));
121 connect(greetingFontChooser, SIGNAL(fontSelected(QFont)), SIGNAL(changed()));
122 fl->addRow(i18nc("font for ...", "Gree&ting:"), greetingFontChooser);
123
124 aacb = new QCheckBox(i18n("Use anti-aliasing for fonts"), box);
125 aacb->setWhatsThis(i18n(
126 "If you check this box and your X-Server has the Xft extension, "
127 "fonts will be antialiased (smoothed) in the login dialog."));
128 connect(aacb, SIGNAL(toggled(bool)), SIGNAL(changed()));
129 fl->addRow(aacb);
130
131 ml->addStretch(1);
132}
133
134void KDMGeneralWidget::loadColorSchemes(KBackedComboBox *combo)
135{
136 // XXX: Global + local schemes
137 const QStringList list = KGlobal::dirs()->
138 findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
139 for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) {
140 KConfig _config(*it, KConfig::SimpleConfig);
141 KConfigGroup config(&_config, "General");
142
143 QString str;
144 if (!(str = config.readEntry("Name")).isEmpty()) {
145 QString str2 = (*it).mid((*it).lastIndexOf('/') + 1); // strip off path
146 str2.chop(7); // strip off ".colors"
147 combo->insertItem(str2, str);
148 }
149 }
150}
151
152void KDMGeneralWidget::loadGuiStyles(KBackedComboBox *combo)
153{
154 // XXX: Global + local schemes
155 const QStringList list = KGlobal::dirs()->
156 findAllResources("data", "kstyle/themes/*.themerc", KStandardDirs::NoDuplicates);
157 for (QStringList::ConstIterator it = list.constBegin(); it != list.constEnd(); ++it) {
158 KConfig config(*it, KConfig::SimpleConfig);
159
160 if (!(config.hasGroup("KDE") && config.hasGroup("Misc")))
161 continue;
162
163 if (config.group("Desktop Entry").readEntry("Hidden" , false))
164 continue;
165
166 QString str2 = config.group("KDE").readEntry("WidgetStyle");
167 if (str2.isNull())
168 continue;
169
170 combo->insertItem(str2, config.group("Misc").readEntry("Name"));
171 }
172}
173
174void KDMGeneralWidget::set_def()
175{
176 stdFontChooser->setFont(QFont("Sans Serif", 10));
177 failFontChooser->setFont(QFont("Sans Serif", 10, QFont::Bold));
178 greetingFontChooser->setFont(QFont("Serif", 20));
179}
180
181void KDMGeneralWidget::save()
182{
183 KConfigGroup configGrp = config->group("X-*-Greeter");
184
185 configGrp.writeEntry("UseTheme", useThemeCheck->isChecked());
186 configGrp.writeEntry("GUIStyle", guicombo->currentId());
187 configGrp.writeEntry("ColorScheme", colcombo->currentId());
188 configGrp.writeEntry("Language", langcombo->current());
189 configGrp.writeEntry("StdFont", stdFontChooser->font());
190 configGrp.writeEntry("GreetFont", greetingFontChooser->font());
191 configGrp.writeEntry("FailFont", failFontChooser->font());
192 configGrp.writeEntry("AntiAliasing", aacb->isChecked());
193}
194
195
196void KDMGeneralWidget::load()
197{
198 set_def();
199
200 KConfigGroup configGrp = config->group("X-*-Greeter");
201
202 useThemeCheck->setChecked(configGrp.readEntry("UseTheme", false));
203
204 // Check the GUI type
205 guicombo->setCurrentId(configGrp.readEntry("GUIStyle"));
206
207 // Check the Color Scheme
208 colcombo->setCurrentId(configGrp.readEntry("ColorScheme"));
209
210 // get the language
211 langcombo->setCurrentItem(configGrp.readEntry("Language", "C"));
212
213 // Read the fonts
214 QFont font = stdFontChooser->font();
215 stdFontChooser->setFont(configGrp.readEntry("StdFont", font));
216 font = failFontChooser->font();
217 failFontChooser->setFont(configGrp.readEntry("FailFont", font));
218 font = greetingFontChooser->font();
219 greetingFontChooser->setFont(configGrp.readEntry("GreetFont", font));
220
221 aacb->setChecked(configGrp.readEntry("AntiAliasing", false));
222}
223
224
225void KDMGeneralWidget::defaults()
226{
227 useThemeCheck->setChecked(true);
228 guicombo->setCurrentId("");
229 colcombo->setCurrentId("");
230 langcombo->setCurrentItem("en_US");
231 set_def();
232 aacb->setChecked(false);
233}
234
235void KDMGeneralWidget::slotUseThemeChanged()
236{
237 bool en = useThemeCheck->isChecked();
238 failFontChooser->setEnabled(!en);
239 greetingFontChooser->setEnabled(!en);
240 emit useThemeChanged(en);
241 emit changed();
242}
243
244#include "kdm-gen.moc"
245