2 * Copyright (c) 1998 Denis Perchine <dyp@perchine.com>
3 * Copyright (c) 2004 Szombathelyi GyĂśrgy <gyurco@freemail.hu>
4 * Former maintainer: Adriaan de Groot <groot@kde.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License version 2 or at your option version 3 as published by
9 * the Free Software Foundation.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
28 #include <QGridLayout>
30 #include <kseparator.h>
31 #include <kmessagebox.h>
36 #include "ku_edituser.h"
38 #include "ku_global.h"
41 void KU_EditUser::addRow(QWidget
*parent
, QGridLayout
*layout
, int row
,
42 QWidget
*widget
, const QString
&label
, const QString
&what
,
43 bool two_column
, bool nochange
)
45 QLabel
*lab
= new QLabel( label
, parent
);
46 lab
->setBuddy( widget
);
47 lab
->setMinimumSize(lab
->sizeHint());
48 widget
->setMinimumSize(widget
->sizeHint());
49 layout
->addWidget(lab
, row
, 0);
52 lab
->setWhatsThis( what
);
53 widget
->setWhatsThis( what
);
56 layout
->addWidget( widget
, row
, 1, 1, 2 );
58 layout
->addWidget(widget
, row
, 1);
60 if ( !nochange
|| ro
) return;
61 QCheckBox
*nc
= new QCheckBox( i18n("Do not change"), parent
);
62 layout
->addWidget( nc
, row
, 3 );
64 mNoChanges
[ widget
] = nc
;
67 KIntSpinBox
*KU_EditUser::addDaysGroup(QWidget
*parent
, QGridLayout
*layout
, int row
,
68 const QString
&title
, bool never
)
72 QLabel
*label
= new QLabel( title
, parent
);
73 layout
->addWidget( label
, row
, 0, 1, 2, Qt::AlignRight
);
75 days
= new KIntSpinBox( parent
);
76 label
->setBuddy( days
);
77 days
->setSuffix( i18n(" days") );
78 days
->setMaximum( 99999 );
81 days
->setMinimum( -1 );
82 days
->setSpecialValueText(i18n("Never"));
86 days
->setMinimum( 0 );
88 layout
->addWidget( days
, row
, 2 );
90 connect(days
, SIGNAL(valueChanged(int)), this, SLOT(changed()));
92 QCheckBox
*nc
= new QCheckBox( i18n("Do not change"), parent
);
93 layout
->addWidget( nc
, row
, 3 );
95 mNoChanges
[ days
] = nc
;
100 void KU_EditUser::initDlg()
102 ro
= KU_Global::users()->getCaps() & KU_Users::Cap_ReadOnly
;
108 QFrame
*frame
= new QFrame();
109 addPage(frame
, i18n("User Info"));
110 QGridLayout
*layout
= new QGridLayout( frame
);
114 frontlayout
= layout
;
116 lbuser
= new QLabel(frame
);
117 // whatstr = i18n("WHAT IS THIS: User login");
118 addRow(frame
, layout
, row
++, lbuser
, i18n("User login:"), whatstr
, false, false);
120 leid
= new KLineEdit(frame
);
121 // whatstr = i18n("WHAT IS THIS: User Id");
122 leid
->setValidator(new QIntValidator(frame
));
123 addRow(frame
, layout
, row
++, leid
, i18n("&User ID:"), whatstr
);
124 connect(leid
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
127 pbsetpwd
= new QPushButton(i18n("Set &Password..."), frame
);
128 layout
->addWidget(pbsetpwd
, 0, 2);
129 connect(pbsetpwd
, SIGNAL(clicked()), this, SLOT(setpwd()));
133 lefname
= new KLineEdit(frame
);
134 // whatstr = i18n("WHAT IS THIS: Full Name");
135 addRow(frame
, layout
, row
++, lefname
, i18n("Full &name:"), whatstr
);
136 connect(lefname
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
139 if ( KU_Global::users()->getCaps() & KU_Users::Cap_InetOrg
) {
140 lesurname
= new KLineEdit(frame
);
141 // whatstr = i18n("WHAT IS THIS: Surname");
142 addRow(frame
, layout
, row
++, lesurname
, i18n("Surname:"), whatstr
);
143 connect(lesurname
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
145 lemail
= new KLineEdit(frame
);
146 // whatstr = i18n("WHAT IS THIS: Email");
147 addRow(frame
, layout
, row
++, lemail
, i18n("Email address:"), whatstr
);
148 connect(lemail
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
151 leshell
= new KComboBox(true, frame
);
153 leshell
->insertItem( 0, i18n("<Empty>") );
155 QStringList shells
= readShells();
157 leshell
->insertItems( 1, shells
);
158 connect(leshell
, SIGNAL(activated(const QString
&)), this, SLOT(changed()));
159 connect(leshell
, SIGNAL(editTextChanged(const QString
&)), this, SLOT(changed()));
160 // whatstr = i18n("WHAT IS THIS: Login Shell");
161 addRow(frame
, layout
, row
++, leshell
, i18n("&Login shell:"), whatstr
);
163 lehome
= new KLineEdit(frame
);
164 connect(lehome
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
165 // whatstr = i18n("WHAT IS THIS: Home Directory");
166 addRow(frame
, layout
, row
++, lehome
, i18n("&Home folder:"), whatstr
);
168 // FreeBSD appears to use the comma separated fields in the GECOS entry
169 // differently than Linux.
170 if ( KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
171 leoffice
= new KLineEdit(frame
);
172 connect(leoffice
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
173 // whatstr = i18n("WHAT IS THIS: Office");
174 addRow(frame
, layout
, row
++, leoffice
, i18n("&Office:"), whatstr
);
176 leophone
= new KLineEdit(frame
);
177 connect(leophone
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
178 // whatstr = i18n("WHAT IS THIS: Office Phone");
179 addRow(frame
, layout
, row
++, leophone
, i18n("Offi&ce Phone:"), whatstr
);
181 lehphone
= new KLineEdit(frame
);
182 connect(lehphone
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
183 // whatstr = i18n("WHAT IS THIS: Home Phone");
184 addRow(frame
, layout
, row
++, lehphone
, i18n("Ho&me Phone:"), whatstr
);
186 leclass
= new KLineEdit(frame
);
187 connect(leclass
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
188 // whatstr = i18n("WHAT IS THIS: Login class");
189 addRow(frame
, layout
, row
++, leclass
, i18n("Login class:"), whatstr
, true);
191 leoffice1
= new KLineEdit(frame
);
192 connect(leoffice1
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
193 // whatstr = i18n("WHAT IS THIS: Office1");
194 addRow(frame
, layout
, row
++, leoffice1
, i18n("&Office #1:"), whatstr
);
196 leoffice2
= new KLineEdit(frame
);
197 connect(leoffice2
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
198 // whatstr = i18n("WHAT IS THIS: Office2");
199 addRow(frame
, layout
, row
++, leoffice2
, i18n("O&ffice #2:"), whatstr
);
201 leaddress
= new KLineEdit(frame
);
202 connect(leaddress
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
203 // whatstr = i18n("WHAT IS THIS: Address");
204 addRow(frame
, layout
, row
++, leaddress
, i18n("&Address:"), whatstr
);
206 cbdisabled
= new QCheckBox(frame
);
207 connect(cbdisabled
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
208 addRow(frame
, layout
, row
++, cbdisabled
, i18n("Account &disabled"), whatstr
);
210 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Disable_POSIX
) {
211 cbposix
= new QCheckBox(frame
);
212 connect(cbposix
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
213 connect(cbposix
, SIGNAL(stateChanged(int)), this, SLOT(cbposixChanged()));
214 addRow(frame
, layout
, row
++, cbposix
, i18n("Disable &POSIX account information"), whatstr
);
221 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
||
222 KU_Global::users()->getCaps() & KU_Users::Cap_Samba
||
223 KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
225 // Tab 2 : Password Management
226 QFrame
*frame
= new QFrame();
227 addPage(frame
, i18n("Password Management"));
228 QGridLayout
*layout
= new QGridLayout( frame
);
232 leslstchg
= new QLabel(frame
);
233 addRow(frame
, layout
, row
++, leslstchg
, i18n("Last password change:"), QString(), true);
235 layout
->addWidget(new KSeparator(Qt::Horizontal
, frame
), row
, 0, 1, 4);
238 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
) {
239 layout
->addWidget( new QLabel( i18n("POSIX parameters:"), frame
), row
++, 0 );
240 lesmin
= addDaysGroup(frame
, layout
, row
++, i18n("Time before password may ¬ be changed after last password change:"), false);
241 lesmax
= addDaysGroup(frame
, layout
, row
++, i18n("Time when password &expires after last password change:") );
242 leswarn
= addDaysGroup(frame
, layout
, row
++, i18n("Time before password expires to &issue an expire warning:"));
243 lesinact
= addDaysGroup(frame
, layout
, row
++, i18n("Time when account will be &disabled after expiration of password:"));
244 layout
->addWidget(new KSeparator(Qt::Horizontal
, frame
), row
, 0, 1, 4);
248 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba ) {
249 layout->addWidget( new QLabel( i18n("SAMBA parameters:"), frame ), row++, 0 );
250 layout->addMultiCellWidget(new KSeparator(Qt::Horizontal, frame), row, row, 0, 3);
254 QLabel
*label
= new QLabel( i18n("&Account will expire on:"), frame
);
255 layout
->addWidget( label
, row
, 0 );
256 lesexpire
= new KDateTimeWidget( frame
);
257 label
->setBuddy( lesexpire
);
258 layout
->addWidget( lesexpire
, row
, 1, 1, 2 );
260 cbexpire
= new QCheckBox( i18n("Never"), frame
);
261 layout
->addWidget( cbexpire
, row
++, 3 );
263 connect( lesexpire
, SIGNAL(valueChanged(const QDateTime
&)), this, SLOT(changed()) );
264 connect( cbexpire
, SIGNAL(stateChanged(int)), this, SLOT(changed()) );
265 connect( cbexpire
, SIGNAL(toggled(bool)), lesexpire
, SLOT(setDisabled(bool)) );
269 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
270 QFrame
*frame
= new QFrame();
271 addPage(frame
, i18n("Samba"));
272 QGridLayout
*layout
= new QGridLayout( frame
);
275 lerid
= new KLineEdit(frame
);
276 // whatstr = i18n("WHAT IS THIS: Rid");
277 lerid
->setValidator(new QIntValidator(frame
));
278 addRow(frame
, layout
, row
++, lerid
, i18n("RID:"), whatstr
);
279 connect(lerid
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
281 leliscript
= new KLineEdit(frame
);
282 // whatstr = i18n("WHAT IS THIS: Login script");
283 addRow(frame
, layout
, row
++, leliscript
, i18n("Login script:"), whatstr
);
284 connect(leliscript
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
286 leprofile
= new KLineEdit(frame
);
287 // whatstr = i18n("WHAT IS THIS: Login script");
288 addRow(frame
, layout
, row
++, leprofile
, i18n("Profile path:"), whatstr
);
289 connect(leprofile
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
291 lehomedrive
= new KLineEdit(frame
);
292 // whatstr = i18n("WHAT IS THIS: Login script");
293 addRow(frame
, layout
, row
++, lehomedrive
, i18n("Home drive:"), whatstr
);
294 connect(lehomedrive
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
296 lehomepath
= new KLineEdit(frame
);
297 // whatstr = i18n("WHAT IS THIS: Login script");
298 addRow(frame
, layout
, row
++, lehomepath
, i18n("Home path:"), whatstr
);
299 connect(lehomepath
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
301 leworkstations
= new KLineEdit(frame
);
302 // whatstr = i18n("WHAT IS THIS: Login script");
303 addRow(frame
, layout
, row
++, leworkstations
, i18n("User workstations:"), whatstr
);
304 connect(leworkstations
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
306 ledomain
= new KLineEdit(frame
);
307 // whatstr = i18n("WHAT IS THIS: Login script");
308 addRow(frame
, layout
, row
++, ledomain
, i18n("Domain name:"), whatstr
);
309 connect(ledomain
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
311 ledomsid
= new KLineEdit(frame
);
312 // whatstr = i18n("WHAT IS THIS: Login script");
313 addRow(frame
, layout
, row
++, ledomsid
, i18n("Domain SID:"), whatstr
);
314 connect(ledomsid
, SIGNAL(textChanged(const QString
&)), this, SLOT(changed()));
316 cbsamba
= new QCheckBox(frame
);
317 connect(cbsamba
, SIGNAL(stateChanged(int)), this, SLOT(changed()));
318 connect(cbsamba
, SIGNAL(stateChanged(int)), this, SLOT(cbsambaChanged()));
319 addRow(frame
, layout
, row
++, cbsamba
, i18n("Disable &Samba account information"), whatstr
);
324 QFrame
*frame
= new QFrame();
325 addPage(frame
, i18n("Groups"));
326 QGridLayout
*layout
= new QGridLayout( frame
);
328 lstgrp
= new QListWidget(frame
);
329 // lstgrp->setFullWidth(true); // Single column, full widget width.
330 // lstgrp->addColumn( i18n("Groups") );
331 if ( ro
) lstgrp
->setSelectionMode( QListWidget::NoSelection
);
332 // QString whatstr = i18n("Select the groups that this user belongs to.");
333 lstgrp
->setWhatsThis( whatstr
);
334 layout
->addWidget( lstgrp
, 0, 0, 1, 2 );
335 leprigr
= new QLabel( i18n("Primary group: "), frame
);
336 layout
->addWidget( leprigr
, 1, 0 );
338 pbprigr
= new QPushButton( i18n("Set as Primary"), frame
);
339 layout
->addWidget( pbprigr
, 1, 1 );
340 connect( pbprigr
, SIGNAL(clicked()), this, SLOT(setpgroup()) );
342 connect( lstgrp
, SIGNAL(itemClicked(QListWidgetItem
*)), this, SLOT(gchanged()) );
344 // connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) );
347 KU_EditUser::KU_EditUser( const QList
<int> &selected
,
352 setCaption(i18n("User Properties"));
353 setButtons( Ok
| Cancel
);
354 setDefaultButton(Ok
);
355 setFaceType(KPageDialog::Tabbed
);
356 mSelected
= selected
;
357 if ( mSelected
.count() > 1 )
358 setCaption( i18n("User Properties - %1 Selected Users", mSelected
.count() ) );
360 mUser
= KU_Global::users()->at( selected
[0] );
370 KU_EditUser::KU_EditUser( KU_User
&user
, bool fixedprivgroup
,
375 setCaption(i18n("User Properties"));
376 setButtons(Ok
| Cancel
);
377 setDefaultButton( Ok
);
379 setFaceType(KPageDialog::Tabbed
);
383 loadgroups( fixedprivgroup
);
389 KU_EditUser::~KU_EditUser()
393 void KU_EditUser::cbposixChanged()
395 bool posix
= !( cbposix
->checkState() == Qt::Checked
);
396 leid
->setEnabled( posix
&& mSelected
.isEmpty() );
397 leshell
->setEnabled( posix
);
398 lehome
->setEnabled( posix
);
399 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
) {
400 lesmin
->setEnabled( posix
);
401 lesmax
->setEnabled( posix
);
402 leswarn
->setEnabled( posix
);
403 lesinact
->setEnabled( posix
);
407 void KU_EditUser::cbsambaChanged()
409 bool samba
= !( cbsamba
->checkState() == Qt::Checked
);
410 lerid
->setEnabled( samba
&& mSelected
.isEmpty() );
411 leliscript
->setEnabled( samba
);
412 leprofile
->setEnabled( samba
);
413 lehomedrive
->setEnabled( samba
);
414 lehomepath
->setEnabled( samba
);
415 leworkstations
->setEnabled( samba
);
416 ledomain
->setEnabled( samba
);
417 ledomsid
->setEnabled( samba
);
420 void KU_EditUser::setLE( KLineEdit
*le
, const QString
&val
, bool first
)
424 if ( ro
) le
->setReadOnly( true );
427 if ( val
.isEmpty() && le
->text().isEmpty() ) return;
428 if ( le
->text() != val
) {
430 if ( !ro
&& mNoChanges
.contains( le
) ) {
431 mNoChanges
[ le
]->show();
432 mNoChanges
[ le
]->setChecked( true );
437 void KU_EditUser::setCB( QCheckBox
*cb
, bool val
, bool first
)
440 cb
->setChecked( val
);
441 if ( ro
) cb
->setEnabled( false );
444 if ( cb
->isChecked() != val
) {
446 cb
->setCheckState( Qt::PartiallyChecked
);
450 void KU_EditUser::setSB( KIntSpinBox
*sb
, int val
, bool first
)
454 if ( ro
) sb
->setEnabled( false );
457 if ( sb
->value() != val
) {
459 if ( !ro
&& mNoChanges
.contains( sb
) ) {
460 mNoChanges
[ sb
]->show();
461 mNoChanges
[ sb
]->setChecked( true );
466 void KU_EditUser::selectuser()
469 bool one
= mSelected
.isEmpty();
472 ismoreshells
= false;
473 user
= one
? mUser
: KU_Global::users()->at(mSelected
[0]);
474 olduid
= user
.getUID();
475 oldrid
= user
.getSID().getRID();
476 oldshell
= user
.getShell();
477 lstchg
= user
.getLastChange();
479 datetime
.setTime_t( lstchg
);
480 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
||
481 KU_Global::users()->getCaps() & KU_Users::Cap_Samba
||
482 KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
484 leslstchg
->setText( KGlobal::locale()->formatDateTime( datetime
, KLocale::LongDate
) );
488 lbuser
->setText( user
.getName() );
489 leid
->setText( QString::number( user
.getUID() ) );
490 if ( ro
) leid
->setReadOnly( true );
491 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
492 lerid
->setText( QString::number( user
.getSID().getRID() ) );
493 if ( ro
) lerid
->setReadOnly( true );
496 leid
->setEnabled( false );
497 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
498 lerid
->setEnabled( false );
501 if ( ro
) leshell
->setEditable( false );
505 first
= (index
== 0);
506 setLE( lefname
, user
.getFullName(), first
);
508 home
= user
.getHomeDir();
509 if ( !one
) home
.replace( user
.getName(), "%U", Qt::CaseInsensitive
);
510 setLE( lehome
, home
, first
);
512 QString shell
= user
.getShell();
514 if ( !shell
.isEmpty() ) {
516 for ( int i
=0; i
<leshell
->count(); i
++ )
517 if ( leshell
->itemText(i
) == shell
) {
519 leshell
->setCurrentIndex(i
);
523 leshell
->insertItem( leshell
->count(), shell
);
524 leshell
->setCurrentIndex( leshell
->count()-1 );
527 leshell
->setCurrentIndex( 0 );
529 if ( leshell
->currentText() != shell
) {
530 if ( !ismoreshells
) {
531 leshell
->insertItem( 0, i18n("Do Not Change") );
534 leshell
->setCurrentIndex( 0 );
538 setCB( cbdisabled
, user
.getDisabled(), first
);
539 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Disable_POSIX
) {
540 setCB( cbposix
, !(user
.getCaps() & KU_User::Cap_POSIX
), first
);
543 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
544 setLE( leliscript
, user
.getLoginScript(), first
);
546 profile
= user
.getProfilePath();
547 if ( !one
) profile
.replace( user
.getName(), "%U", Qt::CaseInsensitive
);
548 setLE( leprofile
, profile
, first
);
549 setLE( lehomedrive
, user
.getHomeDrive(), first
);
550 home
= user
.getHomePath();
551 if ( !one
) home
.replace( user
.getName(), "%U", Qt::CaseInsensitive
);
552 setLE( lehomepath
, home
, first
);
553 setLE( leworkstations
, user
.getWorkstations(), first
);
554 setLE( ledomain
, user
.getDomain(), first
);
555 setLE( ledomsid
, user
.getSID().getDOM(), first
);
556 setCB( cbsamba
, !(user
.getCaps() & KU_User::Cap_Samba
), first
);
559 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
||
560 KU_Global::users()->getCaps() & KU_Users::Cap_Samba
||
561 KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
563 if ( user
.getLastChange() != lstchg
) {
564 leslstchg
->setText( "" );
569 expire
.setTime_t( user
.getExpire() );
570 kDebug() << "expiration: " << user
.getExpire();
571 setCB( cbexpire
, (int) expire
.toTime_t() == -1, first
);
572 if ( (int) expire
.toTime_t() == -1 ) expire
.setTime_t( 0 );
574 lesexpire
->setDateTime( expire
);
576 if ( lesexpire
->dateTime() != expire
) {
577 expire
.setTime_t( 0 );
578 lesexpire
->setDateTime( expire
);
583 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
) {
584 setSB( lesmin
, user
.getMin(), first
);
585 setSB( lesmax
, user
.getMax(), first
);
586 setSB( leswarn
, user
.getWarn(), first
);
587 setSB( lesinact
, user
.getInactive(), first
);
590 if ( KU_Global::users()->getCaps() & KU_Users::Cap_InetOrg
) {
591 setLE( lesurname
, user
.getSurname(), first
);
592 setLE( lemail
, user
.getEmail(), first
);
594 if ( KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
595 setLE( leoffice
, user
.getOffice(), first
);
596 setLE( leophone
, user
.getWorkPhone(), first
);
597 setLE( lehphone
, user
.getHomePhone(), first
);
598 setLE( leclass
, user
.getClass(), first
);
600 setLE( leoffice1
, user
.getOffice1(), first
);
601 setLE( leoffice2
, user
.getOffice2(), first
);
602 setLE( leaddress
, user
.getAddress(), first
);
606 if ( index
== mSelected
.count() ) break;
607 user
= KU_Global::users()->at(mSelected
[index
++]);
611 void KU_EditUser::loadgroups( bool fixedprivgroup
)
613 bool wasprivgr
= false;
615 primaryGroupWasOn
= false;
617 for ( QList
<KU_Group
>::Iterator it
= KU_Global::groups()->begin();
618 it
!= KU_Global::groups()->end(); ++it
) {
619 QString groupName
= (*it
).getName();
620 QListWidgetItem
*item
= new QListWidgetItem(groupName
, lstgrp
);
621 item
->setFlags( Qt::ItemIsEnabled
| Qt::ItemIsSelectable
| Qt::ItemIsUserCheckable
);
623 KU_User user
= mSelected
.count() > 0 ?
624 KU_Global::users()->at(mSelected
[0]) : mUser
;
627 ( !fixedprivgroup
&& (*it
).getGID() == user
.getGID() ) ||
628 ( fixedprivgroup
&& groupName
== user
.getName() );
629 bool on
= (*it
).lookup_user( user
.getName() ) || prigr
;
632 item
->setFlags( item
->flags() & ~(Qt::ItemIsEnabled
| Qt::ItemIsUserCheckable
) );
634 primaryGroup
= groupName
;
636 if ( primaryGroup
!= groupName
) primaryGroup
= "";
637 // primaryGroupWasOn = group->lookup_user(user->getName());
642 item
->setCheckState( on
? Qt::Checked
: Qt::Unchecked
);
644 if ( item
->checkState() != ( on
? Qt::Checked
: Qt::Unchecked
) ) {
645 item
->setFlags( item
->flags() | Qt::ItemIsTristate
);
646 item
->setCheckState( Qt::PartiallyChecked
);
648 if ( index
== mSelected
.count() ) break;
649 kDebug() << "index: " << index
<< " count: " << mSelected
.count();
650 user
= KU_Global::users()->at(mSelected
[index
++]);
654 if ( fixedprivgroup
) {
655 KU_User user
= mSelected
.isEmpty() ? mUser
: KU_Global::users()->at(mSelected
[0]);
656 kDebug() << "privgroup: " << user
.getName();
658 QListWidgetItem
*item
= new QListWidgetItem(user
.getName(),lstgrp
);
659 item
->setCheckState( Qt::Checked
);
660 item
->setFlags( item
->flags() & ~(Qt::ItemIsEnabled
| Qt::ItemIsUserCheckable
) );
661 primaryGroup
= user
.getName();
664 leprigr
->setText( i18n("Primary group: ") + primaryGroup
);
667 void KU_EditUser::setpgroup()
670 QList
<QListWidgetItem
*> items
= lstgrp
->selectedItems();
671 if ( items
.isEmpty() ) return;
672 QListWidgetItem
*item
= items
[0];
674 if ( item
->text() == primaryGroup
) return;
676 bool prevPrimaryGroupWasOn
= primaryGroupWasOn
;
677 primaryGroup
= item
->text();
679 for ( int row
= 0; row
< lstgrp
->count(); row
++ ) {
681 item
= lstgrp
->item( row
);
682 QString groupName
= item
->text();
683 if ( !(item
->flags() & Qt::ItemIsEnabled
) )
685 item
->setFlags( item
->flags() | Qt::ItemIsEnabled
| Qt::ItemIsUserCheckable
);
686 item
->setCheckState(prevPrimaryGroupWasOn
? Qt::Checked
: Qt::Unchecked
);
688 if ( groupName
== primaryGroup
)
690 primaryGroupWasOn
= ( item
->checkState() == Qt::Checked
);
691 item
->setFlags( item
->flags() & ~(Qt::ItemIsEnabled
| Qt::ItemIsUserCheckable
) );
692 item
->setCheckState( Qt::Checked
);
695 leprigr
->setText( i18n("Primary group: ") + primaryGroup
);
698 void KU_EditUser::changed()
700 QWidget
*widget
= (QWidget
*) sender();
701 if ( mNoChanges
.contains( widget
) ) mNoChanges
[ widget
]->setChecked( false );
703 kDebug() << "changed";
706 void KU_EditUser::gchanged()
711 QString
KU_EditUser::mergeLE( KLineEdit
*le
, const QString
&val
, bool one
)
714 if ( mNoChanges
.contains( le
) ) cb
= mNoChanges
[ le
];
715 return ( one
|| ( cb
&& !cb
->isChecked() ) ) ? le
->text() : val
;
718 int KU_EditUser::mergeSB( KIntSpinBox
*sb
, int val
, bool one
)
721 if ( mNoChanges
.contains( sb
) ) cb
= mNoChanges
[ sb
];
722 return ( one
|| ( cb
&& !cb
->isChecked() ) ) ? sb
->value() : val
;
725 void KU_EditUser::mergeUser( const KU_User
&user
, KU_User
&newuser
)
729 bool one
= mSelected
.isEmpty();
730 bool posix
, samba
= false;
734 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Disable_POSIX
&& cbposix
->checkState() != Qt::PartiallyChecked
) {
735 if ( cbposix
->isChecked() )
736 newuser
.setCaps( newuser
.getCaps() & ~KU_User::Cap_POSIX
);
738 newuser
.setCaps( newuser
.getCaps() | KU_User::Cap_POSIX
);
740 posix
= newuser
.getCaps() & KU_User::Cap_POSIX
;
741 kDebug() << "posix: " << posix
;
743 newuser
.setName( lbuser
->text() );
744 newuser
.setUID( posix
? leid
->text().toInt() : 0 );
746 if ( !newpass
.isNull() ) {
747 KU_Global::users()->createPassword( newuser
, newpass
);
748 newuser
.setLastChange( lstchg
);
750 newuser
.setFullName( mergeLE( lefname
, user
.getFullName(), one
) );
751 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
752 if ( cbsamba
->checkState() != Qt::PartiallyChecked
) {
753 if ( cbsamba
->isChecked() )
754 newuser
.setCaps( newuser
.getCaps() & ~KU_User::Cap_Samba
);
756 newuser
.setCaps( newuser
.getCaps() | KU_User::Cap_Samba
);
758 samba
= newuser
.getCaps() & KU_User::Cap_Samba
;
759 kDebug() << "user : " << newuser
.getName() << " caps: " << newuser
.getCaps() << " samba: " << samba
;
763 sid
.setRID( one
? lerid
->text().toUInt() : user
.getSID().getRID() );
764 sid
.setDOM( mergeLE( ledomsid
, user
.getSID().getDOM(), one
) );
766 newuser
.setSID( sid
);
767 newuser
.setLoginScript( samba
?
768 mergeLE( leliscript
, user
.getLoginScript(), one
) : QString() );
769 newuser
.setProfilePath( samba
?
770 mergeLE( leprofile
, user
.getProfilePath(), one
).replace( "%U", newuser
.getName(), Qt::CaseInsensitive
) : QString() );
771 newuser
.setHomeDrive( samba
?
772 mergeLE( lehomedrive
, user
.getHomeDrive(), one
) : QString() );
773 newuser
.setHomePath( samba
?
774 mergeLE( lehomepath
, user
.getHomePath(), one
).replace( "%U", newuser
.getName(), Qt::CaseInsensitive
) : QString() );
775 newuser
.setWorkstations( samba
?
776 mergeLE( leworkstations
, user
.getWorkstations(), one
) : QString() );
777 newuser
.setDomain( samba
?
778 mergeLE( ledomain
, user
.getDomain(), one
) : QString() );
781 if ( KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
782 newuser
.setOffice( mergeLE( leoffice
, user
.getOffice(), one
) );
783 newuser
.setWorkPhone( mergeLE( leophone
, user
.getWorkPhone(), one
) );
784 newuser
.setHomePhone( mergeLE( lehphone
, user
.getHomePhone(), one
) );
785 newuser
.setClass( mergeLE( leclass
, user
.getClass(), one
) );
787 newuser
.setOffice1( mergeLE( leoffice1
, user
.getOffice1(), one
) );
788 newuser
.setOffice2( mergeLE( leoffice2
, user
.getOffice2(), one
) );
789 newuser
.setAddress( mergeLE( leaddress
, user
.getAddress(), one
) );
792 newuser
.setHomeDir( posix
?
793 mergeLE( lehome
, user
.getHomeDir(), one
).replace( "%U", newuser
.getName(), Qt::CaseInsensitive
) : QString() );
795 if ( leshell
->currentIndex() == 0 && ismoreshells
) {
796 newuser
.setShell( user
.getShell() );
798 ( leshell
->currentIndex() == 0 && !ismoreshells
) ||
799 ( leshell
->currentIndex() == 1 && ismoreshells
) ) {
801 newuser
.setShell( QString::null
); //krazy:exclude=nullstrassign for old broken gcc
803 // TODO: Check shell.
804 newuser
.setShell( leshell
->currentText() );
807 newuser
.setShell( QString::null
); //krazy:exclude=nullstrassign for old broken gcc
809 newuser
.setDisabled( (cbdisabled
->checkState() == Qt::PartiallyChecked
) ? user
.getDisabled() : cbdisabled
->isChecked() );
811 if ( KU_Global::users()->getCaps() & KU_Users::Cap_InetOrg
) {
812 newuser
.setSurname( mergeLE( lesurname
, user
.getSurname(), one
) );
813 newuser
.setEmail( mergeLE( lemail
, user
.getEmail(), one
) );
814 kDebug() << "surname: " << newuser
.getSurname() << " mail: " << newuser
.getEmail();
817 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
) {
818 newuser
.setMin( posix
? mergeSB( lesmin
, user
.getMin(), one
) : 0 );
819 newuser
.setMax( posix
? mergeSB( lesmax
, user
.getMax(), one
) : 0 );
820 newuser
.setWarn( posix
? mergeSB( leswarn
, user
.getWarn(), one
) : 0 );
821 newuser
.setInactive( posix
? mergeSB( lesinact
, user
.getInactive(), one
) : 0 );
824 if ( ( (KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
) && posix
) ||
825 ( (KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) && samba
) ||
826 ( (KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) && posix
) ) {
828 switch ( cbexpire
->checkState() ) {
829 case Qt::PartiallyChecked
:
830 newuser
.setExpire( user
.getExpire() );
833 newuser
.setExpire( -1 );
836 newuser
.setExpire( !one
&& lesexpire
->dateTime().toTime_t() == 0 ?
837 user
.getExpire() : lesexpire
->dateTime().toTime_t() );
841 newuser
.setExpire( -1 );
844 if ( !primaryGroup
.isEmpty() ) {
845 int index
= KU_Global::groups()->lookup( primaryGroup
);
847 KU_Group group
= KU_Global::groups()->at( index
);
848 newuser
.setGID( group
.getGID() );
849 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
850 newuser
.setPGSID( group
.getSID() );
856 bool KU_EditUser::saveg()
858 if ( !isgchanged
) return true;
860 for ( int row
= 0; row
< lstgrp
->count(); row
++ ) {
862 QListWidgetItem
*item
= lstgrp
->item( row
);
864 kDebug() << "saveg: group name: " << item
->text();
865 int grpindex
= KU_Global::groups()->lookup(item
->text());
866 if ( grpindex
!= -1 && item
->checkState() != Qt::PartiallyChecked
) {
868 KU_Group group
= KU_Global::groups()->at( grpindex
);
871 KU_User user
= mSelected
.isEmpty() ?
872 mUser
: KU_Global::users()->at(mSelected
[0]);
875 if ( item
->checkState() == Qt::Checked
&&
876 (( !primaryGroup
.isEmpty() && primaryGroup
!= group
.getName() ) ||
877 ( primaryGroup
.isEmpty() && user
.getGID() != group
.getGID() )) ) {
878 if ( group
.addUser( user
.getName() ) ) mod
= true;
880 if ( group
.removeUser( user
.getName() ) ) mod
= true;
882 if ( index
== mSelected
.count() ) break;
883 user
= KU_Global::users()->at(mSelected
[index
++]);
887 if ( mod
) KU_Global::groups()->mod( grpindex
, group
);
894 bool KU_EditUser::checkShell(const QString
&shell
)
898 QStringList shells
= readShells();
899 return shells
.contains(shell
);
902 bool KU_EditUser::check()
904 kDebug() << "KU_EditUser::check()";
906 bool one
= mSelected
.isEmpty();
907 bool posix
= !( KU_Global::users()->getCaps() & KU_Users::Cap_Disable_POSIX
) || !( cbposix
->isChecked() );
909 if ( one
&& posix
&& leid
->text().isEmpty() ) {
910 KMessageBox::sorry( 0, i18n("You need to specify an UID.") );
914 if ( one
&& posix
&& lehome
->text().isEmpty() ) {
915 KMessageBox::sorry( 0, i18n("You must specify a home directory.") );
919 if ( KU_Global::users()->getCaps() & KU_Users::Cap_InetOrg
) {
920 if ( one
&& lesurname
->text().isEmpty() ) {
921 KMessageBox::sorry( 0, i18n("You must fill the surname field.") );
926 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) {
927 if ( one
&& lerid
->text().isEmpty() && !( cbsamba
->isChecked() ) ) {
928 KMessageBox::sorry( 0, i18n("You need to specify a samba RID.") );
936 void KU_EditUser::setpwd()
940 if ( pd
.exec() == QDialog::Accepted
) {
942 newpass
= pd
.getPassword();
945 datetime
.setTime_t( lstchg
);
946 if ( KU_Global::users()->getCaps() & KU_Users::Cap_Shadow
||
947 KU_Global::users()->getCaps() & KU_Users::Cap_Samba
||
948 KU_Global::users()->getCaps() & KU_Users::Cap_BSD
) {
950 leslstchg
->setText( KGlobal::locale()->formatDateTime( datetime
, KLocale::LongDate
) );
952 cbdisabled
->setChecked( false );
956 void KU_EditUser::accept()
958 kDebug() << "KU_EditUser::slotOk() ischanged: " << ischanged
;
964 bool one
= mSelected
.isEmpty();
966 uid_t newuid
= leid
->text().toULong();
968 if ( one
&& ( !( KU_Global::users()->getCaps() & KU_Users::Cap_Disable_POSIX
) || !cbposix
->isChecked() )
969 && olduid
!= newuid
)
971 if ( KU_Global::users()->lookup(newuid
) != -1 ) {
972 KMessageBox::sorry( 0,
973 i18n("User with UID %1 already exists", newuid
) );
978 if ( one
&& ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) && !cbsamba
->isChecked() ) {
979 uint newrid
= lerid
->text().toInt();
980 if ( oldrid
!= newrid
) {
981 if ( KU_Global::users()->lookup_sam(newrid
) != -1 ) {
982 KMessageBox::sorry( 0,
983 i18n("User with RID %1 already exists", newrid
) );
990 if (leshell
->currentIndex() != 0)
991 newshell
= leshell
->currentText();
993 if (oldshell
!= newshell
)
995 if (!checkShell(newshell
)) {
996 int result
= KMessageBox::warningYesNoCancel( 0,
997 i18n("<p>The shell %1 is not yet listed in the file %2. "
998 "In order to use this shell you must add it to "
999 "this file first.<br />"
1000 "Do you want to add it now?</p>", newshell
, QFile::decodeName(SHELL_FILE
)),
1001 i18n("Unlisted Shell"),
1002 KGuiItem(i18n("&Add Shell")),
1003 KGuiItem(i18n("Do &Not Add")));
1004 if (result
== KMessageBox::Cancel
)
1007 if (result
== KMessageBox::Yes
)
1012 if ( !ischanged
&& !isgchanged
) {
1014 } else if ( check() ) {
1020 #include "ku_edituser.moc"