summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index c6b8a57..719dd1e 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -1,354 +1,354 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#include "userdialog.h" 10#include "userdialog.h"
11 11
12#include <qlayout.h> 12#include <qlayout.h>
13#include <qlabel.h> 13#include <qlabel.h>
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15 15
16#include <stdlib.h> 16#include <stdlib.h>
17 17
18#include <stdio.h> 18#include <stdio.h>
19#include <sys/types.h> 19#include <sys/types.h>
20#include <sys/wait.h> 20#include <sys/wait.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <signal.h> 22#include <signal.h>
23 23
24#include "passwd.h" 24#include "passwd.h"
25 25
26/** 26/**
27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
28 * 28 *
29 */ 29 */
30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
31 QVBoxLayout *layout = new QVBoxLayout(this); 31 QVBoxLayout *layout = new QVBoxLayout(this);
32 myTabWidget=new QTabWidget(this,"User Tab Widget"); 32 myTabWidget=new QTabWidget(this,"User Tab Widget");
33 layout->addWidget(myTabWidget); 33 layout->addWidget(myTabWidget);
34 setupTab1(); 34 setupTab1();
35 setupTab2(); 35 setupTab2();
36 36
37 // And also fill the listview & the combobox with all available groups. 37 // And also fill the listview & the combobox with all available groups.
38 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 38 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
39 accounts->splitGroupEntry(*it); 39 accounts->splitGroupEntry(*it);
40 //new QListViewItem(groupsListView,accounts->gr_name); 40 //new QListViewItem(groupsListView,accounts->gr_name);
41 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 41 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
42 groupComboBox->insertItem(accounts->gr_name); 42 groupComboBox->insertItem(accounts->gr_name);
43 } 43 }
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 // Widget layout 108 // Widget layout
109 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 109 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
110 layout->addWidget(picturePushButton); 110 layout->addWidget(picturePushButton);
111 layout->addSpacing(5); 111 layout->addSpacing(5);
112 layout->addLayout(hlayout); 112 layout->addLayout(hlayout);
113 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 113 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
114 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 114 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
115 // First column, labels 115 // First column, labels
116 vlayout1->addWidget(loginLabel); 116 vlayout1->addWidget(loginLabel);
117 vlayout1->addSpacing(5); 117 vlayout1->addSpacing(5);
118 vlayout1->addWidget(uidLabel); 118 vlayout1->addWidget(uidLabel);
119 vlayout1->addSpacing(5); 119 vlayout1->addSpacing(5);
120 vlayout1->addWidget(gecosLabel); 120 vlayout1->addWidget(gecosLabel);
121 vlayout1->addSpacing(5); 121 vlayout1->addSpacing(5);
122 vlayout1->addWidget(passwordLabel); 122 vlayout1->addWidget(passwordLabel);
123 vlayout1->addSpacing(5); 123 vlayout1->addSpacing(5);
124 vlayout1->addWidget(shellLabel); 124 vlayout1->addWidget(shellLabel);
125 vlayout1->addSpacing(5); 125 vlayout1->addSpacing(5);
126 vlayout1->addWidget(groupLabel); 126 vlayout1->addWidget(groupLabel);
127 // Second column, data 127 // Second column, data
128 vlayout2->addWidget(loginLineEdit); 128 vlayout2->addWidget(loginLineEdit);
129 vlayout2->addSpacing(5); 129 vlayout2->addSpacing(5);
130 vlayout2->addWidget(uidLineEdit); 130 vlayout2->addWidget(uidLineEdit);
131 vlayout2->addSpacing(5); 131 vlayout2->addSpacing(5);
132 vlayout2->addWidget(gecosLineEdit); 132 vlayout2->addWidget(gecosLineEdit);
133 vlayout2->addSpacing(5); 133 vlayout2->addSpacing(5);
134 vlayout2->addWidget(passwordLineEdit); 134 vlayout2->addWidget(passwordLineEdit);
135 vlayout2->addSpacing(5); 135 vlayout2->addSpacing(5);
136 vlayout2->addWidget(shellComboBox); 136 vlayout2->addWidget(shellComboBox);
137 vlayout2->addSpacing(5); 137 vlayout2->addSpacing(5);
138 vlayout2->addWidget(groupComboBox); 138 vlayout2->addWidget(groupComboBox);
139 hlayout->addLayout(vlayout1); 139 hlayout->addLayout(vlayout1);
140 hlayout->addLayout(vlayout2); 140 hlayout->addLayout(vlayout2);
141 141
142 myTabWidget->addTab(tabpage,"User Info"); 142 myTabWidget->addTab(tabpage,"User Info");
143} 143}
144 144
145/** 145/**
146 * Creates the second tab containing additional groups for the user. 146 * Creates the second tab containing additional groups for the user.
147 * 147 *
148 */ 148 */
149void UserDialog::setupTab2() { 149void UserDialog::setupTab2() {
150 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 150 QWidget *tabpage = new QWidget(myTabWidget,"page2");
151 QVBoxLayout *layout = new QVBoxLayout(tabpage); 151 QVBoxLayout *layout = new QVBoxLayout(tabpage);
152 layout->setMargin(5); 152 layout->setMargin(5);
153 153
154 // Additional groups 154 // Additional groups
155 groupsListView=new QListView(tabpage,"groups"); 155 groupsListView=new QListView(tabpage,"groups");
156 groupsListView->addColumn("Additional groups"); 156 groupsListView->addColumn("Additional groups");
157 groupsListView->setColumnWidthMode(0,QListView::Maximum); 157 groupsListView->setColumnWidthMode(0,QListView::Maximum);
158 groupsListView->setMultiSelection(true); 158 groupsListView->setMultiSelection(true);
159 groupsListView->setAllColumnsShowFocus(false); 159 groupsListView->setAllColumnsShowFocus(false);
160 160
161 layout->addSpacing(5); 161 layout->addSpacing(5);
162 // Grouplist 162 // Grouplist
163 layout->addWidget(groupsListView); 163 layout->addWidget(groupsListView);
164 164
165 myTabWidget->addTab(tabpage,"User Groups"); 165 myTabWidget->addTab(tabpage,"User Groups");
166} 166}
167 167
168/** 168/**
169 * Static function that creates the userinfo dialog. 169 * Static function that creates the userinfo dialog.
170 * The user will be prompted to add a user. 170 * The user will be prompted to add a user.
171 * 171 *
172 * @param uid This is a suggested available UID. 172 * @param uid This is a suggested available UID.
173 * @param gid This is a suggested available GID. 173 * @param gid This is a suggested available GID.
174 * 174 *
175 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 175 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
176 * 176 *
177 */ 177 */
178bool UserDialog::addUser(int uid, int gid) { 178bool UserDialog::addUser(int uid, int gid) {
179 UserDialog *adduserDialog=new UserDialog(); 179 UserDialog *adduserDialog=new UserDialog();
180 adduserDialog->setCaption(tr("Add User")); 180 adduserDialog->setCaption(tr("Add User"));
181 adduserDialog->userID=uid;// Set next available UID as default uid. 181 adduserDialog->userID=uid;// Set next available UID as default uid.
182 adduserDialog->groupID=gid;// Set next available GID as default gid. 182 adduserDialog->groupID=gid;// Set next available GID as default gid.
183 // Insert default group into groupComboBox 183 // Insert default group into groupComboBox
184 adduserDialog->groupComboBox->insertItem("<create new group>",0); 184 adduserDialog->groupComboBox->insertItem("<create new group>",0);
185 adduserDialog->uidLineEdit->setText(QString::number(uid)); 185 adduserDialog->uidLineEdit->setText(QString::number(uid));
186 // Show the dialog! 186 // Show the dialog!
187 if(!(adduserDialog->exec())) return false; 187 if(!(adduserDialog->exec())) return false;
188 if((adduserDialog->groupComboBox->currentItem()!=0)) { 188 if((adduserDialog->groupComboBox->currentItem()!=0)) {
189 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 189 accounts->findGroup(adduserDialog->groupComboBox->currentText());
190 adduserDialog->groupID=accounts->gr_gid; 190 adduserDialog->groupID=accounts->gr_gid;
191 qWarning(QString::number(accounts->gr_gid)); 191 qWarning(QString::number(accounts->gr_gid));
192 } 192 }
193 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 193 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
194 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 194 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
195 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 195 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
196 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 196 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
197 return false; 197 return false;
198 } 198 }
199 199
200 // Add User to additional groups. 200 // Add User to additional groups.
201 QListViewItemIterator it( adduserDialog->groupsListView ); 201 QListViewItemIterator it( adduserDialog->groupsListView );
202 for ( ; it.current(); ++it ) { 202 for ( ; it.current(); ++it ) {
203 if ( it.current()->isSelected() ) 203 if ( it.current()->isSelected() )
204 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 204 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
205 } 205 }
206 // Copy image to pics/users/ 206 // Copy image to pics/users/
207 if(!(adduserDialog->userImage.isNull())) { 207 if(!(adduserDialog->userImage.isNull())) {
208 QDir d; 208 QDir d;
209 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 209 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
210 d.mkdir("/opt/QtPalmtop/pics/users"); 210 d.mkdir("/opt/QtPalmtop/pics/users");
211 } 211 }
212 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 212 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
213 adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); 213 adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48);
214 adduserDialog->userImage.save(filename,"PNG"); 214 adduserDialog->userImage.save(filename,"PNG");
215 } 215 }
216 return true; 216 return true;
217} 217}
218 218
219/** 219/**
220 * Deletes the user account. 220 * Deletes the user account.
221 * 221 *
222 * @param username User to be deleted. 222 * @param username User to be deleted.
223 * 223 *
224 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 224 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
225 * 225 *
226 */ 226 */
227bool UserDialog::delUser(const char *username) { 227bool UserDialog::delUser(const char *username) {
228 if((accounts->findUser(username))) {// Does that user exist? 228 if((accounts->findUser(username))) {// Does that user exist?
229 if(!(accounts->delUser(username))) {// Delete the user. 229 if(!(accounts->delUser(username))) {// Delete the user.
230 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 230 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
231 } 231 }
232 } else { 232 } else {
233 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 233 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
234 return false; 234 return false;
235 } 235 }
236 return true; 236 return true;
237} 237}
238 238
239/** 239/**
240 * This displays a confirmation dialog wether a user should be deleted or not. 240 * This displays a confirmation dialog wether a user should be deleted or not.
241 * (And also deletes the account) 241 * (And also deletes the account)
242 * 242 *
243 * @param username User to be deleted. 243 * @param username User to be deleted.
244 * 244 *
245 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 245 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
246 * 246 *
247 */ 247 */
248bool UserDialog::editUser(const char *username) { 248bool UserDialog::editUser(const char *username) {
249 UserDialog *edituserDialog=new UserDialog();// Create Dialog 249 UserDialog *edituserDialog=new UserDialog();// Create Dialog
250 edituserDialog->setCaption(tr("Edit User")); 250 edituserDialog->setCaption(tr("Edit User"));
251 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 251 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
252 accounts->findGroup(accounts->pw_gid);// Locate the user's primary group, and fill group variables in 'accounts' object. 252 accounts->findGroup(accounts->pw_gid);// Locate the user's primary group, and fill group variables in 'accounts' object.
253 // Fill widgets with userinfo. 253 // Fill widgets with userinfo.
254 edituserDialog->loginLineEdit->setText(accounts->pw_name); 254 edituserDialog->loginLineEdit->setText(accounts->pw_name);
255 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 255 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
256 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 256 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
257 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 257 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
258 edituserDialog->passwordLineEdit->setText("........"); 258 edituserDialog->passwordLineEdit->setText("........");
259 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 259 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
260 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 260 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") {
261 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 261 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
262 edituserDialog->shellComboBox->setCurrentItem(0); 262 edituserDialog->shellComboBox->setCurrentItem(0);
263 } 263 }
264 // Select the primary group for this user. 264 // Select the primary group for this user.
265 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 265 for(int i=0;i<edituserDialog->groupComboBox->count();++i) {
266 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 266 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
267 edituserDialog->groupComboBox->setCurrentItem(i); 267 edituserDialog->groupComboBox->setCurrentItem(i);
268 } 268 }
269 } 269 }
270 // Select the groups in the listview, to which the user belongs. 270 // Select the groups in the listview, to which the user belongs.
271 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); 271 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username));
272 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 272 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
273 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 273 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
274 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 274 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
275 for ( ; lvit.current(); ++lvit ) { 275 for ( ; lvit.current(); ++lvit ) {
276 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 276 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
277 lvit.current()->setSelected(true);// If we find a line with that groupname, select it.; 277 lvit.current()->setSelected(true);// If we find a line with that groupname, select it.;
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 282 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
283 283
284 accounts->findUser(username);// Fill user variables in 'acccounts' object. 284 accounts->findUser(username);// Fill user variables in 'acccounts' object.
285 accounts->pw_name=edituserDialog->loginLineEdit->text(); 285 accounts->pw_name=edituserDialog->loginLineEdit->text();
286 // Has the password been changed ? Make a new "crypt":ed password. 286 // Has the password been changed ? Make a new "crypt":ed password.
287 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 287 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
288 288
289 // Set all variables in accounts object, that will be used when calling 'updateUser()' 289 // Set all variables in accounts object, that will be used when calling 'updateUser()'
290 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 290 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
291 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object. 291 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object.
292 accounts->pw_gid=accounts->gr_gid; 292 accounts->pw_gid=accounts->gr_gid;
293 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 293 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
294 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 294 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
295 // Update userinfo, using the information stored in the user variables stored in the accounts object. 295 // Update userinfo, using the information stored in the user variables stored in the accounts object.
296 accounts->updateUser(username); 296 accounts->updateUser(username);
297 297
298 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) 298 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.)
299 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 299 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {
300 accounts->delGroupMember((*it).left((*it).find(":")),username); 300 accounts->delGroupMember((*it).left((*it).find(":")),username);
301 } 301 }
302 302
303 // Add User to additional groups that he/she is a member of. 303 // Add User to additional groups that he/she is a member of.
304 QListViewItemIterator it( edituserDialog->groupsListView ); 304 QListViewItemIterator it( edituserDialog->groupsListView );
305 for ( ; it.current(); ++it ) { 305 for ( ; it.current(); ++it ) {
306 if ( it.current()->isSelected() ) 306 if ( it.current()->isSelected() )
307 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); 307 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text());
308 } 308 }
309 309
310 // Copy image to pics/users/ 310 // Copy image to pics/users/
311 if(!(edituserDialog->userImage.isNull())) { 311 if(!(edituserDialog->userImage.isNull())) {
312 QDir d; 312 QDir d;
313 if(!(d.exists("/opt/QtPalmtop/pics/users"))) { 313 if(!(d.exists("/opt/QtPalmtop/pics/users"))) {
314 d.mkdir("/opt/QtPalmtop/pics/users"); 314 d.mkdir("/opt/QtPalmtop/pics/users");
315 } 315 }
316 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; 316 QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png";
317 edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); 317 edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48);
318 edituserDialog->userImage.save(filename,"PNG"); 318 edituserDialog->userImage.save(filename,"PNG");
319 } 319 }
320 return true; 320 return true;
321} 321}
322 322
323/** 323/**
324 * "OK" has been clicked. Verify some information before closing the dialog. 324 * "OK" has been clicked. Verify some information before closing the dialog.
325 * 325 *
326 */ 326 */
327void UserDialog::accept() { 327void UserDialog::accept() {
328 // Add checking... valid username? username taken? 328 // Add checking... valid username? username taken?
329 if(loginLineEdit->text().isEmpty()) { 329 if(loginLineEdit->text().isEmpty()) {
330 QMessageBox::information(0,"Empty Login","Please enter a login."); 330 QMessageBox::information(0,"Empty Login","Please enter a login.");
331 return; 331 return;
332 } 332 }
333 QDialog::accept(); 333 QDialog::accept();
334} 334}
335 335
336/** 336/**
337 * This slot is called when the usericon is clicked, this loads (should) the iconselector. 337 * This slot is called when the usericon is clicked, this loads (should) the iconselector.
338 * 338 *
339 */ 339 */
340void UserDialog::clickedPicture() { 340void UserDialog::clickedPicture() {
341 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); 341 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics");
342 if(!(filename.isEmpty())) { 342 if(!(filename.isEmpty())) {
343 userImage.reset(); 343 userImage.reset();
344 if(!(userImage.load(filename))) { 344 if(!(userImage.load(filename))) {
345 QMessageBox::information(0,"Sorry!","Icon selection not yet implemented.\nComming real soon now! (tm)\n"+filename); 345 QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename);
346 } else { 346 } else {
347 userImage=userImage.smoothScale(48,48); 347 userImage=userImage.smoothScale(48,48);
348 QPixmap *picture; 348 QPixmap *picture;
349 picture=(QPixmap *)picturePushButton->pixmap(); 349 picture=(QPixmap *)picturePushButton->pixmap();
350 picture->convertFromImage(userImage,0); 350 picture->convertFromImage(userImage,0);
351 picturePushButton->update(); 351 picturePushButton->update();
352 } 352 }
353 } 353 }
354} 354}