-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 32 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.h | 3 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.cpp | 8 | ||||
-rw-r--r-- | noncore/settings/usermanager/usermanager.h | 9 |
4 files changed, 42 insertions, 10 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index b7827a4..90e27d5 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp @@ -25,32 +25,31 @@ /** * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. * */ UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { QVBoxLayout *layout = new QVBoxLayout(this); myTabWidget=new QTabWidget(this,"User Tab Widget"); layout->addWidget(myTabWidget); setupTab1(); setupTab2(); + accounts->groupStringList.sort(); // And also fill the listview & the combobox with all available groups. for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { accounts->splitGroupEntry(*it); - //new QListViewItem(groupsListView,accounts->gr_name); new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); groupComboBox->insertItem(accounts->gr_name); } - showMaximized(); } /** * Empty destructor. * */ UserDialog::~UserDialog() { } /** * Creates the first tab, all userinfo is here. @@ -96,55 +95,67 @@ void UserDialog::setupTab1() { shellLabel->setText("Shell: "); shellComboBox=new QComboBox(tabpage,"shell"); shellComboBox->setEditable(true); shellComboBox->insertItem("/bin/sh"); shellComboBox->insertItem("/bin/ash"); shellComboBox->insertItem("/bin/false"); // Primary Group QLabel *groupLabel=new QLabel(tabpage,"group"); groupLabel->setText("Primary group: "); groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); - // Widget layout + // Copy /etc/skel + QLabel *skelLabel=new QLabel(tabpage,"skel"); + skelLabel->setText("Copy /etc/skel: "); + skelCheckBox=new QCheckBox(tabpage); + skelCheckBox->setChecked(true); + skelLabel->setDisabled(true); + skelCheckBox->setDisabled(true); + + // Widget layout QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); layout->addWidget(picturePushButton); layout->addSpacing(5); layout->addLayout(hlayout); QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); // First column, labels vlayout1->addWidget(loginLabel); vlayout1->addSpacing(5); vlayout1->addWidget(uidLabel); vlayout1->addSpacing(5); vlayout1->addWidget(gecosLabel); vlayout1->addSpacing(5); vlayout1->addWidget(passwordLabel); vlayout1->addSpacing(5); vlayout1->addWidget(shellLabel); vlayout1->addSpacing(5); vlayout1->addWidget(groupLabel); + vlayout1->addSpacing(5); + vlayout1->addWidget(skelLabel); // Second column, data vlayout2->addWidget(loginLineEdit); vlayout2->addSpacing(5); vlayout2->addWidget(uidLineEdit); vlayout2->addSpacing(5); vlayout2->addWidget(gecosLineEdit); vlayout2->addSpacing(5); vlayout2->addWidget(passwordLineEdit); vlayout2->addSpacing(5); vlayout2->addWidget(shellComboBox); vlayout2->addSpacing(5); vlayout2->addWidget(groupComboBox); + vlayout2->addSpacing(5); + vlayout2->addWidget(skelCheckBox); hlayout->addLayout(vlayout1); hlayout->addLayout(vlayout2); myTabWidget->addTab(tabpage,"User Info"); } /** * Creates the second tab containing additional groups for the user. * */ void UserDialog::setupTab2() { QWidget *tabpage = new QWidget(myTabWidget,"page2"); @@ -239,70 +250,79 @@ bool UserDialog::delUser(const char *username) { } /** * This displays a confirmation dialog wether a user should be deleted or not. * (And also deletes the account) * * @param username User to be deleted. * * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. * */ bool UserDialog::editUser(const char *username) { + int invalid_group=0; UserDialog *edituserDialog=new UserDialog(); // Create Dialog edituserDialog->setCaption(tr("Edit User")); accounts->findUser(username); // Locate user in database and fill variables in 'accounts' object. - accounts->findGroup(accounts->pw_gid); // Locate the user's primary group, and fill group variables in 'accounts' object. + if(!(accounts->findGroup(accounts->pw_gid))) { // Locate the user's primary group, and fill group variables in 'accounts' object. + invalid_group=1; + } // Fill widgets with userinfo. edituserDialog->loginLineEdit->setText(accounts->pw_name); edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. edituserDialog->passwordLineEdit->setText("........"); // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); edituserDialog->shellComboBox->setCurrentItem(0); } // Select the primary group for this user. for(int i=0;i<edituserDialog->groupComboBox->count();++i) { if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 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)); 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. 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.; } } } if(!(edituserDialog->exec())) return false; // SHOW THE DIALOG! accounts->findUser(username); // Fill user variables in 'acccounts' object. accounts->pw_name=edituserDialog->loginLineEdit->text(); // Has the password been changed ? Make a new "crypt":ed password. if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); // Set all variables in accounts object, that will be used when calling 'updateUser()' accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); - accounts->findGroup(edituserDialog->groupComboBox->currentText()); // Fill all group variables in 'accounts' object. - accounts->pw_gid=accounts->gr_gid; + if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) { // Fill all group variables in 'accounts' object. + accounts->pw_gid=accounts->gr_gid; // Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. + } accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); accounts->pw_shell=edituserDialog->shellComboBox->currentText(); // Update userinfo, using the information stored in the user variables stored in the accounts object. accounts->updateUser(username); // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { accounts->delGroupMember((*it).left((*it).find(":")),username); } // Add User to additional groups that he/she is a member of. QListViewItemIterator it( edituserDialog->groupsListView ); diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h index a878588..133b35d 100644 --- a/noncore/settings/usermanager/userdialog.h +++ b/noncore/settings/usermanager/userdialog.h @@ -6,41 +6,44 @@ * (at your option) any later version. * * * ***************************************************************************/ #ifndef USERDIALOG_H #define USERDIALOG_H #include <qdialog.h> #include <qlineedit.h> #include <qcombobox.h> #include <qlistview.h> #include <qtabwidget.h> #include <qpushbutton.h> +#include <qcheckbox.h> #include <qpe/resource.h> #include <opie/ofiledialog.h> class UserDialog : public QDialog { Q_OBJECT private: QTabWidget *myTabWidget; QPushButton *picturePushButton; QLineEdit *loginLineEdit; QLineEdit *uidLineEdit; QLineEdit *gecosLineEdit; QLineEdit *passwordLineEdit; QComboBox *shellComboBox; QComboBox *groupComboBox; + QLabel *skelLabel; + QCheckBox *skelCheckBox; QListView *groupsListView; QStringList groupMembers; QString pictureLocation; QImage userImage; int groupID; int userID; void setupTab1(void); void setupTab2(void); void accept(void); diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index 2735e6a..57efa71 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp @@ -45,47 +45,50 @@ UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWind addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); groupstext->setUsesTextLabel(true); addToolBar(toolbar,"myToolBar"); // Add a tabwidget and all the tabs. myTabWidget = new QTabWidget(this,"My Tab Widget"); setupTabAccounts(); setupTabAllUsers(); setupTabAllGroups(); + userPopupMenu.insertItem("Copy",0); getUsers(); // Fill out the iconview & listview with all users. getGroups(); // Fill out the group listview with all groups. setCentralWidget(myTabWidget); } UserConfig::~UserConfig() { accounts->close(); delete accounts; } void UserConfig::setupTabAccounts() { QWidget *tabpage = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(tabpage); layout->setMargin(5); usersIconView=new QListView(tabpage,"users"); usersIconView->addColumn("Icon"); usersIconView->addColumn("Username"); usersIconView->setAllColumnsShowFocus(true); layout->addWidget(usersIconView); + connect(usersIconView,SIGNAL(returnPressed(QListViewItem *)),this,SLOT(showUserMenu(QListViewItem *))); + myTabWidget->addTab(tabpage,"Users"); } void UserConfig::setupTabAllUsers() { QWidget *tabpage = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(tabpage); layout->setMargin(5); usersListView=new QListView(tabpage,"allusers"); usersListView->addColumn("UID"); usersListView->addColumn("Login"); usersListView->addColumn("Username"); @@ -235,12 +238,17 @@ void UserConfig::editGroup() { void UserConfig::delGroup() { const char *groupname; if(groupsListView->currentItem()) { // Any group selected? groupname=groupsListView->currentItem()->text(1); // Get the groupname from the listview. if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { // If confirmed, try to delete the group. if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. } } else { QMessageBox::information(this,"No selection","No group has been selected."); } } + +void UserConfig::showUserMenu(QListViewItem *item) { +// userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); + qWarning("Pressed!"); +} diff --git a/noncore/settings/usermanager/usermanager.h b/noncore/settings/usermanager/usermanager.h index 9909242..6782923 100644 --- a/noncore/settings/usermanager/usermanager.h +++ b/noncore/settings/usermanager/usermanager.h @@ -4,62 +4,63 @@ * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifndef USERCONFIG_H #define USERCONFIG_H #include <qmainwindow.h> #include <qtabwidget.h> #include <qlistview.h> -//#include <qiconview.h> - -#include <qpe/qpemenubar.h> #include <qpopupmenu.h> -#include <qpe/qpetoolbar.h> #include <qtoolbutton.h> +#include <qpe/qpetoolbar.h> + #include "userdialog.h" #include "groupdialog.h" #include "passwd.h" class UserConfig : public QMainWindow { Q_OBJECT public: UserConfig( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~UserConfig(); private: QToolButton *adduserToolButton; QToolButton *edituserToolButton; QToolButton *deleteuserToolButton; QToolButton *addgroupToolButton; QToolButton *editgroupToolButton; QToolButton *deletegroupToolButton; QTabWidget *myTabWidget; QListView *usersIconView; QListView *usersListView; QListView *groupsListView; + QPopupMenu userPopupMenu; + QPopupMenu groupPopupMenu; int availableUID; int availableGID; void setupTabAccounts(); void setupTabAllUsers(); void setupTabAllGroups(); void setupTabPrefs(); void setupTabAbout(); void getUsers(); void getGroups(); private slots: void addUser(); void editUser(); void delUser(); void addGroup(); void editGroup(); void delGroup(); + void showUserMenu(QListViewItem *item); }; #endif // USERCONFIG_H |