-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 2 |
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 | |||
@@ -217,138 +217,138 @@ bool UserDialog::addUser(int uid, int gid) { | |||
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 | */ |
227 | bool UserDialog::delUser(const char *username) { | 227 | bool 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 | */ |
248 | bool UserDialog::editUser(const char *username) { | 248 | bool 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 | */ |
327 | void UserDialog::accept() { | 327 | void 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 | */ |
340 | void UserDialog::clickedPicture() { | 340 | void 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 | } |