source: src-qt4/pc-usermanager/simpledlgcode.cpp @ 87d35b7

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 87d35b7 was 87d35b7, checked in by Kris Moore <kris@…>, 14 months ago

Add ability to PEFS encrypt users home-directories when we
create a new user via the user-manager GUI

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2007, 2012 by Tim McCormick   *
3 *   tim@pcbsd.org   *
4 *                                                                         *
5 *   Permission is hereby granted, free of charge, to any person obtaining *
6 *   a copy of this software and associated documentation files (the       *
7 *   "Software"), to deal in the Software without restriction, including   *
8 *   without limitation the rights to use, copy, modify, merge, publish,   *
9 *   distribute, sublicense, and/or sell copies of the Software, and to    *
10 *   permit persons to whom the Software is furnished to do so, subject to *
11 *   the following conditions:                                             *
12 *                                                                         *
13 *   The above copyright notice and this permission notice shall be        *
14 *   included in all copies or substantial portions of the Software.       *
15 *                                                                         *
16 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
17 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
18 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
20 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
23 ***************************************************************************/
24#include "simpledlgcode.h"
25#include "user.h"
26       
27#include <qstringlist.h>
28#include <qpushbutton.h>
29#include <qcheckbox.h>
30#include <qlineedit.h>
31#include <qtooltip.h>
32#include <qcolor.h>
33#include <QDebug>
34#include "../config.h"
35
36void SimpleDlgCode::programInit(UserManagerBackend *back, QString dir)
37{
38    this->back = back;
39    userImage = QPixmap(PREFIX + "/share/icons/crystalsvg/48x48/kdm/user_male.png");
40    systemChange = false;
41    chroot = dir;
42   
43    refreshUsers();
44   
45    connect(advancedBut, SIGNAL(clicked()), this, SLOT(advancedPressed()));
46    connect(userList, SIGNAL(currentTextChanged( const QString & )), this, SLOT(getUserDetails( const QString& )));
47    connect(fullnameBox, SIGNAL(textChanged(const QString&)), this, SLOT(fullnameChanged()));
48    connect(canAdminCheck, SIGNAL(toggled(bool)), this, SLOT(canAdminChanged(bool)));
49    connect(changePasswordBut, SIGNAL(clicked()), this, SLOT(changePassword()));
50    connect(rootPasswordBut, SIGNAL(clicked()), this, SLOT(changeRootPassword()));
51    connect(removeUserBut, SIGNAL(clicked()), this, SLOT(removeUser()));
52    connect(back, SIGNAL(usersChanged()), this, SLOT(refreshUsers()));
53    connect(addUserBut, SIGNAL(clicked()), this, SLOT(addUser()));
54}
55
56void SimpleDlgCode::refreshUsers()
57{
58    qDebug("Adding user to userlist:" );
59
60    disconnect(userList, SIGNAL(currentTextChanged( const QString & )), 0, 0);
61
62    QString tmp;
63    wheel = back->getGroup(0);
64    QStringList users = back->getAllUsers();
65    users.sort();
66    userList->clear();
67   
68    qDebug() << "All Users in list:" << users;
69
70    // If no users setup yet, lets diable the details and return
71    if ( users.isEmpty() ) {
72      frame->setEnabled(false); 
73      return;
74    }
75    frame->setEnabled(true); 
76    for ( QStringList::Iterator it = users.begin(); it != users.end(); ++it )
77    {
78        new QListWidgetItem(userImage, *it + " (" + back->getUser(*it)->getFullname() + ")", userList);
79    }
80    userList->setCurrentRow(0);
81    getUserDetails(userList->currentItem()->text());
82
83    connect(userList, SIGNAL(currentTextChanged( const QString & )), this, SLOT(getUserDetails( const QString& )));
84}
85
86void SimpleDlgCode::advancedPressed()
87{
88    emit advancedView();
89}
90
91void SimpleDlgCode::getUserDetails(const QString& username)
92{
93    qDebug() << "Simple dialog, fetching information for: " << username;
94   
95    systemChange = true;
96    User *user = back->getUser(username.section(" ", 0, 0));
97   
98    fullnameBox->setText(user->getFullname());
99   
100    canAdminCheck->setChecked(wheel->isMember(user->getUsername()));
101   
102    //Do not allow the removal of the currently logged in user
103    removeUserBut->setEnabled(getenv("USER") != user->getUsername());
104
105    if ( user->getEnc() )
106      changePasswordBut->setEnabled(false);
107    else
108      changePasswordBut->setEnabled(true);
109   
110    systemChange = false;
111}
112
113void SimpleDlgCode::fullnameChanged()
114{
115    User *user = back->getUser(userList->currentItem()->text().section(" ", 0, 0));
116   
117    int fullnameError = back->validateFullname(fullnameBox->text());
118   
119    QColor fullnameBoxColour("white");
120    fullnameBox->setToolTip(tr("Good Input"));
121   
122    switch(fullnameError)
123    {
124    case 1:
125        fullnameBox->setToolTip(tr("The field is empty"));
126        break;
127    case 2:
128        fullnameBoxColour.setRed(fullnameBoxColour.red());
129        fullnameBox->setToolTip(tr("This field may not contain ! @ or :"));
130        break;
131    }
132   
133    if ((! systemChange) && (fullnameError != 2))
134    {
135        user->setFullname(fullnameBox->text());
136        user->setChanges();
137        userList->currentItem()->setText(user->getUsername() + " (" + fullnameBox->text() + ")");
138        emit changed();
139    }
140   
141    QPalette bgPal(fullnameBoxColour);
142    bgPal.setColor(QPalette::Window, fullnameBoxColour);
143    fullnameBox->setPalette(bgPal);
144}
145
146void SimpleDlgCode::canAdminChanged(bool on)
147{
148    if (! systemChange)
149    {
150        QString username = userList->currentItem()->text().section(" ", 0, 0);
151       
152        if ((! wheel->isMember(username)) && on) { back->addUserToGroup(username, "wheel"); }
153        else if (wheel->isMember(username) && (! on)) { back->removeUserFromGroup(username, "wheel"); }
154    }
155}
156
157void SimpleDlgCode::changePassword()
158{
159    changePassUi = new ChangePassCode();
160    changePassUi->programInit(userList->currentItem()->text().section(" ", 0, 0), back);
161    changePassUi->show();
162}
163
164void SimpleDlgCode::changeRootPassword()
165{
166    changePassUi = new ChangePassCode();
167    changePassUi->programInit("root", back);
168    changePassUi->show();
169}
170
171void SimpleDlgCode::removeUser()
172{
173    QString username = userList->currentItem()->text().section(" ", 0, 0);
174    User *user = back->getUser(username);
175    QString home = user->getHome();
176    int answer = QMessageBox::question(this,
177                                       tr("Delete Home Directory?"),
178                                       tr("Delete the home directory for ") + username + " (" + home + ")?" ,
179                                       QMessageBox::Yes | QMessageBox::No,
180                                       QMessageBox::No);
181    if(answer == QMessageBox::Yes) 
182      user->setDeleteHome(true);
183    else
184      user->setDeleteHome(false);
185    back->deleteUser(username);
186}
187
188void SimpleDlgCode::addUser()
189{
190    addUserUi = new SimpleAddCode();
191    addUserUi->programInit(back);
192    addUserUi->show();
193}
194
Note: See TracBrowser for help on using the repository browser.