summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/userdialog.cpp
Unidiff
Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/usermanager/userdialog.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 36bcf86..c82cc9d 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -23,25 +23,26 @@
23#include <signal.h> 23#include <signal.h>
24 24
25#include "passwd.h" 25#include "passwd.h"
26 26
27#include <opie/odevice.h> 27#include <opie/odevice.h>
28using namespace Opie; 28using namespace Opie;
29 29
30 30
31/** 31/**
32 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 32 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
33 * 33 *
34 */ 34 */
35UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 35UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
36 vm=viewmode;
36 QVBoxLayout *layout = new QVBoxLayout(this); 37 QVBoxLayout *layout = new QVBoxLayout(this);
37 myTabWidget=new QTabWidget(this,"User Tab Widget"); 38 myTabWidget=new QTabWidget(this,"User Tab Widget");
38 layout->addWidget(myTabWidget); 39 layout->addWidget(myTabWidget);
39 setupTab1(); 40 setupTab1();
40 setupTab2(); 41 setupTab2();
41 42
42 accounts->groupStringList.sort(); 43 accounts->groupStringList.sort();
43 // And also fill the listview & the combobox with all available groups. 44 // And also fill the listview & the combobox with all available groups.
44 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 45 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
45 accounts->splitGroupEntry(*it); 46 accounts->splitGroupEntry(*it);
46 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); 47 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
47 groupComboBox->insertItem(accounts->gr_name); 48 groupComboBox->insertItem(accounts->gr_name);
@@ -100,67 +101,71 @@ void UserDialog::setupTab1() {
100 shellLabel->setText("Shell: "); 101 shellLabel->setText("Shell: ");
101 shellComboBox=new QComboBox(tabpage,"shell"); 102 shellComboBox=new QComboBox(tabpage,"shell");
102 shellComboBox->setEditable(true); 103 shellComboBox->setEditable(true);
103 shellComboBox->insertItem("/bin/sh"); 104 shellComboBox->insertItem("/bin/sh");
104 shellComboBox->insertItem("/bin/ash"); 105 shellComboBox->insertItem("/bin/ash");
105 shellComboBox->insertItem("/bin/false"); 106 shellComboBox->insertItem("/bin/false");
106 107
107 // Primary Group 108 // Primary Group
108 QLabel *groupLabel=new QLabel(tabpage,"group"); 109 QLabel *groupLabel=new QLabel(tabpage,"group");
109 groupLabel->setText("Primary group: "); 110 groupLabel->setText("Primary group: ");
110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 111 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
111 112
113 if(vm==VIEWMODE_NEW) {
112 // Copy /etc/skel 114 // Copy /etc/skel
113 QLabel *skelLabel=new QLabel(tabpage,"skel"); 115 skelLabel=new QLabel(tabpage,"skel");
114 skelLabel->setText("Copy /etc/skel: "); 116 skelLabel->setText("Copy /etc/skel: ");
115 skelCheckBox=new QCheckBox(tabpage); 117 skelCheckBox=new QCheckBox(tabpage);
116 skelCheckBox->setChecked(true); 118 skelCheckBox->setChecked(true);
117 //skelLabel->setDisabled(true); 119 }
118 //skelCheckBox->setDisabled(true);
119 120
120 // Widget layout 121 // Widget layout
121 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 122 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
122 layout->addWidget(picturePushButton); 123 layout->addWidget(picturePushButton);
123 layout->addSpacing(5); 124 layout->addSpacing(5);
124 layout->addLayout(hlayout); 125 layout->addLayout(hlayout);
125 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 126 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
126 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 127 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
127 // First column, labels 128 // First column, labels
128 vlayout1->addWidget(loginLabel); 129 vlayout1->addWidget(loginLabel);
129 vlayout1->addSpacing(5); 130 vlayout1->addSpacing(5);
130 vlayout1->addWidget(uidLabel); 131 vlayout1->addWidget(uidLabel);
131 vlayout1->addSpacing(5); 132 vlayout1->addSpacing(5);
132 vlayout1->addWidget(gecosLabel); 133 vlayout1->addWidget(gecosLabel);
133 vlayout1->addSpacing(5); 134 vlayout1->addSpacing(5);
134 vlayout1->addWidget(passwordLabel); 135 vlayout1->addWidget(passwordLabel);
135 vlayout1->addSpacing(5); 136 vlayout1->addSpacing(5);
136 vlayout1->addWidget(shellLabel); 137 vlayout1->addWidget(shellLabel);
137 vlayout1->addSpacing(5); 138 vlayout1->addSpacing(5);
138 vlayout1->addWidget(groupLabel); 139 vlayout1->addWidget(groupLabel);
140 if(vm==VIEWMODE_NEW) {
139 vlayout1->addSpacing(5); 141 vlayout1->addSpacing(5);
140 vlayout1->addWidget(skelLabel); 142 vlayout1->addWidget(skelLabel);
143 }
141 // Second column, data 144 // Second column, data
142 vlayout2->addWidget(loginLineEdit); 145 vlayout2->addWidget(loginLineEdit);
143 vlayout2->addSpacing(5); 146 vlayout2->addSpacing(5);
144 vlayout2->addWidget(uidLineEdit); 147 vlayout2->addWidget(uidLineEdit);
145 vlayout2->addSpacing(5); 148 vlayout2->addSpacing(5);
146 vlayout2->addWidget(gecosLineEdit); 149 vlayout2->addWidget(gecosLineEdit);
147 vlayout2->addSpacing(5); 150 vlayout2->addSpacing(5);
148 vlayout2->addWidget(passwordLineEdit); 151 vlayout2->addWidget(passwordLineEdit);
149 vlayout2->addSpacing(5); 152 vlayout2->addSpacing(5);
150 vlayout2->addWidget(shellComboBox); 153 vlayout2->addWidget(shellComboBox);
151 vlayout2->addSpacing(5); 154 vlayout2->addSpacing(5);
152 vlayout2->addWidget(groupComboBox); 155 vlayout2->addWidget(groupComboBox);
156 if(vm==VIEWMODE_NEW) {
153 vlayout2->addSpacing(5); 157 vlayout2->addSpacing(5);
154 vlayout2->addWidget(skelCheckBox); 158 vlayout2->addWidget(skelCheckBox);
159 }
155 hlayout->addLayout(vlayout1); 160 hlayout->addLayout(vlayout1);
156 hlayout->addLayout(vlayout2); 161 hlayout->addLayout(vlayout2);
157 162
158 myTabWidget->addTab(tabpage,"User Info"); 163 myTabWidget->addTab(tabpage,"User Info");
159} 164}
160 165
161/** 166/**
162 * Creates the second tab containing additional groups for the user. 167 * Creates the second tab containing additional groups for the user.
163 * 168 *
164 */ 169 */
165void UserDialog::setupTab2() { 170void UserDialog::setupTab2() {
166 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 171 QWidget *tabpage = new QWidget(myTabWidget,"page2");
@@ -187,25 +192,26 @@ void UserDialog::setupTab2() {
187 * 192 *
188 * @param uid This is a suggested available UID. 193 * @param uid This is a suggested available UID.
189 * @param gid This is a suggested available GID. 194 * @param gid This is a suggested available GID.
190 * 195 *
191 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 196 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
192 * 197 *
193 */ 198 */
194bool UserDialog::addUser(int uid, int gid) { 199bool UserDialog::addUser(int uid, int gid) {
195 QCheckListItem *temp; 200 QCheckListItem *temp;
196 QFile ozTest; 201 QFile ozTest;
197 int oz=false; 202 int oz=false;
198 if(ODevice::inst()->system()==System_OpenZaurus) oz=true; 203 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
199 UserDialog *adduserDialog=new UserDialog(); 204 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here.
205 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW);
200 adduserDialog->setCaption(tr("Add User")); 206 adduserDialog->setCaption(tr("Add User"));
201 adduserDialog->userID=uid;// Set next available UID as default uid. 207 adduserDialog->userID=uid;// Set next available UID as default uid.
202 adduserDialog->groupID=gid;// Set next available GID as default gid. 208 adduserDialog->groupID=gid;// Set next available GID as default gid.
203 // Insert default group into groupComboBox 209 // Insert default group into groupComboBox
204 adduserDialog->groupComboBox->insertItem("<create new group>",0); 210 adduserDialog->groupComboBox->insertItem("<create new group>",0);
205 adduserDialog->uidLineEdit->setText(QString::number(uid)); 211 adduserDialog->uidLineEdit->setText(QString::number(uid));
206 // If we're running on OZ, add new users to some default groups. 212 // If we're running on OZ, add new users to some default groups.
207 if(oz) { 213 if(oz) {
208 QListViewItemIterator iter( adduserDialog->groupsListView ); 214 QListViewItemIterator iter( adduserDialog->groupsListView );
209 for ( ; iter.current(); ++iter ) { 215 for ( ; iter.current(); ++iter ) {
210 temp=(QCheckListItem*)iter.current(); 216 temp=(QCheckListItem*)iter.current();
211 if (temp->text()=="video") temp->setOn(true); 217 if (temp->text()=="video") temp->setOn(true);
@@ -289,25 +295,26 @@ bool UserDialog::delUser(const char *username) {
289 295
290/** 296/**
291 * This displays a confirmation dialog wether a user should be deleted or not. 297 * This displays a confirmation dialog wether a user should be deleted or not.
292 * (And also deletes the account) 298 * (And also deletes the account)
293 * 299 *
294 * @param username User to be deleted. 300 * @param username User to be deleted.
295 * 301 *
296 * @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>.
297 * 303 *
298 */ 304 */
299bool UserDialog::editUser(const char *username) { 305bool UserDialog::editUser(const char *username) {
300 int invalid_group=0; 306 int invalid_group=0;
301 UserDialog *edituserDialog=new UserDialog();// Create Dialog 307 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here.
308 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog
302 edituserDialog->setCaption(tr("Edit User")); 309 edituserDialog->setCaption(tr("Edit User"));
303 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 310 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
304 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 311 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object.
305 invalid_group=1; 312 invalid_group=1;
306 } 313 }
307 // Fill widgets with userinfo. 314 // Fill widgets with userinfo.
308 edituserDialog->loginLineEdit->setText(accounts->pw_name); 315 edituserDialog->loginLineEdit->setText(accounts->pw_name);
309 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); 316 edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid));
310 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); 317 edituserDialog->gecosLineEdit->setText(accounts->pw_gecos);
311 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. 318 // Set password to '........', we will later check if this still is the contents, if not, the password has been changed.
312 edituserDialog->passwordLineEdit->setText("........"); 319 edituserDialog->passwordLineEdit->setText("........");
313 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 320 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.