-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 149 |
1 files changed, 100 insertions, 49 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index d87a005..08de352 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -10,3 +10,9 @@ | |||
10 | #include "userdialog.h" | 10 | #include "userdialog.h" |
11 | #include "passwd.h" | ||
12 | |||
13 | /* OPIE */ | ||
14 | #include <opie/odevice.h> | ||
15 | #include <qpe/qpeapplication.h> | ||
11 | 16 | ||
17 | /* QT */ | ||
12 | #include <qlayout.h> | 18 | #include <qlayout.h> |
@@ -16,2 +22,3 @@ | |||
16 | 22 | ||
23 | /* STD */ | ||
17 | #include <sys/types.h> | 24 | #include <sys/types.h> |
@@ -21,5 +28,3 @@ | |||
21 | 28 | ||
22 | #include "passwd.h" | ||
23 | 29 | ||
24 | #include <opie/odevice.h> | ||
25 | using namespace Opie; | 30 | using namespace Opie; |
@@ -31,3 +36,4 @@ using namespace Opie; | |||
31 | */ | 36 | */ |
32 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { | 37 | UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) |
38 | { | ||
33 | vm=viewmode; | 39 | vm=viewmode; |
@@ -41,5 +47,7 @@ UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool mod | |||
41 | // And also fill the listview & the combobox with all available groups. | 47 | // And also fill the listview & the combobox with all available groups. |
42 | 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 | { | ||
43 | accounts->splitGroupEntry(*it); | 50 | accounts->splitGroupEntry(*it); |
44 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. | 51 | if(accounts->gr_name.find(QRegExp("^#"),0)) |
52 | {// Skip commented lines. | ||
45 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 53 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
@@ -48,3 +56,3 @@ UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool mod | |||
48 | } | 56 | } |
49 | showMaximized(); | 57 | QPEApplication::showDialog( this ); |
50 | } | 58 | } |
@@ -55,4 +63,4 @@ UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool mod | |||
55 | */ | 63 | */ |
56 | UserDialog::~UserDialog() { | 64 | UserDialog::~UserDialog() |
57 | } | 65 | {} |
58 | 66 | ||
@@ -62,3 +70,4 @@ UserDialog::~UserDialog() { | |||
62 | */ | 70 | */ |
63 | void UserDialog::setupTab1() { | 71 | void UserDialog::setupTab1() |
72 | { | ||
64 | QPixmap mypixmap; | 73 | QPixmap mypixmap; |
@@ -111,3 +120,4 @@ void UserDialog::setupTab1() { | |||
111 | 120 | ||
112 | if(vm==VIEWMODE_NEW) { | 121 | if(vm==VIEWMODE_NEW) |
122 | { | ||
113 | // Copy /etc/skel | 123 | // Copy /etc/skel |
@@ -138,3 +148,4 @@ void UserDialog::setupTab1() { | |||
138 | vlayout1->addWidget(groupLabel); | 148 | vlayout1->addWidget(groupLabel); |
139 | if(vm==VIEWMODE_NEW) { | 149 | if(vm==VIEWMODE_NEW) |
150 | { | ||
140 | vlayout1->addSpacing(5); | 151 | vlayout1->addSpacing(5); |
@@ -154,3 +165,4 @@ void UserDialog::setupTab1() { | |||
154 | vlayout2->addWidget(groupComboBox); | 165 | vlayout2->addWidget(groupComboBox); |
155 | if(vm==VIEWMODE_NEW) { | 166 | if(vm==VIEWMODE_NEW) |
167 | { | ||
156 | vlayout2->addSpacing(5); | 168 | vlayout2->addSpacing(5); |
@@ -168,3 +180,4 @@ void UserDialog::setupTab1() { | |||
168 | */ | 180 | */ |
169 | void UserDialog::setupTab2() { | 181 | void UserDialog::setupTab2() |
182 | { | ||
170 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 183 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
@@ -197,3 +210,4 @@ void UserDialog::setupTab2() { | |||
197 | */ | 210 | */ |
198 | bool UserDialog::addUser(int uid, int gid) { | 211 | bool UserDialog::addUser(int uid, int gid) |
212 | { | ||
199 | QCheckListItem *temp; | 213 | QCheckListItem *temp; |
@@ -211,5 +225,7 @@ bool UserDialog::addUser(int uid, int gid) { | |||
211 | // 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. |
212 | if(oz) { | 226 | if(oz) |
227 | { | ||
213 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 228 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
214 | for ( ; iter.current(); ++iter ) { | 229 | for ( ; iter.current(); ++iter ) |
230 | { | ||
215 | temp=(QCheckListItem*)iter.current(); | 231 | temp=(QCheckListItem*)iter.current(); |
@@ -226,3 +242,4 @@ bool UserDialog::addUser(int uid, int gid) { | |||
226 | if(!(adduserDialog->exec())) return false; | 242 | if(!(adduserDialog->exec())) return false; |
227 | if((adduserDialog->groupComboBox->currentItem()!=0)) { | 243 | if((adduserDialog->groupComboBox->currentItem()!=0)) |
244 | { | ||
228 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 245 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
@@ -233,3 +250,4 @@ bool UserDialog::addUser(int uid, int gid) { | |||
233 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 250 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
234 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 251 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) |
252 | { | ||
235 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 253 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
@@ -240,3 +258,4 @@ bool UserDialog::addUser(int uid, int gid) { | |||
240 | QListViewItemIterator it( adduserDialog->groupsListView ); | 258 | QListViewItemIterator it( adduserDialog->groupsListView ); |
241 | for ( ; it.current(); ++it ) { | 259 | for ( ; it.current(); ++it ) |
260 | { | ||
242 | temp=(QCheckListItem*)it.current(); | 261 | temp=(QCheckListItem*)it.current(); |
@@ -246,5 +265,7 @@ bool UserDialog::addUser(int uid, int gid) { | |||
246 | // Copy image to pics/users/ | 265 | // Copy image to pics/users/ |
247 | if(!(adduserDialog->userImage.isNull())) { | 266 | if(!(adduserDialog->userImage.isNull())) |
267 | { | ||
248 | QDir d; | 268 | QDir d; |
249 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 269 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
270 | { | ||
250 | d.mkdir("/opt/QtPalmtop/pics/users"); | 271 | d.mkdir("/opt/QtPalmtop/pics/users"); |
@@ -258,3 +279,4 @@ bool UserDialog::addUser(int uid, int gid) { | |||
258 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 279 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
259 | if(adduserDialog->skelCheckBox->isChecked()) { | 280 | if(adduserDialog->skelCheckBox->isChecked()) |
281 | { | ||
260 | QString command_cp; | 282 | QString command_cp; |
@@ -282,8 +304,13 @@ bool UserDialog::addUser(int uid, int gid) { | |||
282 | */ | 304 | */ |
283 | bool UserDialog::delUser(const char *username) { | 305 | bool UserDialog::delUser(const char *username) |
284 | if((accounts->findUser(username))) {// Does that user exist? | 306 | { |
285 | if(!(accounts->delUser(username))) {// Delete the user. | 307 | if((accounts->findUser(username))) |
308 | {// Does that user exist? | ||
309 | if(!(accounts->delUser(username))) | ||
310 | {// Delete the user. | ||
286 | 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)+"."); |
287 | } | 312 | } |
288 | } else { | 313 | } |
314 | else | ||
315 | { | ||
289 | 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."); |
@@ -303,3 +330,4 @@ bool UserDialog::delUser(const char *username) { | |||
303 | */ | 330 | */ |
304 | bool UserDialog::editUser(const char *username) { | 331 | bool UserDialog::editUser(const char *username) |
332 | { | ||
305 | int invalid_group=0; | 333 | int invalid_group=0; |
@@ -309,3 +337,4 @@ bool UserDialog::editUser(const char *username) { | |||
309 | 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. |
310 | if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. | 338 | if(!(accounts->findGroup(accounts->pw_gid))) |
339 | {// Locate the user's primary group, and fill group variables in 'accounts' object. | ||
311 | invalid_group=1; | 340 | invalid_group=1; |
@@ -319,3 +348,4 @@ bool UserDialog::editUser(const char *username) { | |||
319 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 348 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
320 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { | 349 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") |
350 | { | ||
321 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 351 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
@@ -324,4 +354,6 @@ bool UserDialog::editUser(const char *username) { | |||
324 | // Select the primary group for this user. | 354 | // Select the primary group for this user. |
325 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { | 355 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) |
326 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { | 356 | { |
357 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) | ||
358 | { | ||
327 | edituserDialog->groupComboBox->setCurrentItem(i); | 359 | edituserDialog->groupComboBox->setCurrentItem(i); |
@@ -330,3 +362,4 @@ bool UserDialog::editUser(const char *username) { | |||
330 | } | 362 | } |
331 | if(invalid_group) { | 363 | if(invalid_group) |
364 | { | ||
332 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | 365 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); |
@@ -340,7 +373,10 @@ bool UserDialog::editUser(const char *username) { | |||
340 | 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. |
341 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 374 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
375 | {// Iterate over all of them. | ||
342 | qWarning(*it); | 376 | qWarning(*it); |
343 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 377 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
344 | for ( ; lvit.current(); ++lvit ) { | 378 | for ( ; lvit.current(); ++lvit ) |
345 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 379 | { |
380 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | ||
381 | { | ||
346 | temp=(QCheckListItem*)lvit.current(); | 382 | temp=(QCheckListItem*)lvit.current(); |
@@ -352,7 +388,10 @@ bool UserDialog::editUser(const char *username) { | |||
352 | 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. |
353 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 389 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
390 | {// Iterate over all of them. | ||
354 | qWarning(*it); | 391 | qWarning(*it); |
355 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 392 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
356 | for ( ; lvit.current(); ++lvit ) { | 393 | for ( ; lvit.current(); ++lvit ) |
357 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 394 | { |
395 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) | ||
396 | { | ||
358 | temp=(QCheckListItem*)lvit.current(); | 397 | temp=(QCheckListItem*)lvit.current(); |
@@ -372,3 +411,4 @@ bool UserDialog::editUser(const char *username) { | |||
372 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 411 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
373 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. | 412 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) |
413 | {// Fill all group variables in 'accounts' object. | ||
374 | 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. |
@@ -381,3 +421,4 @@ bool UserDialog::editUser(const char *username) { | |||
381 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 421 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
382 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { | 422 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) |
423 | { | ||
383 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 424 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
@@ -387,3 +428,4 @@ bool UserDialog::editUser(const char *username) { | |||
387 | QListViewItemIterator it( edituserDialog->groupsListView ); | 428 | QListViewItemIterator it( edituserDialog->groupsListView ); |
388 | for ( ; it.current(); ++it ) { | 429 | for ( ; it.current(); ++it ) |
430 | { | ||
389 | temp=(QCheckListItem*)it.current(); | 431 | temp=(QCheckListItem*)it.current(); |
@@ -394,5 +436,7 @@ bool UserDialog::editUser(const char *username) { | |||
394 | // Copy image to pics/users/ | 436 | // Copy image to pics/users/ |
395 | if(!(edituserDialog->userImage.isNull())) { | 437 | if(!(edituserDialog->userImage.isNull())) |
438 | { | ||
396 | QDir d; | 439 | QDir d; |
397 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 440 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) |
441 | { | ||
398 | d.mkdir("/opt/QtPalmtop/pics/users"); | 442 | d.mkdir("/opt/QtPalmtop/pics/users"); |
@@ -410,5 +454,7 @@ bool UserDialog::editUser(const char *username) { | |||
410 | */ | 454 | */ |
411 | void UserDialog::accept() { | 455 | void UserDialog::accept() |
456 | { | ||
412 | // Add checking... valid username? username taken? | 457 | // Add checking... valid username? username taken? |
413 | if(loginLineEdit->text().isEmpty()) { | 458 | if(loginLineEdit->text().isEmpty()) |
459 | { | ||
414 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 460 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
@@ -423,9 +469,14 @@ void UserDialog::accept() { | |||
423 | */ | 469 | */ |
424 | void UserDialog::clickedPicture() { | 470 | void UserDialog::clickedPicture() |
471 | { | ||
425 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); | 472 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED, QString::null); |
426 | if(!(filename.isEmpty())) { | 473 | if(!(filename.isEmpty())) |
474 | { | ||
427 | userImage.reset(); | 475 | userImage.reset(); |
428 | if(!(userImage.load(filename))) { | 476 | if(!(userImage.load(filename))) |
477 | { | ||
429 | 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); |
430 | } else { | 479 | } |
480 | else | ||
481 | { | ||
431 | // userImage=userImage.smoothScale(48,48); | 482 | // userImage=userImage.smoothScale(48,48); |