2 Copyright (C) 2000 Oswald Buddenhagen <ossi@kde.org>
3 Based on several other files.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
23 #include <KColorScheme>
28 #include <KConfigGroup>
30 #include <QButtonGroup>
34 #include <QListWidget>
35 #include <QRadioButton>
36 #include <QGridLayout>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
40 extern KConfig
*config
;
43 KDMConvenienceWidget::KDMConvenienceWidget( QWidget
*parent
)
48 QLabel
*paranoia
= new QLabel(
49 i18n("<big><b><center>Attention<br/>"
50 "Read help</center></b></big>"), this );
52 p
.setBrush( QPalette::WindowText
,
53 KColorScheme( QPalette::Active
, KColorScheme::Window
)
54 .foreground( KColorScheme::NegativeText
) );
55 paranoia
->setPalette( p
);
57 QSizePolicy
vpref( QSizePolicy::Minimum
, QSizePolicy::Fixed
);
59 alGroup
= new QGroupBox( i18n("Enable Au&to-Login"), this );
60 alGroup
->setCheckable( true );
61 alGroup
->setSizePolicy( vpref
);
62 QVBoxLayout
*laygroup2
= new QVBoxLayout( alGroup
);
63 laygroup2
->setSpacing( KDialog::spacingHint() );
65 alGroup
->setWhatsThis( i18n("Turn on the auto-login feature."
66 " This applies only to KDM's graphical login."
67 " Think twice before enabling this!") );
68 connect( alGroup
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
70 userlb
= new KComboBox( alGroup
);
72 QLabel
* u_label
= new QLabel( i18n("Use&r:"), alGroup
);
73 u_label
->setBuddy( userlb
);
74 QHBoxLayout
*hlpl1
= new QHBoxLayout();
75 laygroup2
->addItem( hlpl1
);
76 hlpl1
->setSpacing( KDialog::spacingHint() );
77 hlpl1
->addWidget( u_label
);
78 hlpl1
->addWidget( userlb
);
79 hlpl1
->addStretch( 1 );
80 connect( userlb
, SIGNAL(highlighted( int )), SIGNAL(changed()) );
81 wtstr
= i18n("Select the user to be logged in automatically.");
82 u_label
->setWhatsThis( wtstr
);
83 userlb
->setWhatsThis( wtstr
);
84 autoLockCheck
= new QCheckBox( i18n("Loc&k session"), alGroup
);
85 laygroup2
->addWidget( autoLockCheck
);
86 connect( autoLockCheck
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
87 autoLockCheck
->setWhatsThis( i18n(
88 "The automatically started session "
89 "will be locked immediately (provided it is a KDE session). This can "
90 "be used to obtain a super-fast login restricted to one user.") );
92 puGroup
= new QGroupBox( i18nc("@title:group", "Preselect User"), this );
94 puGroup
->setSizePolicy( vpref
);
96 npRadio
= new QRadioButton( i18nc("@option:radio preselected user", "&None"), puGroup
);
97 ppRadio
= new QRadioButton( i18nc("@option:radio preselected user", "Prev&ious"), puGroup
);
98 ppRadio
->setWhatsThis( i18n(
99 "Preselect the user that logged in previously. "
100 "Use this if this computer is usually used several consecutive times by one user.") );
101 spRadio
= new QRadioButton( i18nc("@option:radio preselected user", "Specif&y"), puGroup
);
102 spRadio
->setWhatsThis( i18n(
103 "Preselect the user specified in the combo box below. "
104 "Use this if this computer is predominantly used by a certain user.") );
105 QButtonGroup
*buttonGroup
= new QButtonGroup( puGroup
);
106 connect( buttonGroup
, SIGNAL(buttonClicked( int )), SLOT(slotPresChanged()) );
107 connect( buttonGroup
, SIGNAL(buttonClicked( int )), SIGNAL(changed()) );
108 buttonGroup
->addButton( npRadio
);
109 buttonGroup
->addButton( ppRadio
);
110 buttonGroup
->addButton( spRadio
);
111 QVBoxLayout
*laygroup5
= new QVBoxLayout( puGroup
);
112 laygroup5
->setSpacing( KDialog::spacingHint() );
113 laygroup5
->addWidget( npRadio
);
114 laygroup5
->addWidget( ppRadio
);
116 puserlb
= new KComboBox( true, puGroup
);
118 pu_label
= new QLabel( i18n("Us&er:"), puGroup
);
119 pu_label
->setBuddy( puserlb
);
120 connect( puserlb
, SIGNAL(editTextChanged( const QString
& )), SIGNAL(changed()) );
122 "Select the user to be preselected for login. "
123 "This box is editable, so you can specify an arbitrary non-existent "
124 "user to mislead possible attackers.");
125 pu_label
->setWhatsThis( wtstr
);
126 puserlb
->setWhatsThis( wtstr
);
127 QBoxLayout
*hlpl
= new QHBoxLayout();
128 laygroup5
->addItem( hlpl
);
129 hlpl
->setSpacing( KDialog::spacingHint() );
130 hlpl
->setMargin( 0 );
131 hlpl
->addWidget( spRadio
);
132 hlpl
->addWidget( pu_label
);
133 hlpl
->addWidget( puserlb
);
134 hlpl
->addStretch( 1 );
135 cbjumppw
= new QCheckBox( i18nc("@option:check action", "Focus pass&word"), puGroup
);
136 laygroup5
->addWidget( cbjumppw
);
137 cbjumppw
->setWhatsThis( i18n(
138 "When this option is on, KDM will place the cursor "
139 "in the password field instead of the user field after preselecting a user. "
140 "Use this to save one key press per login, if the preselection usually "
141 "does not need to be changed.") );
142 connect( cbjumppw
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
144 npGroup
= new QGroupBox( i18n("Enable Password-&Less Logins"), this );
145 QVBoxLayout
*laygroup3
= new QVBoxLayout( npGroup
);
146 laygroup3
->setSpacing( KDialog::spacingHint() );
148 npGroup
->setCheckable( true );
150 npGroup
->setWhatsThis( i18n(
151 "When this option is checked, the checked users from "
152 "the list below will be allowed to log in without entering their "
153 "password. This applies only to KDM's graphical login. "
154 "Think twice before enabling this!") );
156 connect( npGroup
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
158 QLabel
*pl_label
= new QLabel( i18n("No password re&quired for:"), npGroup
);
159 laygroup3
->addWidget( pl_label
);
160 npuserlv
= new QListWidget( npGroup
);
161 laygroup3
->addWidget( npuserlv
);
162 pl_label
->setBuddy( npuserlv
);
163 npuserlv
->setWhatsThis( i18n(
164 "Check all users you want to allow a password-less login for. "
165 "Entries denoted with '@' are user groups. Checking a group is like "
166 "checking all users in that group.") );
168 btGroup
= new QGroupBox( i18nc("@title:group", "Miscellaneous"), this );
169 QVBoxLayout
*laygroup4
= new QVBoxLayout( btGroup
);
170 laygroup4
->setSpacing( KDialog::spacingHint() );
172 cbarlen
= new QCheckBox( i18n("Automatically log in again after &X server crash"), btGroup
);
173 cbarlen
->setWhatsThis( i18n(
174 "When this option is on, a user will be "
175 "logged in again automatically when their session is interrupted by an "
176 "X server crash; note that this can open a security hole: if you use "
177 "a screen locker than KDE's integrated one, this will make "
178 "circumventing a password-secured screen lock possible.") );
179 //TODO a screen locker _other_ than
180 laygroup4
->addWidget( cbarlen
);
181 connect( cbarlen
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
183 QGridLayout
*main
= new QGridLayout( this );
184 main
->setSpacing( 10 );
185 main
->addWidget( paranoia
, 0, 0 );
186 main
->addWidget( alGroup
, 1, 0 );
187 main
->addWidget( puGroup
, 2, 0 );
188 main
->addWidget( npGroup
, 0, 1, 4, 1 );
189 main
->addWidget( btGroup
, 4, 0, 1, 2 );
190 main
->setColumnStretch( 0, 1 );
191 main
->setColumnStretch( 1, 2 );
192 main
->setRowStretch( 3, 1 );
194 connect( userlb
, SIGNAL(activated( const QString
& )),
195 SLOT(slotSetAutoUser( const QString
& )) );
196 connect( puserlb
, SIGNAL(editTextChanged( const QString
& )),
197 SLOT(slotSetPreselUser( const QString
& )) );
198 connect( npuserlv
, SIGNAL(itemClicked( QListWidgetItem
* )),
199 SLOT(slotUpdateNoPassUser( QListWidgetItem
* )) );
203 void KDMConvenienceWidget::makeReadOnly()
205 alGroup
->setEnabled( false ); // this sucks
206 //userlb->setEnabled( false );
207 //autoLockCheck->setEnabled( false );
208 npGroup
->setEnabled( false ); // this sucks, too
209 //npuserlv->setEnabled( false );
210 cbarlen
->setEnabled( false );
211 npRadio
->setEnabled( false );
212 ppRadio
->setEnabled( false );
213 spRadio
->setEnabled( false );
214 puserlb
->setEnabled( false );
215 cbjumppw
->setEnabled( false );
218 void KDMConvenienceWidget::slotPresChanged()
220 bool en
= spRadio
->isChecked();
221 pu_label
->setEnabled( en
);
222 if (!alGroup
->isEnabled()) // read-only
224 puserlb
->setEnabled( en
);
225 cbjumppw
->setEnabled( !npRadio
->isChecked() );
228 void KDMConvenienceWidget::save()
230 KConfigGroup configGrp
= config
->group( "X-:0-Core" );
231 configGrp
.writeEntry( "AutoLoginEnable", alGroup
->isChecked() );
232 configGrp
.writeEntry( "AutoLoginUser", userlb
->currentText() );
233 configGrp
.writeEntry( "AutoLoginLocked", autoLockCheck
->isChecked() );
235 configGrp
= config
->group( "X-:*-Core" );
236 configGrp
.writeEntry( "NoPassEnable", npGroup
->isChecked() );
237 configGrp
.writeEntry( "NoPassUsers", noPassUsers
);
239 config
->group( "X-*-Core" ).writeEntry( "AutoReLogin", cbarlen
->isChecked() );
241 configGrp
= config
->group( "X-:*-Greeter" );
242 configGrp
.writeEntry( "PreselectUser",
243 npRadio
->isChecked() ? "None" :
244 ppRadio
->isChecked() ? "Previous" :
246 configGrp
.writeEntry( "DefaultUser", puserlb
->currentText() );
247 configGrp
.writeEntry( "FocusPasswd", cbjumppw
->isChecked() );
251 void KDMConvenienceWidget::load()
253 KConfigGroup configGrp
= config
->group( "X-:0-Core" );
254 bool alenable
= configGrp
.readEntry( "AutoLoginEnable", false );
255 autoUser
= configGrp
.readEntry( "AutoLoginUser" );
256 autoLockCheck
->setChecked( configGrp
.readEntry( "AutoLoginLocked", false ) );
257 if (autoUser
.isEmpty())
259 alGroup
->setChecked( alenable
);
261 configGrp
= config
->group( "X-:*-Core" );
262 npGroup
->setChecked( configGrp
.readEntry( "NoPassEnable", false ) );
263 noPassUsers
= configGrp
.readEntry( "NoPassUsers", QStringList() );
265 cbarlen
->setChecked( config
->group( "X-*-Core" ).readEntry( "AutoReLogin", false ) );
267 configGrp
= config
->group( "X-:*-Greeter" );
268 QString presstr
= configGrp
.readEntry( "PreselectUser", "None" );
269 if (presstr
== "Previous")
270 ppRadio
->setChecked( true );
271 else if (presstr
== "Default")
272 spRadio
->setChecked( true );
274 npRadio
->setChecked( true );
275 preselUser
= configGrp
.readEntry( "DefaultUser" );
276 cbjumppw
->setChecked( configGrp
.readEntry( "FocusPasswd", false ) );
282 void KDMConvenienceWidget::defaults()
284 alGroup
->setChecked( false );
285 autoLockCheck
->setChecked( false );
286 npRadio
->setChecked( true );
287 npGroup
->setChecked( false );
288 cbarlen
->setChecked( false );
289 cbjumppw
->setChecked( false );
298 void KDMConvenienceWidget::slotSetAutoUser( const QString
&user
)
303 void KDMConvenienceWidget::slotSetPreselUser( const QString
&user
)
308 void KDMConvenienceWidget::slotUpdateNoPassUser( QListWidgetItem
*item
)
312 int ind
= noPassUsers
.indexOf( item
->text() );
313 if (item
->checkState() == Qt::Checked
) {
315 noPassUsers
.append( item
->text() );
320 noPassUsers
.removeAt( ind
);
326 void KDMConvenienceWidget::slotClearUsers()
331 if (!autoUser
.isEmpty())
332 userlb
->addItem( autoUser
);
333 if (!preselUser
.isEmpty())
334 puserlb
->addItem( preselUser
);
337 void KDMConvenienceWidget::slotAddUsers( const QMap
<QString
,int> &users
)
339 QMap
<QString
,int>::const_iterator it
;
340 for (it
= users
.begin(); it
!= users
.end(); ++it
) {
341 if (it
.value() > 0) {
342 if (it
.key() != autoUser
)
343 userlb
->addItem( it
.key() );
344 if (it
.key() != preselUser
)
345 puserlb
->addItem( it
.key() );
347 if (it
.value() != 0) {
348 QListWidgetItem
*item
= new QListWidgetItem( it
.key(), npuserlv
);
349 item
->setFlags( Qt::ItemIsSelectable
| Qt::ItemIsEnabled
|
350 Qt::ItemIsUserCheckable
);
351 item
->setCheckState( noPassUsers
.contains( it
.key() ) ?
352 Qt::Checked
: Qt::Unchecked
);
357 userlb
->model()->sort( 0 );
359 if (puserlb
->model())
360 puserlb
->model()->sort( 0 );
362 npuserlv
->sortItems();
364 userlb
->setCurrentItem( autoUser
);
365 puserlb
->setCurrentItem( preselUser
);
368 void KDMConvenienceWidget::slotDelUsers( const QMap
<QString
,int> &users
)
370 QMap
<QString
,int>::const_iterator it
;
371 for (it
= users
.begin(); it
!= users
.end(); ++it
) {
372 if (it
.value() > 0) {
373 int idx
= userlb
->findText( it
.key() );
374 if (it
.key() != autoUser
&& idx
!= -1)
375 userlb
->removeItem( idx
);
376 idx
= puserlb
->findText( it
.key() );
377 if (it
.key() != preselUser
&& idx
!= -1)
378 puserlb
->removeItem( idx
);
381 delete npuserlv
->findItems( it
.key(), Qt::MatchExactly
).first();
385 #include "kdm-conv.moc"