-rw-r--r-- | noncore/settings/usermanager/passwd.cpp | 11 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 17 |
2 files changed, 23 insertions, 5 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp index 0a2bfba..1e98778 100644 --- a/noncore/settings/usermanager/passwd.cpp +++ b/noncore/settings/usermanager/passwd.cpp @@ -115,17 +115,17 @@ void Passwd::splitPasswdEntry(QString &userString) { // Splits a "group" line into the components and stores them in the gr_* variables. void Passwd::splitGroupEntry(QString &groupString) { groupdataStringList=QStringList::split(":",groupString,true); QStringList::Iterator it=groupdataStringList.begin(); gr_name=(*it++); it++; gr_gid=(*it++).toInt(); - gr_mem=QStringList::split(" ",(*it++)); + gr_mem=QStringList::split(",",(*it++)); } // Find a user in the passwdStringList. Return true if found and also fill the pw_* variables. bool Passwd::searchUser(QRegExp &userRegExp) { QStringList tempStringList(passwdStringList.grep(userRegExp)); if((tempStringList.isEmpty())) { return false; } else { @@ -234,19 +234,20 @@ bool Passwd::addGroup(QString gr_name, int gr_gid) { } // Update fields for a group in groupStringList, take info from the gr_* variables. bool Passwd::updateGroup(int gid) { QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { if(groupRegExp.find((*it),0)!=-1) { *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); - for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end(); ++member) { + for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end();) { *it+=*member; - *it+=" "; + ++member; + if(member!=gr_mem.end()) *it+=","; } return true; } } return false; } // Delete a group from groupStringList. @@ -270,17 +271,19 @@ bool Passwd::delGroup(const char *groupname) { bool Passwd::delGroup(int gid) { QRegExp groupRegExp(QString(":%1\\:").arg(gid)); return deleteGroup(groupRegExp); } // Add a user as a member to a group in groupStringList. bool Passwd::addGroupMember(QString groupname, QString member) { if(!(findGroup(groupname))) return false; - gr_mem << member; + QRegExp memberRegExp(QString("^%1$").arg(member)); + QStringList templist=gr_mem.grep(memberRegExp); + if(templist.isEmpty()) gr_mem << member; if(!(updateGroup(gr_gid))) return false; return true; } // Delete a user as a groupmember from a group in groupStringList. bool Passwd::delGroupMember(QString groupname, QString member) { if(!(findGroup(groupname))) return false; for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index c82cc9d..0d2122b 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp @@ -328,21 +328,36 @@ bool UserDialog::editUser(const char *username) { edituserDialog->groupComboBox->setCurrentItem(i); break; } } if(invalid_group) { edituserDialog->groupComboBox->insertItem("<Undefined group>",0); edituserDialog->groupComboBox->setCurrentItem(0); } + // Select the groups in the listview, to which the user belongs. QCheckListItem *temp; - QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); + // 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. + QRegExp userRegExp(QString("[:,]%1$").arg(username)); // The end of line variant. QStringList tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { // Iterate over all of them. + qWarning(*it); + QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. + for ( ; lvit.current(); ++lvit ) { + if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { + temp=(QCheckListItem*)lvit.current(); + temp->setOn(true); // If we find a line with that groupname, select it.; + } + } + } + userRegExp=QRegExp(QString("[:,]%1,").arg(username)); // And the other one. (not end of line.) + tempList=accounts->groupStringList.grep(userRegExp); // Find all entries in the group database, that the user is a member of. + for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { // Iterate over all of them. + qWarning(*it); QListViewItemIterator lvit( edituserDialog->groupsListView ); // Compare to all groups. for ( ; lvit.current(); ++lvit ) { if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { temp=(QCheckListItem*)lvit.current(); temp->setOn(true); // If we find a line with that groupname, select it.; } } } |