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.
28 #include <KConfigGroup>
30 #include <QButtonGroup>
34 #include <QRadioButton>
35 #include <QGridLayout>
36 #include <QHBoxLayout>
37 #include <QVBoxLayout>
38 #include <Qt3Support/Q3Header>
40 extern KConfig
*config
;
42 KDMConvenienceWidget::KDMConvenienceWidget( QWidget
*parent
)
47 QLabel
*paranoia
= new QLabel(
48 i18n("<big style='color:red;text-align:center;font-weight:bold;'>Attention<br/>"
49 "Read help</big>"), this );
51 QSizePolicy
vpref( QSizePolicy::Minimum
, QSizePolicy::Fixed
);
53 alGroup
= new QGroupBox( i18n("Enable Au&to-Login"), this );
54 alGroup
->setCheckable( true );
55 alGroup
->setSizePolicy( vpref
);
56 QVBoxLayout
*laygroup2
= new QVBoxLayout( alGroup
);
57 laygroup2
->setSpacing( KDialog::spacingHint() );
59 alGroup
->setWhatsThis( i18n("Turn on the auto-login feature."
60 " This applies only to KDM's graphical login."
61 " Think twice before enabling this!") );
62 connect( alGroup
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
64 userlb
= new KComboBox( alGroup
);
65 u_label
= new QLabel( i18n("Use&r:"), alGroup
);
66 u_label
->setBuddy( userlb
);
67 QHBoxLayout
*hlpl1
= new QHBoxLayout();
68 laygroup2
->addItem( hlpl1
);
69 hlpl1
->setSpacing( KDialog::spacingHint() );
70 hlpl1
->addWidget( u_label
);
71 hlpl1
->addWidget( userlb
);
72 hlpl1
->addStretch( 1 );
73 connect( userlb
, SIGNAL(highlighted( int )), SIGNAL(changed()) );
74 wtstr
= i18n("Select the user to be logged in automatically.");
75 u_label
->setWhatsThis( wtstr
);
76 userlb
->setWhatsThis( wtstr
);
77 autoLockCheck
= new QCheckBox( i18n("Loc&k session"), alGroup
);
78 laygroup2
->addWidget( autoLockCheck
);
79 connect( autoLockCheck
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
80 autoLockCheck
->setWhatsThis( i18n("The automatically started session "
81 "will be locked immediately (provided it is a KDE session). This can "
82 "be used to obtain a super-fast login restricted to one user.") );
84 puGroup
= new QGroupBox( i18n("Preselect User"), this );
86 puGroup
->setSizePolicy( vpref
);
88 npRadio
= new QRadioButton( i18nc("preselected user", "&None"), puGroup
);
89 ppRadio
= new QRadioButton( i18n("Prev&ious"), puGroup
);
90 ppRadio
->setWhatsThis( i18n("Preselect the user that logged in previously. "
91 "Use this if this computer is usually used several consecutive times by one user.") );
92 spRadio
= new QRadioButton( i18n("Specif&y"), puGroup
);
93 spRadio
->setWhatsThis( i18n("Preselect the user specified in the combo box below. "
94 "Use this if this computer is predominantly used by a certain user.") );
95 QButtonGroup
*buttonGroup
= new QButtonGroup( puGroup
);
96 connect( buttonGroup
, SIGNAL(buttonClicked( int )), SLOT(slotPresChanged()) );
97 connect( buttonGroup
, SIGNAL(buttonClicked( int )), SIGNAL(changed()) );
98 buttonGroup
->addButton( npRadio
);
99 buttonGroup
->addButton( ppRadio
);
100 buttonGroup
->addButton( spRadio
);
101 QVBoxLayout
*laygroup5
= new QVBoxLayout( puGroup
);
102 laygroup5
->setSpacing( KDialog::spacingHint() );
103 laygroup5
->addWidget( npRadio
);
104 laygroup5
->addWidget( ppRadio
);
105 laygroup5
->addWidget( spRadio
);
107 puserlb
= new KComboBox( true, puGroup
);
109 pu_label
= new QLabel( i18n("Us&er:"), puGroup
);
110 pu_label
->setBuddy( puserlb
);
111 connect( puserlb
, SIGNAL(textChanged( const QString
& )), SIGNAL(changed()) );
112 wtstr
= i18n("Select the user to be preselected for login. "
113 "This box is editable, so you can specify an arbitrary non-existent "
114 "user to mislead possible attackers.");
115 pu_label
->setWhatsThis( wtstr
);
116 puserlb
->setWhatsThis( wtstr
);
117 QBoxLayout
*hlpl
= new QHBoxLayout();
118 laygroup5
->addItem( hlpl
);
119 hlpl
->setSpacing( KDialog::spacingHint() );
120 hlpl
->setMargin( 0 );
121 hlpl
->addWidget( pu_label
);
122 hlpl
->addWidget( puserlb
);
123 hlpl
->addStretch( 1 );
124 cbjumppw
= new QCheckBox( i18n("Focus pass&word"), puGroup
);
125 laygroup5
->addWidget( cbjumppw
);
126 cbjumppw
->setWhatsThis( i18n("When this option is on, KDM will place the cursor "
127 "in the password field instead of the user field after preselecting a user. "
128 "Use this to save one key press per login, if the preselection usually does not need to "
130 connect( cbjumppw
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
132 npGroup
= new QGroupBox( i18n("Enable Password-&Less Logins"), this );
133 QVBoxLayout
*laygroup3
= new QVBoxLayout( npGroup
);
134 laygroup3
->setSpacing( KDialog::spacingHint() );
136 npGroup
->setCheckable( true );
138 npGroup
->setWhatsThis( i18n("When this option is checked, the checked users from"
139 " the list below will be allowed to log in without entering their"
140 " password. This applies only to KDM's graphical login."
141 " Think twice before enabling this!") );
143 connect( npGroup
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
145 pl_label
= new QLabel( i18n("No password re&quired for:"),npGroup
);
146 laygroup3
->addWidget( pl_label
);
147 npuserlv
= new K3ListView( npGroup
);
148 laygroup3
->addWidget( npuserlv
);
149 pl_label
->setBuddy( npuserlv
);
150 npuserlv
->addColumn( QString() );
151 npuserlv
->header()->hide();
152 npuserlv
->setResizeMode( Q3ListView::LastColumn
);
153 npuserlv
->setWhatsThis( i18n("Check all users you want to allow a password-less login for."
154 " Entries denoted with '@' are user groups. Checking a group is like checking all users in that group.") );
155 connect( npuserlv
, SIGNAL(clicked( Q3ListViewItem
* )),
158 btGroup
= new QGroupBox( i18n("Miscellaneous"), this );
159 QVBoxLayout
*laygroup4
= new QVBoxLayout( btGroup
);
160 laygroup4
->setSpacing( KDialog::spacingHint() );
162 cbarlen
= new QCheckBox( i18n("Automatically log in again after &X server crash"), btGroup
);
163 cbarlen
->setWhatsThis( i18n("When this option is on, a user will be"
164 " logged in again automatically when their session is interrupted by an"
165 " X server crash; note that this can open a security hole: if you use"
166 " a screen locker than KDE's integrated one, this will make"
167 " circumventing a password-secured screen lock possible.") );
168 laygroup4
->addWidget( cbarlen
);
169 connect( cbarlen
, SIGNAL(toggled( bool )), SIGNAL(changed()) );
171 QGridLayout
*main
= new QGridLayout( this );
172 main
->setSpacing( 10 );
173 main
->addWidget( paranoia
, 0, 0 );
174 main
->addWidget( alGroup
, 1, 0 );
175 main
->addWidget( puGroup
, 2, 0 );
176 main
->addWidget( npGroup
, 0, 1, 4, 1 );
177 main
->addWidget( btGroup
, 4, 0, 1, 2 );
178 main
->setColumnStretch( 0, 1 );
179 main
->setColumnStretch( 1, 2 );
180 main
->setRowStretch( 3, 1 );
182 connect( userlb
, SIGNAL(activated( const QString
& )),
183 SLOT(slotSetAutoUser( const QString
& )) );
184 connect( puserlb
, SIGNAL(textChanged( const QString
& )),
185 SLOT(slotSetPreselUser( const QString
& )) );
186 connect( npuserlv
, SIGNAL(clicked( Q3ListViewItem
* )),
187 SLOT(slotUpdateNoPassUser( Q3ListViewItem
* )) );
191 void KDMConvenienceWidget::makeReadOnly()
193 alGroup
->setEnabled( false ); // this sucks
194 //userlb->setEnabled( false );
195 //autoLockCheck->setEnabled( false );
196 npGroup
->setEnabled( false ); // this sucks, too
197 //npuserlv->setEnabled( false );
198 cbarlen
->setEnabled( false );
199 npRadio
->setEnabled( false );
200 ppRadio
->setEnabled( false );
201 spRadio
->setEnabled( false );
202 puserlb
->setEnabled( false );
203 cbjumppw
->setEnabled( false );
206 void KDMConvenienceWidget::slotPresChanged()
208 bool en
= spRadio
->isChecked();
209 pu_label
->setEnabled( en
);
210 puserlb
->setEnabled( en
);
211 cbjumppw
->setEnabled( !npRadio
->isChecked() );
214 void KDMConvenienceWidget::save()
216 KConfigGroup configGrp
= config
->group( "X-:0-Core" );
217 configGrp
.writeEntry( "AutoLoginEnable", alGroup
->isChecked() );
218 configGrp
.writeEntry( "AutoLoginUser", userlb
->currentText() );
219 configGrp
.writeEntry( "AutoLoginLocked", autoLockCheck
->isChecked() );
221 configGrp
= config
->group( "X-:*-Core" );
222 configGrp
.writeEntry( "NoPassEnable", npGroup
->isChecked() );
223 configGrp
.writeEntry( "NoPassUsers", noPassUsers
);
225 config
->group("X-*-Core").writeEntry( "AutoReLogin", cbarlen
->isChecked() );
227 configGrp
= config
->group( "X-:*-Greeter" );
228 configGrp
.writeEntry( "PreselectUser",
229 npRadio
->isChecked() ? "None" :
230 ppRadio
->isChecked() ? "Previous" :
232 configGrp
.writeEntry( "DefaultUser", puserlb
->currentText() );
233 configGrp
.writeEntry( "FocusPasswd", cbjumppw
->isChecked() );
237 void KDMConvenienceWidget::load()
239 KConfigGroup configGrp
= config
->group( "X-:0-Core" );
240 bool alenable
= configGrp
.readEntry( "AutoLoginEnable", false );
241 autoUser
= configGrp
.readEntry( "AutoLoginUser" );
242 autoLockCheck
->setChecked( configGrp
.readEntry( "AutoLoginLocked", false ) );
243 if (autoUser
.isEmpty())
245 alGroup
->setChecked( alenable
);
247 configGrp
= config
->group( "X-:*-Core" );
248 npGroup
->setChecked( configGrp
.readEntry( "NoPassEnable", false ) );
249 noPassUsers
= configGrp
.readEntry( "NoPassUsers", QStringList() );
251 cbarlen
->setChecked( config
->group("X-*-Core").readEntry( "AutoReLogin", false ) );
253 configGrp
= config
->group( "X-:*-Greeter" );
254 QString presstr
= configGrp
.readEntry( "PreselectUser", "None" );
255 if (presstr
== "Previous")
256 ppRadio
->setChecked( true );
257 else if (presstr
== "Default")
258 spRadio
->setChecked( true );
260 npRadio
->setChecked( true );
261 preselUser
= configGrp
.readEntry( "DefaultUser" );
262 cbjumppw
->setChecked( configGrp
.readEntry( "FocusPasswd", false ) );
268 void KDMConvenienceWidget::defaults()
270 alGroup
->setChecked( false );
271 autoLockCheck
->setChecked( false );
272 npRadio
->setChecked( true );
273 npGroup
->setChecked( false );
274 cbarlen
->setChecked( false );
275 cbjumppw
->setChecked( false );
284 void KDMConvenienceWidget::slotSetAutoUser( const QString
&user
)
289 void KDMConvenienceWidget::slotSetPreselUser( const QString
&user
)
294 void KDMConvenienceWidget::slotUpdateNoPassUser( Q3ListViewItem
*item
)
298 Q3CheckListItem
*itm
= (Q3CheckListItem
*)item
;
299 int ind
= noPassUsers
.indexOf( itm
->text() );
302 noPassUsers
.append( itm
->text() );
305 noPassUsers
.removeAt( ind
);
309 void KDMConvenienceWidget::slotClearUsers()
314 if (!autoUser
.isEmpty())
315 userlb
->addItem( autoUser
);
316 if (!preselUser
.isEmpty())
317 puserlb
->addItem( preselUser
);
320 void KDMConvenienceWidget::slotAddUsers( const QMap
<QString
,int> &users
)
322 QMap
<QString
,int>::const_iterator it
;
323 for (it
= users
.begin(); it
!= users
.end(); ++it
) {
324 if (it
.value() > 0) {
325 if (it
.key() != autoUser
)
326 userlb
->addItem( it
.key() );
327 if (it
.key() != preselUser
)
328 puserlb
->addItem( it
.key() );
331 (new Q3CheckListItem( npuserlv
, it
.key(), Q3CheckListItem::CheckBox
))->
332 setOn( noPassUsers
.contains( it
.key() ) );
336 userlb
->model()->sort( 0 );
338 if (puserlb
->model())
339 puserlb
->model()->sort( 0 );
342 userlb
->setCurrentItem( autoUser
);
343 puserlb
->setCurrentItem( preselUser
);
346 void KDMConvenienceWidget::slotDelUsers( const QMap
<QString
,int> &users
)
348 QMap
<QString
,int>::const_iterator it
;
349 for (it
= users
.begin(); it
!= users
.end(); ++it
) {
350 if (it
.value() > 0) {
351 int idx
= userlb
->findText( it
.key() );
352 if (it
.key() != autoUser
&& idx
!= -1)
353 userlb
->removeItem( idx
);
354 idx
= puserlb
->findText( it
.key() );
355 if (it
.key() != preselUser
&& idx
!= -1)
356 puserlb
->removeItem( idx
);
359 delete npuserlv
->findItem( it
.key(), 0 );
363 #include "kdm-conv.moc"