Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 08de352..eb9a289 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -8,13 +8,13 @@ | |||
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "userdialog.h" | 10 | #include "userdialog.h" |
11 | #include "passwd.h" | 11 | #include "passwd.h" |
12 | 12 | ||
13 | /* OPIE */ | 13 | /* OPIE */ |
14 | #include <opie/odevice.h> | 14 | #include <opie2/odevice.h> |
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | 16 | ||
17 | /* QT */ | 17 | /* QT */ |
18 | #include <qlayout.h> | 18 | #include <qlayout.h> |
19 | #include <qlabel.h> | 19 | #include <qlabel.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
@@ -46,13 +46,13 @@ UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool mod | |||
46 | accounts->groupStringList.sort(); | 46 | accounts->groupStringList.sort(); |
47 | // And also fill the listview & the combobox with all available groups. | 47 | // And also fill the listview & the combobox with all available groups. |
48 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) | 48 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) |
49 | { | 49 | { |
50 | accounts->splitGroupEntry(*it); | 50 | accounts->splitGroupEntry(*it); |
51 | if(accounts->gr_name.find(QRegExp("^#"),0)) | 51 | if(accounts->gr_name.find(QRegExp("^#"),0)) |
52 | {// Skip commented lines. | 52 | { // Skip commented lines. |
53 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 53 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
54 | groupComboBox->insertItem(accounts->gr_name); | 54 | groupComboBox->insertItem(accounts->gr_name); |
55 | } | 55 | } |
56 | } | 56 | } |
57 | QPEApplication::showDialog( this ); | 57 | QPEApplication::showDialog( this ); |
58 | } | 58 | } |
@@ -76,14 +76,14 @@ void UserDialog::setupTab1() | |||
76 | layout->setMargin(5); | 76 | layout->setMargin(5); |
77 | 77 | ||
78 | // Picture | 78 | // Picture |
79 | picturePushButton = new QPushButton(tabpage,"Label"); | 79 | picturePushButton = new QPushButton(tabpage,"Label"); |
80 | picturePushButton->setMinimumSize(48,48); | 80 | picturePushButton->setMinimumSize(48,48); |
81 | picturePushButton->setMaximumSize(48,48); | 81 | picturePushButton->setMaximumSize(48,48); |
82 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. | 82 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon")); // Load default usericon. |
83 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. | 83 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture())); // Clicking the picture should invoke pictureselector. |
84 | 84 | ||
85 | // Login | 85 | // Login |
86 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 86 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
87 | loginLabel->setText("Login: "); | 87 | loginLabel->setText("Login: "); |
88 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 88 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
89 | 89 | ||
@@ -197,13 +197,13 @@ void UserDialog::setupTab2() | |||
197 | 197 | ||
198 | myTabWidget->addTab(tabpage,"User Groups"); | 198 | myTabWidget->addTab(tabpage,"User Groups"); |
199 | } | 199 | } |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Static function that creates the userinfo dialog. | 202 | * Static function that creates the userinfo dialog. |
203 | * The user will be prompted to add a user. | 203 | * The user will be prompted to add a user. |
204 | * | 204 | * |
205 | * @param uid This is a suggested available UID. | 205 | * @param uid This is a suggested available UID. |
206 | * @param gid This is a suggested available GID. | 206 | * @param gid This is a suggested available GID. |
207 | * | 207 | * |
208 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 208 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
209 | * | 209 | * |
@@ -214,14 +214,14 @@ bool UserDialog::addUser(int uid, int gid) | |||
214 | QFile ozTest; | 214 | QFile ozTest; |
215 | int oz=false; | 215 | int oz=false; |
216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; | 216 | if(ODevice::inst()->system()==System_OpenZaurus) oz=true; |
217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. | 217 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here. |
218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); | 218 | UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW); |
219 | adduserDialog->setCaption(tr("Add User")); | 219 | adduserDialog->setCaption(tr("Add User")); |
220 | adduserDialog->userID=uid;// Set next available UID as default uid. | 220 | adduserDialog->userID=uid; // Set next available UID as default uid. |
221 | adduserDialog->groupID=gid;// Set next available GID as default gid. | 221 | adduserDialog->groupID=gid; // Set next available GID as default gid. |
222 | // Insert default group into groupComboBox | 222 | // Insert default group into groupComboBox |
223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 223 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 224 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
225 | // If we're running on OZ, add new users to some default groups. | 225 | // If we're running on OZ, add new users to some default groups. |
226 | if(oz) | 226 | if(oz) |
227 | { | 227 | { |
@@ -268,26 +268,26 @@ bool UserDialog::addUser(int uid, int gid) | |||
268 | QDir d; | 268 | QDir d; |
269 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) | 269 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
270 | { | 270 | { |
271 | d.mkdir("/opt/QtPalmtop/pics/users"); | 271 | d.mkdir("/opt/QtPalmtop/pics/users"); |
272 | } | 272 | } |
273 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 273 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
274 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 274 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
275 | adduserDialog->userImage.save(filename,"PNG"); | 275 | adduserDialog->userImage.save(filename,"PNG"); |
276 | } | 276 | } |
277 | 277 | ||
278 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | 278 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? |
279 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 279 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
280 | if(adduserDialog->skelCheckBox->isChecked()) | 280 | if(adduserDialog->skelCheckBox->isChecked()) |
281 | { | 281 | { |
282 | QString command_cp; | 282 | QString command_cp; |
283 | QString command_chown; | 283 | QString command_chown; |
284 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | 284 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); |
285 | system(command_cp); | 285 | system(command_cp); |
286 | 286 | ||
287 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? | 287 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1()); // Bug in busybox, ".*" includes parent directory, does this work as a workaround? |
288 | system(command_cp); | 288 | system(command_cp); |
289 | 289 | ||
290 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | 290 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); |
291 | system(command_chown); | 291 | system(command_chown); |
292 | } | 292 | } |
293 | 293 | ||
@@ -302,15 +302,15 @@ bool UserDialog::addUser(int uid, int gid) | |||
302 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 302 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
303 | * | 303 | * |
304 | */ | 304 | */ |
305 | bool UserDialog::delUser(const char *username) | 305 | bool UserDialog::delUser(const char *username) |
306 | { | 306 | { |
307 | if((accounts->findUser(username))) | 307 | if((accounts->findUser(username))) |
308 | {// Does that user exist? | 308 | { // Does that user exist? |
309 | if(!(accounts->delUser(username))) | 309 | if(!(accounts->delUser(username))) |
310 | {// Delete the user. | 310 | { // Delete the user. |
311 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 311 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | else | 314 | else |
315 | { | 315 | { |
316 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 316 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
@@ -329,17 +329,17 @@ bool UserDialog::delUser(const char *username) | |||
329 | * | 329 | * |
330 | */ | 330 | */ |
331 | bool UserDialog::editUser(const char *username) | 331 | bool UserDialog::editUser(const char *username) |
332 | { | 332 | { |
333 | int invalid_group=0; | 333 | int invalid_group=0; |
334 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. | 334 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. |
335 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog | 335 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT); // Create Dialog |
336 | edituserDialog->setCaption(tr("Edit User")); | 336 | edituserDialog->setCaption(tr("Edit User")); |
337 | accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. | 337 | accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. |
338 | if(!(accounts->findGroup(accounts->pw_gid))) | 338 | if(!(accounts->findGroup(accounts->pw_gid))) |
339 | {// Locate the user's primary group, and fill group variables in 'accounts' object. | 339 | { // Locate the user's primary group, and fill group variables in 'accounts' object. |
340 | invalid_group=1; | 340 | invalid_group=1; |
341 | } | 341 | } |
342 | // Fill widgets with userinfo. | 342 | // Fill widgets with userinfo. |
343 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 343 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
344 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 344 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
345 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 345 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
@@ -366,55 +366,55 @@ bool UserDialog::editUser(const char *username) | |||
366 | edituserDialog->groupComboBox->setCurrentItem(0); | 366 | edituserDialog->groupComboBox->setCurrentItem(0); |
367 | } | 367 | } |
368 | 368 | ||
369 | // Select the groups in the listview, to which the user belongs. | 369 | // Select the groups in the listview, to which the user belongs. |
370 | QCheckListItem *temp; | 370 | QCheckListItem *temp; |
371 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. | 371 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. |
372 | QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant. | 372 | QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. |
373 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 373 | QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
374 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 374 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
375 | {// Iterate over all of them. | 375 | { // Iterate over all of them. |
376 | qWarning(*it); | 376 | qWarning(*it); |
377 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 377 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
378 | for ( ; lvit.current(); ++lvit ) | 378 | for ( ; lvit.current(); ++lvit ) |
379 | { | 379 | { |
380 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 380 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
381 | { | 381 | { |
382 | temp=(QCheckListItem*)lvit.current(); | 382 | temp=(QCheckListItem*)lvit.current(); |
383 | temp->setOn(true);// If we find a line with that groupname, select it.; | 383 | temp->setOn(true); // If we find a line with that groupname, select it.; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | } | 386 | } |
387 | userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.) | 387 | userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) |
388 | tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 388 | tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. |
389 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) | 389 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
390 | {// Iterate over all of them. | 390 | { // Iterate over all of them. |
391 | qWarning(*it); | 391 | qWarning(*it); |
392 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 392 | QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. |
393 | for ( ; lvit.current(); ++lvit ) | 393 | for ( ; lvit.current(); ++lvit ) |
394 | { | 394 | { |
395 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | 395 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) |
396 | { | 396 | { |
397 | temp=(QCheckListItem*)lvit.current(); | 397 | temp=(QCheckListItem*)lvit.current(); |
398 | temp->setOn(true);// If we find a line with that groupname, select it.; | 398 | temp->setOn(true); // If we find a line with that groupname, select it.; |
399 | } | 399 | } |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! | 403 | if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! |
404 | 404 | ||
405 | accounts->findUser(username);// Fill user variables in 'acccounts' object. | 405 | accounts->findUser(username); // Fill user variables in 'acccounts' object. |
406 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 406 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
407 | // Has the password been changed ? Make a new "crypt":ed password. | 407 | // Has the password been changed ? Make a new "crypt":ed password. |
408 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 408 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
409 | 409 | ||
410 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 410 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
411 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 411 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
412 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) | 412 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) |
413 | {// Fill all group variables in 'accounts' object. | 413 | { // Fill all group variables in 'accounts' object. |
414 | accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. | 414 | accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. |
415 | } | 415 | } |
416 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); | 416 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); |
417 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 417 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
418 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 418 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
419 | accounts->updateUser(username); | 419 | accounts->updateUser(username); |
420 | 420 | ||
@@ -439,13 +439,13 @@ bool UserDialog::editUser(const char *username) | |||
439 | QDir d; | 439 | QDir d; |
440 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) | 440 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
441 | { | 441 | { |
442 | d.mkdir("/opt/QtPalmtop/pics/users"); | 442 | d.mkdir("/opt/QtPalmtop/pics/users"); |
443 | } | 443 | } |
444 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 444 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
445 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 445 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
446 | edituserDialog->userImage.save(filename,"PNG"); | 446 | edituserDialog->userImage.save(filename,"PNG"); |
447 | } | 447 | } |
448 | return true; | 448 | return true; |
449 | } | 449 | } |
450 | 450 | ||
451 | /** | 451 | /** |
@@ -476,13 +476,13 @@ void UserDialog::clickedPicture() | |||
476 | if(!(userImage.load(filename))) | 476 | if(!(userImage.load(filename))) |
477 | { | 477 | { |
478 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 478 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
479 | } | 479 | } |
480 | else | 480 | else |
481 | { | 481 | { |
482 | // userImage=userImage.smoothScale(48,48); | 482 | // userImage=userImage.smoothScale(48,48); |
483 | QPixmap *picture; | 483 | QPixmap *picture; |
484 | picture=(QPixmap *)picturePushButton->pixmap(); | 484 | picture=(QPixmap *)picturePushButton->pixmap(); |
485 | picture->convertFromImage(userImage,0); | 485 | picture->convertFromImage(userImage,0); |
486 | picturePushButton->update(); | 486 | picturePushButton->update(); |
487 | } | 487 | } |
488 | } | 488 | } |