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 <sys/types.h>
32 #include <QVBoxLayout>
35 #include <kmessagebox.h>
39 #include "ku_global.h"
40 #include "ku_adduser.h"
42 KU_AddUser::KU_AddUser( KU_User
&user
, bool useprivategroup
,
44 KU_EditUser( user
, useprivategroup
, parent
)
46 QGroupBox
*group
= new QGroupBox(frontpage
);
47 group
->setTitle(i18n("New Account Options"));
48 QVBoxLayout
*grouplayout
= new QVBoxLayout( group
);
49 grouplayout
->setMargin( marginHint() );
50 grouplayout
->setSpacing( spacingHint() );
51 // grouplayout->addSpacing( group->fontMetrics().lineSpacing() );
53 createhome
= new QCheckBox(i18n("Create home folder"), 0);
54 createhome
->setChecked(true);
55 grouplayout
->addWidget( createhome
);
56 copyskel
= new QCheckBox(i18n("Copy skeleton"), 0);
57 grouplayout
->addWidget( copyskel
);
59 connect(createhome
, SIGNAL(toggled(bool)), copyskel
, SLOT(setEnabled(bool)));
60 frontlayout
->addWidget(group
, frontrow
, 0, 1, 3);
62 if ( useprivategroup
) pbprigr
->setEnabled( false );
67 void KU_AddUser::accept()
69 if ( !check() ) return;
71 mergeUser( mNewUser
, mNewUser
);
72 if ( ( mNewUser
.getCaps() & KU_User::Cap_POSIX
) &&
73 KU_Global::users()->lookup( mNewUser
.getUID() ) != -1 ) {
74 KMessageBox::sorry( 0, i18n("User with UID %1 already exists.", mNewUser
.getUID() ) );
78 if ( ( KU_Global::users()->getCaps() & KU_Users::Cap_Samba
) &&
79 ( mNewUser
.getCaps() & KU_User::Cap_Samba
) ) {
80 if ( KU_Global::users()->lookup_sam( mNewUser
.getSID().getRID() ) != -1 ) {
81 KMessageBox::sorry( 0, i18n("User with RID %1 already exists.", mNewUser
.getSID().getRID() ) );
86 if (createhome
->isChecked())
88 mNewUser
.setCreateHome(true);
89 mNewUser
.setCreateMailBox(true);
91 if (copyskel
->isChecked())
93 mNewUser
.setCopySkel(true);
96 if (mNewUser
.getCreateHome() && !checkHome())
99 if (mNewUser
.getCreateMailBox() && !checkMailBox())
100 mNewUser
.setCreateMailBox(false);
104 kDebug() << "slotOk name: " << mNewUser
.getName();
108 bool KU_AddUser::checkHome()
113 QString h_dir
= mNewUser
.getHomeDir();
114 r
= stat( QFile::encodeName(h_dir
), &s
);
116 if ( (r
== -1) && (errno
== ENOENT
) )
120 if (S_ISDIR(s
.st_mode
)) {
122 warningContinueCancel ( 0,
123 i18n("Folder %1 already exists.\n%2 may become owner and permissions may change.\nDo you really want to use %3?",
124 h_dir
, mNewUser
.getName(), h_dir
), QString(), KStandardGuiItem::cont() ) == KMessageBox::Cancel
)
130 KMessageBox::error( 0, i18n("%1 is not a folder.", h_dir
) );
132 KMessageBox::error( 0, i18n("stat() failed on %1.", h_dir
) );
137 bool KU_AddUser::checkMailBox()
144 mailboxpath
= QFile::decodeName(MAIL_SPOOL_DIR
) + '/' + mNewUser
.getName();
145 r
= stat(QFile::encodeName(mailboxpath
), &s
);
147 if ((r
== -1) && (errno
== ENOENT
))
151 if (S_ISREG(s
.st_mode
))
152 KMessageBox::error( 0, i18n("Mailbox %1 already exists (uid=%2).",
156 KMessageBox::error( 0, i18n("%1 exists but is not a regular file.",
159 KMessageBox::error( 0, i18n("stat() failed on %1.", mailboxpath
) );
163 #include "ku_adduser.moc"