summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index c43b391..42a9144 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -17,325 +17,341 @@
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19#include <stdio.h> 19#include <stdio.h>
20#include <sys/types.h> 20#include <sys/types.h>
21#include <sys/wait.h> 21#include <sys/wait.h>
22#include <unistd.h> 22#include <unistd.h>
23#include <signal.h> 23#include <signal.h>
24 24
25#include "passwd.h" 25#include "passwd.h"
26 26
27/** 27/**
28 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 28 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
29 * 29 *
30 */ 30 */
31UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 31UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
32 QVBoxLayout *layout = new QVBoxLayout(this); 32 QVBoxLayout *layout = new QVBoxLayout(this);
33 myTabWidget=new QTabWidget(this,"User Tab Widget"); 33 myTabWidget=new QTabWidget(this,"User Tab Widget");
34 layout->addWidget(myTabWidget); 34 layout->addWidget(myTabWidget);
35 setupTab1(); 35 setupTab1();
36 setupTab2(); 36 setupTab2();
37 37
38 accounts->groupStringList.sort(); 38 accounts->groupStringList.sort();
39 // And also fill the listview & the combobox with all available groups. 39 // And also fill the listview & the combobox with all available groups.
40 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 40 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
41 accounts->splitGroupEntry(*it); 41 accounts->splitGroupEntry(*it);
42 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 42 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
43 groupComboBox->insertItem(accounts->gr_name); 43 groupComboBox->insertItem(accounts->gr_name);
44 } 44 }
45 showMaximized(); 45 showMaximized();
46} 46}
47 47
48/** 48/**
49 * Empty destructor. 49 * Empty destructor.
50 * 50 *
51 */ 51 */
52UserDialog::~UserDialog() { 52UserDialog::~UserDialog() {
53} 53}
54 54
55/** 55/**
56 * Creates the first tab, all userinfo is here. 56 * Creates the first tab, all userinfo is here.
57 * 57 *
58 */ 58 */
59void UserDialog::setupTab1() { 59void UserDialog::setupTab1() {
60 QPixmap mypixmap; 60 QPixmap mypixmap;
61 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 61 QWidget *tabpage = new QWidget(myTabWidget,"page1");
62 QVBoxLayout *layout = new QVBoxLayout(tabpage); 62 QVBoxLayout *layout = new QVBoxLayout(tabpage);
63 layout->setMargin(5); 63 layout->setMargin(5);
64 64
65 // Picture 65 // Picture
66 picturePushButton = new QPushButton(tabpage,"Label"); 66 picturePushButton = new QPushButton(tabpage,"Label");
67 picturePushButton->setMinimumSize(48,48); 67 picturePushButton->setMinimumSize(48,48);
68 picturePushButton->setMaximumSize(48,48); 68 picturePushButton->setMaximumSize(48,48);
69 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. 69 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon.
70 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. 70 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector.
71 71
72 // Login 72 // Login
73 QLabel *loginLabel=new QLabel(tabpage,"Login: "); 73 QLabel *loginLabel=new QLabel(tabpage,"Login: ");
74 loginLabel->setText("Login: "); 74 loginLabel->setText("Login: ");
75 loginLineEdit=new QLineEdit(tabpage,"Login: "); 75 loginLineEdit=new QLineEdit(tabpage,"Login: ");
76 76
77 // UID 77 // UID
78 QLabel *uidLabel=new QLabel(tabpage,"uid: "); 78 QLabel *uidLabel=new QLabel(tabpage,"uid: ");
79 uidLabel->setText("UserID: "); 79 uidLabel->setText("UserID: ");
80 uidLineEdit=new QLineEdit(tabpage,"uid: "); 80 uidLineEdit=new QLineEdit(tabpage,"uid: ");
81 uidLineEdit->setEnabled(false); 81 uidLineEdit->setEnabled(false);
82 82
83 // Username (gecos) 83 // Username (gecos)
84 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 84 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
85 gecosLabel->setText("Username: "); 85 gecosLabel->setText("Username: ");
86 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 86 gecosLineEdit=new QLineEdit(tabpage,"gecos");
87 87
88 // Password 88 // Password
89 QLabel *passwordLabel=new QLabel(tabpage,"password"); 89 QLabel *passwordLabel=new QLabel(tabpage,"password");
90 passwordLabel->setText("Password: "); 90 passwordLabel->setText("Password: ");
91 passwordLineEdit=new QLineEdit(tabpage,"password"); 91 passwordLineEdit=new QLineEdit(tabpage,"password");
92 passwordLineEdit->setEchoMode(QLineEdit::Password); 92 passwordLineEdit->setEchoMode(QLineEdit::Password);
93 93
94 // Shell 94 // Shell
95 QLabel *shellLabel=new QLabel(tabpage,"shell"); 95 QLabel *shellLabel=new QLabel(tabpage,"shell");
96 shellLabel->setText("Shell: "); 96 shellLabel->setText("Shell: ");
97 shellComboBox=new QComboBox(tabpage,"shell"); 97 shellComboBox=new QComboBox(tabpage,"shell");
98 shellComboBox->setEditable(true); 98 shellComboBox->setEditable(true);
99 shellComboBox->insertItem("/bin/sh"); 99 shellComboBox->insertItem("/bin/sh");
100 shellComboBox->insertItem("/bin/ash"); 100 shellComboBox->insertItem("/bin/ash");
101 shellComboBox->insertItem("/bin/false"); 101 shellComboBox->insertItem("/bin/false");
102 102
103 // Primary Group 103 // Primary Group
104 QLabel *groupLabel=new QLabel(tabpage,"group"); 104 QLabel *groupLabel=new QLabel(tabpage,"group");
105 groupLabel->setText("Primary group: "); 105 groupLabel->setText("Primary group: ");
106 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 106 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
107 107
108 // Copy /etc/skel 108 // Copy /etc/skel
109 QLabel *skelLabel=new QLabel(tabpage,"skel"); 109 QLabel *skelLabel=new QLabel(tabpage,"skel");
110 skelLabel->setText("Copy /etc/skel: "); 110 skelLabel->setText("Copy /etc/skel: ");
111 skelCheckBox=new QCheckBox(tabpage); 111 skelCheckBox=new QCheckBox(tabpage);
112 skelCheckBox->setChecked(true); 112 skelCheckBox->setChecked(true);
113 skelLabel->setDisabled(true); 113 //skelLabel->setDisabled(true);
114 skelCheckBox->setDisabled(true); 114 //skelCheckBox->setDisabled(true);
115 115
116 // Widget layout 116 // Widget layout
117 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 117 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
118 layout->addWidget(picturePushButton); 118 layout->addWidget(picturePushButton);
119 layout->addSpacing(5); 119 layout->addSpacing(5);
120 layout->addLayout(hlayout); 120 layout->addLayout(hlayout);
121 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 121 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
122 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 122 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
123 // First column, labels 123 // First column, labels
124 vlayout1->addWidget(loginLabel); 124 vlayout1->addWidget(loginLabel);
125 vlayout1->addSpacing(5); 125 vlayout1->addSpacing(5);
126 vlayout1->addWidget(uidLabel); 126 vlayout1->addWidget(uidLabel);
127 vlayout1->addSpacing(5); 127 vlayout1->addSpacing(5);
128 vlayout1->addWidget(gecosLabel); 128 vlayout1->addWidget(gecosLabel);
129 vlayout1->addSpacing(5); 129 vlayout1->addSpacing(5);
130 vlayout1->addWidget(passwordLabel); 130 vlayout1->addWidget(passwordLabel);
131 vlayout1->addSpacing(5); 131 vlayout1->addSpacing(5);
132 vlayout1->addWidget(shellLabel); 132 vlayout1->addWidget(shellLabel);
133 vlayout1->addSpacing(5); 133 vlayout1->addSpacing(5);
134 vlayout1->addWidget(groupLabel); 134 vlayout1->addWidget(groupLabel);
135 vlayout1->addSpacing(5); 135 vlayout1->addSpacing(5);
136 vlayout1->addWidget(skelLabel); 136 vlayout1->addWidget(skelLabel);
137 // Second column, data 137 // Second column, data
138 vlayout2->addWidget(loginLineEdit); 138 vlayout2->addWidget(loginLineEdit);
139 vlayout2->addSpacing(5); 139 vlayout2->addSpacing(5);
140 vlayout2->addWidget(uidLineEdit); 140 vlayout2->addWidget(uidLineEdit);
141 vlayout2->addSpacing(5); 141 vlayout2->addSpacing(5);
142 vlayout2->addWidget(gecosLineEdit); 142 vlayout2->addWidget(gecosLineEdit);
143 vlayout2->addSpacing(5); 143 vlayout2->addSpacing(5);
144 vlayout2->addWidget(passwordLineEdit); 144 vlayout2->addWidget(passwordLineEdit);
145 vlayout2->addSpacing(5); 145 vlayout2->addSpacing(5);
146 vlayout2->addWidget(shellComboBox); 146 vlayout2->addWidget(shellComboBox);
147 vlayout2->addSpacing(5); 147 vlayout2->addSpacing(5);
148 vlayout2->addWidget(groupComboBox); 148 vlayout2->addWidget(groupComboBox);
149 vlayout2->addSpacing(5); 149 vlayout2->addSpacing(5);
150 vlayout2->addWidget(skelCheckBox); 150 vlayout2->addWidget(skelCheckBox);
151 hlayout->addLayout(vlayout1); 151 hlayout->addLayout(vlayout1);
152 hlayout->addLayout(vlayout2); 152 hlayout->addLayout(vlayout2);
153 153
154 myTabWidget->addTab(tabpage,"User Info"); 154 myTabWidget->addTab(tabpage,"User Info");
155} 155}
156 156
157/** 157/**
158 * Creates the second tab containing additional groups for the user. 158 * Creates the second tab containing additional groups for the user.
159 * 159 *
160 */ 160 */
161void UserDialog::setupTab2() { 161void UserDialog::setupTab2() {
162 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 162 QWidget *tabpage = new QWidget(myTabWidget,"page2");
163 QVBoxLayout *layout = new QVBoxLayout(tabpage); 163 QVBoxLayout *layout = new QVBoxLayout(tabpage);
164 layout->setMargin(5); 164 layout->setMargin(5);
165 165
166 // Additional groups 166 // Additional groups
167 groupsListView=new QListView(tabpage,"groups"); 167 groupsListView=new QListView(tabpage,"groups");
168 groupsListView->addColumn("Additional groups"); 168 groupsListView->addColumn("Additional groups");
169 groupsListView->setColumnWidthMode(0,QListView::Maximum); 169 groupsListView->setColumnWidthMode(0,QListView::Maximum);
170 groupsListView->setMultiSelection(false); 170 groupsListView->setMultiSelection(false);
171 groupsListView->setAllColumnsShowFocus(false); 171 groupsListView->setAllColumnsShowFocus(false);
172 172
173 layout->addSpacing(5); 173 layout->addSpacing(5);
174 // Grouplist 174 // Grouplist
175 layout->addWidget(groupsListView); 175 layout->addWidget(groupsListView);
176 176
177 myTabWidget->addTab(tabpage,"User Groups"); 177 myTabWidget->addTab(tabpage,"User Groups");
178} 178}
179 179
180/** 180/**
181 * Static function that creates the userinfo dialog. 181 * Static function that creates the userinfo dialog.
182 * The user will be prompted to add a user. 182 * The user will be prompted to add a user.
183 * 183 *
184 * @param uid This is a suggested available UID. 184 * @param uid This is a suggested available UID.
185 * @param gid This is a suggested available GID. 185 * @param gid This is a suggested available GID.
186 * 186 *
187 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 187 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
188 * 188 *
189 */ 189 */
190bool UserDialog::addUser(int uid, int gid) { 190bool UserDialog::addUser(int uid, int gid) {
191 QCheckListItem *temp; 191 QCheckListItem *temp;
192 QFile ozTest; 192 QFile ozTest;
193 int oz=ozTest.exists("/etc/oz_version"); 193 int oz=ozTest.exists("/etc/oz_version");
194 UserDialog *adduserDialog=new UserDialog(); 194 UserDialog *adduserDialog=new UserDialog();
195 adduserDialog->setCaption(tr("Add User")); 195 adduserDialog->setCaption(tr("Add User"));
196 adduserDialog->userID=uid;// Set next available UID as default uid. 196 adduserDialog->userID=uid;// Set next available UID as default uid.
197 adduserDialog->groupID=gid;// Set next available GID as default gid. 197 adduserDialog->groupID=gid;// Set next available GID as default gid.
198 // Insert default group into groupComboBox 198 // Insert default group into groupComboBox
199 adduserDialog->groupComboBox->insertItem("<create new group>",0); 199 adduserDialog->groupComboBox->insertItem("<create new group>",0);
200 adduserDialog->uidLineEdit->setText(QString::number(uid)); 200 adduserDialog->uidLineEdit->setText(QString::number(uid));
201 // If we're running on OZ, add new users to some default groups. 201 // If we're running on OZ, add new users to some default groups.
202 if(oz) { 202 if(oz) {
203 QListViewItemIterator iter( adduserDialog->groupsListView ); 203 QListViewItemIterator iter( adduserDialog->groupsListView );
204 for ( ; iter.current(); ++iter ) { 204 for ( ; iter.current(); ++iter ) {
205 temp=(QCheckListItem*)iter.current(); 205 temp=(QCheckListItem*)iter.current();
206 if (temp->text()=="video") temp->setOn(true); 206 if (temp->text()=="video") temp->setOn(true);
207 if (temp->text()=="audio") temp->setOn(true); 207 if (temp->text()=="audio") temp->setOn(true);
208 if (temp->text()=="time") temp->setOn(true); 208 if (temp->text()=="time") temp->setOn(true);
209 if (temp->text()=="power") temp->setOn(true); 209 if (temp->text()=="power") temp->setOn(true);
210 if (temp->text()=="input") temp->setOn(true); 210 if (temp->text()=="input") temp->setOn(true);
211 if (temp->text()=="sharp") temp->setOn(true); 211 if (temp->text()=="sharp") temp->setOn(true);
212 if (temp->text()=="tty") temp->setOn(true); 212 if (temp->text()=="tty") temp->setOn(true);
213 } 213 }
214 } 214 }
215 // Show the dialog! 215 // Show the dialog!
216 if(!(adduserDialog->exec())) return false; 216 if(!(adduserDialog->exec())) return false;
217 if((adduserDialog->groupComboBox->currentItem()!=0)) { 217 if((adduserDialog->groupComboBox->currentItem()!=0)) {
218 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 218 accounts->findGroup(adduserDialog->groupComboBox->currentText());
219 adduserDialog->groupID=accounts->gr_gid; 219 adduserDialog->groupID=accounts->gr_gid;
220 qWarning(QString::number(accounts->gr_gid)); 220 qWarning(QString::number(accounts->gr_gid));
221 } 221 }
222 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 222 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
223 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 223 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
224 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 224 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
225 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 225 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
226 return false; 226 return false;
227 } 227 }
228 228
229 // Add User to additional groups. 229 // Add User to additional groups.
230 QListViewItemIterator it( adduserDialog->groupsListView ); 230 QListViewItemIterator it( adduserDialog->groupsListView );
231 for ( ; it.current(); ++it ) { 231 for ( ; it.current(); ++it ) {
232 temp=(QCheckListItem*)it.current(); 232 temp=(QCheckListItem*)it.current();
233 if (temp->isOn() ) 233 if (temp->isOn() )
234 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 234 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
235 } 235 }
236 // Copy image to pics/users/ 236 // Copy image to pics/users/
237 if(!(adduserDialog->userImage.isNull())) { 237 if(!(adduserDialog->userImage.isNull())) {
238 QDir d; 238 QDir d;
239 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 239 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
240 d.mkdir("/opt/QtPalmtop/pics/users"); 240 d.mkdir("/opt/QtPalmtop/pics/users");
241 } 241 }
242 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 242 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
243 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 243 // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
244 adduserDialog->userImage.save(filename,"PNG"); 244 adduserDialog->userImage.save(filename,"PNG");
245 } 245 }
246
247 // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory?
248 accounts->findUser(adduserDialog->loginLineEdit->text());
249 if(adduserDialog->skelCheckBox->isChecked()) {
250 QString command_cp;
251 QString command_chown;
252 command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1());
253 system(command_cp);
254
255 command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround?
256 system(command_cp);
257
258 command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1());
259 system(command_chown);
260 }
261
246 return true; 262 return true;
247} 263}
248 264
249/** 265/**
250 * Deletes the user account. 266 * Deletes the user account.
251 * 267 *
252 * @param username User to be deleted. 268 * @param username User to be deleted.
253 * 269 *
254 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 270 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
255 * 271 *
256 */ 272 */
257bool UserDialog::delUser(const char *username) { 273bool UserDialog::delUser(const char *username) {
258 if((accounts->findUser(username))) {// Does that user exist? 274 if((accounts->findUser(username))) {// Does that user exist?
259 if(!(accounts->delUser(username))) {// Delete the user. 275 if(!(accounts->delUser(username))) {// Delete the user.
260 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 276 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
261 } 277 }
262 } else { 278 } else {
263 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 279 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
264 return false; 280 return false;
265 } 281 }
266 return true; 282 return true;
267} 283}
268 284
269/** 285/**
270 * This displays a confirmation dialog wether a user should be deleted or not. 286 * This displays a confirmation dialog wether a user should be deleted or not.
271 * (And also deletes the account) 287 * (And also deletes the account)
272 * 288 *
273 * @param username User to be deleted. 289 * @param username User to be deleted.
274 * 290 *
275 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 291 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
276 * 292 *
277 */ 293 */
278bool UserDialog::editUser(const char *username) { 294bool UserDialog::editUser(const char *username) {
279 int invalid_group=0; 295 int invalid_group=0;
280 UserDialog *edituserDialog=new UserDialog();// Create Dialog 296 UserDialog *edituserDialog=new UserDialog();// Create Dialog
281 edituserDialog->setCaption(tr("Edit User")); 297 edituserDialog->setCaption(tr("Edit User"));
282 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 298 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
283 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 299 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object.
284 invalid_group=1; 300 invalid_group=1;
285 } 301 }
286 // Fill widgets with userinfo. 302 // Fill widgets with userinfo.
287 edituserDialog->loginLineEdit->setText(accounts->pw_name); 303 edituserDialog->loginLineEdit->setText(accounts->pw_name);
288 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 304 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
289 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 305 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
290 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 306 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
291 edituserDialog->passwordLineEdit->setText("........"); 307 edituserDialog->passwordLineEdit->setText("........");
292 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 308 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
293 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 309 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") {
294 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 310 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
295 edituserDialog->shellComboBox->setCurrentItem(0); 311 edituserDialog->shellComboBox->setCurrentItem(0);
296 } 312 }
297 // Select the primary group for this user. 313 // Select the primary group for this user.
298 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 314 for(int i=0;i<edituserDialog->groupComboBox->count();++i) {
299 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 315 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
300 edituserDialog->groupComboBox->setCurrentItem(i); 316 edituserDialog->groupComboBox->setCurrentItem(i);
301 break; 317 break;
302 } 318 }
303 } 319 }
304 if(invalid_group) { 320 if(invalid_group) {
305 edituserDialog->groupComboBox->insertItem("<Undefined group>",0); 321 edituserDialog->groupComboBox->insertItem("<Undefined group>",0);
306 edituserDialog->groupComboBox->setCurrentItem(0); 322 edituserDialog->groupComboBox->setCurrentItem(0);
307 } 323 }
308 // Select the groups in the listview, to which the user belongs. 324 // Select the groups in the listview, to which the user belongs.
309 QCheckListItem *temp; 325 QCheckListItem *temp;
310 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); 326 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username));
311 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 327 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
312 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 328 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
313 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 329 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
314 for ( ; lvit.current(); ++lvit ) { 330 for ( ; lvit.current(); ++lvit ) {
315 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 331 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
316 temp=(QCheckListItem*)lvit.current(); 332 temp=(QCheckListItem*)lvit.current();
317 temp->setOn(true);// If we find a line with that groupname, select it.; 333 temp->setOn(true);// If we find a line with that groupname, select it.;
318 } 334 }
319 } 335 }
320 } 336 }
321 337
322 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 338 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
323 339
324 accounts->findUser(username);// Fill user variables in 'acccounts' object. 340 accounts->findUser(username);// Fill user variables in 'acccounts' object.
325 accounts->pw_name=edituserDialog->loginLineEdit->text(); 341 accounts->pw_name=edituserDialog->loginLineEdit->text();
326 // Has the password been changed ? Make a new "crypt":ed password. 342 // Has the password been changed ? Make a new "crypt":ed password.
327 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 343 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
328 344
329 // Set all variables in accounts object, that will be used when calling 'updateUser()' 345 // Set all variables in accounts object, that will be used when calling 'updateUser()'
330 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 346 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
331 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. 347 if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object.
332 accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. 348 accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group.
333 } 349 }
334 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 350 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
335 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 351 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
336 // Update userinfo, using the information stored in the user variables stored in the accounts object. 352 // Update userinfo, using the information stored in the user variables stored in the accounts object.
337 accounts->updateUser(username); 353 accounts->updateUser(username);
338 354
339 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) 355 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.)
340 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 356 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {
341 accounts->delGroupMember((*it).left((*it).find(":")),username); 357 accounts->delGroupMember((*it).left((*it).find(":")),username);